virStorageFileIsClusterFS;
virStorageFileParseChainIndex;
virStorageFileProbeFormat;
-virStorageFileProbeFormatFromBuf;
virStorageFileResize;
virStorageIsFile;
virStorageNetHostDefClear;
virStorageSourcePoolModeTypeFromString;
virStorageSourcePoolModeTypeToString;
virStorageSourceUpdateBackingSizes;
+virStorageSourceUpdateCapacity;
virStorageSourceUpdatePhysicalSize;
virStorageTypeFromString;
virStorageTypeToString;
{
int ret = -1;
int fd = -1;
- virStorageSourcePtr meta = NULL;
struct stat sb;
- int format;
char *buf = NULL;
ssize_t len;
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
* 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;
}
{
int ret, fd = -1;
struct stat sb;
- virStorageSourcePtr meta = NULL;
char *buf = NULL;
ssize_t len = VIR_STORAGE_MAX_HEADER;
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) {
}
cleanup:
- virStorageSourceFree(meta);
VIR_FORCE_CLOSE(fd);
VIR_FREE(buf);
return ret;
}
-int
+static int
virStorageFileProbeFormatFromBuf(const char *path,
char *buf,
size_t buflen)
}
+/**
+ * @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,
# 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,
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,