1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 #ifndef _NFS_RNODE4_H 30 #define _NFS_RNODE4_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <nfs/rnode.h> /* for symlink_cache, nfs_rwlock_t, etc. */ 37 #include <nfs/nfs4.h> 38 #include <nfs/nfs4_clnt.h> 39 #include <sys/thread.h> 40 #include <sys/sysmacros.h> /* for offsetof */ 41 42 typedef enum nfs4_stub_type { 43 NFS4_STUB_NONE, 44 NFS4_STUB_MIRRORMOUNT 45 } nfs4_stub_type_t; 46 47 typedef enum nfs4_access_type { 48 NFS4_ACCESS_UNKNOWN, 49 NFS4_ACCESS_ALLOWED, 50 NFS4_ACCESS_DENIED 51 } nfs4_access_type_t; 52 53 /* 54 * Access cache 55 */ 56 typedef struct acache4_hash { 57 struct acache4 *next; 58 struct acache4 *prev; 59 krwlock_t lock; 60 } acache4_hash_t; 61 62 typedef struct acache4 { 63 struct acache4 *next; /* next and prev must be first */ 64 struct acache4 *prev; 65 uint32_t known; 66 uint32_t allowed; 67 struct rnode4 *rnode; 68 cred_t *cred; 69 struct acache4 *list; 70 struct acache4_hash *hashq; 71 } acache4_t; 72 73 /* 74 * Note on the different buffer sizes in rddir4_cache: 75 * There seems to be some discrepancy between the intended and actual 76 * use of entlen and buflen, which does not correspond to the comment below. 77 * entlen - nfsv2/3 used as both alloc'd size of entries buffer and 78 * as the actual size of the entries (XXX is this correct?). 79 * nfsv4 will use it only as the alloc'd size. 80 * buflen - used for calculations of readahead. 81 * actlen - added for nfsv4 to serve as the size of the useful 82 * portion of the entries buffer. That is because in 83 * nfsv4, the otw entries are converted to system entries, 84 * and may not be the same size - thus buffer may not be full. 85 */ 86 typedef struct rddir4_cache { 87 lloff_t _cookie; /* cookie used to find this cache entry */ 88 lloff_t _ncookie; /* cookie used to find the next cache entry */ 89 char *entries; /* buffer containing dirent entries */ 90 int eof; /* EOF reached after this request */ 91 int entlen; /* size of dirent entries in buf */ 92 int buflen; /* size of the buffer used to store entries */ 93 int actlen; /* size of the actual entries (nfsv4 only) */ 94 int flags; /* control flags, see below */ 95 kcondvar_t cv; /* cv for blocking */ 96 int error; /* error from RPC operation */ 97 void *data; /* private data */ 98 } rddir4_cache; 99 100 #define nfs4_cookie _cookie._f 101 #define nfs4_ncookie _ncookie._f 102 103 /* 104 * Shadow vnode, v4 only. 105 * 106 * A file's shadow vnode list is protected by its hash bucket lock, 107 * r_hashq->r_lock. 108 * 109 * sv_r_vnode is protected by the appropriate vnode locks. 110 * 111 * sv_dfh, sv_name, sv_dfileid, and sv_dfileid_valid are protected 112 * by rp->r_svlock. 113 */ 114 115 typedef struct insq_link { 116 void *forw; 117 void *back; 118 } insq_link_t; 119 120 typedef struct svnode { 121 insq_link_t sv_link; /* must be first for insque */ 122 vnode_t *sv_r_vnode; /* vnode for this shadow */ 123 nfs4_fname_t *sv_name; /* component name */ 124 nfs4_sharedfh_t *sv_dfh; /* directory file handle */ 125 } svnode_t; 126 127 #define sv_forw sv_link.forw 128 #define sv_back sv_link.back 129 extern svnode_t *vtosv(vnode_t *); 130 #define VTOSV(vp) vtosv(vp) 131 #define SVTOV(svp) (((svp)->sv_r_vnode)) 132 #define IS_SHADOW(vp, rp) ((vp) != (rp)->r_vnode) 133 134 /* 135 * The format of the hash bucket used to lookup rnodes from a file handle. 136 */ 137 typedef struct r4hashq { 138 struct rnode4 *r_hashf; 139 struct rnode4 *r_hashb; 140 krwlock_t r_lock; 141 } r4hashq_t; 142 143 /* 144 * Remote file information structure. 145 * 146 * The rnode is the "inode" for remote files. It contains all the 147 * information necessary to handle remote file on the client side. 148 * 149 * Note on file sizes: we keep two file sizes in the rnode: the size 150 * according to the client (r_size) and the size according to the server 151 * (r_attr.va_size). They can differ because we modify r_size during a 152 * write system call (nfs_rdwr), before the write request goes over the 153 * wire (before the file is actually modified on the server). If an OTW 154 * request occurs before the cached data is written to the server the file 155 * size returned from the server (r_attr.va_size) may not match r_size. 156 * r_size is the one we use, in general. r_attr.va_size is only used to 157 * determine whether or not our cached data is valid. 158 * 159 * Each rnode has 5 locks associated with it (not including the rnode 160 * hash table and free list locks): 161 * 162 * r_rwlock: Serializes nfs_write and nfs_setattr requests 163 * and allows nfs_read requests to proceed in parallel. 164 * Serializes reads/updates to directories. 165 * 166 * r_lkserlock: Serializes lock requests with map, write, and 167 * readahead operations. 168 * 169 * r_statelock: Protects all fields in the rnode except for 170 * those listed below. This lock is intented 171 * to be held for relatively short periods of 172 * time (not accross entire putpage operations, 173 * for example). 174 * 175 * r_statev4_lock: Protects the created_v4 flag, the lock_owners list, 176 * and all the delegation fields except r_deleg_list. 177 * 178 * r_os_lock: Protects r_open_streams. 179 * 180 * 181 * The following members are protected by the mutex rp4freelist_lock: 182 * r_freef 183 * r_freeb 184 * 185 * The following members are protected by the hash bucket rwlock: 186 * r_hashf 187 * r_hashb 188 * 189 * r_fh is read-only except when an rnode is created (or recycled from the 190 * free list). 191 * 192 * The following members are protected by nfs4_server_t::s_lock: 193 * r_deleg_list 194 * 195 * Note: r_modaddr is only accessed when the r_statelock mutex is held. 196 * Its value is also controlled via r_rwlock. It is assumed that 197 * there will be only 1 writer active at a time, so it safe to 198 * set r_modaddr and release r_statelock as long as the r_rwlock 199 * writer lock is held. 200 * 201 * r_inmap informs nfs4_read()/write() that there is a call to nfs4_map() 202 * in progress. nfs4_read()/write() check r_inmap to decide whether 203 * to perform directio on the file or not. r_inmap is atomically 204 * incremented in nfs4_map() before the address space routines are 205 * called and atomically decremented just before nfs4_map() exits. 206 * r_inmap is not protected by any lock. 207 * 208 * r_mapcnt tells that the rnode has mapped pages. r_inmap can be 0 209 * while the rnode has mapped pages. 210 * 211 * 64-bit offsets: the code formerly assumed that atomic reads of 212 * r_size were safe and reliable; on 32-bit architectures, this is 213 * not true since an intervening bus cycle from another processor 214 * could update half of the size field. The r_statelock must now 215 * be held whenever any kind of access of r_size is made. 216 * 217 * Lock ordering: 218 * r_rwlock > r_lkserlock > r_os_lock > r_statelock > r_statev4_lock 219 * vnode_t::v_lock > r_os_lock 220 */ 221 struct exportinfo; /* defined in nfs/export.h */ 222 struct servinfo4; /* defined in nfs/nfs4_clnt.h */ 223 struct failinfo; /* defined in nfs/nfs_clnt.h */ 224 struct mntinfo4; /* defined in nfs/nfs4_clnt.h */ 225 226 typedef struct rnode4 { 227 /* the hash fields must be first to match the rhashq_t */ 228 struct rnode4 *r_hashf; /* hash queue forward pointer */ 229 struct rnode4 *r_hashb; /* hash queue back pointer */ 230 struct rnode4 *r_freef; /* free list forward pointer */ 231 struct rnode4 *r_freeb; /* free list back pointer */ 232 r4hashq_t *r_hashq; /* pointer to the hash bucket */ 233 234 svnode_t r_svnode; /* "master" shadow vnode for file */ 235 kmutex_t r_svlock; /* serializes access to svnode list */ 236 nfs_rwlock_t r_rwlock; /* serializes write/setattr requests */ 237 nfs_rwlock_t r_lkserlock; /* serialize lock with other ops */ 238 kmutex_t r_statelock; /* protects (most of) rnode contents */ 239 nfs4_sharedfh_t *r_fh; /* file handle */ 240 struct servinfo4 241 *r_server; /* current server */ 242 u_offset_t r_nextr; /* next byte read offset (read-ahead) */ 243 uint_t r_flags; /* flags, see below */ 244 short r_error; /* async write error */ 245 cred_t *r_unlcred; /* unlinked credentials */ 246 char *r_unlname; /* unlinked file name */ 247 vnode_t *r_unldvp; /* parent dir of unlinked file */ 248 vnode_t *r_xattr_dir; /* cached xattr dir vnode */ 249 len_t r_size; /* client's view of file size */ 250 vattr_t r_attr; /* cached vnode attributes */ 251 hrtime_t r_time_attr_saved; /* time attributes were cached */ 252 hrtime_t r_time_attr_inval; /* time attributes become invalid */ 253 hrtime_t r_time_cache_inval; /* time caches become invalid */ 254 time_t r_delay_wait; /* future time for DELAY handling */ 255 int r_delay_interval; /* Number of Secs of last DELAY */ 256 time_t r_last_recov; /* time of last recovery operation */ 257 nfs4_recov_t r_recov_act; /* action from last recovery op */ 258 long r_mapcnt; /* count of mmapped pages */ 259 uint_t r_count; /* # of refs not reflect in v_count */ 260 uint_t r_awcount; /* # of outstanding async write */ 261 uint_t r_gcount; /* getattrs waiting to flush pages */ 262 kcondvar_t r_cv; /* condvar for blocked threads */ 263 int (*r_putapage) /* address of putapage routine */ 264 (vnode_t *, page_t *, u_offset_t *, size_t *, int, cred_t *); 265 void *r_dir; /* cache of readdir responses */ 266 rddir4_cache *r_direof; /* pointer to the EOF entry */ 267 symlink_cache r_symlink; /* cached readlink response */ 268 verifier4 r_writeverf; /* file data write verifier */ 269 u_offset_t r_modaddr; /* address for page in writerp */ 270 commit_t r_commit; /* commit information */ 271 u_offset_t r_truncaddr; /* base for truncate operation */ 272 vsecattr_t *r_secattr; /* cached security attributes (acls) */ 273 verifier4 r_cookieverf4; /* version 4 readdir cookie verifier */ 274 nfs4_pathconf_info_t r_pathconf; /* cached pathconf info */ 275 acache4_t *r_acache; /* list of access cache entries */ 276 list_t r_open_streams; /* open streams list */ 277 kmutex_t r_os_lock; /* protects r_open_streams */ 278 nfs4_lock_owner_t 279 r_lo_head; /* lock owners list head */ 280 int created_v4; /* 1 if file has been created in v4 */ 281 kmutex_t r_statev4_lock; /* protects created_v4, state4ptr */ 282 283 list_node_t r_deleg_link; /* linkage into list of */ 284 /* delegated rnodes for this server */ 285 open_delegation_type4 286 r_deleg_type; /* type of delegation granted */ 287 stateid4 r_deleg_stateid; 288 /* delegation state id */ 289 nfs_space_limit4 290 r_deleg_limit; /* file limits returned from */ 291 /* server on delegated open */ 292 nfsace4 r_deleg_perms; /* file permissions returned from */ 293 /* server on delegated open */ 294 fattr4_change r_deleg_change; /* current deleg change attr */ 295 fattr4_change r_deleg_change_grant; 296 /* change @ write deleg grant */ 297 cred_t *r_deleg_cred; /* credential in force when the */ 298 /* delegation was granted */ 299 open_delegation_type4 300 r_deleg_needs_recovery; 301 /* delegation needs recovery */ 302 /* This contains the delegation type */ 303 /* for use with CLAIM_PREVIOUS. */ 304 /* OPEN_DELEGATE_NONE means recovery */ 305 /* is not needed. */ 306 unsigned r_deleg_needs_recall:1; 307 /* delegation has been recalled by */ 308 /* the server during open with */ 309 /* CLAIM_PREVIOUS */ 310 unsigned r_deleg_return_pending:1; 311 /* delegreturn is pending, don't use */ 312 /* the delegation stateid, set in */ 313 /* nfs4_dlistadd */ 314 unsigned r_deleg_return_inprog:1; 315 /* delegreturn is in progress, may */ 316 /* only be set by nfs4delegreturn. */ 317 nfs_rwlock_t r_deleg_recall_lock; 318 /* lock for synchronizing delegreturn */ 319 /* with in other operations, acquired */ 320 /* in read mode by nfs4_start_fop, */ 321 /* acquired in write mode in */ 322 /* nfs4delegreturn */ 323 fattr4_change r_change; /* GETATTR4 change attr; client */ 324 /* should always request change */ 325 /* when c/mtime requested to keep */ 326 /* change and c/mtime in sync */ 327 fattr4_fileid r_mntd_fid; /* mounted on fileid attr */ 328 kthread_t *r_serial; /* attrcache validation thread */ 329 kthread_t *r_pgflush; /* thread flushing page cache */ 330 list_t r_indelmap; /* list of delmap callers */ 331 fattr4_fsid r_srv_fsid; /* fsid of srv fs containing object */ 332 /* when rnode created; compare with */ 333 /* sv_fsid (servinfo4_t) to see why */ 334 /* stub type was set */ 335 nfs4_stub_type_t r_stub_type; 336 /* e.g. mirror-mount */ 337 uint_t r_inmap; /* to serialize read/write and mmap */ 338 } rnode4_t; 339 340 #define r_vnode r_svnode.sv_r_vnode 341 342 /* 343 * Flags 344 */ 345 #define R4READDIRWATTR 0x1 /* Use READDIR with attributes */ 346 #define R4DIRTY 0x2 /* dirty pages from write operation */ 347 #define R4STALE 0x4 /* stale, don't even attempt to write */ 348 #define R4MODINPROGRESS 0x8 /* page modification happening */ 349 #define R4TRUNCATE 0x10 /* truncating, don't commit */ 350 #define R4HAVEVERF 0x20 /* have a write verifier to compare against */ 351 #define R4COMMIT 0x40 /* commit in progress */ 352 #define R4COMMITWAIT 0x80 /* someone is waiting to do a commit */ 353 #define R4HASHED 0x100 /* rnode is in hash queues */ 354 #define R4OUTOFSPACE 0x200 /* an out of space error has happened */ 355 #define R4LODANGLERS 0x400 /* rnode has dangling lock_owners to cleanup */ 356 #define R4WRITEMODIFIED 0x800 /* file data has been modified by write */ 357 #define R4DIRECTIO 0x1000 /* bypass the buffer cache */ 358 #define R4RECOVERR 0x2000 /* couldn't recover */ 359 #define R4RECEXPFH 0x4000 /* recovering expired filehandle */ 360 #define R4RECOVERRP 0x8000 /* R4RECOVERR pending, but not set (yet) */ 361 #define R4ISXATTR 0x20000 /* rnode is a named attribute */ 362 #define R4DELMAPLIST 0x40000 /* delmap callers tracked for as callback */ 363 #define R4PGFLUSH 0x80000 /* page flush thread active */ 364 #define R4INCACHEPURGE 0x100000 /* purging caches due to file size change */ 365 #define R4LOOKUP 0x200000 /* a lookup has been done in the directory */ 366 /* 367 * Convert between vnode and rnode 368 */ 369 #define RTOV4(rp) ((rp)->r_vnode) 370 #define VTOR4(vp) ((rnode4_t *)((vp)->v_data)) 371 372 #define RP_ISSTUB(rp) (((rp)->r_stub_type != NFS4_STUB_NONE)) 373 #define RP_ISSTUB_MIRRORMOUNT(rp) ((rp)->r_stub_type == NFS4_STUB_MIRRORMOUNT) 374 375 /* 376 * Open file instances. 377 */ 378 379 typedef struct nfs4_opinst { 380 struct nfs4_opinst *re_next; /* next in list */ 381 vnode_t *re_vp; /* held reference */ 382 uint32_t re_numosp; /* number of valid open streams */ 383 nfs4_open_stream_t **re_osp; /* held reference */ 384 } nfs4_opinst_t; 385 386 #ifdef _KERNEL 387 388 extern long nrnode; 389 390 /* Used for r_delay_interval */ 391 #define NFS4_INITIAL_DELAY_INTERVAL 1 392 #define NFS4_MAX_DELAY_INTERVAL 20 393 394 /* Used for check_rtable4 */ 395 #define NFSV4_RTABLE4_OK 0 396 #define NFSV4_RTABLE4_NOT_FREE_LIST 1 397 #define NFSV4_RTABLE4_DIRTY_PAGES 2 398 #define NFSV4_RTABLE4_POS_R_COUNT 3 399 400 extern rnode4_t *r4find(r4hashq_t *, nfs4_sharedfh_t *, struct vfs *); 401 extern rnode4_t *r4find_unlocked(nfs4_sharedfh_t *, struct vfs *); 402 extern void r4flush(struct vfs *, cred_t *); 403 extern void destroy_rtable4(struct vfs *, cred_t *); 404 extern int check_rtable4(struct vfs *); 405 extern void rp4_addfree(rnode4_t *, cred_t *); 406 extern void rp4_addhash(rnode4_t *); 407 extern void rp4_rmhash(rnode4_t *); 408 extern void rp4_rmhash_locked(rnode4_t *); 409 extern int rtable4hash(nfs4_sharedfh_t *); 410 411 extern vnode_t *makenfs4node(nfs4_sharedfh_t *, nfs4_ga_res_t *, struct vfs *, 412 hrtime_t, cred_t *, vnode_t *, nfs4_fname_t *); 413 extern vnode_t *makenfs4node_by_fh(nfs4_sharedfh_t *, nfs4_sharedfh_t *, 414 nfs4_fname_t **, nfs4_ga_res_t *, mntinfo4_t *, cred_t *, hrtime_t); 415 416 extern nfs4_opinst_t *r4mkopenlist(struct mntinfo4 *); 417 extern void r4releopenlist(nfs4_opinst_t *); 418 419 /* Access cache calls */ 420 extern nfs4_access_type_t nfs4_access_check(rnode4_t *, uint32_t, cred_t *); 421 extern void nfs4_access_cache(rnode4_t *rp, uint32_t, uint32_t, cred_t *); 422 extern int nfs4_access_purge_rp(rnode4_t *); 423 424 extern int nfs4_free_data_reclaim(rnode4_t *); 425 extern void nfs4_rnode_invalidate(struct vfs *); 426 427 extern time_t r2lease_time(rnode4_t *); 428 extern int nfs4_directio(vnode_t *, int, cred_t *); 429 430 /* shadow vnode functions */ 431 extern void sv_activate(vnode_t **, vnode_t *, nfs4_fname_t **, int); 432 extern vnode_t *sv_find(vnode_t *, vnode_t *, nfs4_fname_t **); 433 extern void sv_update_path(vnode_t *, char *, char *); 434 extern void sv_inactive(vnode_t *); 435 extern void sv_exchange(vnode_t **); 436 extern void sv_uninit(svnode_t *); 437 extern void nfs4_clear_open_streams(rnode4_t *); 438 439 /* 440 * Mark cached attributes as timed out 441 * 442 * The caller must not be holding the rnode r_statelock mutex. 443 */ 444 #define PURGE_ATTRCACHE4_LOCKED(rp) \ 445 rp->r_time_attr_inval = gethrtime(); \ 446 rp->r_time_attr_saved = rp->r_time_attr_inval; \ 447 rp->r_pathconf.pc4_xattr_valid = 0; \ 448 rp->r_pathconf.pc4_cache_valid = 0; 449 450 #define PURGE_ATTRCACHE4(vp) { \ 451 rnode4_t *rp = VTOR4(vp); \ 452 mutex_enter(&rp->r_statelock); \ 453 PURGE_ATTRCACHE4_LOCKED(rp); \ 454 mutex_exit(&rp->r_statelock); \ 455 } 456 457 458 extern void nfs4_async_readdir(vnode_t *, rddir4_cache *, 459 cred_t *, int (*)(vnode_t *, rddir4_cache *, cred_t *)); 460 extern char *rnode4info(rnode4_t *rp); 461 462 extern int writerp4(rnode4_t *, caddr_t, int, struct uio *, int); 463 extern void nfs4_set_nonvattrs(rnode4_t *, struct nfs4attr_to_vattr *); 464 extern void nfs4delegabandon(rnode4_t *); 465 extern stateid4 nfs4_get_w_stateid(cred_t *, rnode4_t *, pid_t, mntinfo4_t *, 466 nfs_opnum4, nfs4_stateid_types_t *); 467 extern stateid4 nfs4_get_stateid(cred_t *, rnode4_t *, pid_t, mntinfo4_t *, 468 nfs_opnum4, nfs4_stateid_types_t *, bool_t); 469 extern nfsstat4 nfs4_find_or_create_lock_owner(pid_t, rnode4_t *, cred_t *, 470 nfs4_open_owner_t **, nfs4_open_stream_t **, 471 nfs4_lock_owner_t **); 472 extern cred_t *nfs4_get_otw_cred_by_osp(rnode4_t *, cred_t *, 473 nfs4_open_stream_t **, bool_t *, bool_t *); 474 475 476 /* 477 * Defines for the flag argument of nfs4delegreturn 478 */ 479 #define NFS4_DR_FORCE 0x1 /* discard even if start_op fails */ 480 #define NFS4_DR_PUSH 0x2 /* push modified data back to the server */ 481 #define NFS4_DR_DISCARD 0x4 /* discard the delegation w/o delegreturn */ 482 #define NFS4_DR_DID_OP 0x8 /* calling function did nfs4_start_op */ 483 #define NFS4_DR_RECALL 0x10 /* delegreturn done in response to CB_RECALL */ 484 #define NFS4_DR_REOPEN 0x20 /* perform file reopens, if applicable */ 485 486 extern int nfs4delegreturn(rnode4_t *, int); 487 extern void nfs4_delegreturn_all(nfs4_server_t *); 488 extern void nfs4delegreturn_cleanup(rnode4_t *, nfs4_server_t *); 489 extern void nfs4_delegation_accept(rnode4_t *, open_claim_type4, OPEN4res *, 490 nfs4_ga_res_t *, cred_t *); 491 492 extern void nfs4_dlistclean(void); 493 extern void nfs4_deleg_discard(mntinfo4_t *, nfs4_server_t *); 494 495 extern void rddir4_cache_create(rnode4_t *); 496 extern void rddir4_cache_purge(rnode4_t *); 497 extern void rddir4_cache_destroy(rnode4_t *); 498 extern rddir4_cache *rddir4_cache_lookup(rnode4_t *, offset_t, int); 499 extern void rddir4_cache_rele(rnode4_t *, rddir4_cache *); 500 501 extern void r4_stub_mirrormount(rnode4_t *); 502 extern void r4_stub_none(rnode4_t *); 503 504 #ifdef DEBUG 505 extern char *rddir4_cache_buf_alloc(size_t, int); 506 extern void rddir4_cache_buf_free(void *, size_t); 507 #endif 508 509 510 511 #endif /* _KERNEL */ 512 513 #ifdef __cplusplus 514 } 515 #endif 516 517 #endif /* _NFS_RNODE4_H */ 518