From 12f5fbdf30cbb917760cc1887abd19089d49b0a8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 17 Sep 2022 15:27:15 +0900 Subject: [PATCH] dissect-image: fix error handling of @cancel_deferred_remove DM command See target_message() in drivers/md/dm-ioctl.c and dm_cancel_deferred_remove() in drivers/md/dm.c. --- src/shared/dissect-image.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 77d6101cff9..6bfea815eed 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -2090,14 +2090,17 @@ static int verity_partition( if (!restore_deferred_remove){ /* To avoid races, disable automatic removal on umount while setting up the new device. Restore it on failure. */ r = dm_deferred_remove_cancel(name); - /* If activation returns EBUSY there might be no deferred removal to cancel, that's fine */ - if (r < 0 && r != -ENXIO) + /* -EBUSY and -ENXIO: the device has already been removed or being removed. We cannot + * use the device, try to open again. See target_message() in drivers/md/dm-ioctl.c + * and dm_cancel_deferred_remove() in drivers/md/dm.c */ + if (IN_SET(r, -EBUSY, -ENXIO)) + goto try_again; + if (r < 0) return log_debug_errno(r, "Failed to disable automated deferred removal for verity device %s: %m", node); - if (r >= 0) { - restore_deferred_remove = strdup(name); - if (!restore_deferred_remove) - return log_oom_debug(); - } + + restore_deferred_remove = strdup(name); + if (!restore_deferred_remove) + return log_oom_debug(); } r = verity_can_reuse(verity, name, &existing_cd);