char *char_ptr;
char *cmd = NULL;
char *ret = NULL;
+ int rv = -1;
/* Getting the remote slot number */
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, iface->conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &slot_num) == -1)
- goto err;
+ goto cleanup;
/* Getting the remote slot number */
VIR_FREE(cmd);
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, iface->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;
/* excluding interface */
VIR_FREE(cmd);
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, iface->conn);
if (exit_status < 0 || ret != NULL)
- goto err;
+ goto cleanup;
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return 0;
+ rv = 0;
- err:
+cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
- return -1;
+ return rv;
}
static virInterfacePtr
char name[PHYP_IFACENAME_SIZE];
char mac[PHYP_MAC_SIZE];
virInterfaceDefPtr def;
+ virInterfacePtr result = NULL;
if (!(def = virInterfaceDefParseString(xml)))
- goto err;
+ goto cleanup;
/* Now need to get the next free slot number */
virBufferAddLit(&buf, "lshwres ");
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ 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;
/* The next free slot itself: */
slot++;
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret != NULL)
- goto err;
+ goto cleanup;
/* Need to sleep a little while to wait for the HMC to
* complete the execution of the command.
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
- goto err;
+ goto cleanup;
}
memcpy(name, ret, PHYP_IFACENAME_SIZE-1);
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
memcpy(mac, ret, PHYP_MAC_SIZE-1);
- VIR_FREE(cmd);
- VIR_FREE(ret);
- virInterfaceDefFree(def);
- return virGetInterface(conn, name, mac);
+ result = virGetInterface(conn, name, mac);
- err:
+cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
virInterfaceDefFree(def);
- return NULL;
+ return result;
}
static virInterfacePtr
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ 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;
/*Getting the lpar_id for the interface */
VIR_FREE(cmd);
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;
/*Getting the interface mac */
virBufferAddLit(&buf, "lshwres ");
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return NULL;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
memcpy(mac, ret, PHYP_MAC_SIZE-1);
result = virGetInterface(conn, name, ret);
+cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
return result;
-
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return NULL;
-
}
static int
char *managed_system = phyp_driver->managed_system;
int system_type = phyp_driver->system_type;
int exit_status = 0;
- int state = 0;
+ int state = -1;
char *char_ptr;
char *cmd = NULL;
char *ret = NULL;
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- return -1;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, iface->conn);
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
if (virStrToLong_i(ret, &char_ptr, 10, &state) == -1)
- goto err;
+ goto cleanup;
+cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
return state;
-
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
-
}
static int
char *networks = NULL;
char *char_ptr2 = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ bool success = false;
virBufferAddLit(&buf, "lshwres");
if (system_type == HMC)
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ goto cleanup;
}
cmd = virBufferContentAndReset(&buf);
ret = phypExec(session, cmd, &exit_status, conn);
- /* I need to parse the textual return in order to get the network interfaces */
+ /* I need to parse the textual return in order to get the network
+ * interfaces */
if (exit_status < 0 || ret == NULL)
- goto err;
+ goto cleanup;
networks = ret;
*char_ptr2 = '\0';
if ((names[got++] = strdup(networks)) == NULL) {
virReportOOMError();
- goto err;
+ goto cleanup;
}
char_ptr2++;
networks = char_ptr2;
}
}
+cleanup:
+ if (!success) {
+ for (i = 0; i < got; i++)
+ VIR_FREE(names[i]);
+ }
VIR_FREE(cmd);
VIR_FREE(ret);
return got;
-
- err:
- for (i = 0; i < got; i++)
- VIR_FREE(names[i]);
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
}
static int
int system_type = phyp_driver->system_type;
int vios_id = phyp_driver->vios_id;
int exit_status = 0;
- int nnets = 0;
+ int nnets = -1;
char *char_ptr;
char *cmd = NULL;
char *ret = NULL;
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError();
- goto err;
+ 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, &nnets) == -1)
- goto err;
+ goto cleanup;
+cleanup:
VIR_FREE(cmd);
VIR_FREE(ret);
return nnets;
-
- err:
- VIR_FREE(cmd);
- VIR_FREE(ret);
- return -1;
-
}
static int