[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 22/27] ssh: Pass BlockdevOptionsSsh to connect_to_ss
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 22/27] ssh: Pass BlockdevOptionsSsh to connect_to_ssh() |
Date: |
Thu, 8 Feb 2018 20:23:23 +0100 |
Move the parsing of the QDict options up to the callers, in preparation
for the .bdrv_co_create implementation that directly gets a QAPI type.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/ssh.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/block/ssh.c b/block/ssh.c
index d565d876d3..776d722353 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -652,19 +652,13 @@ fail:
return result;
}
-static int connect_to_ssh(BDRVSSHState *s, QDict *options,
+static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts,
int ssh_flags, int creat_mode, Error **errp)
{
- BlockdevOptionsSsh *opts;
int r, ret;
const char *user;
long port = 0;
- opts = ssh_parse_options(options, errp);
- if (opts == NULL) {
- return -EINVAL;
- }
-
if (opts->has_user) {
user = opts->user;
} else {
@@ -744,8 +738,6 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
goto err;
}
- qapi_free_BlockdevOptionsSsh(opts);
-
r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs);
if (r < 0) {
sftp_error_setg(errp, s, "failed to read file attributes");
@@ -771,8 +763,6 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
}
s->session = NULL;
- qapi_free_BlockdevOptionsSsh(opts);
-
return ret;
}
@@ -780,6 +770,7 @@ static int ssh_file_open(BlockDriverState *bs, QDict
*options, int bdrv_flags,
Error **errp)
{
BDRVSSHState *s = bs->opaque;
+ BlockdevOptionsSsh *opts;
int ret;
int ssh_flags;
@@ -790,8 +781,13 @@ static int ssh_file_open(BlockDriverState *bs, QDict
*options, int bdrv_flags,
ssh_flags |= LIBSSH2_FXF_WRITE;
}
+ opts = ssh_parse_options(options, errp);
+ if (opts == NULL) {
+ return -EINVAL;
+ }
+
/* Start up SSH. */
- ret = connect_to_ssh(s, options, ssh_flags, 0, errp);
+ ret = connect_to_ssh(s, opts, ssh_flags, 0, errp);
if (ret < 0) {
goto err;
}
@@ -799,6 +795,8 @@ static int ssh_file_open(BlockDriverState *bs, QDict
*options, int bdrv_flags,
/* Go non-blocking. */
libssh2_session_set_blocking(s->session, 0);
+ qapi_free_BlockdevOptionsSsh(opts);
+
return 0;
err:
@@ -807,6 +805,8 @@ static int ssh_file_open(BlockDriverState *bs, QDict
*options, int bdrv_flags,
}
s->sock = -1;
+ qapi_free_BlockdevOptionsSsh(opts);
+
return ret;
}
@@ -828,6 +828,7 @@ static int ssh_create(const char *filename, QemuOpts *opts,
Error **errp)
int r, ret;
int64_t total_size = 0;
QDict *uri_options = NULL;
+ BlockdevOptionsSsh *ssh_opts = NULL;
BDRVSSHState s;
ssize_t r2;
char c[1] = { '\0' };
@@ -846,7 +847,13 @@ static int ssh_create(const char *filename, QemuOpts
*opts, Error **errp)
goto out;
}
- r = connect_to_ssh(&s, uri_options,
+ ssh_opts = ssh_parse_options(uri_options, errp);
+ if (ssh_opts == NULL) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ r = connect_to_ssh(&s, ssh_opts,
LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE|
LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
0644, errp);
@@ -873,6 +880,7 @@ static int ssh_create(const char *filename, QemuOpts *opts,
Error **errp)
if (uri_options != NULL) {
QDECREF(uri_options);
}
+ qapi_free_BlockdevOptionsSsh(ssh_opts);
return ret;
}
--
2.13.6
- [Qemu-devel] [PATCH 17/27] nfs: Support .bdrv_co_create, (continued)
- [Qemu-devel] [PATCH 17/27] nfs: Support .bdrv_co_create, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 18/27] sheepdog: QAPIfy "redundacy" create option, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 19/27] sheepdog: Support .bdrv_co_create, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 20/27] ssh: Use QAPI BlockdevOptionsSsh object, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 21/27] ssh: QAPIfy host-key-check option, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 22/27] ssh: Pass BlockdevOptionsSsh to connect_to_ssh(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 24/27] file-posix: Fix no-op bdrv_truncate() with falloc preallocation, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 23/27] ssh: Support .bdrv_co_create, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 25/27] block: Fail bdrv_truncate() with negative size, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 26/27] qemu-iotests: Test qcow2 over file image creation with QMP, Kevin Wolf, 2018/02/08
- [Qemu-devel] [PATCH 27/27] qemu-iotests: Test ssh image creation over QMP, Kevin Wolf, 2018/02/08