mirror of https://gitee.com/openkylin/libvirt.git
libxl: Use g_strdup_printf() instead of virAsprintf()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
9a2454bbc4
commit
f9d6b01262
|
@ -212,8 +212,7 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
|
|||
|
||||
case VIR_DOMAIN_CHR_TYPE_FILE:
|
||||
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
||||
if (virAsprintf(buf, "%s:%s", type, srcdef->data.file.path) < 0)
|
||||
return -1;
|
||||
*buf = g_strdup_printf("%s:%s", type, srcdef->data.file.path);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_DEV:
|
||||
|
@ -232,12 +231,8 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
|
|||
if (bindService == NULL)
|
||||
bindService = "0";
|
||||
|
||||
if (virAsprintf(buf, "udp:%s:%s@%s:%s",
|
||||
connectHost,
|
||||
srcdef->data.udp.connectService,
|
||||
bindHost,
|
||||
bindService) < 0)
|
||||
return -1;
|
||||
*buf = g_strdup_printf("udp:%s:%s@%s:%s", connectHost,
|
||||
srcdef->data.udp.connectService, bindHost, bindService);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -249,20 +244,15 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
|
|||
else
|
||||
prefix = "tcp";
|
||||
|
||||
if (virAsprintf(buf, "%s:%s:%s%s",
|
||||
prefix,
|
||||
srcdef->data.tcp.host,
|
||||
srcdef->data.tcp.service,
|
||||
srcdef->data.tcp.listen ? ",server,nowait" : "") < 0)
|
||||
return -1;
|
||||
*buf = g_strdup_printf("%s:%s:%s%s", prefix, srcdef->data.tcp.host,
|
||||
srcdef->data.tcp.service,
|
||||
srcdef->data.tcp.listen ? ",server,nowait" : "");
|
||||
break;
|
||||
}
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||
if (virAsprintf(buf, "unix:%s%s",
|
||||
srcdef->data.nix.path,
|
||||
srcdef->data.nix.listen ? ",server,nowait" : "") < 0)
|
||||
return -1;
|
||||
*buf = g_strdup_printf("unix:%s%s", srcdef->data.nix.path,
|
||||
srcdef->data.nix.listen ? ",server,nowait" : "");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1932,11 +1922,12 @@ libxlPrepareChannel(virDomainChrDefPtr channel,
|
|||
if (channel->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN &&
|
||||
channel->source->type == VIR_DOMAIN_CHR_TYPE_UNIX &&
|
||||
!channel->source->data.nix.path) {
|
||||
if (virAsprintf(&channel->source->data.nix.path,
|
||||
"%s/%s-%s", channelDir, domainName,
|
||||
channel->target.name ? channel->target.name
|
||||
: "unknown.sock") < 0)
|
||||
return -1;
|
||||
const char *target = channel->target.name;
|
||||
if (!target)
|
||||
target = "unknown.sock";
|
||||
channel->source->data.nix.path = g_strdup_printf("%s/%s-%s", channelDir,
|
||||
domainName,
|
||||
target);
|
||||
|
||||
channel->source->data.nix.listen = true;
|
||||
}
|
||||
|
|
|
@ -714,7 +714,7 @@ libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
|
|||
char *ret;
|
||||
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
||||
|
||||
ignore_value(virAsprintf(&ret, "%s/%s.save", cfg->saveDir, vm->def->name));
|
||||
ret = g_strdup_printf("%s/%s.save", cfg->saveDir, vm->def->name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -905,11 +905,11 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
|
|||
}
|
||||
}
|
||||
|
||||
if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) > 0) {
|
||||
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
|
||||
VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name);
|
||||
VIR_FREE(file);
|
||||
}
|
||||
file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name);
|
||||
|
||||
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
|
||||
VIR_DEBUG("Failed to remove domain XML for %s", vm->def->name);
|
||||
VIR_FREE(file);
|
||||
|
||||
/* The "release" hook cleans up additional resources */
|
||||
if (virHookPresent(VIR_HOOK_DRIVER_LIBXL)) {
|
||||
|
@ -940,28 +940,20 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
|
|||
char timestr[100];
|
||||
struct tm time_info;
|
||||
char *dumpfile = NULL;
|
||||
int ret = -1;
|
||||
|
||||
localtime_r(&curtime, &time_info);
|
||||
strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info);
|
||||
|
||||
if (virAsprintf(&dumpfile, "%s/%s-%s",
|
||||
cfg->autoDumpDir,
|
||||
vm->def->name,
|
||||
timestr) < 0)
|
||||
goto cleanup;
|
||||
dumpfile = g_strdup_printf("%s/%s-%s", cfg->autoDumpDir, vm->def->name,
|
||||
timestr);
|
||||
|
||||
/* Unlock virDomainObj while dumping core */
|
||||
virObjectUnlock(vm);
|
||||
libxl_domain_core_dump(cfg->ctx, vm->def->id, dumpfile, NULL);
|
||||
virObjectLock(vm);
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(dumpfile);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1130,7 +1122,7 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
|
|||
for (i = 0; i < vm->def->nserials; i++) {
|
||||
chr = vm->def->serials[i];
|
||||
|
||||
ignore_value(virAsprintf(&chr->info.alias, "serial%zd", i));
|
||||
chr->info.alias = g_strdup_printf("serial%zd", i);
|
||||
if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
|
||||
if (chr->source->data.file.path)
|
||||
continue;
|
||||
|
@ -1170,9 +1162,8 @@ libxlDomainCreateIfaceNames(virDomainDefPtr def, libxl_domain_config *d_config)
|
|||
if (net->ifname)
|
||||
continue;
|
||||
|
||||
ignore_value(virAsprintf(&net->ifname,
|
||||
LIBXL_GENERATED_PREFIX_XEN "%d.%d%s",
|
||||
def->id, x_nic->devid, suffix));
|
||||
net->ifname = g_strdup_printf(LIBXL_GENERATED_PREFIX_XEN "%d.%d%s",
|
||||
def->id, x_nic->devid, suffix);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -693,8 +693,7 @@ libxlStateInitialize(bool privileged,
|
|||
if (!(cfg = libxlDriverConfigNew()))
|
||||
goto error;
|
||||
|
||||
if (virAsprintf(&driverConf, "%s/libxl.conf", cfg->configBaseDir) < 0)
|
||||
goto error;
|
||||
driverConf = g_strdup_printf("%s/libxl.conf", cfg->configBaseDir);
|
||||
|
||||
if (libxlDriverConfigLoadFile(cfg, driverConf) < 0)
|
||||
goto error;
|
||||
|
@ -5380,16 +5379,13 @@ libxlDiskSectorSize(int domid, int devno)
|
|||
}
|
||||
|
||||
path = val = NULL;
|
||||
if (virAsprintf(&path, "/local/domain/%d/device/vbd/%d/backend",
|
||||
domid, devno) < 0)
|
||||
goto cleanup;
|
||||
path = g_strdup_printf("/local/domain/%d/device/vbd/%d/backend", domid, devno);
|
||||
|
||||
if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
VIR_FREE(path);
|
||||
if (virAsprintf(&path, "%s/physical-sector-size", val) < 0)
|
||||
goto cleanup;
|
||||
path = g_strdup_printf("%s/physical-sector-size", val);
|
||||
|
||||
VIR_FREE(val);
|
||||
if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
|
||||
|
@ -5427,9 +5423,8 @@ libxlDomainBlockStatsVBD(virDomainObjPtr vm,
|
|||
|
||||
stats->backend = g_strdup("vbd");
|
||||
|
||||
if (virAsprintf(&path, "/sys/bus/xen-backend/devices/vbd-%d-%d/statistics",
|
||||
vm->def->id, devno) < 0)
|
||||
return ret;
|
||||
path = g_strdup_printf("/sys/bus/xen-backend/devices/vbd-%d-%d/statistics",
|
||||
vm->def->id, devno);
|
||||
|
||||
if (!virFileExists(path)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
|
@ -5438,8 +5433,8 @@ libxlDomainBlockStatsVBD(virDomainObjPtr vm,
|
|||
}
|
||||
|
||||
# define LIBXL_SET_VBDSTAT(FIELD, VAR, MUL) \
|
||||
if ((virAsprintf(&name, "%s/"FIELD, path) < 0) || \
|
||||
(virFileReadAll(name, 256, &val) < 0) || \
|
||||
name = g_strdup_printf("%s/"FIELD, path); \
|
||||
if ((virFileReadAll(name, 256, &val) < 0) || \
|
||||
(sscanf(val, "%llu", &status) != 1)) { \
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, \
|
||||
_("cannot read %s"), name); \
|
||||
|
|
|
@ -158,8 +158,7 @@ libxlLoggerNew(const char *logDir, virLogPriority minLevel)
|
|||
if ((logger.files = virHashCreate(3, libxlLoggerFileFree)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (virAsprintf(&path, "%s/libxl-driver.log", logDir) < 0)
|
||||
goto error;
|
||||
path = g_strdup_printf("%s/libxl-driver.log", logDir);
|
||||
|
||||
if ((logger.defaultLogFile = fopen(path, "a")) == NULL)
|
||||
goto error;
|
||||
|
@ -196,9 +195,8 @@ libxlLoggerOpenFile(libxlLoggerPtr logger,
|
|||
char *domidstr = NULL;
|
||||
char ebuf[1024];
|
||||
|
||||
if (virAsprintf(&path, "%s/%s.log", logger->logDir, name) < 0 ||
|
||||
virAsprintf(&domidstr, "%d", id) < 0)
|
||||
goto cleanup;
|
||||
path = g_strdup_printf("%s/%s.log", logger->logDir, name);
|
||||
domidstr = g_strdup_printf("%d", id);
|
||||
|
||||
if (!(logFile = fopen(path, "a"))) {
|
||||
VIR_WARN("Failed to open log file %s: %s",
|
||||
|
@ -222,8 +220,7 @@ void
|
|||
libxlLoggerCloseFile(libxlLoggerPtr logger, int id)
|
||||
{
|
||||
char *domidstr = NULL;
|
||||
if (virAsprintf(&domidstr, "%d", id) < 0)
|
||||
return;
|
||||
domidstr = g_strdup_printf("%d", id);
|
||||
|
||||
ignore_value(virHashRemoveEntry(logger->files, domidstr));
|
||||
|
||||
|
|
|
@ -706,14 +706,12 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
|
|||
goto endjob;
|
||||
|
||||
priv->migrationPort = port;
|
||||
if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
|
||||
goto endjob;
|
||||
*uri_out = g_strdup_printf("tcp://%s:%d", hostname, port);
|
||||
} else {
|
||||
if (!(STRPREFIX(uri_in, "tcp://"))) {
|
||||
/* not full URI, add prefix tcp:// */
|
||||
char *tmp;
|
||||
if (virAsprintf(&tmp, "tcp://%s", uri_in) < 0)
|
||||
goto endjob;
|
||||
tmp = g_strdup_printf("tcp://%s", uri_in);
|
||||
uri = virURIParse(tmp);
|
||||
VIR_FREE(tmp);
|
||||
} else {
|
||||
|
@ -744,8 +742,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
|
|||
port = uri->port;
|
||||
}
|
||||
|
||||
if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0)
|
||||
goto endjob;
|
||||
*uri_out = g_strdup_printf("tcp://%s:%d", hostname, port);
|
||||
}
|
||||
|
||||
snprintf(portstr, sizeof(portstr), "%d", port);
|
||||
|
|
|
@ -1830,12 +1830,11 @@ xenFormatPCI(virConfPtr conf, virDomainDefPtr def)
|
|||
virConfValuePtr val, tmp;
|
||||
char *buf;
|
||||
|
||||
if (virAsprintf(&buf, "%04x:%02x:%02x.%x",
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.domain,
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.bus,
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.slot,
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.function) < 0)
|
||||
goto error;
|
||||
buf = g_strdup_printf("%04x:%02x:%02x.%x",
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.domain,
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.bus,
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.slot,
|
||||
def->hostdevs[i]->source.subsys.u.pci.addr.function);
|
||||
|
||||
if (VIR_ALLOC(val) < 0) {
|
||||
VIR_FREE(buf);
|
||||
|
|
|
@ -83,11 +83,9 @@ static int xenParseCmdline(virConfPtr conf, char **r_cmdline)
|
|||
VIR_WARN("ignoring root= and extra= in favour of cmdline=");
|
||||
} else {
|
||||
if (root && extra) {
|
||||
if (virAsprintf(&cmdline, "root=%s %s", root, extra) < 0)
|
||||
return -1;
|
||||
cmdline = g_strdup_printf("root=%s %s", root, extra);
|
||||
} else if (root) {
|
||||
if (virAsprintf(&cmdline, "root=%s", root) < 0)
|
||||
return -1;
|
||||
cmdline = g_strdup_printf("root=%s", root);
|
||||
} else if (extra) {
|
||||
cmdline = g_strdup(extra);
|
||||
}
|
||||
|
@ -1396,10 +1394,7 @@ xenFormatXLCPUID(virConfPtr conf, virDomainDefPtr def)
|
|||
policy = "0";
|
||||
break;
|
||||
}
|
||||
if (virAsprintf(&cpuid_pairs[j++], "%s=%s",
|
||||
feature_name,
|
||||
policy) < 0)
|
||||
goto cleanup;
|
||||
cpuid_pairs[j++] = g_strdup_printf("%s=%s", feature_name, policy);
|
||||
}
|
||||
cpuid_pairs[j] = NULL;
|
||||
|
||||
|
@ -2064,10 +2059,9 @@ xenFormatXLUSB(virConfPtr conf,
|
|||
virConfValuePtr val, tmp;
|
||||
char *buf;
|
||||
|
||||
if (virAsprintf(&buf, "hostbus=%x,hostaddr=%x",
|
||||
def->hostdevs[i]->source.subsys.u.usb.bus,
|
||||
def->hostdevs[i]->source.subsys.u.usb.device) < 0)
|
||||
goto error;
|
||||
buf = g_strdup_printf("hostbus=%x,hostaddr=%x",
|
||||
def->hostdevs[i]->source.subsys.u.usb.bus,
|
||||
def->hostdevs[i]->source.subsys.u.usb.device);
|
||||
|
||||
if (VIR_ALLOC(val) < 0) {
|
||||
VIR_FREE(buf);
|
||||
|
|
|
@ -90,11 +90,9 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
|
|||
return -1;
|
||||
|
||||
if (root && extra) {
|
||||
if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
|
||||
return -1;
|
||||
def->os.cmdline = g_strdup_printf("root=%s %s", root, extra);
|
||||
} else if (root) {
|
||||
if (virAsprintf(&def->os.cmdline, "root=%s", root) < 0)
|
||||
return -1;
|
||||
def->os.cmdline = g_strdup_printf("root=%s", root);
|
||||
} else if (extra) {
|
||||
def->os.cmdline = g_strdup(extra);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue