mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Adapt to VIR_ALLOC and virAsprintf in src/phyp/*
This commit is contained in:
parent
f5a60ebdc3
commit
c2225f7a40
@ -110,10 +110,8 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
|
|||||||
int sock = connection_data->sock;
|
int sock = connection_data->sock;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(buffer, buffer_size) < 0) {
|
if (VIR_ALLOC_N(buffer, buffer_size) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* Exec non-blocking on the remove host */
|
/* Exec non-blocking on the remove host */
|
||||||
while ((channel = libssh2_channel_open_session(session)) == NULL &&
|
while ((channel = libssh2_channel_open_session(session)) == NULL &&
|
||||||
@ -476,10 +474,8 @@ phypUUIDTable_Push(virConnectPtr conn)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table",
|
if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table",
|
||||||
NULLSTR(conn->uri->user)) < 0) {
|
NULLSTR(conn->uri->user)) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (stat(local_file, &local_fileinfo) == -1) {
|
if (stat(local_file, &local_fileinfo) == -1) {
|
||||||
VIR_WARN("Unable to stat local file.");
|
VIR_WARN("Unable to stat local file.");
|
||||||
@ -580,15 +576,11 @@ phypUUIDTable_AddLpar(virConnectPtr conn, unsigned char *uuid, int id)
|
|||||||
unsigned int i = uuid_table->nlpars;
|
unsigned int i = uuid_table->nlpars;
|
||||||
i--;
|
i--;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(uuid_table->lpars, uuid_table->nlpars) < 0) {
|
if (VIR_REALLOC_N(uuid_table->lpars, uuid_table->nlpars) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC(uuid_table->lpars[i]) < 0) {
|
if (VIR_ALLOC(uuid_table->lpars[i]) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
uuid_table->lpars[i]->id = id;
|
uuid_table->lpars[i]->id = id;
|
||||||
memcpy(uuid_table->lpars[i]->uuid, uuid, VIR_UUID_BUFLEN);
|
memcpy(uuid_table->lpars[i]->uuid, uuid, VIR_UUID_BUFLEN);
|
||||||
@ -627,10 +619,8 @@ phypUUIDTable_ReadFile(virConnectPtr conn)
|
|||||||
|
|
||||||
rc = read(fd, &id, sizeof(int));
|
rc = read(fd, &id, sizeof(int));
|
||||||
if (rc == sizeof(int)) {
|
if (rc == sizeof(int)) {
|
||||||
if (VIR_ALLOC(uuid_table->lpars[i]) < 0) {
|
if (VIR_ALLOC(uuid_table->lpars[i]) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
uuid_table->lpars[i]->id = id;
|
uuid_table->lpars[i]->id = id;
|
||||||
} else {
|
} else {
|
||||||
VIR_WARN
|
VIR_WARN
|
||||||
@ -644,8 +634,7 @@ phypUUIDTable_ReadFile(virConnectPtr conn)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
virReportOOMError();
|
|
||||||
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return 0;
|
return 0;
|
||||||
@ -674,10 +663,8 @@ phypUUIDTable_Pull(virConnectPtr conn)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table",
|
if (virAsprintf(&remote_file, "/home/%s/libvirt_uuid_table",
|
||||||
NULLSTR(conn->uri->user)) < 0) {
|
NULLSTR(conn->uri->user)) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
/* Trying to stat the remote file. */
|
/* Trying to stat the remote file. */
|
||||||
do {
|
do {
|
||||||
@ -771,10 +758,8 @@ phypUUIDTable_Init(virConnectPtr conn)
|
|||||||
if ((nids_numdomains = phypConnectNumOfDomainsGeneric(conn, 2)) < 0)
|
if ((nids_numdomains = phypConnectNumOfDomainsGeneric(conn, 2)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ids, nids_numdomains) < 0) {
|
if (VIR_ALLOC_N(ids, nids_numdomains) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if ((nids_listdomains =
|
if ((nids_listdomains =
|
||||||
phypConnectListDomainsGeneric(conn, ids, nids_numdomains, 1)) < 0)
|
phypConnectListDomainsGeneric(conn, ids, nids_numdomains, 1)) < 0)
|
||||||
@ -800,20 +785,16 @@ phypUUIDTable_Init(virConnectPtr conn)
|
|||||||
table_created = true;
|
table_created = true;
|
||||||
if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) {
|
if (VIR_ALLOC_N(uuid_table->lpars, uuid_table->nlpars) >= 0) {
|
||||||
for (i = 0; i < uuid_table->nlpars; i++) {
|
for (i = 0; i < uuid_table->nlpars; i++) {
|
||||||
if (VIR_ALLOC(uuid_table->lpars[i]) < 0) {
|
if (VIR_ALLOC(uuid_table->lpars[i]) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
uuid_table->lpars[i]->id = ids[i];
|
uuid_table->lpars[i]->id = ids[i];
|
||||||
|
|
||||||
if (virUUIDGenerate(uuid_table->lpars[i]->uuid) < 0)
|
if (virUUIDGenerate(uuid_table->lpars[i]->uuid) < 0)
|
||||||
VIR_WARN("Unable to generate UUID for domain %d",
|
VIR_WARN("Unable to generate UUID for domain %d",
|
||||||
ids[i]);
|
ids[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (phypUUIDTable_WriteFile(conn) == -1)
|
if (phypUUIDTable_WriteFile(conn) == -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -890,10 +871,8 @@ escape_specialcharacters(const char *src)
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(dst, len + 1) < 0) {
|
if (VIR_ALLOC_N(dst, len + 1) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
switch (src[i]) {
|
switch (src[i]) {
|
||||||
@ -931,15 +910,11 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
|
|||||||
if (userhome == NULL)
|
if (userhome == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (virAsprintf(&pubkey, "%s/.ssh/id_rsa.pub", userhome) < 0) {
|
if (virAsprintf(&pubkey, "%s/.ssh/id_rsa.pub", userhome) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
if (virAsprintf(&pvtkey, "%s/.ssh/id_rsa", userhome) < 0) {
|
if (virAsprintf(&pvtkey, "%s/.ssh/id_rsa", userhome) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
if (conn->uri->user != NULL) {
|
if (conn->uri->user != NULL) {
|
||||||
if (VIR_STRDUP(username, conn->uri->user) < 0)
|
if (VIR_STRDUP(username, conn->uri->user) < 0)
|
||||||
@ -1107,20 +1082,14 @@ phypConnectOpen(virConnectPtr conn,
|
|||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(phyp_driver) < 0) {
|
if (VIR_ALLOC(phyp_driver) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC(uuid_table) < 0) {
|
if (VIR_ALLOC(uuid_table) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC(connection_data) < 0) {
|
if (VIR_ALLOC(connection_data) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
|
||||||
connection_data->sock = -1;
|
connection_data->sock = -1;
|
||||||
|
|
||||||
if (conn->uri->path) {
|
if (conn->uri->path) {
|
||||||
@ -1161,10 +1130,8 @@ phypConnectOpen(virConnectPtr conn,
|
|||||||
phyp_driver->managed_system = managed_system;
|
phyp_driver->managed_system = managed_system;
|
||||||
|
|
||||||
phyp_driver->uuid_table = uuid_table;
|
phyp_driver->uuid_table = uuid_table;
|
||||||
if ((phyp_driver->caps = phypCapsInit()) == NULL) {
|
if ((phyp_driver->caps = phypCapsInit()) == NULL)
|
||||||
virReportOOMError();
|
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(phyp_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)))
|
if (!(phyp_driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)))
|
||||||
goto failure;
|
goto failure;
|
||||||
@ -1694,10 +1661,8 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml)
|
|||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
char *domain_name = NULL;
|
char *domain_name = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0) {
|
if (VIR_ALLOC(def) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
domain_name = escape_specialcharacters(domain->name);
|
domain_name = escape_specialcharacters(domain->name);
|
||||||
|
|
||||||
@ -1984,10 +1949,8 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
|
|||||||
virStorageVolPtr dup_vol = NULL;
|
virStorageVolPtr dup_vol = NULL;
|
||||||
char *key = NULL;
|
char *key = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(spdef) < 0) {
|
if (VIR_ALLOC(spdef) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* Filling spdef manually
|
/* Filling spdef manually
|
||||||
* */
|
* */
|
||||||
@ -2310,10 +2273,8 @@ phypStorageVolGetPath(virStorageVolPtr vol)
|
|||||||
if (!pv)
|
if (!pv)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virAsprintf(&path, "/%s/%s/%s", pv, ret, vol->name) < 0) {
|
if (virAsprintf(&path, "/%s/%s/%s", pv, ret, vol->name) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(ret);
|
VIR_FREE(ret);
|
||||||
@ -2597,25 +2558,17 @@ phypStoragePoolLookupByUUID(virConnectPtr conn,
|
|||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
unsigned char *local_uuid = NULL;
|
unsigned char *local_uuid = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(local_uuid, VIR_UUID_BUFLEN) < 0) {
|
if (VIR_ALLOC_N(local_uuid, VIR_UUID_BUFLEN) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
if ((npools = phypConnectNumOfStoragePools(conn)) == -1) {
|
if ((npools = phypConnectNumOfStoragePools(conn)) == -1)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC_N(pools, npools) < 0) {
|
if (VIR_ALLOC_N(pools, npools) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
if ((gotpools = phypConnectListStoragePools(conn, pools, npools)) == -1) {
|
if ((gotpools = phypConnectListStoragePools(conn, pools, npools)) == -1)
|
||||||
virReportOOMError();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
if (gotpools != npools) {
|
if (gotpools != npools) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
|
Loading…
Reference in New Issue
Block a user