master - snapshot: improve validation
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0e7edd1d2438bab5d08...
Commit: 0e7edd1d2438bab5d08a8d3db47c082d9c4e0b12
Parent: 38f7fbac64ee8291776c168b32fbd39ce2706bfe
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 24 16:34:25 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Oct 25 21:58:01 2017 +0200
snapshot: improve validation
Do not allow to take snapshot of mirror/raid leg or log or metadata LV.
This was actually never supported, but user was able to create it,
and this put device stack in hardly fixable state (needs manual work).
This prevents such creation to pass.
Also improve validation when recreating snapshot volume type
from origin and COW volume.
---
WHATS_NEW | 1 +
lib/metadata/lv_manip.c | 9 +++++++++
tools/lvconvert.c | 5 +++--
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 3ba8e30..78a8052 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.176 -
===================================
+ Disallow creation of snapshot of mirror/raid subLV (was never supported).
Fix regression in more advanced vgname extraction in lvconvert (2.02.169).
Allow lvcreate to be used for caching of _tdata LV.
Avoid internal error when resizing cache type _tdata LV (not yet supported).
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index b03f9cf..4cca5a1 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -7622,11 +7622,20 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
}
if (lv_is_mirror_type(origin_lv)) {
+ if (!lv_is_mirror(origin_lv)) {
+ log_error("Snapshots of mirror subvolumes are not supported.");
+ return NULL;
+ }
log_warn("WARNING: Snapshots of mirrors can deadlock under rare device failures.");
log_warn("WARNING: Consider using the raid1 mirror type to avoid this.");
log_warn("WARNING: See global/mirror_segtype_default in lvm.conf.");
}
+ if (lv_is_raid_type(origin_lv) && !lv_is_raid(origin_lv)) {
+ log_error("Snapshots of raid subvolumes are not supported.");
+ return NULL;
+ }
+
if (vg_is_clustered(vg) && lv_is_active(origin_lv) &&
!lv_is_active_exclusive_locally(origin_lv)) {
log_error("%s must be active exclusively to"
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 02c649c..390a784 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1945,8 +1945,9 @@ static int _lvconvert_snapshot(struct cmd_context *cmd,
* LV_foo specification because this LV is not processed by process_each_lv.
*/
if ((lv_is_cache_type(org) && !lv_is_cache(org)) ||
- lv_is_thin_type(org) ||
- lv_is_mirrored(org) ||
+ (lv_is_thin_type(org) && !lv_is_thin_volume(org)) ||
+ (lv_is_mirror_type(org) && !lv_is_mirror(org)) ||
+ (lv_is_raid_type(org) && !lv_is_raid(org)) ||
lv_is_cow(org)) {
log_error("Unable to use LV %s as snapshot origin: invald LV type.",
display_lvname(lv));
6 years, 6 months
master - typo: fix invalid
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0a0cc696cafd36ee5cd...
Commit: 0a0cc696cafd36ee5cd69e15bb4502eb1be22b86
Parent: 0e7edd1d2438bab5d08a8d3db47c082d9c4e0b12
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Oct 25 19:39:25 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Oct 25 22:02:24 2017 +0200
typo: fix invalid
---
tools/lvconvert.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 390a784..aa61f73 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1949,7 +1949,7 @@ static int _lvconvert_snapshot(struct cmd_context *cmd,
(lv_is_mirror_type(org) && !lv_is_mirror(org)) ||
(lv_is_raid_type(org) && !lv_is_raid(org)) ||
lv_is_cow(org)) {
- log_error("Unable to use LV %s as snapshot origin: invald LV type.",
+ log_error("Unable to use LV %s as snapshot origin: invalid LV type.",
display_lvname(lv));
return 0;
}
6 years, 6 months
master - clean-up: Correct the comment to match the particular test case
by Jonathan Brassow
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=38f7fbac64ee8291776...
Commit: 38f7fbac64ee8291776c168b32fbd39ce2706bfe
Parent: 10c76ce35a294b3d5fc84bc8af3ff118168282d7
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Tue Oct 24 14:06:44 2017 -0500
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Tue Oct 24 14:06:44 2017 -0500
clean-up: Correct the comment to match the particular test case
---
test/shell/lvconvert-raid-status-validation.sh | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/shell/lvconvert-raid-status-validation.sh b/test/shell/lvconvert-raid-status-validation.sh
index 51c7048..b4140a9 100644
--- a/test/shell/lvconvert-raid-status-validation.sh
+++ b/test/shell/lvconvert-raid-status-validation.sh
@@ -101,9 +101,9 @@ while true; do
[ "${a[7]}" = "recover" ]
else
# Tough to tell the INVALID case,
- # Before starting sync thread: "Aa X/X recover"
+ # Before starting sync thread: "AAa X/X recover"
# from the valid case,
- # Just finished sync thread: "Aa X/X recover"
+ # Just finished sync thread: "AAa X/X recover"
[ "${a[5]}" = "AAA" ]
[ "${a[7]}" = "idle" ]
break
6 years, 6 months
master - tests:check lvconvert with /dev in vglvname
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=10c76ce35a294b3d5fc...
Commit: 10c76ce35a294b3d5fc84bc8af3ff118168282d7
Parent: ea63a38f5a883238bfdabdb3f4af5d08f4499424
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 24 15:05:13 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 24 16:16:08 2017 +0200
tests:check lvconvert with /dev in vglvname
---
test/shell/lvconvert-cache.sh | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvconvert-cache.sh b/test/shell/lvconvert-cache.sh
index df72f4f..c3742af 100644
--- a/test/shell/lvconvert-cache.sh
+++ b/test/shell/lvconvert-cache.sh
@@ -93,6 +93,12 @@ check lv_exists $vg $lv1 ${lv1}_cachepool
lvremove -f $vg
+lvcreate -L 2 -n $lv1 $vg
+lvcreate --type cache-pool -l 1 -n ${lv1}_cachepool "$DM_DEV_DIR/$vg"
+lvconvert --cache --cachepool "$DM_DEV_DIR/$vg/${lv1}_cachepool" --cachemode writeback -Zy "$DM_DEV_DIR/$vg/$lv1"
+lvremove -f $vg
+
+
lvcreate -n corigin -l 10 $vg
lvcreate -n pool -l 10 $vg
lvs -a -o +devices
@@ -124,8 +130,10 @@ invalid lvconvert --cache --cachepool $vg/$lv1
INVALID=not
# Single vg is required
$INVALID lvconvert --type cache --cachepool $vg/$lv1 --poolmetadata $vg1/$lv2 $vg/$lv3
+$INVALID lvconvert --type cache --cachepool "$DM_DEV_DIR/$vg/$lv1" --poolmetadata "$DM_DEV_DIR/$vg1/$lv2" $vg/$lv3
$INVALID lvconvert --type cache --cachepool $vg/$lv1 --poolmetadata $lv2 $vg1/$lv3
$INVALID lvconvert --type cache --cachepool $vg1/$lv1 --poolmetadata $vg2/$lv2 $vg/$lv3
+$INVALID lvconvert --type cache --cachepool $vg1/$lv1 --poolmetadata $vg2/$lv2 "$DM_DEV_DIR/$vg/$lv3"
$INVALID lvconvert --type cache-pool --poolmetadata $vg2/$lv2 $vg1/$lv1
$INVALID lvconvert --cachepool $vg1/$lv1 --poolmetadata $vg2/$lv2
6 years, 6 months
master - lvconvert: fixing extraction of vgname
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ea63a38f5a883238bfd...
Commit: ea63a38f5a883238bfdabdb3f4af5d08f4499424
Parent: dcc8f90c587be5e60f45847d7c8ffc945e78d41c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 24 14:56:42 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 24 16:16:08 2017 +0200
lvconvert: fixing extraction of vgname
Correction to function for extracting vgname out of lvconvert
parameters.
Avoid repeating some checks.
Add code to handle generic options which may provide vgname in its argument
and compare them all so they match to a single vgname (otherwise it's a
error).
Extract default (envvar) vgname only when no position nor optional vgname is
found.
Fixing regression instroduce with patchset started with commit:
1e2420bca85da9a37570871cd70192e9ae831786 (2.02.169)
---
WHATS_NEW | 1 +
tools/toollib.c | 107 +++++++++++++++++++-----------------------------------
2 files changed, 39 insertions(+), 69 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index d91900b..3ba8e30 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.176 -
===================================
+ Fix regression in more advanced vgname extraction in lvconvert (2.02.169).
Allow lvcreate to be used for caching of _tdata LV.
Avoid internal error when resizing cache type _tdata LV (not yet supported).
Show original converted names when lvconverting LV to pool volume.
diff --git a/tools/toollib.c b/tools/toollib.c
index 79829f4..7eb0bed 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -3386,18 +3386,17 @@ static int _get_arg_lvnames(struct cmd_context *cmd,
}
/*
- * This is a non-standard way of finding vgname/lvname to process. It exists
- * because an earlier form of lvconvert did not follow the standard form, and
- * came up with its own inconsistent approach.
+ * Finding vgname/lvname to process.
*
- * In this case, when the position arg is a single name, it is treated as an LV
- * name (not a VG name). This leaves the VG unknown. So, other option values,
- * or env var, must be searched for a VG name. If one of the option values
- * contains a vgname/lvname value, then the VG name is extracted and used for
- * the LV position arg. Or, if the env var has the VG name, that is used.
+ * When the position arg is a single name without any '/'
+ * it is treated as an LV name (leaving the VG unknown).
+ * Other option values, or env var, must be searched for a VG name.
+ * If one of the option values contains a vgname/lvname value,
+ * then the VG name is extracted and used for the LV position arg.
+ * Or, if the env var has the VG name, that is used.
*
* Other option values that are searched for a VG name are:
- * --thinpool, --cachepool.
+ * --thinpool, --cachepool, --poolmetadata.
*
* . command vg/lv1
* . add vg to arg_vgnames
@@ -3422,22 +3421,23 @@ static int _get_arg_lvnames(struct cmd_context *cmd,
* . add vg to arg_vgnames
* . add vg/lv2 to arg_lvnames
*/
-
static int _get_arg_lvnames_using_options(struct cmd_context *cmd,
int argc, char **argv,
struct dm_list *arg_vgnames,
struct dm_list *arg_lvnames,
struct dm_list *arg_tags)
{
+ /* Array with args which may provide vgname */
+ static const unsigned _opts_with_vgname[] = {
+ cachepool_ARG, poolmetadata_ARG, thinpool_ARG
+ };
+ unsigned i;
const char *pos_name = NULL;
const char *arg_name = NULL;
const char *pos_vgname = NULL;
const char *opt_vgname = NULL;
const char *pos_lvname = NULL;
- const char *env_vgname = NULL;
const char *use_vgname = NULL;
- char *tmp_name;
- char *split;
char *vglv;
size_t vglv_sz;
@@ -3464,76 +3464,45 @@ static int _get_arg_lvnames_using_options(struct cmd_context *cmd,
return ECMD_PROCESSED;
}
- if (*pos_name == '/') {
- if (!(pos_name = skip_dev_dir(cmd, pos_name, NULL)))
- return ECMD_FAILED;
- }
-
- if ((split = strchr(pos_name, '/'))) {
+ if (strchr(pos_name, '/')) {
/*
* This splits pos_name 'x/y' into pos_vgname 'x' and pos_lvname 'y'
* It skips repeated '/', e.g. x//y
* It also checks and fails for extra '/', e.g. x/y/z
*/
- pos_vgname = _extract_vgname(cmd, pos_name, &pos_lvname);
- } else {
+ if (!(pos_vgname = _extract_vgname(cmd, pos_name, &pos_lvname)))
+ return_0;
+ use_vgname = pos_vgname;
+ } else
pos_lvname = pos_name;
- pos_vgname = NULL;
- }
-
- if (arg_is_set(cmd, thinpool_ARG))
- arg_name = arg_str_value(cmd, thinpool_ARG, NULL);
- else if (arg_is_set(cmd, cachepool_ARG))
- arg_name = arg_str_value(cmd, cachepool_ARG, NULL);
- env_vgname = _default_vgname(cmd);
-
- if (!pos_vgname && !arg_name && !env_vgname) {
- log_error("Cannot find VG name for LV %s.", pos_lvname);
- return ECMD_FAILED;
- }
-
- if (arg_name && (split = strchr(arg_name, '/'))) {
- /* combined VG/LV */
-
- if (!(tmp_name = dm_pool_strdup(cmd->mem, arg_name))) {
- log_error("string alloc failed.");
- return ECMD_FAILED;
+ /* Go through the list of options which can provide vgname */
+ for (i = 0; i < DM_ARRAY_SIZE(_opts_with_vgname); ++i) {
+ if ((arg_name = arg_str_value(cmd, _opts_with_vgname[i], NULL)) &&
+ strchr(arg_name, '/')) {
+ /* Combined VG/LV */
+ /* Don't care about opt lvname, only extract vgname. */
+ if (!(opt_vgname = _extract_vgname(cmd, arg_name, NULL)))
+ return_0;
+ /* Compare with already known vgname */
+ if (use_vgname) {
+ if (strcmp(use_vgname, opt_vgname)) {
+ log_error("VG name mismatch from %s arg (%s) and option arg (%s).",
+ pos_vgname ? "position" : "option",
+ use_vgname, opt_vgname);
+ return ECMD_FAILED;
+ }
+ } else
+ use_vgname = opt_vgname;
}
-
- if (!(split = strchr(tmp_name, '/')))
- return ECMD_FAILED;
-
- opt_vgname = tmp_name;
- /* Don't care about opt lvname. */
- /* opt_lvname = split + 1; */
- *split = '\0';
- } else {
- /* Don't care about opt lvname. */
- /* opt_lvname = arg_name; */
- opt_vgname = NULL;
}
- if (!pos_vgname && !opt_vgname && !env_vgname) {
+ /* VG not specified as position nor as optional arg, so check for default VG */
+ if (!use_vgname && !(use_vgname = _default_vgname(cmd))) {
log_error("Cannot find VG name for LV %s.", pos_lvname);
return ECMD_FAILED;
}
- if (pos_vgname && opt_vgname && strcmp(pos_vgname, opt_vgname)) {
- log_error("VG name mismatch from position arg (%s) and option arg (%s).",
- pos_vgname, opt_vgname);
- return ECMD_FAILED;
- }
-
- if (pos_vgname)
- use_vgname = pos_vgname;
- else if (opt_vgname)
- use_vgname = opt_vgname;
- else if (env_vgname)
- use_vgname = env_vgname;
- else
- return_ECMD_FAILED;
-
if (!str_list_add(cmd->mem, arg_vgnames, dm_pool_strdup(cmd->mem, use_vgname))) {
log_error("strlist allocation failed.");
return ECMD_FAILED;
6 years, 6 months
master - fsadm: refactor resize_crypt function
by Ondrej Kozina
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=dcc8f90c587be5e60f4...
Commit: dcc8f90c587be5e60f45847d7c8ffc945e78d41c
Parent: 9916d8fa9ad82eeb63c85b1b74879c8da56f74a0
Author: Ondrej Kozina <okozina(a)redhat.com>
AuthorDate: Tue Oct 24 11:53:22 2017 +0200
Committer: Ondrej Kozina <okozina(a)redhat.com>
CommitterDate: Tue Oct 24 13:41:16 2017 +0200
fsadm: refactor resize_crypt function
split resize_crypt function in two.
a) Detect proper dm-crypt device type and count new --size
value for cryptsetup resize command.
b) Perform the resize
---
scripts/fsadm.sh | 60 ++++++++++++++++++++++++++++-------------------------
1 files changed, 32 insertions(+), 28 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 25bddba..4f402ce 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -607,16 +607,12 @@ resize_luks() {
fi
}
-#################################
-# Resize active crypt device
-# (on direct user request only)
-#################################
-resize_crypt() {
- local CRYPT_TYPE=
- local TMP=
- local SHRINK=0
+detect_crypt_device() {
+ local CRYPT_TYPE
+ local L_NEWSIZE
+ local TMP
- which $CRYPTSETUP > /dev/null 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
+ which $CRYPTSETUP > /dev/null 2>&1 || error "$CRYPTSETUP utility required to resize crypt device"
CRYPT_TYPE=$($CRYPTSETUP status $1 2> /dev/null | $GREP "type:")
@@ -624,31 +620,38 @@ resize_crypt() {
CRYPT_TYPE=${CRYPT_TYPE##*[[:space:]]}
- TMP=$NEWSIZE
+ case "$CRYPT_TYPE" in
+ LUKS[12]|PLAIN)
+ verbose "\"$1\" crypt device is type $CRYPT_TYPE"
+ ;;
+ *)
+ error "Unsupported crypt type \"$CRYPT_TYPE\""
+ esac
+ TMP=$NEWSIZE
decode_size "$2" 512
- detect_device_size
+ L_NEWSIZE=$NEWSIZE
+ NEWSIZE=$TMP
- if [ "$DEVSIZE" -gt "$NEWSIZE" ]; then
- SHRINK=1
+ if [ $((L_NEWSIZE % 512)) -ne 0 ]; then
+ error "New size is not sector alligned"
fi
- NEWSIZE=$TMP
+ CRYPT_RESIZE_BLOCKS=$NEWBLOCKCOUNT
- if [ $SHRINK -eq 1 -a -z "$3" ]; then
- return
+ if [ "$DEVSIZE" -ge "$L_NEWSIZE" ]; then
+ CRYPT_SHRINK=1
+ else
+ CRYPT_GROW=1
fi
+}
- # going to resize, drop the request flag
- unset DO_CRYPTRESIZE
-
- case "$CRYPT_TYPE" in
- LUKS[12]|PLAIN)
- dry $CRYPTSETUP resize "$1" --size $NEWBLOCKCOUNT || error "Failed to resize device $1"
- ;;
- *)
- error "Unsupported crypt type \"$CRYPT_TYPE\""
- esac
+#################################
+# Resize active crypt device
+# (on direct user request only)
+#################################
+resize_crypt() {
+ dry $CRYPTSETUP resize "$1" --size $CRYPT_RESIZE_BLOCKS || error "$CRYPTSETUP failed to resize device $1"
}
####################
@@ -664,7 +667,8 @@ resize() {
test -z "$NEWSIZE" && NEWSIZE=${DEVSIZE}b
test -n "$NEWSIZE_ORIG" || NEWSIZE_ORIG=$NEWSIZE
IFS=$NL
- test -z "$DO_CRYPTRESIZE" || resize_crypt "$VOLUME_ORIG" "$NEWSIZE_ORIG"
+ test -z "$DO_CRYPTRESIZE" || detect_crypt_device "$VOLUME_ORIG" "$NEWSIZE_ORIG"
+ test -z "$CRYPT_GROW" || resize_crypt "$VOLUME_ORIG"
case "$FSTYPE" in
"ext3"|"ext2"|"ext4") resize_ext $NEWSIZE ;;
"reiserfs") resize_reiser $NEWSIZE ;;
@@ -674,7 +678,7 @@ resize() {
resize_luks $NEWSIZE ;;
*) error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
esac || error "Resize $FSTYPE failed."
- test -z "$DO_CRYPTRESIZE" || resize_crypt "$VOLUME_ORIG" "$NEWSIZE_ORIG" do_shrink
+ test -z "$CRYPT_SHRINK" || resize_crypt "$VOLUME_ORIG"
}
####################################
6 years, 6 months
master - fsadm: rename local variables to avoid confusion
by Ondrej Kozina
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9916d8fa9ad82eeb63c...
Commit: 9916d8fa9ad82eeb63c85b1b74879c8da56f74a0
Parent: 213cea3aaa19dffef6e922e914225d21f05589f2
Author: Ondrej Kozina <okozina(a)redhat.com>
AuthorDate: Mon Oct 23 18:11:32 2017 +0200
Committer: Ondrej Kozina <okozina(a)redhat.com>
CommitterDate: Tue Oct 24 13:41:09 2017 +0200
fsadm: rename local variables to avoid confusion
---
scripts/fsadm.sh | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 3614cd2..25bddba 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -526,8 +526,8 @@ resize_xfs() {
# 1) look for LUKS device with well-known UUID format (CRYPT-LUKS[12]-<uuid>-<dmname>)
# 2) the dm-crypt device has to be on top of original device (dont't support detached LUKS headers)
detect_luks_device() {
- local _LUKS_VERSION=
- local _LUKS_UUID=
+ local _LUKS_VERSION
+ local _LUKS_UUID
CRYPT_NAME=""
CRYPT_DATA_OFFSET=""
@@ -564,9 +564,9 @@ detect_luks_device() {
# - LUKS must be active for fs resize
######################################
resize_luks() {
- local NEWFSIZE=
- local NEWCBLOCKCOUNT=
- local NAME=""
+ local L_NEWSIZE
+ local L_NEWBLOCKCOUNT
+ local NAME
local SHRINK=0
detect_luks_device
@@ -585,25 +585,25 @@ resize_luks() {
error "New size is smaller than minimum ($(((CRYPT_DATA_OFFSET + 1) * 512)) bytes) for LUKS device $VOLUME"
fi
- NEWCBLOCKCOUNT=$((NEWBLOCKCOUNT - CRYPT_DATA_OFFSET))
- NEWFSIZE=$(( NEWCBLOCKCOUNT * 512))
+ L_NEWBLOCKCOUNT=$((NEWBLOCKCOUNT - CRYPT_DATA_OFFSET))
+ L_NEWSIZE=$(( L_NEWBLOCKCOUNT * 512))
VOLUME="$DM_DEV_DIR/mapper/$NAME"
detect_device_size
- test "$DEVSIZE" -le "$NEWFSIZE" || SHRINK=1
+ test "$DEVSIZE" -le "$L_NEWSIZE" || SHRINK=1
if [ $SHRINK -eq 1 ]; then
# shrink fs on LUKS device first
- resize "$DM_DEV_DIR/mapper/$NAME" "$NEWFSIZE"b
+ resize "$DM_DEV_DIR/mapper/$NAME" "$L_NEWSIZE"b
fi
# resize LUKS device
- dry $CRYPTSETUP resize $NAME --size $NEWCBLOCKCOUNT || error "Failed to resize active LUKS device"
+ dry $CRYPTSETUP resize $NAME --size $L_NEWBLOCKCOUNT || error "Failed to resize active LUKS device"
if [ $SHRINK -eq 0 ]; then
# grow fs on top of LUKS device
- resize "$DM_DEV_DIR/mapper/$NAME" "$NEWFSIZE"b
+ resize "$DM_DEV_DIR/mapper/$NAME" "$L_NEWSIZE"b
fi
}
6 years, 6 months
master - test: add regression test for fsadm bug
by Ondrej Kozina
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=213cea3aaa19dffef6e...
Commit: 213cea3aaa19dffef6e922e914225d21f05589f2
Parent: af781897fa7d124c073c1763f47adac3d7186907
Author: Ondrej Kozina <okozina(a)redhat.com>
AuthorDate: Tue Oct 24 11:55:14 2017 +0200
Committer: Ondrej Kozina <okozina(a)redhat.com>
CommitterDate: Tue Oct 24 13:41:00 2017 +0200
test: add regression test for fsadm bug
the bug in LUKS grow/shrink decision in fsadm was
masked due to fact that default LVM2 extent size
was larger than LUKS1 default data offset for dm-crypt
mapping. The new test address this bug.
---
test/shell/fsadm-crypt.sh | 62 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/test/shell/fsadm-crypt.sh b/test/shell/fsadm-crypt.sh
index bd2c686..5104feb 100644
--- a/test/shell/fsadm-crypt.sh
+++ b/test/shell/fsadm-crypt.sh
@@ -16,7 +16,7 @@ SKIP_WITH_LVMPOLLD=1
. lib/inittest
-aux prepare_vg 1 200
+aux prepare_vg 1 300
# set to "skip" to avoid testing given fs and test warning result
# i.e. check_reiserfs=skip
@@ -188,7 +188,7 @@ create_crypt_device()
which lsblk > /dev/null || skip
check_missing cryptsetup || skip
-# Test for block sizes != 1024 (rhbz #480022)
+vgchange -s 128k
lvcreate -n $lv1 -L25M $vg
lvcreate -n ${lv1}bar -L35M $vg
lvcreate -n ${lv1}plain -L35M $vg
@@ -217,6 +217,15 @@ test_ext2_resize() {
fscheck_ext3 "$3"
}
+test_ext2_small_shrink() {
+ mkfs.ext2 "$3"
+
+ lvresize -L-1 -r $1
+ lvresize -L-1 -r $1
+
+ fscheck_ext3 "$3"
+}
+
test_ext3_resize() {
mkfs.ext3 -b4096 -j "$3"
@@ -237,6 +246,15 @@ test_ext3_resize() {
umount "$mount_dir"
}
+test_ext3_small_shrink() {
+ mkfs.ext3 "$3"
+
+ lvresize -L-1 -r $1
+ lvresize -L-1 -r $1
+
+ fscheck_ext3 "$3"
+}
+
test_xfs_resize() {
mkfs.xfs -l internal,size=1000b -f "$3"
@@ -252,6 +270,13 @@ test_xfs_resize() {
fscheck_xfs "$3"
}
+test_xfs_small_shrink() {
+ mkfs.xfs -l internal,size=1000b -f "$3"
+
+ not lvresize -L-1 -r $1
+ fscheck_xfs "$3"
+}
+
test_reiserfs_resize() {
mkfs.reiserfs -s 513 -f "$3"
@@ -267,6 +292,15 @@ test_reiserfs_resize() {
fscheck_reiserfs "$3"
}
+test_reiserfs_small_shrink() {
+ mkfs.reiserfs -s 513 -f "$3"
+
+ lvresize -L-1 -r $1
+ lvresize -L-1 -r $1
+
+ fscheck_reiserfs "$3"
+}
+
# $1 LVM backend (vg/lv name)
# $2 LVM backend device (/dev/vg/lv)
# $3 active dm-crypt device (/dev/mapper/some_name )
@@ -478,6 +512,12 @@ if check_missing ext2; then
test_ext2_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
+ lvresize -f -L100M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+ test_ext2_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
+ lvresize -f -L25M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_ext2_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
@@ -496,6 +536,12 @@ if check_missing ext3; then
test_ext3_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
+ lvresize -f -L100M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+ test_ext3_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
+ lvresize -f -L25M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_ext3_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
@@ -514,6 +560,12 @@ if check_missing xfs; then
test_xfs_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
+ lvresize -f -L100M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+ test_xfs_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
+ lvresize -f -L25M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_xfs_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
@@ -532,6 +584,12 @@ if check_missing reiserfs; then
test_reiserfs_plain "$vg_lv3" "$dev_vg_lv3" "$CRYPT_DEV_PLAIN" "$CRYPT_NAME_PLAIN"
crypt_close "$CRYPT_NAME_PLAIN"
+ lvresize -f -L100M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+ test_reiserfs_small_shrink "$vg_lv" "$dev_vg_lv" "$CRYPT_DEV"
+ lvresize -f -L25M $vg_lv
+ cryptsetup resize $CRYPT_NAME
+
if [ -z "$SKIP_DETACHED" ]; then
crypt_open_detached "$dev_vg_lv3" $PWD2 "$CRYPT_NAME2" "$dev_vg_lv2"
test_reiserfs_detached "$vg_lv2" "$dev_vg_lv2" "$CRYPT_DEV2" "$CRYPT_NAME2"
6 years, 6 months
master - fsadm: fix bug in LUKS grow/shrink decision branch
by Ondrej Kozina
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=af781897fa7d124c073...
Commit: af781897fa7d124c073c1763f47adac3d7186907
Parent: 6df7917581eea9eef3cf5144a870df9207be15df
Author: Ondrej Kozina <okozina(a)redhat.com>
AuthorDate: Mon Oct 23 15:41:16 2017 +0200
Committer: Ondrej Kozina <okozina(a)redhat.com>
CommitterDate: Tue Oct 24 13:40:54 2017 +0200
fsadm: fix bug in LUKS grow/shrink decision branch
---
scripts/fsadm.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 3d0fdcd..3614cd2 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -591,7 +591,7 @@ resize_luks() {
VOLUME="$DM_DEV_DIR/mapper/$NAME"
detect_device_size
- test "$DEVSIZE" -le "$NEWSIZE" || SHRINK=1
+ test "$DEVSIZE" -le "$NEWFSIZE" || SHRINK=1
if [ $SHRINK -eq 1 ]; then
# shrink fs on LUKS device first
6 years, 6 months
master - fsadm: add luks specific error message for small devices
by Ondrej Kozina
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6df7917581eea9eef3c...
Commit: 6df7917581eea9eef3cf5144a870df9207be15df
Parent: 888dd33148563e95b2b3faac98f6c6dd5f00a60a
Author: Ondrej Kozina <okozina(a)redhat.com>
AuthorDate: Mon Oct 23 15:31:44 2017 +0200
Committer: Ondrej Kozina <okozina(a)redhat.com>
CommitterDate: Tue Oct 24 13:40:50 2017 +0200
fsadm: add luks specific error message for small devices
---
scripts/fsadm.sh | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index a68c7b8..3d0fdcd 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -581,6 +581,10 @@ resize_luks() {
error "New size is not sector alligned"
fi
+ if [ $((NEWBLOCKCOUNT - CRYPT_DATA_OFFSET)) -lt 1 ]; then
+ error "New size is smaller than minimum ($(((CRYPT_DATA_OFFSET + 1) * 512)) bytes) for LUKS device $VOLUME"
+ fi
+
NEWCBLOCKCOUNT=$((NEWBLOCKCOUNT - CRYPT_DATA_OFFSET))
NEWFSIZE=$(( NEWCBLOCKCOUNT * 512))
6 years, 6 months