[libvirt] [PATCH] Stop free'ing 'const char *' strings
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The VIR_FREE() macro will cast away any const-ness. This masked a
number of places where we passed a 'const char *' string to
VIR_FREE. Fortunately in all of these cases, the variable was not
in fact const data, but a heap allocated string. Fix all the
variable declarations to reflect this.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/conf/domain_conf.c | 30 +++++++++++++++---------------
src/conf/netdev_vlan_conf.c | 4 ++--
src/conf/nwfilter_conf.c | 3 ++-
src/node_device/node_device_udev.c | 2 +-
src/nwfilter/nwfilter_gentech_driver.c | 2 +-
src/qemu/qemu_command.c | 33 +++++++++++++++++++--------------
src/qemu/qemu_domain.c | 2 +-
src/qemu/qemu_driver.c | 4 ++--
src/rpc/virnetsshsession.c | 34 +++++++++++++++++++++-------------
src/storage/storage_backend.c | 2 +-
src/storage/storage_driver.c | 2 +-
src/util/vircommand.c | 9 ++++-----
src/util/virlog.c | 4 ++--
tools/virsh-domain.c | 19 ++++++++++---------
14 files changed, 82 insertions(+), 68 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f8fbf79..678f8ca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6745,9 +6745,9 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
{
int ret = -1;
unsigned int port;
- const char *targetType = virXMLPropString(cur, "type");
- const char *addrStr = NULL;
- const char *portStr = NULL;
+ char *targetType = virXMLPropString(cur, "type");
+ char *addrStr = NULL;
+ char *portStr = NULL;
if ((def->targetType =
virDomainChrTargetTypeFromString(def, def->deviceType,
@@ -8161,7 +8161,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(cur->name, BAD_CAST "channel")) {
- const char *name, *mode;
+ char *name, *mode;
int nameval, modeval;
name = virXMLPropString(cur, "name");
mode = virXMLPropString(cur, "mode");
@@ -8195,7 +8195,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
def->data.spice.channels[nameval] = modeval;
} else if (xmlStrEqual(cur->name, BAD_CAST "image")) {
- const char *compression = virXMLPropString(cur, "compression");
+ char *compression = virXMLPropString(cur, "compression");
int compressionVal;
if (!compression) {
@@ -8216,7 +8216,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
def->data.spice.image = compressionVal;
} else if (xmlStrEqual(cur->name, BAD_CAST "jpeg")) {
- const char *compression = virXMLPropString(cur, "compression");
+ char *compression = virXMLPropString(cur, "compression");
int compressionVal;
if (!compression) {
@@ -8237,7 +8237,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
def->data.spice.jpeg = compressionVal;
} else if (xmlStrEqual(cur->name, BAD_CAST "zlib")) {
- const char *compression = virXMLPropString(cur, "compression");
+ char *compression = virXMLPropString(cur, "compression");
int compressionVal;
if (!compression) {
@@ -8258,7 +8258,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
def->data.spice.zlib = compressionVal;
} else if (xmlStrEqual(cur->name, BAD_CAST "playback")) {
- const char *compression = virXMLPropString(cur, "compression");
+ char *compression = virXMLPropString(cur, "compression");
int compressionVal;
if (!compression) {
@@ -8279,7 +8279,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
def->data.spice.playback = compressionVal;
} else if (xmlStrEqual(cur->name, BAD_CAST "streaming")) {
- const char *mode = virXMLPropString(cur, "mode");
+ char *mode = virXMLPropString(cur, "mode");
int modeVal;
if (!mode) {
@@ -8299,7 +8299,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
def->data.spice.streaming = modeVal;
} else if (xmlStrEqual(cur->name, BAD_CAST "clipboard")) {
- const char *copypaste = virXMLPropString(cur, "copypaste");
+ char *copypaste = virXMLPropString(cur, "copypaste");
int copypasteVal;
if (!copypaste) {
@@ -8319,7 +8319,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
def->data.spice.copypaste = copypasteVal;
} else if (xmlStrEqual(cur->name, BAD_CAST "mouse")) {
- const char *mode = virXMLPropString(cur, "mode");
+ char *mode = virXMLPropString(cur, "mode");
int modeVal;
if (!mode) {
@@ -8511,9 +8511,9 @@ virDomainRNGDefParseXML(const xmlNodePtr node,
xmlXPathContextPtr ctxt,
unsigned int flags)
{
- const char *model = NULL;
- const char *backend = NULL;
- const char *type = NULL;
+ char *model = NULL;
+ char *backend = NULL;
+ char *type = NULL;
virDomainRNGDefPtr def;
xmlNodePtr save = ctxt->node;
xmlNodePtr *backends = NULL;
@@ -15197,7 +15197,7 @@ virDomainChrDefFormat(virBufferPtr buf,
return -1;
}
- const char *addr = virSocketAddrFormat(def->target.addr);
+ char *addr = virSocketAddrFormat(def->target.addr);
if (addr == NULL)
return -1;
diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c
index 60d9eb8..24e1000 100644
--- a/src/conf/netdev_vlan_conf.c
+++ b/src/conf/netdev_vlan_conf.c
@@ -36,8 +36,8 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
{
int ret = -1;
xmlNodePtr save = ctxt->node;
- const char *trunk = NULL;
- const char *nativeMode = NULL;
+ char *trunk = NULL;
+ char *nativeMode = NULL;
xmlNodePtr *tagNodes = NULL;
int nTags;
size_t i;
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index a3901d3..00e74eb 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2432,7 +2432,8 @@ static const char *
virNWFilterIsAllowedChain(const char *chainname)
{
enum virNWFilterChainSuffixType i;
- const char *name, *msg;
+ const char *name;
+ char *msg;
virBuffer buf = VIR_BUFFER_INITIALIZER;
bool printed = false;
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 67fcc58..785c2fa 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -367,7 +367,7 @@ udevLogFunction(struct udev *udev ATTRIBUTE_UNUSED,
va_list args)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- const char *format = NULL;
+ char *format = NULL;
virBufferAdd(&buf, fmt, -1);
virBufferTrim(&buf, "\n", -1);
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index ee9195b..382d73f 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -499,7 +499,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
for (j = 0; j < rule->nVarAccess; j++) {
if (!virNWFilterVarAccessIsAvailable(rule->varAccess[j],
vars)) {
- const char *varAccess;
+ char *varAccess;
virBuffer buf = VIR_BUFFER_INITIALIZER;
virNWFilterVarAccessPrint(rule->varAccess[j], &buf);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f8fccea..754d95a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6050,7 +6050,8 @@ static char *qemuBuildTPMBackendStr(const virDomainDefPtr def,
const virDomainTPMDefPtr tpm = def->tpm;
virBuffer buf = VIR_BUFFER_INITIALIZER;
const char *type = virDomainTPMBackendTypeToString(tpm->type);
- const char *cancel_path, *tpmdev;
+ char *cancel_path;
+ const char *tpmdev;
virBufferAsprintf(&buf, "%s,id=tpm-%s", type, tpm->info.alias);
@@ -7667,7 +7668,7 @@ qemuBuildCommandLine(virConnectPtr conn,
}
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_RTC)) {
- const char *rtcopt;
+ char *rtcopt;
virCommandAddArg(cmd, "-rtc");
if (!(rtcopt = qemuBuildClockArgStr(&def->clock)))
goto error;
@@ -9529,8 +9530,8 @@ qemuBuildChrDeviceStr(char **deviceStr,
* on space
*/
static int qemuStringToArgvEnv(const char *args,
- const char ***retenv,
- const char ***retargv)
+ char ***retenv,
+ char ***retargv)
{
char **arglist = NULL;
int argcount = 0;
@@ -9539,8 +9540,8 @@ static int qemuStringToArgvEnv(const char *args,
size_t i;
const char *curr = args;
const char *start;
- const char **progenv = NULL;
- const char **progargv = NULL;
+ char **progenv = NULL;
+ char **progargv = NULL;
/* Iterate over string, splitting on sequences of ' ' */
while (curr && *curr != '\0') {
@@ -11738,15 +11739,17 @@ virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps,
virDomainChrSourceDefPtr *monConfig,
bool *monJSON)
{
- const char **progenv = NULL;
- const char **progargv = NULL;
+ char **progenv = NULL;
+ char **progargv = NULL;
virDomainDefPtr def = NULL;
size_t i;
if (qemuStringToArgvEnv(args, &progenv, &progargv) < 0)
goto cleanup;
- def = qemuParseCommandLine(qemuCaps, xmlopt, progenv, progargv,
+ def = qemuParseCommandLine(qemuCaps, xmlopt,
+ (const char **)progenv,
+ (const char **)progargv,
pidfile, monConfig, monJSON);
cleanup:
@@ -11764,7 +11767,7 @@ cleanup:
static int qemuParseProcFileStrings(int pid_value,
const char *name,
- const char ***list)
+ char ***list)
{
char *path = NULL;
int ret = -1;
@@ -11800,7 +11803,7 @@ static int qemuParseProcFileStrings(int pid_value,
str[nstr-1] = NULL;
ret = nstr-1;
- *list = (const char **) str;
+ *list = str;
cleanup:
if (ret < 0) {
@@ -11821,8 +11824,8 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
bool *monJSON)
{
virDomainDefPtr def = NULL;
- const char **progargv = NULL;
- const char **progenv = NULL;
+ char **progargv = NULL;
+ char **progenv = NULL;
char *exepath = NULL;
char *emulator;
size_t i;
@@ -11834,7 +11837,9 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps,
qemuParseProcFileStrings(pid, "environ", &progenv) < 0)
goto cleanup;
- if (!(def = qemuParseCommandLine(qemuCaps, xmlopt, progenv, progargv,
+ if (!(def = qemuParseCommandLine(qemuCaps, xmlopt,
+ (const char **)progenv,
+ (const char **)progargv,
pidfile, monConfig, monJSON)))
goto cleanup;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7f4d17d..b71fa4e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1355,7 +1355,7 @@ qemuDomainDefCopy(virQEMUDriverPtr driver,
virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainDefPtr ret = NULL;
virCapsPtr caps = NULL;
- const char *xml = NULL;
+ char *xml = NULL;
if (qemuDomainDefFormatBuf(driver, src, flags, &buf) < 0)
goto cleanup;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ed29373..fa70e74 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14646,7 +14646,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
virDomainDefPtr persistentDef = NULL;
virDomainBlockIoTuneInfo info;
virDomainBlockIoTuneInfo *oldinfo;
- const char *device = NULL;
+ char *device = NULL;
int ret = -1;
size_t i;
int idx = -1;
@@ -14824,7 +14824,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
qemuDomainObjPrivatePtr priv;
virDomainDefPtr persistentDef = NULL;
virDomainBlockIoTuneInfo reply;
- const char *device = NULL;
+ char *device = NULL;
int ret = -1;
size_t i;
virCapsPtr caps = NULL;
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index 816c54e..f544d69 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -268,8 +268,9 @@ virNetSSHKbIntCb(const char *name ATTRIBUTE_UNUSED,
cleanup:
if (askcred) {
for (i = 0; i < num_prompts; i++) {
+ char *prompt = (char *)askcred[i].prompt;
VIR_FREE(askcred[i].result);
- VIR_FREE(askcred[i].prompt);
+ VIR_FREE(prompt);
}
}
@@ -291,6 +292,8 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
int ret;
const char *key;
const char *keyhash;
+ char *keyhashstr;
+ char *tmp;
int keyType;
size_t keyLength;
char *errmsg;
@@ -364,7 +367,7 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
* Sadly, there's no constant to describe the hash length, so
* we have to use a *MAGIC* constant. */
for (i = 0; i < 16; i++)
- virBufferAsprintf(&buff, "%02hhX:", keyhash[i]);
+ virBufferAsprintf(&buff, "%02hhX:", keyhash[i]);
virBufferTrim(&buff, ":", 1);
if (virBufferError(&buff) != 0) {
@@ -372,16 +375,16 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
return -1;
}
- keyhash = virBufferContentAndReset(&buff);
+ keyhashstr = virBufferContentAndReset(&buff);
askKey.type = VIR_CRED_ECHOPROMPT;
if (virAsprintf((char **)&askKey.prompt,
_("Accept SSH host key with hash '%s' for "
"host '%s:%d' (%s/%s)?"),
- keyhash,
+ keyhashstr,
sess->hostname, sess->port,
"y", "n") < 0) {
- VIR_FREE(keyhash);
+ VIR_FREE(keyhashstr);
return -1;
}
@@ -389,23 +392,25 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
virReportError(VIR_ERR_SSH, "%s",
_("failed to retrieve decision to accept "
"host key"));
- VIR_FREE(askKey.prompt);
- VIR_FREE(keyhash);
+ tmp = (char*)askKey.prompt;
+ VIR_FREE(tmp);
+ VIR_FREE(keyhashstr);
return -1;
}
- VIR_FREE(askKey.prompt);
+ tmp = (char*)askKey.prompt;
+ VIR_FREE(tmp);
if (!askKey.result ||
STRCASENEQ(askKey.result, "y")) {
virReportError(VIR_ERR_SSH,
_("SSH host key for '%s' (%s) was not accepted"),
- sess->hostname, keyhash);
- VIR_FREE(keyhash);
+ sess->hostname, keyhashstr);
+ VIR_FREE(keyhashstr);
VIR_FREE(askKey.result);
return -1;
}
- VIR_FREE(keyhash);
+ VIR_FREE(keyhashstr);
VIR_FREE(askKey.result);
}
@@ -590,6 +595,7 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
size_t i;
char *errmsg;
int ret;
+ char *tmp;
/* try open the key with no password */
if ((ret = libssh2_userauth_publickey_fromfile(sess->session,
@@ -644,11 +650,13 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
virReportError(VIR_ERR_SSH, "%s",
_("failed to retrieve private key passphrase: "
"callback has failed"));
- VIR_FREE(retr_passphrase.prompt);
+ tmp = (char *)retr_passphrase.prompt;
+ VIR_FREE(tmp);
return -1;
}
- VIR_FREE(retr_passphrase.prompt);
+ tmp = (char *)retr_passphrase.prompt;
+ VIR_FREE(tmp);
ret = libssh2_userauth_publickey_fromfile(sess->session,
priv->username,
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 4ebe11b..ed893f0 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -931,7 +931,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
unsigned int flags)
{
int ret = -1;
- const char *create_tool;
+ char *create_tool;
int imgformat;
virCommandPtr cmd;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 323be9e..6c39284 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1450,7 +1450,7 @@ storageVolLookupByPath(virConnectPtr conn,
virStoragePoolObjLock(driver->pools.objs[i]);
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
virStorageVolDefPtr vol;
- const char *stable_path;
+ char *stable_path;
stable_path = virStorageBackendStablePath(driver->pools.objs[i],
cleanpath,
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 00ff69a..95331a6 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -405,6 +405,7 @@ virExec(virCommandPtr cmd)
int childout = -1;
int childerr = -1;
int tmpfd;
+ char *binarystr = NULL;
const char *binary = NULL;
int forkRet, ret;
struct sigaction waxon, waxoff;
@@ -412,7 +413,7 @@ virExec(virCommandPtr cmd)
int ngroups;
if (cmd->args[0][0] != '/') {
- if (!(binary = virFindFileInPath(cmd->args[0]))) {
+ if (!(binary = binarystr = virFindFileInPath(cmd->args[0]))) {
virReportSystemError(ENOENT,
_("Cannot find '%s' in path"),
cmd->args[0]);
@@ -506,8 +507,7 @@ virExec(virCommandPtr cmd)
cmd->pid = pid;
- if (binary != cmd->args[0])
- VIR_FREE(binary);
+ VIR_FREE(binarystr);
VIR_FREE(groups);
return 0;
@@ -713,8 +713,7 @@ virExec(virCommandPtr cmd)
should never jump here on error */
VIR_FREE(groups);
- if (binary != cmd->args[0])
- VIR_FREE(binary);
+ VIR_FREE(binarystr);
/* NB we don't virReportError() on any failures here
because the code which jumped here already raised
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 047a131..7ee5117 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -94,7 +94,7 @@ static regex_t *virLogRegex = NULL;
* based on a matching pattern (currently a substring)
*/
struct _virLogFilter {
- const char *match;
+ char *match;
virLogPriority priority;
unsigned int flags;
};
@@ -115,7 +115,7 @@ struct _virLogOutput {
virLogCloseFunc c;
virLogPriority priority;
virLogDestination dest;
- const char *name;
+ char *name;
};
typedef struct _virLogOutput virLogOutput;
typedef virLogOutput *virLogOutputPtr;
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 568d61d..ad15912 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2346,8 +2346,8 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom;
const char *iface;
const char *state;
- const char *value;
- const char *desc;
+ char *value;
+ char *desc;
virMacAddr macaddr;
const char *element;
const char *attr;
@@ -6167,7 +6167,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
bool ret = false;
char *buffer;
char *result = NULL;
- const char **list = NULL;
+ char **list = NULL;
unsigned int flags = 0;
int count = 0;
@@ -6224,7 +6224,8 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
list[i] = vshStrdup(ctl, (const char *)xmlBufferContent(xml_buf));
}
- result = virConnectBaselineCPU(ctl->conn, list, count, flags);
+ result = virConnectBaselineCPU(ctl->conn,
+ (const char **)list, count, flags);
if (result) {
vshPrint(ctl, "%s", result);
@@ -6379,7 +6380,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
params[pos].value.ul / 1000000000,
params[pos].value.ul % 1000000000);
} else {
- const char *s = vshGetTypedParamValue(ctl, ¶ms[pos]);
+ char *s = vshGetTypedParamValue(ctl, ¶ms[pos]);
vshPrint(ctl, _("%s\n"), s);
VIR_FREE(s);
}
@@ -9855,8 +9856,8 @@ vshPrepareDiskXML(xmlNodePtr disk_node,
{
xmlNodePtr cur = NULL;
xmlBufferPtr xml_buf = NULL;
- const char *disk_type = NULL;
- const char *device_type = NULL;
+ char *disk_type = NULL;
+ char *device_type = NULL;
xmlNodePtr new_node = NULL;
char *ret = NULL;
@@ -10192,9 +10193,9 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom = NULL;
const char *source = NULL;
const char *path = NULL;
- const char *doc = NULL;
+ char *doc = NULL;
xmlNodePtr disk_node = NULL;
- const char *disk_xml = NULL;
+ char *disk_xml = NULL;
bool ret = false;
int prepare_type = 0;
const char *action = NULL;
--
1.8.3.1
11 years, 7 months
[libvirt] [PATCH] Stop calling virAllocN directly from ESX code
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The ESX code has a method esxVI_Alloc which would call
virAllocN directly, instead of using the VIR_ALLOC_N
macro. Remove this method and make the callers just
use VIR_ALLOC as is normal practice.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/esx/esx_vi.c | 25 ++++++++-----------------
src/esx/esx_vi.h | 3 ---
src/esx/esx_vi_types.c | 11 +++++++----
3 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 1187bf3..255d0f4 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -51,8 +51,14 @@
int \
esxVI_##_type##_Alloc(esxVI_##_type **ptrptr) \
{ \
- return esxVI_Alloc((void **)ptrptr, sizeof(esxVI_##_type), \
- __FILE__, __FUNCTION__, __LINE__); \
+ if (ptrptr == NULL || *ptrptr != NULL) { \
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); \
+ return -1; \
+ } \
+ \
+ if (VIR_ALLOC(*ptrptr) < 0) \
+ return -1; \
+ return 0; \
}
@@ -1736,21 +1742,6 @@ esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list,
*/
int
-esxVI_Alloc(void **ptrptr, size_t size, const char *file,
- const char *function, size_t linenr)
-{
- if (ptrptr == NULL || *ptrptr != NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
- return -1;
- }
-
- return virAllocN(ptrptr, size, 1, true, VIR_FROM_THIS,
- file, function, linenr);
-}
-
-
-
-int
esxVI_BuildSelectSet(esxVI_SelectionSpec **selectSet,
const char *name, const char *type,
const char *path, const char *selectSetNames)
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index c1612e2..aeee953 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -330,9 +330,6 @@ int esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list,
* - 'get' functions get information from a local object
*/
-int esxVI_Alloc(void **ptrptr, size_t size, const char *file,
- const char *function, size_t linenr);
-
int esxVI_BuildSelectSet
(esxVI_SelectionSpec **selectSet, const char *name,
const char *type, const char *path, const char *selectSetNames);
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index 14caeeb..03df444 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -43,10 +43,13 @@
int \
esxVI_##__type##_Alloc(esxVI_##__type **ptrptr) \
{ \
- if (esxVI_Alloc((void **)ptrptr, sizeof(esxVI_##__type), \
- __FILE__, __FUNCTION__, __LINE__) < 0) { \
- return -1; \
- } \
+ if (ptrptr == NULL || *ptrptr != NULL) { \
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); \
+ return -1; \
+ } \
+ \
+ if (VIR_ALLOC(*ptrptr) < 0) \
+ return -1; \
\
(*ptrptr)->_type = esxVI_Type_##__type; \
\
--
1.8.3.1
11 years, 7 months
[libvirt] [PATCH] Add missing 'libvirt_lxc_api' variable in pkg-config file
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The 'libvirt_lxc_api' variable is intended to allow apps to
query the location of the API XML file for libvirt_lxc.so
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
libvirt.pc.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/libvirt.pc.in b/libvirt.pc.in
index 616575d..d456a88 100644
--- a/libvirt.pc.in
+++ b/libvirt.pc.in
@@ -6,6 +6,7 @@ datarootdir=@datarootdir@
libvirt_api=@datadir(a)/libvirt/api/libvirt-api.xml
libvirt_qemu_api=@datadir(a)/libvirt/api/libvirt-qemu-api.xml
+libvirt_lxc_api=@datadir(a)/libvirt/api/libvirt-lxc-api.xml
Name: libvirt
Version: @VERSION@
--
1.8.3.1
11 years, 7 months
[libvirt] [PATCH] Don't call VIR_ALLOC on def->uuid in parallels storage driver
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The 'uuid' field in virDomainDefPtr is not a pointer, it is a
fixed length array. Calling VIR_ALLOC on it is thus wrong and
leaks memory.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/parallels/parallels_storage.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c
index 3e254ce..44246a7 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -173,9 +173,6 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path)
if (!(def->name = parallelsMakePoolName(conn, path)))
goto error;
- if (VIR_ALLOC_N(def->uuid, VIR_UUID_BUFLEN))
- goto error;
-
if (virUUIDGenerate(def->uuid)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Can't generate UUID"));
--
1.8.3.1
11 years, 7 months
[libvirt] [PATCH 0/5]qemu: add usb-bot scsi controller support
by Guannan Ren
BZ:https://bugzilla.redhat.com/show_bug.cgi?id=917702
qemu patch:http://lists.gnu.org/archive/html/qemu-devel/2013-01/msg02200.html
These patch aims to add usb-bot SCSI controller support for libvirt.
As usb-storage libvirt already supported, usb-bot only supports one
SCSI target with SCSI ID 0.
The difference is that usb-storage creates SCSI HBA and additionaly
either a scsi-disk or a scsi-generic device, usb-bot only creates the
SCSI HBA. we can attach a SCSI device to it with another -device.
usb-bot supports a single target and a number of luns. The limit is
15 luns (0~15 LUN ID) and they must be contiguous(using lun 0 and 2
without 1 doesn't work).
Athought usb-bot is a SCSI controller it needs to be attached to a
exsiting USB controller for work. So it has to use address of usb type.
Libvirt XML:
<devices>
...
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/disk.qcow2'/>
<target dev='sdc' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'/>
<controller type='scsi' index='0' model='usb-bot'>
<address type='usb' bus='0' port='1'/>
</controller>
...
</devices>
The QEMU commandline:
qemu ${other_vm_args} \
-device piix3-usb-uhci,id=usb \
-device usb-bot,id=scsi0,bus=usb.0,port=1 \
-drive file=/var/lib/libvirt/images/disk.qcow2,if=none,id=drive-scsi0-0-0-0,format=raw \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0
As the usb-storage creates scsi disk automatically which doesn't let
you set scsi-disk properties such as vendor, product, wwn, channel,
scsi-id and lun. So QEMU guys prefer usb-bot to usb-storage.
So this is the first part of the whole work. Next step will replace
usb-storage with usb-bot when disk in xml uses usb bus like
<disk ...>
<...>
<target bus='usb'>
</disk>
Guannan Ren(5)
qemu: add usb-bot qemu cap flag
qemu: add usb-bot model scsi controller support
qemu: add usb-bot support from disks points of view
qemu: refactor out function to build scsi device qemu commandline
tests: add xml2argv test for usb-bot scsi controller
docs/formatdomain.html.in | 4 +--
docs/schemas/domaincommon.rng | 1 +
src/conf/domain_conf.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
src/conf/domain_conf.h | 5 +++
src/libvirt_private.syms | 1 +
src/qemu/qemu_capabilities.c | 3 ++
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 124 ++++++++++++++++++++++++++++++++++++++++++-------------------------------
src/vmx/vmx.c | 3 +-
tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-usbbot.args | 10 ++++++
tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-usbbot.xml | 33 ++++++++++++++++++++
tests/qemuxml2argvtest.c | 3 ++
12 files changed, 242 insertions(+), 57 deletions(-)
11 years, 7 months
[libvirt] [PATCH] Fix crash in virDomainGetVcpuPinInfo python wrapper
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
It is possible to jump to the cleanup block before the cpumaps
variable gets initialized. This will result in a VIR_FREE of
an uninitializer pointer
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
python/libvirt-override.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index d16b9a2..cc76c47 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -1769,7 +1769,7 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
virDomainPtr domain;
PyObject *pyobj_domain, *pycpumaps = NULL;
virDomainInfo dominfo;
- unsigned char *cpumaps;
+ unsigned char *cpumaps = NULL;
size_t cpumaplen, vcpu, pcpu;
unsigned int flags;
int i_retval, cpunum;
--
1.8.3.1
11 years, 7 months
[libvirt] [PATCH] build: only create virt-login-shell for lxc builds
by Eric Blake
I noticed from an ./autobuild.sh run that we were installing a
virt-login-shell.exe binary when cross-building for mingw,
even though such a binary is necessarily worthless since the
code depends on lxc which is a Linux-only concept.
* tools/Makefile.am (conf_DATA, bin_PROGRAMS, dist_man1_MANS):
Make virt-login-shell installation conditional.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
I'm debating about pushing this under the build-breaker rule.
tools/Makefile.am | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 74fae2d..4a3338f 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -60,10 +60,10 @@ EXTRA_DIST = \
DISTCLEANFILES =
confdir = $(sysconfdir)/libvirt
-conf_DATA = virt-login-shell.conf
+conf_DATA =
bin_SCRIPTS = virt-xml-validate virt-pki-validate
-bin_PROGRAMS = virsh virt-host-validate virt-login-shell
+bin_PROGRAMS = virsh virt-host-validate
libexec_SCRIPTS = libvirt-guests.sh
if WITH_SANLOCK
@@ -71,12 +71,20 @@ sbin_SCRIPTS = virt-sanlock-cleanup
DISTCLEANFILES += virt-sanlock-cleanup
endif
+if WITH_LXC
+conf_DATA += virt-login-shell.conf
+bin_PROGRAMS += virt-login-shell
+endif WITH_LXC
+
+
dist_man1_MANS = \
virt-host-validate.1 \
virt-pki-validate.1 \
virt-xml-validate.1 \
- virt-login-shell.1 \
virsh.1
+if WITH_LXC
+dist_man1_MANS += virt-login-shell.1
+endif WITH_LXC
if WITH_SANLOCK
dist_man8_MANS = virt-sanlock-cleanup.8
endif
--
1.8.3.1
11 years, 7 months
Re: [libvirt] [PATCHv3 2/6] virsh: Add vshCmdCompleter and vshOptCompleter
by Eric Blake
[re-adding the list, which was accidentally omitted]
On 08/28/2013 05:26 AM, Tomas Meszaros wrote:
>> Per-option completions make sense. For example, 'virsh vol-key --pool
>> <TAB>' wants to use a pool completer, while 'virsh vol-key --vol <TAB>'
>> wants to use a volume completer; furthermore, 'virsh vol-key <TAB>'
>> should be the combination of the option completer (showing --vol and
>> --pool) AND the volume completer filtered to names not starting with '-'
>> (since virsh has the semantics that arguments are positional, where the
>> option '--vol' is implied if the argument that appears in that position
>> does not resemble an option).
>
> So If I get it right, you are suggesting that it should work like this:
>
> virsh # vol-key <TAB>
> vol1 vol2 pool1 pool2
>
> as you said, combination of --vol and --pool completers.
No, it should work like this:
virsh# vol-key <TAB>
vol1 vol2 --vol --pool
the combination of all (non-option) completions for the current
available mandatory option (volume completer), and of all possible
options that still make sense at this point in the command line.
Likewise:
virsh# vol-key vol <TAB>
pool1 pool2 --pool
virsh# vol-key -<TAB>
--vol --pool
virsh# vol-key v<TAB>
vol1 vol2
virsh# vol-key --pool <TAB>
pool1 pool2
virsh# vol-key --pool pool1 <TAB>
vol1 vol2 --vol
and so forth.
>
>
> I was initially thinking that completion should work like this:
>
> virsh # vol-key <TAB>
> vol1 vol2
>
> It is completing <vol> first becasue <vol> is only mandatory argument
> for this command.
It is a mandatory option, but mandatory options need not come first.
Remember, our option parser allows mandatory options to occur
positionally without an option name, OR to be interleaved in any other
order by including the option string.
>
>
> Only if someone type:
>
> virsh # vol-key --pool <TAB>
> pool1 pool2
>
> then call --pool completer.
This is correct - once an option is awaiting an argument, then the
option completer must return nothing at that point in time. But if you
look at it as the union of two completers - the set of options that are
still valid in the current context, and the set of strings that are
valid assuming positional semantics of the current option, you will
always get the right answer, without needing a per-command completer
(just per-option completers).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
11 years, 7 months
[libvirt] [PATCH] examples: Add script to parse topology from capabilities output
by Peter Krempa
Add a demo script originally written by Amador Pahim to parse topology
of the host from data provided in the capabilities XML.
---
examples/python/topology.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100755 examples/python/topology.py
diff --git a/examples/python/topology.py b/examples/python/topology.py
new file mode 100755
index 0000000..1b678bc
--- /dev/null
+++ b/examples/python/topology.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# Parse topology information from the capabilities XML and use
+# them to calculate host topology
+#
+# Authors:
+# Amador Pahim <apahim(a)redhat.com>
+# Peter Krempa <pkrempa(a)redhat.com>
+
+import libvirt
+import sys
+from xml.dom import minidom
+
+try:
+ conn = libvirt.openReadOnly(None)
+except libvirt.libvirtError:
+ print 'Failed to connect to the hypervisor'
+ sys.exit(1)
+
+try:
+ capsXML = conn.getCapabilities()
+except libvirt.libvirtError:
+ print 'Failed to request capabilities'
+ sys.exit(1)
+
+caps = minidom.parseString(capsXML)
+host = caps.getElementsByTagName('host')[0]
+cells = host.getElementsByTagName('cells')[0]
+total_cpus = cells.getElementsByTagName('cpu').length
+
+socketIds = []
+siblingsIds = []
+
+socketIds = [ proc.getAttribute('socket_id')
+ for proc in cells.getElementsByTagName('cpu')
+ if proc.getAttribute('socket_id') not in socketIds ]
+
+siblingsIds = [ proc.getAttribute('siblings')
+ for proc in cells.getElementsByTagName('cpu')
+ if proc.getAttribute('siblings') not in siblingsIds ]
+
+print "Host topology"
+print "NUMA nodes:", cells.getAttribute('num')
+print " Sockets:",len(set(socketIds))
+print " Cores:",len(set(siblingsIds))
+print " Threads:",total_cpus
--
1.8.3.2
11 years, 7 months
[libvirt] RFC: Splitting python binding out into a separate repo & ading to PyPi
by Daniel P. Berrange
As everyone knows, we have historically always shipped the python binding
as part of the libvirt primary tar.gz distribution. In some ways that has
simplified life for people, since we know they'll always have a libvirt
python that matches their libvirt C library.
At the same time though, this policy of ours is causing increasing amounts
of pain for a number of our downstream users.
In OpenStack, in particular, their development and test environments aim
to be able to not rely on any system installed python packages. They use
a virtualenv and pip to install all python deps from PyPi (equivalent of
Perl's CPAN in Python world). This approach works for everything except
the libvirt Python code which is not available standalone on PyPi. This
is causing so much pain that people have suggested taking the libvirt
python code we ship and just uploading it to PyPi themselves[1]. This
would obviously be a somewhat hostile action to take, but the way we
distribute libvirt python is forcing OpenStack to consider such things.
In RHEL world too, bundling of libvirt + its python binding is causing
pain with the fairly recent concept of "software collections"[2]. This
allows users to install multiple versions of languages like Python, Perl,
etc on the same box in parallel. To use libvirt python with thse alternate
python installs though, requires that they recompile the entire libvirt
distribution just to get the Python binding. This is obviously not an
approach that works for most people, particularly if they're looking to
populate their software collection using 'pip' rather than RPM.
Looking on google there are a number of other people asking for libvirt
python as a separate module, eg on Stackoverflow[3].
I don't think these issues are going to go away, in fact I think they
will likely become more pressing, until the point where some 3rd party
takes the step of providing libvirt python bindings themselves. I don't
think we want to let ourselves drift into the situation where we loose
control over releasing libvirt python bindings.
IMHO we should / must listen to our users here before it is too late.
We can still release libvirt python at the same time as normal libvirt
releases, and require that people update the bindings whenever adding
new APIs (if the generator doesn't cope with them). We should simply
distribute python as a separate tar.gz, as we do for all other languages,
and upload it to PyPi, as well as libvirt.org FTP when doing a release.
Obviously there will be some work to separate things out, but I don't
see that being insurmountable, since all other language bindings manage
to be separate, even when doing code generation. We'd also want to
change to use distutils, rather than autoconf, since that's what the
python world wants.
Regards,
Daniel
[1] http://lists.openstack.org/pipermail/openstack-dev/2013-August/013187.html
[2] https://access.redhat.com/site/documentation/en-US/Red_Hat_Developer_Tool...
[3] http://stackoverflow.com/questions/14924460/is-there-any-way-to-install-l...
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
11 years, 7 months