Skip to content

Commit ad7fe23

Browse files
cypharbrauner
authored andcommitted
fscontext: add custom-prefix log helpers
Sometimes, errors associated with an fscontext come from the VFS or otherwise outside of the filesystem driver itself. However, the default logging of errorfc will always prefix the message with the filesystem name. So, add some *fcp() wrappers that allow for custom prefixes to be used when emitting information to the fscontext log. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com> Link: https://lore.kernel.org/20250806-errorfc-mount-too-revealing-v2-1-534b9b4d45bb@cyphar.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 5e6de2a commit ad7fe23

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

include/linux/fs_context.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ struct fc_log {
186186
extern __attribute__((format(printf, 4, 5)))
187187
void logfc(struct fc_log *log, const char *prefix, char level, const char *fmt, ...);
188188

189-
#define __logfc(fc, l, fmt, ...) logfc((fc)->log.log, NULL, \
190-
l, fmt, ## __VA_ARGS__)
191-
#define __plog(p, l, fmt, ...) logfc((p)->log, (p)->prefix, \
192-
l, fmt, ## __VA_ARGS__)
189+
#define __logfc(fc, l, fmt, ...) \
190+
logfc((fc)->log.log, NULL, (l), (fmt), ## __VA_ARGS__)
191+
#define __plogp(p, prefix, l, fmt, ...) \
192+
logfc((p)->log, (prefix), (l), (fmt), ## __VA_ARGS__)
193+
#define __plog(p, l, fmt, ...) __plogp(p, (p)->prefix, l, fmt, ## __VA_ARGS__)
194+
193195
/**
194196
* infof - Store supplementary informational message
195197
* @fc: The context in which to log the informational message
@@ -201,6 +203,8 @@ void logfc(struct fc_log *log, const char *prefix, char level, const char *fmt,
201203
#define infof(fc, fmt, ...) __logfc(fc, 'i', fmt, ## __VA_ARGS__)
202204
#define info_plog(p, fmt, ...) __plog(p, 'i', fmt, ## __VA_ARGS__)
203205
#define infofc(fc, fmt, ...) __plog((&(fc)->log), 'i', fmt, ## __VA_ARGS__)
206+
#define infofcp(fc, prefix, fmt, ...) \
207+
__plogp((&(fc)->log), prefix, 'i', fmt, ## __VA_ARGS__)
204208

205209
/**
206210
* warnf - Store supplementary warning message
@@ -213,6 +217,8 @@ void logfc(struct fc_log *log, const char *prefix, char level, const char *fmt,
213217
#define warnf(fc, fmt, ...) __logfc(fc, 'w', fmt, ## __VA_ARGS__)
214218
#define warn_plog(p, fmt, ...) __plog(p, 'w', fmt, ## __VA_ARGS__)
215219
#define warnfc(fc, fmt, ...) __plog((&(fc)->log), 'w', fmt, ## __VA_ARGS__)
220+
#define warnfcp(fc, prefix, fmt, ...) \
221+
__plogp((&(fc)->log), prefix, 'w', fmt, ## __VA_ARGS__)
216222

217223
/**
218224
* errorf - Store supplementary error message
@@ -225,6 +231,8 @@ void logfc(struct fc_log *log, const char *prefix, char level, const char *fmt,
225231
#define errorf(fc, fmt, ...) __logfc(fc, 'e', fmt, ## __VA_ARGS__)
226232
#define error_plog(p, fmt, ...) __plog(p, 'e', fmt, ## __VA_ARGS__)
227233
#define errorfc(fc, fmt, ...) __plog((&(fc)->log), 'e', fmt, ## __VA_ARGS__)
234+
#define errorfcp(fc, prefix, fmt, ...) \
235+
__plogp((&(fc)->log), prefix, 'e', fmt, ## __VA_ARGS__)
228236

229237
/**
230238
* invalf - Store supplementary invalid argument error message
@@ -237,5 +245,7 @@ void logfc(struct fc_log *log, const char *prefix, char level, const char *fmt,
237245
#define invalf(fc, fmt, ...) (errorf(fc, fmt, ## __VA_ARGS__), -EINVAL)
238246
#define inval_plog(p, fmt, ...) (error_plog(p, fmt, ## __VA_ARGS__), -EINVAL)
239247
#define invalfc(fc, fmt, ...) (errorfc(fc, fmt, ## __VA_ARGS__), -EINVAL)
248+
#define invalfcp(fc, prefix, fmt, ...) \
249+
(errorfcp(fc, prefix, fmt, ## __VA_ARGS__), -EINVAL)
240250

241251
#endif /* _LINUX_FS_CONTEXT_H */

0 commit comments

Comments
 (0)