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
13#define _LINUX_FS_CONTEXT_H13#define _LINUX_FS_CONTEXT_H
14 14
15#include <linux/kernel.h>15#include <linux/kernel.h>
16#include <linux/refcount.h>
16#include <linux/errno.h>17#include <linux/errno.h>
17#include <linux/security.h>18#include <linux/security.h>
18#include <linux/mutex.h>19#include <linux/mutex.h>
@@ -95,6 +96,7 @@ struct fs_context { · 76 unmodified lines
95 struct user_namespace *user_ns; /* The user namespace for this mount */96 struct user_namespace *user_ns; /* The user namespace for this mount */
96 struct net *net_ns; /* The network namespace for this mount */97 struct net *net_ns; /* The network namespace for this mount */
97 const struct cred *cred; /* The mounter's credentials */98 const struct cred *cred; /* The mounter's credentials */
99 struct fc_log *log; /* Logging buffer */
98 const char *source; /* The source name (eg. dev path) */100 const char *source; /* The source name (eg. dev path) */
99 const char *subtype; /* The subtype to set on the superblock */101 const char *subtype; /* The subtype to set on the superblock */
100 void *security; /* Linux S&M options */102 void *security; /* Linux S&M options */
@@ -151,15 +153,21 @@ extern int vfs_get_super(struct fs_context *fc, · 50 unmodified lines
151 153
152extern const struct file_operations fscontext_fops;154extern const struct file_operations fscontext_fops;
153 155
154#ifdef CONFIG_PRINTK156/*
157 * Mount error, warning and informational message logging. This structure is
158 * shareable between a mount and a subordinate mount.
159 */
160struct 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
155extern __attribute__((format(printf, 2, 3)))169extern __attribute__((format(printf, 2, 3)))
156void logfc(struct fs_context *fc, const char *fmt, ...);170void logfc(struct fs_context *fc, const char *fmt, ...);
157#else
158static inline __attribute__((format(printf, 2, 3)))
159void logfc(struct fs_context *fc, const char *fmt, ...)
160{
161}
162#endif
163 171
164/**172/**
165 * infof - Store supplementary informational message173 * 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
709 return false;709 return false;
710}710}
711 711
712static inline bool within_module_core(unsigned long addr,
713 const struct module *mod)
714{
715 return false;
716}
717
712/* Get/put a kernel symbol (calls should be symmetric) */718/* Get/put a kernel symbol (calls should be symmetric) */
713#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })719#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
714#define symbol_put(x) do { } while (0)720#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