Commit 6233b4a8 authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-01-26' into staging



nbd patches for 2018-01-26

- Vladimir Sementsov-Ogievskiy - nbd export qmp interface
- Eric Blake - hmp: Add nbd_server_remove to mirror QMP command
- Edgar Kaziakhmedov - nbd: implement bdrv_get_info callback

# gpg: Signature made Fri 26 Jan 2018 16:02:34 GMT
# gpg:                using RSA key 0xA7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>"
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>"
# gpg:                 aka "[jpeg image of size 6874]"
# Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2  F3AA A7A1 6B4A 2527 436A

* remotes/ericb/tags/pull-nbd-2018-01-26:
  nbd: implement bdrv_get_info callback
  hmp: Add nbd_server_remove to mirror QMP command
  iotest 205: new test for qmp nbd-server-remove
  iotests: implement QemuIoInteractive class
  iotest 147: add cases to test new @name parameter of nbd-server-add
  qapi: add nbd-server-remove
  hmp: Add name parameter to nbd_server_add
  qapi: add name parameter to nbd-server-add

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents e607bbee 9776f0db
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -566,6 +566,14 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
    bs->full_open_options = opts;
}

static int nbd_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
{
    if (bs->supported_zero_flags & BDRV_REQ_MAY_UNMAP) {
        bdi->can_write_zeroes_with_unmap = true;
    }
    return 0;
}

static BlockDriver bdrv_nbd = {
    .format_name                = "nbd",
    .protocol_name              = "nbd",
@@ -583,6 +591,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_get_info              = nbd_get_info,
};

static BlockDriver bdrv_nbd_tcp = {
@@ -602,6 +611,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_get_info              = nbd_get_info,
};

static BlockDriver bdrv_nbd_unix = {
@@ -621,6 +631,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_get_info              = nbd_get_info,
};

static void bdrv_nbd_init(void)
+33 −5
Original line number Diff line number Diff line
@@ -140,8 +140,8 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
    qapi_free_SocketAddress(addr_flat);
}

void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
                        Error **errp)
void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
                        bool has_writable, bool writable, Error **errp)
{
    BlockDriverState *bs = NULL;
    BlockBackend *on_eject_blk;
@@ -152,8 +152,12 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
        return;
    }

    if (nbd_export_find(device)) {
        error_setg(errp, "NBD server already exporting device '%s'", device);
    if (!has_name) {
        name = device;
    }

    if (nbd_export_find(name)) {
        error_setg(errp, "NBD server already has export named '%s'", name);
        return;
    }

@@ -177,7 +181,7 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
        return;
    }

    nbd_export_set_name(exp, device);
    nbd_export_set_name(exp, name);

    /* The list of named exports has a strong reference to this export now and
     * our only way of accessing it is through nbd_export_find(), so we can drop
@@ -185,6 +189,30 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
    nbd_export_put(exp);
}

void qmp_nbd_server_remove(const char *name,
                           bool has_mode, NbdServerRemoveMode mode,
                           Error **errp)
{
    NBDExport *exp;

    if (!nbd_server) {
        error_setg(errp, "NBD server not running");
        return;
    }

    exp = nbd_export_find(name);
    if (exp == NULL) {
        error_setg(errp, "Export '%s' is not found", name);
        return;
    }

    if (!has_mode) {
        mode = NBD_SERVER_REMOVE_MODE_SAFE;
    }

    nbd_export_remove(exp, mode, errp);
}

void qmp_nbd_server_stop(Error **errp)
{
    nbd_export_close_all();
+22 −4
Original line number Diff line number Diff line
@@ -1553,17 +1553,35 @@ ETEXI

    {
        .name       = "nbd_server_add",
        .args_type  = "writable:-w,device:B",
        .params     = "nbd_server_add [-w] device",
        .args_type  = "writable:-w,device:B,name:s?",
        .params     = "nbd_server_add [-w] device [name]",
        .help       = "export a block device via NBD",
        .cmd        = hmp_nbd_server_add,
    },
STEXI
@item nbd_server_add @var{device}
@item nbd_server_add @var{device} [ @var{name} ]
@findex nbd_server_add
Export a block device through QEMU's NBD server, which must be started
beforehand with @command{nbd_server_start}.  The @option{-w} option makes the
exported device writable too.
exported device writable too.  The export name is controlled by @var{name},
defaulting to @var{device}.
ETEXI

    {
        .name       = "nbd_server_remove",
        .args_type  = "force:-f,name:s",
        .params     = "nbd_server_remove [-f] name",
        .help       = "remove an export previously exposed via NBD",
        .cmd        = hmp_nbd_server_remove,
    },
STEXI
@item nbd_server_remove [-f] @var{name}
@findex nbd_server_remove
Stop exporting a block device through QEMU's NBD server, which was
previously started with @command{nbd_server_add}.  The @option{-f}
option forces the server to drop the export immediately even if
clients are connected; otherwise the command fails unless there are no
clients.
ETEXI

    {
+15 −5
Original line number Diff line number Diff line
@@ -2203,7 +2203,8 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
            continue;
        }

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

        if (local_err != NULL) {
            qmp_nbd_server_stop(NULL);
@@ -2220,14 +2221,23 @@ exit:
void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
{
    const char *device = qdict_get_str(qdict, "device");
    const char *name = qdict_get_try_str(qdict, "name");
    bool writable = qdict_get_try_bool(qdict, "writable", false);
    Error *local_err = NULL;

    qmp_nbd_server_add(device, true, writable, &local_err);

    if (local_err != NULL) {
    qmp_nbd_server_add(device, !!name, name, true, writable, &local_err);
    hmp_handle_error(mon, &local_err);
}

void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
{
    const char *name = qdict_get_str(qdict, "name");
    bool force = qdict_get_try_bool(qdict, "force", false);
    Error *err = NULL;

    /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
    qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
    hmp_handle_error(mon, &err);
}

void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
+1 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict);
void hmp_screendump(Monitor *mon, const QDict *qdict);
void hmp_nbd_server_start(Monitor *mon, const QDict *qdict);
void hmp_nbd_server_add(Monitor *mon, const QDict *qdict);
void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict);
void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
void hmp_chardev_add(Monitor *mon, const QDict *qdict);
void hmp_chardev_change(Monitor *mon, const QDict *qdict);
Loading