crypt_deactivate: fail earlier when holders detected

crypt_deactivate_* fail earlier without noisy dm retries
when other device holders detected. The early detection
works if:

a) other device-mapper device has a hold reference on the
   device

- or -

b) mounted fs is detected on the device

Any deactivation flag CRYPT_DEACTIVATE_FORCE or
CRYPT_DEACTIVATE_DEFERRED will disable this detection
This commit is contained in:
Ondrej Kozina
2017-10-16 16:41:43 +02:00
parent f901cb7b25
commit 961e65424e
4 changed files with 33 additions and 11 deletions

View File

@@ -1978,6 +1978,13 @@ int dm_query_device(struct crypt_device *cd, const char *name,
dmd->uuid = strdup(tmp_uuid + DM_UUID_PREFIX_LEN);
}
dmd->holders = 0;
#if (HAVE_DECL_DM_DEVICE_HAS_HOLDERS && HAVE_DECL_DM_DEVICE_HAS_MOUNTED_FS)
if (get_flags & DM_ACTIVE_HOLDERS)
dmd->holders = (dm_device_has_mounted_fs(dmi.major, dmi.minor) ||
dm_device_has_holders(dmi.major, dmi.minor));
#endif
r = (dmi.open_count > 0);
out:
if (dmt)