xref: /linux/include/linux/nfs4.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  include/linux/nfs4.h
4  *
5  *  NFSv4 protocol definitions.
6  *
7  *  Copyright (c) 2002 The Regents of the University of Michigan.
8  *  All rights reserved.
9  *
10  *  Kendrick Smith <kmsmith@umich.edu>
11  *  Andy Adamson   <andros@umich.edu>
12  */
13 #ifndef _LINUX_NFS4_H
14 #define _LINUX_NFS4_H
15 
16 #include <linux/list.h>
17 #include <linux/uidgid.h>
18 #include <uapi/linux/nfs4.h>
19 #include <linux/sunrpc/msg_prot.h>
20 
21 enum nfs4_acl_whotype {
22 	NFS4_ACL_WHO_NAMED = 0,
23 	NFS4_ACL_WHO_OWNER,
24 	NFS4_ACL_WHO_GROUP,
25 	NFS4_ACL_WHO_EVERYONE,
26 };
27 
28 struct nfs4_ace {
29 	uint32_t	type;
30 	uint32_t	flag;
31 	uint32_t	access_mask;
32 	int		whotype;
33 	union {
34 		kuid_t	who_uid;
35 		kgid_t	who_gid;
36 	};
37 };
38 
39 struct nfs4_acl {
40 	uint32_t	naces;
41 	struct nfs4_ace	aces[];
42 };
43 
44 #define NFS4_MAXLABELLEN	2048
45 
46 struct nfs4_label {
47 	uint32_t	lfs;
48 	uint32_t	pi;
49 	u32		len;
50 	char	*label;
51 };
52 
53 typedef struct { char data[NFS4_VERIFIER_SIZE]; } nfs4_verifier;
54 
55 struct nfs4_stateid_struct {
56 	union {
57 		char data[NFS4_STATEID_SIZE];
58 		struct {
59 			__be32 seqid;
60 			char other[NFS4_STATEID_OTHER_SIZE];
61 		} __attribute__ ((packed));
62 	};
63 
64 	enum {
65 		NFS4_INVALID_STATEID_TYPE = 0,
66 		NFS4_SPECIAL_STATEID_TYPE,
67 		NFS4_OPEN_STATEID_TYPE,
68 		NFS4_LOCK_STATEID_TYPE,
69 		NFS4_DELEGATION_STATEID_TYPE,
70 		NFS4_LAYOUT_STATEID_TYPE,
71 		NFS4_PNFS_DS_STATEID_TYPE,
72 		NFS4_REVOKED_STATEID_TYPE,
73 	} type;
74 };
75 
76 typedef struct nfs4_stateid_struct nfs4_stateid;
77 
78 enum nfs_opnum4 {
79 	OP_ACCESS = 3,
80 	OP_CLOSE = 4,
81 	OP_COMMIT = 5,
82 	OP_CREATE = 6,
83 	OP_DELEGPURGE = 7,
84 	OP_DELEGRETURN = 8,
85 	OP_GETATTR = 9,
86 	OP_GETFH = 10,
87 	OP_LINK = 11,
88 	OP_LOCK = 12,
89 	OP_LOCKT = 13,
90 	OP_LOCKU = 14,
91 	OP_LOOKUP = 15,
92 	OP_LOOKUPP = 16,
93 	OP_NVERIFY = 17,
94 	OP_OPEN = 18,
95 	OP_OPENATTR = 19,
96 	OP_OPEN_CONFIRM = 20,
97 	OP_OPEN_DOWNGRADE = 21,
98 	OP_PUTFH = 22,
99 	OP_PUTPUBFH = 23,
100 	OP_PUTROOTFH = 24,
101 	OP_READ = 25,
102 	OP_READDIR = 26,
103 	OP_READLINK = 27,
104 	OP_REMOVE = 28,
105 	OP_RENAME = 29,
106 	OP_RENEW = 30,
107 	OP_RESTOREFH = 31,
108 	OP_SAVEFH = 32,
109 	OP_SECINFO = 33,
110 	OP_SETATTR = 34,
111 	OP_SETCLIENTID = 35,
112 	OP_SETCLIENTID_CONFIRM = 36,
113 	OP_VERIFY = 37,
114 	OP_WRITE = 38,
115 	OP_RELEASE_LOCKOWNER = 39,
116 
117 	/* nfs41 */
118 	OP_BACKCHANNEL_CTL = 40,
119 	OP_BIND_CONN_TO_SESSION = 41,
120 	OP_EXCHANGE_ID = 42,
121 	OP_CREATE_SESSION = 43,
122 	OP_DESTROY_SESSION = 44,
123 	OP_FREE_STATEID = 45,
124 	OP_GET_DIR_DELEGATION = 46,
125 	OP_GETDEVICEINFO = 47,
126 	OP_GETDEVICELIST = 48,
127 	OP_LAYOUTCOMMIT = 49,
128 	OP_LAYOUTGET = 50,
129 	OP_LAYOUTRETURN = 51,
130 	OP_SECINFO_NO_NAME = 52,
131 	OP_SEQUENCE = 53,
132 	OP_SET_SSV = 54,
133 	OP_TEST_STATEID = 55,
134 	OP_WANT_DELEGATION = 56,
135 	OP_DESTROY_CLIENTID = 57,
136 	OP_RECLAIM_COMPLETE = 58,
137 
138 	/* nfs42 */
139 	OP_ALLOCATE = 59,
140 	OP_COPY = 60,
141 	OP_COPY_NOTIFY = 61,
142 	OP_DEALLOCATE = 62,
143 	OP_IO_ADVISE = 63,
144 	OP_LAYOUTERROR = 64,
145 	OP_LAYOUTSTATS = 65,
146 	OP_OFFLOAD_CANCEL = 66,
147 	OP_OFFLOAD_STATUS = 67,
148 	OP_READ_PLUS = 68,
149 	OP_SEEK = 69,
150 	OP_WRITE_SAME = 70,
151 	OP_CLONE = 71,
152 
153 	/* xattr support (RFC8276) */
154 	OP_GETXATTR                = 72,
155 	OP_SETXATTR                = 73,
156 	OP_LISTXATTRS              = 74,
157 	OP_REMOVEXATTR             = 75,
158 
159 	OP_ILLEGAL = 10044,
160 };
161 
162 /*Defining first and last NFS4 operations implemented.
163 Needs to be updated if more operations are defined in future.*/
164 
165 #define FIRST_NFS4_OP	OP_ACCESS
166 #define LAST_NFS40_OP	OP_RELEASE_LOCKOWNER
167 #define LAST_NFS41_OP	OP_RECLAIM_COMPLETE
168 #define LAST_NFS42_OP	OP_REMOVEXATTR
169 #define LAST_NFS4_OP	LAST_NFS42_OP
170 
171 enum nfsstat4 {
172 	NFS4_OK = 0,
173 	NFS4ERR_PERM = 1,
174 	NFS4ERR_NOENT = 2,
175 	NFS4ERR_IO = 5,
176 	NFS4ERR_NXIO = 6,
177 	NFS4ERR_ACCESS = 13,
178 	NFS4ERR_EXIST = 17,
179 	NFS4ERR_XDEV = 18,
180 	/* Unused/reserved 19 */
181 	NFS4ERR_NOTDIR = 20,
182 	NFS4ERR_ISDIR = 21,
183 	NFS4ERR_INVAL = 22,
184 	NFS4ERR_FBIG = 27,
185 	NFS4ERR_NOSPC = 28,
186 	NFS4ERR_ROFS = 30,
187 	NFS4ERR_MLINK = 31,
188 	NFS4ERR_NAMETOOLONG = 63,
189 	NFS4ERR_NOTEMPTY = 66,
190 	NFS4ERR_DQUOT = 69,
191 	NFS4ERR_STALE = 70,
192 	NFS4ERR_BADHANDLE = 10001,
193 	NFS4ERR_BAD_COOKIE = 10003,
194 	NFS4ERR_NOTSUPP = 10004,
195 	NFS4ERR_TOOSMALL = 10005,
196 	NFS4ERR_SERVERFAULT = 10006,
197 	NFS4ERR_BADTYPE = 10007,
198 	NFS4ERR_DELAY = 10008,
199 	NFS4ERR_SAME = 10009,
200 	NFS4ERR_DENIED = 10010,
201 	NFS4ERR_EXPIRED = 10011,
202 	NFS4ERR_LOCKED = 10012,
203 	NFS4ERR_GRACE = 10013,
204 	NFS4ERR_FHEXPIRED = 10014,
205 	NFS4ERR_SHARE_DENIED = 10015,
206 	NFS4ERR_WRONGSEC = 10016,
207 	NFS4ERR_CLID_INUSE = 10017,
208 	NFS4ERR_RESOURCE = 10018,
209 	NFS4ERR_MOVED = 10019,
210 	NFS4ERR_NOFILEHANDLE = 10020,
211 	NFS4ERR_MINOR_VERS_MISMATCH = 10021,
212 	NFS4ERR_STALE_CLIENTID = 10022,
213 	NFS4ERR_STALE_STATEID = 10023,
214 	NFS4ERR_OLD_STATEID = 10024,
215 	NFS4ERR_BAD_STATEID = 10025,
216 	NFS4ERR_BAD_SEQID = 10026,
217 	NFS4ERR_NOT_SAME = 10027,
218 	NFS4ERR_LOCK_RANGE = 10028,
219 	NFS4ERR_SYMLINK = 10029,
220 	NFS4ERR_RESTOREFH = 10030,
221 	NFS4ERR_LEASE_MOVED = 10031,
222 	NFS4ERR_ATTRNOTSUPP = 10032,
223 	NFS4ERR_NO_GRACE = 10033,
224 	NFS4ERR_RECLAIM_BAD = 10034,
225 	NFS4ERR_RECLAIM_CONFLICT = 10035,
226 	NFS4ERR_BADXDR = 10036,
227 	NFS4ERR_LOCKS_HELD = 10037,
228 	NFS4ERR_OPENMODE = 10038,
229 	NFS4ERR_BADOWNER = 10039,
230 	NFS4ERR_BADCHAR = 10040,
231 	NFS4ERR_BADNAME = 10041,
232 	NFS4ERR_BAD_RANGE = 10042,
233 	NFS4ERR_LOCK_NOTSUPP = 10043,
234 	NFS4ERR_OP_ILLEGAL = 10044,
235 	NFS4ERR_DEADLOCK = 10045,
236 	NFS4ERR_FILE_OPEN = 10046,
237 	NFS4ERR_ADMIN_REVOKED = 10047,
238 	NFS4ERR_CB_PATH_DOWN = 10048,
239 
240 	/* nfs41 */
241 	NFS4ERR_BADIOMODE	= 10049,
242 	NFS4ERR_BADLAYOUT	= 10050,
243 	NFS4ERR_BAD_SESSION_DIGEST = 10051,
244 	NFS4ERR_BADSESSION	= 10052,
245 	NFS4ERR_BADSLOT		= 10053,
246 	NFS4ERR_COMPLETE_ALREADY = 10054,
247 	NFS4ERR_CONN_NOT_BOUND_TO_SESSION = 10055,
248 	NFS4ERR_DELEG_ALREADY_WANTED = 10056,
249 	NFS4ERR_BACK_CHAN_BUSY	= 10057,	/* backchan reqs outstanding */
250 	NFS4ERR_LAYOUTTRYLATER	= 10058,
251 	NFS4ERR_LAYOUTUNAVAILABLE = 10059,
252 	NFS4ERR_NOMATCHING_LAYOUT = 10060,
253 	NFS4ERR_RECALLCONFLICT	= 10061,
254 	NFS4ERR_UNKNOWN_LAYOUTTYPE = 10062,
255 	NFS4ERR_SEQ_MISORDERED = 10063, 	/* unexpected seq.id in req */
256 	NFS4ERR_SEQUENCE_POS	= 10064,	/* [CB_]SEQ. op not 1st op */
257 	NFS4ERR_REQ_TOO_BIG	= 10065,	/* request too big */
258 	NFS4ERR_REP_TOO_BIG	= 10066,	/* reply too big */
259 	NFS4ERR_REP_TOO_BIG_TO_CACHE = 10067,	/* rep. not all cached */
260 	NFS4ERR_RETRY_UNCACHED_REP = 10068,	/* retry & rep. uncached */
261 	NFS4ERR_UNSAFE_COMPOUND = 10069,	/* retry/recovery too hard */
262 	NFS4ERR_TOO_MANY_OPS	= 10070,	/* too many ops in [CB_]COMP */
263 	NFS4ERR_OP_NOT_IN_SESSION = 10071,	/* op needs [CB_]SEQ. op */
264 	NFS4ERR_HASH_ALG_UNSUPP = 10072,	/* hash alg. not supp. */
265 						/* Error 10073 is unused. */
266 	NFS4ERR_CLIENTID_BUSY	= 10074,	/* clientid has state */
267 	NFS4ERR_PNFS_IO_HOLE	= 10075,	/* IO to _SPARSE file hole */
268 	NFS4ERR_SEQ_FALSE_RETRY	= 10076,	/* retry not original */
269 	NFS4ERR_BAD_HIGH_SLOT	= 10077,	/* sequence arg bad */
270 	NFS4ERR_DEADSESSION	= 10078,	/* persistent session dead */
271 	NFS4ERR_ENCR_ALG_UNSUPP = 10079,	/* SSV alg mismatch */
272 	NFS4ERR_PNFS_NO_LAYOUT	= 10080,	/* direct I/O with no layout */
273 	NFS4ERR_NOT_ONLY_OP	= 10081,	/* bad compound */
274 	NFS4ERR_WRONG_CRED	= 10082,	/* permissions:state change */
275 	NFS4ERR_WRONG_TYPE	= 10083,	/* current operation mismatch */
276 	NFS4ERR_DIRDELEG_UNAVAIL = 10084,	/* no directory delegation */
277 	NFS4ERR_REJECT_DELEG	= 10085,	/* on callback */
278 	NFS4ERR_RETURNCONFLICT	= 10086,	/* outstanding layoutreturn */
279 	NFS4ERR_DELEG_REVOKED	= 10087,	/* deleg./layout revoked */
280 
281 	/* nfs42 */
282 	NFS4ERR_PARTNER_NOTSUPP	= 10088,
283 	NFS4ERR_PARTNER_NO_AUTH	= 10089,
284 	NFS4ERR_UNION_NOTSUPP	= 10090,
285 	NFS4ERR_OFFLOAD_DENIED	= 10091,
286 	NFS4ERR_WRONG_LFS	= 10092,
287 	NFS4ERR_BADLABEL	= 10093,
288 	NFS4ERR_OFFLOAD_NO_REQS	= 10094,
289 
290 	/* xattr (RFC8276) */
291 	NFS4ERR_NOXATTR		= 10095,
292 	NFS4ERR_XATTR2BIG	= 10096,
293 
294 	/* can be used for internal errors */
295 	NFS4ERR_FIRST_FREE
296 };
297 
298 /* error codes for internal client use */
299 #define NFS4ERR_RESET_TO_MDS   12001
300 #define NFS4ERR_RESET_TO_PNFS  12002
301 
seqid_mutating_err(u32 err)302 static inline bool seqid_mutating_err(u32 err)
303 {
304 	/* See RFC 7530, section 9.1.7 */
305 	switch (err) {
306 	case NFS4ERR_STALE_CLIENTID:
307 	case NFS4ERR_STALE_STATEID:
308 	case NFS4ERR_BAD_STATEID:
309 	case NFS4ERR_BAD_SEQID:
310 	case NFS4ERR_BADXDR:
311 	case NFS4ERR_RESOURCE:
312 	case NFS4ERR_NOFILEHANDLE:
313 	case NFS4ERR_MOVED:
314 		return false;
315 	}
316 	return true;
317 }
318 
319 /*
320  * Note: NF4BAD is not actually part of the protocol; it is just used
321  * internally by nfsd.
322  */
323 enum nfs_ftype4 {
324 	NF4BAD		= 0,
325         NF4REG          = 1,    /* Regular File */
326         NF4DIR          = 2,    /* Directory */
327         NF4BLK          = 3,    /* Special File - block device */
328         NF4CHR          = 4,    /* Special File - character device */
329         NF4LNK          = 5,    /* Symbolic Link */
330         NF4SOCK         = 6,    /* Special File - socket */
331         NF4FIFO         = 7,    /* Special File - fifo */
332         NF4ATTRDIR      = 8,    /* Attribute Directory */
333         NF4NAMEDATTR    = 9     /* Named Attribute */
334 };
335 
336 enum open_claim_type4 {
337 	NFS4_OPEN_CLAIM_NULL = 0,
338 	NFS4_OPEN_CLAIM_PREVIOUS = 1,
339 	NFS4_OPEN_CLAIM_DELEGATE_CUR = 2,
340 	NFS4_OPEN_CLAIM_DELEGATE_PREV = 3,
341 	NFS4_OPEN_CLAIM_FH = 4, /* 4.1 */
342 	NFS4_OPEN_CLAIM_DELEG_CUR_FH = 5, /* 4.1 */
343 	NFS4_OPEN_CLAIM_DELEG_PREV_FH = 6, /* 4.1 */
344 };
345 
346 enum opentype4 {
347 	NFS4_OPEN_NOCREATE = 0,
348 	NFS4_OPEN_CREATE = 1
349 };
350 
351 enum createmode4 {
352 	NFS4_CREATE_UNCHECKED = 0,
353 	NFS4_CREATE_GUARDED = 1,
354 	NFS4_CREATE_EXCLUSIVE = 2,
355 	/*
356 	 * New to NFSv4.1. If session is persistent,
357 	 * GUARDED4 MUST be used. Otherwise, use
358 	 * EXCLUSIVE4_1 instead of EXCLUSIVE4.
359 	 */
360 	NFS4_CREATE_EXCLUSIVE4_1 = 3
361 };
362 
363 enum limit_by4 {
364 	NFS4_LIMIT_SIZE = 1,
365 	NFS4_LIMIT_BLOCKS = 2
366 };
367 
368 enum open_delegation_type4 {
369 	NFS4_OPEN_DELEGATE_NONE = 0,
370 	NFS4_OPEN_DELEGATE_READ = 1,
371 	NFS4_OPEN_DELEGATE_WRITE = 2,
372 	NFS4_OPEN_DELEGATE_NONE_EXT = 3, /* 4.1 */
373 	NFS4_OPEN_DELEGATE_READ_ATTRS_DELEG = 4,
374 	NFS4_OPEN_DELEGATE_WRITE_ATTRS_DELEG = 5,
375 };
376 
377 enum why_no_delegation4 { /* new to v4.1 */
378 	WND4_NOT_WANTED = 0,
379 	WND4_CONTENTION = 1,
380 	WND4_RESOURCE = 2,
381 	WND4_NOT_SUPP_FTYPE = 3,
382 	WND4_WRITE_DELEG_NOT_SUPP_FTYPE = 4,
383 	WND4_NOT_SUPP_UPGRADE = 5,
384 	WND4_NOT_SUPP_DOWNGRADE = 6,
385 	WND4_CANCELLED = 7,
386 	WND4_IS_DIR = 8,
387 };
388 
389 enum lock_type4 {
390 	NFS4_UNLOCK_LT = 0,
391 	NFS4_READ_LT = 1,
392 	NFS4_WRITE_LT = 2,
393 	NFS4_READW_LT = 3,
394 	NFS4_WRITEW_LT = 4
395 };
396 
397 /*
398  * Symbol names and values are from RFC 7531 Section 2.
399  * "XDR Description of NFSv4.0"
400  */
401 enum {
402 	FATTR4_SUPPORTED_ATTRS		= 0,
403 	FATTR4_TYPE			= 1,
404 	FATTR4_FH_EXPIRE_TYPE		= 2,
405 	FATTR4_CHANGE			= 3,
406 	FATTR4_SIZE			= 4,
407 	FATTR4_LINK_SUPPORT		= 5,
408 	FATTR4_SYMLINK_SUPPORT		= 6,
409 	FATTR4_NAMED_ATTR		= 7,
410 	FATTR4_FSID			= 8,
411 	FATTR4_UNIQUE_HANDLES		= 9,
412 	FATTR4_LEASE_TIME		= 10,
413 	FATTR4_RDATTR_ERROR		= 11,
414 	FATTR4_ACL			= 12,
415 	FATTR4_ACLSUPPORT		= 13,
416 	FATTR4_ARCHIVE			= 14,
417 	FATTR4_CANSETTIME		= 15,
418 	FATTR4_CASE_INSENSITIVE		= 16,
419 	FATTR4_CASE_PRESERVING		= 17,
420 	FATTR4_CHOWN_RESTRICTED		= 18,
421 	FATTR4_FILEHANDLE		= 19,
422 	FATTR4_FILEID			= 20,
423 	FATTR4_FILES_AVAIL		= 21,
424 	FATTR4_FILES_FREE		= 22,
425 	FATTR4_FILES_TOTAL		= 23,
426 	FATTR4_FS_LOCATIONS		= 24,
427 	FATTR4_HIDDEN			= 25,
428 	FATTR4_HOMOGENEOUS		= 26,
429 	FATTR4_MAXFILESIZE		= 27,
430 	FATTR4_MAXLINK			= 28,
431 	FATTR4_MAXNAME			= 29,
432 	FATTR4_MAXREAD			= 30,
433 	FATTR4_MAXWRITE			= 31,
434 	FATTR4_MIMETYPE			= 32,
435 	FATTR4_MODE			= 33,
436 	FATTR4_NO_TRUNC			= 34,
437 	FATTR4_NUMLINKS			= 35,
438 	FATTR4_OWNER			= 36,
439 	FATTR4_OWNER_GROUP		= 37,
440 	FATTR4_QUOTA_AVAIL_HARD		= 38,
441 	FATTR4_QUOTA_AVAIL_SOFT		= 39,
442 	FATTR4_QUOTA_USED		= 40,
443 	FATTR4_RAWDEV			= 41,
444 	FATTR4_SPACE_AVAIL		= 42,
445 	FATTR4_SPACE_FREE		= 43,
446 	FATTR4_SPACE_TOTAL		= 44,
447 	FATTR4_SPACE_USED		= 45,
448 	FATTR4_SYSTEM			= 46,
449 	FATTR4_TIME_ACCESS		= 47,
450 	FATTR4_TIME_ACCESS_SET		= 48,
451 	FATTR4_TIME_BACKUP		= 49,
452 	FATTR4_TIME_CREATE		= 50,
453 	FATTR4_TIME_DELTA		= 51,
454 	FATTR4_TIME_METADATA		= 52,
455 	FATTR4_TIME_MODIFY		= 53,
456 	FATTR4_TIME_MODIFY_SET		= 54,
457 	FATTR4_MOUNTED_ON_FILEID	= 55,
458 };
459 
460 /*
461  * Symbol names and values are from RFC 5662 Section 2.
462  * "XDR Description of NFSv4.1"
463  */
464 enum {
465 	FATTR4_DIR_NOTIF_DELAY		= 56,
466 	FATTR4_DIRENT_NOTIF_DELAY	= 57,
467 	FATTR4_DACL			= 58,
468 	FATTR4_SACL			= 59,
469 	FATTR4_CHANGE_POLICY		= 60,
470 	FATTR4_FS_STATUS		= 61,
471 	FATTR4_FS_LAYOUT_TYPES		= 62,
472 	FATTR4_LAYOUT_HINT		= 63,
473 	FATTR4_LAYOUT_TYPES		= 64,
474 	FATTR4_LAYOUT_BLKSIZE		= 65,
475 	FATTR4_LAYOUT_ALIGNMENT		= 66,
476 	FATTR4_FS_LOCATIONS_INFO	= 67,
477 	FATTR4_MDSTHRESHOLD		= 68,
478 	FATTR4_RETENTION_GET		= 69,
479 	FATTR4_RETENTION_SET		= 70,
480 	FATTR4_RETENTEVT_GET		= 71,
481 	FATTR4_RETENTEVT_SET		= 72,
482 	FATTR4_RETENTION_HOLD		= 73,
483 	FATTR4_MODE_SET_MASKED		= 74,
484 	FATTR4_SUPPATTR_EXCLCREAT	= 75,
485 	FATTR4_FS_CHARSET_CAP		= 76,
486 };
487 
488 /*
489  * Symbol names and values are from RFC 7863 Section 2.
490  * "XDR Description of NFSv4.2"
491  */
492 enum {
493 	FATTR4_CLONE_BLKSIZE		= 77,
494 	FATTR4_SPACE_FREED		= 78,
495 	FATTR4_CHANGE_ATTR_TYPE		= 79,
496 	FATTR4_SEC_LABEL		= 80,
497 };
498 
499 /*
500  * Symbol names and values are from RFC 8275 Section 5.
501  * "The mode_umask Attribute"
502  */
503 enum {
504 	FATTR4_MODE_UMASK		= 81,
505 };
506 
507 /*
508  * Symbol names and values are from RFC 8276 Section 8.6.
509  * "Numeric Values Assigned to Protocol Extensions"
510  */
511 enum {
512 	FATTR4_XATTR_SUPPORT		= 82,
513 };
514 
515 enum {
516 	FATTR4_TIME_DELEG_ACCESS	= 84,
517 	FATTR4_TIME_DELEG_MODIFY	= 85,
518 	FATTR4_OPEN_ARGUMENTS		= 86,
519 };
520 
521 /*
522  * The following internal definitions enable processing the above
523  * attribute bits within 32-bit word boundaries.
524  */
525 
526 /* Mandatory Attributes */
527 #define FATTR4_WORD0_SUPPORTED_ATTRS    BIT(FATTR4_SUPPORTED_ATTRS)
528 #define FATTR4_WORD0_TYPE               BIT(FATTR4_TYPE)
529 #define FATTR4_WORD0_FH_EXPIRE_TYPE     BIT(FATTR4_FH_EXPIRE_TYPE)
530 #define FATTR4_WORD0_CHANGE             BIT(FATTR4_CHANGE)
531 #define FATTR4_WORD0_SIZE               BIT(FATTR4_SIZE)
532 #define FATTR4_WORD0_LINK_SUPPORT       BIT(FATTR4_LINK_SUPPORT)
533 #define FATTR4_WORD0_SYMLINK_SUPPORT    BIT(FATTR4_SYMLINK_SUPPORT)
534 #define FATTR4_WORD0_NAMED_ATTR         BIT(FATTR4_NAMED_ATTR)
535 #define FATTR4_WORD0_FSID               BIT(FATTR4_FSID)
536 #define FATTR4_WORD0_UNIQUE_HANDLES     BIT(FATTR4_UNIQUE_HANDLES)
537 #define FATTR4_WORD0_LEASE_TIME         BIT(FATTR4_LEASE_TIME)
538 #define FATTR4_WORD0_RDATTR_ERROR       BIT(FATTR4_RDATTR_ERROR)
539 /* Mandatory in NFSv4.1 */
540 #define FATTR4_WORD2_SUPPATTR_EXCLCREAT BIT(FATTR4_SUPPATTR_EXCLCREAT - 64)
541 
542 /* Recommended Attributes */
543 #define FATTR4_WORD0_ACL                BIT(FATTR4_ACL)
544 #define FATTR4_WORD0_ACLSUPPORT         BIT(FATTR4_ACLSUPPORT)
545 #define FATTR4_WORD0_ARCHIVE            BIT(FATTR4_ARCHIVE)
546 #define FATTR4_WORD0_CANSETTIME         BIT(FATTR4_CANSETTIME)
547 #define FATTR4_WORD0_CASE_INSENSITIVE   BIT(FATTR4_CASE_INSENSITIVE)
548 #define FATTR4_WORD0_CASE_PRESERVING    BIT(FATTR4_CASE_PRESERVING)
549 #define FATTR4_WORD0_CHOWN_RESTRICTED   BIT(FATTR4_CHOWN_RESTRICTED)
550 #define FATTR4_WORD0_FILEHANDLE         BIT(FATTR4_FILEHANDLE)
551 #define FATTR4_WORD0_FILEID             BIT(FATTR4_FILEID)
552 #define FATTR4_WORD0_FILES_AVAIL        BIT(FATTR4_FILES_AVAIL)
553 #define FATTR4_WORD0_FILES_FREE         BIT(FATTR4_FILES_FREE)
554 #define FATTR4_WORD0_FILES_TOTAL        BIT(FATTR4_FILES_TOTAL)
555 #define FATTR4_WORD0_FS_LOCATIONS       BIT(FATTR4_FS_LOCATIONS)
556 #define FATTR4_WORD0_HIDDEN             BIT(FATTR4_HIDDEN)
557 #define FATTR4_WORD0_HOMOGENEOUS        BIT(FATTR4_HOMOGENEOUS)
558 #define FATTR4_WORD0_MAXFILESIZE        BIT(FATTR4_MAXFILESIZE)
559 #define FATTR4_WORD0_MAXLINK            BIT(FATTR4_MAXLINK)
560 #define FATTR4_WORD0_MAXNAME            BIT(FATTR4_MAXNAME)
561 #define FATTR4_WORD0_MAXREAD            BIT(FATTR4_MAXREAD)
562 #define FATTR4_WORD0_MAXWRITE           BIT(FATTR4_MAXWRITE)
563 
564 #define FATTR4_WORD1_MIMETYPE           BIT(FATTR4_MIMETYPE - 32)
565 #define FATTR4_WORD1_MODE               BIT(FATTR4_MODE	- 32)
566 #define FATTR4_WORD1_NO_TRUNC           BIT(FATTR4_NO_TRUNC - 32)
567 #define FATTR4_WORD1_NUMLINKS           BIT(FATTR4_NUMLINKS - 32)
568 #define FATTR4_WORD1_OWNER              BIT(FATTR4_OWNER - 32)
569 #define FATTR4_WORD1_OWNER_GROUP        BIT(FATTR4_OWNER_GROUP - 32)
570 #define FATTR4_WORD1_QUOTA_HARD         BIT(FATTR4_QUOTA_AVAIL_HARD - 32)
571 #define FATTR4_WORD1_QUOTA_SOFT         BIT(FATTR4_QUOTA_AVAIL_SOFT - 32)
572 #define FATTR4_WORD1_QUOTA_USED         BIT(FATTR4_QUOTA_USED - 32)
573 #define FATTR4_WORD1_RAWDEV             BIT(FATTR4_RAWDEV - 32)
574 #define FATTR4_WORD1_SPACE_AVAIL        BIT(FATTR4_SPACE_AVAIL - 32)
575 #define FATTR4_WORD1_SPACE_FREE         BIT(FATTR4_SPACE_FREE - 32)
576 #define FATTR4_WORD1_SPACE_TOTAL        BIT(FATTR4_SPACE_TOTAL - 32)
577 #define FATTR4_WORD1_SPACE_USED         BIT(FATTR4_SPACE_USED - 32)
578 #define FATTR4_WORD1_SYSTEM             BIT(FATTR4_SYSTEM - 32)
579 #define FATTR4_WORD1_TIME_ACCESS        BIT(FATTR4_TIME_ACCESS - 32)
580 #define FATTR4_WORD1_TIME_ACCESS_SET    BIT(FATTR4_TIME_ACCESS_SET - 32)
581 #define FATTR4_WORD1_TIME_BACKUP        BIT(FATTR4_TIME_BACKUP - 32)
582 #define FATTR4_WORD1_TIME_CREATE        BIT(FATTR4_TIME_CREATE - 32)
583 #define FATTR4_WORD1_TIME_DELTA         BIT(FATTR4_TIME_DELTA - 32)
584 #define FATTR4_WORD1_TIME_METADATA      BIT(FATTR4_TIME_METADATA - 32)
585 #define FATTR4_WORD1_TIME_MODIFY        BIT(FATTR4_TIME_MODIFY - 32)
586 #define FATTR4_WORD1_TIME_MODIFY_SET    BIT(FATTR4_TIME_MODIFY_SET - 32)
587 #define FATTR4_WORD1_MOUNTED_ON_FILEID  BIT(FATTR4_MOUNTED_ON_FILEID - 32)
588 #define FATTR4_WORD1_DACL               BIT(FATTR4_DACL	- 32)
589 #define FATTR4_WORD1_SACL               BIT(FATTR4_SACL	- 32)
590 #define FATTR4_WORD1_FS_LAYOUT_TYPES    BIT(FATTR4_FS_LAYOUT_TYPES - 32)
591 
592 #define FATTR4_WORD2_LAYOUT_TYPES       BIT(FATTR4_LAYOUT_TYPES - 64)
593 #define FATTR4_WORD2_LAYOUT_BLKSIZE     BIT(FATTR4_LAYOUT_BLKSIZE - 64)
594 #define FATTR4_WORD2_MDSTHRESHOLD       BIT(FATTR4_MDSTHRESHOLD	- 64)
595 #define FATTR4_WORD2_CLONE_BLKSIZE	BIT(FATTR4_CLONE_BLKSIZE - 64)
596 #define FATTR4_WORD2_CHANGE_ATTR_TYPE	BIT(FATTR4_CHANGE_ATTR_TYPE - 64)
597 #define FATTR4_WORD2_SECURITY_LABEL     BIT(FATTR4_SEC_LABEL - 64)
598 #define FATTR4_WORD2_MODE_UMASK		BIT(FATTR4_MODE_UMASK - 64)
599 #define FATTR4_WORD2_XATTR_SUPPORT	BIT(FATTR4_XATTR_SUPPORT - 64)
600 #define FATTR4_WORD2_TIME_DELEG_ACCESS	BIT(FATTR4_TIME_DELEG_ACCESS - 64)
601 #define FATTR4_WORD2_TIME_DELEG_MODIFY	BIT(FATTR4_TIME_DELEG_MODIFY - 64)
602 #define FATTR4_WORD2_OPEN_ARGUMENTS	BIT(FATTR4_OPEN_ARGUMENTS - 64)
603 
604 /* MDS threshold bitmap bits */
605 #define THRESHOLD_RD                    (1UL << 0)
606 #define THRESHOLD_WR                    (1UL << 1)
607 #define THRESHOLD_RD_IO                 (1UL << 2)
608 #define THRESHOLD_WR_IO                 (1UL << 3)
609 
610 #define NFSPROC4_NULL 0
611 #define NFSPROC4_COMPOUND 1
612 #define NFS4_VERSION 4
613 #define NFS4_MINOR_VERSION 0
614 
615 #define NFS4_DEBUG 1
616 
617 /*
618  * Index of predefined Linux client operations
619  *
620  * To ensure that /proc/net/rpc/nfs remains correctly ordered, please
621  * append only to this enum when adding new client operations.
622  */
623 
624 enum {
625 	NFSPROC4_CLNT_NULL = 0,		/* Unused */
626 	NFSPROC4_CLNT_READ,
627 	NFSPROC4_CLNT_WRITE,
628 	NFSPROC4_CLNT_COMMIT,
629 	NFSPROC4_CLNT_OPEN,
630 	NFSPROC4_CLNT_OPEN_CONFIRM,
631 	NFSPROC4_CLNT_OPEN_NOATTR,
632 	NFSPROC4_CLNT_OPEN_DOWNGRADE,
633 	NFSPROC4_CLNT_CLOSE,
634 	NFSPROC4_CLNT_SETATTR,
635 	NFSPROC4_CLNT_FSINFO,
636 	NFSPROC4_CLNT_RENEW,
637 	NFSPROC4_CLNT_SETCLIENTID,
638 	NFSPROC4_CLNT_SETCLIENTID_CONFIRM,
639 	NFSPROC4_CLNT_LOCK,
640 	NFSPROC4_CLNT_LOCKT,
641 	NFSPROC4_CLNT_LOCKU,
642 	NFSPROC4_CLNT_ACCESS,
643 	NFSPROC4_CLNT_GETATTR,
644 	NFSPROC4_CLNT_LOOKUP,
645 	NFSPROC4_CLNT_LOOKUP_ROOT,
646 	NFSPROC4_CLNT_REMOVE,
647 	NFSPROC4_CLNT_RENAME,
648 	NFSPROC4_CLNT_LINK,
649 	NFSPROC4_CLNT_SYMLINK,
650 	NFSPROC4_CLNT_CREATE,
651 	NFSPROC4_CLNT_PATHCONF,
652 	NFSPROC4_CLNT_STATFS,
653 	NFSPROC4_CLNT_READLINK,
654 	NFSPROC4_CLNT_READDIR,
655 	NFSPROC4_CLNT_SERVER_CAPS,
656 	NFSPROC4_CLNT_DELEGRETURN,
657 	NFSPROC4_CLNT_GETACL,
658 	NFSPROC4_CLNT_SETACL,
659 	NFSPROC4_CLNT_FS_LOCATIONS,
660 	NFSPROC4_CLNT_RELEASE_LOCKOWNER,
661 	NFSPROC4_CLNT_SECINFO,
662 	NFSPROC4_CLNT_FSID_PRESENT,
663 
664 	NFSPROC4_CLNT_EXCHANGE_ID,
665 	NFSPROC4_CLNT_CREATE_SESSION,
666 	NFSPROC4_CLNT_DESTROY_SESSION,
667 	NFSPROC4_CLNT_SEQUENCE,
668 	NFSPROC4_CLNT_GET_LEASE_TIME,
669 	NFSPROC4_CLNT_RECLAIM_COMPLETE,
670 	NFSPROC4_CLNT_LAYOUTGET,
671 	NFSPROC4_CLNT_GETDEVICEINFO,
672 	NFSPROC4_CLNT_LAYOUTCOMMIT,
673 	NFSPROC4_CLNT_LAYOUTRETURN,
674 	NFSPROC4_CLNT_SECINFO_NO_NAME,
675 	NFSPROC4_CLNT_TEST_STATEID,
676 	NFSPROC4_CLNT_FREE_STATEID,
677 	NFSPROC4_CLNT_GETDEVICELIST,
678 	NFSPROC4_CLNT_BIND_CONN_TO_SESSION,
679 	NFSPROC4_CLNT_DESTROY_CLIENTID,
680 
681 	NFSPROC4_CLNT_SEEK,
682 	NFSPROC4_CLNT_ALLOCATE,
683 	NFSPROC4_CLNT_DEALLOCATE,
684 	NFSPROC4_CLNT_LAYOUTSTATS,
685 	NFSPROC4_CLNT_CLONE,
686 	NFSPROC4_CLNT_COPY,
687 	NFSPROC4_CLNT_OFFLOAD_CANCEL,
688 
689 	NFSPROC4_CLNT_LOOKUPP,
690 	NFSPROC4_CLNT_LAYOUTERROR,
691 	NFSPROC4_CLNT_COPY_NOTIFY,
692 
693 	NFSPROC4_CLNT_GETXATTR,
694 	NFSPROC4_CLNT_SETXATTR,
695 	NFSPROC4_CLNT_LISTXATTRS,
696 	NFSPROC4_CLNT_REMOVEXATTR,
697 	NFSPROC4_CLNT_READ_PLUS,
698 };
699 
700 /* nfs41 types */
701 struct nfs4_sessionid {
702 	unsigned char data[NFS4_MAX_SESSIONID_LEN];
703 };
704 
705 /* Create Session Flags */
706 #define SESSION4_PERSIST	0x001
707 #define SESSION4_BACK_CHAN	0x002
708 #define SESSION4_RDMA		0x004
709 
710 #define SESSION4_FLAG_MASK_A	0x007
711 
712 enum state_protect_how4 {
713 	SP4_NONE	= 0,
714 	SP4_MACH_CRED	= 1,
715 	SP4_SSV		= 2
716 };
717 
718 /* GET_DIR_DELEGATION non-fatal status codes */
719 enum gddrnf4_status {
720 	GDD4_OK		= 0,
721 	GDD4_UNAVAIL	= 1
722 };
723 
724 enum pnfs_layouttype {
725 	LAYOUT_NFSV4_1_FILES  = 1,
726 	LAYOUT_OSD2_OBJECTS = 2,
727 	LAYOUT_BLOCK_VOLUME = 3,
728 	LAYOUT_FLEX_FILES = 4,
729 	LAYOUT_SCSI = 5,
730 	LAYOUT_TYPE_MAX
731 };
732 
733 /* used for both layout return and recall */
734 enum pnfs_layoutreturn_type {
735 	RETURN_FILE = 1,
736 	RETURN_FSID = 2,
737 	RETURN_ALL  = 3
738 };
739 
740 enum pnfs_iomode {
741 	IOMODE_READ = 1,
742 	IOMODE_RW = 2,
743 	IOMODE_ANY = 3,
744 };
745 
746 enum pnfs_notify_deviceid_type4 {
747 	NOTIFY_DEVICEID4_CHANGE = 1 << 1,
748 	NOTIFY_DEVICEID4_DELETE = 1 << 2,
749 };
750 
751 enum pnfs_block_volume_type {
752 	PNFS_BLOCK_VOLUME_SIMPLE	= 0,
753 	PNFS_BLOCK_VOLUME_SLICE		= 1,
754 	PNFS_BLOCK_VOLUME_CONCAT	= 2,
755 	PNFS_BLOCK_VOLUME_STRIPE	= 3,
756 	PNFS_BLOCK_VOLUME_SCSI		= 4,
757 };
758 
759 enum pnfs_block_extent_state {
760 	PNFS_BLOCK_READWRITE_DATA	= 0,
761 	PNFS_BLOCK_READ_DATA		= 1,
762 	PNFS_BLOCK_INVALID_DATA		= 2,
763 	PNFS_BLOCK_NONE_DATA		= 3,
764 };
765 
766 /* on the wire size of a block layout extent */
767 #define PNFS_BLOCK_EXTENT_SIZE \
768 	(7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE)
769 
770 /* on the wire size of a scsi commit range */
771 #define PNFS_SCSI_RANGE_SIZE \
772 	(4 * sizeof(__be32))
773 
774 enum scsi_code_set {
775 	PS_CODE_SET_BINARY	= 1,
776 	PS_CODE_SET_ASCII	= 2,
777 	PS_CODE_SET_UTF8	= 3
778 };
779 
780 enum scsi_designator_type {
781 	PS_DESIGNATOR_T10	= 1,
782 	PS_DESIGNATOR_EUI64	= 2,
783 	PS_DESIGNATOR_NAA	= 3,
784 	PS_DESIGNATOR_NAME	= 8
785 };
786 
787 #define NFL4_UFLG_MASK			0x0000003F
788 #define NFL4_UFLG_DENSE			0x00000001
789 #define NFL4_UFLG_COMMIT_THRU_MDS	0x00000002
790 #define NFL4_UFLG_STRIPE_UNIT_SIZE_MASK	0xFFFFFFC0
791 
792 /* Encoded in the loh_body field of type layouthint4 */
793 enum filelayout_hint_care4 {
794 	NFLH4_CARE_DENSE		= NFL4_UFLG_DENSE,
795 	NFLH4_CARE_COMMIT_THRU_MDS	= NFL4_UFLG_COMMIT_THRU_MDS,
796 	NFLH4_CARE_STRIPE_UNIT_SIZE	= 0x00000040,
797 	NFLH4_CARE_STRIPE_COUNT		= 0x00000080
798 };
799 
800 #define NFS4_DEVICEID4_SIZE 16
801 
802 struct nfs4_deviceid {
803 	char data[NFS4_DEVICEID4_SIZE];
804 };
805 
806 enum data_content4 {
807 	NFS4_CONTENT_DATA		= 0,
808 	NFS4_CONTENT_HOLE		= 1,
809 };
810 
811 enum pnfs_update_layout_reason {
812 	PNFS_UPDATE_LAYOUT_UNKNOWN = 0,
813 	PNFS_UPDATE_LAYOUT_NO_PNFS,
814 	PNFS_UPDATE_LAYOUT_RD_ZEROLEN,
815 	PNFS_UPDATE_LAYOUT_MDSTHRESH,
816 	PNFS_UPDATE_LAYOUT_NOMEM,
817 	PNFS_UPDATE_LAYOUT_BULK_RECALL,
818 	PNFS_UPDATE_LAYOUT_IO_TEST_FAIL,
819 	PNFS_UPDATE_LAYOUT_FOUND_CACHED,
820 	PNFS_UPDATE_LAYOUT_RETURN,
821 	PNFS_UPDATE_LAYOUT_RETRY,
822 	PNFS_UPDATE_LAYOUT_BLOCKED,
823 	PNFS_UPDATE_LAYOUT_INVALID_OPEN,
824 	PNFS_UPDATE_LAYOUT_SEND_LAYOUTGET,
825 	PNFS_UPDATE_LAYOUT_EXIT,
826 };
827 
828 #define NFS4_OP_MAP_NUM_LONGS					\
829 	DIV_ROUND_UP(LAST_NFS4_OP, 8 * sizeof(unsigned long))
830 #define NFS4_OP_MAP_NUM_WORDS \
831 	(NFS4_OP_MAP_NUM_LONGS * sizeof(unsigned long) / sizeof(u32))
832 struct nfs4_op_map {
833 	union {
834 		unsigned long longs[NFS4_OP_MAP_NUM_LONGS];
835 		u32 words[NFS4_OP_MAP_NUM_WORDS];
836 	} u;
837 };
838 
839 struct nfs42_netaddr {
840 	char		netid[RPCBIND_MAXNETIDLEN];
841 	char		addr[RPCBIND_MAXUADDRLEN + 1];
842 	u32		netid_len;
843 	u32		addr_len;
844 };
845 
846 enum netloc_type4 {
847 	NL4_NAME		= 1,
848 	NL4_URL			= 2,
849 	NL4_NETADDR		= 3,
850 };
851 
852 struct nl4_server {
853 	enum netloc_type4	nl4_type;
854 	union {
855 		struct { /* NL4_NAME, NL4_URL */
856 			int	nl4_str_sz;
857 			char	nl4_str[NFS4_OPAQUE_LIMIT + 1];
858 		};
859 		struct nfs42_netaddr	nl4_addr; /* NL4_NETADDR */
860 	} u;
861 };
862 
863 enum nfs4_change_attr_type {
864 	NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR = 0,
865 	NFS4_CHANGE_TYPE_IS_VERSION_COUNTER = 1,
866 	NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS = 2,
867 	NFS4_CHANGE_TYPE_IS_TIME_METADATA = 3,
868 	NFS4_CHANGE_TYPE_IS_UNDEFINED = 4,
869 };
870 
871 /*
872  * Options for setxattr. These match the flags for setxattr(2).
873  */
874 enum nfs4_setxattr_options {
875 	SETXATTR4_EITHER	= 0,
876 	SETXATTR4_CREATE	= 1,
877 	SETXATTR4_REPLACE	= 2,
878 };
879 
880 enum {
881 	RCA4_TYPE_MASK_RDATA_DLG	= 0,
882 	RCA4_TYPE_MASK_WDATA_DLG	= 1,
883 	RCA4_TYPE_MASK_DIR_DLG		= 2,
884 	RCA4_TYPE_MASK_FILE_LAYOUT	= 3,
885 	RCA4_TYPE_MASK_BLK_LAYOUT	= 4,
886 	RCA4_TYPE_MASK_OBJ_LAYOUT_MIN	= 8,
887 	RCA4_TYPE_MASK_OBJ_LAYOUT_MAX	= 9,
888 	RCA4_TYPE_MASK_OTHER_LAYOUT_MIN	= 12,
889 	RCA4_TYPE_MASK_OTHER_LAYOUT_MAX	= 15,
890 };
891 
892 enum nfs_cb_opnum4 {
893 	OP_CB_GETATTR = 3,
894 	OP_CB_RECALL  = 4,
895 
896 	/* Callback operations new to NFSv4.1 */
897 	OP_CB_LAYOUTRECALL  = 5,
898 	OP_CB_NOTIFY        = 6,
899 	OP_CB_PUSH_DELEG    = 7,
900 	OP_CB_RECALL_ANY    = 8,
901 	OP_CB_RECALLABLE_OBJ_AVAIL = 9,
902 	OP_CB_RECALL_SLOT   = 10,
903 	OP_CB_SEQUENCE      = 11,
904 	OP_CB_WANTS_CANCELLED = 12,
905 	OP_CB_NOTIFY_LOCK   = 13,
906 	OP_CB_NOTIFY_DEVICEID = 14,
907 
908 	/* Callback operations new to NFSv4.2 */
909 	OP_CB_OFFLOAD = 15,
910 
911 	OP_CB_ILLEGAL = 10044,
912 };
913 
914 #endif
915