thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-ssh-Do-not-report-read-write-flush-errors-to-t.patch

4ec855
From 2deb556f99ae439125674fa3c6d77424048fd30c Mon Sep 17 00:00:00 2001
4ec855
From: Pino Toscano <ptoscano@redhat.com>
4ec855
Date: Mon, 8 Jul 2019 15:25:53 +0100
4ec855
Subject: [PATCH 07/39] block/ssh: Do not report read/write/flush errors to the
4ec855
 user
4ec855
MIME-Version: 1.0
4ec855
Content-Type: text/plain; charset=UTF-8
4ec855
Content-Transfer-Encoding: 8bit
4ec855
4ec855
RH-Author: Pino Toscano <ptoscano@redhat.com>
4ec855
Message-id: <20190708152601.21123-3-ptoscano@redhat.com>
4ec855
Patchwork-id: 89418
4ec855
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v3 02/10] block/ssh: Do not report read/write/flush errors to the user
4ec855
Bugzilla: 1513367
4ec855
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4ec855
RH-Acked-by: Max Reitz <mreitz@redhat.com>
4ec855
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4ec855
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
4ec855
4ec855
From: Markus Armbruster <armbru@redhat.com>
4ec855
4ec855
Callbacks ssh_co_readv(), ssh_co_writev(), ssh_co_flush() report
4ec855
errors to the user with error_printf().  They shouldn't, it's their
4ec855
caller's job.  Replace by a suitable trace point.  While there, drop
4ec855
the unreachable !s->sftp case.
4ec855
4ec855
Perhaps we should convert this part of the block driver interface to
4ec855
Error, so block drivers can pass more detail to their callers.  Not
4ec855
today.
4ec855
4ec855
Cc: "Richard W.M. Jones" <rjones@redhat.com>
4ec855
Cc: Kevin Wolf <kwolf@redhat.com>
4ec855
Cc: Max Reitz <mreitz@redhat.com>
4ec855
Cc: qemu-block@nongnu.org
4ec855
Signed-off-by: Markus Armbruster <armbru@redhat.com>
4ec855
Reviewed-by: Eric Blake <eblake@redhat.com>
4ec855
Message-Id: <20190417190641.26814-3-armbru@redhat.com>
4ec855
(cherry picked from commit 6b3048cee0e0eccd27b62954ecc57c4a1bceb976)
4ec855
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 block/ssh.c        | 38 +++++++++++++-------------------------
4ec855
 block/trace-events |  3 +++
4ec855
 2 files changed, 16 insertions(+), 25 deletions(-)
4ec855
4ec855
diff --git a/block/ssh.c b/block/ssh.c
4ec855
index dfb3e3c..89abce0 100644
4ec855
--- a/block/ssh.c
4ec855
+++ b/block/ssh.c
4ec855
@@ -159,31 +159,19 @@ sftp_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...)
4ec855
     g_free(msg);
4ec855
 }
4ec855
 
4ec855
-static void GCC_FMT_ATTR(2, 3)
4ec855
-sftp_error_report(BDRVSSHState *s, const char *fs, ...)
4ec855
+static void sftp_error_trace(BDRVSSHState *s, const char *op)
4ec855
 {
4ec855
-    va_list args;
4ec855
-
4ec855
-    va_start(args, fs);
4ec855
-    error_vprintf(fs, args);
4ec855
+    char *ssh_err;
4ec855
+    int ssh_err_code;
4ec855
+    unsigned long sftp_err_code;
4ec855
 
4ec855
-    if ((s)->sftp) {
4ec855
-        char *ssh_err;
4ec855
-        int ssh_err_code;
4ec855
-        unsigned long sftp_err_code;
4ec855
+    /* This is not an errno.  See <libssh2.h>. */
4ec855
+    ssh_err_code = libssh2_session_last_error(s->session,
4ec855
+                                              &ssh_err, NULL, 0);
4ec855
+    /* See <libssh2_sftp.h>. */
4ec855
+    sftp_err_code = libssh2_sftp_last_error((s)->sftp);
4ec855
 
4ec855
-        /* This is not an errno.  See <libssh2.h>. */
4ec855
-        ssh_err_code = libssh2_session_last_error(s->session,
4ec855
-                                                  &ssh_err, NULL, 0);
4ec855
-        /* See <libssh2_sftp.h>. */
4ec855
-        sftp_err_code = libssh2_sftp_last_error((s)->sftp);
4ec855
-
4ec855
-        error_printf(": %s (libssh2 error code: %d, sftp error code: %lu)",
4ec855
-                     ssh_err, ssh_err_code, sftp_err_code);
4ec855
-    }
4ec855
-
4ec855
-    va_end(args);
4ec855
-    error_printf("\n");
4ec855
+    trace_sftp_error(op, ssh_err, ssh_err_code, sftp_err_code);
4ec855
 }
4ec855
 
4ec855
 static int parse_uri(const char *filename, QDict *options, Error **errp)
4ec855
@@ -1035,7 +1023,7 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs,
4ec855
             goto again;
4ec855
         }
4ec855
         if (r < 0) {
4ec855
-            sftp_error_report(s, "read failed");
4ec855
+            sftp_error_trace(s, "read");
4ec855
             s->offset = -1;
4ec855
             return -EIO;
4ec855
         }
4ec855
@@ -1105,7 +1093,7 @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs,
4ec855
             goto again;
4ec855
         }
4ec855
         if (r < 0) {
4ec855
-            sftp_error_report(s, "write failed");
4ec855
+            sftp_error_trace(s, "write");
4ec855
             s->offset = -1;
4ec855
             return -EIO;
4ec855
         }
4ec855
@@ -1186,7 +1174,7 @@ static coroutine_fn int ssh_flush(BDRVSSHState *s, BlockDriverState *bs)
4ec855
         return 0;
4ec855
     }
4ec855
     if (r < 0) {
4ec855
-        sftp_error_report(s, "fsync failed");
4ec855
+        sftp_error_trace(s, "fsync");
4ec855
         return -EIO;
4ec855
     }
4ec855
 
4ec855
diff --git a/block/trace-events b/block/trace-events
4ec855
index 4c69548..23c9963 100644
4ec855
--- a/block/trace-events
4ec855
+++ b/block/trace-events
4ec855
@@ -167,3 +167,6 @@ ssh_write(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu"
4ec855
 ssh_write_buf(void *buf, size_t size) "sftp_write buf=%p size=%zu"
4ec855
 ssh_write_return(ssize_t ret) "sftp_write returned %zd"
4ec855
 ssh_seek(int64_t offset) "seeking to offset=%" PRIi64
4ec855
+
4ec855
+# ssh.c
4ec855
+sftp_error(const char *op, const char *ssh_err, int ssh_err_code, unsigned long sftp_err_code) "%s failed: %s (libssh2 error code: %d, sftp error code: %lu)"
4ec855
-- 
4ec855
1.8.3.1
4ec855