Skip to content

Commit b6ddaa4

Browse files
onikombroz
authored andcommitted
Refactor tcrypt subdev check in a helper routine.
Add comments what parts will be removed later.
1 parent 1c75cd0 commit b6ddaa4

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

lib/tcrypt/tcrypt.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,24 @@ int TCRYPT_activate(struct crypt_device *cd,
926926
return r;
927927
}
928928

929+
static bool is_tcrypt_subdev(const char *dm_uuid, const char *base_uuid)
930+
{
931+
assert(base_uuid);
932+
933+
if (!dm_uuid)
934+
return false;
935+
936+
if (!strncmp(dm_uuid, "SUBDEV-", 7))
937+
/* dm_uuid + 6 because function requires dm_uuid to contain '-' */
938+
return !dm_uuid_cmp(dm_uuid + 6, strchr(base_uuid, '-'));
939+
940+
/*
941+
* FIXME: Drop after shift to dependency based deactivation (CRYPT_SUBDEV)
942+
* in later releases
943+
*/
944+
return !strncmp(dm_uuid, base_uuid, strlen(base_uuid));
945+
}
946+
929947
static int TCRYPT_remove_one(struct crypt_device *cd, const char *name,
930948
const char *base_uuid, int index, uint32_t flags)
931949
{
@@ -941,9 +959,7 @@ static int TCRYPT_remove_one(struct crypt_device *cd, const char *name,
941959
return r;
942960

943961
r = dm_query_device(cd, dm_name, DM_ACTIVE_UUID, &dmd);
944-
if (!r &&
945-
(!strncmp(dmd.uuid, base_uuid, strlen(base_uuid)) ||
946-
!dm_uuid_cmp(dmd.uuid, strchr(base_uuid, '-'))))
962+
if (!r && is_tcrypt_subdev(dmd.uuid, base_uuid))
947963
r = dm_remove_device(cd, dm_name, flags);
948964

949965
free(CONST_CAST(void*)dmd.uuid);

0 commit comments

Comments
 (0)