From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Markus Armbruster <armbru@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 23/33] block/ssh: Propagate errors to open and create methods
Date: Fri, 23 May 2014 17:41:55 +0200 [thread overview]
Message-ID: <1400859725-31879-24-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1400859725-31879-1-git-send-email-stefanha@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
Completes the conversion to Error started in commit 015a103^..d5124c0.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/ssh.c | 47 ++++++++++++++++++++++-------------------------
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/block/ssh.c b/block/ssh.c
index 26078c4..b212971 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -131,29 +131,34 @@ session_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...)
g_free(msg);
}
-/* Wrappers around error_report which make sure to dump as much
- * information from libssh2 as possible.
- */
-static void GCC_FMT_ATTR(2, 3)
-session_error_report(BDRVSSHState *s, const char *fs, ...)
+static void GCC_FMT_ATTR(3, 4)
+sftp_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...)
{
va_list args;
+ char *msg;
va_start(args, fs);
- error_vprintf(fs, args);
+ msg = g_strdup_vprintf(fs, args);
+ va_end(args);
- if ((s)->session) {
+ if (s->sftp) {
char *ssh_err;
int ssh_err_code;
+ unsigned long sftp_err_code;
/* This is not an errno. See <libssh2.h>. */
ssh_err_code = libssh2_session_last_error(s->session,
&ssh_err, NULL, 0);
- error_printf(": %s (libssh2 error code: %d)", ssh_err, ssh_err_code);
- }
+ /* See <libssh2_sftp.h>. */
+ sftp_err_code = libssh2_sftp_last_error((s)->sftp);
- va_end(args);
- error_printf("\n");
+ error_setg(errp,
+ "%s: %s (libssh2 error code: %d, sftp error code: %lu)",
+ msg, ssh_err, ssh_err_code, sftp_err_code);
+ } else {
+ error_setg(errp, "%s", msg);
+ }
+ g_free(msg);
}
static void GCC_FMT_ATTR(2, 3)
@@ -594,14 +599,14 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
path, ssh_flags, creat_mode);
s->sftp_handle = libssh2_sftp_open(s->sftp, path, ssh_flags, creat_mode);
if (!s->sftp_handle) {
- session_error_report(s, "failed to open remote file '%s'", path);
+ session_error_setg(errp, s, "failed to open remote file '%s'", path);
ret = -EINVAL;
goto err;
}
r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs);
if (r < 0) {
- sftp_error_report(s, "failed to read file attributes");
+ sftp_error_setg(errp, s, "failed to read file attributes");
return -EINVAL;
}
@@ -639,7 +644,6 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
Error **errp)
{
- Error *local_err = NULL;
BDRVSSHState *s = bs->opaque;
int ret;
int ssh_flags;
@@ -652,10 +656,8 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
}
/* Start up SSH. */
- ret = connect_to_ssh(s, options, ssh_flags, 0, &local_err);
+ ret = connect_to_ssh(s, options, ssh_flags, 0, errp);
if (ret < 0) {
- qerror_report_err(local_err);
- error_free(local_err);
goto err;
}
@@ -686,7 +688,6 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{
int r, ret;
- Error *local_err = NULL;
int64_t total_size = 0;
QDict *uri_options = NULL;
BDRVSSHState s;
@@ -705,10 +706,8 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
DPRINTF("total_size=%" PRIi64, total_size);
uri_options = qdict_new();
- r = parse_uri(filename, uri_options, &local_err);
+ r = parse_uri(filename, uri_options, errp);
if (r < 0) {
- qerror_report_err(local_err);
- error_free(local_err);
ret = r;
goto out;
}
@@ -716,10 +715,8 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
r = connect_to_ssh(&s, uri_options,
LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE|
LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
- 0644, &local_err);
+ 0644, errp);
if (r < 0) {
- qerror_report_err(local_err);
- error_free(local_err);
ret = r;
goto out;
}
@@ -728,7 +725,7 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
libssh2_sftp_seek64(s.sftp_handle, total_size-1);
r2 = libssh2_sftp_write(s.sftp_handle, c, 1);
if (r2 < 0) {
- sftp_error_report(&s, "truncate failed");
+ sftp_error_setg(errp, &s, "truncate failed");
ret = -EINVAL;
goto out;
}
--
1.9.0
next prev parent reply other threads:[~2014-05-23 15:43 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 15:41 [Qemu-devel] [PULL 00/33] Block patches Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 01/33] qemu-iotests: Handle cache mode option in 091 Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 02/33] QemuOpt: add unit tests Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 03/33] qcow2: Fix memory leak in COW error path Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 04/33] aio: Fix use-after-free in cancellation path Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 05/33] iotests: Use _img_info in test 089 Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 06/33] block: Add BlockOpType enum Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 07/33] block: Introduce op_blockers to BlockDriverState Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 08/33] block: Replace in_use with operation blocker Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 09/33] block: Move op_blocker check from block_job_create to its caller Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 10/33] block: Add bdrv_set_backing_hd() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 11/33] block: Use bdrv_set_backing_hd everywhere Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 12/33] block: Add backing_blocker in BlockDriverState Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 13/33] block: Drop redundant bdrv_refresh_limits Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 14/33] docs: Define refcount_bits value Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 15/33] blockdev: Don't use qerror_report_err() in drive_init() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 16/33] blockdev: Don't use qerror_report() in do_drive_del() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 17/33] qemu-nbd: Don't use qerror_report() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 18/33] block/rbd: Propagate errors to open and create methods Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 19/33] block/ssh: Drop superfluous libssh2_session_last_errno() calls Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 20/33] block/ssh: Propagate errors through check_host_key() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 21/33] block/ssh: Propagate errors through authenticate() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 22/33] block/ssh: Propagate errors through connect_to_ssh() Stefan Hajnoczi
2014-05-23 15:41 ` Stefan Hajnoczi [this message]
2014-05-23 15:41 ` [Qemu-devel] [PULL 24/33] block/vvfat: Propagate errors through enable_write_target() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 25/33] block/vvfat: Propagate errors through init_directories() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 26/33] block/sheepdog: Propagate errors through connect_to_sdog() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 27/33] block/sheepdog: Propagate errors through get_sheep_fd() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 28/33] block/sheepdog: Propagate errors through sd_prealloc() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 29/33] block/sheepdog: Propagate errors through do_sd_create() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 30/33] block/sheepdog: Propagate errors through find_vdi_name() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 31/33] block/sheepdog: Propagate errors to open and create methods Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 32/33] block/sheepdog: Fix silent sd_open(), sd_create() failures Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 33/33] block/sheepdog: Don't use qerror_report() Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400859725-31879-24-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=armbru@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).