On Mon, Nov 07, 2011 at 02:52:17PM +0800, Li Zhi Hui wrote: > @@ -260,10 +261,15 @@ static int cow_create(const char *filename, > QEMUOptionParameter *options) > options++; > } > > - cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, > - 0644); > - if (cow_fd < 0) > - return -errno; > + ret = bdrv_create_file(filename, options); > + if (ret < 0) { > + return ret; > + } > + > + ret = bdrv_file_open(&cow_bs, filename, BDRV_O_RDWR); > + if (ret < 0) { > + return ret; > + } > memset(&cow_header, 0, sizeof(cow_header)); > cow_header.magic = cpu_to_be32(COW_MAGIC); > cow_header.version = cpu_to_be32(COW_VERSION); > @@ -271,16 +277,16 @@ static int cow_create(const char *filename, > QEMUOptionParameter *options) > /* Note: if no file, we put a dummy mtime */ > cow_header.mtime = cpu_to_be32(0); > > - fd = open(image_filename, O_RDONLY | O_BINARY); > - if (fd < 0) { > - close(cow_fd); > + ret = bdrv_file_open(&image_bs, image_filename, BDRV_O_RDWR); > + if (ret < 0) { > + bdrv_close(cow_bs);
This should be bdrv_delete() instead of bdrv_close() because bdrv_file_open() does bdrv_new() to allocate the BlockDriverState - it needs to be freed. The same applies to the other hunks in this patch. Stefan