このudevルールがcryptsetupを停止するのはなぜですか?

このudevルールがcryptsetupを停止するのはなぜですか?

システムからドライブを取り出すたびに、私に電子メールを送信するスクリプトを実行するルールがあります。

SUBSYSTEM=="block", ACTION=="remove", ENV{DEVTYPE}=="disk",\
    RUN="/usr/sbin/disk-monitor.sh $env{DEVNAME}"

スクリプトは次のとおりです。

#!/bin/bash

echo "Dropout detected $(date)" | mail -s "WARNING: Drive $1 has dropped out!" logger@gentooserver

これにより、「cryptsetup close」や「integritysetup format」などの特定のcryptsetupコマンドが停止します。なぜこれが起こるのですか?

cryptsetup --debug close offline1
# cryptsetup 2.4.3 processing "cryptsetup --debug close offline1"
# Running command close.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating crypt device context by device offline1.
# Initialising device-mapper backend library.
# dm version   [ opencount flush ]   [16384] (*1)
# dm versions   [ opencount flush ]   [16384] (*1)
# Detected dm-ioctl version 4.47.0.
# Detected dm-crypt version 1.24.0.
# Detected dm-integrity version 1.10.0.
# Device-mapper backend running with UDEV support enabled.
# dm status offline1  [ opencount noflush ]   [16384] (*1)
# Releasing device-mapper backend.
# Trying to open and read device /dev/sdk1 with direct-io.
# Allocating context for crypt device /dev/sdk1.
# Trying to open and read device /dev/sdk1 with direct-io.
# Initialising device-mapper backend library.
# dm versions   [ opencount flush ]   [16384] (*1)
# dm table offline1  [ opencount flush securedata ]   [16384] (*1)
# Trying to open and read device /dev/sdk1 with direct-io.
# dm versions   [ opencount flush ]   [16384] (*1)
# dm deps offline1  [ opencount flush ]   [16384] (*1)
# Crypto backend (OpenSSL 1.1.1t  7 Feb 2023) initialized in cryptsetup library version 2.4.3.
# Detected kernel Linux 6.1.12-gentoo-x86_64 x86_64.
# Reloading LUKS2 header (repair disabled).
# Acquiring read lock for device /dev/sdk1.
# Opening lock resource file /run/cryptsetup/L_8:161
# Verifying lock handle for /dev/sdk1.
# Device /dev/sdk1 READ lock taken.
# Trying to read primary LUKS2 header at offset 0x0.
# Opening locked device /dev/sdk1
# Verifying locked device handle (bdev)
# LUKS2 header version 2 of size 16384 bytes, checksum sha256.
# Checksum:a4bc53825c88a45b53709738107a718a9c4f896dfef90951cfd9d9cfe68dd259 (on-disk)
# Checksum:a4bc53825c88a45b53709738107a718a9c4f896dfef90951cfd9d9cfe68dd259 (in-memory)
# Trying to read secondary LUKS2 header at offset 0x4000.
# Reusing open ro fd on device /dev/sdk1
# LUKS2 header version 2 of size 16384 bytes, checksum sha256.
# Checksum:ca42f7c96748267f126f3ab48536dee1a05525aa1db10a1feb85a5a60e3338e8 (on-disk)
# Checksum:ca42f7c96748267f126f3ab48536dee1a05525aa1db10a1feb85a5a60e3338e8 (in-memory)
# Device size 4000785964544, offset 16777216.
# Device /dev/sdk1 READ lock released.
# PBKDF argon2id, time_ms 2000 (iterations 0), max_memory_kb 1048576, parallel_threads 4.
# Deactivating volume offline1.
# dm versions   [ opencount flush ]   [16384] (*1)
# dm status offline1  [ opencount noflush ]   [16384] (*1)
# dm versions   [ opencount flush ]   [16384] (*1)
# dm table offline1  [ opencount flush securedata ]   [16384] (*1)
# Trying to open and read device /dev/sdk1 with direct-io.
# dm versions   [ opencount flush ]   [16384] (*1)
# dm deps offline1  [ opencount flush ]   [16384] (*1)
# dm versions   [ opencount flush ]   [16384] (*1)
# dm table offline1  [ opencount flush securedata ]   [16384] (*1)
# dm versions   [ opencount flush ]   [16384] (*1)
# Udev cookie 0xd4d82bf (semid 5) created
# Udev cookie 0xd4d82bf (semid 5) incremented to 1
# Udev cookie 0xd4d82bf (semid 5) incremented to 2
# Udev cookie 0xd4d82bf (semid 5) assigned to REMOVE task(2) with flags DISABLE_LIBRARY_FALLBACK         (0x20)
# dm remove offline1  [ opencount flush retryremove ]   [16384] (*1)
# Udev cookie 0xd4d82bf (semid 5) decremented to 1
# Udev cookie 0xd4d82bf (semid 5) waiting for zero //hangs here

