cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-ssh-Propagate-errors-through-connect_to_ssh.patch

9ae3a8
From bd7acae27a2bc4bc1a7865fdaeb30fd9c3a0430c Mon Sep 17 00:00:00 2001
9ae3a8
From: Richard Jones <rjones@redhat.com>
9ae3a8
Date: Mon, 8 Jun 2015 11:56:58 +0200
9ae3a8
Subject: [PATCH 05/30] block/ssh: Propagate errors through connect_to_ssh()
9ae3a8
9ae3a8
Message-id: <1433764620-20506-5-git-send-email-rjones@redhat.com>
9ae3a8
Patchwork-id: 65480
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm PATCH 4/6] block/ssh: Propagate errors through connect_to_ssh()
9ae3a8
Bugzilla: 1226683
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
Upstream-status: 5f0c39e59822fdfd6a730824eded06209942e495
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/ssh.c | 34 +++++++++++++++++-----------------
9ae3a8
 1 file changed, 17 insertions(+), 17 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/ssh.c b/block/ssh.c
9ae3a8
index 5908e6d..07f8a2c 100644
9ae3a8
--- a/block/ssh.c
9ae3a8
+++ b/block/ssh.c
9ae3a8
@@ -506,10 +506,9 @@ static int authenticate(BDRVSSHState *s, const char *user, Error **errp)
9ae3a8
 }
9ae3a8
 
9ae3a8
 static int connect_to_ssh(BDRVSSHState *s, QDict *options,
9ae3a8
-                          int ssh_flags, int creat_mode)
9ae3a8
+                          int ssh_flags, int creat_mode, Error **errp)
9ae3a8
 {
9ae3a8
     int r, ret;
9ae3a8
-    Error *err = NULL;
9ae3a8
     const char *host, *user, *path, *host_key_check;
9ae3a8
     int port;
9ae3a8
 
9ae3a8
@@ -528,6 +527,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
9ae3a8
     } else {
9ae3a8
         user = g_get_user_name();
9ae3a8
         if (!user) {
9ae3a8
+            error_setg_errno(errp, errno, "Can't get user name");
9ae3a8
             ret = -errno;
9ae3a8
             goto err;
9ae3a8
         }
9ae3a8
@@ -544,11 +544,9 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
9ae3a8
     s->hostport = g_strdup_printf("%s:%d", host, port);
9ae3a8
 
9ae3a8
     /* Open the socket and connect. */
9ae3a8
-    s->sock = inet_connect(s->hostport, &err;;
9ae3a8
-    if (err != NULL) {
9ae3a8
+    s->sock = inet_connect(s->hostport, errp);
9ae3a8
+    if (s->sock < 0) {
9ae3a8
         ret = -errno;
9ae3a8
-        qerror_report_err(err);
9ae3a8
-        error_free(err);
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -556,7 +554,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
9ae3a8
     s->session = libssh2_session_init();
9ae3a8
     if (!s->session) {
9ae3a8
         ret = -EINVAL;
9ae3a8
-        session_error_report(s, "failed to initialize libssh2 session");
9ae3a8
+        session_error_setg(errp, s, "failed to initialize libssh2 session");
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -567,30 +565,26 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
9ae3a8
     r = libssh2_session_handshake(s->session, s->sock);
9ae3a8
     if (r != 0) {
9ae3a8
         ret = -EINVAL;
9ae3a8
-        session_error_report(s, "failed to establish SSH session");
9ae3a8
+        session_error_setg(errp, s, "failed to establish SSH session");
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Check the remote host's key against known_hosts. */
9ae3a8
-    ret = check_host_key(s, host, port, host_key_check, &err;;
9ae3a8
+    ret = check_host_key(s, host, port, host_key_check, errp);
9ae3a8
     if (ret < 0) {
9ae3a8
-        qerror_report_err(err);
9ae3a8
-        error_free(err);
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Authenticate. */
9ae3a8
-    ret = authenticate(s, user, &err;;
9ae3a8
+    ret = authenticate(s, user, errp);
9ae3a8
     if (ret < 0) {
9ae3a8
-        qerror_report_err(err);
9ae3a8
-        error_free(err);
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Start SFTP. */
9ae3a8
     s->sftp = libssh2_sftp_init(s->session);
9ae3a8
     if (!s->sftp) {
9ae3a8
-        session_error_report(s, "failed to initialize sftp handle");
9ae3a8
+        session_error_setg(errp, s, "failed to initialize sftp handle");
9ae3a8
         ret = -EINVAL;
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
@@ -645,6 +639,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
9ae3a8
 static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
9ae3a8
                          Error **errp)
9ae3a8
 {
9ae3a8
+    Error *local_err = NULL;
9ae3a8
     BDRVSSHState *s = bs->opaque;
9ae3a8
     int ret;
9ae3a8
     int ssh_flags;
9ae3a8
@@ -657,8 +652,10 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags,
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Start up SSH. */
9ae3a8
-    ret = connect_to_ssh(s, options, ssh_flags, 0);
9ae3a8
+    ret = connect_to_ssh(s, options, ssh_flags, 0, &local_err);
9ae3a8
     if (ret < 0) {
9ae3a8
+        qerror_report_err(local_err);
9ae3a8
+        error_free(local_err);
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -718,8 +715,11 @@ static int ssh_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
 
9ae3a8
     r = connect_to_ssh(&s, uri_options,
9ae3a8
                        LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE|
9ae3a8
-                       LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, 0644);
9ae3a8
+                       LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
9ae3a8
+                       0644, &local_err);
9ae3a8
     if (r < 0) {
9ae3a8
+        qerror_report_err(local_err);
9ae3a8
+        error_free(local_err);
9ae3a8
         ret = r;
9ae3a8
         goto out;
9ae3a8
     }
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8