Commit f4b5b021 authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging



# gpg: Signature made Mon 24 Apr 2017 20:18:05 BST
# gpg:                using RSA key 0xBDBE7B27C0DE3057
# gpg: Good signature from "Jeffrey Cody <jcody@redhat.com>"
# gpg:                 aka "Jeffrey Cody <jeff@codyprime.org>"
# gpg:                 aka "Jeffrey Cody <codyprime@gmail.com>"
# Primary key fingerprint: 9957 4B4D 3474 90E7 9D98  D624 BDBE 7B27 C0DE 3057

* remotes/cody/tags/block-pull-request:
  qemu-iotests: _cleanup_qemu must be called on exit
  block/rbd: Add support for reopen()
  block/rbd - update variable names to more apt names
  block: use bdrv_can_set_read_only() during reopen
  block: introduce bdrv_can_set_read_only()
  block: code movement
  block: honor BDRV_O_ALLOW_RDWR when clearing bs->read_only
  block: do not set BDS read_only if copy_on_read enabled
  block: add bdrv_set_read_only() helper function
  qemu-iotests: exclude vxhs from image creation via protocol
  block/vxhs.c: Add qemu-iotests for new block device type "vxhs"
  block/vxhs.c: Add support for a new block device type called "vxhs"

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents eab1e53c ecfa1854
Loading
Loading
Loading
Loading
+45 −11
Original line number Diff line number Diff line
@@ -192,6 +192,43 @@ void path_combine(char *dest, int dest_size,
    }
}

bool bdrv_is_read_only(BlockDriverState *bs)
{
    return bs->read_only;
}

int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
{
    /* Do not set read_only if copy_on_read is enabled */
    if (bs->copy_on_read && read_only) {
        error_setg(errp, "Can't set node '%s' to r/o with copy-on-read enabled",
                   bdrv_get_device_or_node_name(bs));
        return -EINVAL;
    }

    /* Do not clear read_only if it is prohibited */
    if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR)) {
        error_setg(errp, "Node '%s' is read only",
                   bdrv_get_device_or_node_name(bs));
        return -EPERM;
    }

    return 0;
}

int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
{
    int ret = 0;

    ret = bdrv_can_set_read_only(bs, read_only, errp);
    if (ret < 0) {
        return ret;
    }

    bs->read_only = read_only;
    return 0;
}

void bdrv_get_full_backing_filename_from_filename(const char *backed,
                                                  const char *backing,
                                                  char *dest, size_t sz,
@@ -2752,6 +2789,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
    BlockDriver *drv;
    QemuOpts *opts;
    const char *value;
    bool read_only;

    assert(reopen_state != NULL);
    assert(reopen_state->bs->drv != NULL);
@@ -2780,12 +2818,13 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
        qdict_put(reopen_state->options, "driver", qstring_from_str(value));
    }

    /* if we are to stay read-only, do not allow permission change
     * to r/w */
    if (!(reopen_state->bs->open_flags & BDRV_O_ALLOW_RDWR) &&
        reopen_state->flags & BDRV_O_RDWR) {
        error_setg(errp, "Node '%s' is read only",
                   bdrv_get_device_or_node_name(reopen_state->bs));
    /* If we are to stay read-only, do not allow permission change
     * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is
     * not set, or if the BDS still has copy_on_read enabled */
    read_only = !(reopen_state->flags & BDRV_O_RDWR);
    ret = bdrv_can_set_read_only(reopen_state->bs, read_only, &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
        goto error;
    }

@@ -3355,11 +3394,6 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr)
    *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
}

bool bdrv_is_read_only(BlockDriverState *bs)
{
    return bs->read_only;
}

bool bdrv_is_sg(BlockDriverState *bs)
{
    return bs->sg;
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ block-obj-$(CONFIG_LIBNFS) += nfs.o
block-obj-$(CONFIG_CURL) += curl.o
block-obj-$(CONFIG_RBD) += rbd.o
block-obj-$(CONFIG_GLUSTERFS) += gluster.o
block-obj-$(CONFIG_VXHS) += vxhs.o
block-obj-$(CONFIG_LIBSSH2) += ssh.o
block-obj-y += accounting.o dirty-bitmap.o
block-obj-y += write-threshold.o
@@ -38,6 +39,7 @@ rbd.o-cflags := $(RBD_CFLAGS)
rbd.o-libs         := $(RBD_LIBS)
gluster.o-cflags   := $(GLUSTERFS_CFLAGS)
gluster.o-libs     := $(GLUSTERFS_LIBS)
vxhs.o-libs        := $(VXHS_LIBS)
ssh.o-cflags       := $(LIBSSH2_CFLAGS)
ssh.o-libs         := $(LIBSSH2_LIBS)
block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o
+4 −1
Original line number Diff line number Diff line
@@ -110,7 +110,10 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
        return -EINVAL;
    }

    bs->read_only = true; /* no write support yet */
    ret = bdrv_set_read_only(bs, true, errp); /* no write support yet */
    if (ret < 0) {
        return ret;
    }

    ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs));
    if (ret < 0) {
+4 −1
Original line number Diff line number Diff line
@@ -72,7 +72,10 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
        return -EINVAL;
    }

    bs->read_only = true;
    ret = bdrv_set_read_only(bs, true, errp);
    if (ret < 0) {
        return ret;
    }

    /* read header */
    ret = bdrv_pread(bs->file, 128, &s->block_size, 4);
+5 −1
Original line number Diff line number Diff line
@@ -419,8 +419,12 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
        return -EINVAL;
    }

    ret = bdrv_set_read_only(bs, true, errp);
    if (ret < 0) {
        return ret;
    }

    block_module_load_one("dmg-bz2");
    bs->read_only = true;

    s->n_chunks = 0;
    s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL;
Loading