From patchwork Wed May 28 12:32:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 353401 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D9DCA1400E3 for ; Wed, 28 May 2014 22:41:57 +1000 (EST) Received: from localhost ([::1]:41714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpdB5-0005GP-QA for incoming@patchwork.ozlabs.org; Wed, 28 May 2014 08:41:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wpd3H-0002lc-6h for qemu-devel@nongnu.org; Wed, 28 May 2014 08:33:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wpd39-0005aM-KZ for qemu-devel@nongnu.org; Wed, 28 May 2014 08:33:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wpd39-0005a7-BZ for qemu-devel@nongnu.org; Wed, 28 May 2014 08:33:43 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4SCXfow017027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 May 2014 08:33:41 -0400 Received: from localhost (ovpn-112-46.ams2.redhat.com [10.36.112.46]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s4SCXeh0021072; Wed, 28 May 2014 08:33:40 -0400 From: Stefan Hajnoczi To: Date: Wed, 28 May 2014 14:32:32 +0200 Message-Id: <1401280363-17417-23-git-send-email-stefanha@redhat.com> In-Reply-To: <1401280363-17417-1-git-send-email-stefanha@redhat.com> References: <1401280363-17417-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Markus Armbruster , Stefan Hajnoczi Subject: [Qemu-devel] [PULL v2 22/33] block/ssh: Propagate errors through connect_to_ssh() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Richard W.M. Jones Signed-off-by: Stefan Hajnoczi --- block/ssh.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 18186ba..26078c4 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -506,10 +506,9 @@ static int authenticate(BDRVSSHState *s, const char *user, Error **errp) } static int connect_to_ssh(BDRVSSHState *s, QDict *options, - int ssh_flags, int creat_mode) + int ssh_flags, int creat_mode, Error **errp) { int r, ret; - Error *err = NULL; const char *host, *user, *path, *host_key_check; int port; @@ -528,6 +527,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options, } else { user = g_get_user_name(); if (!user) { + error_setg_errno(errp, errno, "Can't get user name"); ret = -errno; goto err; } @@ -544,11 +544,9 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options, s->hostport = g_strdup_printf("%s:%d", host, port); /* Open the socket and connect. */ - s->sock = inet_connect(s->hostport, &err); - if (err != NULL) { + s->sock = inet_connect(s->hostport, errp); + if (s->sock < 0) { ret = -errno; - qerror_report_err(err); - error_free(err); goto err; } @@ -556,7 +554,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options, s->session = libssh2_session_init(); if (!s->session) { ret = -EINVAL; - session_error_report(s, "failed to initialize libssh2 session"); + session_error_setg(errp, s, "failed to initialize libssh2 session"); goto err; } @@ -567,30 +565,26 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options, r = libssh2_session_handshake(s->session, s->sock); if (r != 0) { ret = -EINVAL; - session_error_report(s, "failed to establish SSH session"); + session_error_setg(errp, s, "failed to establish SSH session"); goto err; } /* Check the remote host's key against known_hosts. */ - ret = check_host_key(s, host, port, host_key_check, &err); + ret = check_host_key(s, host, port, host_key_check, errp); if (ret < 0) { - qerror_report_err(err); - error_free(err); goto err; } /* Authenticate. */ - ret = authenticate(s, user, &err); + ret = authenticate(s, user, errp); if (ret < 0) { - qerror_report_err(err); - error_free(err); goto err; } /* Start SFTP. */ s->sftp = libssh2_sftp_init(s->session); if (!s->sftp) { - session_error_report(s, "failed to initialize sftp handle"); + session_error_setg(errp, s, "failed to initialize sftp handle"); ret = -EINVAL; goto err; } @@ -645,6 +639,7 @@ 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; @@ -657,8 +652,10 @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags, } /* Start up SSH. */ - ret = connect_to_ssh(s, options, ssh_flags, 0); + ret = connect_to_ssh(s, options, ssh_flags, 0, &local_err); if (ret < 0) { + qerror_report_err(local_err); + error_free(local_err); goto err; } @@ -718,8 +715,11 @@ 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); + LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, + 0644, &local_err); if (r < 0) { + qerror_report_err(local_err); + error_free(local_err); ret = r; goto out; }