When virStoragePoolGetAutostart(), virNetworkGetAutostart(), or
virNodeDeviceGetAutostart() fails, the respective info commands
report "no autostart". This is incorrect: the API failure means
we cannot determine the autostart state, not that autostart is
disabled.

The persistent field in the same functions already correctly
reports "unknown" on API failure. Apply the same pattern to the
autostart field for consistency and correctness.

Signed-off-by: Lucas Amaral <[email protected]>
---
Found by code audit. The inconsistency dates back to c2160b137d
(Jun 2010), which introduced both the "Persistent" and "Autostart"
fields for pool-info. The persistent field used _("unknown") on
failure while the autostart field used _("no autostart") — the
mismatch was then copied into net-info, pool-list, net-list, and
nodedev-info as those were added.

All 5 instances across 3 files (virsh-pool.c, virsh-network.c,
virsh-nodedev.c) are fixed in this patch.

Tested on CentOS Stream 9 — full test suite passes (307 OK,
1 Expected Fail, 0 Fail).

 tools/virsh-network.c | 4 ++--
 tools/virsh-nodedev.c | 2 +-
 tools/virsh-pool.c    | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 2e9613e01b..eb7de3da85 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -715,7 +715,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%-15s %s\n", _("Persistent:"), persistent ? _("yes") : 
_("no"));
 
     if (virNetworkGetAutostart(network, &autostart) < 0)
-        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart"));
+        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("unknown"));
     else
         vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : 
_("no"));
 
@@ -1055,7 +1055,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd 
G_GNUC_UNUSED)
 
         if (optTable) {
             if (virNetworkGetAutostart(network, &is_autostart) < 0)
-                autostartStr = _("no autostart");
+                autostartStr = _("unknown");
             else
                 autostartStr = is_autostart ? _("yes") : _("no");
 
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 2ce0c1411f..e78fc24897 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -1245,7 +1245,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
     vshPrint(ctl, "%-15s %s\n", _("Persistent:"),
              virNodeDeviceIsPersistent(device) ? _("yes") : _("no"));
     if (virNodeDeviceGetAutostart(device, &autostart) < 0)
-        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart"));
+        vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("unknown"));
     else
         vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") : 
_("no"));
 
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 2010ef1356..2db2cf6893 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -1204,7 +1204,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd 
G_GNUC_UNUSED)
 
         /* Retrieve the autostart status of the pool */
         if (virStoragePoolGetAutostart(list->pools[i], &autostart) < 0)
-            poolInfoTexts[i].autostart = g_strdup(_("no autostart"));
+            poolInfoTexts[i].autostart = g_strdup(_("unknown"));
         else
             poolInfoTexts[i].autostart = g_strdup(autostart ? _("yes") : 
_("no"));
 
@@ -1554,7 +1554,7 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
 
         /* Check and display whether the pool is autostarted or not */
         if (virStoragePoolGetAutostart(pool, &autostart) < 0)
-            vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("no autostart"));
+            vshPrint(ctl, "%-15s %s\n", _("Autostart:"), _("unknown"));
         else
             vshPrint(ctl, "%-15s %s\n", _("Autostart:"), autostart ? _("yes") 
: _("no"));
 
-- 
2.52.0

Reply via email to