From d20d41c7a550559501ff6d45c18a8cb8e7ce2e0d Mon Sep 17 00:00:00 2001 From: "daniel.zatovic" Date: Tue, 15 Mar 2022 21:05:46 +0100 Subject: [PATCH] Add log messages, when kernel doesn't support resize. --- lib/setup.c | 13 +++++++++++++ lib/utils_dm.h | 1 + src/integritysetup.c | 3 +++ 3 files changed, 17 insertions(+) diff --git a/lib/setup.c b/lib/setup.c index 75d744cd..7c4519d1 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -2858,6 +2858,8 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size) struct crypt_dm_active_device dmdq, dmd = {}; struct dm_target *tgt = &dmdq.segment; struct crypt_params_integrity params = {}; + uint32_t supported_flags = 0; + uint64_t old_size; int r; /* @@ -2921,6 +2923,11 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size) * superblock. */ if (!new_size && tgt->type == DM_INTEGRITY) { + r = INTEGRITY_data_sectors(cd, crypt_metadata_device(cd), + crypt_get_data_offset(cd) * SECTOR_SIZE, &old_size); + if (r < 0) + return r; + dmd.size = dmdq.size; dmd.flags = dmdq.flags | CRYPT_ACTIVATE_REFRESH | CRYPT_ACTIVATE_PRIVATE; @@ -2943,6 +2950,9 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size) if (r < 0) return r; log_dbg(cd, "Maximum integrity device size from kernel %lu", new_size); + + if (old_size == new_size && new_size == dmdq.size && !dm_flags(cd, tgt->type, &supported_flags) && !(supported_flags & DM_INTEGRITY_RESIZE_SUPPORTED)) + log_std(cd, _("WARNING: Maximum size already set or kernel doesn't support resize.\n")); } r = device_block_adjust(cd, crypt_data_device(cd), DEV_OK, @@ -2998,6 +3008,9 @@ int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size) r = LUKS2_unmet_requirements(cd, &cd->u.luks2.hdr, 0, 0); if (!r) r = _reload_device(cd, name, &dmd); + + if (r && tgt->type == DM_INTEGRITY && !dm_flags(cd, tgt->type, &supported_flags) && !(supported_flags & DM_INTEGRITY_RESIZE_SUPPORTED)) + log_err(cd, _("Resize failed, the kernel doesn't support it.")); } out: dm_targets_free(cd, &dmd); diff --git a/lib/utils_dm.h b/lib/utils_dm.h index 825d2299..547a7f9d 100644 --- a/lib/utils_dm.h +++ b/lib/utils_dm.h @@ -70,6 +70,7 @@ static inline uint32_t act2dmflags(uint32_t act_flags) #define DM_BITLK_ELEPHANT_SUPPORTED (1 << 21) /* Elephant diffuser for BITLK supported */ #define DM_VERITY_SIGNATURE_SUPPORTED (1 << 22) /* Verity option root_hash_sig_key_desc supported */ #define DM_INTEGRITY_DISCARDS_SUPPORTED (1 << 23) /* dm-integrity discards/TRIM option is supported */ +#define DM_INTEGRITY_RESIZE_SUPPORTED (1 << 23) /* dm-integrity resize of the integrity device supported (introduced in the same version as discards)*/ #define DM_VERITY_PANIC_CORRUPTION_SUPPORTED (1 << 24) /* dm-verity panic on corruption */ #define DM_CRYPT_NO_WORKQUEUE_SUPPORTED (1 << 25) /* dm-crypt suppot for bypassing workqueues */ #define DM_INTEGRITY_FIX_HMAC_SUPPORTED (1 << 26) /* hmac covers also superblock */ diff --git a/src/integritysetup.c b/src/integritysetup.c index 36bc00fc..7700f770 100644 --- a/src/integritysetup.c +++ b/src/integritysetup.c @@ -261,6 +261,9 @@ static int action_resize(void) } else { log_dbg("Setting recalculate flag"); r = crypt_activate_by_volume_key(cd, action_argv[0], NULL, 0, CRYPT_ACTIVATE_REFRESH | CRYPT_ACTIVATE_RECALCULATE); + + if (r == -ENOTSUP) + log_err(_("Setting recalculate flag is not supported, you may consider using --wipe instead.")); } } out: