From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZtV1-0006GA-6g for qemu-devel@nongnu.org; Tue, 26 Jan 2010 17:03:04 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZtUv-00067a-69 for qemu-devel@nongnu.org; Tue, 26 Jan 2010 17:03:02 -0500 Received: from [199.232.76.173] (port=47985 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZtUu-00067H-PH for qemu-devel@nongnu.org; Tue, 26 Jan 2010 17:02:56 -0500 Received: from mail-iw0-f188.google.com ([209.85.223.188]:40596) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NZtUu-0000RP-97 for qemu-devel@nongnu.org; Tue, 26 Jan 2010 17:02:56 -0500 Received: by mail-iw0-f188.google.com with SMTP id 26so5377896iwn.14 for ; Tue, 26 Jan 2010 14:02:55 -0800 (PST) Message-ID: <4B5F668C.4010301@codemonkey.ws> Date: Tue, 26 Jan 2010 16:02:52 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH v2 1/2] block: clean up bdrv_open2 structure a bit References: <20100120171325.GA8811@lst.de> In-Reply-To: <20100120171325.GA8811@lst.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christoph Hellwig Cc: qemu-devel@nongnu.org On 01/20/2010 11:13 AM, Christoph Hellwig wrote: > Check the whitelist as early as possible instead of continuing the > setup, and move all the error handling code to the end of the > function. > > Signed-off-by: Christoph Hellwig > Applied all. Thanks. Regards, Anthony Liguori > Index: qemu/block.c > =================================================================== > --- qemu.orig/block.c 2010-01-20 17:21:33.000000000 +0100 > +++ qemu/block.c 2010-01-20 17:24:22.596006289 +0100 > @@ -428,10 +428,16 @@ int bdrv_open2(BlockDriverState *bs, con > drv = find_image_format(filename); > } > } > + > if (!drv) { > ret = -ENOENT; > goto unlink_and_fail; > } > + if (use_bdrv_whitelist&& !bdrv_is_whitelisted(drv)) { > + ret = -ENOTSUP; > + goto unlink_and_fail; > + } > + > bs->drv = drv; > bs->opaque = qemu_mallocz(drv->instance_size); > > @@ -453,20 +459,12 @@ int bdrv_open2(BlockDriverState *bs, con > } else { > open_flags = flags& ~(BDRV_O_FILE | BDRV_O_SNAPSHOT); > } > - if (use_bdrv_whitelist&& !bdrv_is_whitelisted(drv)) { > - ret = -ENOTSUP; > - } else { > - ret = drv->bdrv_open(bs, filename, open_flags); > - } > + > + ret = drv->bdrv_open(bs, filename, open_flags); > if (ret< 0) { > - qemu_free(bs->opaque); > - bs->opaque = NULL; > - bs->drv = NULL; > - unlink_and_fail: > - if (bs->is_temporary) > - unlink(filename); > - return ret; > + goto free_and_fail; > } > + > if (drv->bdrv_getlength) { > bs->total_sectors = bdrv_getlength(bs)>> BDRV_SECTOR_BITS; > } > @@ -499,6 +497,15 @@ int bdrv_open2(BlockDriverState *bs, con > bs->change_cb(bs->change_opaque); > } > return 0; > + > +free_and_fail: > + qemu_free(bs->opaque); > + bs->opaque = NULL; > + bs->drv = NULL; > +unlink_and_fail: > + if (bs->is_temporary) > + unlink(filename); > + return ret; > } > > void bdrv_close(BlockDriverState *bs) > > > >