Skip to contentSkip to conversation

nbd: add zero-init parameter

PATCH In review Denis V. Lunev 3 participants 3 messages Oct 5, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nbd: add zero-init parameter

When using a nbd block device, the info about necessity of prior disk zeroing could significantly improve the speed of certain operations (e.g. backups).

This patch also will allow to preserve QCOW2 images during migration. Management software now may specify zero-init option and thus abscent areas in the original QCOW2 image will not be marked as zeroes in the target image. This is tight distiction but it is here.

CC Paolo Bonzini <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
---
 block/nbd.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
block/nbd.c +21 -0
index 6bc06d6..eed06d1 100644
@@ -45,6 +45,7 @@ typedef struct BDRVNBDState {
 
     /* For nbd_refresh_filename() */
     char *path, *host, *port, *export, *tlscredsid;
+    bool zero_init;
 } BDRVNBDState;
 
 static int nbd_parse_uri(const char *filename, QDict *options)
@@ -194,6 +195,7 @@ out:
 static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp)
 {
     SocketAddress *saddr;
+    const char *zero_init;
 
     s->path = g_strdup(qemu_opt_get(opts, "path"));
     s->host = g_strdup(qemu_opt_get(opts, "host"));
@@ -232,6 +234,11 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp)
 
     s->export = g_strdup(qemu_opt_get(opts, "export"));
 
+    zero_init = qemu_opt_get(opts, "zero-init");
+    if (zero_init != NULL) {
+        s->zero_init = strcmp(zero_init, "on") == 0;
+    }
+
     return saddr;
 }
 
@@ -322,6 +329,11 @@ static QemuOptsList nbd_runtime_opts = {
             .type = QEMU_OPT_STRING,
             .help = "ID of the TLS credentials to use",
         },
+        {
+            .name = "zero-init",
+            .type = QEMU_OPT_BOOL,
+            .help = "Zero-initialized image flag",
+        },
     },
 };
 
@@ -483,6 +495,12 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
     bs->full_open_options = opts;
 }
 
+static int nbd_has_zero_init(BlockDriverState *bs)
+{
+    BDRVNBDState *s = bs->opaque;
+    return s->zero_init;
+}
+
 static BlockDriver bdrv_nbd = {
     .format_name                = "nbd",
     .protocol_name              = "nbd",
@@ -499,6 +517,7 @@ static BlockDriver bdrv_nbd = {
     .bdrv_detach_aio_context    = nbd_detach_aio_context,
     .bdrv_attach_aio_context    = nbd_attach_aio_context,
     .bdrv_refresh_filename      = nbd_refresh_filename,
+    .bdrv_has_zero_init         = nbd_has_zero_init,
 };
 
 static BlockDriver bdrv_nbd_tcp = {
@@ -517,6 +536,7 @@ static BlockDriver bdrv_nbd_tcp = {
     .bdrv_detach_aio_context    = nbd_detach_aio_context,
     .bdrv_attach_aio_context    = nbd_attach_aio_context,
     .bdrv_refresh_filename      = nbd_refresh_filename,
+    .bdrv_has_zero_init         = nbd_has_zero_init,
 };
 
 static BlockDriver bdrv_nbd_unix = {
@@ -535,6 +555,7 @@ static BlockDriver bdrv_nbd_unix = {
     .bdrv_detach_aio_context    = nbd_detach_aio_context,
     .bdrv_attach_aio_context    = nbd_attach_aio_context,
     .bdrv_refresh_filename      = nbd_refresh_filename,
+    .bdrv_has_zero_init         = nbd_has_zero_init,
 };
 
 static void bdrv_nbd_init(void)
Signature · 1 line
2.5.0
#1 lore raw

Am 05.10.2016 um 12:57 hat Denis V. Lunev geschrieben:

Quoted 38 lines

When using a nbd block device, the info about necessity of prior disk zeroing could significantly improve the speed of certain operations (e.g. backups).

This patch also will allow to preserve QCOW2 images during migration. Management software now may specify zero-init option and thus abscent areas in the original QCOW2 image will not be marked as zeroes in the target image. This is tight distiction but it is here.

CC Paolo Bonzini <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
---
 block/nbd.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
block/nbd.c +2 -0
index 6bc06d6..eed06d1 100644
@@ -45,6 +45,7 @@ typedef struct BDRVNBDState {
 
     /* For nbd_refresh_filename() */
     char *path, *host, *port, *export, *tlscredsid;
+    bool zero_init;
 } BDRVNBDState;
 
 static int nbd_parse_uri(const char *filename, QDict *options)
@@ -194,6 +195,7 @@ out:
 static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp)
 {
     SocketAddress *saddr;
+    const char *zero_init;
 
     s->path = g_strdup(qemu_opt_get(opts, "path"));
     s->host = g_strdup(qemu_opt_get(opts, "host"));

block/nbd.c static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp) · line 240

Quoted 7 lines
block/nbd.c +4 -0
@@ -232,6 +234,11 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp)
 
     s->export = g_strdup(qemu_opt_get(opts, "export"));
 
+    zero_init = qemu_opt_get(opts, "zero-init");
+    if (zero_init != NULL) {
+        s->zero_init = strcmp(zero_init, "on") == 0;
+    }

We don't need a local char* zero_init and parse it manually:

    s->zero_init = qemu_opt_get_bool(opts, "zero-init", false);

Much easier.

block/nbd.c static QemuOptsList nbd_runtime_opts = { · line 335

Quoted 12 lines
block/nbd.c +5 -0
+
     return saddr;
 }
 
@@ -322,6 +329,11 @@ static QemuOptsList nbd_runtime_opts = {
             .type = QEMU_OPT_STRING,
             .help = "ID of the TLS credentials to use",
         },
+        {
+            .name = "zero-init",
+            .type = QEMU_OPT_BOOL,
+            .help = "Zero-initialized image flag",

We can be a bit more descriptive here:

"If enabled, assume the image to be completely zeroed on startup"

(Or maybe you can think of something better than that.)

Quoted 34 lines
block/nbd.c +9 -0
+        },
     },
 };
 
