From 23008cde712028bc7e7d56d9fd7cbe3da07d80fa Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 7 Oct 2020 14:34:25 +0200 Subject: Added udev rules to kernel module build of xloop The added rules allow udev to properly detect disks and partitions exposed by the xloop kernel module. A proper detection of disks and partitions is needed by some command line tools from the util-linux package. --- CMakeLists.txt | 10 +++++---- kernel/CMakeLists.txt | 6 +++++ kernel/udev/50-xloop.rules | 56 ++++++++++++++++++++++++++++++++++++++++++++++ udev/50-xloop.rules | 37 ------------------------------ 4 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 kernel/udev/50-xloop.rules delete mode 100644 udev/50-xloop.rules diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ecf3e5..3095d7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,21 +55,23 @@ if(${CMAKE_BUILD_TYPE} MATCHES Release) set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) # set DEB generator specific packaging options set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc-bin") - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst "depmod -a\n") - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm "depmod -a\n") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst "depmod -a\nudevadm control --reload-rules\n") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm "depmod -a\nudevadm control --reload-rules\n") set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm) # set RPM generator specific packaging options set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib" "/lib/modules" + "/lib/udev" "/lib/modules/${CMAKE_SYSTEM_VERSION}" "/lib/modules/${CMAKE_SYSTEM_VERSION}/extra" + "/lib/udev/rules.d" "${CPACK_PACKAGING_INSTALL_PREFIX}/share/bash-completion" "${CPACK_PACKAGING_INSTALL_PREFIX}/share/bash-completion/completions" "${CPACK_PACKAGING_INSTALL_PREFIX}/share/man" "${CPACK_PACKAGING_INSTALL_PREFIX}/share/man/man8") - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/rpm/post "depmod -a\n") - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/rpm/postun "depmod -a\n") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/rpm/post "depmod -a\nudevadm control --reload-rules\n") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/package/rpm/postun "depmod -a\nudevadm control --reload-rules\n") set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package/rpm/post) set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package/rpm/postun) # include CPack functionality diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 2dace3f..0e867f6 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -74,3 +74,9 @@ add_kernel_module(xloop_file_fmt_qcow "${KERNEL_DIR}" if(${CMAKE_BUILD_TYPE} MATCHES Debug) add_subdirectory(tests) endif() + +# install udev rules for xloop devices exposed by the xloop kernel module +install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/udev/50-xloop.rules + DESTINATION /lib/udev/rules.d + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + COMPONENT main) diff --git a/kernel/udev/50-xloop.rules b/kernel/udev/50-xloop.rules new file mode 100644 index 0000000..fac04e0 --- /dev/null +++ b/kernel/udev/50-xloop.rules @@ -0,0 +1,56 @@ +# Adapted from /usr/lib/udev/rules.d/60-persistent-storage.rules +# Only handle /dev/xloop* devices. +# +# persistent storage links: /dev/disk/{by-id,by-uuid,by-label,by-path} +# scheme based on "Linux persistent device names", 2004, Hannes Reinecke + +ACTION=="remove", GOTO="xloop_storage_end" +ENV{UDEV_DISABLE_PERSISTENT_STORAGE_RULES_FLAG}=="1", GOTO="xloop_storage_end" + +SUBSYSTEM!="block", GOTO="xloop_storage_end" +KERNEL!="xloop*", GOTO="xloop_storage_end" + +# ignore partitions that span the entire disk +TEST=="whole_disk", GOTO="xloop_storage_end" + +# For partitions import parent disk ID_* information, except ID_FS_*. +# +# This is particularly important on media where a filesystem superblock and +# partition table are found on the same level, e.g. common Linux distro ISO +# installation media. +# +# In the case where a partition device points to the same filesystem that +# was detected on the parent disk, the ID_FS_* information is already +# present on the partition devices as well as the parent, so no need to +# propagate it. In the case where the partition device points to a different +# filesystem, merging the parent ID_FS_ properties would lead to +# inconsistencies, so we avoid doing so. +ENV{DEVTYPE}=="partition", \ + IMPORT{parent}="ID_[!F]*", IMPORT{parent}="ID_", \ + IMPORT{parent}="ID_F[!S]*", IMPORT{parent}="ID_F", \ + IMPORT{parent}="ID_FS[!_]*", IMPORT{parent}="ID_FS" + +# by-path +ENV{DEVTYPE}=="disk", DEVPATH!="*/virtual/*", IMPORT{builtin}="path_id" +KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}" +ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n" +# compatible links for ATA devices +KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH_ATA_COMPAT}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}" +ENV{DEVTYPE}=="partition", ENV{ID_PATH_ATA_COMPAT}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}-part%n" + +# probe filesystem metadata of disks +KERNEL!="sr*", IMPORT{builtin}="blkid" + +# by-label/by-uuid links (filesystem metadata) +ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" +ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}" + +# by-id (World Wide Name) +ENV{DEVTYPE}=="disk", ENV{ID_WWN_WITH_EXTENSION}=="?*", SYMLINK+="disk/by-id/wwn-$env{ID_WWN_WITH_EXTENSION}" +ENV{DEVTYPE}=="partition", ENV{ID_WWN_WITH_EXTENSION}=="?*", SYMLINK+="disk/by-id/wwn-$env{ID_WWN_WITH_EXTENSION}-part%n" + +# by-partlabel/by-partuuid links (partition metadata) +ENV{ID_PART_ENTRY_UUID}=="?*", SYMLINK+="disk/by-partuuid/$env{ID_PART_ENTRY_UUID}" +ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK+="disk/by-partlabel/$env{ID_PART_ENTRY_NAME}" + +LABEL="xloop_storage_end" diff --git a/udev/50-xloop.rules b/udev/50-xloop.rules deleted file mode 100644 index 5d727bf..0000000 --- a/udev/50-xloop.rules +++ /dev/null @@ -1,37 +0,0 @@ -# Adapted from /usr/lib/udev/rules.d/60-persistent-storage.rules -# Only handle /dev/xloop* devices. -# -# persistent storage links: /dev/disk/{by-id,by-uuid,by-label,by-path} -# scheme based on "Linux persistent device names", 2004, Hannes Reinecke - -ACTION=="remove", GOTO="xloop_storage_end" - -SUBSYSTEM!="block", GOTO="xloop_storage_end" -KERNEL!="xloop*", GOTO="xloop_storage_end" - -# ignore partitions that span the entire disk -TEST=="whole_disk", GOTO="xloop_storage_end" - -# for partitions import parent information -ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*" - -# by-path -ENV{DEVTYPE}=="disk", DEVPATH!="*/virtual/*", IMPORT{builtin}="path_id" -ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n" - -# probe filesystem metadata of disks -IMPORT{builtin}="blkid" - -# by-label/by-uuid links (filesystem metadata) -ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" -ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}" - -# by-id (World Wide Name) -ENV{DEVTYPE}=="disk", ENV{ID_WWN_WITH_EXTENSION}=="?*", SYMLINK+="disk/by-id/wwn-$env{ID_WWN_WITH_EXTENSION}" -ENV{DEVTYPE}=="partition", ENV{ID_WWN_WITH_EXTENSION}=="?*", SYMLINK+="disk/by-id/wwn-$env{ID_WWN_WITH_EXTENSION}-part%n" - -# by-partlabel/by-partuuid links (partition metadata) -ENV{ID_PART_ENTRY_UUID}=="?*", SYMLINK+="disk/by-partuuid/$env{ID_PART_ENTRY_UUID}" -ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK+="disk/by-partlabel/$env{ID_PART_ENTRY_NAME}" - -LABEL="xloop_storage_end" -- cgit v1.2.3-55-g7522