From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6TZg-0007lZ-HW for qemu-devel@nongnu.org; Thu, 23 Jan 2014 18:20:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6TZb-0004cL-9t for qemu-devel@nongnu.org; Thu, 23 Jan 2014 18:20:40 -0500 Received: from paradis.irqsave.net ([62.212.105.220]:48206) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6TZa-0004cB-SI for qemu-devel@nongnu.org; Thu, 23 Jan 2014 18:20:35 -0500 Date: Fri, 24 Jan 2014 00:20:33 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140123232033.GF22578@irqsave.net> References: <2e6c5081c97786c29c339f166cea9c162f3854ac.1390516414.git.jcody@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <2e6c5081c97786c29c339f166cea9c162f3854ac.1390516414.git.jcody@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 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: Jeff Cody Cc: kwolf@redhat.com, benoit.canet@irqsave.net, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Le Thursday 23 Jan 2014 =E0 17:45:08 (-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 | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) >=20 > diff --git a/block/mirror.c b/block/mirror.c > index 2932bab..10fd15d 100644 > --- a/block/mirror.c > +++ b/block/mirror.c > @@ -630,11 +630,49 @@ void commit_active_start(BlockDriverState *bs, Bl= ockDriverState *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->filen= ame); > + goto error_restore_flags; > + } > + > + base_length =3D bdrv_getlength(base); > + if (base_length < 0) { > + error_setg(errp, "Unable to determine length of %s", base->fil= ename); > + 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; > + } > + } > + > 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 propa= gate > + * the original error */ > + bdrv_reopen(base, orig_base_flags, NULL); > + return; > } > --=20 > 1.8.3.1 >=20 >=20 Reviewed-by: Benoit Canet