From 614f671b92f411227610eb7cd20d785b03a72a28 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Fri, 21 Jun 2019 10:30:14 +0200 Subject: [PATCH] Introduce SUBDEV internal device type. LUKS2 and other device types allow stacking of dm devices underneath public top level device. The new type identifies clearly those private devices in respective device stack so that they can be easily removed while removing top level public device. Switch LUKS2 reencryption device stack to use SUBDEV type immmediately for hotzone and overlay devices. Other devices will follow in later releases. --- lib/internal.h | 2 ++ lib/luks2/luks2_json_metadata.c | 8 ++++---- lib/luks2/luks2_reencrypt.c | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/internal.h b/lib/internal.h index 31adffda..c8509095 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -56,6 +56,8 @@ #define LOG_MAX_LEN 4096 #define MAX_DM_DEPS 32 +#define CRYPT_SUBDEV "SUBDEV" /* prefix for sublayered devices underneath public crypt types */ + #define at_least(a, b) ({ __typeof__(a) __at_least = (a); (__at_least >= (b))?__at_least:(b); }) #define MISALIGNED(a, b) ((a) & ((b) - 1)) diff --git a/lib/luks2/luks2_json_metadata.c b/lib/luks2/luks2_json_metadata.c index f2ec192a..df2c316d 100644 --- a/lib/luks2/luks2_json_metadata.c +++ b/lib/luks2/luks2_json_metadata.c @@ -2209,20 +2209,20 @@ int LUKS2_deactivate(struct crypt_device *cd, const char *name, struct luks2_hdr struct dm_target *tgt; crypt_status_info ci; struct crypt_dm_active_device dmdc; - char **dep, uuid[37], deps_uuid_prefix[38], *deps[MAX_DM_DEPS+1] = { 0 }; + char **dep, uuid[37], deps_uuid_prefix[40], *deps[MAX_DM_DEPS+1] = { 0 }; const char *namei = NULL; struct crypt_lock_handle *reencrypt_lock = NULL; if (!dmd || !dmd->uuid) return -EINVAL; - r = snprintf(deps_uuid_prefix, sizeof(deps_uuid_prefix), "TEMP-%.32s", dmd->uuid + 6); - if (r < 0 || (size_t)r != 37) + r = snprintf(deps_uuid_prefix, sizeof(deps_uuid_prefix), CRYPT_SUBDEV "-%.32s", dmd->uuid + 6); + if (r < 0 || (size_t)r != (sizeof(deps_uuid_prefix) - 1)) return -EINVAL; r = snprintf(uuid, sizeof(uuid), "%.8s-%.4s-%.4s-%.4s-%.12s", dmd->uuid + 6, dmd->uuid + 14, dmd->uuid + 18, dmd->uuid + 22, dmd->uuid + 26); - if (r < 0 || (size_t)r != 36) + if (r < 0 || (size_t)r != (sizeof(uuid) - 1)) return -EINVAL; /* uuid mismatch with metadata (if available) */ diff --git a/lib/luks2/luks2_reencrypt.c b/lib/luks2/luks2_reencrypt.c index 665bf9df..d19c6216 100644 --- a/lib/luks2/luks2_reencrypt.c +++ b/lib/luks2/luks2_reencrypt.c @@ -1877,7 +1877,7 @@ static int reenc_replace_device(struct crypt_device *cd, const char *target, con r = dm_resume_device(cd, target, dmflags | act2dmflags(dmd_source.flags)); } } else - r = dm_create_device(cd, target, "TEMP", &dmd_source); + r = dm_create_device(cd, target, CRYPT_SUBDEV, &dmd_source); err: dm_targets_free(cd, &dmd_source); dm_targets_free(cd, &dmd_target); @@ -1954,7 +1954,7 @@ static int reenc_activate_hotzone_device(struct crypt_device *cd, const char *na if (r) goto err; - r = dm_create_device(cd, name, "TEMP", &dmd); + r = dm_create_device(cd, name, CRYPT_SUBDEV, &dmd); err: dm_targets_free(cd, &dmd);