@@ -483,6 +495,12 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
     bs->full_open_options = opts;
 }
 
+static int nbd_has_zero_init(BlockDriverState *bs)
+{
+    BDRVNBDState *s = bs->opaque;
+    return s->zero_init;
+}
+
 static BlockDriver bdrv_nbd = {
     .format_name                = "nbd",
     .protocol_name              = "nbd",
@@ -499,6 +517,7 @@ static BlockDriver bdrv_nbd = {
     .bdrv_detach_aio_context    = nbd_detach_aio_context,
     .bdrv_attach_aio_context    = nbd_attach_aio_context,
     .bdrv_refresh_filename      = nbd_refresh_filename,
+    .bdrv_has_zero_init         = nbd_has_zero_init,
 };
 
 static BlockDriver bdrv_nbd_tcp = {
@@ -517,6 +536,7 @@ static BlockDriver bdrv_nbd_tcp = {
     .bdrv_detach_aio_context    = nbd_detach_aio_context,
     .bdrv_attach_aio_context    = nbd_attach_aio_context,
     .bdrv_refresh_filename      = nbd_refresh_filename,
+    .bdrv_has_zero_init         = nbd_has_zero_init,
 };
 
 static BlockDriver bdrv_nbd_unix = {

block/nbd.c static BlockDriver bdrv_nbd_unix = { · line 559

Quoted 5 lines
block/nbd.c +1 -0
@@ -535,6 +555,7 @@ static BlockDriver bdrv_nbd_unix = {
     .bdrv_detach_aio_context    = nbd_detach_aio_context,
     .bdrv_attach_aio_context    = nbd_attach_aio_context,
     .bdrv_refresh_filename      = nbd_refresh_filename,
+    .bdrv_has_zero_init         = nbd_has_zero_init,
 };

I believe nbd_refresh_filename() needs an update, too.

Kevin

#2 lore raw
In reply to Denis V. Lunev
Quoted 5 lines · Denis V. Lunev

When using a nbd block device, the info about necessity of prior disk zeroing could significantly improve the speed of certain operations (e.g. backups).

This patch also will allow to preserve QCOW2 images during migration.

'allow to' is not idiomatic English; and your placement of 'also' before 'will' is awkward. You want either of:

This patch will also allow preservation of QCOW2 images... This patch will also preserve QCOW2 images...

Quoted 1 line

Management software now may specify zero-init option and thus abscent

s/now may/may now/
s/abscent/absent/

Quoted 2 lines

areas in the original QCOW2 image will not be marked as zeroes in the target image. This is tight distiction but it is here.

s/distiction/distinction/

Quoted 11 lines
CC Paolo Bonzini <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
---
 block/nbd.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

block/nbd.c static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp) · line 239

Quoted 6 lines
block/nbd.c +3 -0
@@ -232,6 +234,11 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp)
 
     s->export = g_strdup(qemu_opt_get(opts, "export"));
 
+    zero_init = qemu_opt_get(opts, "zero-init");
+    if (zero_init != NULL) {
+        s->zero_init = strcmp(zero_init, "on") == 0;

As Kevin pointed out, a manual parse makes the command line less consistent; reusing the common parser also means that you will support things like zero-init=true for free.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org