Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * V9FS definitions.
0004  *
0005  *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
0006  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
0007  */
0008 #ifndef FS_9P_V9FS_H
0009 #define FS_9P_V9FS_H
0010 
0011 #include <linux/backing-dev.h>
0012 #include <linux/netfs.h>
0013 
0014 /**
0015  * enum p9_session_flags - option flags for each 9P session
0016  * @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions
0017  * @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions
0018  * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy
0019  * @V9FS_ACCESS_USER: a new attach will be issued for every user (default)
0020  * @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client.
0021  * @V9FS_ACCESS_ANY: use a single attach for all users
0022  * @V9FS_ACCESS_MASK: bit mask of different ACCESS options
0023  * @V9FS_POSIX_ACL: POSIX ACLs are enforced
0024  *
0025  * Session flags reflect options selected by users at mount time
0026  */
0027 #define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \
0028              V9FS_ACCESS_USER |   \
0029              V9FS_ACCESS_CLIENT)
0030 #define V9FS_ACCESS_MASK V9FS_ACCESS_ANY
0031 #define V9FS_ACL_MASK V9FS_POSIX_ACL
0032 
0033 enum p9_session_flags {
0034     V9FS_PROTO_2000U    = 0x01,
0035     V9FS_PROTO_2000L    = 0x02,
0036     V9FS_ACCESS_SINGLE  = 0x04,
0037     V9FS_ACCESS_USER    = 0x08,
0038     V9FS_ACCESS_CLIENT  = 0x10,
0039     V9FS_POSIX_ACL      = 0x20
0040 };
0041 
0042 /* possible values of ->cache */
0043 /**
0044  * enum p9_cache_modes - user specified cache preferences
0045  * @CACHE_NONE: do not cache data, dentries, or directory contents (default)
0046  * @CACHE_LOOSE: cache data, dentries, and directory contents w/no consistency
0047  *
0048  * eventually support loose, tight, time, session, default always none
0049  */
0050 
0051 enum p9_cache_modes {
0052     CACHE_NONE,
0053     CACHE_MMAP,
0054     CACHE_LOOSE,
0055     CACHE_FSCACHE,
0056     nr__p9_cache_modes
0057 };
0058 
0059 /**
0060  * struct v9fs_session_info - per-instance session information
0061  * @flags: session options of type &p9_session_flags
0062  * @nodev: set to 1 to disable device mapping
0063  * @debug: debug level
0064  * @afid: authentication handle
0065  * @cache: cache mode of type &p9_cache_modes
0066  * @cachetag: the tag of the cache associated with this session
0067  * @fscache: session cookie associated with FS-Cache
0068  * @uname: string user name to mount hierarchy as
0069  * @aname: mount specifier for remote hierarchy
0070  * @maxdata: maximum data to be sent/recvd per protocol message
0071  * @dfltuid: default numeric userid to mount hierarchy as
0072  * @dfltgid: default numeric groupid to mount hierarchy as
0073  * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy
0074  * @clnt: reference to 9P network client instantiated for this session
0075  * @slist: reference to list of registered 9p sessions
0076  *
0077  * This structure holds state for each session instance established during
0078  * a sys_mount() .
0079  *
0080  * Bugs: there seems to be a lot of state which could be condensed and/or
0081  * removed.
0082  */
0083 
0084 struct v9fs_session_info {
0085     /* options */
0086     unsigned char flags;
0087     unsigned char nodev;
0088     unsigned short debug;
0089     unsigned int afid;
0090     unsigned int cache;
0091 #ifdef CONFIG_9P_FSCACHE
0092     char *cachetag;
0093     struct fscache_volume *fscache;
0094 #endif
0095 
0096     char *uname;        /* user name to mount as */
0097     char *aname;        /* name of remote hierarchy being mounted */
0098     unsigned int maxdata;   /* max data for client interface */
0099     kuid_t dfltuid;     /* default uid/muid for legacy support */
0100     kgid_t dfltgid;     /* default gid for legacy support */
0101     kuid_t uid;     /* if ACCESS_SINGLE, the uid that has access */
0102     struct p9_client *clnt; /* 9p client */
0103     struct list_head slist; /* list of sessions registered with v9fs */
0104     struct rw_semaphore rename_sem;
0105     long session_lock_timeout; /* retry interval for blocking locks */
0106 };
0107 
0108 /* cache_validity flags */
0109 #define V9FS_INO_INVALID_ATTR 0x01
0110 
0111 struct v9fs_inode {
0112     struct netfs_inode netfs; /* Netfslib context and vfs inode */
0113     struct p9_qid qid;
0114     unsigned int cache_validity;
0115     struct p9_fid *writeback_fid;
0116     struct mutex v_mutex;
0117 };
0118 
0119 static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
0120 {
0121     return container_of(inode, struct v9fs_inode, netfs.inode);
0122 }
0123 
0124 static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode)
0125 {
0126 #ifdef CONFIG_9P_FSCACHE
0127     return netfs_i_cookie(&v9inode->netfs);
0128 #else
0129     return NULL;
0130 #endif
0131 }
0132 
0133 static inline struct fscache_volume *v9fs_session_cache(struct v9fs_session_info *v9ses)
0134 {
0135 #ifdef CONFIG_9P_FSCACHE
0136     return v9ses->fscache;
0137 #else
0138     return NULL;
0139 #endif
0140 }
0141 
0142 
0143 extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
0144 
0145 struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
0146                  const char *dev_name, char *data);
0147 extern void v9fs_session_close(struct v9fs_session_info *v9ses);
0148 extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
0149 extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);
0150 extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
0151                       unsigned int flags);
0152 extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
0153 extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
0154 extern int v9fs_vfs_rename(struct user_namespace *mnt_userns,
0155                struct inode *old_dir, struct dentry *old_dentry,
0156                struct inode *new_dir, struct dentry *new_dentry,
0157                unsigned int flags);
0158 extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
0159                      struct p9_fid *fid,
0160                      struct super_block *sb, int new);
0161 extern const struct inode_operations v9fs_dir_inode_operations_dotl;
0162 extern const struct inode_operations v9fs_file_inode_operations_dotl;
0163 extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
0164 extern const struct netfs_request_ops v9fs_req_ops;
0165 extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,
0166                           struct p9_fid *fid,
0167                           struct super_block *sb, int new);
0168 
0169 /* other default globals */
0170 #define V9FS_PORT   564
0171 #define V9FS_DEFUSER    "nobody"
0172 #define V9FS_DEFANAME   ""
0173 #define V9FS_DEFUID KUIDT_INIT(-2)
0174 #define V9FS_DEFGID KGIDT_INIT(-2)
0175 
0176 static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
0177 {
0178     return inode->i_sb->s_fs_info;
0179 }
0180 
0181 static inline struct v9fs_session_info *v9fs_dentry2v9ses(struct dentry *dentry)
0182 {
0183     return dentry->d_sb->s_fs_info;
0184 }
0185 
0186 static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses)
0187 {
0188     return v9ses->flags & V9FS_PROTO_2000U;
0189 }
0190 
0191 static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
0192 {
0193     return v9ses->flags & V9FS_PROTO_2000L;
0194 }
0195 
0196 /**
0197  * v9fs_get_inode_from_fid - Helper routine to populate an inode by
0198  * issuing a attribute request
0199  * @v9ses: session information
0200  * @fid: fid to issue attribute request for
0201  * @sb: superblock on which to create inode
0202  *
0203  */
0204 static inline struct inode *
0205 v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
0206             struct super_block *sb)
0207 {
0208     if (v9fs_proto_dotl(v9ses))
0209         return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0);
0210     else
0211         return v9fs_inode_from_fid(v9ses, fid, sb, 0);
0212 }
0213 
0214 /**
0215  * v9fs_get_new_inode_from_fid - Helper routine to populate an inode by
0216  * issuing a attribute request
0217  * @v9ses: session information
0218  * @fid: fid to issue attribute request for
0219  * @sb: superblock on which to create inode
0220  *
0221  */
0222 static inline struct inode *
0223 v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
0224                 struct super_block *sb)
0225 {
0226     if (v9fs_proto_dotl(v9ses))
0227         return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);
0228     else
0229         return v9fs_inode_from_fid(v9ses, fid, sb, 1);
0230 }
0231 
0232 #endif