util: storage: Add variables for node names into virStorageSource

'nodeformat' should be used for strings which describe the storage
format object, and 'nodebacking' for the actual storage object itself.
This commit is contained in:
Peter Krempa 2017-02-22 16:20:00 +01:00
parent ad36f3853b
commit cbc6d53513
3 changed files with 51 additions and 0 deletions

View File

@ -2509,6 +2509,7 @@ virStorageNetProtocolTypeToString;
virStorageSourceBackingStoreClear;
virStorageSourceClear;
virStorageSourceCopy;
virStorageSourceFindByNodeName;
virStorageSourceFree;
virStorageSourceGetActualType;
virStorageSourceGetSecurityLabelDef;

View File

@ -2012,6 +2012,8 @@ virStorageSourceCopy(const virStorageSource *src,
VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 ||
VIR_STRDUP(ret->snapshot, src->snapshot) < 0 ||
VIR_STRDUP(ret->configFile, src->configFile) < 0 ||
VIR_STRDUP(ret->nodeformat, src->nodeformat) < 0 ||
VIR_STRDUP(ret->nodebacking, src->nodebacking) < 0 ||
VIR_STRDUP(ret->compat, src->compat) < 0)
goto error;
@ -2232,6 +2234,9 @@ virStorageSourceClear(virStorageSourcePtr def)
virStorageNetHostDefFree(def->nhosts, def->hosts);
virStorageAuthDefFree(def->auth);
VIR_FREE(def->nodebacking);
VIR_FREE(def->nodeformat);
virStorageSourceBackingStoreClear(def);
}
@ -3781,3 +3786,38 @@ virStorageSourceIsRelative(virStorageSourcePtr src)
return false;
}
/**
* virStorageSourceFindByNodeName:
* @top: backing chain top
* @nodeName: node name to find in backing chain
* @index: if provided the index in the backing chain
*
* Looks up the given storage source in the backing chain and returns the
* pointer to it. If @index is passed then it's filled by the index in the
* backing chain. On failure NULL is returned and no error is reported.
*/
virStorageSourcePtr
virStorageSourceFindByNodeName(virStorageSourcePtr top,
const char *nodeName,
unsigned int *index)
{
virStorageSourcePtr tmp;
if (index)
*index = 0;
for (tmp = top; tmp; tmp = tmp->backingStore) {
if (STREQ_NULLABLE(tmp->nodeformat, nodeName) ||
STREQ_NULLABLE(tmp->nodebacking, nodeName))
return tmp;
if (index)
(*index)++;
}
if (index)
*index = 0;
return NULL;
}

View File

@ -276,6 +276,10 @@ struct _virStorageSource {
/* Name of the child backing store recorded in metadata of the
* current file. */
char *backingStoreRaw;
/* metadata that allows identifying given storage source */
char *nodeformat; /* name of the format handler object */
char *nodebacking; /* name of the backing storage object */
};
@ -395,4 +399,10 @@ virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path);
bool virStorageSourceIsRelative(virStorageSourcePtr src);
virStorageSourcePtr
virStorageSourceFindByNodeName(virStorageSourcePtr top,
const char *nodeName,
unsigned int *index)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
#endif /* __VIR_STORAGE_FILE_H__ */