{
LIBSSH2_SESSION *session = NULL;
ConnectionData *connection_data = NULL;
- char *string;
+ char *string = NULL;
size_t len = 0;
int internal_socket;
uuid_tablePtr uuid_table = NULL;
goto failure;
}
- if (VIR_ALLOC_N(managed_system, len) < 0) {
+ /* 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(conn);
goto failure;
}
- managed_system = strdup(conn->uri->path);
- if (!managed_system)
- goto failure;
-
- /* need to shift one byte in order to remove the first "/" of URI component */
- if (managed_system[0] == '/')
- managed_system++;
-
/* here we are handling only the first component of the path,
* so skipping the second:
* */
return VIR_DRV_OPEN_SUCCESS;
failure:
- virCapabilitiesFree(phyp_driver->caps);
- VIR_FREE(phyp_driver->managed_system);
- VIR_FREE(phyp_driver);
- VIR_FREE(uuid_table);
- VIR_FREE(uuid_table->lpars);
+ if (phyp_driver != NULL) {
+ virCapabilitiesFree(phyp_driver->caps);
+ VIR_FREE(phyp_driver->managed_system);
+ VIR_FREE(phyp_driver);
+ }
+
+ phypUUIDTable_Free(uuid_table);
+
+ if (session != NULL) {
+ libssh2_session_disconnect(session, "Disconnecting...");
+ libssh2_session_free(session);
+ }
+
VIR_FREE(connection_data);
VIR_FREE(string);
libssh2_session_free(session);
virCapabilitiesFree(phyp_driver->caps);
- VIR_FREE(phyp_driver->uuid_table);
- VIR_FREE(phyp_driver->uuid_table->lpars);
+ phypUUIDTable_Free(phyp_driver->uuid_table);
VIR_FREE(phyp_driver->managed_system);
VIR_FREE(phyp_driver);
VIR_FREE(connection_data);
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("Failure establishing SSH session."));
- goto err;
+ goto disconnect;
}
/* Trying authentication by pubkey */
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("No authentication callback provided."));
- goto err;
+ goto disconnect;
}
for (i = 0; i < auth->ncredtype; i++) {
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("Required credentials are not supported."));
- goto err;
+ goto disconnect;
}
int res =
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("Unable to fetch credentials."));
- goto err;
+ goto disconnect;
}
if (creds[0].result) {
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("Unable to get password certificates"));
- libssh2_session_disconnect(session, "Disconnecting...");
- libssh2_session_free(session);
- goto err;
+ goto disconnect;
}
while ((rc =
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("Authentication failed"));
- libssh2_session_disconnect(session, "Disconnecting");
- libssh2_session_free(session);
- goto err;
+ goto disconnect;
} else
goto exit;
}
+ disconnect:
+ libssh2_session_disconnect(session, "Disconnecting...");
+ libssh2_session_free(session);
err:
+ VIR_FREE(password);
return NULL;
exit:
+ VIR_FREE(password);
return session;
}
int exit_status = 0;
int lpar_id = 0;
char *char_ptr;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
if (virAsprintf(&cmd,
"lssyscfg -r lpar -m %s --filter lpar_names=%s -F lpar_id",
goto err;
}
- const char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
goto err;
goto err;
VIR_FREE(cmd);
+ VIR_FREE(ret);
return lpar_id;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return -1;
}
phypGetLparNAME(LIBSSH2_SESSION * session, const char *managed_system,
unsigned int lpar_id, virConnectPtr conn)
{
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
int exit_status = 0;
if (virAsprintf(&cmd,
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (ret == NULL)
goto err;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return NULL;
}
{
ConnectionData *connection_data = conn->networkPrivateData;
LIBSSH2_SESSION *session = connection_data->session;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
char *char_ptr;
int memory = 0;
int exit_status = 0;
}
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (ret == NULL)
goto err;
goto err;
VIR_FREE(cmd);
+ VIR_FREE(ret);
return memory;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return 0;
}
{
ConnectionData *connection_data = conn->networkPrivateData;
LIBSSH2_SESSION *session = connection_data->session;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
int exit_status = 0;
int vcpus = 0;
goto err;
}
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (ret == NULL)
goto err;
goto err;
VIR_FREE(cmd);
+ VIR_FREE(ret);
return (unsigned long) vcpus;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return 0;
}
{
ConnectionData *connection_data = conn->networkPrivateData;
LIBSSH2_SESSION *session = connection_data->session;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
char *char_ptr;
int remote_slot = 0;
int exit_status = 0;
virReportOOMError(conn);
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (ret == NULL)
goto err;
goto err;
VIR_FREE(cmd);
+ VIR_FREE(ret);
return remote_slot;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return -1;
}
{
ConnectionData *connection_data = conn->networkPrivateData;
LIBSSH2_SESSION *session = connection_data->session;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
int remote_slot = 0;
int exit_status = 0;
+ char *char_ptr;
+ char *backing_device = NULL;
if ((remote_slot =
phypGetRemoteSlot(conn, managed_system, lpar_name)) == -1)
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
- if (ret == NULL)
+ if (exit_status < 0 || ret == NULL)
goto err;
/* here is a little trick to deal returns of this kind:
* the information we really need is only lv01, so we
* need to skip a lot of things on the string.
* */
- char *backing_device = strchr(ret, '/');
+ char_ptr = strchr(ret, '/');
- if (backing_device) {
- backing_device++;
- if (backing_device[0] == '/')
- backing_device++;
+ if (char_ptr) {
+ char_ptr++;
+ if (char_ptr[0] == '/')
+ char_ptr++;
else
goto err;
+
+ backing_device = strdup(char_ptr);
+
+ if (backing_device == NULL) {
+ virReportOOMError(conn);
+ goto err;
+ }
} else {
backing_device = ret;
+ ret = NULL;
}
- char *char_ptr = strchr(backing_device, '\n');
+ char_ptr = strchr(backing_device, '\n');
if (char_ptr)
*char_ptr = '\0';
- if (exit_status < 0 || backing_device == NULL)
- goto err;
-
VIR_FREE(cmd);
+ VIR_FREE(ret);
return backing_device;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return NULL;
}
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
- char *cmd;
+ 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) {
virReportOOMError(conn);
- goto err;
+ goto cleanup;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
- if (ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL)
+ goto cleanup;
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- VIR_FREE(cmd);
if (STREQ(ret, "Running"))
- return VIR_DOMAIN_RUNNING;
+ state = VIR_DOMAIN_RUNNING;
else if (STREQ(ret, "Not Activated"))
- return VIR_DOMAIN_SHUTOFF;
+ state = VIR_DOMAIN_SHUTOFF;
else if (STREQ(ret, "Shutting Down"))
- return VIR_DOMAIN_SHUTDOWN;
- else
- goto err;
+ state = VIR_DOMAIN_SHUTDOWN;
- err:
+ cleanup:
VIR_FREE(cmd);
- return VIR_DOMAIN_NOSTATE;
+ VIR_FREE(ret);
+ return state;
}
int
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
int exit_status = 0;
int id = -1;
char *char_ptr;
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
goto err;
if (virStrToLong_i(ret, &char_ptr, 10, &id) == -1)
goto err;
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
return id;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return -1;
}
phyp_driverPtr phyp_driver = conn->privateData;
ConnectionData *connection_data = conn->networkPrivateData;
LIBSSH2_SESSION *session = connection_data->session;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
int exit_status = 0;
char *char_ptr;
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/^.*,//g'\"",
managed_system, vios_id, backing_device) < 0) {
virReportOOMError(conn);
- goto err;
+ goto cleanup;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
- if (ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL)
+ goto cleanup;
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
- if (exit_status < 0 || ret == NULL)
- goto err;
-
- VIR_FREE(cmd);
if (STREQ(ret, "LVPOOL"))
- return VIR_DOMAIN_DISK_TYPE_BLOCK;
+ disk_type = VIR_DOMAIN_DISK_TYPE_BLOCK;
else if (STREQ(ret, "FBPOOL"))
- return VIR_DOMAIN_DISK_TYPE_FILE;
- else
- goto err;
+ disk_type = VIR_DOMAIN_DISK_TYPE_FILE;
- err:
+ cleanup:
VIR_FREE(cmd);
- return -1;
+ VIR_FREE(ret);
+ return disk_type;
}
/* This is a generic function that won't be used directly by
int exit_status = 0;
int ndom = 0;
char *char_ptr;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
char *managed_system = phyp_driver->managed_system;
const char *state;
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
goto err;
goto err;
VIR_FREE(cmd);
+ VIR_FREE(ret);
return ndom;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return 0;
}
char *char_ptr;
unsigned int i = 0, j = 0;
char id_c[10];
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
const char *state;
if (type == 0)
virReportOOMError(conn);
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
/* I need to parse the textual return in order to get the ret */
if (exit_status < 0 || ret == NULL)
}
VIR_FREE(cmd);
+ VIR_FREE(ret);
return got;
err:
VIR_FREE(cmd);
+ VIR_FREE(ret);
return 0;
}
char *managed_system = phyp_driver->managed_system;
int exit_status = 0;
int got = 0;
- char *cmd;
- char *domains;
+ int i;
+ char *cmd = NULL;
+ char *ret = NULL;
+ char *domains = NULL;
+ char *char_ptr2 = NULL;
if (virAsprintf
(&cmd,
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
-
- if (VIR_ALLOC(domains) < 0)
- virReportOOMError(conn);
-
- domains = strdup(ret);
- if (!domains)
- goto err;
+ ret = phypExec(session, cmd, &exit_status, conn);
- char *char_ptr2 = NULL;
/* I need to parse the textual return in order to get the domains */
- if (exit_status < 0 || domains == NULL)
+ if (exit_status < 0 || ret == NULL)
goto err;
else {
+ domains = ret;
+
while (got < nnames) {
char_ptr2 = strchr(domains, '\n');
if (char_ptr2) {
*char_ptr2 = '\0';
- if (!strdup(domains))
+ if ((names[got++] = strdup(domains)) == NULL) {
+ virReportOOMError(conn);
goto err;
- names[got] = strdup(domains);
+ }
char_ptr2++;
domains = char_ptr2;
- got++;
}
}
}
- VIR_FREE(domains);
VIR_FREE(cmd);
VIR_FREE(ret);
return got;
err:
- VIR_FREE(domains);
+ for (i = 0; i < got; i++)
+ VIR_FREE(names[i]);
+ VIR_FREE(cmd);
VIR_FREE(ret);
return 0;
}
LIBSSH2_SESSION *session = connection_data->session;
char *managed_system = phyp_driver->managed_system;
int exit_status = 0;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
if (virAsprintf
(&cmd,
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, dom->conn);
+ ret = phypExec(session, cmd, &exit_status, dom->conn);
if (exit_status < 0)
goto err;
LIBSSH2_SESSION *session = connection_data->session;
char *managed_system = phyp_driver->managed_system;
int exit_status = 0;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
if (virAsprintf
(&cmd,
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, dom->conn);
+ ret = phypExec(session, cmd, &exit_status, dom->conn);
if (exit_status < 0)
goto err;
LIBSSH2_SESSION *session = connection_data->session;
char *managed_system = phyp_driver->managed_system;
int exit_status = 0;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
if (virAsprintf
(&cmd,
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, dom->conn);
+ ret = phypExec(session, cmd, &exit_status, dom->conn);
if (exit_status < 0)
goto err;
err:
virDomainDefFree(def);
- VIR_FREE(dom);
+ if (dom)
+ virUnrefDomain(dom);
return NULL;
}
LIBSSH2_SESSION *session = connection_data->session;
char *managed_system = phyp_driver->managed_system;
int exit_status = 0;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
char operation;
unsigned long ncpus = 0;
unsigned int amount = 0;
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, dom->conn);
+ ret = phypExec(session, cmd, &exit_status, dom->conn);
if (exit_status < 0) {
VIR_ERROR("%s",
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
char *managed_system = phyp_driver->managed_system;
- char *cmd;
+ char *cmd = NULL;
+ char *ret = NULL;
int exit_status = 0;
if (virAsprintf
goto err;
}
- char *ret = phypExec(session, cmd, &exit_status, conn);
+ ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0) {
VIR_ERROR("%s\"%s\"", "Unable to create LPAR. Reason: ", ret);
rc = read(fd, buffer, sizeof(int));
if (rc == sizeof(int)) {
- if (VIR_ALLOC(uuid_table->lpars[i]) < 0)
+ if (VIR_ALLOC(uuid_table->lpars[i]) < 0) {
virReportOOMError(conn);
+ goto err;
+ }
uuid_table->lpars[i]->id = (*buffer);
} else {
VIR_WARN("%s",
return -1;
}
+void
+phypUUIDTable_Free(uuid_tablePtr uuid_table)
+{
+ int i;
+
+ if (uuid_table == NULL)
+ return;
+
+ for (i = 0; i < uuid_table->nlpars; i++)
+ VIR_FREE(uuid_table->lpars[i]);
+
+ VIR_FREE(uuid_table->lpars);
+ VIR_FREE(uuid_table);
+}
+
int
phypUUIDTable_Push(virConnectPtr conn)
{