[libvirt] [PATCH] Adding support for IVM

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

On 06/04/2010 03:40 PM, Eduardo Otubo wrote:
Adding support for the IBM IVM Virtualization system under Power Hypervisor.
@@ -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; + }
These changes were easier to review with 'git diff -b', and look reasonable up to this point...
+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;
The two lists of VIR_FREE seem redundant. You could prime exit_status to -1, then blindly return exit_status in the err clause with the success clause falling through to the err clause. Or, since the only way to get to the err clause is after virReportOOMError, when you already know that cmd and ret are NULL, you could get rid of the err clause altogether and just use 'return -1' instead of 'goto err'.
- 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; + }
A lot of the patch is like this, adding a non-HMC version that merely omits the -m %s part of the string. That means the executable contains both variants of all the strings. In my opinion, you should factor this into one virAsprintf per function, with a call out to a helper function to decide whether to add -m %s. Something along these lines, but without the thread-safety hole of static storage: virAsprintf(&cmd, "lssyscfg -r lpar %s --filter lpar_names=%s -F lpar_id", helper(system_type, managed_system), name) < 0 where: static char * helper(int system_type, const char *managed_system) { static char unsafe[1024]; if (system_type == HMC) virSprintf(unsafe, "-m %s", managed_system); else unsafe[0] = 0; return unsafe; } Maybe even change over to virBuffer API instead of virAsprintf. But by your current approach of duplicating the strings, in every method, you risk a maintenance burden of a future change affecting one, but not both, of two similar and long command lines. Dan Berrange's pending patches to provide an improved exec wrapper may be handy on this front, depending on whether phypExec can be rewritten to take advantage of the memory management features it provides.
- 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) {
Ouch - a pre-existing bug. Since this command is being fed to a shell, you need to properly quote the regex being fed to grep, so that it doesn't get interpreted as a glob matching a literal file (such as ^0) that happens to be in the same directory. That should be fixed in an independent patch.
+ "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'",
Here, a minor optimization - you don't need the g flag to that sed s/// expression, since the regex is anchored to the end of the string (you can't replace more than one anchored expression per line). But independent of this patch.
@@ -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.");
Memory leak? Where does username get freed? virBuffer* may be more handy than strdup'ing username just to copy it (virAsprintf) to another malloc'd string then free it.
@@ -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 {
Again, where does username get freed?
+++ 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;
Is this worth an enum? Although I'm probably okay with an int.
char *managed_system; };
int phypCheckSPFreeSapce(virConnectPtr conn, int required_size, char *sp);
+int phypGetSystemType(virConnectPtr conn); + int phypGetVIOSPartitionID(virConnectPtr conn);
virCapsPtr phypCapsInit(void);
Looking forward to v2. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

* src/phyp/phyp_driver.c (phypNumDomainsGeneric): Avoid glob collision by quoting sed argument. (phypDomainSetCPU): Avoid non-portable \+ in sed. (phypGetVIOSPartitionID, phypDiskType, phypListDomainsGeneric) (phypListDefinedDomains): Micro-optimize anchored substitutions. ---
+ 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) { Ouch - a pre-existing bug. Since this command is being fed to a shell, you need to properly quote the regex being fed to grep, so that it doesn't get interpreted as a glob matching a literal file (such as ^0) that happens to be in the same directory. That should be fixed in an independent patch.
Like this one :)
+ "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'", Here, a minor optimization - you don't need the g flag to that sed s/// expression, since the regex is anchored to the end of the string (you can't replace more than one anchored expression per line). But independent of this patch.
While I was touching the file... src/phyp/phyp_driver.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 0f4bc20..f8d12e7 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -886,7 +886,7 @@ phypGetVIOSPartitionID(virConnectPtr conn) if (virAsprintf(&cmd, "lssyscfg -m %s -r lpar -F lpar_id,lpar_env|grep " - "vioserver|sed -s 's/,.*$//g'", managed_system) < 0) { + "vioserver|sed -s 's/,.*$//'", managed_system) < 0) { virReportOOMError(); goto err; } @@ -925,7 +925,7 @@ phypDiskType(virConnectPtr conn, char *backing_device) if (virAsprintf(&cmd, "viosvrcmd -m %s -p %d -c \"lssp -field name type " - "-fmt , -all|grep %s|sed -e 's/^.*,//g'\"", + "-fmt , -all|grep %s|sed -e 's/^.*,//'\"", managed_system, vios_id, backing_device) < 0) { virReportOOMError(); goto cleanup; @@ -983,7 +983,7 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type) if (virAsprintf(&cmd, "lssyscfg -r lpar -m %s -F lpar_id,state %s |grep -c " - "^[0-9]*", managed_system, state) < 0) { + "'^[0-9]*'", managed_system, state) < 0) { virReportOOMError(); goto err; } @@ -1051,7 +1051,7 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids, if (virAsprintf (&cmd, - "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'", + "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//'", managed_system, state) < 0) { virReportOOMError(); goto err; @@ -1115,7 +1115,7 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) if (virAsprintf (&cmd, "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " - "sed -e 's/,.*$//g'", managed_system) < 0) { + "sed -e 's/,.*$//'", managed_system) < 0) { virReportOOMError(); goto err; } @@ -1539,7 +1539,7 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) 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'", + "-e 's/^.*\\([0-9][0-9]*.[0-9][0-9]*\\).*$/\\1/'", managed_system, dom->id, operation, amount) < 0) { virReportOOMError(); goto err; -- 1.7.0.1

