mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemu: Introduce qemuDomainHostdevPrivatePtr
Modeled after the qemuDomainDiskPrivatePtr logic, create a privateData pointer in the _virDomainHostdevDef to allow storage of private data for a hypervisor in order to at least temporarily store auth/secrets data for usage during qemuBuildCommandLine. NB: Since the qemu_parse_command (qemuParseCommandLine) code is not expecting to restore the auth/secret data, there's no need to add code to handle this new structure there. Updated copyrights for modules touched. Some didn't have updates in a couple years even though changes have been made. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
40d8e2ba37
commit
27726d8c21
@ -2121,16 +2121,32 @@ void virDomainVideoDefFree(virDomainVideoDefPtr def)
|
||||
VIR_FREE(def);
|
||||
}
|
||||
|
||||
virDomainHostdevDefPtr virDomainHostdevDefAlloc(void)
|
||||
|
||||
virDomainHostdevDefPtr
|
||||
virDomainHostdevDefAlloc(virDomainXMLOptionPtr xmlopt)
|
||||
{
|
||||
virDomainHostdevDefPtr def = NULL;
|
||||
|
||||
if (VIR_ALLOC(def) < 0 ||
|
||||
VIR_ALLOC(def->info) < 0)
|
||||
VIR_ALLOC(def->info) < 0) {
|
||||
VIR_FREE(def);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (xmlopt &&
|
||||
xmlopt->privateData.hostdevNew &&
|
||||
!(def->privateData = xmlopt->privateData.hostdevNew()))
|
||||
goto error;
|
||||
|
||||
return def;
|
||||
|
||||
error:
|
||||
VIR_FREE(def->info);
|
||||
VIR_FREE(def);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc)
|
||||
{
|
||||
@ -12212,7 +12228,8 @@ virDomainVideoDefParseXML(xmlNodePtr node,
|
||||
}
|
||||
|
||||
static virDomainHostdevDefPtr
|
||||
virDomainHostdevDefParseXML(xmlNodePtr node,
|
||||
virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
xmlNodePtr node,
|
||||
xmlXPathContextPtr ctxt,
|
||||
virHashTablePtr bootHash,
|
||||
unsigned int flags)
|
||||
@ -12224,7 +12241,7 @@ virDomainHostdevDefParseXML(xmlNodePtr node,
|
||||
|
||||
ctxt->node = node;
|
||||
|
||||
if (!(def = virDomainHostdevDefAlloc()))
|
||||
if (!(def = virDomainHostdevDefAlloc(xmlopt)))
|
||||
goto error;
|
||||
|
||||
if (mode) {
|
||||
@ -12874,8 +12891,9 @@ virDomainDeviceDefParse(const char *xmlStr,
|
||||
goto error;
|
||||
break;
|
||||
case VIR_DOMAIN_DEVICE_HOSTDEV:
|
||||
if (!(dev->data.hostdev = virDomainHostdevDefParseXML(node, ctxt,
|
||||
NULL, flags)))
|
||||
if (!(dev->data.hostdev = virDomainHostdevDefParseXML(xmlopt, node,
|
||||
ctxt, NULL,
|
||||
flags)))
|
||||
goto error;
|
||||
break;
|
||||
case VIR_DOMAIN_DEVICE_CONTROLLER:
|
||||
@ -16395,7 +16413,8 @@ virDomainDefParseXML(xmlDocPtr xml,
|
||||
for (i = 0; i < n; i++) {
|
||||
virDomainHostdevDefPtr hostdev;
|
||||
|
||||
hostdev = virDomainHostdevDefParseXML(nodes[i], ctxt, bootHash, flags);
|
||||
hostdev = virDomainHostdevDefParseXML(xmlopt, nodes[i], ctxt,
|
||||
bootHash, flags);
|
||||
if (!hostdev)
|
||||
goto error;
|
||||
|
||||
|
@ -542,6 +542,8 @@ struct _virDomainHostdevCaps {
|
||||
/* basic device for direct passthrough */
|
||||
struct _virDomainHostdevDef {
|
||||
virDomainDeviceDef parent; /* higher level Def containing this */
|
||||
virObjectPtr privateData;
|
||||
|
||||
int mode; /* enum virDomainHostdevMode */
|
||||
int startupPolicy; /* enum virDomainStartupPolicy */
|
||||
bool managed;
|
||||
@ -2495,6 +2497,7 @@ struct _virDomainXMLPrivateDataCallbacks {
|
||||
virDomainXMLPrivateDataAllocFunc alloc;
|
||||
virDomainXMLPrivateDataFreeFunc free;
|
||||
virDomainXMLPrivateDataNewFunc diskNew;
|
||||
virDomainXMLPrivateDataNewFunc hostdevNew;
|
||||
virDomainXMLPrivateDataFormatFunc format;
|
||||
virDomainXMLPrivateDataParseFunc parse;
|
||||
};
|
||||
@ -2572,7 +2575,7 @@ void virDomainMemballoonDefFree(virDomainMemballoonDefPtr def);
|
||||
void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def);
|
||||
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
|
||||
void virDomainVideoDefFree(virDomainVideoDefPtr def);
|
||||
virDomainHostdevDefPtr virDomainHostdevDefAlloc(void);
|
||||
virDomainHostdevDefPtr virDomainHostdevDefAlloc(virDomainXMLOptionPtr xmlopt);
|
||||
void virDomainHostdevDefClear(virDomainHostdevDefPtr def);
|
||||
void virDomainHostdevDefFree(virDomainHostdevDefPtr def);
|
||||
void virDomainHubDefFree(virDomainHubDefPtr def);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* lxc_native.c: LXC native configuration import
|
||||
*
|
||||
* Copyright (c) 2014 Red Hat, Inc.
|
||||
* Copyright (c) 2014-2016 Red Hat, Inc.
|
||||
* Copyright (c) 2013-2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -394,7 +394,7 @@ lxcCreateNetDef(const char *type,
|
||||
static virDomainHostdevDefPtr
|
||||
lxcCreateHostdevDef(int mode, int type, const char *data)
|
||||
{
|
||||
virDomainHostdevDefPtr hostdev = virDomainHostdevDefAlloc();
|
||||
virDomainHostdevDefPtr hostdev = virDomainHostdevDefAlloc(NULL);
|
||||
|
||||
if (!hostdev)
|
||||
return NULL;
|
||||
|
@ -792,6 +792,49 @@ qemuDomainDiskPrivateDispose(void *obj)
|
||||
}
|
||||
|
||||
|
||||
static virClassPtr qemuDomainHostdevPrivateClass;
|
||||
static void qemuDomainHostdevPrivateDispose(void *obj);
|
||||
|
||||
static int
|
||||
qemuDomainHostdevPrivateOnceInit(void)
|
||||
{
|
||||
qemuDomainHostdevPrivateClass =
|
||||
virClassNew(virClassForObject(),
|
||||
"qemuDomainHostdevPrivate",
|
||||
sizeof(qemuDomainHostdevPrivate),
|
||||
qemuDomainHostdevPrivateDispose);
|
||||
if (!qemuDomainHostdevPrivateClass)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(qemuDomainHostdevPrivate)
|
||||
|
||||
static virObjectPtr
|
||||
qemuDomainHostdevPrivateNew(void)
|
||||
{
|
||||
qemuDomainHostdevPrivatePtr priv;
|
||||
|
||||
if (qemuDomainHostdevPrivateInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(priv = virObjectNew(qemuDomainHostdevPrivateClass)))
|
||||
return NULL;
|
||||
|
||||
return (virObjectPtr) priv;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
qemuDomainHostdevPrivateDispose(void *obj)
|
||||
{
|
||||
qemuDomainHostdevPrivatePtr priv = obj;
|
||||
|
||||
qemuDomainSecretInfoFree(&priv->secinfo);
|
||||
}
|
||||
|
||||
|
||||
/* qemuDomainSecretPlainSetup:
|
||||
* @conn: Pointer to connection
|
||||
* @secinfo: Pointer to secret info
|
||||
@ -1417,6 +1460,7 @@ virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks = {
|
||||
.alloc = qemuDomainObjPrivateAlloc,
|
||||
.free = qemuDomainObjPrivateFree,
|
||||
.diskNew = qemuDomainDiskPrivateNew,
|
||||
.hostdevNew = qemuDomainHostdevPrivateNew,
|
||||
.parse = qemuDomainObjPrivateXMLParse,
|
||||
.format = qemuDomainObjPrivateXMLFormat,
|
||||
};
|
||||
|
@ -287,6 +287,19 @@ struct _qemuDomainDiskPrivate {
|
||||
qemuDomainSecretInfoPtr secinfo;
|
||||
};
|
||||
|
||||
# define QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev) \
|
||||
((qemuDomainHostdevPrivatePtr) (hostdev)->privateData)
|
||||
|
||||
typedef struct _qemuDomainHostdevPrivate qemuDomainHostdevPrivate;
|
||||
typedef qemuDomainHostdevPrivate *qemuDomainHostdevPrivatePtr;
|
||||
struct _qemuDomainHostdevPrivate {
|
||||
virObject parent;
|
||||
|
||||
/* for hostdev storage devices using auth/secret
|
||||
* NB: *not* to be written to qemu domain object XML */
|
||||
qemuDomainSecretInfoPtr secinfo;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
QEMU_PROCESS_EVENT_WATCHDOG = 0,
|
||||
QEMU_PROCESS_EVENT_GUESTPANIC,
|
||||
|
@ -1164,7 +1164,7 @@ qemuParseCommandLinePCI(const char *val)
|
||||
int bus = 0, slot = 0, func = 0;
|
||||
const char *start;
|
||||
char *end;
|
||||
virDomainHostdevDefPtr def = virDomainHostdevDefAlloc();
|
||||
virDomainHostdevDefPtr def = virDomainHostdevDefAlloc(NULL);
|
||||
|
||||
if (!def)
|
||||
goto error;
|
||||
@ -1214,7 +1214,7 @@ qemuParseCommandLinePCI(const char *val)
|
||||
static virDomainHostdevDefPtr
|
||||
qemuParseCommandLineUSB(const char *val)
|
||||
{
|
||||
virDomainHostdevDefPtr def = virDomainHostdevDefAlloc();
|
||||
virDomainHostdevDefPtr def = virDomainHostdevDefAlloc(NULL);
|
||||
virDomainHostdevSubsysUSBPtr usbsrc;
|
||||
int first = 0, second = 0;
|
||||
const char *start;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014, Taowei Luo (uaedante@gmail.com)
|
||||
* Copyright (C) 2010-2015 Red Hat, Inc.
|
||||
* Copyright (C) 2010-2016 Red Hat, Inc.
|
||||
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -3033,7 +3033,7 @@ vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, IMachine *ma
|
||||
goto release_filters;
|
||||
|
||||
for (i = 0; i < def->nhostdevs; i++) {
|
||||
def->hostdevs[i] = virDomainHostdevDefAlloc();
|
||||
def->hostdevs[i] = virDomainHostdevDefAlloc(NULL);
|
||||
if (!def->hostdevs[i])
|
||||
goto release_hostdevs;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
* between XM and XL
|
||||
*
|
||||
* Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
* Copyright (C) 2006-2007, 2009-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2007, 2009-2016 Red Hat, Inc.
|
||||
* Copyright (C) 2011 Univention GmbH
|
||||
* Copyright (C) 2006 Daniel P. Berrange
|
||||
*
|
||||
@ -458,7 +458,7 @@ xenParsePCI(virConfPtr conf, virDomainDefPtr def)
|
||||
goto skippci;
|
||||
if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
|
||||
goto skippci;
|
||||
if (!(hostdev = virDomainHostdevDefAlloc()))
|
||||
if (!(hostdev = virDomainHostdevDefAlloc(NULL)))
|
||||
return -1;
|
||||
|
||||
hostdev->managed = false;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* xen_sxpr.c: Xen SEXPR parsing functions
|
||||
*
|
||||
* Copyright (C) 2010-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2010-2016 Red Hat, Inc.
|
||||
* Copyright (C) 2011 Univention GmbH
|
||||
* Copyright (C) 2005 Anthony Liguori <aliguori@us.ibm.com>
|
||||
*
|
||||
@ -1110,7 +1110,7 @@ xenParseSxprPCI(virDomainDefPtr def,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(dev = virDomainHostdevDefAlloc()))
|
||||
if (!(dev = virDomainHostdevDefAlloc(NULL)))
|
||||
goto error;
|
||||
|
||||
dev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
* Copyright (C) 2014-2016 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@ -86,7 +87,7 @@ myInit(void)
|
||||
|
||||
for (i = 0; i < nhostdevs; i++) {
|
||||
virDomainHostdevSubsys subsys;
|
||||
hostdevs[i] = virDomainHostdevDefAlloc();
|
||||
hostdevs[i] = virDomainHostdevDefAlloc(NULL);
|
||||
if (!hostdevs[i])
|
||||
goto cleanup;
|
||||
hostdevs[i]->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
||||
|
Loading…
Reference in New Issue
Block a user