diff mbox

[30/31] kpartx/del-part-nodes.rules: new udev file

Message ID 20170902223900.7339-31-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show

Commit Message

Martin Wilck Sept. 2, 2017, 10:38 p.m. UTC
A new udev rules file "68-del-part-nodes.rules" is introduced,
based on code from Ben Marzinki. This code deletes partitions on
multipath member devices. The purpose of this is to avoid users
accidentally accessing partitions of member devices rather than of the
multipath devcice. The deletion is done only once for every disk
device. If the user wants to get the partitions back, he can run "partx
-a" or "partprobe" on the disk device.

This code could be extended to wipe partitions on member devices
of non-multipath dm targets if desired.

Means to deactivate this behavior are provided via kernel parameter
"dont_del_part_nodes", or a custom udev rules file setting the
"DONT_DEL_PART_NODES" environment variable.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 kpartx/Makefile             |  1 +
 kpartx/del-part-nodes.rules | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 kpartx/del-part-nodes.rules

Comments

Benjamin Marzinski Sept. 13, 2017, 9:23 p.m. UTC | #1
On Sun, Sep 03, 2017 at 12:38:59AM +0200, Martin Wilck wrote:
> A new udev rules file "68-del-part-nodes.rules" is introduced,
> based on code from Ben Marzinki. This code deletes partitions on
> multipath member devices. The purpose of this is to avoid users
> accidentally accessing partitions of member devices rather than of the
> multipath devcice. The deletion is done only once for every disk
> device. If the user wants to get the partitions back, he can run "partx
> -a" or "partprobe" on the disk device.
> 
> This code could be extended to wipe partitions on member devices
> of non-multipath dm targets if desired.
> 
> Means to deactivate this behavior are provided via kernel parameter
> "dont_del_part_nodes", or a custom udev rules file setting the
> "DONT_DEL_PART_NODES" environment variable.

You need to uninstall 68-del-part-nodes.rules. Otherwise, this looks
fine.

-Ben

> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  kpartx/Makefile             |  1 +
>  kpartx/del-part-nodes.rules | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
>  create mode 100644 kpartx/del-part-nodes.rules
> 
> diff --git a/kpartx/Makefile b/kpartx/Makefile
> index 7b75032e..7f5c1708 100644
> --- a/kpartx/Makefile
> +++ b/kpartx/Makefile
> @@ -30,6 +30,7 @@ install: $(EXEC) $(EXEC).8
>  	$(INSTALL_PROGRAM) -m 755 kpartx_id $(DESTDIR)$(libudevdir)
>  	$(INSTALL_PROGRAM) -d $(DESTDIR)$(libudevdir)/rules.d
>  	$(INSTALL_PROGRAM) -m 644 kpartx.rules $(DESTDIR)$(libudevdir)/rules.d/66-kpartx.rules
> +	$(INSTALL_PROGRAM) -m 644 del-part-nodes.rules $(DESTDIR)$(libudevdir)/rules.d/68-del-part-nodes.rules
>  	$(INSTALL_PROGRAM) -d $(DESTDIR)$(man8dir)
>  	$(INSTALL_PROGRAM) -m 644 $(EXEC).8.gz $(DESTDIR)$(man8dir)
>  
> diff --git a/kpartx/del-part-nodes.rules b/kpartx/del-part-nodes.rules
> new file mode 100644
> index 00000000..cee945d9
> --- /dev/null
> +++ b/kpartx/del-part-nodes.rules
> @@ -0,0 +1,32 @@
> +# These rules can delete partitions devnodes for slave devices
> +# for certain aggregate devices such as multipath.
> +# This is desirable to avoid confusion and keep the number
> +# of device nodes and symlinks within limits.
> +#
> +# This is done only once on the first "add" or "change" event for
> +# any given device.
> +#
> +# To suppress this, use the kernel parameter "dont_del_part_nodes",
> +# or create an udev rule file that sets ENV{DONT_DEL_PART_NODES}="1".
> +
> +SUBSYSTEM!="block", GOTO="end_del_part_nodes"
> +KERNEL!="sd*|dasd*|rbd*", GOTO="end_del_part_nodes"
> +ACTION!="add|change", GOTO="end_del_part_nodes"
> +
> +IMPORT{cmdline}="dont_del_part_nodes"
> +ENV{dont_del_part_nodes}=="1", GOTO="end_del_part_nodes"
> +ENV{DONT_DEL_PART_NODES}=="1", GOTO="end_del_part_nodes"
> +
> +# dm-multipath
> +ENV{DM_MULTIPATH_DEVICE_PATH}=="1", GOTO="del_part_nodes"
> +
> +# Other aggregate device types can be added here.
> +
> +GOTO="end_del_part_nodes"
> +
> +LABEL="del_part_nodes"
> +IMPORT{db}="DM_DEL_PART_NODES"
> +ENV{DM_DEL_PART_NODES}!="1", ENV{DM_DEL_PART_NODES}="1", \
> +	RUN+="/usr/sbin/partx -d --nr 1-1024 $env{DEVNAME}"
> +
> +LABEL="end_del_part_nodes"
> -- 
> 2.14.0

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/kpartx/Makefile b/kpartx/Makefile
index 7b75032e..7f5c1708 100644
--- a/kpartx/Makefile
+++ b/kpartx/Makefile
@@ -30,6 +30,7 @@  install: $(EXEC) $(EXEC).8
 	$(INSTALL_PROGRAM) -m 755 kpartx_id $(DESTDIR)$(libudevdir)
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(libudevdir)/rules.d
 	$(INSTALL_PROGRAM) -m 644 kpartx.rules $(DESTDIR)$(libudevdir)/rules.d/66-kpartx.rules
