Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move error messages to hooksets #2314

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

karelzak
Copy link
Collaborator

Now libmount supports many syscalls, additional modules (etc.), and it does not make sense to maintain all error messages in one huge function. This PR adds the possibility to maintain code and error messages in "hooksets" in one place.

Later we can add more specific error messages to other places (id-mapping, verity, ...).

This patch introduces "failure save". The syscall status is subset of
the saved failure, but the failure can be used also for non-syscall
issues.

* save SYS_* numbers rather than names for syscalls. It will make error
  generators more simple (just switch(cxt->failure_syscall))

* save hookset; it will be later used to call hookset specific error
  message generator

* optionally save "failure command", for example syscall sub-command (FSCONFIG_CMD_*) or
  some hook specific stuff

* optionally save "failure argument" as string (to make error messages
  more human friendly)

* use line and filename in debug message for failures

Note that the way how libmount uses syscall_status is not affected by
this patch, because this field is used by public API.

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
It helps to maintain mount syscall-specific error messages on place
where we use the syscalls.

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Comment on lines +567 to +571
switch (cxt->failure_syscall) {
case SYS_open:
errsnprint(buf, sz, er, _("cannot open %s: %m"), cxt->failure_arg);
break;
}

Check notice

Code scanning / CodeQL

No trivial switch statements Note

This switch statement should either handle more cases, or be rewritten as an if statement.
@@ -317,12 +317,202 @@
return rc;
}

/* mount(2) syscall errors */
static int hookset_mkerrmsg(

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 186 lines.
@@ -1217,6 +1217,27 @@ int ul_optstr_next(char **optstr, char **name, size_t *namesz,
return 1; /* end of optstr */
}

int errsnprint(char *buf, size_t bufsz, int errnum, const char *fmt, ...)
Copy link
Member

@t-8ch t-8ch Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems weird.

The advantage of "%m" is that it saves a "%s", strerror(errno).
It is non-standard and of limited advantage.

Instead of introducing a custom helper to do the same with arbitrary errnum the user could just specify "%s", strerror(errnum).

(Also it should probably be called errsnprintf)

@@ -181,7 +183,7 @@ static int setup_loopdev(struct libmnt_context *cxt,
* encryption=
*/
if (!rc && mnt_optlist_get_opt(ol, MNT_MS_ENCRYPTION, cxt->map_userspace)) {
DBG(LOOP, ul_debugobj(cxt, "encryption no longer supported"));
mnt_context_save_failure(cxt, hs, 0, EINVAL, MNT_MS_ENCRYPTION, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below both the debugging and mnt_context_save_failure() are kept.
Here the debugging is dropped. Is this intentional?

if (er == EINVAL) {
switch (cxt->failure_cmd) {
case MNT_MS_OFFSET:
case MNT_MS_SIZELIMIT:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mechanism disconnects the location where the error is encountered in the code from the message that is generated.
So to go from an error message to the respective code location developers have to work backwards from this switch-case statement.

What about formatting the message as part of the call to mnt_context_save_failure()?

This would also remove the need to figure unique error discriminants for each error site.

@karelzak
Copy link
Collaborator Author

This PR is deprecated; we need something better :-).

IMHO, it is fine to move error handling to hook_xxxx.c files, but the way the library creates and maintains the error messages should be different. @t-8ch is right that it would be better to compose the message in the place where the error occurred (and probably save additional data like the syscall number, etc).

It should also work with how the kernel delivers messages by the new mount API, which means supporting more kinds of messages (not just errors only, but also warnings, notices, etc.). Maybe we can create a log (linked list) in the context with all the messages, and the failed syscall will be just one item in the log.

For v2.40 I'd like to use minimalistic #2809.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants