[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCHv2 15/15] virsh: improve memory unit parsing



On 03/06/2012 01:34 AM, Eric Blake wrote:
The last vestige of the inaccurate 'kilobytes' when we meant 1024 is
now gone.  And virsh is now useful for setting memory in units other
than KiB.

* tools/virsh.c (cmdSetmem, cmdSetmaxmem): Use new helper routine,
allow passing bogus arguments on to hypervisor to test driver
sanity checking, and fix leak on parse error.
(cmdMemtuneGetSize): New helper.
(cmdMemtune): Use it.
* tools/virsh.pod (setmem, setmaxmem, memtune): Document this.
---

  static const vshCmdOptDef opts_memtune[] = {
      {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
      {"hard-limit", VSH_OT_INT, VSH_OFLAG_NONE,
-     N_("Max memory in kilobytes")},
+     N_("Max memory, as scaled integer (default KiB)")},
      {"soft-limit", VSH_OT_INT, VSH_OFLAG_NONE,
-     N_("Memory during contention in kilobytes")},
+     N_("Memory during contention, as scaled integer (default KiB)")},
      {"swap-hard-limit", VSH_OT_INT, VSH_OFLAG_NONE,
-     N_("Max memory plus swap in kilobytes")},
+     N_("Max memory plus swap, as scaled integer (default KiB)")},
      {"min-guarantee", VSH_OT_INT, VSH_OFLAG_NONE,
-     N_("Min guaranteed memory in kilobytes")},
+     N_("Min guaranteed memory, as scaled integer (default KiB)")},
      {"config", VSH_OT_BOOL, 0, N_("affect next boot")},
      {"live", VSH_OT_BOOL, 0, N_("affect running domain")},
      {"current", VSH_OT_BOOL, 0, N_("affect current domain")},
      {NULL, 0, 0, NULL}
  };

+static int
+cmdMemtuneGetSize(const vshCmd *cmd, const char *name, long long *value)

As this is a helper function rename it please to vshMemtuneGetSize to avoid confusion with command functions.

+{
+    int ret;
+    unsigned long long tmp;
+    const char *str;
+    char *end;
+
+    ret = vshCommandOptString(cmd, name,&str);
+    if (ret<= 0)
+        return ret;
+    if (virStrToLong_ll(str,&end, 10, value)<  0)
+        return -1;
+    if (*value<  0) {
+        *value = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+        return 1;
+    }
+    tmp = *value;
+    if (virScaleInteger(&tmp, end, 1024, LLONG_MAX)<  0)
+        return -1;
+    *value = VIR_DIV_UP(tmp, 1024);
+    return 0;
+}
+
  static bool
-cmdMemtune(vshControl * ctl, const vshCmd * cmd)
+cmdMemtune(vshControl *ctl, const vshCmd *cmd)
  {
      virDomainPtr dom;
      long long hard_limit = 0, soft_limit = 0, swap_hard_limit = 0;

ACK with the name change.

Peter


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]