ssh: Pass BlockdevOptionsSsh to connect_to_ssh()
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 <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
ec2f54182c
commit
375f0b9266
34
block/ssh.c
34
block/ssh.c
@ -656,19 +656,13 @@ fail:
|
|||||||
return result;
|
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)
|
int ssh_flags, int creat_mode, Error **errp)
|
||||||
{
|
{
|
||||||
BlockdevOptionsSsh *opts;
|
|
||||||
int r, ret;
|
int r, ret;
|
||||||
const char *user;
|
const char *user;
|
||||||
long port = 0;
|
long port = 0;
|
||||||
|
|
||||||
opts = ssh_parse_options(options, errp);
|
|
||||||
if (opts == NULL) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts->has_user) {
|
if (opts->has_user) {
|
||||||
user = opts->user;
|
user = opts->user;
|
||||||
} else {
|
} else {
|
||||||
@ -748,8 +742,6 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
qapi_free_BlockdevOptionsSsh(opts);
|
|
||||||
|
|
||||||
r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs);
|
r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
sftp_error_setg(errp, s, "failed to read file attributes");
|
sftp_error_setg(errp, s, "failed to read file attributes");
|
||||||
@ -775,8 +767,6 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
|
|||||||
}
|
}
|
||||||
s->session = NULL;
|
s->session = NULL;
|
||||||
|
|
||||||
qapi_free_BlockdevOptionsSsh(opts);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -784,6 +774,7 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
|
|||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
BDRVSSHState *s = bs->opaque;
|
BDRVSSHState *s = bs->opaque;
|
||||||
|
BlockdevOptionsSsh *opts;
|
||||||
int ret;
|
int ret;
|
||||||
int ssh_flags;
|
int ssh_flags;
|
||||||
|
|
||||||
@ -794,8 +785,13 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
|
|||||||
ssh_flags |= LIBSSH2_FXF_WRITE;
|
ssh_flags |= LIBSSH2_FXF_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opts = ssh_parse_options(options, errp);
|
||||||
|
if (opts == NULL) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Start up SSH. */
|
/* 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) {
|
if (ret < 0) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -803,6 +799,8 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
|
|||||||
/* Go non-blocking. */
|
/* Go non-blocking. */
|
||||||
libssh2_session_set_blocking(s->session, 0);
|
libssh2_session_set_blocking(s->session, 0);
|
||||||
|
|
||||||
|
qapi_free_BlockdevOptionsSsh(opts);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
@ -811,6 +809,8 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
|
|||||||
}
|
}
|
||||||
s->sock = -1;
|
s->sock = -1;
|
||||||
|
|
||||||
|
qapi_free_BlockdevOptionsSsh(opts);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -860,6 +860,7 @@ static int coroutine_fn ssh_co_create_opts(const char *filename, QemuOpts *opts,
|
|||||||
int r, ret;
|
int r, ret;
|
||||||
int64_t total_size = 0;
|
int64_t total_size = 0;
|
||||||
QDict *uri_options = NULL;
|
QDict *uri_options = NULL;
|
||||||
|
BlockdevOptionsSsh *ssh_opts = NULL;
|
||||||
BDRVSSHState s;
|
BDRVSSHState s;
|
||||||
|
|
||||||
ssh_state_init(&s);
|
ssh_state_init(&s);
|
||||||
@ -876,7 +877,13 @@ static int coroutine_fn ssh_co_create_opts(const char *filename, QemuOpts *opts,
|
|||||||
goto out;
|
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_READ|LIBSSH2_FXF_WRITE|
|
||||||
LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
|
||||||
0644, errp);
|
0644, errp);
|
||||||
@ -899,6 +906,7 @@ static int coroutine_fn ssh_co_create_opts(const char *filename, QemuOpts *opts,
|
|||||||
if (uri_options != NULL) {
|
if (uri_options != NULL) {
|
||||||
QDECREF(uri_options);
|
QDECREF(uri_options);
|
||||||
}
|
}
|
||||||
|
qapi_free_BlockdevOptionsSsh(ssh_opts);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user