aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2020-07-17 14:58:13 +0100
committerPeter Maydell <peter.maydell@linaro.org>2020-07-17 14:58:13 +0100
commit920d213cb22a4b8d1a7c941da1955b45c5fd9a09 (patch)
tree5e5d1be052bfe97a91ce7948f80da0ff79fc29f7 /block
parentb7bda69c4ef46c57480f6e378923f5215b122778 (diff)
parenta8c5cf27c945d392edd85b0b0c64cd5c52cae658 (diff)
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches: - file-posix: Fix read-only Linux block devices with auto-read-only - Require aligned image size with O_DIRECT to avoid assertion failure - Allow byte-aligned direct I/O on NFS instead of guessing 4k alignment - Fix nbd_export_close_all() crash - Fix race in iotests case 030 - qemu-img resize: Require --shrink for shrinking all image formats - crypto: use a stronger private key for tests - Remove VXHS block device - MAINTAINERS: vvfat: set status to odd fixes # gpg: Signature made Fri 17 Jul 2020 13:31:18 BST # gpg: using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6 # gpg: issuer "kwolf@redhat.com" # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * remotes/kevin/tags/for-upstream: file-posix: Fix leaked fd in raw_open_common() error path file-posix: Fix check_hdev_writable() with auto-read-only file-posix: Move check_hdev_writable() up file-posix: Allow byte-aligned O_DIRECT with NFS block: Require aligned image size to avoid assertion failure iotests: test shutdown when bitmap is exported through NBD nbd: make nbd_export_close_all() synchronous iotests/030: Reduce job speed to make race less likely crypto: use a stronger private key for tests qemu-img resize: Require --shrink for shrinking all image formats Remove VXHS block device vvfat: set status to odd fixes Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'block')
-rw-r--r--block/Makefile.objs2
-rw-r--r--block/file-posix.c122
-rw-r--r--block/trace-events17
-rw-r--r--block/vxhs.c587
4 files changed, 79 insertions, 649 deletions
diff --git a/block/Makefile.objs b/block/Makefile.objs
index 577e578bc2..19c6f371c9 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -31,7 +31,6 @@ block-obj-$(CONFIG_LIBNFS) += nfs.o
block-obj-$(CONFIG_CURL) += curl.o
block-obj-$(CONFIG_RBD) += rbd.o
block-obj-$(CONFIG_GLUSTERFS) += gluster.o
-block-obj-$(CONFIG_VXHS) += vxhs.o
block-obj-$(CONFIG_LIBSSH) += ssh.o
block-obj-y += accounting.o dirty-bitmap.o
block-obj-y += write-threshold.o
@@ -61,7 +60,6 @@ rbd.o-cflags := $(RBD_CFLAGS)
rbd.o-libs := $(RBD_LIBS)
gluster.o-cflags := $(GLUSTERFS_CFLAGS)
gluster.o-libs := $(GLUSTERFS_LIBS)
-vxhs.o-libs := $(VXHS_LIBS)
ssh.o-cflags := $(LIBSSH_CFLAGS)
ssh.o-libs := $(LIBSSH_LIBS)
block-obj-dmg-bz2-$(CONFIG_BZIP2) += dmg-bz2.o
diff --git a/block/file-posix.c b/block/file-posix.c
index 8067e238cb..8cc39a1ef6 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -62,10 +62,12 @@
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/syscall.h>
+#include <sys/vfs.h>
#include <linux/cdrom.h>
#include <linux/fd.h>
#include <linux/fs.h>
#include <linux/hdreg.h>
+#include <linux/magic.h>
#include <scsi/sg.h>
#ifdef __s390__
#include <asm/dasd.h>
@@ -300,6 +302,28 @@ static int probe_physical_blocksize(int fd, unsigned int *blk_size)
#endif
}
+/*
+ * Returns true if no alignment restrictions are necessary even for files
+ * opened with O_DIRECT.
+ *
+ * raw_probe_alignment() probes the required alignment and assume that 1 means
+ * the probing failed, so it falls back to a safe default of 4k. This can be
+ * avoided if we know that byte alignment is okay for the file.
+ */
+static bool dio_byte_aligned(int fd)
+{
+#ifdef __linux__
+ struct statfs buf;
+ int ret;
+
+ ret = fstatfs(fd, &buf);
+ if (ret == 0 && buf.f_type == NFS_SUPER_MAGIC) {
+ return true;
+ }
+#endif
+ return false;
+}
+
/* Check if read is allowed with given memory buffer and length.
*
* This function is used to check O_DIRECT memory buffer and request alignment.
@@ -401,6 +425,39 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
}
}
+static int check_hdev_writable(int fd)
+{
+#if defined(BLKROGET)
+ /* Linux block devices can be configured "read-only" using blockdev(8).
+ * This is independent of device node permissions and therefore open(2)
+ * with O_RDWR succeeds. Actual writes fail with EPERM.
+ *
+ * bdrv_open() is supposed to fail if the disk is read-only. Explicitly
+ * check for read-only block devices so that Linux block devices behave
+ * properly.
+ */
+ struct stat st;
+ int readonly = 0;
+
+ if (fstat(fd, &st)) {
+ return -errno;
+ }
+
+ if (!S_ISBLK(st.st_mode)) {
+ return 0;
+ }
+
+ if (ioctl(fd, BLKROGET, &readonly) < 0) {
+ return -errno;
+ }
+
+ if (readonly) {
+ return -EACCES;
+ }
+#endif /* defined(BLKROGET) */
+ return 0;
+}
+
static void raw_parse_flags(int bdrv_flags, int *open_flags, bool has_writers)
{
bool read_write = false;
@@ -585,6 +642,15 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
}
s->fd = fd;
+ /* Check s->open_flags rather than bdrv_flags due to auto-read-only */
+ if (s->open_flags & O_RDWR) {
+ ret = check_hdev_writable(s->fd);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "The device is not writable");
+ goto fail;
+ }
+ }
+
s->perm = 0;
s->shared_perm = BLK_PERM_ALL;
@@ -629,7 +695,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
s->has_discard = true;
s->has_write_zeroes = true;
- if ((bs->open_flags & BDRV_O_NOCACHE) != 0) {
+ if ((bs->open_flags & BDRV_O_NOCACHE) != 0 && !dio_byte_aligned(s->fd)) {
s->needs_alignment = true;
}
@@ -707,6 +773,9 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
}
ret = 0;
fail:
+ if (ret < 0 && s->fd != -1) {
+ qemu_close(s->fd);
+ }
if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) {
unlink(filename);
}
@@ -977,6 +1046,15 @@ static int raw_reconfigure_getfd(BlockDriverState *bs, int flags,
}
}
+ if (fd != -1 && (*open_flags & O_RDWR)) {
+ ret = check_hdev_writable(fd);
+ if (ret < 0) {
+ qemu_close(fd);
+ error_setg_errno(errp, -ret, "The device is not writable");
+ return -1;
+ }
+ }
+
return fd;
}
@@ -3299,39 +3377,6 @@ static int hdev_probe_device(const char *filename)
return 0;
}
-static int check_hdev_writable(BDRVRawState *s)
-{
-#if defined(BLKROGET)
- /* Linux block devices can be configured "read-only" using blockdev(8).
- * This is independent of device node permissions and therefore open(2)
- * with O_RDWR succeeds. Actual writes fail with EPERM.
- *
- * bdrv_open() is supposed to fail if the disk is read-only. Explicitly
- * check for read-only block devices so that Linux block devices behave
- * properly.
- */
- struct stat st;
- int readonly = 0;
-
- if (fstat(s->fd, &st)) {
- return -errno;
- }
-
- if (!S_ISBLK(st.st_mode)) {
- return 0;
- }
-
- if (ioctl(s->fd, BLKROGET, &readonly) < 0) {
- return -errno;
- }
-
- if (readonly) {
- return -EACCES;
- }
-#endif /* defined(BLKROGET) */
- return 0;
-}
-
static void hdev_parse_filename(const char *filename, QDict *options,
Error **errp)
{
@@ -3454,15 +3499,6 @@ hdev_open_Mac_error:
/* Since this does ioctl the device must be already opened */
bs->sg = hdev_is_sg(bs);
- if (flags & BDRV_O_RDWR) {
- ret = check_hdev_writable(s);
- if (ret < 0) {
- raw_close(bs);
- error_setg_errno(errp, -ret, "The device is not writable");
- return ret;
- }
- }
-
return ret;
}
diff --git a/block/trace-events b/block/trace-events
index dbe76a7613..d3533ca896 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -136,23 +136,6 @@ qed_aio_write_prefill(void *s, void *acb, uint64_t start, size_t len, uint64_t o
qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_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 len) "s %p acb %p ret %d offset %"PRIu64" len %zu"
-# 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 = %d size = %"PRIu64" offset = %"PRIu64" ACB = %p. Error = %d, errno = %d"
-vxhs_get_vdisk_stat_err(char *guid, int ret, int err) "vDisk (%s) stat ioctl failed, ret = %d, errno = %d"
-vxhs_get_vdisk_stat(char *vdisk_guid, uint64_t vdisk_size) "vDisk %s stat ioctl returned size %"PRIu64
-vxhs_complete_aio(void *acb, uint64_t ret) "aio failed acb %p ret %"PRIu64
-vxhs_parse_uri_filename(const char *filename) "URI passed via bdrv_parse_filename %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 BDRVVXHSState"
-vxhs_open_iio_open(const char *host) "Failed to connect to storage agent on 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 *client_cert) "cacert %s, client_key %s, client_cert %s"
-
# nvme.c
nvme_kick(void *s, int queue) "s %p queue %d"
nvme_dma_flush_queue_wait(void *s) "s %p"
diff --git a/block/vxhs.c b/block/vxhs.c
deleted file mode 100644
index dc0e254730..0000000000
--- a/block/vxhs.c
+++ /dev/null
@@ -1,587 +0,0 @@
-/*
- * 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 later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#include "qemu/osdep.h"
-#include <qnio/qnio_api.h>
-#include <sys/param.h>
-#include "block/block_int.h"
-#include "block/qdict.h"
-#include "qapi/qmp/qerror.h"
-#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qstring.h"
-#include "trace.h"
-#include "qemu/module.h"
-#include "qemu/uri.h"
-#include "qapi/error.h"
-#include "qemu/uuid.h"
-#include "crypto/tlscredsx509.h"
-#include "sysemu/replay.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 = opaque;
- BlockCompletionFunc *cb = acb->common.cb;
- void *cb_opaque = acb->common.opaque;
- int ret = 0;
-
- if (acb->err != 0) {
- trace_vxhs_complete_aio(acb, acb->err);
- ret = (-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 = 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 = ctx;
- } else {
- trace_vxhs_iio_callback(error);
- goto out;
- }
-
- if (error) {
- if (!acb->err) {
- acb->err = error;
- }
- trace_vxhs_iio_callback(error);
- }
-
- replay_bh_schedule_oneshot_event(bdrv_get_aio_context(acb->common.bs),
- vxhs_complete_aio_bh, acb);
- break;
-
- default:
- if (error == 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 = {
- .name = "vxhs",
- .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
- .desc = {
- {
- .name = VXHS_OPT_FILENAME,
- .type = QEMU_OPT_STRING,
- .help = "URI to the Veritas HyperScale image",
- },
- {
- .name = VXHS_OPT_VDISK_ID,
- .type = QEMU_OPT_STRING,
- .help = "UUID of the VxHS vdisk",
- },
- {
- .name = "tls-creds",
- .type = QEMU_OPT_STRING,
- .help = "ID of the TLS/SSL credentials to use",
- },
- { /* end of list */ }
- },
-};
-
-static QemuOptsList runtime_tcp_opts = {
- .name = "vxhs_tcp",
- .head = QTAILQ_HEAD_INITIALIZER(runtime_tcp_opts.head),
- .desc = {
- {
- .name = VXHS_OPT_HOST,
- .type = QEMU_OPT_STRING,
- .help = "host address (ipv4 addresses)",
- },
- {
- .name = VXHS_OPT_PORT,
- .type = QEMU_OPT_NUMBER,
- .help = "port number on which VxHSD is listening (default 9999)",
- .def_value_str = "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 = NULL;
- char *port;
- int ret = 0;
-
- trace_vxhs_parse_uri_filename(filename);
- uri = uri_parse(filename);
- if (!uri || !uri->server || !uri->path) {
- uri_free(uri);
- return -EINVAL;
- }
-
- qdict_put_str(options, VXHS_OPT_SERVER ".host", uri->server);
-
- if (uri->port) {
- port = g_strdup_printf("%d", uri->port);
- qdict_put_str(options, VXHS_OPT_SERVER ".port", port);
- g_free(port);
- }
-
- qdict_put_str(options, "vdisk-id", 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 specified "
- "at the same time");
- return;
- }
-
- if (strstr(filename, "://")) {
- int ret = vxhs_parse_uri(filename, options);
- if (ret < 0) {
- error_setg(errp, "Invalid URI. URI should be of the form "
- " vxhs://<host_ip>:<port>/<vdisk-id>");
- }
- }
-}
-
-static void vxhs_refresh_limits(BlockDriverState *bs, Error **errp)
-{
- /* XXX Does VXHS support AIO on less than 512-byte alignment? */
- bs->bl.request_alignment = 512;
-}
-
-static int vxhs_init_and_ref(void)
-{
- if (vxhs_ref++ == 0) {
- if (iio_init(QNIO_VERSION, vxhs_iio_callback)) {
- return -ENODEV;
- }
- }
- return 0;
-}
-
-static void vxhs_unref(void)
-{
- if (--vxhs_ref == 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 = object_resolve_path_component(
- object_get_objects_root(), id);
-
- if (!obj) {
- error_setg(errp, "No TLS credentials with id '%s'",
- id);
- return;
- }
-
- creds_x509 = (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 = &creds_x509->parent_obj;
-
- if (creds->endpoint != 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 = g_strdup_printf("%s/%s", creds->dir,
- QCRYPTO_TLS_CREDS_X509_CA_CERT);
- *cert = g_strdup_printf("%s/%s", creds->dir,
- QCRYPTO_TLS_CREDS_X509_CLIENT_CERT);
- *key = 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 = bs->opaque;
- void *dev_handlep;
- QDict *backing_options = NULL;
- QemuOpts *opts = NULL;
- QemuOpts *tcp_opts = NULL;
- char *of_vsa_addr = NULL;
- Error *local_err = NULL;
- const char *vdisk_id_opt;
- const char *server_host_opt;
- int ret = 0;
- char *cacert = NULL;
- char *client_key = NULL;
- char *client_cert = NULL;
-
- ret = vxhs_init_and_ref();
- if (ret < 0) {
- ret = -EINVAL;
- goto out;
- }
-
- /* Create opts info from runtime_opts and runtime_tcp_opts list */
- opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
- tcp_opts = qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_abort);
-
- if (!qemu_opts_absorb_qdict(opts, options, errp)) {
- ret = -EINVAL;
- goto out;
- }
-
- /* vdisk-id is the disk UUID */
- vdisk_id_opt = qemu_opt_get(opts, VXHS_OPT_VDISK_ID);
- if (!vdisk_id_opt) {
- error_setg(errp, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID);
- ret = -EINVAL;
- goto out;
- }
-
- /* vdisk-id may contain a leading '/' */
- if (strlen(vdisk_id_opt) > UUID_FMT_LEN + 1) {
- error_setg(errp, "vdisk-id cannot be more than %d characters",
- UUID_FMT_LEN);
- ret = -EINVAL;
- goto out;
- }
-
- s->vdisk_guid = 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".");
-
- if (!qemu_opts_absorb_qdict(tcp_opts, backing_options, errp)) {
- ret = -EINVAL;
- goto out;
- }
-
- server_host_opt = qemu_opt_get(tcp_opts, VXHS_OPT_HOST);
- if (!server_host_opt) {
- error_setg(errp, QERR_MISSING_PARAMETER,
- VXHS_OPT_SERVER"."VXHS_OPT_HOST);
- ret = -EINVAL;
- goto out;
- }
-
- if (strlen(server_host_opt) > MAXHOSTNAMELEN) {
- error_setg(errp, "server.host cannot be more than %d characters",
- MAXHOSTNAMELEN);
- ret = -EINVAL;
- goto out;
- }
-
- /* check if we got tls-creds via the --object argument */
- s->tlscredsid = 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 != NULL) {
- ret = -EINVAL;
- goto out;
- }
- trace_vxhs_get_creds(cacert, client_key, client_cert);
- }
-
- s->vdisk_hostinfo.host = g_strdup(server_host_opt);
- s->vdisk_hostinfo.port = 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 = 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 = iio_open(of_vsa_addr, s->vdisk_guid, 0,
- cacert, client_key, client_cert);
- if (dev_handlep == NULL) {
- trace_vxhs_open_iio_open(of_vsa_addr);
- ret = -ENODEV;
- goto out;
- }
- s->vdisk_hostinfo.dev_handle = dev_handlep;
-
-out:
- g_free(of_vsa_addr);
- qobject_unref(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();
- g_free(s->vdisk_hostinfo.host);
- g_free(s->vdisk_guid);
- g_free(s->tlscredsid);
- s->vdisk_guid = NULL;
- }
-
- return ret;
-}
-
-static const AIOCBInfo vxhs_aiocb_info = {
- .aiocb_size = 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, uint64_t offset,
- QEMUIOVector *qiov, uint64_t size,
- BlockCompletionFunc *cb, void *opaque,
- VDISKAIOCmd iodir)
-{
- VXHSAIOCB *acb = NULL;
- BDRVVXHSState *s = bs->opaque;
- int iio_flags = 0;
- int ret = 0;
- void *dev_handle = s->vdisk_hostinfo.dev_handle;
-
- acb = qemu_aio_get(&vxhs_aiocb_info, bs, cb, opaque);
-
- /*
- * Initialize VXHSAIOCB.
- */
- acb->err = 0;
-
- iio_flags = IIO_FLAG_ASYNC;
-
- switch (iodir) {
- case VDISK_AIO_WRITE:
- ret = iio_writev(dev_handle, acb, qiov->iov, qiov->niov,
- offset, size, iio_flags);
- break;
- case VDISK_AIO_READ:
- ret = iio_readv(dev_handle, acb, qiov->iov, qiov->niov,
- offset, size, iio_flags);
- break;
- default:
- trace_vxhs_aio_rw_invalid(iodir);
- goto errout;
- }
-
- if (ret != 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_preadv(BlockDriverState *bs,
- uint64_t offset, uint64_t bytes,
- QEMUIOVector *qiov, int flags,
- BlockCompletionFunc *cb, void *opaque)
-{
- return vxhs_aio_rw(bs, offset, qiov, bytes, cb, opaque, VDISK_AIO_READ);
-}
-
-static BlockAIOCB *vxhs_aio_pwritev(BlockDriverState *bs,
- uint64_t offset, uint64_t bytes,
- QEMUIOVector *qiov, int flags,
- BlockCompletionFunc *cb, void *opaque)
-{
- return vxhs_aio_rw(bs, offset, qiov, bytes, cb, opaque, VDISK_AIO_WRITE);
-}
-
-static void vxhs_close(BlockDriverState *bs)
-{
- BDRVVXHSState *s = bs->opaque;
-
- trace_vxhs_close(s->vdisk_guid);
-
- g_free(s->vdisk_guid);
- s->vdisk_guid = NULL;
-
- /*
- * Close vDisk device
- */
- if (s->vdisk_hostinfo.dev_handle) {
- iio_close(s->vdisk_hostinfo.dev_handle);
- s->vdisk_hostinfo.dev_handle = NULL;
- }
-
- vxhs_unref();
-
- /*
- * Free the dynamically allocated host string etc
- */
- g_free(s->vdisk_hostinfo.host);
- g_free(s->tlscredsid);
- s->tlscredsid = NULL;
- s->vdisk_hostinfo.host = NULL;
- s->vdisk_hostinfo.port = 0;
-}
-
-static int64_t vxhs_get_vdisk_stat(BDRVVXHSState *s)
-{
- int64_t vdisk_size = -1;
- int ret = 0;
- void *dev_handle = s->vdisk_hostinfo.dev_handle;
-
- ret = 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 = bs->opaque;
- int64_t vdisk_size;
-
- vdisk_size = vxhs_get_vdisk_stat(s);
- if (vdisk_size < 0) {
- return -EIO;
- }
-
- return vdisk_size;
-}
-
-static const char *const vxhs_strong_runtime_opts[] = {
- VXHS_OPT_VDISK_ID,
- "tls-creds",
- VXHS_OPT_HOST,
- VXHS_OPT_PORT,
- VXHS_OPT_SERVER".",
-
- NULL
-};
-
-static BlockDriver bdrv_vxhs = {
- .format_name = "vxhs",
- .protocol_name = "vxhs",
- .instance_size = sizeof(BDRVVXHSState),
- .bdrv_file_open = vxhs_open,
- .bdrv_parse_filename = vxhs_parse_filename,
- .bdrv_refresh_limits = vxhs_refresh_limits,
- .bdrv_close = vxhs_close,
- .bdrv_getlength = vxhs_getlength,
- .bdrv_aio_preadv = vxhs_aio_preadv,
- .bdrv_aio_pwritev = vxhs_aio_pwritev,
- .strong_runtime_opts = vxhs_strong_runtime_opts,
-};
-
-static void bdrv_vxhs_init(void)
-{
- bdrv_register(&bdrv_vxhs);
-}
-
-block_init(bdrv_vxhs_init);