On 06/08/2010 10:17 PM, Eric Blake wrote:
While I was touching the file...
Thank you very much for this help :)
src/phyp/phyp_driver.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 0f4bc20..f8d12e7 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -886,7 +886,7 @@ phypGetVIOSPartitionID(virConnectPtr conn)
if (virAsprintf(&cmd, "lssyscfg -m %s -r lpar -F lpar_id,lpar_env|grep " - "vioserver|sed -s 's/,.*$//g'", managed_system)< 0) { + "vioserver|sed -s 's/,.*$//'", managed_system)< 0) { virReportOOMError(); goto err; } @@ -925,7 +925,7 @@ phypDiskType(virConnectPtr conn, char *backing_device)
if (virAsprintf(&cmd, "viosvrcmd -m %s -p %d -c \"lssp -field name type " - "-fmt , -all|grep %s|sed -e 's/^.*,//g'\"", + "-fmt , -all|grep %s|sed -e 's/^.*,//'\"", managed_system, vios_id, backing_device)< 0) { virReportOOMError(); goto cleanup; @@ -983,7 +983,7 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type)
if (virAsprintf(&cmd, "lssyscfg -r lpar -m %s -F lpar_id,state %s |grep -c " - "^[0-9]*", managed_system, state)< 0) { + "'^[0-9]*'", managed_system, state)< 0) { virReportOOMError(); goto err; } @@ -1051,7 +1051,7 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids,
if (virAsprintf (&cmd, - "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'", + "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//'", managed_system, state)< 0) { virReportOOMError(); goto err; @@ -1115,7 +1115,7 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) if (virAsprintf (&cmd, "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " - "sed -e 's/,.*$//g'", managed_system)< 0) { + "sed -e 's/,.*$//'", managed_system)< 0) { virReportOOMError(); goto err; } @@ -1539,7 +1539,7 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) 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'", + "-e 's/^.*\\([0-9][0-9]*.[0-9][0-9]*\\).*$/\\1/'", managed_system, dom->id, operation, amount)< 0) { virReportOOMError(); goto err;
I tested all the changes here and it's all ACK for me. -- Eduardo Otubo Software Engineer Linux Technology Center IBM Systems & Technology Group Mobile: +55 19 8135 0885 eotubo@linux.vnet.ibm.com

On 06/16/2010 01:17 PM, Eduardo Otubo wrote:
On 06/08/2010 10:17 PM, Eric Blake wrote:
While I was touching the file...
Thank you very much for this help :)
src/phyp/phyp_driver.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
I tested all the changes here and it's all ACK for me.
Thanks for the review; pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

