Print blkid scan failure.

If old util-linux is used, blkid scan can fail because disk
is already locked for OPAL.
Do the same for other internal blkid issue.

Also add some debug messages to be clear what's going on.
This commit is contained in:
Milan Broz
2023-08-26 17:53:29 +02:00
parent 464fe987f9
commit 1969b6be2f
4 changed files with 32 additions and 7 deletions

View File

@@ -207,8 +207,11 @@ static int action_open_plain(void)
if (!ARG_UINT64(OPT_OFFSET_ID)) { if (!ARG_UINT64(OPT_OFFSET_ID)) {
/* Print all present signatures in read-only mode */ /* Print all present signatures in read-only mode */
r = tools_detect_signatures(action_argv[0], PRB_FILTER_NONE, &signatures, ARG_SET(OPT_BATCH_MODE_ID)); r = tools_detect_signatures(action_argv[0], PRB_FILTER_NONE, &signatures, ARG_SET(OPT_BATCH_MODE_ID));
if (r < 0) if (r < 0) {
if (r == -EIO)
log_err(_("Blkid scan failed for %s."), action_argv[0]);
goto out; goto out;
}
} }
if (signatures && !ARG_SET(OPT_BATCH_MODE_ID)) { if (signatures && !ARG_SET(OPT_BATCH_MODE_ID)) {
@@ -1303,8 +1306,11 @@ static int action_luksRepair(void)
} }
r = tools_detect_signatures(action_argv[0], PRB_FILTER_LUKS, NULL, ARG_SET(OPT_BATCH_MODE_ID)); r = tools_detect_signatures(action_argv[0], PRB_FILTER_LUKS, NULL, ARG_SET(OPT_BATCH_MODE_ID));
if (r < 0) if (r < 0) {
if (r == -EIO)
log_err(_("Blkid scan failed for %s."), action_argv[0]);
goto out; goto out;
}
if (!ARG_SET(OPT_BATCH_MODE_ID) && if (!ARG_SET(OPT_BATCH_MODE_ID) &&
!yesDialog(_("Really try to repair LUKS device header?"), !yesDialog(_("Really try to repair LUKS device header?"),
@@ -1490,8 +1496,11 @@ int luksFormat(struct crypt_device **r_cd, char **r_password, size_t *r_password
/* Print all present signatures in read-only mode */ /* Print all present signatures in read-only mode */
r = tools_detect_signatures(header_device, PRB_FILTER_NONE, &signatures, ARG_SET(OPT_BATCH_MODE_ID)); r = tools_detect_signatures(header_device, PRB_FILTER_NONE, &signatures, ARG_SET(OPT_BATCH_MODE_ID));
if (r < 0) if (r < 0) {
if (r == -EIO)
log_err(_("Blkid scan failed for %s."), header_device);
goto out; goto out;
}
if (!created && !ARG_SET(OPT_BATCH_MODE_ID)) { if (!created && !ARG_SET(OPT_BATCH_MODE_ID)) {
r = asprintf(&msg, _("This will overwrite data on %s irrevocably."), header_device); r = asprintf(&msg, _("This will overwrite data on %s irrevocably."), header_device);

View File

@@ -191,8 +191,11 @@ static int action_format(void)
} }
r = tools_detect_signatures(action_argv[0], PRB_FILTER_NONE, &signatures, ARG_SET(OPT_BATCH_MODE_ID)); r = tools_detect_signatures(action_argv[0], PRB_FILTER_NONE, &signatures, ARG_SET(OPT_BATCH_MODE_ID));
if (r < 0) if (r < 0) {
if (r == -EIO)
log_err(_("Blkid scan failed for %s."), action_argv[0]);
goto out; goto out;
}
/* Signature candidates found */ /* Signature candidates found */
if (signatures && ((r = tools_wipe_all_signatures(action_argv[0], true, false)) < 0)) if (signatures && ((r = tools_wipe_all_signatures(action_argv[0], true, false)) < 0))

View File

@@ -222,17 +222,22 @@ int tools_detect_signatures(const char *device, tools_probe_filter_info filter,
switch (filter) { switch (filter) {
case PRB_FILTER_LUKS: case PRB_FILTER_LUKS:
log_dbg("Blkid check (filter LUKS).");
if (blk_superblocks_filter_luks(h)) { if (blk_superblocks_filter_luks(h)) {
r = -EINVAL; r = -EINVAL;
log_dbg("Blkid filter LUKS probe failed.");
goto out; goto out;
} }
/* fall-through */ /* fall-through */
case PRB_FILTER_NONE: case PRB_FILTER_NONE:
log_dbg("Blkid check (filter none).");
blk_set_chains_for_full_print(h); blk_set_chains_for_full_print(h);
break; break;
case PRB_ONLY_LUKS: case PRB_ONLY_LUKS:
log_dbg("Blkid check (LUKS only).");
blk_set_chains_for_fast_detection(h); blk_set_chains_for_fast_detection(h);
if (blk_superblocks_only_luks(h)) { if (blk_superblocks_only_luks(h)) {
log_dbg("Blkid only LUKS probe failed.");
r = -EINVAL; r = -EINVAL;
goto out; goto out;
} }
@@ -251,8 +256,11 @@ int tools_detect_signatures(const char *device, tools_probe_filter_info filter,
(*count)++; (*count)++;
} }
if (pr == PRB_FAIL) if (pr == PRB_FAIL) {
r = -EINVAL; /* Expect device cannot be read */
r = -EIO;
log_dbg("Blkid probe failed.");
}
out: out:
blk_free(h); blk_free(h);
return r; return r;
@@ -302,6 +310,8 @@ int tools_wipe_all_signatures(const char *path, bool exclusive, bool only_luks)
goto out; goto out;
} }
log_dbg("Blkid wipe.");
while ((pr = blk_probe(h)) < PRB_EMPTY) { while ((pr = blk_probe(h)) < PRB_EMPTY) {
if (blk_is_partition(h)) if (blk_is_partition(h))
log_verbose(_("Existing '%s' partition signature on device %s will be wiped."), log_verbose(_("Existing '%s' partition signature on device %s will be wiped."),

View File

@@ -1329,8 +1329,11 @@ static int check_broken_luks_signature(const char *device)
size_t count; size_t count;
r = tools_detect_signatures(device, PRB_ONLY_LUKS, &count, ARG_SET(OPT_BATCH_MODE_ID)); r = tools_detect_signatures(device, PRB_ONLY_LUKS, &count, ARG_SET(OPT_BATCH_MODE_ID));
if (r < 0) if (r < 0) {
if (r == -EIO)
log_err(_("Blkid scan failed for %s."), device);
return -EINVAL; return -EINVAL;
}
if (count) { if (count) {
log_err(_("Device %s contains broken LUKS metadata. Aborting operation."), device); log_err(_("Device %s contains broken LUKS metadata. Aborting operation."), device);
return -EINVAL; return -EINVAL;