Received: from eggs.gnu.org ([2001:4830:134:3::10]:47560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCQe2-0001C3-Hl for qemu-devel@nongnu.org; Thu, 22 Aug 2013 04:53:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCQdw-0003IV-CS for qemu-devel@nongnu.org; Thu, 22 Aug 2013 04:53:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCQdw-0003HG-3x for qemu-devel@nongnu.org; Thu, 22 Aug 2013 04:53:24 -0400 Date: Thu, 22 Aug 2013 16:53:20 +0800 From: Fam Zheng Message-ID: <20130822085320.GA14691@T430s.nay.redhat.com> References: <1375071932-31627-1-git-send-email-famz@redhat.com> <1375071932-31627-4-git-send-email-famz@redhat.com> <20130821130203.GB11975@stefanha-thinkpad.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130821130203.GB11975@stefanha-thinkpad.redhat.com> Subject: Re: [Qemu-devel] [RFC PATCH 3/4] qmp: Add "snapshot=" option to nbd-server-add Reply-To: famz@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: kwolf@redhat.com, pbonzini@redhat.com, imain@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Wed, 08/21 15:02, Stefan Hajnoczi wrote: > On Mon, Jul 29, 2013 at 12:25:31PM +0800, Fam Zheng wrote: > > +/* create a point-in-time snapshot BDS from an existing BDS */ > > +static BlockDriverState *nbd_create_snapshot(BlockDriverState *orig_bs) > > +{ > > + int ret; > > + char filename[1024]; > > + BlockDriver *drv; > > + BlockDriverState *bs; > > + QEMUOptionParameter *options; > > + Error *local_err = NULL; > > + > > + bs = bdrv_new(""); > > + ret = get_tmp_filename(filename, sizeof(filename)); > > + if (ret < 0) { > > + goto err; > > unlink(filename) is not safe if this function returns an error. > > It is simpler if you get the temporary filename first and then do > bdrv_new(). > > > + } > > + drv = bdrv_find_format("qcow2"); > > + if (drv < 0) { > > + goto err; > > + } > > + options = parse_option_parameters("", drv->create_options, NULL); > > + set_option_parameter_int(options, BLOCK_OPT_SIZE, bdrv_getlength(orig_bs)); > > + > > + ret = bdrv_create(drv, filename, options); > > This is handy but only works if the QEMU process has permission to > create temporary files. > Yes, this is a shortcut, it has this limitation, but the good side is it's easy to get and no other dependency. To avoid creating file, we'll need blockdev-add to override backing_hd, and blockdev-backup to use an existing BDS as target, then we simply use current nbd-server-add to export it. This series is still RFC, with above said, we still need to decide which is the way we (QEMU and libvirt) want for 1.7. any thoughts? Thanks Fam