mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
conf: consolidate disk def allocation
A future patch wants to create disk definitions with non-zero default contents; to avoid crashes, all callers that allocate a disk definition should go through a common point. I found allocation points by looking for any code that increments ndisks, as well as any matches for ALLOC.*disk. Most places that modified ndisks were covered by the parse from XML to domain/device definition by initial domain creation or device hotplug; I also hand-checked all drivers that generate a device struct on the fly during getXMLDesc. * src/conf/domain_conf.h (virDomainDiskDefNew): New prototype. * src/conf/domain_conf.c (virDomainDiskDefNew): New function. (virDomainDiskDefParseXML): Use it. * src/parallels/parallels_driver.c (parallelsAddHddInfo): Likewise. * src/qemu/qemu_command.c (qemuParseCommandLine): Likewise. * src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc): Likewise. * src/vmx/vmx.c (virVMXParseDisk): Likewise. * src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr): Likewise. * src/xenxs/xen_xm.c (xenParseXM): Likewise. * src/libvirt_private.syms (domain_conf.h): Export it. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
00c6327a12
commit
bc3f5f190e
@ -1181,6 +1181,16 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def)
|
||||
}
|
||||
|
||||
|
||||
virDomainDiskDefPtr
|
||||
virDomainDiskDefNew(void)
|
||||
{
|
||||
virDomainDiskDefPtr ret;
|
||||
|
||||
ignore_value(VIR_ALLOC(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virDomainDiskDefFree(virDomainDiskDefPtr def)
|
||||
{
|
||||
@ -5232,7 +5242,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
int expected_secret_usage = -1;
|
||||
int auth_secret_usage = -1;
|
||||
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
if (!(def = virDomainDiskDefNew()))
|
||||
return NULL;
|
||||
|
||||
def->geometry.cylinders = 0;
|
||||
|
@ -2129,6 +2129,7 @@ void virDomainPanicDefFree(virDomainPanicDefPtr panic);
|
||||
void virDomainResourceDefFree(virDomainResourceDefPtr resource);
|
||||
void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def);
|
||||
void virDomainInputDefFree(virDomainInputDefPtr def);
|
||||
virDomainDiskDefPtr virDomainDiskDefNew(void);
|
||||
void virDomainDiskDefFree(virDomainDiskDefPtr def);
|
||||
void virDomainLeaseDefFree(virDomainLeaseDefPtr def);
|
||||
int virDomainDiskGetType(virDomainDiskDefPtr def);
|
||||
|
@ -207,6 +207,7 @@ virDomainDiskDefAssignAddress;
|
||||
virDomainDiskDefForeachPath;
|
||||
virDomainDiskDefFree;
|
||||
virDomainDiskDefGetSecurityLabelDef;
|
||||
virDomainDiskDefNew;
|
||||
virDomainDiskDeviceTypeToString;
|
||||
virDomainDiskDiscardTypeToString;
|
||||
virDomainDiskErrorPolicyTypeFromString;
|
||||
|
@ -407,7 +407,7 @@ parallelsAddHddInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value)
|
||||
{
|
||||
virDomainDiskDefPtr disk = NULL;
|
||||
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto error;
|
||||
|
||||
if (parallelsGetHddInfo(def, disk, key, value))
|
||||
|
@ -10997,7 +10997,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
||||
STRPREFIX(arg, "-fd") ||
|
||||
STREQ(arg, "-cdrom")) {
|
||||
WANT_VALUE();
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto error;
|
||||
|
||||
if (STRPREFIX(val, "/dev/"))
|
||||
@ -11297,7 +11297,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
||||
goto error;
|
||||
}
|
||||
} else if (STRPREFIX(val, "disk:")) {
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto error;
|
||||
if (VIR_STRDUP(disk->src.path, val + strlen("disk:")) < 0)
|
||||
goto error;
|
||||
|
@ -2768,7 +2768,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
|
||||
|
||||
if ((def->ndisks > 0) && (VIR_ALLOC_N(def->disks, def->ndisks) >= 0)) {
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
if (VIR_ALLOC(def->disks[i]) >= 0) {
|
||||
if ((def->disks[i] = virDomainDiskDefNew())) {
|
||||
def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK;
|
||||
def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE;
|
||||
virDomainDiskSetType(def->disks[i],
|
||||
@ -3247,7 +3247,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
|
||||
|
||||
def->ndisks++;
|
||||
if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) {
|
||||
if (VIR_ALLOC(def->disks[def->ndisks - 1]) >= 0) {
|
||||
if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew())) {
|
||||
def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
|
||||
def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_IDE;
|
||||
virDomainDiskSetType(def->disks[def->ndisks - 1],
|
||||
@ -3294,7 +3294,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
|
||||
|
||||
def->ndisks++;
|
||||
if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) {
|
||||
if (VIR_ALLOC(def->disks[def->ndisks - 1]) >= 0) {
|
||||
if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew())) {
|
||||
def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY;
|
||||
def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_FDC;
|
||||
virDomainDiskSetType(def->disks[def->ndisks - 1],
|
||||
|
@ -1998,7 +1998,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(*def) < 0)
|
||||
if (!(*def = virDomainDiskDefNew()))
|
||||
return -1;
|
||||
|
||||
(*def)->device = device;
|
||||
|
@ -370,7 +370,7 @@ xenParseSxprDisks(virDomainDefPtr def,
|
||||
bootable = sexpr_node(node, "device/tap/bootable");
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto error;
|
||||
|
||||
if (dst == NULL) {
|
||||
@ -1304,7 +1304,7 @@ xenParseSxpr(const struct sexpr *root,
|
||||
tmp = sexpr_node(root, "domain/image/hvm/cdrom");
|
||||
if ((tmp != NULL) && (tmp[0] != 0)) {
|
||||
virDomainDiskDefPtr disk;
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto error;
|
||||
if (virDomainDiskSetSource(disk, tmp) < 0) {
|
||||
virDomainDiskDefFree(disk);
|
||||
@ -1339,10 +1339,10 @@ xenParseSxpr(const struct sexpr *root,
|
||||
tmp = sexpr_fmt_node(root, "domain/image/hvm/%s", fds[i]);
|
||||
if ((tmp != NULL) && (tmp[0] != 0)) {
|
||||
virDomainDiskDefPtr disk;
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto error;
|
||||
if (virDomainDiskSetSource(disk, tmp) < 0) {
|
||||
VIR_FREE(disk);
|
||||
virDomainDiskDefFree(disk);
|
||||
goto error;
|
||||
}
|
||||
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE);
|
||||
|
@ -486,7 +486,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
|
||||
goto skipdisk;
|
||||
head = list->str;
|
||||
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto cleanup;
|
||||
|
||||
/*
|
||||
@ -632,7 +632,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
|
||||
if (xenXMConfigGetString(conf, "cdrom", &str, NULL) < 0)
|
||||
goto cleanup;
|
||||
if (str) {
|
||||
if (VIR_ALLOC(disk) < 0)
|
||||
if (!(disk = virDomainDiskDefNew()))
|
||||
goto cleanup;
|
||||
|
||||
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user