blob: a2442ebe5acf68e79aa47c48679d98f5486a2d80 [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 Myklebustb66ae6d2020-01-06 13:40:32 -050060__be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos,
61 struct nfsd_file *nf_dst, u64 dst_pos,
62 u64 count, bool sync);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050063#endif /* CONFIG_NFSD_V4 */
J. Bruce Fieldsb44061d2016-07-20 16:16:06 -040064__be32 nfsd_create_locked(struct svc_rqst *, struct svc_fh *,
65 char *name, int len, struct iattr *attrs,
66 int type, dev_t rdev, struct svc_fh *res);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050067__be32 nfsd_create(struct svc_rqst *, struct svc_fh *,
68 char *name, int len, struct iattr *attrs,
69 int type, dev_t rdev, struct svc_fh *res);
70#ifdef CONFIG_NFSD_V3
71__be32 nfsd_access(struct svc_rqst *, struct svc_fh *, u32 *, u32 *);
Mi Jinlongac6721a2011-04-20 17:06:25 +080072__be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *,
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050073 char *name, int len, struct iattr *attrs,
74 struct svc_fh *res, int createmode,
J. Bruce Fields856121b2011-10-13 11:37:11 -040075 u32 *verifier, bool *truncp, bool *created);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050076__be32 nfsd_commit(struct svc_rqst *, struct svc_fh *,
Trond Myklebust524ff1a2020-01-06 13:40:36 -050077 loff_t, unsigned long, __be32 *verf);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050078#endif /* CONFIG_NFSD_V3 */
Frank van der Linden32119442020-06-23 22:39:23 +000079#ifdef CONFIG_NFSD_V4
80__be32 nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
81 char *name, void **bufp, int *lenp);
82__be32 nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
83 char **bufp, int *lenp);
84__be32 nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
85 char *name);
86__be32 nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
87 char *name, void *buf, u32 len, u32 flags);
88#endif
Jeff Layton65294c12019-08-18 14:18:48 -040089int nfsd_open_break_lease(struct inode *, int);
Al Viro175a4eb2011-07-26 03:30:54 -040090__be32 nfsd_open(struct svc_rqst *, struct svc_fh *, umode_t,
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050091 int, struct file **);
Jeff Layton65294c12019-08-18 14:18:48 -040092__be32 nfsd_open_verified(struct svc_rqst *, struct svc_fh *, umode_t,
93 int, struct file **);
Chuck Lever87c59422018-03-28 13:29:11 -040094__be32 nfsd_splice_read(struct svc_rqst *rqstp, struct svc_fh *fhp,
95 struct file *file, loff_t offset,
Trond Myklebust83a63072019-08-26 13:03:11 -040096 unsigned long *count,
97 u32 *eof);
Chuck Lever87c59422018-03-28 13:29:11 -040098__be32 nfsd_readv(struct svc_rqst *rqstp, struct svc_fh *fhp,
99 struct file *file, loff_t offset,
100 struct kvec *vec, int vlen,
Trond Myklebust83a63072019-08-26 13:03:11 -0400101 unsigned long *count,
102 u32 *eof);
J. Bruce Fields039a87c2010-07-30 11:33:32 -0400103__be32 nfsd_read(struct svc_rqst *, struct svc_fh *,
Trond Myklebust83a63072019-08-26 13:03:11 -0400104 loff_t, struct kvec *, int, unsigned long *,
105 u32 *eof);
Kinglong Mee52e380e2016-12-31 21:00:13 +0800106__be32 nfsd_write(struct svc_rqst *, struct svc_fh *, loff_t,
Trond Myklebust19e06632020-01-06 13:40:37 -0500107 struct kvec *, int, unsigned long *,
108 int stable, __be32 *verf);
Christoph Hellwigaf90f702015-06-18 16:45:00 +0200109__be32 nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp,
Trond Myklebust16f8f892020-01-06 13:40:29 -0500110 struct nfsd_file *nf, loff_t offset,
Christoph Hellwigaf90f702015-06-18 16:45:00 +0200111 struct kvec *vec, int vlen, unsigned long *cnt,
Trond Myklebust19e06632020-01-06 13:40:37 -0500112 int stable, __be32 *verf);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500113__be32 nfsd_readlink(struct svc_rqst *, struct svc_fh *,
114 char *, int *);
115__be32 nfsd_symlink(struct svc_rqst *, struct svc_fh *,
J. Bruce Fields52ee0432014-06-20 11:52:21 -0400116 char *name, int len, char *path,
Kinglong Mee1e444f52014-07-01 17:48:02 +0800117 struct svc_fh *res);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500118__be32 nfsd_link(struct svc_rqst *, struct svc_fh *,
119 char *, int, struct svc_fh *);
Anna Schumaker29ae7f92016-09-07 15:57:30 -0400120ssize_t nfsd_copy_file_range(struct file *, u64,
121 struct file *, u64, u64);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500122__be32 nfsd_rename(struct svc_rqst *,
123 struct svc_fh *, char *, int,
124 struct svc_fh *, char *, int);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500125__be32 nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
126 char *name, int len);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500127__be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *,
Miklos Szerediac7576f2014-10-30 17:37:34 +0100128 loff_t *, struct readdir_cd *, nfsd_filldir_t);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500129__be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,
130 struct kstatfs *, int access);
131
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500132__be32 nfsd_permission(struct svc_rqst *, struct svc_export *,
133 struct dentry *, int);
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500134
Al Virobad0dcf2011-11-23 12:03:18 -0500135static inline int fh_want_write(struct svc_fh *fh)
136{
J. Bruce Fields0b8f6262019-04-12 16:37:30 -0400137 int ret;
Jan Kara4a55c102012-06-12 16:20:33 +0200138
J. Bruce Fields0b8f6262019-04-12 16:37:30 -0400139 if (fh->fh_want_write)
140 return 0;
141 ret = mnt_want_write(fh->fh_export->ex_path.mnt);
Jan Kara4a55c102012-06-12 16:20:33 +0200142 if (!ret)
Jeff Laytonaaf91ec2015-09-17 08:28:39 -0400143 fh->fh_want_write = true;
Jan Kara4a55c102012-06-12 16:20:33 +0200144 return ret;
Al Virobad0dcf2011-11-23 12:03:18 -0500145}
146
147static inline void fh_drop_write(struct svc_fh *fh)
148{
Jan Kara4a55c102012-06-12 16:20:33 +0200149 if (fh->fh_want_write) {
Jeff Laytonaaf91ec2015-09-17 08:28:39 -0400150 fh->fh_want_write = false;
Jan Kara4a55c102012-06-12 16:20:33 +0200151 mnt_drop_write(fh->fh_export->ex_path.mnt);
152 }
Al Virobad0dcf2011-11-23 12:03:18 -0500153}
154
Al Viro3dadecc2013-01-24 02:18:08 -0500155static inline __be32 fh_getattr(struct svc_fh *fh, struct kstat *stat)
156{
157 struct path p = {.mnt = fh->fh_export->ex_path.mnt,
158 .dentry = fh->fh_dentry};
David Howellsa528d352017-01-31 16:46:22 +0000159 return nfserrno(vfs_getattr(&p, stat, STATX_BASIC_STATS,
160 AT_STATX_SYNC_AS_STAT));
Al Viro3dadecc2013-01-24 02:18:08 -0500161}
162
Kinglong Meeead8fb82015-07-30 21:55:02 +0800163static inline int nfsd_create_is_exclusive(int createmode)
164{
165 return createmode == NFS3_CREATE_EXCLUSIVE
166 || createmode == NFS4_CREATE_EXCLUSIVE4_1;
167}
168
J. Bruce Fields0a3adad2009-11-04 18:12:35 -0500169#endif /* LINUX_NFSD_VFS_H */