]> sourceware.org Git - lvm2.git/commitdiff
thin: add lvchange for discard and zero change
authorZdenek Kabelac <zkabelac@redhat.com>
Thu, 28 Jun 2012 12:52:23 +0000 (14:52 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Wed, 18 Jul 2012 12:38:34 +0000 (14:38 +0200)
Update lvchange to allow change of 'zero' flag for thinpool.
Add support for changing discard handling.

N.B.  from/to  ignore could be only changed for inactive pool.

WHATS_NEW
man/lvchange.8.in
tools/commands.h
tools/lvchange.c

index 7811b6d6ee1425121b167a0028c9f1c85a1033ab..925ae235c90ab9d5c6938c2eb0102065e2073f2e 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.97 - 
 ===============================
+  Support changing of discard and zeroing for thin pool.
   Report used discard for thin pool and volume.
   Add support for controlling discard behavior of thin pool.
   Detect features for new 1.1 thin pool target.
index bf9ef480a5fa8e5accd6a01224fc40d83e009407..beb77a86bc09947329fe9a3cc90884dbfd162a28 100644 (file)
@@ -16,6 +16,8 @@ lvchange \- change attributes of a logical volume
 .RB [ \-d | \-\-debug ]
 .RB [ \-\-deltag
 .IR Tag ]
+.RB [ \-\-discard
+.RI { ignore | nopassdown | passdown }]
 .RB [ \-\-resync ]
 .RB [ \-h | \-? | \-\-help ]
 .RB [ \-\-ignorelockingfailure ]
@@ -37,7 +39,9 @@ lvchange \- change attributes of a logical volume
 .RI { ReadAheadSectors | auto | none }]
 .RB [ \-\-refresh ]
 .RB [ \-t | \-\-test ]
-.RB [ \-v | \-\-verbose]
+.RB [ \-v | \-\-verbose ]
+.RB [ \-Z | \-\-zero
+.RI { y | n }]
 .I LogicalVolumePath
 .RI [ LogicalVolumePath ...]
 .SH DESCRIPTION
@@ -68,6 +72,9 @@ logical volumes. It's only possible to change a non-contiguous
 logical volume's allocation policy to contiguous, if all of the
 allocated physical extents are already contiguous.
 .TP
+.BR \-\-discard " {" \fIignore | \fInopassdown | \fIpassdown }
+Change discard behavior.
+.TP
 .B \-\-resync
 Forces the complete resynchronization of a mirror.  In normal
 circumstances you should not need this option because synchronization
@@ -142,6 +149,11 @@ If the logical volume is active, reload its metadata.
 This is not necessary in normal operation, but may be useful
 if something has gone wrong or if you're doing clustering
 manually without a clustered lock manager.
+.TP
+.BR \-Z ", " \-\-zero " {" \fIy | \fIn }
+Set zeroing mode for thin pool. Note: already provisioned blocks from pool
+in non-zero mode are not cleared in unwritten parts when setting zero to
+\fIy\fP.
 .SH Examples
 Changes the permission on volume lvol1 in volume group vg00 to be read-only:
 .sp
index fe7403dadaf1065e685d0504cecb0b3528e1e325..88c170ae3ceca39e38e958689139faf93a79eca8 100644 (file)
@@ -69,6 +69,7 @@ xx(lvchange,
    "\t[--deltag Tag]\n"
    "\t[-f|--force]\n"
    "\t[-h|--help]\n"
+   "\t[--discard {ignore|nopassdown|passdown}]\n"
    "\t[--ignorelockingfailure]\n"
    "\t[--ignoremonitoring]\n"
    "\t[--monitor {y|n}]\n"
@@ -84,14 +85,16 @@ xx(lvchange,
    "\t[-t|--test]\n"
    "\t[-v|--verbose]\n"
    "\t[-y|--yes]\n"
-   "\t[--version]" "\n"
+   "\t[--version]\n"
+   "\t[-Z|--zero {y|n}]\n"
    "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
 
    alloc_ARG, autobackup_ARG, activate_ARG, available_ARG, contiguous_ARG,
    force_ARG, ignorelockingfailure_ARG, ignoremonitoring_ARG, major_ARG,
    minor_ARG, monitor_ARG, noudevsync_ARG, partial_ARG, permission_ARG,
    persistent_ARG, poll_ARG, readahead_ARG, resync_ARG, refresh_ARG,
-   addtag_ARG, deltag_ARG, sysinit_ARG, test_ARG, yes_ARG)
+   addtag_ARG, deltag_ARG, sysinit_ARG, test_ARG, yes_ARG,
+   discard_ARG, zero_ARG)
 
 xx(lvconvert,
    "Change logical volume layout",
index 9054ac7855b1991516e631a8c2c876a9abe9f5af..a24d26c2df63aa9ad50bfd3273d3bf5d8bc1f42e 100644 (file)
@@ -89,6 +89,77 @@ out:
        return r;
 }
 