Fixing all pointed in the previous email. Thanks for all the comments. --- src/phyp/phyp_driver.c | 356 +++++++++++++++++++++++++++++++++--------------- src/phyp/phyp_driver.h | 8 + 2 files changed, 252 insertions(+), 112 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index c04a487..60e2493 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__) +static unsigned const int HMC = 0; +static unsigned const int 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,11 +498,45 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status, return virBufferContentAndReset(&tex_ret); } +static char * +hmc_helper(int system_type, const char *managed_system) +{ + char *unsafe = NULL; + if (system_type == HMC) + virAsprintf(&unsafe, "-m %s", managed_system); + else + unsafe[0] = 0; + return unsafe; +} + +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(); + exit_status = -1; + } + ret = phypExec(session, cmd, &exit_status, conn); + + VIR_FREE(cmd); + VIR_FREE(ret); + return exit_status; +} + + /* 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; @@ -500,8 +544,8 @@ phypGetLparID(LIBSSH2_SESSION * session, const char *managed_system, char *ret = NULL; if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s --filter lpar_names=%s -F lpar_id", - managed_system, name) < 0) { + "lssyscfg -r lpar %s --filter lpar_names=%s -F lpar_id", + hmc_helper(system_type, managed_system), name) < 0) { virReportOOMError(); goto err; } @@ -529,13 +573,16 @@ 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) { + "lssyscfg -r lpar %s --filter lpar_ids=%d -F name", + hmc_helper(system_type, managed_system), + lpar_id) < 0) { virReportOOMError(); goto err; } @@ -595,6 +642,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; @@ -606,17 +655,19 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int lpar_id, if (type) { if (virAsprintf(&cmd, - "lshwres -m %s -r mem --level lpar -F curr_mem " + "lshwres %s -r mem --level lpar -F curr_mem " "--filter lpar_ids=%d", - managed_system, lpar_id) < 0) { + hmc_helper(system_type, managed_system), + lpar_id) < 0) { virReportOOMError(); goto err; } } else { if (virAsprintf(&cmd, - "lshwres -m %s -r mem --level lpar -F " + "lshwres %s -r mem --level lpar -F " "curr_max_mem --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { + hmc_helper(system_type, managed_system), + lpar_id) < 0) { virReportOOMError(); goto err; } @@ -667,6 +718,8 @@ 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; @@ -675,17 +728,19 @@ phypGetLparCPUGeneric(virConnectPtr conn, const char *managed_system, if (type) { if (virAsprintf(&cmd, - "lshwres -m %s -r proc --level lpar -F " + "lshwres %s -r proc --level lpar -F " "curr_max_procs --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { + hmc_helper(system_type, managed_system), + lpar_id) < 0) { virReportOOMError(); goto err; } } else { if (virAsprintf(&cmd, - "lshwres -m %s -r proc --level lpar -F " + "lshwres %s -r proc --level lpar -F " "curr_procs --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { + hmc_helper(system_type, managed_system), + lpar_id) < 0) { virReportOOMError(); goto err; } @@ -719,6 +774,8 @@ 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; @@ -726,9 +783,10 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system, int exit_status = 0; if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " + "lshwres %s -r virtualio --rsubtype scsi -F " "remote_slot_num --filter lpar_names=%s", - managed_system, lpar_name) < 0) { + hmc_helper(system_type, managed_system), + lpar_name) < 0) { virReportOOMError(); goto err; } @@ -761,6 +819,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; @@ -773,9 +833,10 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, goto err; if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " + "lshwres %s -r virtualio --rsubtype scsi -F " "backing_devices --filter slots=%d", - managed_system, remote_slot) < 0) { + hmc_helper(system_type, managed_system), + remote_slot) < 0) { virReportOOMError(); goto err; } @@ -834,6 +895,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; @@ -842,8 +904,9 @@ phypGetLparState(virConnectPtr conn, unsigned int lpar_id) int state = VIR_DOMAIN_NOSTATE; if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s -F state --filter lpar_ids=%d", - managed_system, lpar_id) < 0) { + "lssyscfg -r lpar %s -F state --filter lpar_ids=%d", + hmc_helper(system_type, managed_system), + lpar_id) < 0) { virReportOOMError(); goto cleanup; } @@ -877,6 +940,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; @@ -885,8 +949,9 @@ phypGetVIOSPartitionID(virConnectPtr conn) 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) { + "lssyscfg %s -r lpar -F lpar_id,lpar_env|grep " + "vioserver|sed -s 's/,.*$//g'", + hmc_helper(system_type, managed_system)) < 0) { virReportOOMError(); goto err; } @@ -915,6 +980,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; @@ -924,9 +990,10 @@ phypDiskType(virConnectPtr conn, char *backing_device) int disk_type = -1; if (virAsprintf(&cmd, - "viosvrcmd -m %s -p %d -c \"lssp -field name type " + "viosvrcmd %s -p %d -c \"lssp -field name type " "-fmt , -all|grep %s|sed -e 's/^.*,//g'\"", - managed_system, vios_id, backing_device) < 0) { + hmc_helper(system_type, managed_system), vios_id, + backing_device) < 0) { virReportOOMError(); goto cleanup; } @@ -966,6 +1033,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,14 +1044,19 @@ 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) { + "lssyscfg -r lpar %s -F lpar_id,state %s |grep -c " + "^[0-9]*", hmc_helper(system_type, + managed_system), state) < 0) { virReportOOMError(); goto err; } @@ -1032,6 +1105,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; @@ -1051,11 +1125,12 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids, if (virAsprintf (&cmd, - "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'", - managed_system, state) < 0) { + "lssyscfg -r lpar %s -F lpar_id,state %s | sed -e 's/,.*$//g'", + hmc_helper(system_type, managed_system), 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 +1178,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; @@ -1114,8 +1190,9 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) if (virAsprintf (&cmd, - "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " - "sed -e 's/,.*$//g'", managed_system) < 0) { + "lssyscfg -r lpar %s -F name,state | grep \"Not Activated\" | " + "sed -e 's/,.*$//g'", hmc_helper(system_type, + managed_system)) < 0) { virReportOOMError(); goto err; } @@ -1272,6 +1349,7 @@ 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; @@ -1279,8 +1357,9 @@ phypDomainResume(virDomainPtr dom) if (virAsprintf (&cmd, - "chsysstate -m %s -r lpar -o on --id %d -f %s", - managed_system, dom->id, dom->name) < 0) { + "chsysstate %s -r lpar -o on --id %d -f %s", + hmc_helper(system_type, managed_system), dom->id, + dom->name) < 0) { virReportOOMError(); goto err; } @@ -1304,8 +1383,10 @@ 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; @@ -1313,12 +1394,11 @@ phypDomainShutdown(virDomainPtr dom) if (virAsprintf (&cmd, - "chsysstate -m %s -r lpar -o shutdown --id %d", - managed_system, dom->id) < 0) { + "chsysstate %s -r lpar -o shutdown --id %d", + hmc_helper(system_type, managed_system), dom->id) < 0) { virReportOOMError(); goto err; } - ret = phypExec(session, cmd, &exit_status, dom->conn); if (exit_status < 0) @@ -1363,16 +1443,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); @@ -1396,8 +1485,7 @@ phypDomainDestroy(virDomainPtr dom) static virDomainPtr phypDomainCreateAndStart(virConnectPtr conn, - const char *xml, - unsigned int flags) + const char *xml, unsigned int flags) { ConnectionData *connection_data = conn->networkPrivateData; @@ -1510,6 +1598,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; @@ -1538,9 +1627,10 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) if (virAsprintf (&cmd, - "chhwres -r proc -m %s --id %d -o %c --procunits %d 2>&1 |sed" + "chhwres -r proc %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) { + hmc_helper(system_type, managed_system), dom->id, operation, + amount) < 0) { virReportOOMError(); goto err; } @@ -1548,8 +1638,9 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) 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; } @@ -1566,9 +1657,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 */ @@ -1647,23 +1736,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 @@ -1672,6 +1761,7 @@ 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; @@ -1679,11 +1769,11 @@ phypBuildLpar(virConnectPtr conn, virDomainDefPtr def) if (virAsprintf (&cmd, - "mksyscfg -m %s -r lpar -p %s -i min_mem=%d,desired_mem=%d," + "mksyscfg %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) { + hmc_helper(system_type, managed_system), def->name, + (int) def->memory, (int) def->memory, (int) def->maxmem, + (int) def->vcpus, def->disks[0]->src) < 0) { virReportOOMError(); goto err; } @@ -1799,7 +1889,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; } @@ -1950,14 +2041,33 @@ phypUUIDTable_Push(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) + < 0) { + virReportOOMError(); + goto err; + } if (stat(local_file, &local_fileinfo) == -1) { VIR_WARN0("Unable to stat local file."); @@ -2015,6 +2125,7 @@ phypUUIDTable_Push(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0; err: @@ -2034,6 +2145,7 @@ phypUUIDTable_Pull(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; struct stat fileinfo; char buffer[1024]; int rc = 0; @@ -2042,8 +2154,26 @@ 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) + < 0) { + virReportOOMError(); + goto err; + } /* Trying to stat the remote file. */ do { @@ -2075,7 +2205,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; @@ -2103,6 +2234,7 @@ phypUUIDTable_Pull(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0; err: 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

On 06/16/2010 04:22 PM, Eduardo Otubo wrote:
Fixing all pointed in the previous email. Thanks for all the comments.
--- src/phyp/phyp_driver.c | 356 +++++++++++++++++++++++++++++++++--------------- src/phyp/phyp_driver.h | 8 + 2 files changed, 252 insertions(+), 112 deletions(-)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index c04a487..60e2493 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__)
+static unsigned const int HMC = 0; +static unsigned const int 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,11 +498,45 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status, return virBufferContentAndReset(&tex_ret); }
+static char * +hmc_helper(int system_type, const char *managed_system) +{ + char *unsafe = NULL; + if (system_type == HMC) + virAsprintf(&unsafe, "-m %s", managed_system); + else + unsafe[0] = 0; + return unsafe; +} + +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(); + exit_status = -1; + } + ret = phypExec(session, cmd,&exit_status, conn); + + VIR_FREE(cmd); + VIR_FREE(ret); + return exit_status; +} + + /* 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; @@ -500,8 +544,8 @@ phypGetLparID(LIBSSH2_SESSION * session, const char *managed_system, char *ret = NULL;
if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s --filter lpar_names=%s -F lpar_id", - managed_system, name)< 0) { + "lssyscfg -r lpar %s --filter lpar_names=%s -F lpar_id", + hmc_helper(system_type, managed_system), name)< 0) { virReportOOMError(); goto err; } @@ -529,13 +573,16 @@ 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) { + "lssyscfg -r lpar %s --filter lpar_ids=%d -F name", + hmc_helper(system_type, managed_system), + lpar_id)< 0) { virReportOOMError(); goto err; } @@ -595,6 +642,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; @@ -606,17 +655,19 @@ phypGetLparMem(virConnectPtr conn, const char *managed_system, int lpar_id,
if (type) { if (virAsprintf(&cmd, - "lshwres -m %s -r mem --level lpar -F curr_mem " + "lshwres %s -r mem --level lpar -F curr_mem " "--filter lpar_ids=%d", - managed_system, lpar_id)< 0) { + hmc_helper(system_type, managed_system), + lpar_id)< 0) { virReportOOMError(); goto err; } } else { if (virAsprintf(&cmd, - "lshwres -m %s -r mem --level lpar -F " + "lshwres %s -r mem --level lpar -F " "curr_max_mem --filter lpar_ids=%d", - managed_system, lpar_id)< 0) { + hmc_helper(system_type, managed_system), + lpar_id)< 0) { virReportOOMError(); goto err; } @@ -667,6 +718,8 @@ 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; @@ -675,17 +728,19 @@ phypGetLparCPUGeneric(virConnectPtr conn, const char *managed_system,
if (type) { if (virAsprintf(&cmd, - "lshwres -m %s -r proc --level lpar -F " + "lshwres %s -r proc --level lpar -F " "curr_max_procs --filter lpar_ids=%d", - managed_system, lpar_id)< 0) { + hmc_helper(system_type, managed_system), + lpar_id)< 0) { virReportOOMError(); goto err; } } else { if (virAsprintf(&cmd, - "lshwres -m %s -r proc --level lpar -F " + "lshwres %s -r proc --level lpar -F " "curr_procs --filter lpar_ids=%d", - managed_system, lpar_id)< 0) { + hmc_helper(system_type, managed_system), + lpar_id)< 0) { virReportOOMError(); goto err; } @@ -719,6 +774,8 @@ 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; @@ -726,9 +783,10 @@ phypGetRemoteSlot(virConnectPtr conn, const char *managed_system, int exit_status = 0;
if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " + "lshwres %s -r virtualio --rsubtype scsi -F " "remote_slot_num --filter lpar_names=%s", - managed_system, lpar_name)< 0) { + hmc_helper(system_type, managed_system), + lpar_name)< 0) { virReportOOMError(); goto err; } @@ -761,6 +819,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; @@ -773,9 +833,10 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, goto err;
if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " + "lshwres %s -r virtualio --rsubtype scsi -F " "backing_devices --filter slots=%d", - managed_system, remote_slot)< 0) { + hmc_helper(system_type, managed_system), + remote_slot)< 0) { virReportOOMError(); goto err; } @@ -834,6 +895,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; @@ -842,8 +904,9 @@ phypGetLparState(virConnectPtr conn, unsigned int lpar_id) int state = VIR_DOMAIN_NOSTATE;
if (virAsprintf(&cmd, - "lssyscfg -r lpar -m %s -F state --filter lpar_ids=%d", - managed_system, lpar_id)< 0) { + "lssyscfg -r lpar %s -F state --filter lpar_ids=%d", + hmc_helper(system_type, managed_system), + lpar_id)< 0) { virReportOOMError(); goto cleanup; } @@ -877,6 +940,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; @@ -885,8 +949,9 @@ phypGetVIOSPartitionID(virConnectPtr conn) 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) { + "lssyscfg %s -r lpar -F lpar_id,lpar_env|grep " + "vioserver|sed -s 's/,.*$//g'", + hmc_helper(system_type, managed_system))< 0) { virReportOOMError(); goto err; } @@ -915,6 +980,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; @@ -924,9 +990,10 @@ phypDiskType(virConnectPtr conn, char *backing_device) int disk_type = -1;
if (virAsprintf(&cmd, - "viosvrcmd -m %s -p %d -c \"lssp -field name type " + "viosvrcmd %s -p %d -c \"lssp -field name type " "-fmt , -all|grep %s|sed -e 's/^.*,//g'\"", - managed_system, vios_id, backing_device)< 0) { + hmc_helper(system_type, managed_system), vios_id, + backing_device)< 0) { virReportOOMError(); goto cleanup; } @@ -966,6 +1033,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,14 +1044,19 @@ 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) { + "lssyscfg -r lpar %s -F lpar_id,state %s |grep -c " + "^[0-9]*", hmc_helper(system_type, + managed_system), state)< 0) { virReportOOMError(); goto err; } @@ -1032,6 +1105,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; @@ -1051,11 +1125,12 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids,
if (virAsprintf (&cmd, - "lssyscfg -r lpar -m %s -F lpar_id,state %s | sed -e 's/,.*$//g'", - managed_system, state)< 0) { + "lssyscfg -r lpar %s -F lpar_id,state %s | sed -e 's/,.*$//g'", + hmc_helper(system_type, managed_system), 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 +1178,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; @@ -1114,8 +1190,9 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames)
if (virAsprintf (&cmd, - "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " - "sed -e 's/,.*$//g'", managed_system)< 0) { + "lssyscfg -r lpar %s -F name,state | grep \"Not Activated\" | " + "sed -e 's/,.*$//g'", hmc_helper(system_type, + managed_system))< 0) { virReportOOMError(); goto err; } @@ -1272,6 +1349,7 @@ 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; @@ -1279,8 +1357,9 @@ phypDomainResume(virDomainPtr dom)
if (virAsprintf (&cmd, - "chsysstate -m %s -r lpar -o on --id %d -f %s", - managed_system, dom->id, dom->name)< 0) { + "chsysstate %s -r lpar -o on --id %d -f %s", + hmc_helper(system_type, managed_system), dom->id, + dom->name)< 0) { virReportOOMError(); goto err; } @@ -1304,8 +1383,10 @@ 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; @@ -1313,12 +1394,11 @@ phypDomainShutdown(virDomainPtr dom)
if (virAsprintf (&cmd, - "chsysstate -m %s -r lpar -o shutdown --id %d", - managed_system, dom->id)< 0) { + "chsysstate %s -r lpar -o shutdown --id %d", + hmc_helper(system_type, managed_system), dom->id)< 0) { virReportOOMError(); goto err; } - ret = phypExec(session, cmd,&exit_status, dom->conn);
if (exit_status< 0) @@ -1363,16 +1443,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); @@ -1396,8 +1485,7 @@ phypDomainDestroy(virDomainPtr dom)
static virDomainPtr phypDomainCreateAndStart(virConnectPtr conn, - const char *xml, - unsigned int flags) + const char *xml, unsigned int flags) {
ConnectionData *connection_data = conn->networkPrivateData; @@ -1510,6 +1598,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; @@ -1538,9 +1627,10 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus)
if (virAsprintf (&cmd, - "chhwres -r proc -m %s --id %d -o %c --procunits %d 2>&1 |sed" + "chhwres -r proc %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) { + hmc_helper(system_type, managed_system), dom->id, operation, + amount)< 0) { virReportOOMError(); goto err; } @@ -1548,8 +1638,9 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) 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; }
@@ -1566,9 +1657,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 */ @@ -1647,23 +1736,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 @@ -1672,6 +1761,7 @@ 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; @@ -1679,11 +1769,11 @@ phypBuildLpar(virConnectPtr conn, virDomainDefPtr def)
if (virAsprintf (&cmd, - "mksyscfg -m %s -r lpar -p %s -i min_mem=%d,desired_mem=%d," + "mksyscfg %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) { + hmc_helper(system_type, managed_system), def->name, + (int) def->memory, (int) def->memory, (int) def->maxmem, + (int) def->vcpus, def->disks[0]->src)< 0) { virReportOOMError(); goto err; } @@ -1799,7 +1889,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; }
@@ -1950,14 +2041,33 @@ phypUUIDTable_Push(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) +< 0) { + virReportOOMError(); + goto err; + }
if (stat(local_file,&local_fileinfo) == -1) { VIR_WARN0("Unable to stat local file."); @@ -2015,6 +2125,7 @@ phypUUIDTable_Push(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0;
err: @@ -2034,6 +2145,7 @@ phypUUIDTable_Pull(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; struct stat fileinfo; char buffer[1024]; int rc = 0; @@ -2042,8 +2154,26 @@ 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) +< 0) { + virReportOOMError(); + goto err; + }
/* Trying to stat the remote file. */ do { @@ -2075,7 +2205,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; @@ -2103,6 +2234,7 @@ phypUUIDTable_Pull(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0;
err: 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);
Sorry! It is supposed to be "Adding support..." Oh, I am embarassed. -- Eduardo Otubo Software Engineer Linux Technology Center IBM Systems & Technology Group Mobile: +55 19 8135 0885 eotubo@linux.vnet.ibm.com

On 06/16/2010 01:22 PM, Eduardo Otubo wrote:
Fixing all pointed in the previous email. Thanks for all the comments.
@@ -488,11 +498,45 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status, return virBufferContentAndReset(&tex_ret); }
+static char * +hmc_helper(int system_type, const char *managed_system) +{ + char *unsafe = NULL; + if (system_type == HMC) + virAsprintf(&unsafe, "-m %s", managed_system); + else + unsafe[0] = 0; + return unsafe;
Unfortunately, for the IVM case, this dereferences NULL :( And it has the problem that it is not thread-safe. I'm going to try my hand at tweaking this patch to use virBuffer instead, but we are getting closer... -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 06/16/2010 02:47 PM, Eric Blake wrote:
On 06/16/2010 01:22 PM, Eduardo Otubo wrote:
Fixing all pointed in the previous email. Thanks for all the comments.
@@ -488,11 +498,45 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status, return virBufferContentAndReset(&tex_ret); }
+static char * +hmc_helper(int system_type, const char *managed_system) +{ + char *unsafe = NULL; + if (system_type == HMC) + virAsprintf(&unsafe, "-m %s", managed_system); + else + unsafe[0] = 0; + return unsafe;
Unfortunately, for the IVM case, this dereferences NULL :(
And it has the problem that it is not thread-safe.
I'm going to try my hand at tweaking this patch to use virBuffer instead, but we are getting closer...
Here's what I'm thinking, at which point we don't need hmc_helper after all: diff --git i/src/phyp/phyp_driver.c w/src/phyp/phyp_driver.c index e111a47..1aea417 100644 --- i/src/phyp/phyp_driver.c +++ w/src/phyp/phyp_driver.c @@ -542,13 +542,18 @@ phypGetLparID(LIBSSH2_SESSION * session, const char *managed_system, char *char_ptr; char *cmd = NULL; char *ret = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; - if (virAsprintf(&cmd, - "lssyscfg -r lpar %s --filter lpar_names=%s -F lpar_id", - hmc_helper(system_type, managed_system), name) < 0) { + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " --filter lpar_names=%s -F lpar_id", name); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

From: Eduardo Otubo <otubo@linux.vnet.ibm.com> Use virBuffer* API to contionally keep the portion of the command line specific to HMC, so that IVM can work. --- This starts from Eduardo's patch, then converts everything away from using double virAsprintf (in the HVM case) over to using virBuffer. src/phyp/phyp_driver.c | 560 +++++++++++++++++++++++++++++++----------------- src/phyp/phyp_driver.h | 8 + 2 files changed, 368 insertions(+), 200 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 4c6391f..cefb8be 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__) +static unsigned const int HMC = 0; +static unsigned const int 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,23 +498,51 @@ 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(); + exit_status = -1; + } + ret = phypExec(session, cmd, &exit_status, conn); + + VIR_FREE(cmd); + VIR_FREE(ret); + return exit_status; +} + + /* 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " --filter lpar_names=%s -F lpar_id", name); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -529,16 +567,23 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " --filter lpar_ids=%d -F name", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return NULL; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -595,32 +640,29 @@ 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; int memory = 0; int exit_status = 0; + virBuffer buf = VIR_BUFFER_INITIALIZER; 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; - } - } 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; - } + return 0; + + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r mem --level lpar -F %s --filter lpar_ids=%d", + type ? "curr_mem" : "curr_max_mem", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); + virReportOOMError(); + return 0; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -667,29 +709,27 @@ 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; - } - } 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; - } + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r proc --level lpar -F %s --filter lpar_ids=%d", + type ? "curr_max_procs" : "curr_procs", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); + virReportOOMError(); + return 0; } + cmd = virBufferContentAndReset(&buf); + ret = phypExec(session, cmd, &exit_status, conn); if (exit_status < 0 || ret == NULL) @@ -719,19 +759,28 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r virtualio --rsubtype scsi -F " + "remote_slot_num --filter lpar_names=%s", + lpar_name); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); + ret = phypExec(session, cmd, &exit_status, conn); if (exit_status < 0 || ret == NULL) @@ -761,24 +810,31 @@ 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; int exit_status = 0; char *char_ptr; char *backing_device = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; if ((remote_slot = phypGetRemoteSlot(conn, managed_system, lpar_name)) == -1) - goto err; + return NULL; - if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " - "backing_devices --filter slots=%d", - managed_system, remote_slot) < 0) { + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r virtualio --rsubtype scsi -F " + "backing_devices --filter slots=%d", remote_slot); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return NULL; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -834,19 +890,25 @@ 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; char *char_ptr = NULL; 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F state --filter lpar_ids=%d", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto cleanup; + return state; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -877,19 +939,26 @@ 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; int id = -1; 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/,.*$//'", managed_system) < 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferAddLit(&buf, " -r lpar -F lpar_id,lpar_env|grep " + "vioserver|sed -s 's/,.*$//'"); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -915,6 +984,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; @@ -922,14 +992,20 @@ phypDiskType(virConnectPtr conn, char *backing_device) char *managed_system = phyp_driver->managed_system; 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/^.*,//'\"", - managed_system, vios_id, backing_device) < 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "viosvrcmd"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -p %d -c \"lssp -field name type " + "-fmt , -all|grep %s|sed -e 's/^.*,//'\"", + vios_id, backing_device); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto cleanup; + return disk_type; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -966,6 +1042,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; @@ -973,20 +1050,29 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type) char *ret = NULL; char *managed_system = phyp_driver->managed_system; const char *state; + virBuffer buf = VIR_BUFFER_INITIALIZER; 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) { + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F lpar_id,state %s |grep -c '^[0-9]*'", state); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -1032,6 +1118,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; @@ -1041,6 +1128,7 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids, char *cmd = NULL; char *ret = NULL; const char *state; + virBuffer buf = VIR_BUFFER_INITIALIZER; if (type == 0) state = "|grep Running"; @@ -1049,13 +1137,17 @@ 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/,.*$//'", - managed_system, state) < 0) { + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F lpar_id,state %s | sed -e 's/,.*$//'", state); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); + ret = phypExec(session, cmd, &exit_status, conn); /* I need to parse the textual return in order to get the ret */ @@ -1103,6 +1195,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; @@ -1111,14 +1204,19 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) char *ret = NULL; char *domains = NULL; char *char_ptr2 = NULL; - - if (virAsprintf - (&cmd, - "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " - "sed -e 's/,.*$//'", managed_system) < 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F name,state | grep \"Not Activated\" | " + "sed -e 's/,.*$//'"); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -1272,18 +1370,24 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "chsysstate"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r lpar -o on --id %d -f %s", + dom->id, dom->name); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, dom->conn); @@ -1304,20 +1408,26 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "chsysstate"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r lpar -o shutdown --id %d", dom->id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return 0; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, dom->conn); @@ -1363,17 +1473,23 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "rmsyscfg"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r lpar --id %d", dom->id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, dom->conn); @@ -1396,8 +1512,7 @@ phypDomainDestroy(virDomainPtr dom) static virDomainPtr phypDomainCreateAndStart(virConnectPtr conn, - const char *xml, - unsigned int flags) + const char *xml, unsigned int flags) { ConnectionData *connection_data = conn->networkPrivateData; @@ -1510,6 +1625,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; @@ -1517,14 +1633,15 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) char operation; unsigned long ncpus = 0; unsigned int amount = 0; + virBuffer buf = VIR_BUFFER_INITIALIZER; if ((ncpus = phypGetLparCPU(dom->conn, managed_system, dom->id)) == 0) - goto err; + return 0; if (nvcpus > phypGetLparCPUMAX(dom)) { VIR_ERROR0(_("You are trying to set a number of CPUs bigger than " - "the max possible..")); - goto err; + "the max possible.")); + return 0; } if (ncpus > nvcpus) { @@ -1534,31 +1651,29 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) operation = 'a'; amount = nvcpus - ncpus; } 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]*.[0-9][0-9]*\\).*$/\\1/'", - managed_system, dom->id, operation, amount) < 0) { + return 0; + + virBufferAddLit(&buf, "chhwres -r proc"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " --id %d -o %c --procunits %d 2>&1 |sed " + "-e 's/^.*\\([0-9][0-9]*.[0-9][0-9]*\\).*$/\\1/'", + dom->id, operation, amount); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return 0; } + cmd = virBufferContentAndReset(&buf); 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.")); - goto err; + VIR_ERROR0(_ + ("Possibly you don't have IBM Tools installed in your LPAR." + " Contact your support to enable this feature.")); } - exit: - VIR_FREE(cmd); - VIR_FREE(ret); - return 0; - - err: VIR_FREE(cmd); VIR_FREE(ret); return 0; @@ -1566,9 +1681,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 */ @@ -1647,23 +1760,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 @@ -1672,21 +1785,26 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "mksyscfg"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -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); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); ret = phypExec(session, cmd, &exit_status, conn); @@ -1799,7 +1917,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; } @@ -1950,14 +2069,33 @@ phypUUIDTable_Push(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) + < 0) { + virReportOOMError(); + goto err; + } if (stat(local_file, &local_fileinfo) == -1) { VIR_WARN0("Unable to stat local file."); @@ -2015,6 +2153,7 @@ phypUUIDTable_Push(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0; err: @@ -2034,6 +2173,7 @@ phypUUIDTable_Pull(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; struct stat fileinfo; char buffer[1024]; int rc = 0; @@ -2042,8 +2182,26 @@ 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) + < 0) { + virReportOOMError(); + goto err; + } /* Trying to stat the remote file. */ do { @@ -2075,7 +2233,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; @@ -2103,6 +2262,7 @@ phypUUIDTable_Pull(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0; err: 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.1

