ssize_t max_len,
char **buf);
+typedef const char *
+(*virStorageFileBackendGetUniqueIdentifier)(virStorageSourcePtr src);
virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
virStorageFileBackendInit backendInit;
virStorageFileBackendDeinit backendDeinit;
virStorageFileBackendReadHeader storageFileReadHeader;
+ virStorageFileBackendGetUniqueIdentifier storageFileGetUniqueIdentifier;
/* The following group of callbacks is expected to set errno
* and return -1 on error. No libvirt error shall be reported */
};
+typedef struct _virStorageFileBackendFsPriv virStorageFileBackendFsPriv;
+typedef virStorageFileBackendFsPriv *virStorageFileBackendFsPrivPtr;
+
+struct _virStorageFileBackendFsPriv {
+ char *canonpath; /* unique file identifier (canonical path) */
+};
+
+
static void
virStorageFileBackendFileDeinit(virStorageSourcePtr src)
{
virStorageTypeToString(virStorageSourceGetActualType(src)),
src->path);
+ virStorageFileBackendFsPrivPtr priv = src->drv->priv;
+
+ VIR_FREE(priv->canonpath);
+ VIR_FREE(priv);
}
static int
virStorageFileBackendFileInit(virStorageSourcePtr src)
{
+ virStorageFileBackendFsPrivPtr priv = NULL;
+
VIR_DEBUG("initializing FS storage file %p (%s:%s)", src,
virStorageTypeToString(virStorageSourceGetActualType(src)),
src->path);
+ if (VIR_ALLOC(priv) < 0)
+ return -1;
+
+ src->drv->priv = priv;
+
return 0;
}
}
+static const char *
+virStorageFileBackendFileGetUniqueIdentifier(virStorageSourcePtr src)
+{
+ virStorageFileBackendFsPrivPtr priv = src->drv->priv;
+
+ if (!priv->canonpath) {
+ if (!(priv->canonpath = canonicalize_file_name(src->path))) {
+ virReportSystemError(errno, _("can't canonicalize path '%s'"),
+ src->path);
+ return NULL;
+ }
+ }
+
+ return priv->canonpath;
+}
+
+
virStorageFileBackend virStorageFileBackendFile = {
.type = VIR_STORAGE_TYPE_FILE,
.storageFileUnlink = virStorageFileBackendFileUnlink,
.storageFileStat = virStorageFileBackendFileStat,
.storageFileReadHeader = virStorageFileBackendFileReadHeader,
+
+ .storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
};
.storageFileStat = virStorageFileBackendFileStat,
.storageFileReadHeader = virStorageFileBackendFileReadHeader,
+
+ .storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
};
+virStorageFileBackend virStorageFileBackendDir = {
+ .type = VIR_STORAGE_TYPE_DIR,
+
+ .backendInit = virStorageFileBackendFileInit,
+ .backendDeinit = virStorageFileBackendFileDeinit,
+
+ .storageFileGetUniqueIdentifier = virStorageFileBackendFileGetUniqueIdentifier,
+};
+
#endif /* WITH_STORAGE_FS */
return ret;
}
+
+
+/*
+ * virStorageFileGetUniqueIdentifier: Get a unique string describing the volume
+ *
+ * @src: file structure pointing to the file
+ *
+ * Returns a string uniquely describing a single volume (canonical path).
+ * The string shall not be freed and is valid until the storage file is
+ * deinitialized. Returns NULL on error and sets a libvirt error code */
+const char *
+virStorageFileGetUniqueIdentifier(virStorageSourcePtr src)
+{
+ if (!virStorageFileIsInitialized(src)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("storage file backend not initialized"));
+ return NULL;
+ }
+
+ if (!src->drv->backend->storageFileGetUniqueIdentifier) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unique storage file identifier not implemented for "
+ "storage type %s (protocol: %s)'"),
+ virStorageTypeToString(src->type),
+ virStorageNetProtocolTypeToString(src->protocol));
+ return NULL;
+ }
+
+ return src->drv->backend->storageFileGetUniqueIdentifier(src);
+}