]> xenbits.xensource.com Git - libvirt.git/commitdiff
internal: Introduce virCheckNonEmptyStringArgGoto and reuse it
authorPeter Krempa <pkrempa@redhat.com>
Tue, 23 Jun 2015 15:35:16 +0000 (17:35 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 26 Jun 2015 14:05:10 +0000 (16:05 +0200)
The helper makes sure that strings passed to APIs are non-NULL and
non-empty. This allows to drop some inlined checks where it does not
make sense.

src/internal.h
src/libvirt-domain.c
src/qemu/qemu_driver.c
src/util/virerror.h

index 7c042e0dbaaa4e20a04e26e91162b51998b050bb..db26fb077ce32abc102fadfe2198f51240883e67 100644 (file)
             goto label;                             \
         }                                           \
     } while (0)
+# define virCheckNonEmptyStringArgGoto(argname, label) \
+    do {                                               \
+        if (argname == NULL) {                         \
+            virReportInvalidNonNullArg(argname);       \
+            goto label;                                \
+        }                                              \
+        if (*argname == '\0') {                        \
+            virReportInvalidEmptyStringArg(argname);   \
+            goto label;                                \
+        }                                              \
+    } while (0)
 # define virCheckPositiveArgGoto(argname, label)    \
     do {                                            \
         if (argname <= 0) {                         \
index 4d7b88af37827efc1bed0355325ec4fd54402eee..909c264e2a41ca56877604217507492c7215f338 100644 (file)
@@ -6065,7 +6065,7 @@ virDomainBlockPeek(virDomainPtr dom,
     conn = dom->conn;
 
     virCheckReadOnlyGoto(conn->flags, error);
-    virCheckNonNullArgGoto(disk, error);
+    virCheckNonEmptyStringArgGoto(disk, error);
 
     /* Allow size == 0 as an access test. */
     if (size > 0)
@@ -6333,7 +6333,7 @@ virDomainGetBlockInfo(virDomainPtr domain, const char *disk,
         memset(info, 0, sizeof(*info));
 
     virCheckDomainReturn(domain, -1);
-    virCheckNonNullArgGoto(disk, error);
+    virCheckNonEmptyStringArgGoto(disk, error);
     virCheckNonNullArgGoto(info, error);
 
     conn = domain->conn;
index 1e3caf4a525f75270b1233f9d0d4ba2bc55819bd..6df170c0ec534fc9fa024bc8541a398c95dfb609 100644 (file)
@@ -11530,12 +11530,6 @@ qemuDomainBlockPeek(virDomainPtr dom,
     if (virDomainBlockPeekEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (!path || path[0] == '\0') {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       "%s", _("NULL or empty path"));
-        goto cleanup;
-    }
-
     /* Check the path belongs to this domain.  */
     if (!(actual = virDomainDiskPathByName(vm->def, path))) {
         virReportError(VIR_ERR_INVALID_ARG,
@@ -11821,11 +11815,6 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
     if (virDomainGetBlockInfoEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (!path || path[0] == '\0') {
-        virReportError(VIR_ERR_INVALID_ARG, "%s", _("NULL or empty path"));
-        goto cleanup;
-    }
-
     /* Technically, we only need a job if we are going to query the
      * monitor, which is only for active domains that are using
      * non-raw block devices.  But it is easier to share code if we
index ad3a9464aedee453990565e57931ec702c221048..baa2d088088508ea4ddf1248eaed4fdfed18bf94 100644 (file)
@@ -95,6 +95,17 @@ void virReportSystemErrorFull(int domcode,
                       0, 0,                                          \
                       _("%s in %s must not be NULL"),                \
                       #argname, __FUNCTION__)
+# define virReportInvalidEmptyStringArg(argname)                     \
+    virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
+                      VIR_FROM_THIS,                                 \
+                      VIR_ERR_INVALID_ARG,                           \
+                      VIR_ERR_ERROR,                                 \
+                      __FUNCTION__,                                  \
+                      #argname,                                      \
+                      NULL,                                          \
+                      0, 0,                                          \
+                      _("string %s in %s must not be empty"),        \
+                      #argname, __FUNCTION__)
 # define virReportInvalidPositiveArg(argname)                        \
     virRaiseErrorFull(__FILE__, __FUNCTION__, __LINE__,              \
                       VIR_FROM_THIS,                                 \