mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
Switch Power Hypervisor to libssh2
* configure.in src/Makefile.am: change detection and flags * src/phyp/phyp_driver.c src/phyp/phyp_driver.h: connection now need to be done as part of the driver code, cleaned up by DV
This commit is contained in:
parent
02d9cef356
commit
191053b53d
52
configure.in
52
configure.in
@ -187,8 +187,8 @@ AC_ARG_WITH([uml],
|
||||
[ --with-uml add UML support (on)],[],[with_uml=check])
|
||||
AC_ARG_WITH([openvz],
|
||||
[ --with-openvz add OpenVZ support (on)],[],[with_openvz=yes])
|
||||
AC_ARG_WITH([libssh],
|
||||
[ --with-libssh=[PFX] libssh location],[],[with_libssh=yes])
|
||||
AC_ARG_WITH([libssh2],
|
||||
[ --with-libssh2=[PFX] libssh2 location],[],[with_libssh2=yes])
|
||||
AC_ARG_WITH([phyp],
|
||||
[ --with-phyp=[PFX] add PHYP support (on)],[],[with_phyp=check])
|
||||
AC_ARG_WITH([vbox],
|
||||
@ -866,45 +866,45 @@ dnl
|
||||
dnl libssh checks
|
||||
dnl
|
||||
|
||||
if test "$with_libssh" != "yes" -a "$with_libssh" != "no"; then
|
||||
libssh_path="$with_libssh"
|
||||
elif test "$with_libssh" = "yes"; then
|
||||
libssh_path="/usr/local/lib/"
|
||||
elif test "$with_libssh" = "no"; then
|
||||
if test "$with_libssh2" != "yes" -a "$with_libssh2" != "no"; then
|
||||
libssh2_path="$with_libssh2"
|
||||
elif test "$with_libssh2" = "yes"; then
|
||||
libssh2_path="/usr/local/lib/"
|
||||
elif test "$with_libssh2" = "no"; then
|
||||
with_phyp="no";
|
||||
fi
|
||||
|
||||
if test "$with_phyp" = "check"; then
|
||||
AC_CHECK_LIB([ssh],[ssh_new],[
|
||||
LIBSSH_LIBS="$LIBSSH_LIBS -lssh -L$libssh_path"
|
||||
AC_SUBST([LIBSSH_LIBS])],[
|
||||
AC_CHECK_LIB([ssh2],[libssh2_session_startup],[
|
||||
LIBSSH2_LIBS="$LIBSSH2_LIBS -lssh2 -L$libssh2_path"
|
||||
AC_SUBST([LIBSSH2_LIBS])],[
|
||||
with_phyp="no"
|
||||
with_libssh="no";
|
||||
with_libssh2="no";
|
||||
],[])
|
||||
|
||||
if test "$with_phyp" != "no"; then
|
||||
AC_CHECK_HEADERS([libssh/libssh.h],[
|
||||
AC_CHECK_HEADERS([libssh2.h],[
|
||||
with_phyp="yes"
|
||||
LIBSSH_CFLAGS="-I/usr/local/include/libssh"
|
||||
AC_SUBST([LIBSSH_CFLAGS])
|
||||
LIBSSH2_CFLAGS="-I/usr/local/include"
|
||||
AC_SUBST([LIBSSH2_CFLAGS])
|
||||
AC_DEFINE_UNQUOTED([WITH_PHYP], 1,
|
||||
[whether IBM HMC / IVM driver is enabled])
|
||||
],[
|
||||
with_phyp="no"
|
||||
with_libssh="no";
|
||||
with_libssh2="no";
|
||||
],[])
|
||||
fi
|
||||
elif test "$with_phyp" = "yes"; then
|
||||
AC_CHECK_LIB([ssh],[ssh_new],[
|
||||
LIBSSH_LIBS="$LIBSSH_LIBS -lssh -L$libssh_path"
|
||||
AC_SUBST([LIBSSH_LIBS])],[
|
||||
AC_MSG_ERROR([You must install the libssh to compile Phype driver.])
|
||||
AC_CHECK_LIB([ssh2],[libssh2_session_startup],[
|
||||
LIBSSH2_LIBS="$LIBSSH2_LIBS -lssh2 -L$libssh2_path"
|
||||
AC_SUBST([LIBSSH2_LIBS])],[
|
||||
AC_MSG_ERROR([You must install the libssh2 to compile Phype driver.])
|
||||
])
|
||||
|
||||
AC_CHECK_HEADERS([libssh/libssh.h],[
|
||||
LIBSSH_CFLAGS="-I/usr/local/include/libssh"
|
||||
AC_SUBST([LIBSSH_CFLAGS])],[
|
||||
AC_MSG_ERROR([Cannot find libssh headers.Is libssh installed ?])
|
||||
AC_CHECK_HEADERS([libssh2.h],[
|
||||
LIBSSH2_CFLAGS="-I/usr/local/include"
|
||||
AC_SUBST([LIBSSH2_CFLAGS])],[
|
||||
AC_MSG_ERROR([Cannot find libssh2 headers.Is libssh2 installed ?])
|
||||
],[])
|
||||
AC_DEFINE_UNQUOTED([WITH_PHYP], 1,
|
||||
[whether IBM HMC / IVM driver is enabled])
|
||||
@ -1699,10 +1699,10 @@ AC_MSG_NOTICE([ libcurl: $LIBCURL_CFLAGS $LIBCURL_LIBS])
|
||||
else
|
||||
AC_MSG_NOTICE([ libcurl: no])
|
||||
fi
|
||||
if test "$with_libssh" != "no" ; then
|
||||
AC_MSG_NOTICE([ libssh: $LIBSSH_CFLAGS $LIBSSH_LIBS])
|
||||
if test "$with_libssh2" != "no" ; then
|
||||
AC_MSG_NOTICE([ libssh2: $LIBSSH2_CFLAGS $LIBSSH2_LIBS])
|
||||
else
|
||||
AC_MSG_NOTICE([ libssh: no])
|
||||
AC_MSG_NOTICE([ libssh2: no])
|
||||
fi
|
||||
AC_MSG_NOTICE([ gnutls: $GNUTLS_CFLAGS $GNUTLS_LIBS])
|
||||
if test "$with_sasl" != "no" ; then
|
||||
|
@ -6,7 +6,7 @@ INCLUDES = \
|
||||
-I@top_srcdir@/include \
|
||||
-I@top_srcdir@/qemud \
|
||||
$(LIBXML_CFLAGS) \
|
||||
$(LIBSSH_CFLAGS) \
|
||||
$(LIBSSH2_CFLAGS) \
|
||||
$(XEN_CFLAGS) \
|
||||
$(SELINUX_CFLAGS) \
|
||||
$(DRIVER_MODULE_CFLAGS) \
|
||||
@ -308,8 +308,8 @@ else
|
||||
noinst_LTLIBRARIES += libvirt_driver_phyp.la
|
||||
libvirt_la_LIBADD += libvirt_driver_phyp.la
|
||||
endif
|
||||
libvirt_driver_phyp_la_LDFLAGS = $(LIBSSH_LIBS)
|
||||
libvirt_driver_phyp_la_CFLAGS = $(LIBSSH_CFLAGS)
|
||||
libvirt_driver_phyp_la_LDFLAGS = $(LIBSSH2_LIBS)
|
||||
libvirt_driver_phyp_la_CFLAGS = $(LIBSSH2_CFLAGS)
|
||||
libvirt_driver_phyp_la_SOURCES = $(PHYP_DRIVER_SOURCES)
|
||||
endif
|
||||
|
||||
|
@ -34,8 +34,11 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libssh/libssh.h>
|
||||
#include <libssh2.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "util.h"
|
||||
@ -53,6 +56,10 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_PHYP
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
#define PHYP_CMD_DEBUG fprintf(stdout,"%s:%d - COMMAND:%s\n",__FUNCTION__,__LINE__,cmd);
|
||||
#endif
|
||||
|
||||
static int escape_specialcharacters(char *src, char *dst, size_t dstlen);
|
||||
|
||||
/*
|
||||
@ -63,11 +70,12 @@ static virDrvOpenStatus
|
||||
phypOpen(virConnectPtr conn,
|
||||
virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
|
||||
{
|
||||
SSH_SESSION *session = NULL;
|
||||
LIBSSH2_SESSION *session = NULL;
|
||||
ConnectionData *connection_data = NULL;
|
||||
char *string;
|
||||
size_t len = 0;
|
||||
uuid_dbPtr uuid_db = NULL;
|
||||
int internal_socket;
|
||||
|
||||
if (!conn || !conn->uri)
|
||||
return VIR_DRV_OPEN_DECLINED;
|
||||
@ -113,15 +121,13 @@ phypOpen(virConnectPtr conn,
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if ((session = openSSHSession(conn, auth)) == NULL) {
|
||||
if ((session = openSSHSession(conn, auth, &internal_socket)) == NULL) {
|
||||
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Error while opening SSH session."));
|
||||
goto failure;
|
||||
}
|
||||
|
||||
VIR_FREE(conn->uri->path);
|
||||
conn->uri->path = string;
|
||||
//conn->uri->path = string;
|
||||
connection_data->session = session;
|
||||
connection_data->auth = auth;
|
||||
|
||||
@ -134,7 +140,7 @@ phypOpen(virConnectPtr conn,
|
||||
|
||||
return VIR_DRV_OPEN_SUCCESS;
|
||||
|
||||
failure:
|
||||
failure:
|
||||
VIR_FREE(uuid_db);
|
||||
VIR_FREE(connection_data);
|
||||
VIR_FREE(string);
|
||||
@ -146,63 +152,95 @@ static int
|
||||
phypClose(virConnectPtr conn)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
|
||||
ssh_disconnect(ssh_session);
|
||||
libssh2_session_disconnect(session, "Disconnecting...");
|
||||
libssh2_session_free(session);
|
||||
|
||||
VIR_FREE(connection_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSH_SESSION *
|
||||
openSSHSession(virConnectPtr conn, virConnectAuthPtr auth)
|
||||
LIBSSH2_SESSION *
|
||||
openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
|
||||
int *internal_socket)
|
||||
{
|
||||
SSH_SESSION *session;
|
||||
SSH_OPTIONS *opt;
|
||||
char *user = conn->uri->user;
|
||||
char *host = conn->uri->server;
|
||||
int ssh_auth = 0;
|
||||
char *banner;
|
||||
int port = 22;
|
||||
char *password;
|
||||
LIBSSH2_SESSION *session;
|
||||
const char *hostname = conn->uri->server;
|
||||
const char *username = conn->uri->user;
|
||||
const char *password = NULL;
|
||||
int sock;
|
||||
int rc;
|
||||
|
||||
if (conn->uri->port)
|
||||
port = conn->uri->port;
|
||||
struct addrinfo *ai = NULL, *cur;
|
||||
struct addrinfo hints;
|
||||
int ret;
|
||||
|
||||
session = ssh_new();
|
||||
opt = ssh_options_new();
|
||||
memset (&hints, '\0', sizeof (hints));
|
||||
hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
/*setting some ssh options */
|
||||
ssh_options_set_host(opt, host);
|
||||
ssh_options_set_port(opt, port);
|
||||
ssh_options_set_username(opt, user);
|
||||
ssh_set_options(session, opt);
|
||||
|
||||
/*starting ssh connection */
|
||||
if (ssh_connect(session)) {
|
||||
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP, VIR_ERR_ERROR,
|
||||
NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Connection failed."));
|
||||
ssh_disconnect(session);
|
||||
ssh_finalize();
|
||||
ret = getaddrinfo (hostname, "22", &hints, &ai);
|
||||
if (ret != 0) {
|
||||
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
||||
_("Error while getting %s address info"),
|
||||
hostname);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*trying to use pub key */
|
||||
if ((ssh_auth =
|
||||
ssh_userauth_autopubkey(session, NULL)) == SSH_AUTH_ERROR) {
|
||||
VIR_WARN("%s", "Authentication with public key failed.");
|
||||
cur = ai;
|
||||
while (cur != NULL) {
|
||||
sock = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
|
||||
if (sock >= 0) {
|
||||
if (connect (sock, cur->ai_addr, cur->ai_addrlen) == 0) {
|
||||
goto connected;
|
||||
}
|
||||
close (sock);
|
||||
}
|
||||
cur = cur->ai_next;
|
||||
}
|
||||
|
||||
if ((banner = ssh_get_issue_banner(session))) {
|
||||
VIR_INFO("%s", banner);
|
||||
VIR_FREE(banner);
|
||||
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
||||
_("Failed to connect to %s"), hostname);
|
||||
freeaddrinfo (ai);
|
||||
goto err;
|
||||
|
||||
connected:
|
||||
|
||||
(*internal_socket) = sock;
|
||||
|
||||
/* Create a session instance */
|
||||
session = libssh2_session_init();
|
||||
if (!session)
|
||||
goto err;
|
||||
|
||||
/* tell libssh2 we want it all done non-blocking */
|
||||
libssh2_session_set_blocking(session, 0);
|
||||
|
||||
while ((rc = libssh2_session_startup(session, sock)) ==
|
||||
LIBSSH2_ERROR_EAGAIN) ;
|
||||
if (rc) {
|
||||
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Failure establishing SSH session."));
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ssh_auth != SSH_AUTH_SUCCESS) {
|
||||
/* Trying authentication by pubkey */
|
||||
while ((rc =
|
||||
libssh2_userauth_publickey_fromfile(session, username,
|
||||
"/home/user/"
|
||||
".ssh/id_rsa.pub",
|
||||
"/home/user/"
|
||||
".ssh/id_rsa",
|
||||
password)) ==
|
||||
LIBSSH2_ERROR_EAGAIN) ;
|
||||
if (rc) {
|
||||
int i;
|
||||
int hasPassphrase = 0;
|
||||
int auth_check = 0;
|
||||
|
||||
virConnectCredential creds[] = {
|
||||
{VIR_CRED_PASSPHRASE, "password", "Password", NULL, NULL, 0},
|
||||
@ -237,34 +275,32 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (creds[0].result)
|
||||
if (creds[0].result) {
|
||||
password = creds[0].result;
|
||||
else {
|
||||
} else {
|
||||
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
||||
_("Unable to get password certificate: %s"),
|
||||
ssh_get_error(session));
|
||||
ssh_disconnect(session);
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Unable to get password certificates"));
|
||||
libssh2_session_disconnect(session, "Disconnecting...");
|
||||
libssh2_session_free(session);
|
||||
goto err;
|
||||
}
|
||||
|
||||
char *username = user;
|
||||
while ((rc =
|
||||
libssh2_userauth_password(session, username,
|
||||
password)) ==
|
||||
LIBSSH2_ERROR_EAGAIN) ;
|
||||
|
||||
auth_check = ssh_userauth_password(session, username, password);
|
||||
memset(password, 0, strlen(password));
|
||||
|
||||
if (auth_check != SSH_AUTH_SUCCESS) {
|
||||
if (rc) {
|
||||
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
||||
_("Authentication failed: %s"),
|
||||
ssh_get_error(session));
|
||||
ssh_disconnect(session);
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Authentication failed"));
|
||||
libssh2_session_disconnect(session, "Disconnecting");
|
||||
libssh2_session_free(session);
|
||||
goto err;
|
||||
} else
|
||||
goto exit;
|
||||
} else
|
||||
goto exit;
|
||||
|
||||
}
|
||||
err:
|
||||
return NULL;
|
||||
|
||||
@ -275,56 +311,73 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth)
|
||||
/* this functions is the layer that manipulates the ssh channel itself
|
||||
* and executes the commands on the remote machine */
|
||||
static char *
|
||||
phypExec(SSH_SESSION * session, char *cmd, int *exit_status,
|
||||
phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status,
|
||||
virConnectPtr conn)
|
||||
{
|
||||
CHANNEL *channel = channel_new(session);
|
||||
LIBSSH2_CHANNEL *channel;
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
virBuffer tex_ret = VIR_BUFFER_INITIALIZER;
|
||||
char buf[4096] = { 0 };
|
||||
int ret = 0;
|
||||
char buffer[0x4000] = { 0 };
|
||||
int exitcode;
|
||||
int bytecount = 0;
|
||||
int sock = connection_data->sock;
|
||||
int rc = 0;
|
||||
|
||||
if (channel_open_session(channel) == SSH_ERROR) {
|
||||
virRaiseError(NULL, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Unable to open a SSH channel."));
|
||||
/* Exec non-blocking on the remove host */
|
||||
while ((channel = libssh2_channel_open_session(session)) == NULL &&
|
||||
libssh2_session_last_error(session, NULL, NULL, 0) ==
|
||||
LIBSSH2_ERROR_EAGAIN) {
|
||||
waitsocket(sock, session);
|
||||
}
|
||||
|
||||
if (channel == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (channel_request_exec(channel, cmd) == SSH_ERROR) {
|
||||
virRaiseError(NULL, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Unable to execute remote command."));
|
||||
while ((rc = libssh2_channel_exec(channel, cmd)) ==
|
||||
LIBSSH2_ERROR_EAGAIN) {
|
||||
waitsocket(sock, session);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (channel_send_eof(channel) == SSH_ERROR) {
|
||||
virRaiseError(NULL, NULL, NULL, 0, VIR_FROM_PHYP,
|
||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
|
||||
_("Unable to send EOF."));
|
||||
goto err;
|
||||
}
|
||||
|
||||
while (channel && channel_is_open(channel)) {
|
||||
ret = channel_read(channel, buf, sizeof(buf), 0);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
if (ret == 0) {
|
||||
channel_send_eof(channel);
|
||||
if (channel_get_exit_status(channel) == -1)
|
||||
goto err;
|
||||
|
||||
if (channel_close(channel) == SSH_ERROR)
|
||||
goto err;
|
||||
|
||||
channel_free(channel);
|
||||
channel = NULL;
|
||||
goto exit;
|
||||
for (;;) {
|
||||
/* loop until we block */
|
||||
do {
|
||||
rc = libssh2_channel_read(channel, buffer, sizeof(buffer));
|
||||
if (rc > 0) {
|
||||
bytecount += rc;
|
||||
virBufferVSprintf(&tex_ret, "%s", buffer);
|
||||
}
|
||||
}
|
||||
while (rc > 0);
|
||||
|
||||
virBufferAdd(&tex_ret, (const char *) &buf, ret);
|
||||
/* this is due to blocking that would occur otherwise so we loop on
|
||||
* this condition */
|
||||
if (rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
waitsocket(sock, session);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
exitcode = 127;
|
||||
|
||||
while ((rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN) {
|
||||
waitsocket(sock, session);
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
exitcode = libssh2_channel_get_exit_status(channel);
|
||||
}
|
||||
|
||||
(*exit_status) = exitcode;
|
||||
libssh2_channel_free(channel);
|
||||
channel = NULL;
|
||||
goto exit;
|
||||
|
||||
err:
|
||||
(*exit_status) = SSH_CMD_ERR;
|
||||
char *cleanup_buf = virBufferContentAndReset(&tex_ret);
|
||||
@ -342,7 +395,7 @@ phypExec(SSH_SESSION * session, char *cmd, int *exit_status,
|
||||
|
||||
/* return the lpar_id given a name and a managed system name */
|
||||
static int
|
||||
phypGetLparID(SSH_SESSION * ssh_session, const char *managed_system,
|
||||
phypGetLparID(LIBSSH2_SESSION * session, const char *managed_system,
|
||||
const char *name, virConnectPtr conn)
|
||||
{
|
||||
int exit_status = 0;
|
||||
@ -356,13 +409,14 @@ phypGetLparID(SSH_SESSION * ssh_session, const char *managed_system,
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
const char *tex_ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
const char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (exit_status < 0 || tex_ret == NULL)
|
||||
if (exit_status < 0 || ret == NULL)
|
||||
goto err;
|
||||
|
||||
if (virStrToLong_i(tex_ret, &char_ptr, 10, &lpar_id) == -1)
|
||||
if (virStrToLong_i(ret, &char_ptr, 10, &lpar_id) == -1)
|
||||
goto err;
|
||||
|
||||
VIR_FREE(cmd);
|
||||
@ -375,7 +429,7 @@ phypGetLparID(SSH_SESSION * ssh_session, const char *managed_system,
|
||||
|
||||
/* return the lpar name given a lpar_id and a managed system name */
|
||||
static char *
|
||||
phypGetLparNAME(SSH_SESSION * ssh_session, const char *managed_system,
|
||||
phypGetLparNAME(LIBSSH2_SESSION * session, const char *managed_system,
|
||||
unsigned int lpar_id, virConnectPtr conn)
|
||||
{
|
||||
char *cmd;
|
||||
@ -387,22 +441,23 @@ phypGetLparNAME(SSH_SESSION * ssh_session, const char *managed_system,
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *lpar_name = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (lpar_name == NULL)
|
||||
if (ret == NULL)
|
||||
goto err;
|
||||
|
||||
char *char_ptr = strchr(lpar_name, '\n');
|
||||
char *char_ptr = strchr(ret, '\n');
|
||||
|
||||
if (char_ptr)
|
||||
*char_ptr = '\0';
|
||||
|
||||
if (exit_status < 0 || lpar_name == NULL)
|
||||
if (exit_status < 0 || ret == NULL)
|
||||
goto err;
|
||||
|
||||
VIR_FREE(cmd);
|
||||
return lpar_name;
|
||||
return ret;
|
||||
|
||||
err:
|
||||
VIR_FREE(cmd);
|
||||
@ -443,7 +498,7 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int lpar_id,
|
||||
int type)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *cmd;
|
||||
char *char_ptr;
|
||||
int memory = 0;
|
||||
@ -467,13 +522,14 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int lpar_id,
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *tex_ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (tex_ret == NULL)
|
||||
if (ret == NULL)
|
||||
goto err;
|
||||
|
||||
char *mem_char_ptr = strchr(tex_ret, '\n');
|
||||
char *mem_char_ptr = strchr(ret, '\n');
|
||||
|
||||
if (mem_char_ptr)
|
||||
*mem_char_ptr = '\0';
|
||||
@ -481,7 +537,7 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int lpar_id,
|
||||
if (exit_status < 0)
|
||||
goto err;
|
||||
|
||||
if (virStrToLong_i(tex_ret, &char_ptr, 10, &memory) == -1)
|
||||
if (virStrToLong_i(ret, &char_ptr, 10, &memory) == -1)
|
||||
goto err;
|
||||
|
||||
VIR_FREE(cmd);
|
||||
@ -497,7 +553,7 @@ unsigned long
|
||||
phypGetLparCPU(virConnectPtr conn, const char *managed_system, int lpar_id)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *cmd;
|
||||
int exit_status = 0;
|
||||
int vcpus = 0;
|
||||
@ -508,17 +564,18 @@ phypGetLparCPU(virConnectPtr conn, const char *managed_system, int lpar_id)
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
char *tex_ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
PHYP_CMD_DEBUG;
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (tex_ret == NULL)
|
||||
if (ret == NULL)
|
||||
goto err;
|
||||
|
||||
char *char_ptr = strchr(tex_ret, '\n');
|
||||
char *char_ptr = strchr(ret, '\n');
|
||||
|
||||
if (char_ptr)
|
||||
*char_ptr = '\0';
|
||||
|
||||
if (virStrToLong_i(tex_ret, &char_ptr, 10, &vcpus) == -1)
|
||||
if (virStrToLong_i(ret, &char_ptr, 10, &vcpus) == -1)
|
||||
goto err;
|
||||
|
||||
if (exit_status < 0)
|
||||
@ -537,7 +594,7 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system,
|
||||
const char *lpar_name)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *cmd;
|
||||
char *char_ptr;
|
||||
int remote_slot = 0;
|
||||
@ -549,12 +606,13 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system,
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
char *tex_ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
PHYP_CMD_DEBUG;
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (tex_ret == NULL)
|
||||
if (ret == NULL)
|
||||
goto err;
|
||||
|
||||
char *char_ptr2 = strchr(tex_ret, '\n');
|
||||
char *char_ptr2 = strchr(ret, '\n');
|
||||
|
||||
if (char_ptr2)
|
||||
*char_ptr2 = '\0';
|
||||
@ -562,7 +620,7 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system,
|
||||
if (exit_status < 0)
|
||||
goto err;
|
||||
|
||||
if (virStrToLong_i(tex_ret, &char_ptr, 10, &remote_slot) == -1)
|
||||
if (virStrToLong_i(ret, &char_ptr, 10, &remote_slot) == -1)
|
||||
goto err;
|
||||
|
||||
VIR_FREE(cmd);
|
||||
@ -578,7 +636,7 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system,
|
||||
char *lpar_name)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *cmd;
|
||||
int remote_slot = 0;
|
||||
int exit_status = 0;
|
||||
@ -593,8 +651,9 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system,
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (ret == NULL)
|
||||
goto err;
|
||||
@ -639,7 +698,7 @@ int
|
||||
phypGetLparState(virConnectPtr conn, unsigned int lpar_id)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *cmd;
|
||||
int exit_status = 0;
|
||||
char *char_ptr = NULL;
|
||||
@ -664,8 +723,9 @@ phypGetLparState(virConnectPtr conn, unsigned int lpar_id)
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (ret == NULL)
|
||||
goto err;
|
||||
@ -697,7 +757,7 @@ int
|
||||
phypDiskType(virConnectPtr conn, char *backing_device)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *cmd;
|
||||
int exit_status = 0;
|
||||
|
||||
@ -707,8 +767,9 @@ phypDiskType(virConnectPtr conn, char *backing_device)
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (ret == NULL)
|
||||
goto err;
|
||||
@ -746,7 +807,7 @@ static int
|
||||
phypNumDomainsGeneric(virConnectPtr conn, unsigned int type)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
int exit_status = 0;
|
||||
int ndom = 0;
|
||||
char *char_ptr;
|
||||
@ -780,8 +841,9 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type)
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (exit_status < 0 || ret == NULL)
|
||||
goto err;
|
||||
@ -821,7 +883,7 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids,
|
||||
unsigned int type)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *managed_system = conn->uri->path;
|
||||
int exit_status = 0;
|
||||
int got = 0;
|
||||
@ -857,21 +919,22 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids,
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
char *domains = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
PHYP_CMD_DEBUG;
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
/* I need to parse the textual return in order to get the domains */
|
||||
if (exit_status < 0 || domains == NULL || got == 0)
|
||||
/* I need to parse the textual return in order to get the ret */
|
||||
if (exit_status < 0 || ret == NULL)
|
||||
goto err;
|
||||
else {
|
||||
while (got < nids) {
|
||||
if (domains[i] == '\n') {
|
||||
if (ret[i] == '\n') {
|
||||
if (virStrToLong_i(id_c, &char_ptr, 10, &ids[got]) == -1)
|
||||
return 0;
|
||||
memset(id_c, 0, 10);
|
||||
j = 0;
|
||||
got++;
|
||||
} else {
|
||||
id_c[j] = domains[i];
|
||||
id_c[j] = ret[i];
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
@ -896,7 +959,7 @@ static int
|
||||
phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *managed_system = conn->uri->path;
|
||||
int exit_status = 0;
|
||||
int got = 0;
|
||||
@ -923,8 +986,9 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames)
|
||||
virReportOOMError(conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *ret = phypExec(ssh_session, cmd, &exit_status, conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, conn);
|
||||
|
||||
if (VIR_ALLOC(domains) < 0)
|
||||
virReportOOMError(conn);
|
||||
@ -968,7 +1032,7 @@ static virDomainPtr
|
||||
phypDomainLookupByName(virConnectPtr conn, const char *lpar_name)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
virDomainPtr dom = NULL;
|
||||
int lpar_id = 0;
|
||||
char *managed_system = conn->uri->path;
|
||||
@ -989,7 +1053,7 @@ phypDomainLookupByName(virConnectPtr conn, const char *lpar_name)
|
||||
if (char_ptr)
|
||||
*char_ptr = '\0';
|
||||
|
||||
lpar_id = phypGetLparID(ssh_session, managed_system, lpar_name, conn);
|
||||
lpar_id = phypGetLparID(session, managed_system, lpar_name, conn);
|
||||
if (lpar_id < 0)
|
||||
goto err;
|
||||
|
||||
@ -1013,7 +1077,7 @@ static virDomainPtr
|
||||
phypDomainLookupByID(virConnectPtr conn, int lpar_id)
|
||||
{
|
||||
ConnectionData *connection_data = conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
virDomainPtr dom = NULL;
|
||||
char *managed_system = conn->uri->path;
|
||||
int exit_status = 0;
|
||||
@ -1034,7 +1098,7 @@ phypDomainLookupByID(virConnectPtr conn, int lpar_id)
|
||||
if (char_ptr)
|
||||
*char_ptr = '\0';
|
||||
|
||||
char *lpar_name = phypGetLparNAME(ssh_session, managed_system, lpar_id,
|
||||
char *lpar_name = phypGetLparNAME(session, managed_system, lpar_id,
|
||||
conn);
|
||||
|
||||
if (phypGetLparUUID(lpar_uuid, lpar_id, conn) == -1)
|
||||
@ -1062,7 +1126,7 @@ static char *
|
||||
phypDomainDumpXML(virDomainPtr dom, int flags)
|
||||
{
|
||||
ConnectionData *connection_data = dom->conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
virDomainDefPtr def = NULL;
|
||||
char *ret = NULL;
|
||||
char *managed_system = dom->conn->uri->path;
|
||||
@ -1089,7 +1153,7 @@ phypDomainDumpXML(virDomainPtr dom, int flags)
|
||||
def->virtType = VIR_DOMAIN_VIRT_PHYP;
|
||||
def->id = dom->id;
|
||||
|
||||
char *lpar_name = phypGetLparNAME(ssh_session, managed_system, def->id,
|
||||
char *lpar_name = phypGetLparNAME(session, managed_system, def->id,
|
||||
dom->conn);
|
||||
|
||||
if (lpar_name == NULL) {
|
||||
@ -1136,7 +1200,7 @@ static int
|
||||
phypDomainResume(virDomainPtr dom)
|
||||
{
|
||||
ConnectionData *connection_data = dom->conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *managed_system = dom->conn->uri->path;
|
||||
int exit_status = 0;
|
||||
char *char_ptr = NULL;
|
||||
@ -1161,8 +1225,9 @@ phypDomainResume(virDomainPtr dom)
|
||||
virReportOOMError(dom->conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *ret = phypExec(ssh_session, cmd, &exit_status, dom->conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, dom->conn);
|
||||
|
||||
err:
|
||||
VIR_FREE(cmd);
|
||||
@ -1175,7 +1240,7 @@ static int
|
||||
phypDomainShutdown(virDomainPtr dom)
|
||||
{
|
||||
ConnectionData *connection_data = dom->conn->networkPrivateData;
|
||||
SSH_SESSION *ssh_session = connection_data->session;
|
||||
LIBSSH2_SESSION *session = connection_data->session;
|
||||
char *managed_system = dom->conn->uri->path;
|
||||
int exit_status = 0;
|
||||
char *char_ptr = NULL;
|
||||
@ -1200,8 +1265,9 @@ phypDomainShutdown(virDomainPtr dom)
|
||||
virReportOOMError(dom->conn);
|
||||
goto err;
|
||||
}
|
||||
PHYP_CMD_DEBUG;
|
||||
|
||||
char *ret = phypExec(ssh_session, cmd, &exit_status, dom->conn);
|
||||
char *ret = phypExec(session, cmd, &exit_status, dom->conn);
|
||||
|
||||
err:
|
||||
VIR_FREE(cmd);
|
||||
@ -1392,3 +1458,34 @@ escape_specialcharacters(char *src, char *dst, size_t dstlen)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
waitsocket(int socket_fd, LIBSSH2_SESSION * session)
|
||||
{
|
||||
struct timeval timeout;
|
||||
int rc;
|
||||
fd_set fd;
|
||||
fd_set *writefd = NULL;
|
||||
fd_set *readfd = NULL;
|
||||
int dir;
|
||||
|
||||
timeout.tv_sec = 10;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&fd);
|
||||
|
||||
FD_SET(socket_fd, &fd);
|
||||
|
||||
/* now make sure we wait in the correct direction */
|
||||
dir = libssh2_session_block_directions(session);
|
||||
|
||||
if (dir & LIBSSH2_SESSION_BLOCK_INBOUND)
|
||||
readfd = &fd;
|
||||
|
||||
if (dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||
writefd = &fd;
|
||||
|
||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <config.h>
|
||||
#include <libssh/libssh.h>
|
||||
#include <libssh2.h>
|
||||
|
||||
#define LPAR_EXEC_ERR -1
|
||||
#define SSH_CONN_ERR -2 /* error while trying to connect to remote host */
|
||||
@ -8,8 +8,9 @@
|
||||
typedef struct _ConnectionData ConnectionData;
|
||||
typedef ConnectionData *ConnectionDataPtr;
|
||||
struct _ConnectionData {
|
||||
SSH_SESSION *session;
|
||||
LIBSSH2_SESSION *session;
|
||||
virConnectAuthPtr auth;
|
||||
int sock;
|
||||
};
|
||||
|
||||
/* This is the lpar (domain) struct that relates
|
||||
@ -42,8 +43,6 @@ void stripPath(char *striped_path, char *path);
|
||||
|
||||
void stripNewline(char *striped_string, char *string);
|
||||
|
||||
int buffer_add_u8(struct buffer_struct *buffer, u8 data);
|
||||
|
||||
int phypGetLparState(virConnectPtr conn, unsigned int lpar_id);
|
||||
|
||||
unsigned long phypGetLparMem(virConnectPtr conn,
|
||||
@ -61,4 +60,6 @@ char *phypGetBackingDevice(virConnectPtr conn, const char *managed_system,
|
||||
|
||||
int phypDiskType(virConnectPtr conn, char *backing_device);
|
||||
|
||||
SSH_SESSION *openSSHSession(virConnectPtr conn, virConnectAuthPtr auth);
|
||||
LIBSSH2_SESSION *openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, int *internal_socket);
|
||||
|
||||
int waitsocket(int socket_fd, LIBSSH2_SESSION * session);
|
||||
|
Loading…
Reference in New Issue
Block a user