Adding support for the IBM IVM Virtualization system under Power Hypervisor. --- src/phyp/phyp_driver.c | 644 ++++++++++++++++++++++++++++++++++-------------- src/phyp/phyp_driver.h | 8 + 2 files changed, 471 insertions(+), 181 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index f8bea42..787b93d 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -66,6 +66,9 @@ virReportErrorHelper(NULL, VIR_FROM_PHYP, code, __FILE__, __FUNCTION__, \ __LINE__, __VA_ARGS__) +#define HMC 0 +#define IVM 127 + /* * URI: phyp://user@[hmc|ivm]/managed_system * */ @@ -82,7 +85,7 @@ phypOpen(virConnectPtr conn, uuid_tablePtr uuid_table = NULL; phyp_driverPtr phyp_driver = NULL; char *char_ptr; - char *managed_system; + char *managed_system = NULL; if (!conn || !conn->uri) return VIR_DRV_OPEN_DECLINED; @@ -96,12 +99,6 @@ phypOpen(virConnectPtr conn, return VIR_DRV_OPEN_ERROR; } - if (conn->uri->path == NULL) { - PHYP_ERROR(VIR_ERR_INTERNAL_ERROR, - "%s", _("Missing managed system name in phyp:// URI")); - return VIR_DRV_OPEN_ERROR; - } - if (VIR_ALLOC(phyp_driver) < 0) { virReportOOMError(); goto failure; @@ -117,36 +114,39 @@ phypOpen(virConnectPtr conn, goto failure; } - len = strlen(conn->uri->path) + 1; + if (conn->uri->path) { + len = strlen(conn->uri->path) + 1; - if (VIR_ALLOC_N(string, len) < 0) { - virReportOOMError(); - goto failure; - } + if (VIR_ALLOC_N(string, len) < 0) { + virReportOOMError(); + goto failure; + } - /* need to shift one byte in order to remove the first "/" of URI component */ - if (conn->uri->path[0] == '/') - managed_system = strdup(conn->uri->path + 1); - else - managed_system = strdup(conn->uri->path); + /* need to shift one byte in order to remove the first "/" of URI component */ + if (conn->uri->path[0] == '/') + managed_system = strdup(conn->uri->path + 1); + else + managed_system = strdup(conn->uri->path); - if (!managed_system) { - virReportOOMError(); - goto failure; - } + if (!managed_system) { + virReportOOMError(); + goto failure; + } - /* here we are handling only the first component of the path, - * so skipping the second: - * */ - char_ptr = strchr(managed_system, '/'); + /* here we are handling only the first component of the path, + * so skipping the second: + * */ + char_ptr = strchr(managed_system, '/'); - if (char_ptr) - *char_ptr = '\0'; + if (char_ptr) + *char_ptr = '\0'; - if (escape_specialcharacters(conn->uri->path, string, len) == -1) { - PHYP_ERROR(VIR_ERR_INTERNAL_ERROR, - "%s", _("Error parsing 'path'. Invalid characters.")); - goto failure; + if (escape_specialcharacters(conn->uri->path, string, len) == -1) { + PHYP_ERROR(VIR_ERR_INTERNAL_ERROR, + "%s", + _("Error parsing 'path'. Invalid characters.")); + goto failure; + } } if ((session = openSSHSession(conn, auth, &internal_socket)) == NULL) { @@ -160,7 +160,9 @@ phypOpen(virConnectPtr conn, uuid_table->nlpars = 0; uuid_table->lpars = NULL; - phyp_driver->managed_system = managed_system; + if (conn->uri->path) + phyp_driver->managed_system = managed_system; + phyp_driver->uuid_table = uuid_table; if ((phyp_driver->caps = phypCapsInit()) == NULL) { virReportOOMError(); @@ -169,12 +171,18 @@ phypOpen(virConnectPtr conn, conn->privateData = phyp_driver; conn->networkPrivateData = connection_data; - if (phypUUIDTable_Init(conn) == -1) + + if ((phyp_driver->system_type = phypGetSystemType(conn)) == -1) goto failure; - if ((phyp_driver->vios_id = phypGetVIOSPartitionID(conn)) == -1) + if (phypUUIDTable_Init(conn) == -1) goto failure; + if (phyp_driver->system_type == HMC) { + if ((phyp_driver->vios_id = phypGetVIOSPartitionID(conn)) == -1) + goto failure; + } + return VIR_DRV_OPEN_SUCCESS; failure: @@ -280,7 +288,8 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, username = virRequestUsername(auth, NULL, conn->uri->server); if (username == NULL) { - PHYP_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Username request failed")); + PHYP_ERROR(VIR_ERR_AUTH_FAILED, "%s", + _("Username request failed")); goto err; } } @@ -360,7 +369,8 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, password = virRequestPassword(auth, username, conn->uri->server); if (password == NULL) { - PHYP_ERROR(VIR_ERR_AUTH_FAILED, "%s", _("Password request failed")); + PHYP_ERROR(VIR_ERR_AUTH_FAILED, "%s", + _("Password request failed")); goto disconnect; } @@ -488,22 +498,58 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status, return virBufferContentAndReset(&tex_ret); } +int +phypGetSystemType(virConnectPtr conn) +{ + ConnectionData *connection_data = conn->networkPrivateData; + LIBSSH2_SESSION *session = connection_data->session; + char *cmd = NULL; + char *ret = NULL; + int exit_status = 0; + + if (virAsprintf(&cmd, "lshmc -V") < 0) { + virReportOOMError(); + goto err; + } + ret = phypExec(session, cmd, &exit_status, conn); + + VIR_FREE(cmd); + VIR_FREE(ret); + return exit_status; + + err: + VIR_FREE(cmd); + VIR_FREE(ret); + return -1; +} + /* return the lpar_id given a name and a managed system name */ static int phypGetLparID(LIBSSH2_SESSION * session, const char *managed_system, const char *name, virConnectPtr conn) { + phyp_driverPtr phyp_driver = conn->privateData; + int system_type = phyp_driver->system_type; int exit_status = 0; int lpar_id = 0; char *char_ptr; char *cmd = NULL; char *ret = NULL; - if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s --filter lpar_names=%s -F lpar_id", - managed_system, name) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "lssyscfg -r lpar -m %s --filter lpar_names=%s -F lpar_id", + managed_system, name) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lssyscfg -r lpar --filter lpar_names=%s -F lpar_id", + name) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -529,15 +575,26 @@ static char * phypGetLparNAME(LIBSSH2_SESSION * session, const char *managed_system, unsigned int lpar_id, virConnectPtr conn) { + phyp_driverPtr phyp_driver = conn->privateData; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; int exit_status = 0; - if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s --filter lpar_ids=%d -F name", - managed_system, lpar_id) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "lssyscfg -r lpar -m %s --filter lpar_ids=%d -F name", + managed_system, lpar_id) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lssyscfg -r lpar --filter lpar_ids=%d -F name", + lpar_id) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -595,6 +652,8 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int lpar_id, { ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; + phyp_driverPtr phyp_driver = conn->privateData; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; char *char_ptr; @@ -604,21 +663,40 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int lpar_id, if (type != 1 && type != 0) goto err; - if (type) { - if (virAsprintf(&cmd, - "lshwres -m %s -r mem --level lpar -F curr_mem " - "--filter lpar_ids=%d", - managed_system, lpar_id) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (type) { + if (virAsprintf(&cmd, + "lshwres -m %s -r mem --level lpar -F curr_mem " + "--filter lpar_ids=%d", + managed_system, lpar_id) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lshwres -m %s -r mem --level lpar -F " + "curr_max_mem --filter lpar_ids=%d", + managed_system, lpar_id) < 0) { + virReportOOMError(); + goto err; + } } } else { - if (virAsprintf(&cmd, - "lshwres -m %s -r mem --level lpar -F " - "curr_max_mem --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { - virReportOOMError(); - goto err; + if (type) { + if (virAsprintf(&cmd, + "lshwres -r mem --level lpar -F curr_mem " + "--filter lpar_ids=%d", lpar_id) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lshwres -r mem --level lpar -F " + "curr_max_mem --filter lpar_ids=%d", + lpar_id) < 0) { + virReportOOMError(); + goto err; + } } } @@ -667,27 +745,49 @@ phypGetLparCPUGeneric(virConnectPtr conn, const char *managed_system, { ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; + phyp_driverPtr phyp_driver = conn->privateData; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; char *char_ptr; int exit_status = 0; int vcpus = 0; - if (type) { - if (virAsprintf(&cmd, - "lshwres -m %s -r proc --level lpar -F " - "curr_max_procs --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (type) { + if (virAsprintf(&cmd, + "lshwres -m %s -r proc --level lpar -F " + "curr_max_procs --filter lpar_ids=%d", + managed_system, lpar_id) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lshwres -m %s -r proc --level lpar -F " + "curr_procs --filter lpar_ids=%d", + managed_system, lpar_id) < 0) { + virReportOOMError(); + goto err; + } } } else { - if (virAsprintf(&cmd, - "lshwres -m %s -r proc --level lpar -F " - "curr_procs --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { - virReportOOMError(); - goto err; + if (type) { + if (virAsprintf(&cmd, + "lshwres -r proc --level lpar -F " + "curr_max_procs --filter lpar_ids=%d", + lpar_id) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lshwres -r proc --level lpar -F " + "curr_procs --filter lpar_ids=%d", + lpar_id) < 0) { + virReportOOMError(); + goto err; + } } } ret = phypExec(session, cmd, &exit_status, conn); @@ -719,18 +819,30 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system, { ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; + phyp_driverPtr phyp_driver = conn->privateData; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; char *char_ptr; int remote_slot = 0; int exit_status = 0; - if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " - "remote_slot_num --filter lpar_names=%s", - managed_system, lpar_name) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "lshwres -m %s -r virtualio --rsubtype scsi -F " + "remote_slot_num --filter lpar_names=%s", + managed_system, lpar_name) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lshwres -r virtualio --rsubtype scsi -F " + "remote_slot_num --filter lpar_names=%s", + lpar_name) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -761,6 +873,8 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, { ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; + phyp_driverPtr phyp_driver = conn->privateData; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; int remote_slot = 0; @@ -772,12 +886,22 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, phypGetRemoteSlot(conn, managed_system, lpar_name)) == -1) goto err; - if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " - "backing_devices --filter slots=%d", - managed_system, remote_slot) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "lshwres -m %s -r virtualio --rsubtype scsi -F " + "backing_devices --filter slots=%d", + managed_system, remote_slot) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lshwres -r virtualio --rsubtype scsi -F " + "backing_devices --filter slots=%d", + remote_slot) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -834,6 +958,7 @@ phypGetLparState(virConnectPtr conn, unsigned int lpar_id) ConnectionData *connection_data = conn->networkPrivateData; phyp_driverPtr phyp_driver = conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; int exit_status = 0; @@ -841,11 +966,20 @@ phypGetLparState(virConnectPtr conn, unsigned int lpar_id) char *managed_system = phyp_driver->managed_system; int state = VIR_DOMAIN_NOSTATE; - if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s -F state --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { - virReportOOMError(); - goto cleanup; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "lssyscfg -r lpar -m %s -F state --filter lpar_ids=%d", + managed_system, lpar_id) < 0) { + virReportOOMError(); + goto cleanup; + } + } else { + if (virAsprintf(&cmd, + "lssyscfg -r lpar -F state --filter lpar_ids=%d", + lpar_id) < 0) { + virReportOOMError(); + goto cleanup; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -877,6 +1011,7 @@ phypGetVIOSPartitionID(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; phyp_driverPtr phyp_driver = conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; int exit_status = 0; @@ -884,11 +1019,21 @@ phypGetVIOSPartitionID(virConnectPtr conn) char *char_ptr; char *managed_system = phyp_driver->managed_system; - if (virAsprintf(&cmd, - "lssyscfg -m %s -r lpar -F lpar_id,lpar_env|grep " - "vioserver|sed -s 's/,.*$//g'", managed_system) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "lssyscfg -m %s -r lpar -F lpar_id,lpar_env|grep " + "vioserver|sed -s 's/,.*$//g'", + managed_system) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lssyscfg -r lpar -F lpar_id,lpar_env|grep " + "vioserver|sed -s 's/,.*$//g'") < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -915,6 +1060,7 @@ phypDiskType(virConnectPtr conn, char *backing_device) phyp_driverPtr phyp_driver = conn->privateData; ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *cmd = NULL; char *ret = NULL; int exit_status = 0; @@ -923,12 +1069,22 @@ phypDiskType(virConnectPtr conn, char *backing_device) int vios_id = phyp_driver->vios_id; int disk_type = -1; - if (virAsprintf(&cmd, - "viosvrcmd -m %s -p %d -c \"lssp -field name type " - "-fmt , -all|grep %s|sed -e 's/^.*,//g'\"", - managed_system, vios_id, backing_device) < 0) { - virReportOOMError(); - goto cleanup; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "viosvrcmd -m %s -p %d -c \"lssp -field name type " + "-fmt , -all|grep %s|sed -e 's/^.*,//g'\"", + managed_system, vios_id, backing_device) < 0) { + virReportOOMError(); + goto cleanup; + } + } else { + if (virAsprintf(&cmd, + "viosvrcmd -p %d -c \"lssp -field name type " + "-fmt , -all|grep %s|sed -e 's/^.*,//g'\"", + vios_id, backing_device) < 0) { + virReportOOMError(); + goto cleanup; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -966,6 +1122,7 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type) ConnectionData *connection_data = conn->networkPrivateData; phyp_driverPtr phyp_driver = conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; int exit_status = 0; int ndom = 0; char *char_ptr; @@ -976,16 +1133,29 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type) if (type == 0) state = "|grep Running"; - else if (type == 1) - state = "|grep \"Not Activated\""; - else + else if (type == 1) { + if (system_type == HMC) { + state = "|grep \"Not Activated\""; + } else { + state = "|grep \"Open Firmware\""; + } + } else state = " "; - if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s -F lpar_id,state %s |grep -c " - "^[0-9]*", managed_system, state) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf(&cmd, + "lssyscfg -r lpar -m %s -F lpar_id,state %s |grep -c " + "^[0-9]*", managed_system, state) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, + "lssyscfg -r lpar -F lpar_id,state %s |grep -c " + "^[0-9]*", state) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -1032,6 +1202,7 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids, ConnectionData *connection_data = conn->networkPrivateData; phyp_driverPtr phyp_driver = conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *managed_system = phyp_driver->managed_system; int exit_status = 0; int got = 0; @@ -1049,13 +1220,24 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids, memset(id_c, 0, 10); - if (virAsprintf - (&cmd, - "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'", - managed_system, state) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf + (&cmd, + "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'", + managed_system, state) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf + (&cmd, + "lssyscfg -r lpar -F lpar_id,state %s | sed -e 's/,.*$//g'", + state) < 0) { + virReportOOMError(); + goto err; + } } + ret = phypExec(session, cmd, &exit_status, conn); /* I need to parse the textual return in order to get the ret */ @@ -1103,6 +1285,7 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) ConnectionData *connection_data = conn->networkPrivateData; phyp_driverPtr phyp_driver = conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *managed_system = phyp_driver->managed_system; int exit_status = 0; int got = 0; @@ -1112,12 +1295,22 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) char *domains = NULL; char *char_ptr2 = NULL; - if (virAsprintf - (&cmd, - "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " - "sed -e 's/,.*$//g'", managed_system) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf + (&cmd, + "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " + "sed -e 's/,.*$//g'", managed_system) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf + (&cmd, + "lssyscfg -r lpar -F name,state | grep \"Open Firmware\" | " + "sed -e 's/,.*$//g'") < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -1272,17 +1465,28 @@ phypDomainResume(virDomainPtr dom) ConnectionData *connection_data = dom->conn->networkPrivateData; phyp_driverPtr phyp_driver = dom->conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *managed_system = phyp_driver->managed_system; int exit_status = 0; char *cmd = NULL; char *ret = NULL; - if (virAsprintf - (&cmd, - "chsysstate -m %s -r lpar -o on --id %d -f %s", - managed_system, dom->id, dom->name) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf + (&cmd, + "chsysstate -m %s -r lpar -o on --id %d -f %s", + managed_system, dom->id, dom->name) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf + (&cmd, + "chsysstate -r lpar -o on --id %d -f %s", + dom->id, dom->name) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, dom->conn); @@ -1304,21 +1508,31 @@ static int phypDomainShutdown(virDomainPtr dom) { ConnectionData *connection_data = dom->conn->networkPrivateData; - phyp_driverPtr phyp_driver = dom->conn->privateData; + virConnectPtr conn = dom->conn; LIBSSH2_SESSION *session = connection_data->session; + phyp_driverPtr phyp_driver = conn->privateData; + int system_type = phyp_driver->system_type; char *managed_system = phyp_driver->managed_system; int exit_status = 0; char *cmd = NULL; char *ret = NULL; - if (virAsprintf - (&cmd, - "chsysstate -m %s -r lpar -o shutdown --id %d", - managed_system, dom->id) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf + (&cmd, + "chsysstate -m %s -r lpar -o shutdown --id %d", + managed_system, dom->id) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf + (&cmd, + "chsysstate -r lpar -o shutdown --id %d", dom->id) < 0) { + virReportOOMError(); + goto err; + } } - ret = phypExec(session, cmd, &exit_status, dom->conn); if (exit_status < 0) @@ -1363,16 +1577,25 @@ phypDomainDestroy(virDomainPtr dom) ConnectionData *connection_data = dom->conn->networkPrivateData; phyp_driverPtr phyp_driver = dom->conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *managed_system = phyp_driver->managed_system; int exit_status = 0; char *cmd = NULL; char *ret = NULL; - if (virAsprintf - (&cmd, - "rmsyscfg -m %s -r lpar --id %d", managed_system, dom->id) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf + (&cmd, + "rmsyscfg -m %s -r lpar --id %d", managed_system, + dom->id) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf(&cmd, "rmsyscfg -r lpar --id %d", dom->id) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, dom->conn); @@ -1508,6 +1731,7 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) ConnectionData *connection_data = dom->conn->networkPrivateData; phyp_driverPtr phyp_driver = dom->conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *managed_system = phyp_driver->managed_system; int exit_status = 0; char *cmd = NULL; @@ -1534,20 +1758,32 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) } else goto exit; - if (virAsprintf - (&cmd, - "chhwres -r proc -m %s --id %d -o %c --procunits %d 2>&1 |sed" - "-e 's/^.*\\([0-9]\\+.[0-9]\\+\\).*$/\\1/g'", - managed_system, dom->id, operation, amount) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf + (&cmd, + "chhwres -r proc -m %s --id %d -o %c --procunits %d 2>&1 |sed" + "-e 's/^.*\\([0-9]\\+.[0-9]\\+\\).*$/\\1/g'", + managed_system, dom->id, operation, amount) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf + (&cmd, + "chhwres -r proc -id %d -o %c --procunits %d 2>&1 |sed" + "-e 's/^.*\\([0-9]\\+.[0-9]\\+\\).*$/\\1/g'", + dom->id, operation, amount) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, dom->conn); if (exit_status < 0) { - VIR_ERROR0(_("Possibly you don't have IBM Tools installed in your LPAR." - "Contact your support to enable this feature.")); + VIR_ERROR0(_ + ("Possibly you don't have IBM Tools installed in your LPAR." + "Contact your support to enable this feature.")); goto err; } @@ -1564,9 +1800,7 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) } virDriver phypDriver = { - VIR_DRV_PHYP, - "PHYP", - phypOpen, /* open */ + VIR_DRV_PHYP, "PHYP", phypOpen, /* open */ phypClose, /* close */ NULL, /* supports_feature */ NULL, /* type */ @@ -1644,23 +1878,23 @@ virDriver phypDriver = { NULL, /* domainIsPersistent */ NULL, /* cpuCompare */ NULL, /* cpuBaseline */ - NULL, /* domainGetJobInfo */ - NULL, /* domainAbortJob */ - NULL, /* domainMigrateSetMaxDowntime */ - NULL, /* domainEventRegisterAny */ - NULL, /* domainEventDeregisterAny */ - NULL, /* domainManagedSave */ - NULL, /* domainHasManagedSaveImage */ - NULL, /* domainManagedSaveRemove */ - NULL, /* domainSnapshotCreateXML */ - NULL, /* domainSnapshotDumpXML */ - NULL, /* domainSnapshotNum */ - NULL, /* domainSnapshotListNames */ - NULL, /* domainSnapshotLookupByName */ - NULL, /* domainHasCurrentSnapshot */ - NULL, /* domainSnapshotCurrent */ - NULL, /* domainRevertToSnapshot */ - NULL, /* domainSnapshotDelete */ + NULL, /* domainGetJobInfo */ + NULL, /* domainAbortJob */ + NULL, /* domainMigrateSetMaxDowntime */ + NULL, /* domainEventRegisterAny */ + NULL, /* domainEventDeregisterAny */ + NULL, /* domainManagedSave */ + NULL, /* domainHasManagedSaveImage */ + NULL, /* domainManagedSaveRemove */ + NULL, /* domainSnapshotCreateXML */ + NULL, /* domainSnapshotDumpXML */ + NULL, /* domainSnapshotNum */ + NULL, /* domainSnapshotListNames */ + NULL, /* domainSnapshotLookupByName */ + NULL, /* domainHasCurrentSnapshot */ + NULL, /* domainSnapshotCurrent */ + NULL, /* domainRevertToSnapshot */ + NULL, /* domainSnapshotDelete */ }; int @@ -1669,20 +1903,34 @@ phypBuildLpar(virConnectPtr conn, virDomainDefPtr def) ConnectionData *connection_data = conn->networkPrivateData; phyp_driverPtr phyp_driver = conn->privateData; LIBSSH2_SESSION *session = connection_data->session; + int system_type = phyp_driver->system_type; char *managed_system = phyp_driver->managed_system; char *cmd = NULL; char *ret = NULL; int exit_status = 0; - if (virAsprintf - (&cmd, - "mksyscfg -m %s -r lpar -p %s -i min_mem=%d,desired_mem=%d," - "max_mem=%d,desired_procs=%d,virtual_scsi_adapters=%s", - managed_system, def->name, (int) def->memory, - (int) def->memory, (int) def->maxmem, (int) def->vcpus, - def->disks[0]->src) < 0) { - virReportOOMError(); - goto err; + if (system_type == HMC) { + if (virAsprintf + (&cmd, + "mksyscfg -m %s -r lpar -p %s -i min_mem=%d,desired_mem=%d," + "max_mem=%d,desired_procs=%d,virtual_scsi_adapters=%s", + managed_system, def->name, (int) def->memory, + (int) def->memory, (int) def->maxmem, (int) def->vcpus, + def->disks[0]->src) < 0) { + virReportOOMError(); + goto err; + } + } else { + if (virAsprintf + (&cmd, + "mksyscfg -r lpar -p %s -i min_mem=%d,desired_mem=%d," + "max_mem=%d,desired_procs=%d,virtual_scsi_adapters=%s", + def->name, (int) def->memory, + (int) def->memory, (int) def->maxmem, (int) def->vcpus, + def->disks[0]->src) < 0) { + virReportOOMError(); + goto err; + } } ret = phypExec(session, cmd, &exit_status, conn); @@ -1796,7 +2044,8 @@ phypUUIDTable_ReadFile(virConnectPtr conn) } uuid_table->lpars[i]->id = id; } else { - VIR_WARN0("Unable to read from information to local file."); + VIR_WARN0 + ("Unable to read from information to local file."); goto err; } @@ -1947,14 +2196,30 @@ phypUUIDTable_Push(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + char *username = NULL; struct stat local_fileinfo; char buffer[1024]; int rc = 0; FILE *fd; size_t nread, sent; char *ptr; - char remote_file[] = "/home/hscroot/libvirt_uuid_table"; char local_file[] = "./uuid_table"; + char *remote_file = NULL; + + if (conn->uri->user != NULL) { + username = strdup(conn->uri->user); + + if (username == NULL) { + virReportOOMError(); + goto err; + } + } + + if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table", username) + < 0) { + virReportOOMError(); + goto err; + } if (stat(local_file, &local_fileinfo) == -1) { VIR_WARN0("Unable to stat local file."); @@ -2031,6 +2296,7 @@ phypUUIDTable_Pull(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + char *username = NULL; struct stat fileinfo; char buffer[1024]; int rc = 0; @@ -2039,8 +2305,23 @@ phypUUIDTable_Pull(virConnectPtr conn) int amount = 0; int total = 0; int sock = 0; - char remote_file[] = "/home/hscroot/libvirt_uuid_table"; char local_file[] = "./uuid_table"; + char *remote_file = NULL; + + if (conn->uri->user != NULL) { + username = strdup(conn->uri->user); + + if (username == NULL) { + virReportOOMError(); + goto err; + } + } + + if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table", username) + < 0) { + virReportOOMError(); + goto err; + } /* Trying to stat the remote file. */ do { @@ -2072,7 +2353,8 @@ phypUUIDTable_Pull(virConnectPtr conn) rc = libssh2_channel_read(channel, buffer, amount); if (rc > 0) { if (safewrite(fd, buffer, rc) != rc) - VIR_WARN0("Unable to write information to local file."); + VIR_WARN0 + ("Unable to write information to local file."); got += rc; total += rc; diff --git a/src/phyp/phyp_driver.h b/src/phyp/phyp_driver.h index f680994..80ff0c3 100644 --- a/src/phyp/phyp_driver.h +++ b/src/phyp/phyp_driver.h @@ -66,11 +66,19 @@ struct _phyp_driver { uuid_tablePtr uuid_table; virCapsPtr caps; int vios_id; + + /* system_type: + * 0 = hmc + * 127 = ivm + * */ + int system_type; char *managed_system; }; int phypCheckSPFreeSapce(virConnectPtr conn, int required_size, char *sp); +int phypGetSystemType(virConnectPtr conn); + int phypGetVIOSPartitionID(virConnectPtr conn); virCapsPtr phypCapsInit(void); -- 1.7.0.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list