A future patch will split virDomainDiskDef, in order to track
multiple host resources per guest <disk>. To reduce the size
of that patch, I've factored out the four most common accesses
into functions, so that I can incrementally upgrade the code
base to use the accessors, and so that code that doesn't care
about the distinction of per-file details won't have to be
changed when the struct changes.
* src/conf/domain_conf.h (virDomainDiskGetType)
(virDomainDiskSetType, virDomainDiskGetSource)
(virDomainDiskSetSource, virDomainDiskGetDriver)
(virDomainDiskSetDriver, virDomainDiskGetFormat)
(virDomainDiskSetFormat): New prototypes.
* src/conf/domain_conf.c (virDomainDiskGetType)
(virDomainDiskSetType, virDomainDiskGetSource)
(virDomainDiskSetSource, virDomainDiskGetDriver)
(virDomainDiskSetDriver, virDomainDiskGetFormat)
(virDomainDiskSetFormat): Implement them.
* src/libvirt_private.syms (domain_conf.h): Export them.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/conf/domain_conf.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 10 +++++++
src/libvirt_private.syms | 8 ++++++
3 files changed, 90 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 89aa52c..d2724ca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1355,6 +1355,20 @@ error:
int
+virDomainDiskGetType(virDomainDiskDefPtr def)
+{
+ return def->type;
+}
+
+
+void
+virDomainDiskSetType(virDomainDiskDefPtr def, int type)
+{
+ def->type = type;
+}
+
+
+int
virDomainDiskGetActualType(virDomainDiskDefPtr def)
{
if (def->type == VIR_DOMAIN_DISK_TYPE_VOLUME && def->srcpool)
@@ -1364,6 +1378,64 @@ virDomainDiskGetActualType(virDomainDiskDefPtr def)
}
+const char *
+virDomainDiskGetSource(virDomainDiskDefPtr def)
+{
+ return def->src;
+}
+
+
+int
+virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
+{
+ int ret;
+ char *tmp = def->src;
+
+ ret = VIR_STRDUP(def->src, src);
+ if (ret < 0)
+ def->src = tmp;
+ else
+ VIR_FREE(tmp);
+ return ret;
+}
+
+
+const char *
+virDomainDiskGetDriver(virDomainDiskDefPtr def)
+{
+ return def->driverName;
+}
+
+
+int
+virDomainDiskSetDriver(virDomainDiskDefPtr def, const char *name)
+{
+ int ret;
+ char *tmp = def->driverName;
+
+ ret = VIR_STRDUP(def->driverName, name);
+ if (ret < 0)
+ def->driverName = tmp;
+ else
+ VIR_FREE(tmp);
+ return ret;
+}
+
+
+int
+virDomainDiskGetFormat(virDomainDiskDefPtr def)
+{
+ return def->format;
+}
+
+
+void
+virDomainDiskSetFormat(virDomainDiskDefPtr def, int format)
+{
+ def->format = format;
+}
+
+
void virDomainControllerDefFree(virDomainControllerDefPtr def)
{
if (!def)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 27f07e6..cc447b0 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2256,7 +2256,17 @@ void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def);
void virDomainDiskHostDefFree(size_t nhosts, virDomainDiskHostDefPtr hosts);
virDomainDiskHostDefPtr virDomainDiskHostDefCopy(size_t nhosts,
virDomainDiskHostDefPtr hosts);
+int virDomainDiskGetType(virDomainDiskDefPtr def);
+void virDomainDiskSetType(virDomainDiskDefPtr def, int type);
int virDomainDiskGetActualType(virDomainDiskDefPtr def);
+const char *virDomainDiskGetSource(virDomainDiskDefPtr def);
+int virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
+ ATTRIBUTE_RETURN_CHECK;
+const char *virDomainDiskGetDriver(virDomainDiskDefPtr def);
+int virDomainDiskSetDriver(virDomainDiskDefPtr def, const char *name)
+ ATTRIBUTE_RETURN_CHECK;
+int virDomainDiskGetFormat(virDomainDiskDefPtr def);
+void virDomainDiskSetFormat(virDomainDiskDefPtr def, int format);
int virDomainDeviceFindControllerModel(virDomainDefPtr def,
virDomainDeviceInfoPtr info,
int controllerType);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3baf766..624b420 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -200,6 +200,10 @@ virDomainDiskFindByBusAndDst;
virDomainDiskGeometryTransTypeFromString;
virDomainDiskGeometryTransTypeToString;
virDomainDiskGetActualType;
+virDomainDiskGetDriver;
+virDomainDiskGetFormat;
+virDomainDiskGetSource;
+virDomainDiskGetType;
virDomainDiskHostDefClear;
virDomainDiskHostDefCopy;
virDomainDiskHostDefFree;
@@ -214,6 +218,10 @@ virDomainDiskProtocolTransportTypeToString;
virDomainDiskProtocolTypeToString;
virDomainDiskRemove;
virDomainDiskRemoveByName;
+virDomainDiskSetDriver;
+virDomainDiskSetFormat;
+virDomainDiskSetSource;
+virDomainDiskSetType;
virDomainDiskSourceIsBlockType;
virDomainDiskTypeFromString;
virDomainDiskTypeToString;
--
1.8.5.3