blob: 2c43d10e3cab419642cd0b28de4c3e55ff1d7cc2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
J. Bruce Fields0a3adad2009-11-04 18:12:35 -05002/*
3 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
4 */
5
6#ifndef LINUX_NFSD_VFS_H
7#define LINUX_NFSD_VFS_H
8
J. Bruce Fields1557aca2009-12-04 19:36:06 -05009#include "nfsfh.h"
Al Viro3dadecc2013-01-24 02:18:08 -050010#include "nfsd.h"
J. Bruce Fields1557aca2009-12-04 19:36:06 -050011
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050012/*
13 * Flags for nfsd_permission
14 */
J. Bruce Fields8e82fa82011-08-25 14:23:39 -040015#define NFSD_MAY_NOP 0
16#define NFSD_MAY_EXEC 0x001 /* == MAY_EXEC */
17#define NFSD_MAY_WRITE 0x002 /* == MAY_WRITE */
18#define NFSD_MAY_READ 0x004 /* == MAY_READ */
19#define NFSD_MAY_SATTR 0x008
20#define NFSD_MAY_TRUNC 0x010
21#define NFSD_MAY_LOCK 0x020
22#define NFSD_MAY_MASK 0x03f
J. Bruce Fieldsaea93392011-04-10 10:35:12 -040023
24/* extra hints to permission and open routines: */
J. Bruce Fields8e82fa82011-08-25 14:23:39 -040025#define NFSD_MAY_OWNER_OVERRIDE 0x040
26#define NFSD_MAY_LOCAL_ACCESS 0x080 /* for device special files */
27#define NFSD_MAY_BYPASS_GSS_ON_ROOT 0x100
28#define NFSD_MAY_NOT_BREAK_LEASE 0x200
29#define NFSD_MAY_BYPASS_GSS 0x400
30#define NFSD_MAY_READ_IF_EXEC 0x800
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050031
Bernd Schubert06effdb2012-03-18 22:44:50 -040032#define NFSD_MAY_64BIT_COOKIE 0x1000 /* 64 bit readdir cookies for >= NFSv3 */
33
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050034#define NFSD_MAY_CREATE (NFSD_MAY_EXEC|NFSD_MAY_WRITE)
35#define NFSD_MAY_REMOVE (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
36
Trond Myklebust16f8f892020-01-06 13:40:29 -050037struct nfsd_file;
38
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050039/*
40 * Callback function for readdir
41 */
Miklos Szerediac7576f2014-10-30 17:37:34 +010042typedef int (*nfsd_filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050043
44/* nfsd/vfs.c */
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050045int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
46 struct svc_export **expp);
47__be32 nfsd_lookup(struct svc_rqst *, struct svc_fh *,
48 const char *, unsigned int, struct svc_fh *);
49__be32 nfsd_lookup_dentry(struct svc_rqst *, struct svc_fh *,
50 const char *, unsigned int,
51 struct svc_export **, struct dentry **);
52__be32 nfsd_setattr(struct svc_rqst *, struct svc_fh *,
Arnd Bergmann2a1aa482019-11-03 17:50:18 +010053 struct iattr *, int, time64_t);
J. Bruce Fields3227fa42009-10-25 21:43:01 -040054int nfsd_mountpoint(struct dentry *, struct svc_export *);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050055#ifdef CONFIG_NFSD_V4
David Quigley18032ca2013-05-02 13:19:10 -040056__be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *,
57 struct xdr_netobj *);
Anna Schumaker95d871f2014-11-07 14:44:26 -050058__be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *,
59 struct file *, loff_t, loff_t, int);
Trond Myklebusta2f4c3f2021-12-18 20:38:00 -050060__be32 nfsd4_clone_file_range(struct svc_rqst *rqstp,
61 struct nfsd_file *nf_src, u64 src_pos,
Trond Myklebustb66ae6d2020-01-06 13:40:32 -050062 struct nfsd_file *nf_dst, u64 dst_pos,
63 u64 count, bool sync);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050064#endif /* CONFIG_NFSD_V4 */
J. Bruce Fieldsb44061d2016-07-20 16:16:06 -040065__be32 nfsd_create_locked(struct svc_rqst *, struct svc_fh *,
66 char *name, int len, struct iattr *attrs,
67 int type, dev_t rdev, struct svc_fh *res);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050068__be32 nfsd_create(struct svc_rqst *, struct svc_fh *,
69 char *name, int len, struct iattr *attrs,
70 int type, dev_t rdev, struct svc_fh *res);
71#ifdef CONFIG_NFSD_V3
72__be32 nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
Mi Jinlongac6721a2011-04-20 17:06:25 +080073__be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *,
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050074 char *name, int len, struct iattr *attrs,
75 struct svc_fh *res, int createmode,
J. Bruce Fields856121b2011-10-13 11:37:11 -040076 u32 *verifier, bool *truncp, bool *created);
Chuck Lever3f965022022-01-24 15:50:31 -050077__be32 nfsd_commit(struct svc_rqst *rqst, struct svc_fh *fhp,
78 u64 offset, u32 count, __be32 *verf);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050079#endif /* CONFIG_NFSD_V3 */
Frank van der Linden32119442020-06-23 22:39:23 +000080#ifdef CONFIG_NFSD_V4
81__be32 nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
82 char *name, void **bufp, int *lenp);
83__be32 nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
84 char **bufp, int *lenp);
85__be32 nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
86 char *name);
87__be32 nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
88 char *name, void *buf, u32 len, u32 flags);
89#endif
Jeff Layton65294c12019-08-18 14:18:48 -040090int nfsd_open_break_lease(struct inode *, int);
Al Viro175a4eb2011-07-26 03:30:54 -040091__be32 nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t,
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050092 int, struct file **);
Jeff Layton65294c12019-08-18 14:18:48 -040093__be32 nfsd_open_verified(struct svc_rqst *, struct svc_fh *, umode_t,
94 int, struct file **);
Chuck Lever87c59422018-03-28 13:29:11 -040095__be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
96 struct file *file, loff_t offset,
Trond Myklebust83a63072019-08-26 13:03:11 -040097 unsigned long *count,
98 u32 *eof);
Chuck Lever87c59422018-03-28 13:29:11 -040099__be32 nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp,
100 struct file *file, loff_t offset,
101 struct kvec *vec, int vlen,
Trond Myklebust83a63072019-08-26 13:03:11 -0400102 unsigned long *count,
103 u32 *eof);
J. Bruce Fields039a87c2010-07-30 11:33:32 -0400104__be32 nfsd_read(struct svc_rqst *, struct svc_fh *,
Trond Myklebust83a63072019-08-26 13:03:11 -0400105 loff_t, struct kvec *, int, unsigned long *,
106 u32 *eof);
Kinglong Mee52e380e2016-12-31 21:00:13 +0800107__be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
Trond Myklebust19e06632020-01-06 13:40:37 -0500108 struct kvec *, int, unsigned long *,
109 int stable, __be32 *verf);
Christoph Hellwigaf90f702015-06-18 16:45:00 +0200110__be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
Trond Myklebust16f8f892020-01-06 13:40:29 -0500111 struct nfsd_file *nf, loff_t offset,
Christoph Hellwigaf90f702015-06-18 16:45:00 +0200112 struct kvec *vec, int vlen, unsigned long *cnt,
Trond Myklebust19e06632020-01-06 13:40:37 -0500113 int stable, __be32 *verf);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500114__be32 nfsd_readlink(struct svc_rqst *, struct svc_fh *,
115 char *, int *);
116__be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *,
J. Bruce Fields52ee0432014-06-20 11:52:21 -0400117 char *name, int len, char *path,
Kinglong Mee1e444f52014-07-01 17:48:02 +0800118 struct svc_fh *res);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500119__be32 nfsd_link(struct svc_rqst *, struct svc_fh *,
120 char *, int, struct svc_fh *);
Anna Schumaker29ae7f92016-09-07 15:57:30 -0400121ssize_t nfsd_copy_file_range(struct file *, u64,
122 struct file *, u64, u64);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500123__be32 nfsd_rename(struct svc_rqst *,
124 struct svc_fh *, char *, int,
125 struct svc_fh *, char *, int);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500126__be32 nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
127 char *name, int len);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500128__be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *,
Miklos Szerediac7576f2014-10-30 17:37:34 +0100129 loff_t *, struct readdir_cd *, nfsd_filldir_t);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500130__be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,
131 struct kstatfs *, int access);
132
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500133__be32 nfsd_permission(struct svc_rqst *, struct svc_export *,
134 struct dentry *, int);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500135
Al Virobad0dcf2011-11-23 12:03:18 -0500136static inline int fh_want_write(struct svc_fh *fh)
137{
J. Bruce Fields0b8f6262019-04-12 16:37:30 -0400138 int ret;
Jan Kara4a55c102012-06-12 16:20:33 +0200139
J. Bruce Fields0b8f6262019-04-12 16:37:30 -0400140 if (fh->fh_want_write)
141 return 0;
142 ret = mnt_want_write(fh->fh_export->ex_path.mnt);
Jan Kara4a55c102012-06-12 16:20:33 +0200143 if (!ret)
Jeff Laytonaaf91ec2015-09-17 08:28:39 -0400144 fh->fh_want_write = true;
Jan Kara4a55c102012-06-12 16:20:33 +0200145 return ret;
Al Virobad0dcf2011-11-23 12:03:18 -0500146}
147
148static inline void fh_drop_write(struct svc_fh *fh)
149{
Jan Kara4a55c102012-06-12 16:20:33 +0200150 if (fh->fh_want_write) {
Jeff Laytonaaf91ec2015-09-17 08:28:39 -0400151 fh->fh_want_write = false;
Jan Kara4a55c102012-06-12 16:20:33 +0200152 mnt_drop_write(fh->fh_export->ex_path.mnt);
153 }
Al Virobad0dcf2011-11-23 12:03:18 -0500154}
155
Chuck Lever907c3822020-10-22 13:56:58 -0400156static inline __be32 fh_getattr(const struct svc_fh *fh, struct kstat *stat)
Al Viro3dadecc2013-01-24 02:18:08 -0500157{
158 struct path p = {.mnt = fh->fh_export->ex_path.mnt,
159 .dentry = fh->fh_dentry};
David Howellsa528d352017-01-31 16:46:22 +0000160 return nfserrno(vfs_getattr(&p, stat, STATX_BASIC_STATS,
161 AT_STATX_SYNC_AS_STAT));
Al Viro3dadecc2013-01-24 02:18:08 -0500162}
163
Kinglong Meeead8fb82015-07-30 21:55:02 +0800164static inline int nfsd_create_is_exclusive(int createmode)
165{
166 return createmode == NFS3_CREATE_EXCLUSIVE
167 || createmode == NFS4_CREATE_EXCLUSIVE4_1;
168}
169
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500170#endif /* LINUX_NFSD_VFS_H */