mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
util: Introduce virStorageSourceUpdateCapacity
Instead of having duplicated code in qemuStorageLimitsRefresh and virStorageBackendUpdateVolTargetInfo to get capacity specific data about the storage backing source or volume -- create a common API to handle the details for both. As a side effect, virStorageFileProbeFormatFromBuf returns to being a local/static helper to virstoragefile.c For the QEMU code - if the probe is done, then the format is saved so as to avoid future such probes. For the storage backend code, there is no need to deal with the probe since we cannot call the new API if target->format == NONE. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
3039ec962e
commit
9d734b60a7
@ -2425,7 +2425,6 @@ virStorageFileGetSCSIKey;
|
||||
virStorageFileIsClusterFS;
|
||||
virStorageFileParseChainIndex;
|
||||
virStorageFileProbeFormat;
|
||||
virStorageFileProbeFormatFromBuf;
|
||||
virStorageFileResize;
|
||||
virStorageIsFile;
|
||||
virStorageNetHostDefClear;
|
||||
@ -2451,6 +2450,7 @@ virStorageSourcePoolDefFree;
|
||||
virStorageSourcePoolModeTypeFromString;
|
||||
virStorageSourcePoolModeTypeToString;
|
||||
virStorageSourceUpdateBackingSizes;
|
||||
virStorageSourceUpdateCapacity;
|
||||
virStorageSourceUpdatePhysicalSize;
|
||||
virStorageTypeFromString;
|
||||
virStorageTypeToString;
|
||||
|
@ -11667,9 +11667,7 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
|
||||
{
|
||||
int ret = -1;
|
||||
int fd = -1;
|
||||
virStorageSourcePtr meta = NULL;
|
||||
struct stat sb;
|
||||
int format;
|
||||
char *buf = NULL;
|
||||
ssize_t len;
|
||||
|
||||
@ -11691,27 +11689,8 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
|
||||
if (virStorageSourceUpdateBackingSizes(src, fd, &sb) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Raw files: capacity is physical size. For all other files: if
|
||||
* the metadata has a capacity, use that, otherwise fall back to
|
||||
* physical size. */
|
||||
if (!(format = src->format)) {
|
||||
if (!cfg->allowDiskFormatProbing) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("no disk format for %s and probing is disabled"),
|
||||
src->path);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((format = virStorageFileProbeFormatFromBuf(src->path,
|
||||
buf, len)) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
if (format == VIR_STORAGE_FILE_RAW)
|
||||
src->capacity = src->physical;
|
||||
else if ((meta = virStorageFileGetMetadataFromBuf(src->path, buf,
|
||||
len, format, NULL)))
|
||||
src->capacity = meta->capacity ? meta->capacity : src->physical;
|
||||
else
|
||||
if (virStorageSourceUpdateCapacity(src, buf, len,
|
||||
cfg->allowDiskFormatProbing) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* If guest is not using raw disk format and is on a host block
|
||||
@ -11719,14 +11698,14 @@ qemuStorageLimitsRefresh(virQEMUDriverPtr driver,
|
||||
* query the highest allocated extent from QEMU
|
||||
*/
|
||||
if (virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_BLOCK &&
|
||||
format != VIR_STORAGE_FILE_RAW &&
|
||||
src->format != VIR_STORAGE_FILE_RAW &&
|
||||
S_ISBLK(sb.st_mode))
|
||||
src->allocation = 0;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(buf);
|
||||
virStorageSourceFree(meta);
|
||||
qemuDomainStorageCloseStat(src, &fd);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1884,7 +1884,6 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
|
||||
{
|
||||
int ret, fd = -1;
|
||||
struct stat sb;
|
||||
virStorageSourcePtr meta = NULL;
|
||||
char *buf = NULL;
|
||||
ssize_t len = VIR_STORAGE_MAX_HEADER;
|
||||
|
||||
@ -1929,14 +1928,10 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(meta = virStorageFileGetMetadataFromBuf(target->path, buf, len, target->format,
|
||||
NULL))) {
|
||||
if (virStorageSourceUpdateCapacity(target, buf, len, false) < 0) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (meta->capacity)
|
||||
target->capacity = meta->capacity;
|
||||
}
|
||||
|
||||
if (withBlockVolFormat) {
|
||||
@ -1946,7 +1941,6 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
|
||||
}
|
||||
|
||||
cleanup:
|
||||
virStorageSourceFree(meta);
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
VIR_FREE(buf);
|
||||
return ret;
|
||||
|
@ -797,7 +797,7 @@ virStorageIsRelative(const char *backing)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
static int
|
||||
virStorageFileProbeFormatFromBuf(const char *path,
|
||||
char *buf,
|
||||
size_t buflen)
|
||||
@ -3293,6 +3293,61 @@ virStorageSourceUpdateBackingSizes(virStorageSourcePtr src,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @src: disk source definition structure
|
||||
* @buf: buffer to the storage file header
|
||||
* @len: length of the storage file header
|
||||
* @probe: allow probe
|
||||
*
|
||||
* Update the storage @src capacity. This may involve probing the storage
|
||||
* @src in order to "see" if we can recognize what exists.
|
||||
*
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
virStorageSourceUpdateCapacity(virStorageSourcePtr src,
|
||||
char *buf,
|
||||
ssize_t len,
|
||||
bool probe)
|
||||
{
|
||||
int ret = -1;
|
||||
virStorageSourcePtr meta = NULL;
|
||||
int format = src->format;
|
||||
|
||||
/* Raw files: capacity is physical size. For all other files: if
|
||||
* the metadata has a capacity, use that, otherwise fall back to
|
||||
* physical size. */
|
||||
if (format == VIR_STORAGE_FILE_NONE) {
|
||||
if (!probe) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("no disk format for %s and probing is disabled"),
|
||||
src->path);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((format = virStorageFileProbeFormatFromBuf(src->path,
|
||||
buf, len)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
src->format = format;
|
||||
}
|
||||
|
||||
if (format == VIR_STORAGE_FILE_RAW)
|
||||
src->capacity = src->physical;
|
||||
else if ((meta = virStorageFileGetMetadataFromBuf(src->path, buf,
|
||||
len, format, NULL)))
|
||||
src->capacity = meta->capacity ? meta->capacity : src->physical;
|
||||
else
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virStorageSourceFree(meta);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
virStorageFileCanonicalizeFormatPath(char **components,
|
||||
size_t ncomponents,
|
||||
|
@ -284,9 +284,6 @@ struct _virStorageSource {
|
||||
# endif
|
||||
|
||||
int virStorageFileProbeFormat(const char *path, uid_t uid, gid_t gid);
|
||||
int virStorageFileProbeFormatFromBuf(const char *path,
|
||||
char *buf,
|
||||
size_t buflen);
|
||||
|
||||
int virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
|
||||
char *buf,
|
||||
@ -361,6 +358,9 @@ int virStorageSourceUpdatePhysicalSize(virStorageSourcePtr src,
|
||||
int fd, struct stat const *sb);
|
||||
int virStorageSourceUpdateBackingSizes(virStorageSourcePtr src,
|
||||
int fd, struct stat const *sb);
|
||||
int virStorageSourceUpdateCapacity(virStorageSourcePtr src,
|
||||
char *buf, ssize_t len,
|
||||
bool probe);
|
||||
|
||||
virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent);
|
||||
virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src,
|
||||
|
Loading…
x
Reference in New Issue
Block a user