virnetdev: Make virNetDevGenerateName() return 1 if no name was generated

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>
This commit is contained in:
Michal Privoznik 2022-12-08 17:48:06 +01:00
parent 8a5a4e6dbd
commit 6cbbc71e0d

View 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)