mirror of https://gitee.com/openkylin/libvirt.git
util: storage: Store backing store format in virStorageSource
We store the backing file string in the structure so we should also store the format so that callers can be simplified. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
35d1f5bd14
commit
62539c5f7d
|
@ -935,15 +935,11 @@ virStorageFileGetEncryptionPayloadOffset(const struct FileEncryptionInfo *info,
|
||||||
static int
|
static int
|
||||||
virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
|
virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
|
||||||
char *buf,
|
char *buf,
|
||||||
size_t len,
|
size_t len)
|
||||||
int *backingFormat)
|
|
||||||
{
|
{
|
||||||
int dummy;
|
int format;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!backingFormat)
|
|
||||||
backingFormat = &dummy;
|
|
||||||
|
|
||||||
VIR_DEBUG("path=%s, buf=%p, len=%zu, meta->format=%d",
|
VIR_DEBUG("path=%s, buf=%p, len=%zu, meta->format=%d",
|
||||||
meta->path, buf, len, meta->format);
|
meta->path, buf, len, meta->format);
|
||||||
|
|
||||||
|
@ -1009,8 +1005,10 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
|
||||||
VIR_FREE(meta->backingStoreRaw);
|
VIR_FREE(meta->backingStoreRaw);
|
||||||
if (fileTypeInfo[meta->format].getBackingStore != NULL) {
|
if (fileTypeInfo[meta->format].getBackingStore != NULL) {
|
||||||
int store = fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw,
|
int store = fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw,
|
||||||
backingFormat,
|
&format,
|
||||||
buf, len);
|
buf, len);
|
||||||
|
meta->backingStoreRawFormat = format;
|
||||||
|
|
||||||
if (store == BACKING_STORE_INVALID)
|
if (store == BACKING_STORE_INVALID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -1135,20 +1133,18 @@ virStorageFileGetMetadataFromBuf(const char *path,
|
||||||
int *backingFormat)
|
int *backingFormat)
|
||||||
{
|
{
|
||||||
virStorageSourcePtr ret = NULL;
|
virStorageSourcePtr ret = NULL;
|
||||||
int dummy;
|
|
||||||
|
|
||||||
if (!backingFormat)
|
|
||||||
backingFormat = &dummy;
|
|
||||||
|
|
||||||
if (!(ret = virStorageFileMetadataNew(path, format)))
|
if (!(ret = virStorageFileMetadataNew(path, format)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virStorageFileGetMetadataInternal(ret, buf, len,
|
if (virStorageFileGetMetadataInternal(ret, buf, len) < 0) {
|
||||||
backingFormat) < 0) {
|
|
||||||
virObjectUnref(ret);
|
virObjectUnref(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (backingFormat)
|
||||||
|
*backingFormat = ret->backingStoreRawFormat;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1211,9 +1207,12 @@ virStorageFileGetMetadataFromFD(const char *path,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageFileGetMetadataInternal(meta, buf, len, backingFormat) < 0)
|
if (virStorageFileGetMetadataInternal(meta, buf, len) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (backingFormat)
|
||||||
|
*backingFormat = meta->backingStoreRawFormat;
|
||||||
|
|
||||||
if (S_ISREG(sb.st_mode))
|
if (S_ISREG(sb.st_mode))
|
||||||
meta->type = VIR_STORAGE_TYPE_FILE;
|
meta->type = VIR_STORAGE_TYPE_FILE;
|
||||||
else if (S_ISBLK(sb.st_mode))
|
else if (S_ISBLK(sb.st_mode))
|
||||||
|
@ -2293,6 +2292,7 @@ virStorageSourceCopy(const virStorageSource *src,
|
||||||
def->volume = g_strdup(src->volume);
|
def->volume = g_strdup(src->volume);
|
||||||
def->relPath = g_strdup(src->relPath);
|
def->relPath = g_strdup(src->relPath);
|
||||||
def->backingStoreRaw = g_strdup(src->backingStoreRaw);
|
def->backingStoreRaw = g_strdup(src->backingStoreRaw);
|
||||||
|
def->backingStoreRawFormat = src->backingStoreRawFormat;
|
||||||
def->externalDataStoreRaw = g_strdup(src->externalDataStoreRaw);
|
def->externalDataStoreRaw = g_strdup(src->externalDataStoreRaw);
|
||||||
def->snapshot = g_strdup(src->snapshot);
|
def->snapshot = g_strdup(src->snapshot);
|
||||||
def->configFile = g_strdup(src->configFile);
|
def->configFile = g_strdup(src->configFile);
|
||||||
|
@ -5000,7 +5000,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
||||||
unsigned int depth)
|
unsigned int depth)
|
||||||
{
|
{
|
||||||
size_t headerLen;
|
size_t headerLen;
|
||||||
int backingFormat;
|
|
||||||
int rv;
|
int rv;
|
||||||
g_autofree char *buf = NULL;
|
g_autofree char *buf = NULL;
|
||||||
g_autoptr(virStorageSource) backingStore = NULL;
|
g_autoptr(virStorageSource) backingStore = NULL;
|
||||||
|
@ -5018,7 +5017,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
||||||
&buf, &headerLen, cycle) < 0)
|
&buf, &headerLen, cycle) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStorageFileGetMetadataInternal(src, buf, headerLen, &backingFormat) < 0)
|
if (virStorageFileGetMetadataInternal(src, buf, headerLen) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (src->backingStoreRaw) {
|
if (src->backingStoreRaw) {
|
||||||
|
@ -5029,7 +5028,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
||||||
if (rv == 1)
|
if (rv == 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
backingStore->format = backingFormat;
|
backingStore->format = src->backingStoreRawFormat;
|
||||||
|
|
||||||
if (backingStore->format == VIR_STORAGE_FILE_AUTO) {
|
if (backingStore->format == VIR_STORAGE_FILE_AUTO) {
|
||||||
/* Assuming the backing store to be raw can lead to failures. We do
|
/* Assuming the backing store to be raw can lead to failures. We do
|
||||||
|
@ -5180,7 +5179,7 @@ virStorageFileGetBackingStoreStr(virStorageSourcePtr src,
|
||||||
if (!(tmp = virStorageSourceCopy(src, false)))
|
if (!(tmp = virStorageSourceCopy(src, false)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0)
|
if (virStorageFileGetMetadataInternal(tmp, buf, headerLen) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*backing = g_steal_pointer(&tmp->backingStoreRaw);
|
*backing = g_steal_pointer(&tmp->backingStoreRaw);
|
||||||
|
|
|
@ -330,6 +330,7 @@ struct _virStorageSource {
|
||||||
/* Name of the child backing store recorded in metadata of the
|
/* Name of the child backing store recorded in metadata of the
|
||||||
* current file. */
|
* current file. */
|
||||||
char *backingStoreRaw;
|
char *backingStoreRaw;
|
||||||
|
virStorageFileFormat backingStoreRawFormat;
|
||||||
/* Name of the child data file recorded in metadata of the current file. */
|
/* Name of the child data file recorded in metadata of the current file. */
|
||||||
char *externalDataStoreRaw;
|
char *externalDataStoreRaw;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue