]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Add TRIM algorithm to storage volume API
authorWido den Hollander <wido@widodh.nl>
Wed, 27 Jan 2016 10:20:07 +0000 (11:20 +0100)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 29 Jan 2016 16:09:14 +0000 (11:09 -0500)
This new algorithm adds support for wiping volumes using TRIM.

It does not overwrite all the data in a volume, but it tells the
backing storage pool/driver that all bytes in a volume can be
discarded.

It depends on the backing storage pool how this is handled.

A SCSI backend might send UNMAP commands to remove all data present
on a LUN.

A Ceph backend might use rbd_discard() to instruct the Ceph cluster
that all data on that RBD volume can be discarded.

Signed-off-by: Wido den Hollander <wido@widodh.nl>
include/libvirt/libvirt-storage.h
src/storage/storage_backend.c
src/storage/storage_backend_rbd.c
tools/virsh-volume.c
tools/virsh.pod

index 2c55c93e7426aeca23b8d400fb63d7032bca78e8..1a868ccddd632ecc195c675b94270dc66583fb9c 100644 (file)
@@ -4,7 +4,7 @@
  * Description: Provides APIs for the management of storage pools and volumes
  * Author: Daniel Veillard <veillard@redhat.com>
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2016 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -153,6 +153,9 @@ typedef enum {
 
     VIR_STORAGE_VOL_WIPE_ALG_RANDOM = 8, /* 1-pass random */
 
+    VIR_STORAGE_VOL_WIPE_ALG_TRIM = 9, /* 1-pass, trim all data on the
+                                          volume by using TRIM or DISCARD */
+
 # ifdef VIR_ENUM_SENTINELS
     VIR_STORAGE_VOL_WIPE_ALG_LAST
     /*
index 8fb869c0a88f20334230f23d38f8ea94a3a82a13..c07b642b24854f3ecbf05df18732e496ea740806 100644 (file)
@@ -2105,6 +2105,10 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
     case VIR_STORAGE_VOL_WIPE_ALG_RANDOM:
         alg_char = "random";
         break;
+    case VIR_STORAGE_VOL_WIPE_ALG_TRIM:
+        virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+                       _("'trim' algorithm not supported"));
+        goto cleanup;
     case VIR_STORAGE_VOL_WIPE_ALG_LAST:
         virReportError(VIR_ERR_INVALID_ARG,
                        _("unsupported algorithm %d"),
index 59a281b9c342a404b27af9b5de1a2c2c501db6b3..8a3efe9f9d969ece37898f44ae4b40295a30fb72 100644 (file)
@@ -831,6 +831,7 @@ virStorageBackendRBDVolWipe(virConnectPtr conn,
     case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7:
     case VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33:
     case VIR_STORAGE_VOL_WIPE_ALG_RANDOM:
+    case VIR_STORAGE_VOL_WIPE_ALG_TRIM:
     case VIR_STORAGE_VOL_WIPE_ALG_LAST:
         virReportError(VIR_ERR_INVALID_ARG, _("unsupported algorithm %d"),
                        algorithm);
index 661c876042df49987071f0c9e8f0a4b4db10af72..35f0cbd78e88868b316b710eb190a46fc46df569 100644 (file)
@@ -906,7 +906,7 @@ static const vshCmdOptDef opts_vol_wipe[] = {
 VIR_ENUM_DECL(virStorageVolWipeAlgorithm)
 VIR_ENUM_IMPL(virStorageVolWipeAlgorithm, VIR_STORAGE_VOL_WIPE_ALG_LAST,
               "zero", "nnsa", "dod", "bsi", "gutmann", "schneier",
-              "pfitzner7", "pfitzner33", "random");
+              "pfitzner7", "pfitzner33", "random", "trim");
 
 static bool
 cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
index e830c597dd05441498cca441b5b8ac13c561f9c7..435c64907e43bc167f92c22e00f876b2ef3b35d4 100644 (file)
@@ -3546,9 +3546,19 @@ B<Supported algorithms>
   pfitzner7  - Roy Pfitzner's 7-random-pass method: random x7.
   pfitzner33 - Roy Pfitzner's 33-random-pass method: random x33.
   random     - 1-pass pattern: random.
-
-B<Note>: The availability of algorithms may be limited by the version
-of the C<scrub> binary installed on the host.
+  trim       - 1-pass trimming the volume using TRIM or DISCARD
+
+B<Note>: The C<scrub> binary will be used to handle the 'nnsa', 'dod',
+'bsi', 'gutmann', 'schneier', 'pfitzner7' and 'pfitzner33' algorithms.
+The availability of the algorithms may be limited by the version of
+the C<scrub> binary installed on the host. The 'zero' algorithm will
+write zeroes to the entire volume. For some volumes, such as sparse
+or rbd volumes, this may result in completely filling the volume with
+zeroes making it appear to be completely full. As an alternative, the
+'trim' algorithm does not overwrite all the data in a volume, rather
+it expects the storage driver to be able to discard all bytes in a
+volume. It is up to the storage driver to handle how the discarding
+occurs. Not all storage drivers or volume types can support 'trim'.
 
 =item B<vol-dumpxml> [I<--pool> I<pool-or-uuid>] I<vol-name-or-key-or-path>