Skip to contentSkip to conversation

vgremove: PVID file leakage in /run/lvm/pvs_online

PATCH New miaoguanqin 3 participants 4 messages Sep 8, 2022 – Sep 14, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vgremove: PVID file leakage in /run/lvm/pvs_online

We found PVID file leakage problem when exec the following test;
pvcreate /dev/sdb
vgcreate -s 1M docker /dev/sdb
lvcreate -L 10M docker
pvscan --cache --listvg --checkcomplete --vgonline --udevoutput
--journal=output /dev/sdb
vgremove -ff docker

pvcreate operation generates a new PVID, which is used to create PVID pvid file
when exec pvcan. However vgremove does not delete the old PVID file.

Here, we will delete all PVID files of each pv in current vg, when exec vgremove.

---
  lib/metadata/metadata.c | 33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
lib/metadata/metadata.c +33 -0
index 1cda1888f..75233d120 100644
@@ -38,6 +38,30 @@
  #include <time.h>
  #include <math.h>
 
+
+static const char *_pvs_online_dir = DEFAULT_RUN_DIR "/pvs_online";
+
+static int remove_pvid_file(struct physical_volume *pv)
+{
+	char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };
+	char path[PATH_MAX] __attribute__((aligned(8))) = { 0 };
+
+	memcpy(pvid, &pv->id.uuid, ID_LEN);
+
+	if (dm_snprintf(path, sizeof(path), "%s/%s", _pvs_online_dir, pvid) < 0) {
+		log_warn("WARNING:pvid file path is %s", path);
+		return 0;
+	}
+
+	log_warn("unlink pvid file, path is %s", path);
+
+	if (unlink(path) && (errno != ENOENT)) {
+		log_warn("WARNING:unlink pvid file path error, path is %s", path);
+		return 0;
+	}
+	return 1;
+}
+
  static struct physical_volume *_pv_read(struct cmd_context *cmd,
  					const struct format_type *fmt,
  					struct volume_group *vg,
@@ -665,6 +689,15 @@ int vg_remove_direct(struct volume_group *vg)
  				  " from volume group \"%s\"",
  				  pv_dev_name(pv), vg->name);
  			ret = 0;
+			continue;
+		}
+
+		/* Remove pvid files */
+		if(!remove_pvid_file(pv)){
+			log_error("Failed to remove pvid files \"%s\""
+				  " from volume group \"%s\"",
+				  _pvs_online_dir, vg->name);
+			ret = 0;
  		}
  	}
 
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/1 vgremove: PVID file leakage in /run/lvm/pvs_online

Quoted 8 lines · miaoguanqin

We found PVID file leakage problem when exec the following test;
pvcreate /dev/sdb
vgcreate -s 1M docker /dev/sdb
lvcreate -L 10M docker
pvscan --cache --listvg --checkcomplete --vgonline --udevoutput
--journal=output /dev/sdb
vgremove -ff docker

Quoted 6 lines

pvcreate operation generates a new PVID, which is used to create PVID pvid file
when exec pvcan. However vgremove does not delete the old PVID file.

Here, we will delete all PVID files of each pv in current vg, when exec vgremove.

Hi, these files are located in tmpfs, so they will disappear automatically when the system reboots. Is there a reason that you want remove them in vgremove instead of waiting for reboot to remove them?

Dave

#2 lore raw

PATCH 1/1 vgremove: PVID file leakage in /run/lvm/pvs_online

Thanks for your reply.
/run dir is mounted as tmpfs type, which has a setting inode number by systemd service. If the number of leakage pvid files increases with time, it may cause Deny of Service for other apps because cannot create files in /run.

????David Teigland <[email protected]>
????LVM2 development <[email protected]>
????zkabelac <[email protected]>;linfeilong <[email protected]>;wuguanghao <[email protected]>;liuzhiqiang (I) <[email protected]> ????2022-09-09 22:27:45
????Re: [lvm-devel] [PATCH] vgremove: PVID file leakage in /run/lvm/pvs_online

Quoted 8 lines · miaoguanqin

We found PVID file leakage problem when exec the following test; pvcreate /dev/sdb
vgcreate -s 1M docker /dev/sdb
lvcreate -L 10M docker
pvscan --cache --listvg --checkcomplete --vgonline --udevoutput --journal=output /dev/sdb
vgremove -ff docker

Quoted 6 lines

pvcreate operation generates a new PVID, which is used to create PVID pvid file
when exec pvcan. However vgremove does not delete the old PVID file.

Here, we will delete all PVID files of each pv in current vg, when exec vgremove.

Hi, these files are located in tmpfs, so they will disappear automatically when the system reboots. Is there a reason that you want remove them in vgremove instead of waiting for reboot to remove them?

Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20220910/67b53b3a/attachment.htm>

#3 lore raw

PATCH 1/1 vgremove: PVID file leakage in /run/lvm/pvs_online

Hi, a patch for this is here:
https://sourceware.org/git/?p=lvm2.git;a=commit;h=0887896847807e159a70edc5ac92a4030c13923a

Dave

Quoted 28 lines · liuzhiqiang (I)

Thanks for your reply.
/run dir is mounted as tmpfs type, which has a setting inode number by systemd service. If the number of leakage pvid files increases with time, it may cause Deny of Service for other apps because cannot create files in /run.

????David Teigland <[email protected]>
????LVM2 development <[email protected]>
????zkabelac <[email protected]>;linfeilong <[email protected]>;wuguanghao <[email protected]>;liuzhiqiang (I) <[email protected]> ????2022-09-09 22:27:45
????Re: [lvm-devel] [PATCH] vgremove: PVID file leakage in /run/lvm/pvs_online

Quoted 8 lines · miaoguanqin

We found PVID file leakage problem when exec the following test; pvcreate /dev/sdb
vgcreate -s 1M docker /dev/sdb
lvcreate -L 10M docker
pvscan --cache --listvg --checkcomplete --vgonline --udevoutput --journal=output /dev/sdb
vgremove -ff docker

Quoted 6 lines

pvcreate operation generates a new PVID, which is used to create PVID pvid file
when exec pvcan. However vgremove does not delete the old PVID file.

Here, we will delete all PVID files of each pv in current vg, when exec vgremove.

Hi, these files are located in tmpfs, so they will disappear automatically when the system reboots. Is there a reason that you want remove them in vgremove instead of waiting for reboot to remove them?