unsigned int flags ATTRIBUTE_UNUSED)
{
int ret = -1;
- char size[100];
+ char *size = NULL;
char *create_tool;
const char *type = virStorageFileFormatTypeToString(vol->target.format);
}
/* Size in KB */
- snprintf(size, sizeof(size), "%lluK", vol->capacity/1024);
+ if (virAsprintf(&size, "%lluK", vol->capacity / 1024) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
/* KVM is usually ahead of qemu on features, so try that first */
create_tool = virFindFileInPath("kvm-img");
}
cleanup:
+ VIR_FREE(size);
VIR_FREE(create_tool);
return ret;
unsigned int flags ATTRIBUTE_UNUSED)
{
int ret;
- char size[100];
+ char *size;
const char *imgargv[4];
if (inputvol) {
}
/* Size in MB - yes different units to qemu-img :-( */
- snprintf(size, sizeof(size), "%llu", vol->capacity/1024/1024);
+ if (virAsprintf(&size, "%llu", vol->capacity / 1024 / 1024) < 0) {
+ virReportOOMError();
+ return -1;
+ }
imgargv[0] = virFindFileInPath("qcow-create");
imgargv[1] = size;
ret = virStorageBackendCreateExecCommand(pool, vol, imgargv);
VIR_FREE(imgargv[0]);
+ VIR_FREE(size);
return ret;
}
static int
virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
- char* partFormat)
+ char** partFormat)
{
int i;
if (pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) {
return -1;
}
}
- sprintf(partFormat, "%s", partedFormat);
+ if ((*partFormat = strdup(partedFormat)) == NULL) {
+ virReportOOMError();
+ return -1;
+ }
} else {
/* create primary partition as long as it is possible
and after that check if an extended partition exists
/* XXX Only support one extended partition */
switch (virStorageBackendDiskPartTypeToCreate(pool)) {
case VIR_STORAGE_VOL_DISK_TYPE_PRIMARY:
- sprintf(partFormat, "primary %s", partedFormat);
+ if (virAsprintf(partFormat, "primary %s", partedFormat) < 0) {
+ virReportOOMError();
+ return -1;
+ }
break;
case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL:
/* make sure we have a extended partition */
for (i = 0; i < pool->volumes.count; i++) {
if (pool->volumes.objs[i]->target.format ==
VIR_STORAGE_VOL_DISK_EXTENDED) {
- sprintf(partFormat, "logical %s", partedFormat);
+ if (virAsprintf(partFormat, "logical %s",
+ partedFormat) < 0) {
+ virReportOOMError();
+ return -1;
+ }
break;
}
}
}
break;
default:
- break;
+ virStorageReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("unknown partition type"));
+ return -1;
}
}
} else {
- sprintf(partFormat, "primary");
+ if ((*partFormat = strdup("primary")) == NULL) {
+ virReportOOMError();
+ return -1;
+ }
}
return 0;
}
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol)
{
- char start[100], end[100], partFormat[100];
+ int res = -1;
+ char *start = NULL;
+ char *end = NULL;
+ char *partFormat;
unsigned long long startOffset = 0, endOffset = 0;
const char *cmdargv[] = {
PARTED,
pool->def->source.devices[0].path,
"mkpart",
"--script",
- partFormat,
- start,
- end,
+ NULL /*partFormat*/,
+ NULL /*start*/,
+ NULL /*end*/,
NULL
};
return -1;
}
- if (virStorageBackendDiskPartFormat(pool, vol, partFormat) != 0) {
+ if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) {
return -1;
}
+ cmdargv[4] = partFormat;
if (virStorageBackendDiskPartBoundries(pool, &startOffset,
&endOffset,
vol->capacity) != 0) {
- return -1;
+ goto cleanup;
}
- snprintf(start, sizeof(start)-1, "%lluB", startOffset);
- start[sizeof(start)-1] = '\0';
- snprintf(end, sizeof(end)-1, "%lluB", endOffset);
- end[sizeof(end)-1] = '\0';
+ if (virAsprintf(&start, "%lluB", startOffset) < 0 ||
+ virAsprintf(&end, "%lluB", endOffset) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ cmdargv[5] = start;
+ cmdargv[6] = end;
if (virRun(cmdargv, NULL) < 0)
- return -1;
+ goto cleanup;
/* wait for device node to show up */
virFileWaitForDevices();
/* Fetch actual extent info, generate key */
if (virStorageBackendDiskReadPartitions(pool, vol) < 0)
- return -1;
+ goto cleanup;
- return 0;
+ res = 0;
+
+cleanup:
+ VIR_FREE(partFormat);
+ VIR_FREE(start);
+ VIR_FREE(end);
+ return res;
}
static int