From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHv5p-00030l-BV for qemu-devel@nongnu.org; Thu, 14 Aug 2014 09:29:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHv5l-0000fu-1Z for qemu-devel@nongnu.org; Thu, 14 Aug 2014 09:29:25 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:36490 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHv5k-0000fq-Nx for qemu-devel@nongnu.org; Thu, 14 Aug 2014 09:29:20 -0400 Date: Thu, 14 Aug 2014 15:28:28 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140814132828.GL2009@irqsave.net> References: <1407950419-3486-1-git-send-email-pl@kamp.de> <1407950419-3486-3-git-send-email-pl@kamp.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1407950419-3486-3-git-send-email-pl@kamp.de> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCHv2 2/3] qemu-nbd: add option to set detect-zeroes mode List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven Cc: kwolf@redhat.com, hutao@cn.fujitsu.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, armbru@redhat.com The Wednesday 13 Aug 2014 =E0 19:20:18 (+0200), Peter Lieven wrote : > Signed-off-by: Peter Lieven > Reviewed-by: Eric Blake > --- > qemu-nbd.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) >=20 > diff --git a/qemu-nbd.c b/qemu-nbd.c > index 626e584..6ef8b10 100644 > --- a/qemu-nbd.c > +++ b/qemu-nbd.c > @@ -18,11 +18,13 @@ > =20 > #include "qemu-common.h" > #include "block/block.h" > +#include "block/block_int.h" > #include "block/nbd.h" > #include "qemu/main-loop.h" > #include "qemu/sockets.h" > #include "qemu/error-report.h" > #include "block/snapshot.h" > +#include "qapi/util.h" > =20 > #include > #include > @@ -41,6 +43,7 @@ > #define QEMU_NBD_OPT_CACHE 1 > #define QEMU_NBD_OPT_AIO 2 > #define QEMU_NBD_OPT_DISCARD 3 > +#define QEMU_NBD_OPT_DETECT_ZEROES 4 > =20 > static NBDExport *exp; > static int verbose; > @@ -96,6 +99,8 @@ static void usage(const char *name) > #ifdef CONFIG_LINUX_AIO > " --aio=3DMODE set AIO mode (native or threads)\n" > #endif > +" --discard=3DMODE set discard mode (ignore, unmap)\n" > +" --detect-zeroes=3DMODE set detect-zeroes mode (off, on, discar= d)\n" > "\n" > "Report bugs to \n" > , name, NBD_DEFAULT_PORT, "DEVICE"); > @@ -410,6 +415,7 @@ int main(int argc, char **argv) > { "aio", 1, NULL, QEMU_NBD_OPT_AIO }, > #endif > { "discard", 1, NULL, QEMU_NBD_OPT_DISCARD }, > + { "detect-zeroes", 1, NULL, QEMU_NBD_OPT_DETECT_ZEROES }, > { "shared", 1, NULL, 'e' }, > { "format", 1, NULL, 'f' }, > { "persistent", 0, NULL, 't' }, > @@ -432,6 +438,7 @@ int main(int argc, char **argv) > pthread_t client_thread; > const char *fmt =3D NULL; > Error *local_err =3D NULL; > + BlockdevDetectZeroesOptions detect_zeroes =3D BLOCKDEV_DETECT_ZERO= ES_OPTIONS_OFF; > =20 > /* The client thread uses SIGTERM to interrupt the server. A sign= al > * handler ensures that "qemu-nbd -v -c" exits with a nice status = code. > @@ -483,6 +490,23 @@ int main(int argc, char **argv) > errx(EXIT_FAILURE, "Invalid discard mode `%s'", optarg= ); > } > break; > + case QEMU_NBD_OPT_DETECT_ZEROES: > + detect_zeroes =3D > + qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, > + optarg, > + BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX, > + BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, > + &local_err); > + if (local_err) { > + errx(EXIT_FAILURE, "Failed to parse detect_zeroes mode= : %s",=20 > + error_get_pretty(local_err)); > + } > + if (detect_zeroes =3D=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_UN= MAP && > + !(flags & BDRV_O_UNMAP)) { > + errx(EXIT_FAILURE, "setting detect-zeroes to unmap is = not allowed " > + "without setting discard operation = to unmap");=20 > + } > + break; > case 'b': > bindto =3D optarg; > break; > @@ -686,6 +710,7 @@ int main(int argc, char **argv) > error_get_pretty(local_err)); > } > =20 > + bs->detect_zeroes =3D detect_zeroes; > fd_size =3D bdrv_getlength(bs); > =20 > if (partition !=3D -1) { > --=20 > 1.7.9.5 >=20 >=20 Reviewed-by: Benoit Canet