main - vgimportdevices: LOCK_EX requires <sys/file.h> include
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a1a1439215f56335a06...
Commit: a1a1439215f56335a06ae5ac6ca73b5e0d734760
Parent: be124ae81027e8736106e4958bd2dfab971d6764
Author: Jory Pratt <anarchy(a)gentoo.org>
AuthorDate: Tue Feb 7 14:27:12 2023 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Feb 10 17:50:27 2023 +0100
vgimportdevices: LOCK_EX requires <sys/file.h> include
https://linux.die.net/man/2/flock
Bug: https://bugs.gentoo.org/887259
---
tools/vgimportdevices.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/vgimportdevices.c b/tools/vgimportdevices.c
index ab359d31c..07d07402a 100644
--- a/tools/vgimportdevices.c
+++ b/tools/vgimportdevices.c
@@ -15,6 +15,8 @@
#include "tools.h"
#include "lib/cache/lvmcache.h"
#include "lib/device/device_id.h"
+/* coverity[unnecessary_header] needed for MuslC */
+#include <sys/file.h>
struct vgimportdevices_params {
uint32_t added_devices;
3 months, 3 weeks
main - vgimportclone: fix non-duplicate PV with non-unique basevgname arg
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=be124ae81027e873610...
Commit: be124ae81027e8736106e4958bd2dfab971d6764
Parent: 94f77a4d8d9737fca05fb4e451678ec440c68670
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 9 17:14:19 2023 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Feb 9 17:37:22 2023 -0600
vgimportclone: fix non-duplicate PV with non-unique basevgname arg
Fix hang of vgimportclone command when:
the PV(s) being imported are not actually clones/duplicates, and
the -n vgname arg is the same as the current vgname.
(Not the intended use of the command, but it should still work.)
In this case, the old and new vgnames ended up being the same, when
the code expected they would be different. A file lock on both the
old and new vgnames is used, so when both flocks are on the same
file, the second blocks indefinitely.
Fix the new vgname to be the old name plus a numeric suffix, which
is the expected result.
---
test/shell/vgimportclone.sh | 20 ++++++++++++++++++++
tools/vgimportclone.c | 15 +++++++++++++--
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/test/shell/vgimportclone.sh b/test/shell/vgimportclone.sh
index e1b9d3832..13924c3dd 100644
--- a/test/shell/vgimportclone.sh
+++ b/test/shell/vgimportclone.sh
@@ -104,6 +104,26 @@ pvremove "$dev1"
pvremove "$dev2"
pvremove "$dev3"
+# Test importing a non-duplicate pv using the existing vg name
+vgcreate $vg1 "$dev1"
+vgimportclone -n $vg1 "$dev1"
+vgs ${vg1}1
+not vgs $vg1
+vgremove ${vg1}1
+
+# Test importing a non-duplicate pv using the existing vg name
+# Another existing VG is using the initial generated vgname with
+# the "1" suffix, so "2" is used.
+vgcreate $vg1 "$dev1"
+vgcreate ${vg1}1 "$dev2"
+vgimportclone -n $vg1 "$dev1"
+vgs ${vg1}1
+vgs ${vg1}2
+vgremove ${vg1}1
+vgremove ${vg1}2
+pvremove "$dev1"
+pvremove "$dev2"
+
# Verify that if we provide the -n|--basevgname,
# the number suffix is not added unnecessarily.
vgcreate $SHARED --metadatasize 128k A${vg1}B "$dev1"
diff --git a/tools/vgimportclone.c b/tools/vgimportclone.c
index 93fa3b18d..a6d055f7f 100644
--- a/tools/vgimportclone.c
+++ b/tools/vgimportclone.c
@@ -407,8 +407,19 @@ int vgimportclone(struct cmd_context *cmd, int argc, char **argv)
log_error("Base vg name %s is too long.", vgname);
goto out;
}
- (void) dm_strncpy(tmp_vgname, base_vgname, NAME_LEN);
- vgname_count = 0;
+ if (strcmp(vgname, vp.old_vgname)) {
+ (void) dm_strncpy(tmp_vgname, base_vgname, NAME_LEN);
+ vgname_count = 0;
+ } else {
+ /* Needed when basename matches old name, and PV is not a duplicate
+ which means old name is not found on other devs, and is not seen
+ in the vgnames search below, causing old and new names to match. */
+ if (dm_snprintf(tmp_vgname, sizeof(tmp_vgname), "%s1", vp.old_vgname) < 0) {
+ log_error("Temporary vg name %s1 is too long.", vp.old_vgname);
+ goto out;
+ }
+ vgname_count = 1;
+ }
} else {
if (dm_snprintf(base_vgname, sizeof(base_vgname), "%s", vp.old_vgname) < 0) {
log_error(INTERNAL_ERROR "Old vg name %s is too long.", vp.old_vgname);
3 months, 3 weeks
rhel-9.2.0 - udev: import previous results of blkid when in suspended state
by Marian Csontos
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=285c766877b54b24234...
Commit: 285c766877b54b24234f84c313bb5806c0dcfa21
Parent: fba3614c3ed596b99d8adf2fe6c60886db10b2c0
Author: Yu Watanabe <watanabe.yu+github(a)gmail.com>
AuthorDate: Thu Feb 2 00:28:12 2023 +0900
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Thu Feb 9 17:06:18 2023 +0100
udev: import previous results of blkid when in suspended state
Follow-up for e10f67e91728f1e576803df884049ecbd92874d0.
The commit e10f67e91728f1e576803df884049ecbd92874d0 tries to keep device
node symlinks even if the device is in the suspended state. However,
necessary properties that may previously obtained by the blkid command
were not imported at least in the .rules file. So, unless ID_FS_xyz
properties are imported by another earlier .rules file, the device node
symlinks are still lost when event is processed in the suspended state.
Let's explicitly import the necessary properties.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2158628
GHPR: https://github.com/lvmteam/lvm2/pull/105
(cherry picked from commit 94f77a4d8d9737fca05fb4e451678ec440c68670)
---
WHATS_NEW_DM | 4 ++++
udev/13-dm-disk.rules.in | 14 ++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index f676ff7e1..c129c7f8a 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,3 +1,7 @@
+Version 1.02.191 -
+=====================================
+ Import previous ID_FS_* udev records in 13-dm-disk.rules for suspended DM dev.
+
Version 1.02.187 - 10th November 2022
=====================================
Add DM_REPORT_GROUP_JSON_STD for more JSON standard compliant output format.
diff --git a/udev/13-dm-disk.rules.in b/udev/13-dm-disk.rules.in
index 5cc08121e..dca00bc01 100644
--- a/udev/13-dm-disk.rules.in
+++ b/udev/13-dm-disk.rules.in
@@ -17,12 +17,22 @@ ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}=="1", GOTO="dm_end"
SYMLINK+="disk/by-id/dm-name-$env{DM_NAME}"
ENV{DM_UUID}=="?*", SYMLINK+="disk/by-id/dm-uuid-$env{DM_UUID}"
-ENV{DM_SUSPENDED}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_link"
-ENV{DM_NOSCAN}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_link"
+ENV{DM_SUSPENDED}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_import"
+ENV{DM_NOSCAN}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_import"
ENV{DM_SUSPENDED}=="1", GOTO="dm_end"
ENV{DM_NOSCAN}=="1", GOTO="dm_watch"
(BLKID_RULE)
+GOTO="dm_link"
+
+LABEL="dm_import"
+IMPORT{db}="ID_FS_USAGE"
+IMPORT{db}="ID_FS_UUID_ENC"
+IMPORT{db}="ID_FS_LABEL_ENC"
+IMPORT{db}="ID_PART_ENTRY_NAME"
+IMPORT{db}="ID_PART_ENTRY_UUID"
+IMPORT{db}="ID_PART_ENTRY_SCHEME"
+IMPORT{db}="ID_PART_GPT_AUTO_ROOT"
LABEL="dm_link"
ENV{DM_UDEV_LOW_PRIORITY_FLAG}=="1", OPTIONS="link_priority=-100"
3 months, 3 weeks
rhel-9.2.0 - lvresize: fail early if mounted LV was renamed
by Marian Csontos
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=fba3614c3ed596b99d8...
Commit: fba3614c3ed596b99d8adf2fe6c60886db10b2c0
Parent: 7e0c2e1581225a916269edc8f04fb10e4ef5e952
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jan 26 14:00:00 2023 -0600
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Thu Feb 9 16:29:38 2023 +0100
lvresize: fail early if mounted LV was renamed
If a mounted LV is renamed, then fs resizing utilities will fail,
so detect this condition and fail the command before any changes
are made.
(cherry picked from commit 5374a44c57127cdd832a675545c1d2bbf0b3751a)
---
lib/device/filesystem.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++
lib/device/filesystem.h | 2 +
lib/metadata/lv_manip.c | 3 ++
test/shell/lvresize-fs.sh | 11 +++++
4 files changed, 126 insertions(+)
diff --git a/lib/device/filesystem.c b/lib/device/filesystem.c
index b4c43a626..db507bdda 100644
--- a/lib/device/filesystem.c
+++ b/lib/device/filesystem.c
@@ -214,6 +214,116 @@ int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
return ret;
}
+int fs_mount_state_is_misnamed(struct cmd_context *cmd, struct logical_volume *lv, char *lv_path, char *fstype)
+{
+ FILE *fp;
+ char proc_line[PATH_MAX];
+ char proc_fstype[FSTYPE_MAX];
+ char proc_devpath[1024];
+ char proc_mntpath[1024];
+ char lv_mapper_path[1024];
+ char mntent_mount_dir[1024];
+ char *dm_name;
+ struct stat st_lv;
+ struct stat stme;
+ FILE *fme = NULL;
+ struct mntent *me;
+ int renamed = 0;
+ int found_dir = 0;
+ int found_dev = 0;
+ int dev_match, dir_match;
+
+ if (stat(lv_path, &st_lv) < 0) {
+ log_error("Failed to get LV path %s", lv_path);
+ return 0;
+ }
+
+ /*
+ * If LVs have been renamed while their file systems were mounted, then
+ * inconsistencies appear in the device path and mount point info
+ * provided by getmntent and /proc/mounts. If there's any
+ * inconsistency or duplication of info for the LV name or the mount
+ * point, then give up and don't try fs resize which is likely to fail
+ * due to kernel problems where mounts reference old device names
+ * causing fs resizing tools to fail.
+ */
+
+ if (!(fme = setmntent("/etc/mtab", "r")))
+ return_0;
+
+ while ((me = getmntent(fme))) {
+ if (strcmp(me->mnt_type, fstype))
+ continue;
+ if (me->mnt_dir[0] != '/')
+ continue;
+ if (me->mnt_fsname[0] != '/')
+ continue;
+ if (stat(me->mnt_dir, &stme) < 0)
+ continue;
+ if (stme.st_dev != st_lv.st_rdev)
+ continue;
+ strncpy(mntent_mount_dir, me->mnt_dir, PATH_MAX-1);
+ }
+ endmntent(fme);
+
+ if (!(dm_name = dm_build_dm_name(cmd->mem, lv->vg->name, lv->name, NULL)))
+ return_0;
+
+ if ((dm_snprintf(lv_mapper_path, 1024, "%s/%s", dm_dir(), dm_name) < 0))
+ return_0;
+
+ if (!(fp = fopen("/proc/mounts", "r")))
+ return_0;
+
+ while (fgets(proc_line, sizeof(proc_line), fp)) {
+ if (proc_line[0] != '/')
+ continue;
+ if (sscanf(proc_line, "%s %s %s", proc_devpath, proc_mntpath, proc_fstype) != 3)
+ continue;
+ if (strcmp(fstype, proc_fstype))
+ continue;
+
+ dir_match = !strcmp(mntent_mount_dir, proc_mntpath);
+ dev_match = !strcmp(lv_mapper_path, proc_devpath);
+
+ if (dir_match)
+ found_dir++;
+ if (dev_match)
+ found_dev++;
+
+ if (dir_match != dev_match) {
+ log_error("LV %s mounted at %s may have been renamed (from %s).",
+ lv_mapper_path, proc_mntpath, proc_devpath);
+ renamed = 1;
+ }
+ }
+
+ if (fclose(fp))
+ stack;
+
+ /*
+ * Don't try resizing if:
+ * - different device names apppear for the mount point
+ * (LVs probably renamed while mounted), or
+ * - the mount point for the LV appears multiple times, or
+ * - the LV device is listed for multiple mounts.
+ */
+ if (renamed) {
+ log_error("File system resizing not supported: fs utilities do not support renamed devices.");
+ return 1;
+ }
+ /* These two are likely detected as renamed, but include checks in case. */
+ if (found_dir > 1) {
+ log_error("File system resizing not supported: %s appears more than once in /proc/mounts.", mntent_mount_dir);
+ return 1;
+ }
+ if (found_dev > 1) {
+ log_error("File system resizing not supported: %s appears more than once in /proc/mounts.", lv_mapper_path);
+ return 1;
+ }
+ return 0;
+}
+
#define FS_CMD_MAX_ARGS 16
int crypt_resize_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
diff --git a/lib/device/filesystem.h b/lib/device/filesystem.h
index fd1af0416..77eac34d0 100644
--- a/lib/device/filesystem.h
+++ b/lib/device/filesystem.h
@@ -48,4 +48,6 @@ int fs_reduce_script(struct cmd_context *cmd, struct logical_volume *lv, struct
uint64_t newsize_bytes, char *fsmode);
int crypt_resize_script(struct cmd_context *cmd, struct logical_volume *lv, struct fs_info *fsi,
uint64_t newsize_bytes_fs);
+
+int fs_mount_state_is_misnamed(struct cmd_context *cmd, struct logical_volume *lv, char *lv_path, char *fstype);
#endif
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index a2e9db2c9..25e16d41d 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -6928,6 +6928,9 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
log_error("File system not found for --resizefs or --fs options.");
goto out;
}
+ /* FS utils will fail if LVs were renamed while mounted. */
+ if (fs_mount_state_is_misnamed(cmd, lv_top, lv_path, fstype))
+ goto_out;
}
/*
diff --git a/test/shell/lvresize-fs.sh b/test/shell/lvresize-fs.sh
index 0be6911a0..f437652d6 100644
--- a/test/shell/lvresize-fs.sh
+++ b/test/shell/lvresize-fs.sh
@@ -262,6 +262,17 @@ umount "$mount_dir"
lvchange -an $vg/$lv
lvremove $vg/$lv
+# lvextend|lvreduce, ext4, active, mounted, --fs resize, renamed LV
+lvcreate -n $lv -L 256M $vg
+mkfs.ext4 "$DM_DEV_DIR/$vg/$lv"
+mount "$DM_DEV_DIR/$vg/$lv" "$mount_dir"
+lvrename $vg/$lv $vg/$lv2
+not lvextend --fs resize -L+32M $vg/$lv2
+not lvreduce --fs resize -L-32M $vg/$lv2
+umount "$mount_dir"
+lvchange -an $vg/$lv2
+lvremove $vg/$lv2
+
#
# lvextend, xfs
3 months, 3 weeks
rhel-9.2.0 - lvresize: only resize crypt when fs resize is enabled
by Marian Csontos
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7e0c2e1581225a91626...
Commit: 7e0c2e1581225a916269edc8f04fb10e4ef5e952
Parent: 380e3855fbc661eed490665cf1e3d05e985da189
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jan 19 11:36:51 2023 -0600
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Thu Feb 9 16:29:07 2023 +0100
lvresize: only resize crypt when fs resize is enabled
There were a couple of cases where lvresize, without --fs resize,
was resizing the crypt layer above the LV. Resizing the crypt
layer should only be done when fs resizing is enabled (even if the
fs is already small enough due to being independently reduced.)
Also, check the size of the crypt device to see if it's already
been reduced independently, and skip the cryptsetup resize if
it's not needed.
(cherry picked from commit 3bb55765286dc8e4f0000957d85a6b8ee2752852)
---
lib/device/filesystem.c | 12 ++++++++++++
lib/device/filesystem.h | 1 +
lib/metadata/lv_manip.c | 18 +++++++++++++++++-
test/shell/lvresize-fs-crypt.sh | 7 ++++++-
4 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/lib/device/filesystem.c b/lib/device/filesystem.c
index bdc230175..b4c43a626 100644
--- a/lib/device/filesystem.c
+++ b/lib/device/filesystem.c
@@ -106,6 +106,7 @@ int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
struct fs_info info;
FILE *fme = NULL;
struct mntent *me;
+ int fd;
int ret;
if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", lv->vg->cmd->dev_dir,
@@ -151,6 +152,17 @@ int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
log_print("File system found on crypt device %s on LV %s.",
crypt_path, display_lvname(lv));
+ if ((fd = open(crypt_path, O_RDONLY)) < 0) {
+ log_error("Failed to open crypt path %s", crypt_path);
+ return 0;
+ }
+ if (ioctl(fd, BLKGETSIZE64, &info.crypt_dev_size_bytes) < 0) {
+ log_error("Failed to get crypt device size %s", crypt_path);
+ close(fd);
+ return 0;
+ }
+ close(fd);
+
if (!fs_get_blkid(crypt_path, &info)) {
log_error("No file system info from blkid for dm-crypt device %s on LV %s.",
crypt_path, display_lvname(lv));
diff --git a/lib/device/filesystem.h b/lib/device/filesystem.h
index 7a34d2ae0..fd1af0416 100644
--- a/lib/device/filesystem.h
+++ b/lib/device/filesystem.h
@@ -25,6 +25,7 @@ struct fs_info {
uint64_t fs_last_byte; /* last byte on the device used by the fs */
uint32_t crypt_offset_bytes; /* offset in bytes of crypt data on LV */
dev_t crypt_devt; /* dm-crypt device between the LV and FS */
+ uint64_t crypt_dev_size_bytes;
unsigned nofs:1;
unsigned unmounted:1;
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index f8eae0447..a2e9db2c9 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -6397,7 +6397,23 @@ static int _fs_reduce(struct cmd_context *cmd, struct logical_volume *lv,
* but the crypt dev over the LV should be shrunk to correspond with
* the LV size, so that the FS does not see an incorrect device size.
*/
- if (!fsinfo.needs_reduce && fsinfo.needs_crypt && !test_mode()) {
+ if (!fsinfo.needs_reduce && fsinfo.needs_crypt) {
+ /* Check if the crypt device is already sufficiently reduced. */
+ if (fsinfo.crypt_dev_size_bytes <= newsize_bytes_fs) {
+ log_print("crypt device is already reduced to %llu bytes.",
+ (unsigned long long)fsinfo.crypt_dev_size_bytes);
+ ret = 1;
+ goto out;
+ }
+ if (!strcmp(lp->fsopt, "checksize")) {
+ log_error("crypt reduce is required (see --resizefs or cryptsetup resize.)");
+ ret = 0;
+ goto out;
+ }
+ if (test_mode()) {
+ ret = 1;
+ goto_out;
+ }
ret = crypt_resize_script(cmd, lv, &fsinfo, newsize_bytes_fs);
goto out;
}
diff --git a/test/shell/lvresize-fs-crypt.sh b/test/shell/lvresize-fs-crypt.sh
index 61a6de022..4bef771dc 100644
--- a/test/shell/lvresize-fs-crypt.sh
+++ b/test/shell/lvresize-fs-crypt.sh
@@ -151,7 +151,12 @@ mount /dev/mapper/$cr "$mount_dir"
# this lvresize will not resize the fs (which is already reduced
# to smaller than the requested LV size), but lvresize will use
# the helper to resize the crypt dev before resizing the LV.
-lvresize -L-100M $vg/$lv
+# Using --fs resize is required to allow lvresize to look above
+# the lv at crypt&fs layers for potential resizing. Without
+# --fs resize, lvresize fails because it sees that crypt resize
+# is needed and --fs resize is needed to enable that.
+not lvresize -L-100 $vg/$lv
+lvresize -L-100M --fs resize $vg/$lv
check lv_field $vg/$lv lv_size "356.00m"
df --output=size "$mount_dir" |tee df2
not diff df1 df2
3 months, 3 weeks
rhel-9.2.0 - tests: lvresize-fs-crypt using helper only for crypt dev
by Marian Csontos
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=380e3855fbc661eed49...
Commit: 380e3855fbc661eed490665cf1e3d05e985da189
Parent: 611b768134fe39ddfb2eec99eb5417e7e001d8cd
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Jan 3 14:35:26 2023 -0600
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Thu Feb 9 16:28:32 2023 +0100
tests: lvresize-fs-crypt using helper only for crypt dev
(cherry picked from commit 2580f007f0aaa3bf22c43295caa2c60c6142494f)
---
test/shell/lvresize-fs-crypt.sh | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/test/shell/lvresize-fs-crypt.sh b/test/shell/lvresize-fs-crypt.sh
index e7b8b9426..61a6de022 100644
--- a/test/shell/lvresize-fs-crypt.sh
+++ b/test/shell/lvresize-fs-crypt.sh
@@ -135,6 +135,31 @@ cryptsetup close $cr
lvchange -an $vg/$lv
lvremove $vg/$lv
+# lvresize uses helper only for crypt dev resize
+# because the fs was resized separately beforehand
+lvcreate -n $lv -L 456M $vg
+echo 93R4P4pIqAH8 | cryptsetup luksFormat -i1 --type luks1 "$DM_DEV_DIR/$vg/$lv"
+echo 93R4P4pIqAH8 | cryptsetup luksOpen "$DM_DEV_DIR/$vg/$lv" $cr
+mkfs.ext4 /dev/mapper/$cr
+mount /dev/mapper/$cr "$mount_dir"
+dd if=/dev/zero of="$mount_dir/zeros1" bs=1M count=100 conv=fdatasync
+df --output=size "$mount_dir" |tee df1
+# resize only the fs (to 256M), not the crypt dev or LV
+umount "$mount_dir"
+resize2fs /dev/mapper/$cr 262144k
+mount /dev/mapper/$cr "$mount_dir"
+# this lvresize will not resize the fs (which is already reduced
+# to smaller than the requested LV size), but lvresize will use
+# the helper to resize the crypt dev before resizing the LV.
+lvresize -L-100M $vg/$lv
+check lv_field $vg/$lv lv_size "356.00m"
+df --output=size "$mount_dir" |tee df2
+not diff df1 df2
+umount "$mount_dir"
+cryptsetup close $cr
+lvchange -an $vg/$lv
+lvremove $vg/$lv
+
# test with LUKS2?
vgremove -ff $vg
3 months, 3 weeks
main - udev: import previous results of blkid when in suspended state
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=94f77a4d8d9737fca05...
Commit: 94f77a4d8d9737fca05fb4e451678ec440c68670
Parent: dc99f0def17b936f95c63612a56ae2a6ae81db0e
Author: Yu Watanabe <watanabe.yu+github(a)gmail.com>
AuthorDate: Thu Feb 2 00:28:12 2023 +0900
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Feb 7 09:37:27 2023 +0100
udev: import previous results of blkid when in suspended state
Follow-up for e10f67e91728f1e576803df884049ecbd92874d0.
The commit e10f67e91728f1e576803df884049ecbd92874d0 tries to keep device
node symlinks even if the device is in the suspended state. However,
necessary properties that may previously obtained by the blkid command
were not imported at least in the .rules file. So, unless ID_FS_xyz
properties are imported by another earlier .rules file, the device node
symlinks are still lost when event is processed in the suspended state.
Let's explicitly import the necessary properties.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2158628
GHPR: https://github.com/lvmteam/lvm2/pull/105
---
WHATS_NEW_DM | 1 +
udev/13-dm-disk.rules.in | 14 ++++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 43bf62a29..020efe6f4 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.191 -
=====================================
+ Import previous ID_FS_* udev records in 13-dm-disk.rules for suspended DM dev.
Remove NAME="mapper/control" rule from 10-dm.rules to avoid udev warnings.
Version 1.02.189 - 22nd December 2022
diff --git a/udev/13-dm-disk.rules.in b/udev/13-dm-disk.rules.in
index 5cc08121e..dca00bc01 100644
--- a/udev/13-dm-disk.rules.in
+++ b/udev/13-dm-disk.rules.in
@@ -17,12 +17,22 @@ ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}=="1", GOTO="dm_end"
SYMLINK+="disk/by-id/dm-name-$env{DM_NAME}"
ENV{DM_UUID}=="?*", SYMLINK+="disk/by-id/dm-uuid-$env{DM_UUID}"
-ENV{DM_SUSPENDED}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_link"
-ENV{DM_NOSCAN}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_link"
+ENV{DM_SUSPENDED}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_import"
+ENV{DM_NOSCAN}=="1", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}=="1", GOTO="dm_import"
ENV{DM_SUSPENDED}=="1", GOTO="dm_end"
ENV{DM_NOSCAN}=="1", GOTO="dm_watch"
(BLKID_RULE)
+GOTO="dm_link"
+
+LABEL="dm_import"
+IMPORT{db}="ID_FS_USAGE"
+IMPORT{db}="ID_FS_UUID_ENC"
+IMPORT{db}="ID_FS_LABEL_ENC"
+IMPORT{db}="ID_PART_ENTRY_NAME"
+IMPORT{db}="ID_PART_ENTRY_UUID"
+IMPORT{db}="ID_PART_ENTRY_SCHEME"
+IMPORT{db}="ID_PART_GPT_AUTO_ROOT"
LABEL="dm_link"
ENV{DM_UDEV_LOW_PRIORITY_FLAG}=="1", OPTIONS="link_priority=-100"
3 months, 3 weeks
main - device_id: ignore quotes in device id
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=dc99f0def17b936f95c...
Commit: dc99f0def17b936f95c63612a56ae2a6ae81db0e
Parent: 57ad78d4369ee531ab0173b42aa91048eb316353
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Feb 6 12:18:55 2023 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Feb 6 12:24:18 2023 -0600
device_id: ignore quotes in device id
A t10 wwid string was found containing a " character
which breaks vg metadata parsing. Ignore any quotation
marks in device id strings.
---
lib/device/device_id.c | 6 ++++--
lib/device/parse_vpd.c | 6 ++++++
test/shell/devicesfile-vpd-ids.sh | 24 ++++++++++++++++++++++++
3 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 1be6b0787..79da12884 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -438,8 +438,8 @@ int dev_read_sys_wwid(struct cmd_context *cmd, struct device *dev,
if (!ret || !buf[0])
return 0;
- /* in t10 id, replace series of spaces with one _ */
- if (!strncmp(buf, "t10.", 4) && strchr(buf, ' ')) {
+ /* in t10 id, replace characters like space and quote */
+ if (!strncmp(buf, "t10.", 4)) {
if (bufsize < DEV_WWID_SIZE)
return 0;
memcpy(tmpbuf, buf, DEV_WWID_SIZE);
@@ -587,6 +587,8 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
/* wwids are already munged if needed */
if (idtype != DEV_ID_TYPE_SYS_WWID) {
for (i = 0; i < strlen(sysbuf); i++) {
+ if (sysbuf[i] == '"')
+ continue;
if (isblank(sysbuf[i]) || isspace(sysbuf[i]) || iscntrl(sysbuf[i]))
sysbuf[i] = '_';
}
diff --git a/lib/device/parse_vpd.c b/lib/device/parse_vpd.c
index bea8834d4..c1ac974fd 100644
--- a/lib/device/parse_vpd.c
+++ b/lib/device/parse_vpd.c
@@ -53,6 +53,12 @@ int format_t10_id(const unsigned char *in, int in_bytes, unsigned char *out, int
/* skip leading spaces */
if (!retlen && (in[i] == ' '))
continue;
+ /* skip non-ascii non-printable characters */
+ if (!isascii(in[i]) || !isprint(in[i]))
+ continue;
+ /* skip quote */
+ if (in[i] == '"')
+ continue;
/* replace one or more spaces with _ */
if (in[i] == ' ') {
in_space = 1;
diff --git a/test/shell/devicesfile-vpd-ids.sh b/test/shell/devicesfile-vpd-ids.sh
index 2801310ef..b2042fb9a 100644
--- a/test/shell/devicesfile-vpd-ids.sh
+++ b/test/shell/devicesfile-vpd-ids.sh
@@ -219,6 +219,30 @@ vgremove $vg
rm $SYS_DIR/dev/block/$MAJOR1:$MINOR1/wwid
cleanup_sysfs
+# Test t10 wwid containing quote
+rm $DF
+aux wipefs_a "$DEV1"
+mkdir -p $SYS_DIR/dev/block/$MAJOR1:$MINOR1/
+echo "t10.ATA_2.5\"_SATA_SSD_1112-A___111111111111" > $SYS_DIR/dev/block/$MAJOR1:$MINOR1/wwid
+lvmdevices --adddev "$DEV1"
+cat $DF
+vgcreate $vg "$DEV1"
+lvcreate -l1 -an $vg
+cat $DF
+# check wwid string in metadata output
+pvs -o+deviceidtype,deviceid "$DEV1" |tee out
+grep sys_wwid out
+# the quote is removed after the 5
+grep 2.5_SATA_SSD out
+# check wwid string in system.devices
+grep sys_wwid $DF
+# the quote is removed after the 5
+grep 2.5_SATA_SSD $DF
+lvremove -y $vg
+vgremove $vg
+rm $SYS_DIR/dev/block/$MAJOR1:$MINOR1/wwid
+cleanup_sysfs
+
# TODO: lvmdevices --adddev <dev> --deviceidtype <type> --deviceid <val>
# This would let the user specify the second naa wwid.
3 months, 3 weeks
main - vg_read: remove unused code for md components
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=57ad78d4369ee531ab0...
Commit: 57ad78d4369ee531ab0173b42aa91048eb316353
Parent: 8498874147c886032817c24d11231947a041bc2e
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 2 16:15:13 2023 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Feb 2 16:15:13 2023 -0600
vg_read: remove unused code for md components
This code was no longer used after ommit
87ee401eea3c3c3958ec5cda6e5c246b80503b8c
---
lib/metadata/metadata.c | 44 +-------------------------------------------
1 file changed, 1 insertion(+), 43 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 30b2c1779..91a23f931 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4643,11 +4643,9 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
struct volume_group *vg, *vg_ret = NULL;
struct metadata_area *mda, *mda2;
unsigned use_precommitted = precommitted;
- struct device *mda_dev, *dev_ret = NULL, *dev;
+ struct device *mda_dev, *dev_ret = NULL;
struct cached_vg_fmtdata *vg_fmtdata = NULL; /* Additional format-specific data about the vg */
- struct pv_list *pvl;
int found_old_metadata = 0;
- int found_md_component = 0;
unsigned use_previous_vg;
log_debug_metadata("Reading VG %s %s", vgname ?: "<no name>", vgid ?: "<no vgid>");
@@ -4866,46 +4864,6 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
goto_out;
}
- /*
- * Usually md components are eliminated during label scan, or duplicate
- * resolution, but sometimes an md component can get through and be
- * detected in set_pv_device() (which will do an md component check if
- * the device/PV sizes don't match.) In this case we need to fix up
- * lvmcache to drop the component dev and fix up metadata_areas_in_use
- * to drop it also.
- */
- if (found_md_component) {
- dm_list_iterate_items(pvl, &vg_ret->pvs) {
- if (!(dev = lvmcache_device_from_pv_id(cmd, &pvl->pv->id, NULL)))
- continue;
-
- /* dev_is_md_component set this flag if it was found */
- if (!(dev->flags & DEV_IS_MD_COMPONENT))
- continue;
-
- log_debug_metadata("Drop dev for MD component from cache %s.", dev_name(dev));
- lvmcache_del_dev(dev);
-
- dm_list_iterate_items(mda, &fid->metadata_areas_in_use)
- if (mda_get_device(mda) == dev) {
- log_debug_metadata("Drop mda from MD component from mda list %s.", dev_name(dev));
- dm_list_del(&mda->list);
- break;
- }
- }
- }
-
- /*
- * After dropping MD components there may be no remaining legitimate
- * devices for this VG.
- */
- if (!lvmcache_vginfo_from_vgid(vgid)) {
- log_debug_metadata("VG %s not found on any remaining devices.", vgname);
- release_vg(vg_ret);
- vg_ret = NULL;
- goto out;
- }
-
/*
* Correct the lvmcache representation of the VG using the metadata
* that we have chosen above (vg_ret).
4 months
main - udev: remove rule for explicit creation of /dev/mapper/control
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8498874147c88603281...
Commit: 8498874147c886032817c24d11231947a041bc2e
Parent: e7c8a825061d57efaffad80667873fa8d68d31ab
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Feb 2 15:30:30 2023 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Feb 2 15:41:47 2023 +0100
udev: remove rule for explicit creation of /dev/mapper/control
We used KERNEL=="device-mapper", NAME="/dev/mapper/control" udev rule to
create the /dev/mapper/control file. The "NAME" rule should be only used
to rename network devices, otherwise udev issues a warning message. The
device-mapper driver has proper DEVNAME=/dev/mapper/control propagated
in the uevent environment when it is loaded so we don't need further
instruction on where to create the node - udev knows already.
Also, these days, it is created directly by kernel inside devtmpfs.
This makes the NAME="/dev/mapper/control" rule completely obsolete.
---
WHATS_NEW_DM | 1 +
udev/10-dm.rules.in | 2 --
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 052fb9daf..43bf62a29 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.191 -
=====================================
+ Remove NAME="mapper/control" rule from 10-dm.rules to avoid udev warnings.
Version 1.02.189 - 22nd December 2022
=====================================
diff --git a/udev/10-dm.rules.in b/udev/10-dm.rules.in
index b4fa52ab7..4ffd3e265 100644
--- a/udev/10-dm.rules.in
+++ b/udev/10-dm.rules.in
@@ -28,8 +28,6 @@
# Also, keep in mind that recent rules may also require recent
# subsystem-specific binaries.
-KERNEL=="device-mapper", NAME="(DM_DIR)/control"
-
SUBSYSTEM!="block", GOTO="dm_end"
KERNEL!="dm-[0-9]*", GOTO="dm_end"
(DM_EXEC_RULE)
4 months