From: Alexandre Ioffe Date: Tue, 23 Nov 2021 00:58:00 +0000 (-0800) Subject: EX-4218 lipe: Fix assertion in lipe_ssh_session_create X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=4ba9a8b235a9f34e8db665bcb7b5b56e38109725;p=fs%2Flustre-release.git EX-4218 lipe: Fix assertion in lipe_ssh_session_create Return SSH_ERROR code in all faulty cases Add reporting libssh return error code Signed-off-by: Alexandre Ioffe Test-Parameters: trivial testlist=hot-pools Change-Id: I84d5c3d1fe0e6d1c7818ec181a7b9ea07413eb8a Reviewed-on: https://review.whamcloud.com/45638 Tested-by: Maloo Reviewed-by: Jian Yu Tested-by: jenkins Reviewed-by: John L. Hammond Reviewed-on: https://review.whamcloud.com/46127 --- diff --git a/lipe/src/lipe_ssh.c b/lipe/src/lipe_ssh.c index ed510a3..a980dfe 100644 --- a/lipe/src/lipe_ssh.c +++ b/lipe/src/lipe_ssh.c @@ -24,22 +24,24 @@ static int lipe_ssh_session_start_cmd(ssh_session session, const char *cmd, ssh_ channel = ssh_channel_new(session); if (channel == NULL) { LX_ERROR("cannot create a new SSH channel: %s\n", - ssh_get_error(session)); + ssh_get_error(session)); rc = SSH_ERROR; goto out; } rc = ssh_channel_open_session(channel); if (rc != SSH_OK) { - LX_ERROR("cannot open SSH session channel: %s\n", - ssh_get_error(session)); + LX_ERROR("cannot open SSH session channel: %d: %s\n", + rc, ssh_get_error(session)); + rc = SSH_ERROR; goto out; } rc = ssh_channel_request_exec(channel, cmd); if (rc != SSH_OK) { - LX_ERROR("cannot execute SSH command: %s\n", - ssh_get_error(session)); + LX_ERROR("cannot execute SSH command: %d: %s\n", + rc, ssh_get_error(session)); + rc = SSH_ERROR; goto out; } @@ -67,11 +69,15 @@ static int lipe_ssh_session_exec_cmd(ssh_session session, const char *cmd, int * return rc; rc = ssh_channel_get_exit_status(channel); - if (rc < 0) + if (rc < 0) { + LX_ERROR("lipe_ssh_session_start_cmd failed: %d: %s\n", + rc, ssh_get_error(session)); + rc = SSH_ERROR; goto out; + } *pstatus = rc; - rc = 0; + rc = SSH_OK; out: ssh_channel_send_eof(channel); ssh_channel_close(channel); @@ -110,8 +116,8 @@ static int lipe_ssh_session_create(ssh_session *psession, const char *host) session = ssh_new(); if (session == NULL) { - LX_ERROR("cannot create a new SSH session: %s\n", - strerror(ENOMEM)); /* Probably. */ + LX_ERROR("cannot create a new SSH session: '%s'\n", + strerror(ENOMEM)); /* Probably. */ rc = SSH_ERROR; goto out; } @@ -123,31 +129,35 @@ static int lipe_ssh_session_create(ssh_session *psession, const char *host) rc = ssh_options_set(session, SSH_OPTIONS_HOST, host); if (rc != SSH_OK) { - LX_ERROR("cannot set SSH session host to '%s': %s\n", - host, ssh_get_error(session)); + LX_ERROR("cannot set SSH session host to '%s': %d: %s\n", + host, rc, ssh_get_error(session)); + rc = SSH_ERROR; goto out; } rc = ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &timeout); if (rc != SSH_OK) { - LX_ERROR("cannot set SSH timeout to %ld: %s\n", - timeout, ssh_get_error(session)); + LX_ERROR("cannot set SSH timeout to %ld: %d: %s\n", + timeout, rc, ssh_get_error(session)); + rc = SSH_ERROR; goto out; } /* Connect to the ssh server */ rc = ssh_connect(session); if (rc != SSH_OK) { - LX_ERROR("cannot connect SSH session to host '%s': %s\n", - host, ssh_get_error(session)); + LX_ERROR("cannot connect SSH session to host '%s': %d: %s\n", + host, rc, ssh_get_error(session)); + rc = SSH_ERROR; goto out; } /* Automatically authenticate with public key */ rc = ssh_userauth_publickey_auto(session, NULL, NULL); if (rc != SSH_AUTH_SUCCESS) { - LX_ERROR("cannot authenticate SSH session to host '%s': %s\n", - host, ssh_get_error(session)); + LX_ERROR("cannot authenticate SSH session to host '%s': %d: %s\n", + host, rc, ssh_get_error(session)); + rc = SSH_ERROR; goto out; }