]> xenbits.xensource.com Git - libvirt.git/commitdiff
virnetdev: Make virNetDevGenerateName() return 1 if no name was generated
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 8 Dec 2022 16:48:06 +0000 (17:48 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Dec 2022 07:46:39 +0000 (08:46 +0100)
A caller might be interested in the case when @ifname was already
set and it wasn't a template. In such case the
virNetDevGenerateName() does not touch the @ifname at all and
returns 0 to indicate success. Make it return 1 to distinguish
this case from the other case, in which a new name was generated.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/util/virnetdev.c

index 66cfc5d781db82d2df94152d92b7d4bc0e204158..82dbb486f288ca8d8e9941773f4098f1534892b9 100644 (file)
@@ -3595,7 +3595,9 @@ virNetDevReserveName(const char *name)
  * Note: if string pointed by @ifname is NOT a template or NULL, leave
  * it unchanged and return it directly.
  *
- * Returns 0 on success, -1 on failure.
+ * Returns: 1 if @ifname already contains a valid name,
+ *          0 on success (@ifname was generated),
+ *         -1 on failure.
  */
 int
 virNetDevGenerateName(char **ifname, virNetDevGenNameType type)
@@ -3609,7 +3611,7 @@ virNetDevGenerateName(char **ifname, virNetDevGenNameType type)
     if (*ifname &&
         (strchr(*ifname, '%') != strrchr(*ifname, '%') ||
          strstr(*ifname, "%d") == NULL)) {
-        return 0;
+        return 1;
     }
 
     if (maxIDd <= (double)INT_MAX)