From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=52839 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBP9G-0006tM-Tt for qemu-devel@nongnu.org; Thu, 28 Oct 2010 05:51:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PBP9F-0000ZC-JJ for qemu-devel@nongnu.org; Thu, 28 Oct 2010 05:51:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PBP9F-0000Z5-Bs for qemu-devel@nongnu.org; Thu, 28 Oct 2010 05:51:53 -0400 Date: Thu, 28 Oct 2010 10:51:49 +0100 From: "Daniel P. Berrange" Subject: Re: [Qemu-devel] [PATCH] block: fix the use of protocols in backing files Message-ID: <20101028095149.GE11647@redhat.com> References: <1288203550-23698-1-git-send-email-aliguori@us.ibm.com> <20101028093502.GC11647@redhat.com> <4CC94746.1040601@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4CC94746.1040601@redhat.com> Reply-To: "Daniel P. Berrange" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: Stefan Hajnoczi , Anthony Liguori , qemu-devel@nongnu.org, Stefan Hajnoczi , Adam Litke On Thu, Oct 28, 2010 at 11:49:58AM +0200, Kevin Wolf wrote: > Am 28.10.2010 11:35, schrieb Daniel P. Berrange: > > On Thu, Oct 28, 2010 at 09:30:09AM +0100, Stefan Hajnoczi wrote: > >> On Wed, Oct 27, 2010 at 7:19 PM, Anthony Liguori wrote: > >>> Signed-off-by: Anthony Liguori > >>> > >>> diff --git a/block.c b/block.c > >>> index 1a965b2..00b6f21 100644 > >>> --- a/block.c > >>> +++ b/block.c > >>> @@ -603,10 +603,16 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, > >>> BlockDriver *back_drv = NULL; > >>> > >>> bs->backing_hd = bdrv_new(""); > >>> - path_combine(backing_filename, sizeof(backing_filename), > >>> - filename, bs->backing_file); > >>> - if (bs->backing_format[0] != '\0') > >>> - back_drv = bdrv_find_format(bs->backing_format); > >>> + back_drv = bdrv_find_protocol(bs->backing_file); > >>> + if (!back_drv) { > >>> + path_combine(backing_filename, sizeof(backing_filename), > >>> + filename, bs->backing_file); > >>> + if (bs->backing_format[0] != '\0') > >>> + back_drv = bdrv_find_format(bs->backing_format); > >>> + } else { > >>> + pstrcpy(backing_filename, sizeof(backing_filename), > >>> + bs->backing_file); > >>> + } > >>> > >>> /* backing files always opened read-only */ > >>> back_flags = > >>> -- > >>> 1.7.0.4 > >> > >> I think this makes sense. > >> > >> Now it is possible to specify backing files that are relative to > >> QEMU's current working directory using file:filename. I don't see > >> harm in this. > > > > Shouldn't a backing file be treated as relative to the image file pointing > > to it, rather than the QEMU working directory. eg so you can do > > > > # qemu-img create backing.img > > # qemu-img create -o backing_file=file:backing.img main.img > > > > And have main.img be able to resolve backing.img in its same directory, > > no matter what directory QEMU itself is executing from > > The problem is that this wouldn't work in the general case. It's rather > an exception that it makes sense for file: backing files with file: > images. Consider this: > > # qemu-img create -o backing_file=nbd:foo:1234 /tmp/main.img > > Without this patch, you'll end up with /tmp/nbd:foo:1234, which is > probably not what you wanted. With a patch that would work for file: you > would get a hardly better path nbd:/tmp/foo:1234 Since we know the protocol, there could be a per-protocol function used for resolving the backing store URI relative to the master URI. That would avoid needing to special case file: in the shared generic code. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|