mirror of
https://github.com/systemd/systemd
synced 2024-10-15 04:24:19 +00:00
gpt-auto-generator: "translate" errno codes into proper messages
E.g. in logs on jammy-ppc64el in https://github.com/systemd/systemd/pull/27294:
Apr 16 17:42:50 H systemd-gpt-auto-generator[300]: Failed to dissect partition table of block device /dev/sda: No message of desired type
Apr 16 17:42:50 H (sd-execu[295]: /usr/lib/systemd/system-generators/systemd-gpt-auto-generator failed with exit status 1.
ee0e6e476e
made this particular condition not an
error. But for other errnos we want to print a better message too.
dissect_loop_device_and_warn() already does this, but it always prints the
error at error level. We want to suppress some of the errors, so let's make the
print helper public and do the error suppression in the caller.
This commit is contained in:
parent
de47cd0610
commit
4953e39c70
|
@ -761,12 +761,11 @@ static int enumerate_partitions(dev_t devnum) {
|
||||||
* on. And thus we also don't set DISSECT_IMAGE_PIN_PARTITION_DEVICES here, because
|
* on. And thus we also don't set DISSECT_IMAGE_PIN_PARTITION_DEVICES here, because
|
||||||
* we don't actually mount anything immediately. */
|
* we don't actually mount anything immediately. */
|
||||||
&m);
|
&m);
|
||||||
if (r == -ENOPKG) {
|
if (r < 0) {
|
||||||
log_debug_errno(r, "No suitable partition table found on block device %s, ignoring.", devname);
|
bool ok = r == -ENOPKG;
|
||||||
return 0;
|
dissect_log_error(ok ? LOG_DEBUG : LOG_ERR, r, devname, NULL);
|
||||||
|
return ok ? 0 : r;
|
||||||
}
|
}
|
||||||
if (r < 0)
|
|
||||||
return log_error_errno(r, "Failed to dissect partition table of block device %s: %m", devname);
|
|
||||||
|
|
||||||
if (m->partitions[PARTITION_SWAP].found) {
|
if (m->partitions[PARTITION_SWAP].found) {
|
||||||
k = add_partition_swap(m->partitions + PARTITION_SWAP);
|
k = add_partition_swap(m->partitions + PARTITION_SWAP);
|
||||||
|
|
|
@ -1575,7 +1575,8 @@ int dissect_image_file(
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dissect_log_error(int r, const char *name, const VeritySettings *verity) {
|
int dissect_log_error(int log_level, int r, const char *name, const VeritySettings *verity) {
|
||||||
|
assert(log_level >= 0 && log_level <= LOG_DEBUG);
|
||||||
assert(name);
|
assert(name);
|
||||||
|
|
||||||
switch (r) {
|
switch (r) {
|
||||||
|
@ -1620,7 +1621,7 @@ static int dissect_log_error(int r, const char *name, const VeritySettings *veri
|
||||||
return log_error_errno(r, "%s: no suitable partitions found.", name);
|
return log_error_errno(r, "%s: no suitable partitions found.", name);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return log_error_errno(r, "Failed to dissect image '%s': %m", name);
|
return log_error_errno(r, "%s: cannot dissect image: %m", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1633,6 +1634,7 @@ int dissect_image_file_and_warn(
|
||||||
DissectedImage **ret) {
|
DissectedImage **ret) {
|
||||||
|
|
||||||
return dissect_log_error(
|
return dissect_log_error(
|
||||||
|
LOG_ERR,
|
||||||
dissect_image_file(path, verity, mount_options, image_policy, flags, ret),
|
dissect_image_file(path, verity, mount_options, image_policy, flags, ret),
|
||||||
path,
|
path,
|
||||||
verity);
|
verity);
|
||||||
|
@ -3560,6 +3562,7 @@ int dissect_loop_device_and_warn(
|
||||||
assert(loop);
|
assert(loop);
|
||||||
|
|
||||||
return dissect_log_error(
|
return dissect_log_error(
|
||||||
|
LOG_ERR,
|
||||||
dissect_loop_device(loop, verity, mount_options, image_policy, flags, ret),
|
dissect_loop_device(loop, verity, mount_options, image_policy, flags, ret),
|
||||||
loop->backing_file ?: loop->node,
|
loop->backing_file ?: loop->node,
|
||||||
verity);
|
verity);
|
||||||
|
|
|
@ -147,6 +147,7 @@ static inline int probe_filesystem(const char *path, char **ret_fstype) {
|
||||||
return probe_filesystem_full(-1, path, 0, UINT64_MAX, ret_fstype);
|
return probe_filesystem_full(-1, path, 0, UINT64_MAX, ret_fstype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dissect_log_error(int log_level, int r, const char *name, const VeritySettings *verity);
|
||||||
int dissect_image_file(const char *path, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
|
int dissect_image_file(const char *path, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
|
||||||
int dissect_image_file_and_warn(const char *path, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
|
int dissect_image_file_and_warn(const char *path, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
|
||||||
int dissect_loop_device(LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
|
int dissect_loop_device(LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
|
||||||
|
|
Loading…
Reference in a new issue