conf: accessors for common source information

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@redhat.com>
This commit is contained in:
Eric Blake 2014-03-17 11:39:57 -06:00
parent e7b0e71d92
commit 1014c34e3c
3 changed files with 90 additions and 0 deletions

View File

@ -1354,6 +1354,20 @@ error:
}
int
virDomainDiskGetType(virDomainDiskDefPtr def)
{
return def->type;
}
void
virDomainDiskSetType(virDomainDiskDefPtr def, int type)
{
def->type = type;
}
int
virDomainDiskGetActualType(virDomainDiskDefPtr def)
{
@ -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)

View File

@ -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);

View File

@ -201,6 +201,10 @@ virDomainDiskFindByBusAndDst;
virDomainDiskGeometryTransTypeFromString;
virDomainDiskGeometryTransTypeToString;
virDomainDiskGetActualType;
virDomainDiskGetDriver;
virDomainDiskGetFormat;
virDomainDiskGetSource;
virDomainDiskGetType;
virDomainDiskHostDefClear;
virDomainDiskHostDefCopy;
virDomainDiskHostDefFree;
@ -215,6 +219,10 @@ virDomainDiskProtocolTransportTypeToString;
virDomainDiskProtocolTypeToString;
virDomainDiskRemove;
virDomainDiskRemoveByName;
virDomainDiskSetDriver;
virDomainDiskSetFormat;
virDomainDiskSetSource;
virDomainDiskSetType;
virDomainDiskSourceIsBlockType;
virDomainDiskTypeFromString;
virDomainDiskTypeToString;