+	$(INSTALL_PROGRAM) -m 644 del-part-nodes.rules $(DESTDIR)$(libudevdir)/rules.d/68-del-part-nodes.rules
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(man8dir)
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).8.gz $(DESTDIR)$(man8dir)
 
diff --git a/kpartx/del-part-nodes.rules b/kpartx/del-part-nodes.rules
new file mode 100644
index 00000000..cee945d9
--- /dev/null
+++ b/kpartx/del-part-nodes.rules
@@ -0,0 +1,32 @@ 
+# These rules can delete partitions devnodes for slave devices
+# for certain aggregate devices such as multipath.
+# This is desirable to avoid confusion and keep the number
+# of device nodes and symlinks within limits.
+#
+# This is done only once on the first "add" or "change" event for
+# any given device.
+#
+# To suppress this, use the kernel parameter "dont_del_part_nodes",
+# or create an udev rule file that sets ENV{DONT_DEL_PART_NODES}="1".
+
+SUBSYSTEM!="block", GOTO="end_del_part_nodes"
+KERNEL!="sd*|dasd*|rbd*", GOTO="end_del_part_nodes"
+ACTION!="add|change", GOTO="end_del_part_nodes"
+
+IMPORT{cmdline}="dont_del_part_nodes"
+ENV{dont_del_part_nodes}=="1", GOTO="end_del_part_nodes"
+ENV{DONT_DEL_PART_NODES}=="1", GOTO="end_del_part_nodes"
+
+# dm-multipath
+ENV{DM_MULTIPATH_DEVICE_PATH}=="1", GOTO="del_part_nodes"
+
+# Other aggregate device types can be added here.
+
+GOTO="end_del_part_nodes"
+
+LABEL="del_part_nodes"
+IMPORT{db}="DM_DEL_PART_NODES"
+ENV{DM_DEL_PART_NODES}!="1", ENV{DM_DEL_PART_NODES}="1", \
+	RUN+="/usr/sbin/partx -d --nr 1-1024 $env{DEVNAME}"
+
+LABEL="end_del_part_nodes"