-
Notifications
You must be signed in to change notification settings - Fork 1.2k
move error messages to hooksets #2314
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
base: master
Are you sure you want to change the base?
Conversation
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 <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
It helps to maintain mount syscall-specific error messages on place where we use the syscalls. Signed-off-by: Karel Zak <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
Signed-off-by: Karel Zak <[email protected]>
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
@@ -317,12 +317,202 @@ | |||
return rc; | |||
} | |||
|
|||
/* mount(2) syscall errors */ | |||
static int hookset_mkerrmsg( |
Check warning
Code scanning / CodeQL
Poorly documented large function
@@ -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, ...) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
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. |
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, ...).