loop_device_relinquish(setup.loop);
- r = dm_deferred_remove(setup.dm_name);
+ r = crypt_deactivate_by_name(NULL, setup.dm_name, CRYPT_DEACTIVATE_DEFERRED);
if (r < 0)
log_warning_errno(r, "Failed to relinquish DM device, ignoring: %m");
if (p->relinquished)
continue;
- r = dm_deferred_remove(p->name);
+ r = crypt_deactivate_by_name(NULL, p->name, CRYPT_DEACTIVATE_DEFERRED);
if (r < 0)
return log_debug_errno(r, "Failed to mark %s for auto-removal: %m", p->name);
#include "dm-util.h"
#include "fd-util.h"
#include "string-util.h"
-
-int dm_deferred_remove(const char *name) {
-
- struct dm_ioctl dm = {
- .version = {
- DM_VERSION_MAJOR,
- DM_VERSION_MINOR,
- DM_VERSION_PATCHLEVEL
- },
- .data_size = sizeof(dm),
- .flags = DM_DEFERRED_REMOVE,
- };
-
- _cleanup_close_ int fd = -1;
-
- assert(name);
-
- /* Unfortunately, libcryptsetup doesn't provide a proper API for this, hence call the ioctl()
- * directly. */
-
- if (strlen(name) >= sizeof(dm.name))
- return -ENODEV; /* A device with a name longer than this cannot possibly exist */
-
- fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
- if (fd < 0)
- return -errno;
-
- strncpy_exact(dm.name, name, sizeof(dm.name));
-
- if (ioctl(fd, DM_DEV_REMOVE, &dm))
- return -errno;
-
- return 0;
-}