History

vfs: Implement logging through fs_context

Implement the ability for filesystems to log error, warning and informational messages through the fs_context. These can be extracted by userspace by reading from an fd created by fsopen(). Error messages are prefixed with "e ", warnings with "w " and informational messages with "i ". Inside the kernel, formatted messages are malloc'd but unformatted messages are not copied if they're either in the core .rodata section or in the .rodata section of the filesystem module pinned by fs_context::fs_type. The messages are only good till the fs_type is released. Note that the logging object is shared between duplicated fs_context structures. This is so that such as NFS which do a mount within a mount can get at least some of the errors from the inner mount. Five logging functions are provided for this: (1) void logfc(struct fs_context *fc, const char *fmt, ...); This logs a message into the context. If the buffer is full, the earliest message is discarded. (2) void errorf(fc, fmt, ...); This wraps logfc() to log an error. (3) void invalf(fc, fmt, ...); This wraps errorf() and returns -EINVAL for convenience. (4) void warnf(fc, fmt, ...); This wraps logfc() to log a warning. (5) void infof(fc, fmt, ...); This wraps logfc() to log an informational message.

David Howells committed 8 years ago

Commit 007ec261 parent 24dcb3d4 files · +179 −21Browse files

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/fs_context.h +15 −7
  2. include/linux/module.h +6 −0
include/linux/fs_context.h+15−7
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #define _LINUX_FS_CONTEXT_H
1414
1515 #include <linux/kernel.h>
16+#include <linux/refcount.h>
1617 #include <linux/errno.h>
1718 #include <linux/security.h>
1819 #include <linux/mutex.h>
@@ -95,6 +96,7 @@ struct fs_context { · 76 unmodified lines
9596 struct user_namespace *user_ns; /* The user namespace for this mount */
9697 struct net *net_ns; /* The network namespace for this mount */
9798 const struct cred *cred; /* The mounter's credentials */
99+ struct fc_log *log; /* Logging buffer */
98100 const char *source; /* The source name (eg. dev path) */
99101 const char *subtype; /* The subtype to set on the superblock */
100102 void *security; /* Linux S&M options */
@@ -151,15 +153,21 @@ extern int vfs_get_super(struct fs_context *fc, · 50 unmodified lines
151153
152154 extern const struct file_operations fscontext_fops;
153155
154−#ifdef CONFIG_PRINTK
156+/*
157+ * Mount error, warning and informational message logging. This structure is
158+ * shareable between a mount and a subordinate mount.
159+ */
160+struct fc_log {
161+ refcount_t usage;
162+ u8 head; /* Insertion index in buffer[] */
163+ u8 tail; /* Removal index in buffer[] */
164+ u8 need_free; /* Mask of kfree'able items in buffer[] */
165+ struct module *owner; /* Owner module for strings that don't then need freeing */
166+ char *buffer[8];
167+};
168+
155169 extern __attribute__((format(printf, 2, 3)))
156170 void logfc(struct fs_context *fc, const char *fmt, ...);
157−#else
158−static inline __attribute__((format(printf, 2, 3)))
159−void logfc(struct fs_context *fc, const char *fmt, ...)
160−{
161−}
162−#endif
163171
164172 /**
165173 * infof - Store supplementary informational message
include/linux/module.h+6−0
@@ -709,6 +709,12 @@ static inline bool is_module_text_address(unsigned long addr) · 708 unmodified lines
709709 return false;
710710 }
711711
712+static inline bool within_module_core(unsigned long addr,
713+ const struct module *mod)
714+{
715+ return false;
716+}
717+
712718 /* Get/put a kernel symbol (calls should be symmetric) */
713719 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
714720 #define symbol_put(x) do { } while (0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t