treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 36
[linux-block.git] / include / linux / fs_context.h
index eaca452088fa53034b0e64335e7b72719294e9ac..d476ff0c10dfd7deec2220c7a6a9a0f8a575d325 100644 (file)
@@ -1,20 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 /* Filesystem superblock creation and reconfiguration context.
  *
  * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
  * Written by David Howells (dhowells@redhat.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public Licence
- * as published by the Free Software Foundation; either version
- * 2 of the Licence, or (at your option) any later version.
  */
 
 #ifndef _LINUX_FS_CONTEXT_H
 #define _LINUX_FS_CONTEXT_H
 
 #include <linux/kernel.h>
+#include <linux/refcount.h>
 #include <linux/errno.h>
 #include <linux/security.h>
+#include <linux/mutex.h>
 
 struct cred;
 struct dentry;
@@ -34,6 +32,19 @@ enum fs_context_purpose {
        FS_CONTEXT_FOR_RECONFIGURE,     /* Superblock reconfiguration (remount) */
 };
 
+/*
+ * Userspace usage phase for fsopen/fspick.
+ */
+enum fs_context_phase {
+       FS_CONTEXT_CREATE_PARAMS,       /* Loading params for sb creation */
+       FS_CONTEXT_CREATING,            /* A superblock is being created */
+       FS_CONTEXT_AWAITING_MOUNT,      /* Superblock created, awaiting fsmount() */
+       FS_CONTEXT_AWAITING_RECONF,     /* Awaiting initialisation for reconfiguration */
+       FS_CONTEXT_RECONF_PARAMS,       /* Loading params for reconfiguration */
+       FS_CONTEXT_RECONFIGURING,       /* Reconfiguring the superblock */
+       FS_CONTEXT_FAILED,              /* Failed to correctly transition a context */
+};
+
 /*
  * Type of parameter value.
  */
@@ -74,12 +85,14 @@ struct fs_parameter {
  */
 struct fs_context {
        const struct fs_context_operations *ops;
+       struct mutex            uapi_mutex;     /* Userspace access mutex */
        struct file_system_type *fs_type;
        void                    *fs_private;    /* The filesystem's context */
        struct dentry           *root;          /* The root and superblock */
        struct user_namespace   *user_ns;       /* The user namespace for this mount */
        struct net              *net_ns;        /* The network namespace for this mount */
        const struct cred       *cred;          /* The mounter's credentials */
+       struct fc_log           *log;           /* Logging buffer */
        const char              *source;        /* The source name (eg. dev path) */
        const char              *subtype;       /* The subtype to set on the superblock */
        void                    *security;      /* Linux S&M options */
@@ -88,6 +101,7 @@ struct fs_context {
        unsigned int            sb_flags_mask;  /* Superblock flags that were changed */
        unsigned int            lsm_flags;      /* Information flags from the fs to the LSM */
        enum fs_context_purpose purpose:8;
+       enum fs_context_phase   phase:8;        /* The phase the context is in */
        bool                    need_free:1;    /* Need to call ops->free() */
        bool                    global:1;       /* Goes into &init_user_ns */
 };
@@ -135,15 +149,21 @@ extern int vfs_get_super(struct fs_context *fc,
 
 extern const struct file_operations fscontext_fops;
 
-#ifdef CONFIG_PRINTK
+/*
+ * Mount error, warning and informational message logging.  This structure is
+ * shareable between a mount and a subordinate mount.
+ */
+struct fc_log {
+       refcount_t      usage;
+       u8              head;           /* Insertion index in buffer[] */
+       u8              tail;           /* Removal index in buffer[] */
+       u8              need_free;      /* Mask of kfree'able items in buffer[] */
+       struct module   *owner;         /* Owner module for strings that don't then need freeing */
+       char            *buffer[8];
+};
+
 extern __attribute__((format(printf, 2, 3)))
 void logfc(struct fs_context *fc, const char *fmt, ...);
-#else
-static inline __attribute__((format(printf, 2, 3)))
-void logfc(struct fs_context *fc, const char *fmt, ...)
-{
-}
-#endif
 
 /**
  * infof - Store supplementary informational message