Commit 5b7686f3 authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2020-02-06' into staging



nbd patches for 2020-02-06

- Allow setting NBD description from QMP for parity with qemu-nbd
- Remove deprecated 'qemu-nbd --partition'

# gpg: Signature made Thu 06 Feb 2020 12:50:46 GMT
# gpg:                using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full]
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full]
# gpg:                 aka "[jpeg image of size 6874]" [full]
# Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2  F3AA A7A1 6B4A 2527 436A

* remotes/ericb/tags/pull-nbd-2020-02-06:
  qemu-nbd: Removed deprecated --partition option
  docs: Fix typo in qemu-nbd -P replacement
  nbd: Allow description when creating NBD blockdev

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 863d2ed5 0bc16997
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
}

void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
                        bool has_description, const char *description,
                        bool has_writable, bool writable,
                        bool has_bitmap, const char *bitmap, Error **errp)
{
@@ -167,6 +168,11 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
        return;
    }

    if (has_description && strlen(description) > NBD_MAX_STRING_SIZE) {
        error_setg(errp, "description '%s' too long", description);
        return;
    }

    if (nbd_export_find(name)) {
        error_setg(errp, "NBD server already has export named '%s'", name);
        return;
@@ -195,7 +201,8 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
        writable = false;
    }

    exp = nbd_export_new(bs, 0, len, name, NULL, bitmap, !writable, !writable,
    exp = nbd_export_new(bs, 0, len, name, description, bitmap,
                         !writable, !writable,
                         NULL, false, on_eject_blk, errp);
    if (!exp) {
        goto out;
+4 −11
Original line number Diff line number Diff line
@@ -72,13 +72,6 @@ driver options if ``--image-opts`` is specified.

  Export the disk as read-only.

.. option:: -P, --partition=NUM

  Deprecated: Only expose MBR partition *NUM*.  Understands physical
  partitions 1-4 and logical partition 5. New code should instead use
  :option:`--image-opts` with the raw driver wrapping a subset of the
  original image.

.. option:: -B, --bitmap=NAME

  If *filename* has a qcow2 persistent bitmap *NAME*, expose
@@ -224,14 +217,14 @@ a 1 megabyte subset of a raw file, using the export name 'subset':
    -t -x subset -p 10810 \
    --image-opts driver=raw,offset=1M,size=1M,file.driver=file,file.filename=file.raw

Serve a read-only copy of just the first MBR partition of a guest
image over a Unix socket with as many as 5 simultaneous readers, with
a persistent process forked as a daemon:
Serve a read-only copy of a guest image over a Unix socket with as
many as 5 simultaneous readers, with a persistent process forked as a
daemon:

::

  qemu-nbd --fork --persistent --shared=5 --socket=/path/to/sock \
    --partition=1 --read-only --format=qcow2 file.qcow2
    --read-only --format=qcow2 file.qcow2

Expose the guest-visible contents of a qcow2 file via a block device
/dev/nbd0 (and possibly creating /dev/nbd0p1 and friends for
+2 −2
Original line number Diff line number Diff line
@@ -2351,7 +2351,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
            continue;
        }

        qmp_nbd_server_add(info->value->device, false, NULL,
        qmp_nbd_server_add(info->value->device, false, NULL, false, NULL,
                           true, writable, false, NULL, &local_err);

        if (local_err != NULL) {
@@ -2373,7 +2373,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
    bool writable = qdict_get_try_bool(qdict, "writable", false);
    Error *local_err = NULL;

    qmp_nbd_server_add(device, !!name, name, true, writable,
    qmp_nbd_server_add(device, !!name, name, false, NULL, true, writable,
                       false, NULL, &local_err);
    hmp_handle_error(mon, local_err);
}
+6 −3
Original line number Diff line number Diff line
@@ -250,9 +250,12 @@
# @name: Export name. If unspecified, the @device parameter is used as the
#        export name. (Since 2.12)
#
# @description: Free-form description of the export, up to 4096 bytes.
#               (Since 5.0)
#
# @writable: Whether clients should be able to write to the device via the
#     NBD connection (default false).

#
# @bitmap: Also export the dirty bitmap reachable from @device, so the
#          NBD client can use NBD_OPT_SET_META_CONTEXT with
#          "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0)
@@ -263,8 +266,8 @@
# Since: 1.3.0
##
{ 'command': 'nbd-server-add',
  'data': {'device': 'str', '*name': 'str', '*writable': 'bool',
           '*bitmap': 'str' } }
  'data': {'device': 'str', '*name': 'str', '*description': 'str',
           '*writable': 'bool', '*bitmap': 'str' } }

##
# @NbdServerRemoveMode:
+18 −31
Original line number Diff line number Diff line
@@ -313,37 +313,6 @@ The above, converted to the current supported format:

@section Related binaries

@subsection qemu-nbd --partition (since 4.0.0)

The ``qemu-nbd --partition $digit'' code (also spelled @option{-P})
can only handle MBR partitions, and has never correctly handled
logical partitions beyond partition 5.  If you know the offset and
length of the partition (perhaps by using @code{sfdisk} within the
guest), you can achieve the effect of exporting just that subset of
the disk by use of the @option{--image-opts} option with a raw
blockdev using the @code{offset} and @code{size} parameters layered on
top of any other existing blockdev. For example, if partition 1 is
100MiB long starting at 1MiB, the old command:

@code{qemu-nbd -t -P 1 -f qcow2 file.qcow2}

can be rewritten as:

@code{qemu-nbd -t --image-opts driver=raw,offset=1M,size=100M,file.driver=qcow2,file.backing.driver=file,file.backing.filename=file.qcow2}

Alternatively, the @code{nbdkit} project provides a more powerful
partition filter on top of its nbd plugin, which can be used to select
an arbitrary MBR or GPT partition on top of any other full-image NBD
export.  Using this to rewrite the above example results in:

@code{qemu-nbd -t -k /tmp/sock -f qcow2 file.qcow2 &}
@code{nbdkit -f --filter=partition nbd socket=/tmp/sock partition=1}

Note that if you are exposing the export via /dev/nbd0, it is easier
to just export the entire image and then mount only /dev/nbd0p1 than
it is to reinvoke @command{qemu-nbd -c /dev/nbd0} limited to just a
subset of the image.

@subsection qemu-img convert -n -o (since 4.2.0)

All options specified in @option{-o} are image creation options, so
@@ -400,3 +369,21 @@ trouble after a recent upgrade.

The "autoload" parameter has been ignored since 2.12.0. All bitmaps
are automatically loaded from qcow2 images.

@section Related binaries

@subsection qemu-nbd --partition (removed in 5.0.0)

The ``qemu-nbd --partition $digit'' code (also spelled @option{-P})
could only handle MBR partitions, and never correctly handled logical
partitions beyond partition 5.  Exporting a partition can still be
done by utilizing the @option{--image-opts} option with a raw blockdev
using the @code{offset} and @code{size} parameters layered on top of
any other existing blockdev. For example, if partition 1 is 100MiB
long starting at 1MiB, the old command:

@code{qemu-nbd -t -P 1 -f qcow2 file.qcow2}

can be rewritten as:

@code{qemu-nbd -t --image-opts driver=raw,offset=1M,size=100M,file.driver=qcow2,file.file.driver=file,file.file.filename=file.qcow2}
Loading