Received: from eggs.gnu.org ([140.186.70.92]:34746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNLOc-0007N7-G5 for qemu-devel@nongnu.org; Mon, 07 Nov 2011 04:21:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RNLOZ-0001Og-4E for qemu-devel@nongnu.org; Mon, 07 Nov 2011 04:21:38 -0500 Received: from mtagate2.uk.ibm.com ([194.196.100.162]:56264) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNLOY-0001O7-TK for qemu-devel@nongnu.org; Mon, 07 Nov 2011 04:21:35 -0500 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pA79LVq3011751 for ; Mon, 7 Nov 2011 09:21:31 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pA79LVFo2674696 for ; Mon, 7 Nov 2011 09:21:31 GMT Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pA79LVNG003707 for ; Mon, 7 Nov 2011 02:21:31 -0700 Date: Mon, 7 Nov 2011 08:34:36 +0000 From: Stefan Hajnoczi Message-ID: <20111107083435.GA8972@stefanha-thinkpad.localdomain> References: <1320648737-22798-1-git-send-email-zhihuili@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1320648737-22798-1-git-send-email-zhihuili@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v2] block: Use bdrv functions to replace file operation in cow.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Li Zhi Hui Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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