On 06/16/2010 07:04 PM, Eric Blake wrote:
From: Eduardo Otubo<otubo@linux.vnet.ibm.com>
Use virBuffer* API to contionally keep the portion of the command line specific to HMC, so that IVM can work. ---
This starts from Eduardo's patch, then converts everything away from using double virAsprintf (in the HVM case) over to using virBuffer.
src/phyp/phyp_driver.c | 560 +++++++++++++++++++++++++++++++----------------- src/phyp/phyp_driver.h | 8 + 2 files changed, 368 insertions(+), 200 deletions(-)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 4c6391f..cefb8be 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__)
+static unsigned const int HMC = 0; +static unsigned const int 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,23 +498,51 @@ 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(); + exit_status = -1; + } + ret = phypExec(session, cmd,&exit_status, conn); + + VIR_FREE(cmd); + VIR_FREE(ret); + return exit_status; +} + + /* 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " --filter lpar_names=%s -F lpar_id", name); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -529,16 +567,23 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " --filter lpar_ids=%d -F name", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return NULL; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -595,32 +640,29 @@ 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; int memory = 0; int exit_status = 0; + virBuffer buf = VIR_BUFFER_INITIALIZER;
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; - } - } 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; - } + return 0; + + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r mem --level lpar -F %s --filter lpar_ids=%d", + type ? "curr_mem" : "curr_max_mem", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); + virReportOOMError(); + return 0; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -667,29 +709,27 @@ 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; - } - } 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; - } + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r proc --level lpar -F %s --filter lpar_ids=%d", + type ? "curr_max_procs" : "curr_procs", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); + virReportOOMError(); + return 0; } + cmd = virBufferContentAndReset(&buf); + ret = phypExec(session, cmd,&exit_status, conn);
if (exit_status< 0 || ret == NULL) @@ -719,19 +759,28 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r virtualio --rsubtype scsi -F " + "remote_slot_num --filter lpar_names=%s", + lpar_name); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); + ret = phypExec(session, cmd,&exit_status, conn);
if (exit_status< 0 || ret == NULL) @@ -761,24 +810,31 @@ 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; int exit_status = 0; char *char_ptr; char *backing_device = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER;
if ((remote_slot = phypGetRemoteSlot(conn, managed_system, lpar_name)) == -1) - goto err; + return NULL;
- if (virAsprintf(&cmd, - "lshwres -m %s -r virtualio --rsubtype scsi -F " - "backing_devices --filter slots=%d", - managed_system, remote_slot)< 0) { + virBufferAddLit(&buf, "lshwres"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r virtualio --rsubtype scsi -F " + "backing_devices --filter slots=%d", remote_slot); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return NULL; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -834,19 +890,25 @@ 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; char *char_ptr = NULL; 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F state --filter lpar_ids=%d", lpar_id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto cleanup; + return state; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -877,19 +939,26 @@ 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; int id = -1; 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/,.*$//'", managed_system)< 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferAddLit(&buf, " -r lpar -F lpar_id,lpar_env|grep " + "vioserver|sed -s 's/,.*$//'"); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -915,6 +984,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; @@ -922,14 +992,20 @@ phypDiskType(virConnectPtr conn, char *backing_device) char *managed_system = phyp_driver->managed_system; 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/^.*,//'\"", - managed_system, vios_id, backing_device)< 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "viosvrcmd"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -p %d -c \"lssp -field name type " + "-fmt , -all|grep %s|sed -e 's/^.*,//'\"", + vios_id, backing_device); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto cleanup; + return disk_type; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -966,6 +1042,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; @@ -973,20 +1050,29 @@ phypNumDomainsGeneric(virConnectPtr conn, unsigned int type) char *ret = NULL; char *managed_system = phyp_driver->managed_system; const char *state; + virBuffer buf = VIR_BUFFER_INITIALIZER;
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) { + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F lpar_id,state %s |grep -c '^[0-9]*'", state); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -1032,6 +1118,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; @@ -1041,6 +1128,7 @@ phypListDomainsGeneric(virConnectPtr conn, int *ids, int nids, char *cmd = NULL; char *ret = NULL; const char *state; + virBuffer buf = VIR_BUFFER_INITIALIZER;
if (type == 0) state = "|grep Running"; @@ -1049,13 +1137,17 @@ 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/,.*$//'", - managed_system, state)< 0) { + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F lpar_id,state %s | sed -e 's/,.*$//'", state); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf); + ret = phypExec(session, cmd,&exit_status, conn);
/* I need to parse the textual return in order to get the ret */ @@ -1103,6 +1195,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; @@ -1111,14 +1204,19 @@ phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames) char *ret = NULL; char *domains = NULL; char *char_ptr2 = NULL; - - if (virAsprintf - (&cmd, - "lssyscfg -r lpar -m %s -F name,state | grep \"Not Activated\" | " - "sed -e 's/,.*$//'", managed_system)< 0) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "lssyscfg -r lpar"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -F name,state | grep \"Not Activated\" | " + "sed -e 's/,.*$//'"); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -1272,18 +1370,24 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "chsysstate"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r lpar -o on --id %d -f %s", + dom->id, dom->name); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, dom->conn);
@@ -1304,20 +1408,26 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "chsysstate"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r lpar -o shutdown --id %d", dom->id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return 0; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, dom->conn);
@@ -1363,17 +1473,23 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "rmsyscfg"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -r lpar --id %d", dom->id); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, dom->conn);
@@ -1396,8 +1512,7 @@ phypDomainDestroy(virDomainPtr dom)
static virDomainPtr phypDomainCreateAndStart(virConnectPtr conn, - const char *xml, - unsigned int flags) + const char *xml, unsigned int flags) {
ConnectionData *connection_data = conn->networkPrivateData; @@ -1510,6 +1625,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; @@ -1517,14 +1633,15 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) char operation; unsigned long ncpus = 0; unsigned int amount = 0; + virBuffer buf = VIR_BUFFER_INITIALIZER;
if ((ncpus = phypGetLparCPU(dom->conn, managed_system, dom->id)) == 0) - goto err; + return 0;
if (nvcpus> phypGetLparCPUMAX(dom)) { VIR_ERROR0(_("You are trying to set a number of CPUs bigger than " - "the max possible..")); - goto err; + "the max possible.")); + return 0; }
if (ncpus> nvcpus) { @@ -1534,31 +1651,29 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus) operation = 'a'; amount = nvcpus - ncpus; } 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]*.[0-9][0-9]*\\).*$/\\1/'", - managed_system, dom->id, operation, amount)< 0) { + return 0; + + virBufferAddLit(&buf, "chhwres -r proc"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " --id %d -o %c --procunits %d 2>&1 |sed " + "-e 's/^.*\\([0-9][0-9]*.[0-9][0-9]*\\).*$/\\1/'", + dom->id, operation, amount); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return 0; } + cmd = virBufferContentAndReset(&buf);
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.")); - goto err; + VIR_ERROR0(_ + ("Possibly you don't have IBM Tools installed in your LPAR." + " Contact your support to enable this feature.")); }
- exit: - VIR_FREE(cmd); - VIR_FREE(ret); - return 0; - - err: VIR_FREE(cmd); VIR_FREE(ret); return 0; @@ -1566,9 +1681,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 */ @@ -1647,23 +1760,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 @@ -1672,21 +1785,26 @@ 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) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virBufferAddLit(&buf, "mksyscfg"); + if (system_type == HMC) + virBufferVSprintf(&buf, " -m %s", managed_system); + virBufferVSprintf(&buf, " -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); + if (virBufferError(&buf)) { + virBufferFreeAndReset(&buf); virReportOOMError(); - goto err; + return -1; } + cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd,&exit_status, conn);
@@ -1799,7 +1917,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; }
@@ -1950,14 +2069,33 @@ phypUUIDTable_Push(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) +< 0) { + virReportOOMError(); + goto err; + }
if (stat(local_file,&local_fileinfo) == -1) { VIR_WARN0("Unable to stat local file."); @@ -2015,6 +2153,7 @@ phypUUIDTable_Push(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0;
err: @@ -2034,6 +2173,7 @@ phypUUIDTable_Pull(virConnectPtr conn) ConnectionData *connection_data = conn->networkPrivateData; LIBSSH2_SESSION *session = connection_data->session; LIBSSH2_CHANNEL *channel = NULL; + virBuffer username = VIR_BUFFER_INITIALIZER; struct stat fileinfo; char buffer[1024]; int rc = 0; @@ -2042,8 +2182,26 @@ 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) { + virBufferVSprintf(&username, "%s", conn->uri->user); + + if (virBufferError(&username)) { + virBufferFreeAndReset(&username); + virReportOOMError(); + goto err; + } + } + + if (virAsprintf + (&remote_file, "/home/%s/libvirt_uuid_table", + virBufferContentAndReset(&username)) +< 0) { + virReportOOMError(); + goto err; + }
/* Trying to stat the remote file. */ do { @@ -2075,7 +2233,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; @@ -2103,6 +2262,7 @@ phypUUIDTable_Pull(virConnectPtr conn) libssh2_channel_free(channel); channel = NULL; } + virBufferFreeAndReset(&username); return 0;
err: 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);
Tested here, working on both HMC and IVM. Thanks! -- Eduardo Otubo Software Engineer Linux Technology Center IBM Systems & Technology Group Mobile: +55 19 8135 0885 eotubo@linux.vnet.ibm.com

On 06/16/2010 06:29 PM, Eduardo Otubo wrote:
On 06/16/2010 07:04 PM, Eric Blake wrote:
From: Eduardo Otubo<otubo@linux.vnet.ibm.com>
Use virBuffer* API to contionally keep the portion of the command line specific to HMC, so that IVM can work.
Tested here, working on both HMC and IVM. Thanks!
Thanks for the review; pushed now. And feel free to trim portions of quoted emails, if it makes it easier to get to your comments. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eduardo Otubo
-
Eric Blake