From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7ms9-0000nM-Jc for qemu-devel@nongnu.org; Tue, 31 May 2016 12:50:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7ms7-0006bs-2S for qemu-devel@nongnu.org; Tue, 31 May 2016 12:50:28 -0400 References: <8E87729A-E996-4D12-B940-87B77C1D22EC@meituan.com> From: Eric Blake Message-ID: <574DC0CB.7020707@redhat.com> Date: Tue, 31 May 2016 10:50:19 -0600 MIME-Version: 1.0 In-Reply-To: <8E87729A-E996-4D12-B940-87B77C1D22EC@meituan.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8156Xu2lJ3sihwOhCOM1tFtfe5hwavlfn" Subject: Re: [Qemu-devel] [PATCH] qcow2 resize with snapshot List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: zhangzhiming , qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Kevin Wolf , Max Reitz , lihuiba This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --8156Xu2lJ3sihwOhCOM1tFtfe5hwavlfn Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/27/2016 02:14 AM, zhangzhiming wrote: > Hi, i modified my code for qcow2 resize, and delete some code related t= o=20 > qemu monitor. >=20 > and thanks for the review. >=20 > zhangzhiming > zhangzhiming02@meituan.com Still missing a Signed-off-by designation, so it can't be applied as-is. >=20 > --- > block.c | 19 +++++++++++++++++++ > block/qcow2-cluster.c | 29 +++++++++++++++++++++++++++++ > block/qcow2-snapshot.c | 34 ++++++++++++++++++++++++---------- > block/qcow2.c | 29 ++++++++++++++++++++--------- > block/qcow2.h | 1 + > include/block/snapshot.h | 1 + > 6 files changed, 94 insertions(+), 19 deletions(-) >=20 > diff --git a/block.c b/block.c > index 18a497f..729f820 100644 > --- a/block.c > +++ b/block.c > @@ -2631,6 +2631,25 @@ int bdrv_truncate(BlockDriverState *bs, int64_t = offset) > return ret; > } > =20 > +int bdrv_apply_snapshot(BlockDriverState *bs, const char *snapshot_id,= > + uint64_t snapshot_size) > +{ > + int ret =3D bdrv_snapshot_goto(bs, snapshot_id); > + if (ret < 0) { > + return ret; > + } > + > + ret =3D refresh_total_sectors(bs, snapshot_size >> BDRV_SECTOR_BIT= S); > + if (ret < 0) { > + return ret; > + } > + bdrv_dirty_bitmap_truncate(bs); /* void return */ > + if (bs->blk) { > + blk_dev_resize_cb(bs->blk); /* void return too */ The comments don't add anything here. > + } > + return ret; > +} > + > /** > * Length of a allocated file in bytes. Sparse files are counted by ac= tual > * allocated space. Return < 0 if error or unknown. > diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c > index 31ecc10..e4c5c05 100644 > --- a/block/qcow2-cluster.c > +++ b/block/qcow2-cluster.c > @@ -31,6 +31,35 @@ > #include "block/qcow2.h" > #include "trace.h" > =20 > +int shrink_l1_table(BlockDriverState *bs, int64_t new_l1_size) > +{ > + BDRVQcow2State *s =3D bs->opaque; > + int64_t old_l1_size =3D s->l1_size; > + s->l1_size =3D new_l1_size; > + int ret =3D qcow2_update_snapshot_refcount(bs, s->l1_table_offset,= > + s->l1_size, 1); Indentation is off. > + if (ret < 0) { > + return ret; > + } > + > + s->l1_size =3D old_l1_size; > + ret =3D qcow2_update_snapshot_refcount(bs, s->l1_table_offset, > + s->l1_size, -1); and again. > + if (ret < 0) { > + return ret; > + } > + s->l1_size =3D new_l1_size; > + > +++ b/block/qcow2-snapshot.c > @@ -552,10 +562,12 @@ int qcow2_snapshot_goto(BlockDriverState *bs, con= st char *snapshot_id) > * Now update the in-memory L1 table to be in sync with the on-dis= k one. We > * need to do this even if updating refcounts failed. > */ > - for(i =3D 0;i < s->l1_size; i++) { > + memset(s->l1_table, 0, s->l1_size*sizeof(uint64_t)); > + for(i =3D 0;i < sn->l1_size; i++) { As long as you are touching this, use the preferred spacing: for (i =3D 0; i < sn->l1_size; i++) { > s->l1_table[i] =3D be64_to_cpu(sn_l1_table[i]); > } > =20 > + > if (ret < 0) { Why the added blank line? > +++ b/block/qcow2.c > @@ -2501,22 +2501,33 @@ static int qcow2_truncate(BlockDriverState *bs,= int64_t offset) > return -EINVAL; > } > =20 > - /* cannot proceed if image has snapshots */ > - if (s->nb_snapshots) { > - error_report("Can't resize an image which has snapshots"); > + bool v3_truncate =3D (s->qcow_version =3D=3D 3); > + > + /* cannot proceed if image has snapshots and qcow_version is not 3= */ Space before */ > + if (!v3_truncate && s->nb_snapshots) { > + error_report("Can't resize an image which has snapshots and " > + "qcow_version is not 3"); > return -ENOTSUP; > } > =20 > - /* shrinking is currently not supported */ > - if (offset < bs->total_sectors * 512) { > - error_report("qcow2 doesn't support shrinking images yet"); > + /* shrinking is supported from version 3*/ and again > + if (!v3_truncate && offset < bs->total_sectors * 512) { > + error_report("qcow2 doesn't support shrinking images yet while= " > + " qcow_version is not 3"); > return -ENOTSUP; > } --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --8156Xu2lJ3sihwOhCOM1tFtfe5hwavlfn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXTcDLAAoJEKeha0olJ0NqFwsIAK6q2lLT9dQfGCa2h7+Mn0Ck tjCLw6BMtB5iW42NcnbzzWTBSr8r2yhgsZJzjnFer1FGL9+vTyTGSDsJ1DwE7ZO5 fF46iRx6BlN5kkr0wP8/Pubg+3I0+OuICdiBhehi8aQwHJwgit/xvH1XLt2Gffwj 8w91dsrSPuYEGZqYlWwAAIK3Po3/BzHlcrAQxFUkTbL1YqgHcPjXPdPZrsTleBY/ 6FUKmMZQtW4FfJbKPn/S0iE5muksA5FqPVqeK2+ny/J82zViPsdugPeLXUSALL3y Se363GB7BVJQBUpuPG7XnvMRMFaOfqvAMmMMg/LxZxsSOLZbOXJess51TMyf06s= =eaSm -----END PGP SIGNATURE----- --8156Xu2lJ3sihwOhCOM1tFtfe5hwavlfn--