util: Add function to check if a virStorageSource is "empty"

To express empty drive we historically use storage source with empty
path. Unfortunately NBD disks may be declared without a path.

Add a helper to wrap this logic.
This commit is contained in:
Peter Krempa 2014-09-11 19:43:53 +02:00
parent 3c07693aa2
commit 5e3e991928
3 changed files with 23 additions and 0 deletions

View File

@ -1941,6 +1941,7 @@ virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourceGetSecurityLabelDef;
virStorageSourceInitChainElement;
virStorageSourceIsEmpty;
virStorageSourceIsLocalStorage;
virStorageSourceNewFromBacking;
virStorageSourcePoolDefFree;

View File

@ -1975,6 +1975,27 @@ virStorageSourceIsLocalStorage(virStorageSourcePtr src)
}
/**
* virStorageSourceIsEmpty:
*
* @src: disk source to check
*
* Returns true if the guest disk has no associated host storage source
* (such as an empty cdrom drive).
*/
bool
virStorageSourceIsEmpty(virStorageSourcePtr src)
{
if (virStorageSourceIsLocalStorage(src) && !src->path)
return true;
if (src->type == VIR_STORAGE_TYPE_NONE)
return true;
return false;
}
/**
* virStorageSourceBackingStoreClear:
*

View File

@ -353,6 +353,7 @@ void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
void virStorageSourceClear(virStorageSourcePtr def);
int virStorageSourceGetActualType(virStorageSourcePtr def);
bool virStorageSourceIsLocalStorage(virStorageSourcePtr src);
bool virStorageSourceIsEmpty(virStorageSourcePtr src);
void virStorageSourceFree(virStorageSourcePtr def);
void virStorageSourceBackingStoreClear(virStorageSourcePtr def);
virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent);