From cbc6d53513568c9c9613b3eaae1c8a8230fd6aab Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 22 Feb 2017 16:20:00 +0100 Subject: [PATCH] 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. --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 40 +++++++++++++++++++++++++++++++++++++++ src/util/virstoragefile.h | 10 ++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3091791f4a..010942529a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2509,6 +2509,7 @@ virStorageNetProtocolTypeToString; virStorageSourceBackingStoreClear; virStorageSourceClear; virStorageSourceCopy; +virStorageSourceFindByNodeName; virStorageSourceFree; virStorageSourceGetActualType; virStorageSourceGetSecurityLabelDef; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index c8eb26aa74..3bcb69bf62 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -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; +} diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 5f6e419117..9ebfc11081 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -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__ */ -- GitLab