]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Allow error reporting in virDomainDiskSourceIsBlockType
authorJohn Ferlan <jferlan@redhat.com>
Sat, 18 Jul 2015 11:34:34 +0000 (07:34 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 4 Aug 2015 11:19:25 +0000 (07:19 -0400)
Rather than provide a somewhat generic error message when the API
returns false, allow the caller to supply a "report = true" option
in order to cause virReportError's to describe which of the 3 paths
that can cause failure.

Some callers don't care about what caused the failure, they just want
to have a true/false - for those, calling with report = false should
be sufficient.

src/conf/domain_conf.c
src/conf/domain_conf.h
src/lxc/lxc_cgroup.c
src/lxc/lxc_driver.c
src/qemu/qemu_command.c
src/qemu/qemu_conf.c

index 77a50c35b7f2037908307b6a694918668cac0d58..ab96354edc6aaecb588774cf353ac58e3a9b7081 100644 (file)
@@ -23995,10 +23995,16 @@ virDomainDefFindDevice(virDomainDefPtr def,
  * Return true if its source is block type, or false otherwise.
  */
 bool
-virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
+virDomainDiskSourceIsBlockType(virStorageSourcePtr src,
+                               bool report)
 {
-    if (!src->path)
+    if (!src->path) {
+        if (report)
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("source path not found for device='lun' "
+                             "using type='%d'"), src->type);
         return false;
+    }
 
     if (src->type == VIR_STORAGE_TYPE_BLOCK)
         return true;
@@ -24014,11 +24020,20 @@ virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
          * (e.g. set sgio=filtered|unfiltered for it) in libvirt.
          */
          if (src->srcpool->pooltype == VIR_STORAGE_POOL_ISCSI &&
-             src->srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT)
+             src->srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT) {
+             if (report)
+                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                _("disk device='lun' for iSCSI is not "
+                                  "supported with mode='direct'."));
              return false;
+         }
 
         return true;
     }
+    if (report)
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("disk device='lun' is only valid for block "
+                         "type disk source"));
     return false;
 }
 
index 0fe6b1a47c8fdf67b55171ffdb581d20c5075d7e..698a4d245aada382aef7c86e17b4b53676d42512 100644 (file)
@@ -3128,7 +3128,7 @@ int virDomainDefFindDevice(virDomainDefPtr def,
                            virDomainDeviceDefPtr dev,
                            bool reportError);
 
-bool virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
+bool virDomainDiskSourceIsBlockType(virStorageSourcePtr src, bool report)
     ATTRIBUTE_NONNULL(1);
 
 void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);
index 507d56759f6e6eecc57c567dd5a81041bb9fa888..e9caa3e68a26b7c16123c4a39b4c0c414cb730da 100644 (file)
@@ -382,7 +382,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
 
     VIR_DEBUG("Allowing any disk block devs");
     for (i = 0; i < def->ndisks; i++) {
-        if (!virDomainDiskSourceIsBlockType(def->disks[i]->src))
+        if (!virDomainDiskSourceIsBlockType(def->disks[i]->src, false))
             continue;
 
         if (virCgroupAllowDevicePath(cgroup,
index 81bb71186cfc9262344bb194574b57649e96f100..d8d5119843b0c0ab41e5aba7e399ce18495bbaaf 100644 (file)
@@ -4069,11 +4069,9 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (!virDomainDiskSourceIsBlockType(def->src)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Can't setup disk for non-block device"));
+    if (!virDomainDiskSourceIsBlockType(def->src, true))
         goto cleanup;
-    }
+
     src = virDomainDiskGetSource(def);
     if (src == NULL) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
index 501c7df0485908735ec7094dd090556e3f3f5df5..c8522fb81c4715256e33d75686a7e8d9d5fddde7 100644 (file)
@@ -3476,10 +3476,7 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
                                virStorageNetProtocolTypeToString(disk->src->protocol));
                 goto error;
             }
-        } else if (!virDomainDiskSourceIsBlockType(disk->src)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("disk device='lun' is only valid for block "
-                             "type disk source"));
+        } else if (!virDomainDiskSourceIsBlockType(disk->src, true)) {
             goto error;
         }
         if (disk->wwn) {
index 29049dc495ad51ba83d2061bf46a4454f0ee68ef..da26c2d80e46164754efaadc1f427f2b0923e1e2 100644 (file)
@@ -1210,7 +1210,7 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
     char *key = NULL;
     int ret = -1;
 
-    if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src))
+    if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
         return 0;
 
     qemuDriverLock(driver);
@@ -1355,7 +1355,7 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver,
     char *key = NULL;
     int ret = -1;
 
-    if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src))
+    if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src, false))
         return 0;
 
     qemuDriverLock(driver);
@@ -1443,7 +1443,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
         disk = dev->data.disk;
 
         if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
-            !virDomainDiskSourceIsBlockType(disk->src))
+            !virDomainDiskSourceIsBlockType(disk->src, false))
             return 0;
 
         path = virDomainDiskGetSource(disk);