]> xenbits.xensource.com Git - libvirt.git/commitdiff
Allow non-file disk backingStores
authorAdam Litke <agl@us.ibm.com>
Wed, 3 Nov 2010 15:50:11 +0000 (10:50 -0500)
committerEric Blake <eblake@redhat.com>
Tue, 9 Nov 2010 23:40:27 +0000 (16:40 -0700)
I am trying to use a qcow image with libvirt where the backing 'file' is a
qemu-nbd server.  Unfortunately virDomainDiskDefForeachPath() assumes that
backingStore is always a real file so something like 'nbd:0:3333' is rejected
because a file with that name cannot be accessed.  Note that I am not worried
about directly using nbd images.  That would require a new disk type with XML
markup, etc.  I only want it to be permitted as a backingStore

The following patch implements danpb's suggestion:
> I think I'm inclined to push the logic for skipping NBD one stage higher.
> I'd rather expect virStorageFileGetMetadata() to return all backing
> stores, even if not files. The virDomainDiskDefForeachPath() method
> should definitely ignore non-file backing stores though.
>
> So what I'm thinking is to extend the virStorageFileMetadata struct and
> just add a 'bool isFile' field to it. Default this field to true, unless
> you see the prefix of nbd: in which case set it to false. The
> virDomainDiskDefForeachPath() method can then skip over any backing
> store with isFile == false

Signed-off-by: Adam Litke <agl@us.ibm.com>
Cc: Daniel P. Berrange <berrange@redhat.com>
src/conf/domain_conf.c
src/util/storage_file.c
src/util/storage_file.h

index 655449c7f6aff7812b604ce2b8661d20022e5691..30c27db1f0ba30311287357df8e18be2853676e4 100644 (file)
@@ -8218,6 +8218,13 @@ int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
         depth++;
         nextpath = meta.backingStore;
 
+        /* Stop iterating if we reach a non-file backing store */
+        if (nextpath && !meta.backingStoreIsFile) {
+            VIR_DEBUG("Stopping iteration on non-file backing store: %s",
+                      nextpath);
+            break;
+        }
+
         format = meta.backingStoreFormat;
 
         if (format == VIR_STORAGE_FILE_AUTO &&
index 403b0c089276c94be0a762d0a8afa871b507edf6..f1a445a56d75fc3f87fc32defe3e3bfd7694f434 100644 (file)
@@ -503,6 +503,14 @@ virStorageFileMatchesVersion(int format,
     return true;
 }
 
+static bool
+virBackingStoreIsFile(const char *backing)
+{
+    /* Backing store is a network block device */
+    if (STRPREFIX(backing, "nbd:"))
+        return false;
+    return true;
+}
 
 static int
 virStorageFileGetMetadataFromBuf(int format,
@@ -573,8 +581,14 @@ virStorageFileGetMetadataFromBuf(int format,
         if (ret == BACKING_STORE_ERROR)
             return -1;
 
+        meta->backingStoreIsFile = false;
         if (backing != NULL) {
-            meta->backingStore = absolutePathFromBaseFile(path, backing);
+            if (virBackingStoreIsFile(backing)) {
+                meta->backingStoreIsFile = true;
+                meta->backingStore = absolutePathFromBaseFile(path, backing);
+            } else {
+                meta->backingStore = strdup(backing);
+            }
             VIR_FREE(backing);
             if (meta->backingStore == NULL) {
                 virReportOOMError();
index ba44111d99264cf89c9ff8515874c049fdc9eeab..34ece6d8efe7cd65a2ca6cb7bbe9641f4d96e44f 100644 (file)
@@ -48,6 +48,7 @@ VIR_ENUM_DECL(virStorageFileFormat);
 typedef struct _virStorageFileMetadata {
     char *backingStore;
     int backingStoreFormat;
+    bool backingStoreIsFile;
     unsigned long long capacity;
     bool encrypted;
 } virStorageFileMetadata;