From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Sbh-0002JS-Sr for qemu-devel@nongnu.org; Thu, 23 Jan 2014 17:18:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6Sbb-0002oy-TX for qemu-devel@nongnu.org; Thu, 23 Jan 2014 17:18:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6Sbb-0002ot-Lg for qemu-devel@nongnu.org; Thu, 23 Jan 2014 17:18:35 -0500 Date: Thu, 23 Jan 2014 17:18:30 -0500 From: Jeff Cody Message-ID: <20140123221830.GE13722@localhost.localdomain> References: <5cb7f2874a3525b2359739109c361f1b2640285a.1390513348.git.jcody@redhat.com> <20140123220526.GD22578@irqsave.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20140123220526.GD22578@irqsave.net> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 2/3] block: resize backing image during active layer commit, if needed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Beno=EEt?= Canet Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Thu, Jan 23, 2014 at 11:05:26PM +0100, Beno=EEt Canet wrote: > Le Thursday 23 Jan 2014 =E0 16:48:56 (-0500), Jeff Cody a =E9crit : > > If the top image to commit is the active layer, and also larger than > > the base image, then an I/O error will likely be returned during > > block-commit. > >=20 > > For instance, if we have a base image with a virtual size 10G, and a > > active layer image of size 20G, then committing the snapshot via > > 'block-commit' will likely fail. > >=20 > > This will automatically attempt to resize the base image, if the > > active layer image to be committed is larger. > >=20 > > Signed-off-by: Jeff Cody > > Reviewed-by: Eric Blake > > --- > > block/mirror.c | 41 +++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 41 insertions(+) > >=20 > > diff --git a/block/mirror.c b/block/mirror.c > > index 2932bab..2a33aa6 100644 > > --- a/block/mirror.c > > +++ b/block/mirror.c > > @@ -630,11 +630,52 @@ void commit_active_start(BlockDriverState *bs, = BlockDriverState *base, > > BlockDriverCompletionFunc *cb, > > void *opaque, Error **errp) > > { > > + int64_t length, base_length; > > + int orig_base_flags; > > + > > + orig_base_flags =3D bdrv_get_flags(base); > > + > > if (bdrv_reopen(base, bs->open_flags, errp)) { > > return; > > } > > + > > + length =3D bdrv_getlength(bs); > > + if (length < 0) { > > + error_setg(errp, "Unable to determine length of %s", bs->fil= ename); > > + goto error_restore_flags; > > + } > > + > > + base_length =3D bdrv_getlength(base); > > + if (base_length < 0) { > > + error_setg(errp, "Unable to determine length of %s", base->f= ilename); > > + goto error_restore_flags; > > + } > > + > > + if (length > base_length) { > > + if (bdrv_truncate(base, length) < 0) { > > + error_setg(errp, "Top image %s is larger than base image= %s, and " > > + "resize of base image failed", > > + bs->filename, base->filename); > > + goto error_restore_flags; > > + } >=20 >=20 > > + } else if (length < 0) { > > + goto error_restore_flags; > > + } > The code already test for (length < 0) ten lines above. Is this branch = really > needed ? >=20 > Best regards >=20 > Beno=EEt Thanks - no, it is not needed. I did not mean to have that there - while harmless, it is essentially dead code and should be culled. I'll submit a v4 to take care of that. >=20 > > + > > + > > bdrv_ref(base); > > mirror_start_job(bs, base, speed, 0, 0, > > on_error, on_error, cb, opaque, errp, > > &commit_active_job_driver, false, base); > > + if (error_is_set(errp)) { > > + goto error_restore_flags; > > + } > > + > > + return; > > + > > +error_restore_flags: > > + /* ignore error and errp for bdrv_reopen, because we want to pro= pagate > > + * the original error */ > > + bdrv_reopen(base, orig_base_flags, NULL); > > + return; > > } > > --=20 > > 1.8.3.1 > >=20 > >=20