]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Expose new virDomainFSTrim API
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 20 Nov 2012 17:23:20 +0000 (18:23 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 28 Nov 2012 15:15:01 +0000 (16:15 +0100)
It's exposed under domfstrim command. Although the API
doesn't support specifying mount point yet, expose it
anyway.

tools/virsh-domain.c
tools/virsh.pod

index cc47383f7dbddb6447a4fe5a94a5fdd620a0aac2..3e81e4ac86c2e43d706a4affd4e0367bd7f3d008 100644 (file)
@@ -8300,6 +8300,52 @@ cleanup:
     return ret;
 }
 
+static const vshCmdInfo info_domfstrim[] = {
+    {"help", N_("Invoke fstrim on domain's mounted filesystems.")},
+    {"desc", N_("Invoke fstrim on domain's mounted filesystems.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_domfstrim[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"minimum", VSH_OT_INT, 0, N_("Just a hint to ignore contiguous "
+                                  "free ranges smaller than this (Bytes)")},
+    {"mountpoint", VSH_OT_DATA, 0, N_("which mount point to trim")},
+    {NULL, 0, 0, NULL}
+};
+static bool
+cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom = NULL;
+    bool ret = false;
+    unsigned long long minimum = 0;
+    const char *mountPoint = NULL;
+    unsigned int flags = 0;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        goto cleanup;
+
+    if (vshCommandOptULongLong(cmd, "minimum", &minimum) < 0) {
+        vshError(ctl, _("Unable to parse integer parameter minimum"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptString(cmd, "mountpoint", &mountPoint) < 0) {
+        vshError(ctl, _("Unable to parse mountpoint parameter"));
+        goto cleanup;
+    }
+
+    if (virDomainFSTrim(dom, mountPoint, minimum, flags) < 0) {
+        vshError(ctl, _("Unable to invoke fstrim"));
+        goto cleanup;
+    }
+
+    ret = true;
+
+cleanup:
+    return ret;
+}
+
 const vshCmdDef domManagementCmds[] = {
     {"attach-device", cmdAttachDevice, opts_attach_device,
      info_attach_device, 0},
@@ -8332,6 +8378,7 @@ const vshCmdDef domManagementCmds[] = {
     {"detach-interface", cmdDetachInterface, opts_detach_interface,
      info_detach_interface, 0},
     {"domdisplay", cmdDomDisplay, opts_domdisplay, info_domdisplay, 0},
+    {"domfstrim", cmdDomFSTrim, opts_domfstrim, info_domfstrim, 0},
     {"domhostname", cmdDomHostname, opts_domhostname, info_domhostname, 0},
     {"domid", cmdDomid, opts_domid, info_domid, 0},
     {"domif-setlink", cmdDomIfSetLink, opts_domif_setlink, info_domif_setlink, 0},
index c4d505fdbf8f14c2459065a01f17e2b64b7dc1eb..353af66ec5a5657ed800676708dd6584e3188e30 100644 (file)
@@ -878,6 +878,20 @@ Output a URI which can be used to connect to the graphical display of the
 domain via VNC, SPICE or RDP. If I<--include-password> is specified, the
 SPICE channel password will be included in the URI.
 
+=item B<domfstrim> I<domain> [I<--minimum> B<bytes>]
+[I<--mountpoint mountPoint>]
+
+Issue a fstrim command on all mounted filesystems within a running
+domain. It discards blocks which are not in use by the filesystem.
+If I<--minimum> B<bytes> is specified, it tells guest kernel length
+of contiguous free range. Smaller than this may be ignored (this is
+a hint and the guest may not respect it). By increasing this value,
+the fstrim operation will complete more quickly for filesystems
+with badly fragmented free space, although not all blocks will
+be discarded.  The default value is zero, meaning "discard
+every free block". Moreover, a if user wants to trim only one mount
+point, it can be specified via optional I<--mountpoint> parameter.
+
 =item B<domhostname> I<domain>
 
 Returns the hostname of a domain, if the hypervisor makes it available.