/* SPDX-License-Identifier: GPL-2.0-only */1/*2* V9FS definitions.3*4* Copyright (C) 2004-2008 by Eric Van Hensbergen <[email protected]>5* Copyright (C) 2002 by Ron Minnich <[email protected]>6*/7#ifndef FS_9P_V9FS_H8#define FS_9P_V9FS_H910#include <linux/backing-dev.h>11#include <linux/netfs.h>1213/**14* enum p9_session_flags - option flags for each 9P session15* @V9FS_PROTO_2000U: whether or not to use 9P2000.u extensions16* @V9FS_PROTO_2000L: whether or not to use 9P2000.l extensions17* @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy18* @V9FS_ACCESS_USER: a new attach will be issued for every user (default)19* @V9FS_ACCESS_CLIENT: Just like user, but access check is performed on client.20* @V9FS_ACCESS_ANY: use a single attach for all users21* @V9FS_ACCESS_MASK: bit mask of different ACCESS options22* @V9FS_POSIX_ACL: POSIX ACLs are enforced23*24* Session flags reflect options selected by users at mount time25*/26#define V9FS_ACCESS_ANY (V9FS_ACCESS_SINGLE | \27V9FS_ACCESS_USER | \28V9FS_ACCESS_CLIENT)29#define V9FS_ACCESS_MASK V9FS_ACCESS_ANY30#define V9FS_ACL_MASK V9FS_POSIX_ACL3132enum p9_session_flags {33V9FS_PROTO_2000U = 0x01,34V9FS_PROTO_2000L = 0x02,35V9FS_ACCESS_SINGLE = 0x04,36V9FS_ACCESS_USER = 0x08,37V9FS_ACCESS_CLIENT = 0x10,38V9FS_POSIX_ACL = 0x20,39V9FS_NO_XATTR = 0x40,40V9FS_IGNORE_QV = 0x80, /* ignore qid.version for cache hints */41V9FS_DIRECT_IO = 0x100,42V9FS_SYNC = 0x20043};4445/**46* enum p9_cache_shortcuts - human readable cache preferences47* @CACHE_SC_NONE: disable all caches48* @CACHE_SC_READAHEAD: only provide caching for readahead49* @CACHE_SC_MMAP: provide caching to enable mmap50* @CACHE_SC_LOOSE: non-coherent caching for files and meta data51* @CACHE_SC_FSCACHE: persistent non-coherent caching for files and meta-data52*53*/5455enum p9_cache_shortcuts {56CACHE_SC_NONE = 0b00000000,57CACHE_SC_READAHEAD = 0b00000001,58CACHE_SC_MMAP = 0b00000101,59CACHE_SC_LOOSE = 0b00001111,60CACHE_SC_FSCACHE = 0b10001111,61};6263/**64* enum p9_cache_bits - possible values of ->cache65* @CACHE_NONE: caches disabled66* @CACHE_FILE: file caching (open to close)67* @CACHE_META: meta-data and directory caching68* @CACHE_WRITEBACK: write-back caching for files69* @CACHE_LOOSE: don't check cache consistency70* @CACHE_FSCACHE: local persistent caches71*72*/7374enum p9_cache_bits {75CACHE_NONE = 0b00000000,76CACHE_FILE = 0b00000001,77CACHE_META = 0b00000010,78CACHE_WRITEBACK = 0b00000100,79CACHE_LOOSE = 0b00001000,80CACHE_FSCACHE = 0b10000000,81};8283/**84* struct v9fs_session_info - per-instance session information85* @flags: session options of type &p9_session_flags86* @nodev: set to 1 to disable device mapping87* @debug: debug level88* @afid: authentication handle89* @cache: cache mode of type &p9_cache_bits90* @cachetag: the tag of the cache associated with this session91* @fscache: session cookie associated with FS-Cache92* @uname: string user name to mount hierarchy as93* @aname: mount specifier for remote hierarchy94* @maxdata: maximum data to be sent/recvd per protocol message95* @dfltuid: default numeric userid to mount hierarchy as96* @dfltgid: default numeric groupid to mount hierarchy as97* @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy98* @clnt: reference to 9P network client instantiated for this session99* @slist: reference to list of registered 9p sessions100*101* This structure holds state for each session instance established during102* a sys_mount() .103*104* Bugs: there seems to be a lot of state which could be condensed and/or105* removed.106*/107108struct v9fs_session_info {109/* options */110unsigned int flags;111unsigned char nodev;112unsigned short debug;113unsigned int afid;114unsigned int cache;115#ifdef CONFIG_9P_FSCACHE116char *cachetag;117struct fscache_volume *fscache;118#endif119120char *uname; /* user name to mount as */121char *aname; /* name of remote hierarchy being mounted */122unsigned int maxdata; /* max data for client interface */123kuid_t dfltuid; /* default uid/muid for legacy support */124kgid_t dfltgid; /* default gid for legacy support */125kuid_t uid; /* if ACCESS_SINGLE, the uid that has access */126struct p9_client *clnt; /* 9p client */127struct list_head slist; /* list of sessions registered with v9fs */128struct rw_semaphore rename_sem;129long session_lock_timeout; /* retry interval for blocking locks */130};131132/* cache_validity flags */133#define V9FS_INO_INVALID_ATTR 0x01134135struct v9fs_inode {136struct netfs_inode netfs; /* Netfslib context and vfs inode */137struct p9_qid qid;138unsigned int cache_validity;139struct mutex v_mutex;140};141142static inline struct v9fs_inode *V9FS_I(const struct inode *inode)143{144return container_of(inode, struct v9fs_inode, netfs.inode);145}146147static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode)148{149#ifdef CONFIG_9P_FSCACHE150return netfs_i_cookie(&v9inode->netfs);151#else152return NULL;153#endif154}155156static inline struct fscache_volume *v9fs_session_cache(struct v9fs_session_info *v9ses)157{158#ifdef CONFIG_9P_FSCACHE159return v9ses->fscache;160#else161return NULL;162#endif163}164165166extern int v9fs_show_options(struct seq_file *m, struct dentry *root);167168struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,169const char *dev_name, char *data);170extern void v9fs_session_close(struct v9fs_session_info *v9ses);171extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);172extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);173extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,174unsigned int flags);175extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);176extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);177extern int v9fs_vfs_rename(struct mnt_idmap *idmap,178struct inode *old_dir, struct dentry *old_dentry,179struct inode *new_dir, struct dentry *new_dentry,180unsigned int flags);181extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,182struct p9_fid *fid,183struct super_block *sb, int new);184extern const struct inode_operations v9fs_dir_inode_operations_dotl;185extern const struct inode_operations v9fs_file_inode_operations_dotl;186extern const struct inode_operations v9fs_symlink_inode_operations_dotl;187extern const struct netfs_request_ops v9fs_req_ops;188extern struct inode *v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses,189struct p9_fid *fid,190struct super_block *sb, int new);191192/* other default globals */193#define V9FS_PORT 564194#define V9FS_DEFUSER "nobody"195#define V9FS_DEFANAME ""196#define V9FS_DEFUID KUIDT_INIT(-2)197#define V9FS_DEFGID KGIDT_INIT(-2)198199static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)200{201return inode->i_sb->s_fs_info;202}203204static inline struct v9fs_session_info *v9fs_dentry2v9ses(const struct dentry *dentry)205{206return dentry->d_sb->s_fs_info;207}208209static inline int v9fs_proto_dotu(struct v9fs_session_info *v9ses)210{211return v9ses->flags & V9FS_PROTO_2000U;212}213214static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)215{216return v9ses->flags & V9FS_PROTO_2000L;217}218219/**220* v9fs_get_inode_from_fid - Helper routine to populate an inode by221* issuing a attribute request222* @v9ses: session information223* @fid: fid to issue attribute request for224* @sb: superblock on which to create inode225*226*/227static inline struct inode *228v9fs_get_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,229struct super_block *sb)230{231if (v9fs_proto_dotl(v9ses))232return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 0);233else234return v9fs_inode_from_fid(v9ses, fid, sb, 0);235}236237/**238* v9fs_get_new_inode_from_fid - Helper routine to populate an inode by239* issuing a attribute request240* @v9ses: session information241* @fid: fid to issue attribute request for242* @sb: superblock on which to create inode243*244*/245static inline struct inode *246v9fs_get_new_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,247struct super_block *sb)248{249if (v9fs_proto_dotl(v9ses))250return v9fs_inode_from_fid_dotl(v9ses, fid, sb, 1);251else252return v9fs_inode_from_fid(v9ses, fid, sb, 1);253}254255#endif256257258