/* this function is the layer that manipulates the ssh channel itself
* and executes the commands on the remote machine */
static char *
-phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status,
+phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
virConnectPtr conn)
{
LIBSSH2_CHANNEL *channel;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &id) == -1)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return id;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return id;
}
static virCapsPtr
LIBSSH2_SESSION *session = connection_data->session;
int system_type = phyp_driver->system_type;
int exit_status = 0;
- int ndom = 0;
+ int ndom = -1;
char *char_ptr;
char *cmd = NULL;
char *ret = NULL;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &ndom) == -1)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return ndom;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return ndom;
}
/* This is a generic function that won't be used directly by
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
/* I need to parse the textual return in order to get the ids */
line = ret;
if (virStrToLong_i(line, &next_line, 10, &ids[got]) == -1) {
VIR_ERROR(_("Cannot parse number from '%s'"), line);
got = -1;
- goto err;
+ goto cleanup;
}
got++;
line = next_line;
line++; /* skip \n */
}
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
+
return got;
}
phyp_driverPtr phyp_driver = conn->privateData;
int system_type = phyp_driver->system_type;
int exit_status = 0;
- int lpar_id = 0;
+ int lpar_id = -1;
char *char_ptr;
char *cmd = NULL;
char *ret = NULL;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &lpar_id) == -1)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return lpar_id;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return lpar_id;
}
/* return the lpar name given a lpar_id and a managed system name */
ret = phypExec(session, cmd, &exit_status, conn);
- if (exit_status < 0 || ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL) {
+ VIR_FREE(ret);
+ goto cleanup;
+ }
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
+ cleanup:
VIR_FREE(cmd);
- return ret;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ return ret;
}
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
char_ptr = strchr(ret, '\n');
*char_ptr = '\0';
if (virStrToLong_i(ret, &char_ptr, 10, &memory) == -1)
- goto err;
-
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return memory;
+ goto cleanup;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return 0;
+ return memory;
}
static unsigned long
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
char_ptr = strchr(ret, '\n');
*char_ptr = '\0';
if (virStrToLong_i(ret, &char_ptr, 10, &vcpus) == -1)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return (unsigned long) vcpus;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ return vcpus;
}
static unsigned long
char *cmd = NULL;
char *ret = NULL;
char *char_ptr;
- int remote_slot = 0;
+ int remote_slot = -1;
int exit_status = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
char_ptr = strchr(ret, '\n');
*char_ptr = '\0';
if (virStrToLong_i(ret, &char_ptr, 10, &remote_slot) == -1)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return remote_slot;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return remote_slot;
}
/* XXX - is this needed? */
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
/* here is a little trick to deal returns of this kind:
*
if (char_ptr[0] == '/')
char_ptr++;
else
- goto err;
+ goto cleanup;
backing_device = strdup(char_ptr);
if (backing_device == NULL) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
} else {
backing_device = ret;
if (char_ptr)
*char_ptr = '\0';
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return backing_device;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ return backing_device;
}
static char *
ret = phypExec(session, cmd, &exit_status, conn);
- if (exit_status < 0 || ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL) {
+ VIR_FREE(ret);
+ goto cleanup;
+ }
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
+ cleanup:
VIR_FREE(cmd);
- return ret;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ return ret;
}
static int
char *cmd = NULL;
char *ret = NULL;
char *profile = NULL;
- int slot = 0;
+ int slot = -1;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (!(profile = phypGetLparProfile(conn, vios_id))) {
VIR_ERROR0(_("Unable to get VIOS profile name."));
- goto err;
+ return -1;
}
virBufferAddLit(&buf, "lssyscfg");
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
- goto err;
+ goto cleanup;
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return slot + 1;
+ slot += 1;
- err:
+ cleanup:
+ VIR_FREE(profile);
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return slot;
}
static int
phypCreateServerSCSIAdapter(virConnectPtr conn)
{
+ int result = -1;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
(vios_name =
phypGetLparNAME(session, managed_system, vios_id, conn))) {
VIR_ERROR0(_("Unable to get VIOS name"));
- goto err;
+ goto cleanup;
}
if (!(profile = phypGetLparProfile(conn, vios_id))) {
VIR_ERROR0(_("Unable to get VIOS profile name."));
- goto err;
+ goto cleanup;
}
if ((slot = phypGetVIOSNextSlotNumber(conn)) == -1) {
VIR_ERROR0(_("Unable to get free slot number"));
- goto err;
+ goto cleanup;
}
/* Listing all the virtual_scsi_adapter interfaces, the new adapter must
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
/* Here I change the VIOS configuration to append the new adapter
* with the free slot I got with phypGetVIOSNextSlotNumber.
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
- cmd = virBufferContentAndReset(&buf);
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
+
+ cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
/* Finally I add the new scsi adapter to VIOS using the same slot
* I used in the VIOS configuration.
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
- cmd = virBufferContentAndReset(&buf);
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
+
+ cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
- VIR_FREE(profile);
- VIR_FREE(vios_name);
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(profile);
VIR_FREE(vios_name);
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return result;
}
static char *
ret = phypExec(session, cmd, &exit_status, conn);
- if (exit_status < 0 || ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL) {
+ VIR_FREE(ret);
+ goto cleanup;
+ }
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
+ cleanup:
VIR_FREE(cmd);
- return ret;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ return ret;
}
static int
phypAttachDevice(virDomainPtr domain, const char *xml)
{
-
+ int result = -1;
virConnectPtr conn = domain->conn;
ConnectionData *connection_data = domain->conn->networkPrivateData;
phyp_driverPtr phyp_driver = domain->conn->privateData;
if (VIR_ALLOC_N(domain_name, sizeof(domain->name)) < 0) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
if (escape_specialcharacters
(domain->name, domain_name, strlen(domain->name)) == -1) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
def->os.type = strdup("aix");
if (def->os.type == NULL) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
dev = virDomainDeviceDefParse(phyp_driver->caps, def, xml,
VIR_DOMAIN_XML_INACTIVE);
if (!dev) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
if (!
(vios_name =
phypGetLparNAME(session, managed_system, vios_id, conn))) {
VIR_ERROR0(_("Unable to get VIOS name"));
- goto err;
+ goto cleanup;
}
/* First, let's look for a free SCSI Adapter
* */
if (phypCreateServerSCSIAdapter(conn) == -1) {
VIR_ERROR0(_("Unable to create new virtual adapter"));
- goto err;
+ goto cleanup;
} else {
if (!(scsi_adapter = phypGetVIOSFreeSCSIAdapter(conn))) {
VIR_ERROR0(_("Unable to create new virtual adapter"));
- goto err;
+ goto cleanup;
}
}
}
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
- cmd = virBufferContentAndReset(&buf);
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
+
+ cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (!(profile = phypGetLparProfile(conn, domain->id))) {
VIR_ERROR0(_("Unable to get VIOS profile name."));
- goto err;
+ goto cleanup;
}
/* Let's get the slot number for the adapter we just created
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
- cmd = virBufferContentAndReset(&buf);
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
+
+ cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
- goto err;
+ goto cleanup;
/* Listing all the virtual_scsi_adapter interfaces, the new adapter must
* be appended to this list
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
- cmd = virBufferContentAndReset(&buf);
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
+
+ cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
/* Here I change the LPAR configuration to append the new adapter
* with the new slot we just created
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
- cmd = virBufferContentAndReset(&buf);
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
+
+ cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (virStrToLong_i(ret, &char_ptr, 10, &slot) == -1)
- goto err;
+ goto cleanup;
/* Finally I add the new scsi adapter to VIOS using the same slot
* I used in the VIOS configuration.
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
- cmd = virBufferContentAndReset(&buf);
+ VIR_FREE(cmd);
+ VIR_FREE(ret);
+
+ cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL) {
VIR_ERROR0(_
("Possibly you don't have IBM Tools installed in your LPAR."
"Contact your support to enable this feature."));
- goto err;
+ goto cleanup;
}
- VIR_FREE(cmd);
- VIR_FREE(ret);
- VIR_FREE(def);
- VIR_FREE(dev);
- VIR_FREE(vios_name);
- VIR_FREE(scsi_adapter);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- VIR_FREE(def);
- VIR_FREE(dev);
+ virDomainDeviceDefFree(dev);
+ virDomainDefFree(def);
VIR_FREE(vios_name);
VIR_FREE(scsi_adapter);
- return -1;
+ VIR_FREE(profile);
+ VIR_FREE(domain_name);
+
+ return result;
}
static char *
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
- if (exit_status < 0 || ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL) {
+ VIR_FREE(ret);
+ goto cleanup;
+ }
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
- VIR_FREE(cmd);
- return ret;
-
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ cleanup:
+ VIR_FREE(cmd);
+
+ return ret;
}
static char *
ret = phypExec(session, cmd, &exit_status, conn);
- if (exit_status < 0 || ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL) {
+ VIR_FREE(ret);
+ goto cleanup;
+ }
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
+ cleanup:
VIR_FREE(cmd);
- return ret;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ return ret;
}
static unsigned long int
int vios_id = phyp_driver->vios_id;
char *cmd = NULL;
char *ret = NULL;
- int sp_size = 0;
+ int sp_size = -1;
char *char_ptr;
virBuffer buf = VIR_BUFFER_INITIALIZER;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &sp_size) == -1)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return sp_size;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return sp_size;
}
static char *
char *ret = NULL;
int exit_status = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- char *key;
+ char *key = NULL;
if (system_type == HMC)
virBufferVSprintf(&buf, "viosvrcmd -m %s --id %d -c '",
if (exit_status < 0) {
VIR_ERROR(_("Unable to create Volume: %s"), ret);
- goto err;
+ goto cleanup;
}
key = phypVolumeGetKey(conn, lvname);
if (key == NULL)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return key;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ return key;
}
static virStorageVolPtr
ret = phypExec(session, cmd, &exit_status, conn);
- if (exit_status < 0 || ret == NULL)
- goto err;
+ if (exit_status < 0 || ret == NULL) {
+ VIR_FREE(ret);
+ goto cleanup;
+ }
char_ptr = strchr(ret, '\n');
if (char_ptr)
*char_ptr = '\0';
+ cleanup:
VIR_FREE(cmd);
- return ret;
-
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
+ return ret;
}
static virStorageVolPtr
char *char_ptr;
char *key = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- virStorageVolPtr vol;
+ virStorageVolPtr vol = NULL;
if (system_type == HMC)
virBufferVSprintf(&buf, "viosvrcmd -m %s --id %d -c '",
spname = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || spname == NULL)
- return NULL;
+ goto cleanup;
char_ptr = strchr(spname, '\n');
key = phypVolumeGetKey(conn, volname);
if (key == NULL)
- return NULL;
+ goto cleanup;
vol = virGetStorageVol(conn, spname, volname, key);
+ cleanup:
+ VIR_FREE(cmd);
+ VIR_FREE(spname);
VIR_FREE(key);
return vol;
phypGetStoragePoolUUID(virConnectPtr conn, unsigned char *uuid,
const char *name)
{
+ int result = -1;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (memmove(uuid, ret, VIR_UUID_BUFLEN) == NULL)
- goto err;
+ goto cleanup;
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return result;
}
static virStoragePoolPtr
static char *
phypVolumeGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
{
+ virStorageVolDef voldef;
+ virStoragePoolDef pool;
+ virStoragePoolPtr sp;
char *xml;
virCheckFlags(0, NULL);
- virStorageVolDef voldef;
memset(&voldef, 0, sizeof(virStorageVolDef));
+ memset(&pool, 0, sizeof(virStoragePoolDef));
- virStoragePoolPtr sp =
- phypStoragePoolLookupByName(vol->conn, vol->pool);
+ sp = phypStoragePoolLookupByName(vol->conn, vol->pool);
if (!sp)
goto err;
- virStoragePoolDef pool;
- memset(&pool, 0, sizeof(virStoragePoolDef));
-
if (sp->name != NULL) {
pool.name = sp->name;
} else {
sp = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || sp == NULL)
- goto err;
+ goto cleanup;
char_ptr = strchr(sp, '\n');
pv = phypVolumeGetPhysicalVolumeByStoragePool(vol, sp);
- if (pv) {
- if (virAsprintf(&path, "/%s/%s/%s", pv, sp, vol->name) < 0) {
- virReportOOMError();
- goto err;
- }
- } else {
- goto err;
- }
+ if (!pv)
+ goto cleanup;
- VIR_FREE(cmd);
- return path;
+ if (virAsprintf(&path, "/%s/%s/%s", pv, sp, vol->name) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(sp);
VIR_FREE(path);
- return NULL;
+
+ return path;
}
phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes,
int nvolumes)
{
+ bool success = false;
virConnectPtr conn = pool->conn;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
/* I need to parse the textual return in order to get the volumes */
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
else {
volumes_list = ret;
*char_ptr2 = '\0';
if ((volumes[got++] = strdup(volumes_list)) == NULL) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
char_ptr2++;
volumes_list = char_ptr2;
}
}
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return got;
+ success = true;
+
+ cleanup:
+ if (!success) {
+ for (i = 0; i < got; i++)
+ VIR_FREE(volumes[i]);
+
+ got = -1;
+ }
- err:
- for (i = 0; i < got; i++)
- VIR_FREE(volumes[i]);
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return got;
}
static int
LIBSSH2_SESSION *session = connection_data->session;
int system_type = phyp_driver->system_type;
int exit_status = 0;
- int nvolumes = 0;
+ int nvolumes = -1;
char *cmd = NULL;
char *ret = NULL;
char *managed_system = phyp_driver->managed_system;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &nvolumes) == -1)
- goto err;
+ goto cleanup;
/* We need to remove 2 line from the header text output */
nvolumes -= 2;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return nvolumes;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return nvolumes;
}
static int
phypDestroyStoragePool(virStoragePoolPtr pool)
{
+ int result = -1;
virConnectPtr conn = pool->conn;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
"'rmsp %s'", managed_system, vios_id,
pool->name) < 0) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0) {
VIR_ERROR(_("Unable to create Storage Pool: %s"), ret);
- goto err;
+ goto cleanup;
}
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return result;
}
static int
phypBuildStoragePool(virConnectPtr conn, virStoragePoolDefPtr def)
{
+ int result = -1;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
if (exit_status < 0) {
VIR_ERROR(_("Unable to create Storage Pool: %s"), ret);
- goto err;
+ goto cleanup;
}
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return result;
}
LIBSSH2_SESSION *session = connection_data->session;
int system_type = phyp_driver->system_type;
int exit_status = 0;
- int nsp = 0;
+ int nsp = -1;
char *cmd = NULL;
char *ret = NULL;
char *managed_system = phyp_driver->managed_system;
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &nsp) == -1)
- goto err;
+ goto cleanup;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return nsp;
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return nsp;
}
static int
phypListStoragePools(virConnectPtr conn, char **const pools, int npools)
{
+ bool success = false;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
/* I need to parse the textual return in order to get the storage pools */
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
else {
storage_pools = ret;
*char_ptr2 = '\0';
if ((pools[got++] = strdup(storage_pools)) == NULL) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
char_ptr2++;
storage_pools = char_ptr2;
}
}
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return got;
+ success = true;
+
+ cleanup:
+ if (!success) {
+ for (i = 0; i < got; i++)
+ VIR_FREE(pools[i]);
+
+ got = -1;
+ }
- err:
- for (i = 0; i < got; i++)
- VIR_FREE(pools[i]);
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return got;
}
static virStoragePoolPtr
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto err;
}
cmd = virBufferContentAndReset(&buf);
static int
phypListDefinedDomains(virConnectPtr conn, char **const names, int nnames)
{
+ bool success = false;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
/* I need to parse the textual return in order to get the domains */
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
else {
domains = ret;
*char_ptr2 = '\0';
if ((names[got++] = strdup(domains)) == NULL) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
char_ptr2++;
domains = char_ptr2;
}
}
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return got;
+ success = true;
+
+ cleanup:
+ if (!success) {
+ for (i = 0; i < got; i++)
+ VIR_FREE(names[i]);
+
+ got = -1;
+ }
- err:
- for (i = 0; i < got; i++)
- VIR_FREE(names[i]);
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return got;
}
static virDomainPtr
conn);
if (phypGetLparUUID(lpar_uuid, lpar_id, conn) == -1)
- goto err;
+ goto cleanup;
if (exit_status < 0)
- goto err;
+ goto cleanup;
dom = virGetDomain(conn, lpar_name, lpar_uuid);
if (dom)
dom->id = lpar_id;
+ cleanup:
VIR_FREE(lpar_name);
- return dom;
- err:
- VIR_FREE(lpar_name);
- return NULL;
+ return dom;
}
static char *
static int
phypDomainResume(virDomainPtr dom)
{
+ int result = -1;
ConnectionData *connection_data = dom->conn->networkPrivateData;
phyp_driverPtr phyp_driver = dom->conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
ret = phypExec(session, cmd, &exit_status, dom->conn);
if (exit_status < 0)
- goto err;
+ goto cleanup;
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return result;
}
static int
phypDomainShutdown(virDomainPtr dom)
{
+ int result = -1;
ConnectionData *connection_data = dom->conn->networkPrivateData;
virConnectPtr conn = dom->conn;
LIBSSH2_SESSION *session = connection_data->session;
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return 0;
+ return -1;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, dom->conn);
if (exit_status < 0)
- goto err;
+ goto cleanup;
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return 0;
+
+ return result;
}
static int
static int
phypDomainDestroy(virDomainPtr dom)
{
+ int result = -1;
ConnectionData *connection_data = dom->conn->networkPrivateData;
phyp_driverPtr phyp_driver = dom->conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
ret = phypExec(session, cmd, &exit_status, dom->conn);
if (exit_status < 0)
- goto err;
+ goto cleanup;
if (phypUUIDTable_RemLpar(dom->conn, dom->id) == -1)
- goto err;
+ goto cleanup;
dom->id = -1;
+ result = 0;
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return 0;
-
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
+ return result;
}
static int
phypBuildLpar(virConnectPtr conn, virDomainDefPtr def)
{
+ int result = -1;
ConnectionData *connection_data = conn->networkPrivateData;
phyp_driverPtr phyp_driver = conn->privateData;
LIBSSH2_SESSION *session = connection_data->session;
PHYP_ERROR(VIR_ERR_XML_ERROR,"%s",
_("Field \"<memory>\" on the domain XML file is missing or has "
"invalid value."));
- goto err;
+ goto cleanup;
}
if (!def->mem.max_balloon) {
PHYP_ERROR(VIR_ERR_XML_ERROR,"%s",
_("Field \"<currentMemory>\" on the domain XML file is missing or"
" has invalid value."));
- goto err;
+ goto cleanup;
}
if (def->ndisks < 1) {
PHYP_ERROR(VIR_ERR_XML_ERROR, "%s",
_("Domain XML must contain at least one \"<disk>\" element."));
- goto err;
+ goto cleanup;
}
if (!def->disks[0]->src) {
PHYP_ERROR(VIR_ERR_XML_ERROR,"%s",
_("Field \"<src>\" under \"<disk>\" on the domain XML file is "
"missing."));
- goto err;
+ goto cleanup;
}
virBufferAddLit(&buf, "mksyscfg");
if (exit_status < 0) {
VIR_ERROR(_("Unable to create LPAR. Reason: '%s'"), ret);
- goto err;
+ goto cleanup;
}
if (phypUUIDTable_AddLpar(conn, def->uuid, def->id) == -1) {
VIR_ERROR0(_("Unable to add LPAR to the table"));
- goto err;
+ goto cleanup;
}
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ result = 0;
- err:
+ cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+
+ return result;
}
static virDomainPtr