]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: expose probe for non-local storage
authorEric Blake <eblake@redhat.com>
Wed, 9 Apr 2014 22:08:42 +0000 (16:08 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 10 Apr 2014 22:37:01 +0000 (16:37 -0600)
Deciding if a user string represents a local file instead of a
network path is an operation worth exposing directly, particularly
since the next patch will be removing a redundant variable that
was caching the information.

* src/util/virstoragefile.h (virStorageIsFile): New declaration.
* src/util/virstoragefile.c (virBackingStoreIsFile): Rename...
(virStorageIsFile): ...export, and allow NULL input.
(virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataRecurse, virStorageFileGetMetadata):
Update callers.
* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Use it.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/libvirt_private.syms (virstoragefile.h): Export function.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/conf/domain_conf.c
src/libvirt_private.syms
src/storage/storage_backend_fs.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 1c4f9d2a22f02c93f73a6690d07161b56feb4ca2..726c8bad04e98b423b1f737d377d124877df399d 100644 (file)
@@ -18565,7 +18565,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
         goto cleanup;
 
     tmp = disk->backingChain;
-    while (tmp && tmp->backingStoreIsFile) {
+    while (tmp && virStorageIsFile(tmp->backingStore)) {
         if (!ignoreOpenFailure && !tmp->backingMeta) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unable to visit backing chain file %s"),
index 9c189dc2a9fc1d016194ec68f96fbb5e6faf44ec..cd4333548dc7ddc2e38cb7ceeae3a0603c45ef4c 100644 (file)
@@ -1833,6 +1833,7 @@ virStorageFileIsClusterFS;
 virStorageFileProbeFormat;
 virStorageFileProbeFormatFromBuf;
 virStorageFileResize;
+virStorageIsFile;
 virStorageNetHostDefClear;
 virStorageNetHostDefCopy;
 virStorageNetHostDefFree;
index bb203851fc4b4f3718de6b16b8659e8f7bb12f3e..5730e3beeec99914697935730ea65f6076bef660 100644 (file)
@@ -118,7 +118,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
         *backingStore = meta->backingStore;
         meta->backingStore = NULL;
         if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO &&
-            meta->backingStoreIsFile) {
+            virStorageIsFile(*backingStore)) {
             if ((ret = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) {
                 /* If the backing file is currently unavailable, only log an error,
                  * but continue. Returning -1 here would disable the whole storage
index 2349607ac70c9b154541cc88a7429a9f326b8691..c647a14ef35012c9a1cc04f7362b749d34f06368 100644 (file)
@@ -688,11 +688,17 @@ virStorageFileMatchesVersion(int format,
     return false;
 }
 
-static bool
-virBackingStoreIsFile(const char *backing)
+bool
+virStorageIsFile(const char *backing)
 {
-    char *colon = strchr(backing, ':');
-    char *slash = strchr(backing, '/');
+    char *colon;
+    char *slash;
+
+    if (!backing)
+        return false;
+
+    colon = strchr(backing, ':');
+    slash = strchr(backing, '/');
 
     /* Reject anything that looks like a protocol (such as nbd: or
      * rbd:); if someone really does want a relative file name that
@@ -866,7 +872,7 @@ virStorageFileGetMetadataInternal(const char *path,
                 VIR_FREE(backing);
                 goto cleanup;
             }
-            if (virBackingStoreIsFile(backing)) {
+            if (virStorageIsFile(backing)) {
                 meta->backingStoreIsFile = true;
                 meta->backingStoreRaw = meta->backingStore;
                 meta->backingStore = NULL;
@@ -1146,7 +1152,7 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
     if (virHashAddEntry(cycle, canonPath, (void *)1) < 0)
         return -1;
 
-    if (virBackingStoreIsFile(path)) {
+    if (virStorageIsFile(path)) {
         if ((fd = virFileOpenAs(canonPath, O_RDONLY, 0, uid, gid, 0)) < 0) {
             virReportSystemError(-fd, _("Failed to open file '%s'"), path);
             return -1;
@@ -1235,7 +1241,7 @@ virStorageFileGetMetadata(const char *path, int format,
     if (!cycle)
         return NULL;
 
-    if (virBackingStoreIsFile(path)) {
+    if (virStorageIsFile(path)) {
         if (!(canonPath = canonicalize_file_name(path))) {
             virReportSystemError(errno, _("unable to resolve '%s'"), path);
             goto cleanup;
index 41921406a3d4d35d5e6787144ed3079ca9005d46..6c08c3115c1b79cc45a7dd9ff93267ee24fbfecb 100644 (file)
@@ -315,6 +315,7 @@ int virStorageFileResize(const char *path,
                          bool pre_allocate);
 
 int virStorageFileIsClusterFS(const char *path);
+bool virStorageIsFile(const char *path);
 
 int virStorageFileGetLVMKey(const char *path,
                             char **key);