From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149278286951133.44406406455107; Fri, 21 Apr 2017 06:54:29 -0700 (PDT) Received: from localhost ([::1]:59782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Z11-0002Y1-G9 for importer@patchew.org; Fri, 21 Apr 2017 09:54:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Ytp-00050g-Ah for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytj-0002QR-7Y for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytb-0002Nq-RK; Fri, 21 Apr 2017 09:46:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0F7CA7553; Fri, 21 Apr 2017 13:46:46 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D536AC6D4; Fri, 21 Apr 2017 13:46:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B0F7CA7553 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B0F7CA7553 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:33 -0400 Message-Id: <20170421134644.10239-2-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Apr 2017 13:46:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/12] block/vxhs.c: Add support for a new block device type called "vxhs" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, Ashish Mittal , qemu-devel@nongnu.org, Ashish Mittal Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ashish Mittal Source code for the qnio library that this code loads can be downloaded fro= m: https://github.com/VeritasHyperScale/libqnio.git Sample command line using JSON syntax: ./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0= :0 -k en-us -vga cirrus -device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,a= ddr=3D0x5 -msg timestamp=3Don 'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", "server":{"host":"172.172.17.4","port":"9999"}}' Sample command line using URI syntax: qemu-img convert -f raw -O raw -n /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0 Sample command line using TLS credentials (run in secure mode): ./qemu-io --object tls-creds-x509,id=3Dtls0,dir=3D/etc/pki/qemu/vxhs,endpoint=3Dclient -c 'read -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}' Signed-off-by: Ashish Mittal Reviewed-by: Stefan Hajnoczi Reviewed-by: Jeff Cody Signed-off-by: Jeff Cody Message-id: 1491277689-24949-2-git-send-email-Ashish.Mittal@veritas.com --- block/Makefile.objs | 2 + block/trace-events | 17 ++ block/vxhs.c | 575 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ configure | 39 ++++ qapi/block-core.json | 23 ++- 5 files changed, 654 insertions(+), 2 deletions(-) create mode 100644 block/vxhs.c diff --git a/block/Makefile.objs b/block/Makefile.objs index de96f8e..ea95530 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -19,6 +19,7 @@ block-obj-$(CONFIG_LIBNFS) +=3D nfs.o block-obj-$(CONFIG_CURL) +=3D curl.o block-obj-$(CONFIG_RBD) +=3D rbd.o block-obj-$(CONFIG_GLUSTERFS) +=3D gluster.o +block-obj-$(CONFIG_VXHS) +=3D vxhs.o block-obj-$(CONFIG_LIBSSH2) +=3D ssh.o block-obj-y +=3D accounting.o dirty-bitmap.o block-obj-y +=3D write-threshold.o @@ -38,6 +39,7 @@ rbd.o-cflags :=3D $(RBD_CFLAGS) rbd.o-libs :=3D $(RBD_LIBS) gluster.o-cflags :=3D $(GLUSTERFS_CFLAGS) gluster.o-libs :=3D $(GLUSTERFS_LIBS) +vxhs.o-libs :=3D $(VXHS_LIBS) ssh.o-cflags :=3D $(LIBSSH2_CFLAGS) ssh.o-libs :=3D $(LIBSSH2_LIBS) block-obj-$(if $(CONFIG_BZIP2),m,n) +=3D dmg-bz2.o diff --git a/block/trace-events b/block/trace-events index 0bc5c0a..7758ec3 100644 --- a/block/trace-events +++ b/block/trace-events @@ -110,3 +110,20 @@ qed_aio_write_data(void *s, void *acb, int ret, uint64= _t offset, size_t len) "s qed_aio_write_prefill(void *s, void *acb, uint64_t start, size_t len, uint= 64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64 qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uin= t64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64 qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t le= n) "s %p acb %p ret %d offset %"PRIu64" len %zu" + +# block/vxhs.c +vxhs_iio_callback(int error) "ctx is NULL: error %d" +vxhs_iio_callback_chnfail(int err, int error) "QNIO channel failed, no i/o= %d, %d" +vxhs_iio_callback_unknwn(int opcode, int err) "unexpected opcode %d, errno= %d" +vxhs_aio_rw_invalid(int req) "Invalid I/O request iodir %d" +vxhs_aio_rw_ioerr(char *guid, int iodir, uint64_t size, uint64_t off, void= *acb, int ret, int err) "IO ERROR (vDisk %s) FOR : Read/Write =3D %d size = =3D %lu offset =3D %lu ACB =3D %p. Error =3D %d, errno =3D %d" +vxhs_get_vdisk_stat_err(char *guid, int ret, int err) "vDisk (%s) stat ioc= tl failed, ret =3D %d, errno =3D %d" +vxhs_get_vdisk_stat(char *vdisk_guid, uint64_t vdisk_size) "vDisk %s stat = ioctl returned size %lu" +vxhs_complete_aio(void *acb, uint64_t ret) "aio failed acb %p ret %ld" +vxhs_parse_uri_filename(const char *filename) "URI passed via bdrv_parse_f= ilename %s" +vxhs_open_vdiskid(const char *vdisk_id) "Opening vdisk-id %s" +vxhs_open_hostinfo(char *of_vsa_addr, int port) "Adding host %s:%d to BDRV= VXHSState" +vxhs_open_iio_open(const char *host) "Failed to connect to storage agent o= n host %s" +vxhs_parse_uri_hostinfo(char *host, int port) "Host: IP %s, Port %d" +vxhs_close(char *vdisk_guid) "Closing vdisk %s" +vxhs_get_creds(const char *cacert, const char *client_key, const char *cli= ent_cert) "cacert %s, client_key %s, client_cert %s" diff --git a/block/vxhs.c b/block/vxhs.c new file mode 100644 index 0000000..9ffe9d3 --- /dev/null +++ b/block/vxhs.c @@ -0,0 +1,575 @@ +/* + * QEMU Block driver for Veritas HyperScale (VxHS) + * + * Copyright (c) 2017 Veritas Technologies LLC. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include +#include +#include "block/block_int.h" +#include "qapi/qmp/qerror.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "trace.h" +#include "qemu/uri.h" +#include "qapi/error.h" +#include "qemu/uuid.h" +#include "crypto/tlscredsx509.h" + +#define VXHS_OPT_FILENAME "filename" +#define VXHS_OPT_VDISK_ID "vdisk-id" +#define VXHS_OPT_SERVER "server" +#define VXHS_OPT_HOST "host" +#define VXHS_OPT_PORT "port" + +/* Only accessed under QEMU global mutex */ +static uint32_t vxhs_ref; + +typedef enum { + VDISK_AIO_READ, + VDISK_AIO_WRITE, +} VDISKAIOCmd; + +/* + * HyperScale AIO callbacks structure + */ +typedef struct VXHSAIOCB { + BlockAIOCB common; + int err; +} VXHSAIOCB; + +typedef struct VXHSvDiskHostsInfo { + void *dev_handle; /* Device handle */ + char *host; /* Host name or IP */ + int port; /* Host's port number */ +} VXHSvDiskHostsInfo; + +/* + * Structure per vDisk maintained for state + */ +typedef struct BDRVVXHSState { + VXHSvDiskHostsInfo vdisk_hostinfo; /* Per host info */ + char *vdisk_guid; + char *tlscredsid; /* tlscredsid */ +} BDRVVXHSState; + +static void vxhs_complete_aio_bh(void *opaque) +{ + VXHSAIOCB *acb =3D opaque; + BlockCompletionFunc *cb =3D acb->common.cb; + void *cb_opaque =3D acb->common.opaque; + int ret =3D 0; + + if (acb->err !=3D 0) { + trace_vxhs_complete_aio(acb, acb->err); + ret =3D (-EIO); + } + + qemu_aio_unref(acb); + cb(cb_opaque, ret); +} + +/* + * Called from a libqnio thread + */ +static void vxhs_iio_callback(void *ctx, uint32_t opcode, uint32_t error) +{ + VXHSAIOCB *acb =3D NULL; + + switch (opcode) { + case IRP_READ_REQUEST: + case IRP_WRITE_REQUEST: + + /* + * ctx is VXHSAIOCB* + * ctx is NULL if error is QNIOERROR_CHANNEL_HUP + */ + if (ctx) { + acb =3D ctx; + } else { + trace_vxhs_iio_callback(error); + goto out; + } + + if (error) { + if (!acb->err) { + acb->err =3D error; + } + trace_vxhs_iio_callback(error); + } + + aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), + vxhs_complete_aio_bh, acb); + break; + + default: + if (error =3D=3D QNIOERROR_HUP) { + /* + * Channel failed, spontaneous notification, + * not in response to I/O + */ + trace_vxhs_iio_callback_chnfail(error, errno); + } else { + trace_vxhs_iio_callback_unknwn(opcode, error); + } + break; + } +out: + return; +} + +static QemuOptsList runtime_opts =3D { + .name =3D "vxhs", + .head =3D QTAILQ_HEAD_INITIALIZER(runtime_opts.head), + .desc =3D { + { + .name =3D VXHS_OPT_FILENAME, + .type =3D QEMU_OPT_STRING, + .help =3D "URI to the Veritas HyperScale image", + }, + { + .name =3D VXHS_OPT_VDISK_ID, + .type =3D QEMU_OPT_STRING, + .help =3D "UUID of the VxHS vdisk", + }, + { + .name =3D "tls-creds", + .type =3D QEMU_OPT_STRING, + .help =3D "ID of the TLS/SSL credentials to use", + }, + { /* end of list */ } + }, +}; + +static QemuOptsList runtime_tcp_opts =3D { + .name =3D "vxhs_tcp", + .head =3D QTAILQ_HEAD_INITIALIZER(runtime_tcp_opts.head), + .desc =3D { + { + .name =3D VXHS_OPT_HOST, + .type =3D QEMU_OPT_STRING, + .help =3D "host address (ipv4 addresses)", + }, + { + .name =3D VXHS_OPT_PORT, + .type =3D QEMU_OPT_NUMBER, + .help =3D "port number on which VxHSD is listening (default 99= 99)", + .def_value_str =3D "9999" + }, + { /* end of list */ } + }, +}; + +/* + * Parse incoming URI and populate *options with the host + * and device information + */ +static int vxhs_parse_uri(const char *filename, QDict *options) +{ + URI *uri =3D NULL; + char *port; + int ret =3D 0; + + trace_vxhs_parse_uri_filename(filename); + uri =3D uri_parse(filename); + if (!uri || !uri->server || !uri->path) { + uri_free(uri); + return -EINVAL; + } + + qdict_put(options, VXHS_OPT_SERVER".host", qstring_from_str(uri->serve= r)); + + if (uri->port) { + port =3D g_strdup_printf("%d", uri->port); + qdict_put(options, VXHS_OPT_SERVER".port", qstring_from_str(port)); + g_free(port); + } + + qdict_put(options, "vdisk-id", qstring_from_str(uri->path)); + + trace_vxhs_parse_uri_hostinfo(uri->server, uri->port); + uri_free(uri); + + return ret; +} + +static void vxhs_parse_filename(const char *filename, QDict *options, + Error **errp) +{ + if (qdict_haskey(options, "vdisk-id") || qdict_haskey(options, "server= ")) { + error_setg(errp, "vdisk-id/server and a file name may not be speci= fied " + "at the same time"); + return; + } + + if (strstr(filename, "://")) { + int ret =3D vxhs_parse_uri(filename, options); + if (ret < 0) { + error_setg(errp, "Invalid URI. URI should be of the form " + " vxhs://:/"); + } + } +} + +static int vxhs_init_and_ref(void) +{ + if (vxhs_ref++ =3D=3D 0) { + if (iio_init(QNIO_VERSION, vxhs_iio_callback)) { + return -ENODEV; + } + } + return 0; +} + +static void vxhs_unref(void) +{ + if (--vxhs_ref =3D=3D 0) { + iio_fini(); + } +} + +static void vxhs_get_tls_creds(const char *id, char **cacert, + char **key, char **cert, Error **errp) +{ + Object *obj; + QCryptoTLSCreds *creds; + QCryptoTLSCredsX509 *creds_x509; + + obj =3D object_resolve_path_component( + object_get_objects_root(), id); + + if (!obj) { + error_setg(errp, "No TLS credentials with id '%s'", + id); + return; + } + + creds_x509 =3D (QCryptoTLSCredsX509 *) + object_dynamic_cast(obj, TYPE_QCRYPTO_TLS_CREDS_X509); + + if (!creds_x509) { + error_setg(errp, "Object with id '%s' is not TLS credentials", + id); + return; + } + + creds =3D &creds_x509->parent_obj; + + if (creds->endpoint !=3D QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { + error_setg(errp, + "Expecting TLS credentials with a client endpoint"); + return; + } + + /* + * Get the cacert, client_cert and client_key file names. + */ + if (!creds->dir) { + error_setg(errp, "TLS object missing 'dir' property value"); + return; + } + + *cacert =3D g_strdup_printf("%s/%s", creds->dir, + QCRYPTO_TLS_CREDS_X509_CA_CERT); + *cert =3D g_strdup_printf("%s/%s", creds->dir, + QCRYPTO_TLS_CREDS_X509_CLIENT_CERT); + *key =3D g_strdup_printf("%s/%s", creds->dir, + QCRYPTO_TLS_CREDS_X509_CLIENT_KEY); +} + +static int vxhs_open(BlockDriverState *bs, QDict *options, + int bdrv_flags, Error **errp) +{ + BDRVVXHSState *s =3D bs->opaque; + void *dev_handlep; + QDict *backing_options =3D NULL; + QemuOpts *opts =3D NULL; + QemuOpts *tcp_opts =3D NULL; + char *of_vsa_addr =3D NULL; + Error *local_err =3D NULL; + const char *vdisk_id_opt; + const char *server_host_opt; + int ret =3D 0; + char *cacert =3D NULL; + char *client_key =3D NULL; + char *client_cert =3D NULL; + + ret =3D vxhs_init_and_ref(); + if (ret < 0) { + ret =3D -EINVAL; + goto out; + } + + /* Create opts info from runtime_opts and runtime_tcp_opts list */ + opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); + tcp_opts =3D qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_abort= ); + + qemu_opts_absorb_qdict(opts, options, &local_err); + if (local_err) { + ret =3D -EINVAL; + goto out; + } + + /* vdisk-id is the disk UUID */ + vdisk_id_opt =3D qemu_opt_get(opts, VXHS_OPT_VDISK_ID); + if (!vdisk_id_opt) { + error_setg(&local_err, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID); + ret =3D -EINVAL; + goto out; + } + + /* vdisk-id may contain a leading '/' */ + if (strlen(vdisk_id_opt) > UUID_FMT_LEN + 1) { + error_setg(&local_err, "vdisk-id cannot be more than %d characters= ", + UUID_FMT_LEN); + ret =3D -EINVAL; + goto out; + } + + s->vdisk_guid =3D g_strdup(vdisk_id_opt); + trace_vxhs_open_vdiskid(vdisk_id_opt); + + /* get the 'server.' arguments */ + qdict_extract_subqdict(options, &backing_options, VXHS_OPT_SERVER"."); + + qemu_opts_absorb_qdict(tcp_opts, backing_options, &local_err); + if (local_err !=3D NULL) { + ret =3D -EINVAL; + goto out; + } + + server_host_opt =3D qemu_opt_get(tcp_opts, VXHS_OPT_HOST); + if (!server_host_opt) { + error_setg(&local_err, QERR_MISSING_PARAMETER, + VXHS_OPT_SERVER"."VXHS_OPT_HOST); + ret =3D -EINVAL; + goto out; + } + + if (strlen(server_host_opt) > MAXHOSTNAMELEN) { + error_setg(&local_err, "server.host cannot be more than %d charact= ers", + MAXHOSTNAMELEN); + ret =3D -EINVAL; + goto out; + } + + /* check if we got tls-creds via the --object argument */ + s->tlscredsid =3D g_strdup(qemu_opt_get(opts, "tls-creds")); + if (s->tlscredsid) { + vxhs_get_tls_creds(s->tlscredsid, &cacert, &client_key, + &client_cert, &local_err); + if (local_err !=3D NULL) { + ret =3D -EINVAL; + goto out; + } + trace_vxhs_get_creds(cacert, client_key, client_cert); + } + + s->vdisk_hostinfo.host =3D g_strdup(server_host_opt); + s->vdisk_hostinfo.port =3D g_ascii_strtoll(qemu_opt_get(tcp_opts, + VXHS_OPT_PORT), + NULL, 0); + + trace_vxhs_open_hostinfo(s->vdisk_hostinfo.host, + s->vdisk_hostinfo.port); + + of_vsa_addr =3D g_strdup_printf("of://%s:%d", + s->vdisk_hostinfo.host, + s->vdisk_hostinfo.port); + + /* + * Open qnio channel to storage agent if not opened before + */ + dev_handlep =3D iio_open(of_vsa_addr, s->vdisk_guid, 0, + cacert, client_key, client_cert); + if (dev_handlep =3D=3D NULL) { + trace_vxhs_open_iio_open(of_vsa_addr); + ret =3D -ENODEV; + goto out; + } + s->vdisk_hostinfo.dev_handle =3D dev_handlep; + +out: + g_free(of_vsa_addr); + QDECREF(backing_options); + qemu_opts_del(tcp_opts); + qemu_opts_del(opts); + g_free(cacert); + g_free(client_key); + g_free(client_cert); + + if (ret < 0) { + vxhs_unref(); + error_propagate(errp, local_err); + g_free(s->vdisk_hostinfo.host); + g_free(s->vdisk_guid); + g_free(s->tlscredsid); + s->vdisk_guid =3D NULL; + } + + return ret; +} + +static const AIOCBInfo vxhs_aiocb_info =3D { + .aiocb_size =3D sizeof(VXHSAIOCB) +}; + +/* + * This allocates QEMU-VXHS callback for each IO + * and is passed to QNIO. When QNIO completes the work, + * it will be passed back through the callback. + */ +static BlockAIOCB *vxhs_aio_rw(BlockDriverState *bs, int64_t sector_num, + QEMUIOVector *qiov, int nb_sectors, + BlockCompletionFunc *cb, void *opaque, + VDISKAIOCmd iodir) +{ + VXHSAIOCB *acb =3D NULL; + BDRVVXHSState *s =3D bs->opaque; + size_t size; + uint64_t offset; + int iio_flags =3D 0; + int ret =3D 0; + void *dev_handle =3D s->vdisk_hostinfo.dev_handle; + + offset =3D sector_num * BDRV_SECTOR_SIZE; + size =3D nb_sectors * BDRV_SECTOR_SIZE; + acb =3D qemu_aio_get(&vxhs_aiocb_info, bs, cb, opaque); + + /* + * Initialize VXHSAIOCB. + */ + acb->err =3D 0; + + iio_flags =3D IIO_FLAG_ASYNC; + + switch (iodir) { + case VDISK_AIO_WRITE: + ret =3D iio_writev(dev_handle, acb, qiov->iov, qiov->niov, + offset, (uint64_t)size, iio_flags); + break; + case VDISK_AIO_READ: + ret =3D iio_readv(dev_handle, acb, qiov->iov, qiov->niov, + offset, (uint64_t)size, iio_flags); + break; + default: + trace_vxhs_aio_rw_invalid(iodir); + goto errout; + } + + if (ret !=3D 0) { + trace_vxhs_aio_rw_ioerr(s->vdisk_guid, iodir, size, offset, + acb, ret, errno); + goto errout; + } + return &acb->common; + +errout: + qemu_aio_unref(acb); + return NULL; +} + +static BlockAIOCB *vxhs_aio_readv(BlockDriverState *bs, + int64_t sector_num, QEMUIOVector *qiov, + int nb_sectors, + BlockCompletionFunc *cb, void *opaque) +{ + return vxhs_aio_rw(bs, sector_num, qiov, nb_sectors, cb, + opaque, VDISK_AIO_READ); +} + +static BlockAIOCB *vxhs_aio_writev(BlockDriverState *bs, + int64_t sector_num, QEMUIOVector *qiov, + int nb_sectors, + BlockCompletionFunc *cb, void *opaque) +{ + return vxhs_aio_rw(bs, sector_num, qiov, nb_sectors, + cb, opaque, VDISK_AIO_WRITE); +} + +static void vxhs_close(BlockDriverState *bs) +{ + BDRVVXHSState *s =3D bs->opaque; + + trace_vxhs_close(s->vdisk_guid); + + g_free(s->vdisk_guid); + s->vdisk_guid =3D NULL; + + /* + * Close vDisk device + */ + if (s->vdisk_hostinfo.dev_handle) { + iio_close(s->vdisk_hostinfo.dev_handle); + s->vdisk_hostinfo.dev_handle =3D NULL; + } + + vxhs_unref(); + + /* + * Free the dynamically allocated host string etc + */ + g_free(s->vdisk_hostinfo.host); + g_free(s->tlscredsid); + s->tlscredsid =3D NULL; + s->vdisk_hostinfo.host =3D NULL; + s->vdisk_hostinfo.port =3D 0; +} + +static int64_t vxhs_get_vdisk_stat(BDRVVXHSState *s) +{ + int64_t vdisk_size =3D -1; + int ret =3D 0; + void *dev_handle =3D s->vdisk_hostinfo.dev_handle; + + ret =3D iio_ioctl(dev_handle, IOR_VDISK_STAT, &vdisk_size, 0); + if (ret < 0) { + trace_vxhs_get_vdisk_stat_err(s->vdisk_guid, ret, errno); + return -EIO; + } + + trace_vxhs_get_vdisk_stat(s->vdisk_guid, vdisk_size); + return vdisk_size; +} + +/* + * Returns the size of vDisk in bytes. This is required + * by QEMU block upper block layer so that it is visible + * to guest. + */ +static int64_t vxhs_getlength(BlockDriverState *bs) +{ + BDRVVXHSState *s =3D bs->opaque; + int64_t vdisk_size; + + vdisk_size =3D vxhs_get_vdisk_stat(s); + if (vdisk_size < 0) { + return -EIO; + } + + return vdisk_size; +} + +static BlockDriver bdrv_vxhs =3D { + .format_name =3D "vxhs", + .protocol_name =3D "vxhs", + .instance_size =3D sizeof(BDRVVXHSState), + .bdrv_file_open =3D vxhs_open, + .bdrv_parse_filename =3D vxhs_parse_filename, + .bdrv_close =3D vxhs_close, + .bdrv_getlength =3D vxhs_getlength, + .bdrv_aio_readv =3D vxhs_aio_readv, + .bdrv_aio_writev =3D vxhs_aio_writev, +}; + +static void bdrv_vxhs_init(void) +{ + bdrv_register(&bdrv_vxhs); +} + +block_init(bdrv_vxhs_init); diff --git a/configure b/configure index be4d326..c6c37aa 100755 --- a/configure +++ b/configure @@ -320,6 +320,7 @@ numa=3D"" tcmalloc=3D"no" jemalloc=3D"no" replication=3D"yes" +vxhs=3D"" =20 supported_cpu=3D"no" supported_os=3D"no" @@ -1183,6 +1184,10 @@ for opt do ;; --enable-replication) replication=3D"yes" ;; + --disable-vxhs) vxhs=3D"no" + ;; + --enable-vxhs) vxhs=3D"yes" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1427,6 +1432,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: xfsctl xfsctl support qom-cast-debug cast debugging support tools build qemu-io, qemu-nbd and qemu-image tools + vxhs Veritas HyperScale vDisk backend support =20 NOTE: The object files are built at the place where configure is launched EOF @@ -4781,6 +4787,33 @@ if compile_prog "" "" ; then fi =20 ########################################## +# Veritas HyperScale block driver VxHS +# Check if libvxhs is installed + +if test "$vxhs" !=3D "no" ; then + cat > $TMPC < +#include + +void *vxhs_callback; + +int main(void) { + iio_init(QNIO_VERSION, vxhs_callback); + return 0; +} +EOF + vxhs_libs=3D"-lvxhs -lssl" + if compile_prog "" "$vxhs_libs" ; then + vxhs=3Dyes + else + if test "$vxhs" =3D "yes" ; then + feature_not_found "vxhs block device" "Install libvxhs See github" + fi + vxhs=3Dno + fi +fi + +########################################## # End of CC checks # After here, no more $cc or $ld runs =20 @@ -5146,6 +5179,7 @@ echo "tcmalloc support $tcmalloc" echo "jemalloc support $jemalloc" echo "avx2 optimization $avx2_opt" echo "replication support $replication" +echo "VxHS block device $vxhs" =20 if test "$sdl_too_old" =3D "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -5785,6 +5819,11 @@ if test "$pthread_setname_np" =3D "yes" ; then echo "CONFIG_PTHREAD_SETNAME_NP=3Dy" >> $config_host_mak fi =20 +if test "$vxhs" =3D "yes" ; then + echo "CONFIG_VXHS=3Dy" >> $config_host_mak + echo "VXHS_LIBS=3D$vxhs_libs" >> $config_host_mak +fi + if test "$tcg_interpreter" =3D "yes"; then QEMU_INCLUDES=3D"-I\$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" =3D "sparc64" ; then diff --git a/qapi/block-core.json b/qapi/block-core.json index 033457c..87fb747 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2108,6 +2108,8 @@ # # Drivers that are supported in block device operations. # +# @vxhs: Since 2.10 +# # Since: 2.9 ## { 'enum': 'BlockdevDriver', @@ -2116,7 +2118,7 @@ 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', - 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } =20 ## # @BlockdevOptionsFile: @@ -2866,6 +2868,22 @@ 'data': { '*offset': 'int', '*size': 'int' } } =20 ## +# @BlockdevOptionsVxHS: +# +# Driver specific block device options for VxHS +# +# @vdisk-id: UUID of VxHS volume +# @server: vxhs server IP, port +# @tls-creds: TLS credentials ID +# +# Since: 2.10 +## +{ 'struct': 'BlockdevOptionsVxHS', + 'data': { 'vdisk-id': 'str', + 'server': 'InetSocketAddressBase', + '*tls-creds': 'str' } } + +## # @BlockdevOptions: # # Options for creating a block device. Many options are available for all @@ -2927,7 +2945,8 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'vxhs': 'BlockdevOptionsVxHS' } } =20 ## --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782697996687.421940040266; Fri, 21 Apr 2017 06:51:37 -0700 (PDT) Received: from localhost ([::1]:59765 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1YyG-0008Un-8a for importer@patchew.org; Fri, 21 Apr 2017 09:51:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Ytj-0004t2-6t for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Yth-0002Pf-Pr for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytd-0002O7-01; Fri, 21 Apr 2017 09:46:49 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D45846E792; Fri, 21 Apr 2017 13:46:47 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 905C3AE0E7; Fri, 21 Apr 2017 13:46:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D45846E792 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D45846E792 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:34 -0400 Message-Id: <20170421134644.10239-3-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Apr 2017 13:46:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/12] block/vxhs.c: Add qemu-iotests for new block device type "vxhs" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, Ashish Mittal , qemu-devel@nongnu.org, Ashish Mittal Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ashish Mittal These changes use a vxhs test server that is a part of the following repository: https://github.com/VeritasHyperScale/libqnio.git Signed-off-by: Ashish Mittal Reviewed-by: Stefan Hajnoczi Reviewed-by: Jeff Cody Signed-off-by: Jeff Cody Message-id: 1491277689-24949-3-git-send-email-Ashish.Mittal@veritas.com --- tests/qemu-iotests/common | 6 ++++++ tests/qemu-iotests/common.config | 13 +++++++++++++ tests/qemu-iotests/common.filter | 1 + tests/qemu-iotests/common.rc | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common index 4d5650d..9c6f972 100644 --- a/tests/qemu-iotests/common +++ b/tests/qemu-iotests/common @@ -157,6 +157,7 @@ check options -ssh test ssh -nfs test nfs -luks test luks + -vxhs test vxhs -xdiff graphical mode diff -nocache use O_DIRECT on backing file -misalign misalign memory allocations @@ -260,6 +261,11 @@ testlist options xpand=3Dfalse ;; =20 + -vxhs) + IMGPROTO=3Dvxhs + xpand=3Dfalse + ;; + -ssh) IMGPROTO=3Dssh xpand=3Dfalse diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.c= onfig index 55527aa..c4b51b3 100644 --- a/tests/qemu-iotests/common.config +++ b/tests/qemu-iotests/common.config @@ -105,6 +105,10 @@ if [ -z "$QEMU_NBD_PROG" ]; then export QEMU_NBD_PROG=3D"`set_prog_path qemu-nbd`" fi =20 +if [ -z "$QEMU_VXHS_PROG" ]; then + export QEMU_VXHS_PROG=3D"`set_prog_path qnio_server`" +fi + _qemu_wrapper() { ( @@ -156,10 +160,19 @@ _qemu_nbd_wrapper() ) } =20 +_qemu_vxhs_wrapper() +{ + ( + echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid" + exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@" + ) +} + export QEMU=3D_qemu_wrapper export QEMU_IMG=3D_qemu_img_wrapper export QEMU_IO=3D_qemu_io_wrapper export QEMU_NBD=3D_qemu_nbd_wrapper +export QEMU_VXHS=3D_qemu_vxhs_wrapper =20 QEMU_IMG_EXTRA_ARGS=3D if [ "$IMGOPTSSYNTAX" =3D "true" ]; then diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index 1040013..c9a2d5c 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -122,6 +122,7 @@ _filter_img_info() -e "s#$TEST_DIR#TEST_DIR#g" \ -e "s#$IMGFMT#IMGFMT#g" \ -e 's#nbd://127.0.0.1:10810$#TEST_DIR/t.IMGFMT#g' \ + -e 's#json.*vdisk-id.*vxhs"}}#TEST_DIR/t.IMGFMT#' \ -e "/encrypted: yes/d" \ -e "/cluster_size: [0-9]\\+/d" \ -e "/table_size: [0-9]\\+/d" \ diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 7d4781d..62529ee 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -85,6 +85,9 @@ else elif [ "$IMGPROTO" =3D "nfs" ]; then TEST_DIR=3D"nfs://127.0.0.1/$TEST_DIR" TEST_IMG=3D$TEST_DIR/t.$IMGFMT + elif [ "$IMGPROTO" =3D "vxhs" ]; then + TEST_IMG_FILE=3D$TEST_DIR/t.$IMGFMT + TEST_IMG=3D"vxhs://127.0.0.1:9999/t.$IMGFMT" else TEST_IMG=3D$IMGPROTO:$TEST_DIR/t.$IMGFMT fi @@ -171,6 +174,12 @@ _make_test_img() eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT $TEST_IMG_= FILE >/dev/null &" sleep 1 # FIXME: qemu-nbd needs to be listening before we continue fi + + # Start QNIO server on image directory for vxhs protocol + if [ $IMGPROTO =3D "vxhs" ]; then + eval "$QEMU_VXHS -d $TEST_DIR > /dev/null &" + sleep 1 # Wait for server to come up. + fi } =20 _rm_test_img() @@ -197,6 +206,16 @@ _cleanup_test_img() fi rm -f "$TEST_IMG_FILE" ;; + vxhs) + if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then + local QEMU_VXHS_PID + read QEMU_VXHS_PID < "${TEST_DIR}/qemu-vxhs.pid" + kill ${QEMU_VXHS_PID} >/dev/null 2>&1 + rm -f "${TEST_DIR}/qemu-vxhs.pid" + fi + rm -f "$TEST_IMG_FILE" + ;; + file) _rm_test_img "$TEST_DIR/t.$IMGFMT" _rm_test_img "$TEST_DIR/t.$IMGFMT.orig" --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782698083815.0654986302347; Fri, 21 Apr 2017 06:51:38 -0700 (PDT) Received: from localhost ([::1]:59764 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1YyG-0008UE-Er for importer@patchew.org; Fri, 21 Apr 2017 09:51:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yti-0004s5-4j for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Yth-0002PI-18 for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Yte-0002OF-1Y; Fri, 21 Apr 2017 09:46:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E82AAC08E2A1; Fri, 21 Apr 2017 13:46:48 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE2E882D3A; Fri, 21 Apr 2017 13:46:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E82AAC08E2A1 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E82AAC08E2A1 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:35 -0400 Message-Id: <20170421134644.10239-4-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Apr 2017 13:46:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/12] qemu-iotests: exclude vxhs from image creation via protocol X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The protocol VXHS does not support image creation. Some tests expect to be able to create images through the protocol. Exclude VXHS from these tests. Signed-off-by: Jeff Cody --- tests/qemu-iotests/017 | 1 + tests/qemu-iotests/020 | 1 + tests/qemu-iotests/029 | 1 + tests/qemu-iotests/073 | 1 + tests/qemu-iotests/114 | 1 + tests/qemu-iotests/130 | 1 + tests/qemu-iotests/134 | 1 + tests/qemu-iotests/156 | 1 + tests/qemu-iotests/158 | 1 + 9 files changed, 9 insertions(+) diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017 index e3f9e75..4f9302d 100755 --- a/tests/qemu-iotests/017 +++ b/tests/qemu-iotests/017 @@ -41,6 +41,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 # Any format supporting backing files _supported_fmt qcow qcow2 vmdk qed _supported_proto generic +_unsupported_proto vxhs _supported_os Linux _unsupported_imgopts "subformat=3DmonolithicFlat" "subformat=3DtwoGbMaxExt= entFlat" =20 diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 index 9c4a68c..7a11110 100755 --- a/tests/qemu-iotests/020 +++ b/tests/qemu-iotests/020 @@ -43,6 +43,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 # Any format supporting backing files _supported_fmt qcow qcow2 vmdk qed _supported_proto generic +_unsupported_proto vxhs _supported_os Linux _unsupported_imgopts "subformat=3DmonolithicFlat" \ "subformat=3DtwoGbMaxExtentFlat" \ diff --git a/tests/qemu-iotests/029 b/tests/qemu-iotests/029 index e639ac0..30bab24 100755 --- a/tests/qemu-iotests/029 +++ b/tests/qemu-iotests/029 @@ -42,6 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 # Any format supporting intenal snapshots _supported_fmt qcow2 _supported_proto generic +_unsupported_proto vxhs _supported_os Linux # Internal snapshots are (currently) impossible with refcount_bits=3D1 _unsupported_imgopts 'refcount_bits=3D1[^0-9]' diff --git a/tests/qemu-iotests/073 b/tests/qemu-iotests/073 index ad37a61..40f85b1 100755 --- a/tests/qemu-iotests/073 +++ b/tests/qemu-iotests/073 @@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 =20 _supported_fmt qcow2 _supported_proto generic +_unsupported_proto vxhs _supported_os Linux =20 CLUSTER_SIZE=3D64k diff --git a/tests/qemu-iotests/114 b/tests/qemu-iotests/114 index f110d4f..5b7dc54 100755 --- a/tests/qemu-iotests/114 +++ b/tests/qemu-iotests/114 @@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 =20 _supported_fmt qcow2 _supported_proto generic +_unsupported_proto vxhs _supported_os Linux =20 =20 diff --git a/tests/qemu-iotests/130 b/tests/qemu-iotests/130 index ecc8a5b..f941fc9 100755 --- a/tests/qemu-iotests/130 +++ b/tests/qemu-iotests/130 @@ -42,6 +42,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 =20 _supported_fmt qcow2 _supported_proto generic +_unsupported_proto vxhs _supported_os Linux =20 qemu_comm_method=3D"monitor" diff --git a/tests/qemu-iotests/134 b/tests/qemu-iotests/134 index af618b8..acce946 100755 --- a/tests/qemu-iotests/134 +++ b/tests/qemu-iotests/134 @@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 =20 _supported_fmt qcow2 _supported_proto generic +_unsupported_proto vxhs _supported_os Linux =20 =20 diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156 index cc95ff1..78deaff 100755 --- a/tests/qemu-iotests/156 +++ b/tests/qemu-iotests/156 @@ -48,6 +48,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 =20 _supported_fmt qcow2 qed _supported_proto generic +_unsupported_proto vxhs _supported_os Linux =20 # Create source disk diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158 index a6cdd6d..ef8d70f 100755 --- a/tests/qemu-iotests/158 +++ b/tests/qemu-iotests/158 @@ -39,6 +39,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 =20 _supported_fmt qcow2 _supported_proto generic +_unsupported_proto vxhs _supported_os Linux =20 =20 --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782535363451.377024802852; Fri, 21 Apr 2017 06:48:55 -0700 (PDT) Received: from localhost ([::1]:59751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yvd-0006MZ-MD for importer@patchew.org; Fri, 21 Apr 2017 09:48:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yti-0004sY-LW for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Yth-0002PU-JF for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47104) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytf-0002OO-5D; Fri, 21 Apr 2017 09:46:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E855C60ED; Fri, 21 Apr 2017 13:46:50 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA311AC6E2; Fri, 21 Apr 2017 13:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0E855C60ED Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0E855C60ED From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:36 -0400 Message-Id: <20170421134644.10239-5-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 21 Apr 2017 13:46:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/12] block: add bdrv_set_read_only() helper function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We have a helper wrapper for checking for the BDS read_only flag, add a helper wrapper to set the read_only flag as well. Reviewed-by: Stefan Hajnoczi Signed-off-by: Jeff Cody Reviewed-by: John Snow Message-id: 9b18972d05f5fa2ac16c014f0af98d680553048d.1491597120.git.jcody@r= edhat.com --- block.c | 5 +++++ block/bochs.c | 2 +- block/cloop.c | 2 +- block/dmg.c | 2 +- block/rbd.c | 2 +- block/vvfat.c | 4 ++-- include/block/block.h | 1 + 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 1fbbb8d..25a4cfd 100644 --- a/block.c +++ b/block.c @@ -192,6 +192,11 @@ void path_combine(char *dest, int dest_size, } } =20 +void bdrv_set_read_only(BlockDriverState *bs, bool read_only) +{ + bs->read_only =3D read_only; +} + void bdrv_get_full_backing_filename_from_filename(const char *backed, const char *backing, char *dest, size_t sz, diff --git a/block/bochs.c b/block/bochs.c index 516da56..bdc2831 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -110,7 +110,7 @@ static int bochs_open(BlockDriverState *bs, QDict *opti= ons, int flags, return -EINVAL; } =20 - bs->read_only =3D true; /* no write support yet */ + bdrv_set_read_only(bs, true); /* no write support yet */ =20 ret =3D bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); if (ret < 0) { diff --git a/block/cloop.c b/block/cloop.c index a6c7b9d..11f17c8 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -72,7 +72,7 @@ static int cloop_open(BlockDriverState *bs, QDict *option= s, int flags, return -EINVAL; } =20 - bs->read_only =3D true; + bdrv_set_read_only(bs, true); =20 /* read header */ ret =3D bdrv_pread(bs->file, 128, &s->block_size, 4); diff --git a/block/dmg.c b/block/dmg.c index a7d25fc..27ce4a6 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -420,7 +420,7 @@ static int dmg_open(BlockDriverState *bs, QDict *option= s, int flags, } =20 block_module_load_one("dmg-bz2"); - bs->read_only =3D true; + bdrv_set_read_only(bs, true); =20 s->n_chunks =3D 0; s->offsets =3D s->lengths =3D s->sectors =3D s->sectorcounts =3D NULL; diff --git a/block/rbd.c b/block/rbd.c index 1ceeeb5..6ad2904 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -641,7 +641,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *o= ptions, int flags, goto failed_open; } =20 - bs->read_only =3D (s->snap !=3D NULL); + bdrv_set_read_only(bs, (s->snap !=3D NULL)); =20 qemu_opts_del(opts); return 0; diff --git a/block/vvfat.c b/block/vvfat.c index af5153d..d4ce6d7 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1157,7 +1157,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, s->current_cluster=3D0xffffffff; =20 /* read only is the default for safety */ - bs->read_only =3D true; + bdrv_set_read_only(bs, true); s->qcow =3D NULL; s->qcow_filename =3D NULL; s->fat2 =3D NULL; @@ -1173,7 +1173,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, if (ret < 0) { goto fail; } - bs->read_only =3D false; + bdrv_set_read_only(bs, false); } =20 bs->total_sectors =3D cyls * heads * secs; diff --git a/include/block/block.h b/include/block/block.h index 5ddc0cf..16eb909 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -434,6 +434,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, int64_t sector_num, int nb_sectors, int *pnum); =20 bool bdrv_is_read_only(BlockDriverState *bs); +void bdrv_set_read_only(BlockDriverState *bs, bool read_only); bool bdrv_is_sg(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); int bdrv_media_changed(BlockDriverState *bs); --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782568091790.0145241045866; Fri, 21 Apr 2017 06:49:28 -0700 (PDT) Received: from localhost ([::1]:59753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1YwA-0006jv-4k for importer@patchew.org; Fri, 21 Apr 2017 09:49:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Ytk-0004uu-Ow for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytj-0002Qo-Ij for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytg-0002Og-AH; Fri, 21 Apr 2017 09:46:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4110C2BA7AF; Fri, 21 Apr 2017 13:46:51 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E52E2AC6D4; Fri, 21 Apr 2017 13:46:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4110C2BA7AF Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4110C2BA7AF From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:37 -0400 Message-Id: <20170421134644.10239-6-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 21 Apr 2017 13:46:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/12] block: do not set BDS read_only if copy_on_read enabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A few block drivers will set the BDS read_only flag from their .bdrv_open() function. This means the bs->read_only flag could be set after we enable copy_on_read, as the BDRV_O_COPY_ON_READ flag check occurs prior to the call to bdrv->bdrv_open(). This adds an error return to bdrv_set_read_only(), and an error will be return if we try to set the BDS to read_only while copy_on_read is enabled. This patch also changes the behavior of vvfat. Before, vvfat could override the drive 'readonly' flag with its own, internal 'rw' flag. For instance, this -drive parameter would result in a writable image: "-drive format=3Dvvfat,dir=3D/tmp/vvfat,rw,if=3Dvirtio,readonly=3Don" This is not correct. Now, attempting to use the above -drive parameter will result in an error (i.e., 'rw' is incompatible with 'readonly=3Don'). Signed-off-by: Jeff Cody Reviewed-by: Stefan Hajnoczi Reviewed-by: John Snow Message-id: 0c5b4c1cc2c651471b131f21376dfd5ea24d2196.1491597120.git.jcody@r= edhat.com --- block.c | 10 +++++++++- block/bochs.c | 5 ++++- block/cloop.c | 5 ++++- block/dmg.c | 6 +++++- block/rbd.c | 11 ++++++++++- block/vvfat.c | 19 +++++++++++++++---- include/block/block.h | 2 +- 7 files changed, 48 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 25a4cfd..4766b8a 100644 --- a/block.c +++ b/block.c @@ -192,9 +192,17 @@ void path_combine(char *dest, int dest_size, } } =20 -void bdrv_set_read_only(BlockDriverState *bs, bool read_only) +int bdrv_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 ena= bled", + bdrv_get_device_or_node_name(bs)); + return -EINVAL; + } + bs->read_only =3D read_only; + return 0; } =20 void bdrv_get_full_backing_filename_from_filename(const char *backed, diff --git a/block/bochs.c b/block/bochs.c index bdc2831..a759b6e 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -110,7 +110,10 @@ static int bochs_open(BlockDriverState *bs, QDict *opt= ions, int flags, return -EINVAL; } =20 - bdrv_set_read_only(bs, true); /* no write support yet */ + ret =3D bdrv_set_read_only(bs, true, errp); /* no write support yet */ + if (ret < 0) { + return ret; + } =20 ret =3D bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); if (ret < 0) { diff --git a/block/cloop.c b/block/cloop.c index 11f17c8..d6597fc 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -72,7 +72,10 @@ static int cloop_open(BlockDriverState *bs, QDict *optio= ns, int flags, return -EINVAL; } =20 - bdrv_set_read_only(bs, true); + ret =3D bdrv_set_read_only(bs, true, errp); + if (ret < 0) { + return ret; + } =20 /* read header */ ret =3D bdrv_pread(bs->file, 128, &s->block_size, 4); diff --git a/block/dmg.c b/block/dmg.c index 27ce4a6..900ae5a 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -419,8 +419,12 @@ static int dmg_open(BlockDriverState *bs, QDict *optio= ns, int flags, return -EINVAL; } =20 + ret =3D bdrv_set_read_only(bs, true, errp); + if (ret < 0) { + return ret; + } + block_module_load_one("dmg-bz2"); - bdrv_set_read_only(bs, true); =20 s->n_chunks =3D 0; s->offsets =3D s->lengths =3D s->sectors =3D s->sectorcounts =3D NULL; diff --git a/block/rbd.c b/block/rbd.c index 6ad2904..1c43171 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -635,13 +635,22 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict = *options, int flags, goto failed_shutdown; } =20 + /* rbd_open is always r/w */ r =3D rbd_open(s->io_ctx, s->name, &s->image, s->snap); if (r < 0) { error_setg_errno(errp, -r, "error reading header from %s", s->name= ); goto failed_open; } =20 - bdrv_set_read_only(bs, (s->snap !=3D NULL)); + /* If we are using an rbd snapshot, we must be r/o, otherwise + * leave as-is */ + if (s->snap !=3D NULL) { + r =3D bdrv_set_read_only(bs, true, &local_err); + if (r < 0) { + error_propagate(errp, local_err); + goto failed_open; + } + } =20 qemu_opts_del(opts); return 0; diff --git a/block/vvfat.c b/block/vvfat.c index d4ce6d7..b509d55 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1156,8 +1156,6 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, =20 s->current_cluster=3D0xffffffff; =20 - /* read only is the default for safety */ - bdrv_set_read_only(bs, true); s->qcow =3D NULL; s->qcow_filename =3D NULL; s->fat2 =3D NULL; @@ -1169,11 +1167,24 @@ static int vvfat_open(BlockDriverState *bs, QDict *= options, int flags, s->sector_count =3D cyls * heads * secs - (s->first_sectors_number - 1= ); =20 if (qemu_opt_get_bool(opts, "rw", false)) { - ret =3D enable_write_target(bs, errp); + if (!bdrv_is_read_only(bs)) { + ret =3D enable_write_target(bs, errp); + if (ret < 0) { + goto fail; + } + } else { + ret =3D -EPERM; + error_setg(errp, + "Unable to set VVFAT to 'rw' when drive is read-onl= y"); + goto fail; + } + } else { + /* read only is the default for safety */ + ret =3D bdrv_set_read_only(bs, true, &local_err); if (ret < 0) { + error_propagate(errp, local_err); goto fail; } - bdrv_set_read_only(bs, false); } =20 bs->total_sectors =3D cyls * heads * secs; diff --git a/include/block/block.h b/include/block/block.h index 16eb909..3525590 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -434,7 +434,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, int64_t sector_num, int nb_sectors, int *pnum); =20 bool bdrv_is_read_only(BlockDriverState *bs); -void bdrv_set_read_only(BlockDriverState *bs, bool read_only); +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); bool bdrv_is_sg(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); int bdrv_media_changed(BlockDriverState *bs); --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782540826161.93008983039147; Fri, 21 Apr 2017 06:49:00 -0700 (PDT) Received: from localhost ([::1]:59752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yvj-0006Qt-Ah for importer@patchew.org; Fri, 21 Apr 2017 09:48:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Ytk-0004uZ-FE for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytj-0002Qj-HJ for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53812) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Yth-0002PF-Ey; Fri, 21 Apr 2017 09:46:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B1B072882; Fri, 21 Apr 2017 13:46:52 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23147AC6D4; Fri, 21 Apr 2017 13:46:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5B1B072882 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5B1B072882 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:38 -0400 Message-Id: <20170421134644.10239-7-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 21 Apr 2017 13:46:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/12] block: honor BDRV_O_ALLOW_RDWR when clearing bs->read_only X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The BDRV_O_ALLOW_RDWR flag allows / prohibits the changing of the BDS 'read_only' state, but there are a few places where it is ignored. In the bdrv_set_read_only() helper, make sure to honor the flag. Signed-off-by: Jeff Cody Reviewed-by: Stefan Hajnoczi Reviewed-by: John Snow Message-id: be2e5fb2d285cbece2b6d06bed54a6f56520d251.1491597120.git.jcody@r= edhat.com --- block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block.c b/block.c index 4766b8a..b74d445 100644 --- a/block.c +++ b/block.c @@ -201,6 +201,13 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read= _only, Error **errp) return -EINVAL; } =20 + /* 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; + } + bs->read_only =3D read_only; return 0; } --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782700823927.6077865747027; Fri, 21 Apr 2017 06:51:40 -0700 (PDT) Received: from localhost ([::1]:59766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1YyJ-00005r-9a for importer@patchew.org; Fri, 21 Apr 2017 09:51:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Ytl-0004vc-Fz for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytk-0002RH-Jb for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:46:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48000) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Yti-0002Pk-Ia; Fri, 21 Apr 2017 09:46:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 77861DDB49; Fri, 21 Apr 2017 13:46:53 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CDB817B93; Fri, 21 Apr 2017 13:46:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 77861DDB49 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 77861DDB49 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:39 -0400 Message-Id: <20170421134644.10239-8-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 21 Apr 2017 13:46:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/12] block: code movement X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move bdrv_is_read_only() up with its friends. Reviewed-by: Stefan Hajnoczi Reviewed-by: John Snow Signed-off-by: Jeff Cody Message-id: 73b2399459760c32506f9407efb9dddb3a2789de.1491597120.git.jcody@r= edhat.com --- block.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index b74d445..bf09026 100644 --- a/block.c +++ b/block.c @@ -192,6 +192,11 @@ void path_combine(char *dest, int dest_size, } } =20 +bool bdrv_is_read_only(BlockDriverState *bs) +{ + return bs->read_only; +} + int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) { /* Do not set read_only if copy_on_read is enabled */ @@ -3375,11 +3380,6 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_= t *nb_sectors_ptr) *nb_sectors_ptr =3D nb_sectors < 0 ? 0 : nb_sectors; } =20 -bool bdrv_is_read_only(BlockDriverState *bs) -{ - return bs->read_only; -} - bool bdrv_is_sg(BlockDriverState *bs) { return bs->sg; --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782727433243.03092467100976; Fri, 21 Apr 2017 06:52:07 -0700 (PDT) Received: from localhost ([::1]:59768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yyk-0000Rt-4p for importer@patchew.org; Fri, 21 Apr 2017 09:52:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Ytp-00051F-VA for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytl-0002Rl-Us for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytj-0002QK-Mp; Fri, 21 Apr 2017 09:46:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92E54C00C0EB; Fri, 21 Apr 2017 13:46:54 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57337121E2C; Fri, 21 Apr 2017 13:46:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 92E54C00C0EB Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 92E54C00C0EB From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:40 -0400 Message-Id: <20170421134644.10239-9-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 21 Apr 2017 13:46:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/12] block: introduce bdrv_can_set_read_only() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce check function for setting read_only flags. Will return < 0 on error, with appropriate Error value set. Does not alter any flags. Signed-off-by: Jeff Cody Reviewed-by: Stefan Hajnoczi Reviewed-by: John Snow Message-id: e2bba34ac3bc76a0c42adc390413f358ae0566e8.1491597120.git.jcody@r= edhat.com --- block.c | 14 +++++++++++++- include/block/block.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index bf09026..84f12f7 100644 --- a/block.c +++ b/block.c @@ -197,7 +197,7 @@ bool bdrv_is_read_only(BlockDriverState *bs) return bs->read_only; } =20 -int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) +int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **e= rrp) { /* Do not set read_only if copy_on_read is enabled */ if (bs->copy_on_read && read_only) { @@ -213,6 +213,18 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read= _only, Error **errp) return -EPERM; } =20 + return 0; +} + +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) +{ + int ret =3D 0; + + ret =3D bdrv_can_set_read_only(bs, read_only, errp); + if (ret < 0) { + return ret; + } + bs->read_only =3D read_only; return 0; } diff --git a/include/block/block.h b/include/block/block.h index 3525590..56b27fb 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -434,6 +434,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, int64_t sector_num, int nb_sectors, int *pnum); =20 bool bdrv_is_read_only(BlockDriverState *bs); +int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **e= rrp); int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); bool bdrv_is_sg(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492782860039335.86692947461245; Fri, 21 Apr 2017 06:54:20 -0700 (PDT) Received: from localhost ([::1]:59781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Z0s-0002S9-GS for importer@patchew.org; Fri, 21 Apr 2017 09:54:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yts-00055I-LS for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytr-0002Ta-LM for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytk-0002R4-Rt; Fri, 21 Apr 2017 09:46:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2D197E9CB; Fri, 21 Apr 2017 13:46:55 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 744C2AE0EA; Fri, 21 Apr 2017 13:46:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C2D197E9CB Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C2D197E9CB From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:41 -0400 Message-Id: <20170421134644.10239-10-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 21 Apr 2017 13:46:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/12] block: use bdrv_can_set_read_only() during reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jeff Cody Reviewed-by: Stefan Hajnoczi Reviewed-by: John Snow Message-id: 00aed7ffdd7be4b9ed9ce1007d50028a72b34ebe.1491597120.git.jcody@r= edhat.com --- block.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 84f12f7..9fca814 100644 --- a/block.c +++ b/block.c @@ -2789,6 +2789,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state= , BlockReopenQueue *queue, BlockDriver *drv; QemuOpts *opts; const char *value; + bool read_only; =20 assert(reopen_state !=3D NULL); assert(reopen_state->bs->drv !=3D NULL); @@ -2817,12 +2818,13 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_sta= te, BlockReopenQueue *queue, qdict_put(reopen_state->options, "driver", qstring_from_str(value)= ); } =20 - /* 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_RD= WR is + * not set, or if the BDS still has copy_on_read enabled */ + read_only =3D !(reopen_state->flags & BDRV_O_RDWR); + ret =3D bdrv_can_set_read_only(reopen_state->bs, read_only, &local_err= ); + if (local_err) { + error_propagate(errp, local_err); goto error; } =20 --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492783017402140.5934421956398; Fri, 21 Apr 2017 06:56:57 -0700 (PDT) Received: from localhost ([::1]:59799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Z3P-0004fl-Td for importer@patchew.org; Fri, 21 Apr 2017 09:56:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yts-00055O-OY for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytr-0002Tf-Ls for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55880) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytm-0002Rf-7p; Fri, 21 Apr 2017 09:46:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22D03C08E2B3; Fri, 21 Apr 2017 13:46:57 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4B0977FC1; Fri, 21 Apr 2017 13:46:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 22D03C08E2B3 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 22D03C08E2B3 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:42 -0400 Message-Id: <20170421134644.10239-11-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Apr 2017 13:46:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/12] block/rbd - update variable names to more apt names X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Update 'clientname' to be 'user', which tracks better with both the QAPI and rados variable naming. Update 'name' to be 'image_name', as it indicates the rbd image. Naming it 'image' would have been ideal, but we are using that for the rados_image_t value returned by rbd_open(). Reviewed-by: Stefan Hajnoczi Signed-off-by: Jeff Cody Reviewed-by: John Snow Message-id: b7ec1fb2e1cf36f9b6911631447a5b0422590b7d.1491597120.git.jcody@r= edhat.com --- block/rbd.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 1c43171..35853c9 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -94,7 +94,7 @@ typedef struct BDRVRBDState { rados_t cluster; rados_ioctx_t io_ctx; rbd_image_t image; - char *name; + char *image_name; char *snap; } BDRVRBDState; =20 @@ -350,7 +350,7 @@ static int qemu_rbd_create(const char *filename, QemuOp= ts *opts, Error **errp) int64_t bytes =3D 0; int64_t objsize; int obj_order =3D 0; - const char *pool, *name, *conf, *clientname, *keypairs; + const char *pool, *image_name, *conf, *user, *keypairs; const char *secretid; rados_t cluster; rados_ioctx_t io_ctx; @@ -393,11 +393,11 @@ static int qemu_rbd_create(const char *filename, Qemu= Opts *opts, Error **errp) */ pool =3D qdict_get_try_str(options, "pool"); conf =3D qdict_get_try_str(options, "conf"); - clientname =3D qdict_get_try_str(options, "user"); - name =3D qdict_get_try_str(options, "image"); + user =3D qdict_get_try_str(options, "user"); + image_name =3D qdict_get_try_str(options, "image"); keypairs =3D qdict_get_try_str(options, "=3Dkeyvalue-pairs"); =20 - ret =3D rados_create(&cluster, clientname); + ret =3D rados_create(&cluster, user); if (ret < 0) { error_setg_errno(errp, -ret, "error initializing"); goto exit; @@ -434,7 +434,7 @@ static int qemu_rbd_create(const char *filename, QemuOp= ts *opts, Error **errp) goto shutdown; } =20 - ret =3D rbd_create(io_ctx, name, bytes, &obj_order); + ret =3D rbd_create(io_ctx, image_name, bytes, &obj_order); if (ret < 0) { error_setg_errno(errp, -ret, "error rbd create"); } @@ -540,7 +540,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *o= ptions, int flags, Error **errp) { BDRVRBDState *s =3D bs->opaque; - const char *pool, *snap, *conf, *clientname, *name, *keypairs; + const char *pool, *snap, *conf, *user, *image_name, *keypairs; const char *secretid; QemuOpts *opts; Error *local_err =3D NULL; @@ -567,24 +567,24 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict = *options, int flags, pool =3D qemu_opt_get(opts, "pool"); conf =3D qemu_opt_get(opts, "conf"); snap =3D qemu_opt_get(opts, "snapshot"); - clientname =3D qemu_opt_get(opts, "user"); - name =3D qemu_opt_get(opts, "image"); + user =3D qemu_opt_get(opts, "user"); + image_name =3D qemu_opt_get(opts, "image"); keypairs =3D qemu_opt_get(opts, "=3Dkeyvalue-pairs"); =20 - if (!pool || !name) { + if (!pool || !image_name) { error_setg(errp, "Parameters 'pool' and 'image' are required"); r =3D -EINVAL; goto failed_opts; } =20 - r =3D rados_create(&s->cluster, clientname); + r =3D rados_create(&s->cluster, user); if (r < 0) { error_setg_errno(errp, -r, "error initializing"); goto failed_opts; } =20 s->snap =3D g_strdup(snap); - s->name =3D g_strdup(name); + s->image_name =3D g_strdup(image_name); =20 /* try default location when conf=3DNULL, but ignore failure */ r =3D rados_conf_read_file(s->cluster, conf); @@ -636,9 +636,10 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *= options, int flags, } =20 /* rbd_open is always r/w */ - r =3D rbd_open(s->io_ctx, s->name, &s->image, s->snap); + r =3D rbd_open(s->io_ctx, s->image_name, &s->image, s->snap); if (r < 0) { - error_setg_errno(errp, -r, "error reading header from %s", s->name= ); + error_setg_errno(errp, -r, "error reading header from %s", + s->image_name); goto failed_open; } =20 @@ -660,7 +661,7 @@ failed_open: failed_shutdown: rados_shutdown(s->cluster); g_free(s->snap); - g_free(s->name); + g_free(s->image_name); failed_opts: qemu_opts_del(opts); g_free(mon_host); @@ -674,7 +675,7 @@ static void qemu_rbd_close(BlockDriverState *bs) rbd_close(s->image); rados_ioctx_destroy(s->io_ctx); g_free(s->snap); - g_free(s->name); + g_free(s->image_name); rados_shutdown(s->cluster); } =20 --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14927828677901002.8695118078113; Fri, 21 Apr 2017 06:54:27 -0700 (PDT) Received: from localhost ([::1]:59783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Z10-0002YS-CS for importer@patchew.org; Fri, 21 Apr 2017 09:54:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yts-00054s-Bp for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ytr-0002TU-GH for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44324) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytn-0002Ry-QC; Fri, 21 Apr 2017 09:46:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B03168E69D; Fri, 21 Apr 2017 13:46:58 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0571077FC5; Fri, 21 Apr 2017 13:46:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B03168E69D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B03168E69D From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:43 -0400 Message-Id: <20170421134644.10239-12-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Apr 2017 13:46:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/12] block/rbd: Add support for reopen() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This adds support for reopen in rbd, for changing between r/w and r/o. Note, that this is only a flag change, but we will block a change from r/o to r/w if we are using an RBD internal snapshot. Reviewed-by: Stefan Hajnoczi Signed-off-by: Jeff Cody Reviewed-by: John Snow Message-id: d4e87539167ec6527d44c97b164eabcccf96e4f3.1491597120.git.jcody@r= edhat.com --- block/rbd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/block/rbd.c b/block/rbd.c index 35853c9..6471f4f 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -668,6 +668,26 @@ failed_opts: return r; } =20 + +/* Since RBD is currently always opened R/W via the API, + * we just need to check if we are using a snapshot or not, in + * order to determine if we will allow it to be R/W */ +static int qemu_rbd_reopen_prepare(BDRVReopenState *state, + BlockReopenQueue *queue, Error **errp) +{ + BDRVRBDState *s =3D state->bs->opaque; + int ret =3D 0; + + if (s->snap && state->flags & BDRV_O_RDWR) { + error_setg(errp, + "Cannot change node '%s' to r/w when using RBD snapshot= ", + bdrv_get_device_or_node_name(state->bs)); + ret =3D -EINVAL; + } + + return ret; +} + static void qemu_rbd_close(BlockDriverState *bs) { BDRVRBDState *s =3D bs->opaque; @@ -1074,6 +1094,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_parse_filename =3D qemu_rbd_parse_filename, .bdrv_file_open =3D qemu_rbd_open, .bdrv_close =3D qemu_rbd_close, + .bdrv_reopen_prepare =3D qemu_rbd_reopen_prepare, .bdrv_create =3D qemu_rbd_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_get_info =3D qemu_rbd_getinfo, --=20 2.9.3 From nobody Wed May 1 03:56:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492783155422326.6565701158131; Fri, 21 Apr 2017 06:59:15 -0700 (PDT) Received: from localhost ([::1]:59816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Z5e-0006pH-40 for importer@patchew.org; Fri, 21 Apr 2017 09:59:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Yu2-0005HE-MJ for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Yu1-0002ap-Jo for qemu-devel@nongnu.org; Fri, 21 Apr 2017 09:47:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1Ytp-0002SS-Ni; Fri, 21 Apr 2017 09:47:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 999CA345B27; Fri, 21 Apr 2017 13:47:00 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9693977FCB; Fri, 21 Apr 2017 13:46:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 999CA345B27 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 999CA345B27 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 21 Apr 2017 09:46:44 -0400 Message-Id: <20170421134644.10239-13-jcody@redhat.com> In-Reply-To: <20170421134644.10239-1-jcody@redhat.com> References: <20170421134644.10239-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 21 Apr 2017 13:47:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/12] qemu-iotests: _cleanup_qemu must be called on exit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For the tests that use the common.qemu functions for running a QEMU process, _cleanup_qemu must be called in the exit function. If it is not, if the qemu process aborts, then not all of the droppings are cleaned up (e.g. pidfile, fifos). This updates those tests that did not have a cleanup in qemu-iotests. (I swapped spaces for tabs in test 102 as well) Reported-by: Eric Blake Reviewed-by: Eric Blake Signed-off-by: Jeff Cody Message-id: d59c2f6ad6c1da8b9b3c7f357c94a7122ccfc55a.1492544096.git.jcody@r= edhat.com --- tests/qemu-iotests/028 | 1 + tests/qemu-iotests/094 | 11 ++++++++--- tests/qemu-iotests/102 | 5 +++-- tests/qemu-iotests/109 | 1 + tests/qemu-iotests/117 | 1 + tests/qemu-iotests/130 | 1 + tests/qemu-iotests/140 | 1 + tests/qemu-iotests/141 | 1 + tests/qemu-iotests/143 | 1 + tests/qemu-iotests/156 | 1 + 10 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/028 b/tests/qemu-iotests/028 index 7783e57..97a8869 100755 --- a/tests/qemu-iotests/028 +++ b/tests/qemu-iotests/028 @@ -32,6 +32,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu rm -f "${TEST_IMG}.copy" _cleanup_test_img } diff --git a/tests/qemu-iotests/094 b/tests/qemu-iotests/094 index 0ba0b0c..9aa01e3 100755 --- a/tests/qemu-iotests/094 +++ b/tests/qemu-iotests/094 @@ -27,7 +27,14 @@ echo "QA output created by $seq" here=3D"$PWD" status=3D1 # failure is the default! =20 -trap "exit \$status" 0 1 2 3 15 +_cleanup() +{ + _cleanup_qemu + _cleanup_test_img + rm -f "$TEST_DIR/source.$IMGFMT" +} + +trap "_cleanup; exit \$status" 0 1 2 3 15 =20 # get standard environment, filters and checks . ./common.rc @@ -73,8 +80,6 @@ _send_qemu_cmd $QEMU_HANDLE \ =20 wait=3D1 _cleanup_qemu =20 -_cleanup_test_img -rm -f "$TEST_DIR/source.$IMGFMT" =20 # success, all done echo '*** done' diff --git a/tests/qemu-iotests/102 b/tests/qemu-iotests/102 index 64b4af9..87db1bb 100755 --- a/tests/qemu-iotests/102 +++ b/tests/qemu-iotests/102 @@ -25,11 +25,12 @@ seq=3D$(basename $0) echo "QA output created by $seq" =20 here=3D$PWD -status=3D1 # failure is the default! +status=3D1 # failure is the default! =20 _cleanup() { - _cleanup_test_img + _cleanup_qemu + _cleanup_test_img } trap "_cleanup; exit \$status" 0 1 2 3 15 =20 diff --git a/tests/qemu-iotests/109 b/tests/qemu-iotests/109 index 927151a..6161633 100755 --- a/tests/qemu-iotests/109 +++ b/tests/qemu-iotests/109 @@ -29,6 +29,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu rm -f $TEST_IMG.src _cleanup_test_img } diff --git a/tests/qemu-iotests/117 b/tests/qemu-iotests/117 index e955d52..6c83461 100755 --- a/tests/qemu-iotests/117 +++ b/tests/qemu-iotests/117 @@ -29,6 +29,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu _cleanup_test_img } trap "_cleanup; exit \$status" 0 1 2 3 15 diff --git a/tests/qemu-iotests/130 b/tests/qemu-iotests/130 index f941fc9..e7e43de 100755 --- a/tests/qemu-iotests/130 +++ b/tests/qemu-iotests/130 @@ -31,6 +31,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu _cleanup_test_img } trap "_cleanup; exit \$status" 0 1 2 3 15 diff --git a/tests/qemu-iotests/140 b/tests/qemu-iotests/140 index 49f9df4..8c80a5a 100755 --- a/tests/qemu-iotests/140 +++ b/tests/qemu-iotests/140 @@ -33,6 +33,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu _cleanup_test_img rm -f "$TEST_DIR/nbd" } diff --git a/tests/qemu-iotests/141 b/tests/qemu-iotests/141 index 27fb1cc..40a3405 100755 --- a/tests/qemu-iotests/141 +++ b/tests/qemu-iotests/141 @@ -29,6 +29,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu _cleanup_test_img rm -f "$TEST_DIR/{b,m,o}.$IMGFMT" } diff --git a/tests/qemu-iotests/143 b/tests/qemu-iotests/143 index ec4ef22..5ff1944 100755 --- a/tests/qemu-iotests/143 +++ b/tests/qemu-iotests/143 @@ -29,6 +29,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu rm -f "$TEST_DIR/nbd" } trap "_cleanup; exit \$status" 0 1 2 3 15 diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156 index 78deaff..d799b73 100755 --- a/tests/qemu-iotests/156 +++ b/tests/qemu-iotests/156 @@ -37,6 +37,7 @@ status=3D1 # failure is the default! =20 _cleanup() { + _cleanup_qemu rm -f "$TEST_IMG{,.target}{,.backing,.overlay}" } trap "_cleanup; exit \$status" 0 1 2 3 15 --=20 2.9.3