Blame SOURCES/kvm-block-ssh-Propagate-errors-to-open-and-create-method.patch

05bba0
From 82480db1c89f2ac291e44c74274bd0b6a860a720 Mon Sep 17 00:00:00 2001
05bba0
From: Richard Jones <rjones@redhat.com>
05bba0
Date: Mon, 8 Jun 2015 11:56:59 +0200
05bba0
Subject: [PATCH 06/30] block/ssh: Propagate errors to open and create methods
05bba0
05bba0
Message-id: <1433764620-20506-6-git-send-email-rjones@redhat.com>
05bba0
Patchwork-id: 65482
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 5/6] block/ssh: Propagate errors to open and create methods
05bba0
Bugzilla: 1226683
05bba0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
05bba0
05bba0
From: Markus Armbruster <armbru@redhat.com>
05bba0
05bba0
Completes the conversion to Error started in commit 015a103^..d5124c0.
05bba0
05bba0
Signed-off-by: Markus Armbruster <armbru@redhat.com>
05bba0
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
05bba0
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
Upstream-status: 5496fb1aebb624b379a503a8b2a156922a275fa1
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/ssh.c | 47 ++++++++++++++++++++++-------------------------
05bba0
 1 file changed, 22 insertions(+), 25 deletions(-)
05bba0
05bba0
diff --git a/block/ssh.c b/block/ssh.c
05bba0
index 07f8a2c..3b4d9e7 100644
05bba0
--- a/block/ssh.c
05bba0
+++ b/block/ssh.c
05bba0
@@ -131,29 +131,34 @@ session_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...)
05bba0
     g_free(msg);
05bba0
 }
05bba0
 
05bba0
-/* Wrappers around error_report which make sure to dump as much
05bba0
- * information from libssh2 as possible.
05bba0
- */
05bba0
-static void GCC_FMT_ATTR(2, 3)
05bba0
-session_error_report(BDRVSSHState *s, const char *fs, ...)
05bba0
+static void GCC_FMT_ATTR(3, 4)
05bba0
+sftp_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...)
05bba0
 {
05bba0
     va_list args;
05bba0
+    char *msg;
05bba0
 
05bba0
     va_start(args, fs);
05bba0
-    error_vprintf(fs, args);
05bba0
+    msg = g_strdup_vprintf(fs, args);
05bba0
+    va_end(args);
05bba0
 
05bba0
-    if ((s)->session) {
05bba0
+    if (s->sftp) {
05bba0
         char *ssh_err;
05bba0
         int ssh_err_code;
05bba0
+        unsigned long sftp_err_code;
05bba0
 
05bba0
         /* This is not an errno.  See <libssh2.h>. */
05bba0
         ssh_err_code = libssh2_session_last_error(s->session,
05bba0
                                                   &ssh_err, NULL, 0);
05bba0
-        error_printf(": %s (libssh2 error code: %d)", ssh_err, ssh_err_code);
05bba0
-    }
05bba0
+        /* See <libssh2_sftp.h>. */
05bba0
+        sftp_err_code = libssh2_sftp_last_error((s)->sftp);
05bba0
 
05bba0
-    va_end(args);
05bba0
-    error_printf("\n");
05bba0
+        error_setg(errp,
05bba0
+                   "%s: %s (libssh2 error code: %d, sftp error code: %lu)",
05bba0
+                   msg, ssh_err, ssh_err_code, sftp_err_code);
05bba0
+    } else {
05bba0
+        error_setg(errp, "%s", msg);
05bba0
+    }
05bba0
+    g_free(msg);
05bba0
 }
05bba0
 
05bba0
 static void GCC_FMT_ATTR(2, 3)
05bba0
@@ -594,14 +599,14 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
05bba0
             path, ssh_flags, creat_mode);
05bba0
     s->sftp_handle = libssh2_sftp_open(s->sftp, path, ssh_flags, creat_mode);
05bba0
     if (!s->sftp_handle) {
05bba0
-        session_error_report(s, "failed to open remote file '%s'", path);
05bba0
+        session_error_setg(errp, s, "failed to open remote file '%s'", path);
05bba0
         ret = -EINVAL;
05bba0
         goto err;
05bba0
     }
05bba0
 
05bba0
     r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs);
05bba0
     if (r < 0) {
05bba0
-        sftp_error_report(s, "failed to read file attributes");
05bba0
+        sftp_error_setg(errp, s, "failed to read file attributes");
05bba0
         return -EINVAL;
05bba0
     }
05bba0
 
05bba0
@@ -639,7 +644,6 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
05bba0
 static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
05bba0
                          Error **errp)
05bba0
 {
05bba0
-    Error *local_err = NULL;
05bba0
     BDRVSSHState *s = bs->opaque;
05bba0
     int ret;
05bba0
     int ssh_flags;
05bba0
@@ -652,10 +656,8 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
05bba0
     }
05bba0
 
05bba0
     /* Start up SSH. */
05bba0
-    ret = connect_to_ssh(s, options, ssh_flags, 0, &local_err);
05bba0
+    ret = connect_to_ssh(s, options, ssh_flags, 0, errp);
05bba0
     if (ret < 0) {
05bba0
-        qerror_report_err(local_err);
05bba0
-        error_free(local_err);
05bba0
         goto err;
05bba0
     }
05bba0
 
05bba0
@@ -686,7 +688,6 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
05bba0
                       Error **errp)
05bba0
 {
05bba0
     int r, ret;
05bba0
-    Error *local_err = NULL;
05bba0
     int64_t total_size = 0;
05bba0
     QDict *uri_options = NULL;
05bba0
     BDRVSSHState s;
05bba0
@@ -705,10 +706,8 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
05bba0
     DPRINTF("total_size=%" PRIi64, total_size);
05bba0
 
05bba0
     uri_options = qdict_new();
05bba0
-    r = parse_uri(filename, uri_options, &local_err);
05bba0
+    r = parse_uri(filename, uri_options, errp);
05bba0
     if (r < 0) {
05bba0
-        qerror_report_err(local_err);
05bba0
-        error_free(local_err);
05bba0
         ret = r;
05bba0
         goto out;
05bba0
     }
05bba0
@@ -716,10 +715,8 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
05bba0
     r = connect_to_ssh(&s, uri_options,
05bba0
                        LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE|
05bba0
                        LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
05bba0
-                       0644, &local_err);
05bba0
+                       0644, errp);
05bba0
     if (r < 0) {
05bba0
-        qerror_report_err(local_err);
05bba0
-        error_free(local_err);
05bba0
         ret = r;
05bba0
         goto out;
05bba0
     }
05bba0
@@ -728,7 +725,7 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
05bba0
         libssh2_sftp_seek64(s.sftp_handle, total_size-1);
05bba0
         r2 = libssh2_sftp_write(s.sftp_handle, c, 1);
05bba0
         if (r2 < 0) {
05bba0
-            sftp_error_report(&s, "truncate failed");
05bba0
+            sftp_error_setg(errp, &s, "truncate failed");
05bba0
             ret = -EINVAL;
05bba0
             goto out;
05bba0
         }
05bba0
-- 
05bba0
1.8.3.1
05bba0