[PATCH v2 3/3] virsh-domain: Drop support for old APIs in cmdSetmem and cmdSetmaxmem

Michal Privoznik mprivozn at redhat.com
Wed May 19 10:16:57 UTC 2021


Some of our really old APIs are missing @flags argument. We
introduced their variants with "Flags" suffix and wired some
logic into virsh to call the new variant only if necessary. This
enables virsh to talk to older daemon which may be lacking new
APIs.

However, in case of cmdSetmem() we are talking about v0.1.1
(virDomainSetMemory()) vs. v0.9.0 (virDomainSetMemoryFlags()) and
in case of cmdSetmaxmem() we are talking about v0.0.3
(virDomainSetMaxMemory()) vs v0.9.0 (virDomainSetMemoryFlags()).

Libvirt v0.9.0 was released more than 10 years ago and recently
we dropped support for RHEL-7 which has v4.5.0 (released ~3 years
ago). Thus it is not really necessary to have support in virsh
for such old daemons.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tools/virsh-domain.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 5a5215ab4c..81357d23aa 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9000,15 +9000,15 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
     bool current = vshCommandOptBool(cmd, "current");
-    unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+    unsigned int flags = VIR_DOMAIN_AFFECT_LIVE;
 
     VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
     VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
 
+    if (current)
+        flags = VIR_DOMAIN_AFFECT_CURRENT;
     if (config)
         flags |= VIR_DOMAIN_AFFECT_CONFIG;
-    if (live)
-        flags |= VIR_DOMAIN_AFFECT_LIVE;
 
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -9023,13 +9023,8 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     kibibytes = VIR_DIV_UP(bytes, 1024);
 
-    if (!current && !live && !config) {
-        if (virDomainSetMemory(dom, kibibytes) != 0)
-            goto cleanup;
-    } else {
-        if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0)
-            goto cleanup;
-    }
+    if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0)
+        goto cleanup;
 
     ret = true;
  cleanup:
@@ -9101,16 +9096,9 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     kibibytes = VIR_DIV_UP(bytes, 1024);
 
-    if (flags == 0) {
-        if (virDomainSetMaxMemory(dom, kibibytes) != 0) {
-            vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
-            goto cleanup;
-        }
-    } else {
-        if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM_MAXIMUM) < 0) {
-            vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
-            goto cleanup;
-        }
+    if (virDomainSetMemoryFlags(dom, kibibytes, flags | VIR_DOMAIN_MEM_MAXIMUM) < 0) {
+        vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
+        goto cleanup;
     }
 
     ret = true;
-- 
2.26.3




More information about the libvir-list mailing list