udevログ:

Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: dm-2: Device is queued (SEQNUM=4516, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: dm-2: Device ready for processing (SEQNUM=4516, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: Successfully forked off 'n/a' as PID 8410.
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: dm-2: Worker [8410] is forked for processing SEQNUM=4516.
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: 252:2: Device is queued (SEQNUM=4517, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: 252:2: Device ready for processing (SEQNUM=4517, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Processing device (SEQNUM=4516, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Removing watch handle 50.
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: Successfully forked off 'n/a' as PID 8411.
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: 252:2: Worker [8411] is forked for processing SEQNUM=4517.
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: dm-2: Device is queued (SEQNUM=4518, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: dm-2: SEQNUM=4518 blocked by SEQNUM=4516
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: /usr/lib/udev/rules.d/95-dm-notify.rules:12 RUN '/sbin/dmsetup udevcomplete $env{DM_COOKIE}'
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: /usr/lib/udev/rules.d/disk-monitor.rules:4 RUN '/usr/sbin/disk-monitor.sh $env{DEVNAME}'
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: No reference left for '/dev/mapper/offline1', removing
Feb 26 18:51:38 gentoodesktop systemd-udevd[8411]: 252:2: Processing device (SEQNUM=4517, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: No reference left for '/dev/disk/by-id/dm-name-offline1', removing
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: No reference left for '/dev/disk/by-id/dm-uuid-CRYPT-LUKS2-f2eafcc2880e4d34afa3132486d1d6ae-offline1', removing
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: No reference left for '/dev/disk/by-uuid/5d5633e2-2f7c-49de-babf-f3ed263a3c8b', removing
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Running command "/usr/sbin/disk-monitor.sh /dev/dm-2"
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Starting '/usr/sbin/disk-monitor.sh /dev/dm-2'
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: Successfully forked off '(spawn)' as PID 8412.
Feb 26 18:51:38 gentoodesktop systemd-udevd[8411]: 252:2: Device processed (SEQNUM=4517, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[8411]: 252:2: sd-device-monitor(worker): Passed 167 byte to netlink monitor.
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Process '/usr/sbin/disk-monitor.sh /dev/dm-2' succeeded.
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Device processed (SEQNUM=4516, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: sd-device-monitor(worker): Passed 963 byte to netlink monitor.
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: dm-2: Device ready for processing (SEQNUM=4518, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: dm-2: sd-device-monitor(manager): Passed 230 byte to netlink monitor.
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Processing device (SEQNUM=4518, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Removing watch handle -1.
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: /usr/lib/udev/rules.d/disk-monitor.rules:4 RUN '/usr/sbin/disk-monitor.sh $env{DEVNAME}'
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Running command "/usr/sbin/disk-monitor.sh /dev/dm-2"
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Starting '/usr/sbin/disk-monitor.sh /dev/dm-2'
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: Successfully forked off '(spawn)' as PID 8419.
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Process '/usr/sbin/disk-monitor.sh /dev/dm-2' succeeded.
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: Device processed (SEQNUM=4518, ACTION=remove)
Feb 26 18:51:38 gentoodesktop systemd-udevd[8410]: dm-2: sd-device-monitor(worker): Passed 230 byte to netlink monitor.
Feb 26 18:51:38 gentoodesktop systemd-udevd[7823]: No events are queued, removing /run/udev/queue.
Feb 26 18:51:42 gentoodesktop systemd-udevd[7823]: Cleanup idle workers
Feb 26 18:51:42 gentoodesktop systemd-udevd[8411]: Unload kernel module index.
Feb 26 18:51:42 gentoodesktop systemd-udevd[8410]: Unload kernel module index.
Feb 26 18:51:42 gentoodesktop systemd-udevd[8410]: Unloaded link configuration context.
Feb 26 18:51:42 gentoodesktop systemd-udevd[8411]: Unloaded link configuration context.
Feb 26 18:51:42 gentoodesktop systemd-udevd[7823]: Worker [8411] exited.
Feb 26 18:51:42 gentoodesktop systemd-udevd[7823]: Worker [8410] exited.
Feb 26 18:51:46 gentoodesktop systemd-udevd[7823]: Cleanup idle workers

答え1

ここでの問題は、あなたのRUN=scriptディレクティブがdmcryptが正しく機能するために必要な既存のディレクティブを上書きすることです。よりうまく機能することを確認するために試してみてくださいRUN+="/usr/sbin/disk-monitor.sh $env{DEVNAME}"(注+)。

これは本当にDEVNAME本当ですか?ブロックデバイスが持つことができる属性については教えてくれますが、それについてはman udev教えてくれません。$dev$devpath$devnodeDEVNAME

関連情報