+static int lvchange_pool_update(struct cmd_context *cmd,
+                               struct logical_volume *lv)
+{
+       int r = 0;
+       int update = 0;
+       unsigned val;
+       thin_discard_t discard;
+
+       if (!lv_is_thin_pool(lv)) {
+               log_error("Logical volume \"%s\" is not a thinpool.", lv->name);
+               return 0;
+       }
+
+       if (arg_count(cmd, discard_ARG)) {
+               discard = arg_uint_value(cmd, discard_ARG, 0);
+               if (discard != first_seg(lv)->discard) {
+                       if (((discard == THIN_DISCARD_IGNORE) ||
+                            (first_seg(lv)->discard == THIN_DISCARD_IGNORE)) &&
+                           lv_is_active(lv))
+                               log_error("Cannot change discard state for active "
+                                         "logical volume \"%s\".", lv->name);
+                       else {
+                               first_seg(lv)->discard = discard;
+                               update++;
+                       }
+               } else
+                       log_error("Logical volume \"%s\" already uses discard %s.",
+                                 lv->name, get_pool_discard_name(discard));
+       }
+
+       if (arg_count(cmd, zero_ARG)) {
+               val = arg_uint_value(cmd, zero_ARG, 1);
+               if (val != first_seg(lv)->zero_new_blocks) {
+                       first_seg(lv)->zero_new_blocks = val;
+                       update++;
+               } else
+                       log_error("Logical volume \"%s\" already %szero new blocks.",
+                                 lv->name, val ? "" : "does not ");
+       }
+
+       if (!update)
+               return 0;
+
+       log_very_verbose("Updating logical volume \"%s\" on disk(s).", lv->name);
+       if (!vg_write(lv->vg))
+               return_0;
+
+       if (!suspend_lv_origin(cmd, lv)) {
+               log_error("Failed to update active %s/%s (deactivation is needed).",
+                         lv->vg->name, lv->name);
+               vg_revert(lv->vg);
+               goto out;
+       }
+
+       if (!vg_commit(lv->vg)) {
+               if (!resume_lv_origin(cmd, lv))
+                       stack;
+               goto_out;
+       }
+
+       if (!resume_lv_origin(cmd, lv)) {
+               log_error("Problem reactivating %s.", lv->name);
+               goto out;
+       }
+
+       r = 1;
+out:
+       backup(lv->vg);
+       return r;
+}
+
 static int lvchange_monitoring(struct cmd_context *cmd,
                               struct logical_volume *lv)
 {
@@ -545,6 +616,8 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
        if (!(lv->vg->status & LVM_WRITE) &&
            (arg_count(cmd, contiguous_ARG) || arg_count(cmd, permission_ARG) ||
             arg_count(cmd, readahead_ARG) || arg_count(cmd, persistent_ARG) ||
+            arg_count(cmd, discard_ARG) ||
+            arg_count(cmd, zero_ARG) ||
             arg_count(cmd, alloc_ARG))) {
                log_error("Only -a permitted with read-only volume "
                          "group \"%s\"", lv->vg->name);
@@ -670,6 +743,17 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
                }
        }
 
+       if (arg_count(cmd, discard_ARG) ||
+           arg_count(cmd, zero_ARG)) {
+               if (!archived && !archive(lv->vg)) {
+                       stack;
+                       return ECMD_FAILED;
+               }
+               archived = 1;
+               doit += lvchange_pool_update(cmd, lv);
+               docmds++;
+       }
+
        /* add tag */
        if (arg_count(cmd, addtag_ARG)) {
                if (!archived && !archive(lv->vg)) {
@@ -747,7 +831,9 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
                arg_count(cmd, contiguous_ARG) || arg_count(cmd, permission_ARG) ||
                arg_count(cmd, readahead_ARG) || arg_count(cmd, persistent_ARG) ||
                arg_count(cmd, addtag_ARG) || arg_count(cmd, deltag_ARG) ||
-               arg_count(cmd, resync_ARG) || arg_count(cmd, alloc_ARG);
+               arg_count(cmd, resync_ARG) || arg_count(cmd, alloc_ARG) ||
+               arg_count(cmd, discard_ARG) ||
+               arg_count(cmd, zero_ARG);
 
        if (!update &&
             !arg_count(cmd, activate_ARG) && !arg_count(cmd, refresh_ARG) &&
This page took 0.04696 seconds and 5 git commands to generate.