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.
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.
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]
22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
28 * Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/systm.h>
38 #include <sys/vfs_opreg.h>
39 #include <sys/vnode.h>
41 #include <sys/errno.h>
42 #include <sys/sysmacros.h>
43 #include <sys/statvfs.h>
45 #include <sys/dirent.h>
46 #include <sys/cmn_err.h>
47 #include <sys/debug.h>
48 #include <sys/systeminfo.h>
49 #include <sys/flock.h>
50 #include <sys/pathname.h>
51 #include <sys/nbmlock.h>
52 #include <sys/share.h>
53 #include <sys/atomic.h>
54 #include <sys/policy.h>
60 #include <fs/fs_reparse.h>
62 #include <rpc/types.h>
64 #include <rpc/rpcsec_gss.h>
68 #include <nfs/export.h>
69 #include <nfs/nfs_cmd.h>
73 #include <sys/strsubr.h>
74 #include <sys/strsun.h>
76 #include <inet/common.h>
80 #include <sys/tsol/label.h>
81 #include <sys/tsol/tndb.h>
83 #define RFS4_MAXLOCK_TRIES 4 /* Try to get the lock this many times */
84 static int rfs4_maxlock_tries
= RFS4_MAXLOCK_TRIES
;
85 #define RFS4_LOCK_DELAY 10 /* Milliseconds */
86 static clock_t rfs4_lock_delay
= RFS4_LOCK_DELAY
;
87 extern struct svc_ops rdma_svc_ops
;
88 extern int nfs_loaned_buffers
;
91 static int rdma_setup_read_data4(READ4args
*, READ4res
*);
94 * Used to bump the stateid4.seqid value and show changes in the stateid
96 #define next_stateid(sp) (++(sp)->bits.chgseq)
99 * RFS4_MINLEN_ENTRY4: XDR-encoded size of smallest possible dirent.
100 * This is used to return NFS4ERR_TOOSMALL when clients specify
101 * maxcount that isn't large enough to hold the smallest possible
102 * XDR encoded dirent.
104 * sizeof cookie (8 bytes) +
105 * sizeof name_len (4 bytes) +
106 * sizeof smallest (padded) name (4 bytes) +
107 * sizeof bitmap4_len (12 bytes) + NOTE: we always encode len=2 bm4
108 * sizeof attrlist4_len (4 bytes) +
109 * sizeof next boolean (4 bytes)
111 * RFS4_MINLEN_RDDIR4: XDR-encoded size of READDIR op reply containing
112 * the smallest possible entry4 (assumes no attrs requested).
113 * sizeof nfsstat4 (4 bytes) +
114 * sizeof verifier4 (8 bytes) +
115 * sizeof entry4list bool (4 bytes) +
116 * sizeof entry4 (36 bytes) +
117 * sizeof eof bool (4 bytes)
119 * RFS4_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
120 * VOP_READDIR. Its value is the size of the maximum possible dirent
121 * for solaris. The DIRENT64_RECLEN macro returns the size of dirent
122 * required for a given name length. MAXNAMELEN is the maximum
123 * filename length allowed in Solaris. The first two DIRENT64_RECLEN()
124 * macros are to allow for . and .. entries -- just a minor tweak to try
125 * and guarantee that buffer we give to VOP_READDIR will be large enough
126 * to hold ., .., and the largest possible solaris dirent64.
128 #define RFS4_MINLEN_ENTRY4 36
129 #define RFS4_MINLEN_RDDIR4 (4 + NFS4_VERIFIER_SIZE + 4 + RFS4_MINLEN_ENTRY4 + 4)
130 #define RFS4_MINLEN_RDDIR_BUF \
131 (DIRENT64_RECLEN(1) + DIRENT64_RECLEN(2) + DIRENT64_RECLEN(MAXNAMELEN))
134 * It would be better to pad to 4 bytes since that's what XDR would do,
135 * but the dirents UFS gives us are already padded to 8, so just take
136 * what we're given. Dircount is only a hint anyway. Currently the
137 * solaris kernel is ASCII only, so there's no point in calling the
140 * dirent64: named padded to provide 8 byte struct alignment
141 * d_ino(8) + d_off(8) + d_reclen(2) + d_name(namelen + null(1) + pad)
143 * cookie: uint64_t + utf8namelen: uint_t + utf8name padded to 8 bytes
146 #define DIRENT64_TO_DIRCOUNT(dp) \
147 (3 * BYTES_PER_XDR_UNIT + DIRENT64_NAMELEN((dp)->d_reclen))
149 time_t rfs4_start_time
; /* Initialized in rfs4_srvrinit */
151 static sysid_t lockt_sysid
; /* dummy sysid for all LOCKT calls */
153 u_longlong_t nfs4_srv_caller_id
;
154 uint_t nfs4_srv_vkey
= 0;
156 verifier4 Write4verf
;
157 verifier4 Readdir4verf
;
159 void rfs4_init_compound_state(struct compound_state
*);
161 static void nullfree(caddr_t
);
162 static void rfs4_op_inval(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
163 struct compound_state
*);
164 static void rfs4_op_access(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
165 struct compound_state
*);
166 static void rfs4_op_close(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
167 struct compound_state
*);
168 static void rfs4_op_commit(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
169 struct compound_state
*);
170 static void rfs4_op_create(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
171 struct compound_state
*);
172 static void rfs4_op_create_free(nfs_resop4
*resop
);
173 static void rfs4_op_delegreturn(nfs_argop4
*, nfs_resop4
*,
174 struct svc_req
*, struct compound_state
*);
175 static void rfs4_op_delegpurge(nfs_argop4
*, nfs_resop4
*,
176 struct svc_req
*, struct compound_state
*);
177 static void rfs4_op_getattr(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
178 struct compound_state
*);
179 static void rfs4_op_getattr_free(nfs_resop4
*);
180 static void rfs4_op_getfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
181 struct compound_state
*);
182 static void rfs4_op_getfh_free(nfs_resop4
*);
183 static void rfs4_op_illegal(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
184 struct compound_state
*);
185 static void rfs4_op_link(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
186 struct compound_state
*);
187 static void rfs4_op_lock(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
188 struct compound_state
*);
189 static void lock_denied_free(nfs_resop4
*);
190 static void rfs4_op_locku(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
191 struct compound_state
*);
192 static void rfs4_op_lockt(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
193 struct compound_state
*);
194 static void rfs4_op_lookup(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
195 struct compound_state
*);
196 static void rfs4_op_lookupp(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
197 struct compound_state
*);
198 static void rfs4_op_openattr(nfs_argop4
*argop
, nfs_resop4
*resop
,
199 struct svc_req
*req
, struct compound_state
*cs
);
200 static void rfs4_op_nverify(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
201 struct compound_state
*);
202 static void rfs4_op_open(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
203 struct compound_state
*);
204 static void rfs4_op_open_confirm(nfs_argop4
*, nfs_resop4
*,
205 struct svc_req
*, struct compound_state
*);
206 static void rfs4_op_open_downgrade(nfs_argop4
*, nfs_resop4
*,
207 struct svc_req
*, struct compound_state
*);
208 static void rfs4_op_putfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
209 struct compound_state
*);
210 static void rfs4_op_putpubfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
211 struct compound_state
*);
212 static void rfs4_op_putrootfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
213 struct compound_state
*);
214 static void rfs4_op_read(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
215 struct compound_state
*);
216 static void rfs4_op_read_free(nfs_resop4
*);
217 static void rfs4_op_readdir_free(nfs_resop4
*resop
);
218 static void rfs4_op_readlink(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
219 struct compound_state
*);
220 static void rfs4_op_readlink_free(nfs_resop4
*);
221 static void rfs4_op_release_lockowner(nfs_argop4
*, nfs_resop4
*,
222 struct svc_req
*, struct compound_state
*);
223 static void rfs4_op_remove(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
224 struct compound_state
*);
225 static void rfs4_op_rename(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
226 struct compound_state
*);
227 static void rfs4_op_renew(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
228 struct compound_state
*);
229 static void rfs4_op_restorefh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
230 struct compound_state
*);
231 static void rfs4_op_savefh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
232 struct compound_state
*);
233 static void rfs4_op_setattr(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
234 struct compound_state
*);
235 static void rfs4_op_verify(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
236 struct compound_state
*);
237 static void rfs4_op_write(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
238 struct compound_state
*);
239 static void rfs4_op_setclientid(nfs_argop4
*, nfs_resop4
*,
240 struct svc_req
*, struct compound_state
*);
241 static void rfs4_op_setclientid_confirm(nfs_argop4
*, nfs_resop4
*,
242 struct svc_req
*req
, struct compound_state
*);
243 static void rfs4_op_secinfo(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
244 struct compound_state
*);
245 static void rfs4_op_secinfo_free(nfs_resop4
*);
247 static nfsstat4
check_open_access(uint32_t,
248 struct compound_state
*, struct svc_req
*);
249 nfsstat4
rfs4_client_sysid(rfs4_client_t
*, sysid_t
*);
250 void rfs4_ss_clid(rfs4_client_t
*);
253 * translation table for attrs
255 struct nfs4_ntov_table
{
256 union nfs4_attr_u
*na
;
257 uint8_t amap
[NFS4_MAXNUM_ATTRS
];
262 static void nfs4_ntov_table_init(struct nfs4_ntov_table
*ntovp
);
263 static void nfs4_ntov_table_free(struct nfs4_ntov_table
*ntovp
,
264 struct nfs4_svgetit_arg
*sargp
);
266 static nfsstat4
do_rfs4_set_attrs(bitmap4
*resp
, fattr4
*fattrp
,
267 struct compound_state
*cs
, struct nfs4_svgetit_arg
*sargp
,
268 struct nfs4_ntov_table
*ntovp
, nfs4_attr_cmd_t cmd
);
273 rfs4_servinst_t
*rfs4_cur_servinst
= NULL
; /* current server instance */
274 kmutex_t rfs4_servinst_lock
; /* protects linked list */
275 int rfs4_seen_first_compound
; /* set first time we see one */
278 * NFS4 op dispatch table
282 void (*dis_proc
)(); /* proc to call */
283 void (*dis_resfree
)(); /* frees space allocated by proc */
284 int dis_flags
; /* RPC_IDEMPOTENT, etc... */
287 static struct rfsv4disp rfsv4disptab
[] = {
293 {rfs4_op_illegal
, nullfree
, 0},
296 {rfs4_op_illegal
, nullfree
, 0},
299 {rfs4_op_illegal
, nullfree
, 0},
302 {rfs4_op_access
, nullfree
, RPC_IDEMPOTENT
},
305 {rfs4_op_close
, nullfree
, 0},
308 {rfs4_op_commit
, nullfree
, RPC_IDEMPOTENT
},
311 {rfs4_op_create
, nullfree
, 0},
313 /* OP_DELEGPURGE = 7 */
314 {rfs4_op_delegpurge
, nullfree
, 0},
316 /* OP_DELEGRETURN = 8 */
317 {rfs4_op_delegreturn
, nullfree
, 0},
320 {rfs4_op_getattr
, rfs4_op_getattr_free
, RPC_IDEMPOTENT
},
323 {rfs4_op_getfh
, rfs4_op_getfh_free
, RPC_ALL
},
326 {rfs4_op_link
, nullfree
, 0},
329 {rfs4_op_lock
, lock_denied_free
, 0},
332 {rfs4_op_lockt
, lock_denied_free
, 0},
335 {rfs4_op_locku
, nullfree
, 0},
338 {rfs4_op_lookup
, nullfree
, (RPC_IDEMPOTENT
| RPC_PUBLICFH_OK
)},
340 /* OP_LOOKUPP = 16 */
341 {rfs4_op_lookupp
, nullfree
, (RPC_IDEMPOTENT
| RPC_PUBLICFH_OK
)},
343 /* OP_NVERIFY = 17 */
344 {rfs4_op_nverify
, nullfree
, RPC_IDEMPOTENT
},
347 {rfs4_op_open
, rfs4_free_reply
, 0},
349 /* OP_OPENATTR = 19 */
350 {rfs4_op_openattr
, nullfree
, 0},
352 /* OP_OPEN_CONFIRM = 20 */
353 {rfs4_op_open_confirm
, nullfree
, 0},
355 /* OP_OPEN_DOWNGRADE = 21 */
356 {rfs4_op_open_downgrade
, nullfree
, 0},
358 /* OP_OPEN_PUTFH = 22 */
359 {rfs4_op_putfh
, nullfree
, RPC_ALL
},
361 /* OP_PUTPUBFH = 23 */
362 {rfs4_op_putpubfh
, nullfree
, RPC_ALL
},
364 /* OP_PUTROOTFH = 24 */
365 {rfs4_op_putrootfh
, nullfree
, RPC_ALL
},
368 {rfs4_op_read
, rfs4_op_read_free
, RPC_IDEMPOTENT
},
370 /* OP_READDIR = 26 */
371 {rfs4_op_readdir
, rfs4_op_readdir_free
, RPC_IDEMPOTENT
},
373 /* OP_READLINK = 27 */
374 {rfs4_op_readlink
, rfs4_op_readlink_free
, RPC_IDEMPOTENT
},
377 {rfs4_op_remove
, nullfree
, 0},
380 {rfs4_op_rename
, nullfree
, 0},
383 {rfs4_op_renew
, nullfree
, 0},
385 /* OP_RESTOREFH = 31 */
386 {rfs4_op_restorefh
, nullfree
, RPC_ALL
},
389 {rfs4_op_savefh
, nullfree
, RPC_ALL
},
391 /* OP_SECINFO = 33 */
392 {rfs4_op_secinfo
, rfs4_op_secinfo_free
, 0},
394 /* OP_SETATTR = 34 */
395 {rfs4_op_setattr
, nullfree
, 0},
397 /* OP_SETCLIENTID = 35 */
398 {rfs4_op_setclientid
, nullfree
, 0},
400 /* OP_SETCLIENTID_CONFIRM = 36 */
401 {rfs4_op_setclientid_confirm
, nullfree
, 0},
404 {rfs4_op_verify
, nullfree
, RPC_IDEMPOTENT
},
407 {rfs4_op_write
, nullfree
, 0},
409 /* OP_RELEASE_LOCKOWNER = 39 */
410 {rfs4_op_release_lockowner
, nullfree
, 0},
413 static uint_t rfsv4disp_cnt
= sizeof (rfsv4disptab
) / sizeof (rfsv4disptab
[0]);
415 #define OP_ILLEGAL_IDX (rfsv4disp_cnt)
419 int rfs4_fillone_debug
= 0;
420 int rfs4_no_stub_access
= 1;
421 int rfs4_rddir_debug
= 0;
423 static char *rfs4_op_string
[] = {
431 "rfs4_op_delegpurge",
432 "rfs4_op_delegreturn",
444 "rfs4_op_open_confirm",
445 "rfs4_op_open_downgrade",
459 "rfs4_op_setclientid",
460 "rfs4_op_setclient_confirm",
463 "rfs4_op_release_lockowner",
468 void rfs4_ss_chkclid(rfs4_client_t
*);
470 extern size_t strlcpy(char *dst
, const char *src
, size_t dstsize
);
472 extern void rfs4_free_fs_locations4(fs_locations4
*);
477 #define nextdp(dp) ((struct dirent64 *)((char *)(dp) + (dp)->d_reclen))
479 static const fs_operation_def_t nfs4_rd_deleg_tmpl
[] = {
480 VOPNAME_OPEN
, { .femop_open
= deleg_rd_open
},
481 VOPNAME_WRITE
, { .femop_write
= deleg_rd_write
},
482 VOPNAME_SETATTR
, { .femop_setattr
= deleg_rd_setattr
},
483 VOPNAME_RWLOCK
, { .femop_rwlock
= deleg_rd_rwlock
},
484 VOPNAME_SPACE
, { .femop_space
= deleg_rd_space
},
485 VOPNAME_SETSECATTR
, { .femop_setsecattr
= deleg_rd_setsecattr
},
486 VOPNAME_VNEVENT
, { .femop_vnevent
= deleg_rd_vnevent
},
489 static const fs_operation_def_t nfs4_wr_deleg_tmpl
[] = {
490 VOPNAME_OPEN
, { .femop_open
= deleg_wr_open
},
491 VOPNAME_READ
, { .femop_read
= deleg_wr_read
},
492 VOPNAME_WRITE
, { .femop_write
= deleg_wr_write
},
493 VOPNAME_SETATTR
, { .femop_setattr
= deleg_wr_setattr
},
494 VOPNAME_RWLOCK
, { .femop_rwlock
= deleg_wr_rwlock
},
495 VOPNAME_SPACE
, { .femop_space
= deleg_wr_space
},
496 VOPNAME_SETSECATTR
, { .femop_setsecattr
= deleg_wr_setsecattr
},
497 VOPNAME_VNEVENT
, { .femop_vnevent
= deleg_wr_vnevent
},
506 extern void rfs4_attr_init();
507 extern krwlock_t rfs4_deleg_policy_lock
;
510 * The following algorithm attempts to find a unique verifier
511 * to be used as the write verifier returned from the server
512 * to the client. It is important that this verifier change
513 * whenever the server reboots. Of secondary importance, it
514 * is important for the verifier to be unique between two
517 * Thus, an attempt is made to use the system hostid and the
518 * current time in seconds when the nfssrv kernel module is
519 * loaded. It is assumed that an NFS server will not be able
520 * to boot and then to reboot in less than a second. If the
521 * hostid has not been set, then the current high resolution
522 * time is used. This will ensure different verifiers each
523 * time the server reboots and minimize the chances that two
524 * different servers will have the same verifier.
525 * XXX - this is broken on LP64 kernels.
527 verf
.tv_sec
= (time_t)zone_get_hostid(NULL
);
528 if (verf
.tv_sec
!= 0) {
529 verf
.tv_nsec
= gethrestime_sec();
534 verf
.tv_sec
= (time_t)tverf
.tv_sec
;
535 verf
.tv_nsec
= tverf
.tv_nsec
;
538 Write4verf
= *(uint64_t *)&verf
;
541 mutex_init(&rfs4_deleg_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
543 /* Used to manage create/destroy of server state */
544 mutex_init(&rfs4_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
546 /* Used to manage access to server instance linked list */
547 mutex_init(&rfs4_servinst_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
549 /* Used to manage access to rfs4_deleg_policy */
550 rw_init(&rfs4_deleg_policy_lock
, NULL
, RW_DEFAULT
, NULL
);
552 error
= fem_create("deleg_rdops", nfs4_rd_deleg_tmpl
, &deleg_rdops
);
554 rfs4_disable_delegation();
556 error
= fem_create("deleg_wrops", nfs4_wr_deleg_tmpl
,
559 rfs4_disable_delegation();
560 fem_free(deleg_rdops
);
564 nfs4_srv_caller_id
= fs_new_caller_id();
566 lockt_sysid
= lm_alloc_sysidt();
568 vsd_create(&nfs4_srv_vkey
, NULL
);
576 extern krwlock_t rfs4_deleg_policy_lock
;
578 if (lockt_sysid
!= LM_NOSYSID
) {
579 lm_free_sysidt(lockt_sysid
);
580 lockt_sysid
= LM_NOSYSID
;
583 mutex_destroy(&rfs4_deleg_lock
);
584 mutex_destroy(&rfs4_state_lock
);
585 rw_destroy(&rfs4_deleg_policy_lock
);
587 fem_free(deleg_rdops
);
588 fem_free(deleg_wrops
);
592 rfs4_init_compound_state(struct compound_state
*cs
)
594 bzero(cs
, sizeof (*cs
));
596 cs
->access
= CS_ACCESS_DENIED
;
598 cs
->mandlock
= FALSE
;
599 cs
->fh
.nfs_fh4_val
= cs
->fhbuf
;
603 rfs4_grace_start(rfs4_servinst_t
*sip
)
605 rw_enter(&sip
->rwlock
, RW_WRITER
);
606 sip
->start_time
= (time_t)TICK_TO_SEC(ddi_get_lbolt());
607 sip
->grace_period
= rfs4_grace_period
;
608 rw_exit(&sip
->rwlock
);
612 * returns true if the instance's grace period has never been started
615 rfs4_servinst_grace_new(rfs4_servinst_t
*sip
)
619 rw_enter(&sip
->rwlock
, RW_READER
);
620 start_time
= sip
->start_time
;
621 rw_exit(&sip
->rwlock
);
623 return (start_time
== 0);
627 * Indicates if server instance is within the
631 rfs4_servinst_in_grace(rfs4_servinst_t
*sip
)
635 rw_enter(&sip
->rwlock
, RW_READER
);
636 grace_expiry
= sip
->start_time
+ sip
->grace_period
;
637 rw_exit(&sip
->rwlock
);
639 return (((time_t)TICK_TO_SEC(ddi_get_lbolt())) < grace_expiry
);
643 rfs4_clnt_in_grace(rfs4_client_t
*cp
)
645 ASSERT(rfs4_dbe_refcnt(cp
->rc_dbe
) > 0);
647 return (rfs4_servinst_in_grace(cp
->rc_server_instance
));
651 * reset all currently active grace periods
654 rfs4_grace_reset_all(void)
656 rfs4_servinst_t
*sip
;
658 mutex_enter(&rfs4_servinst_lock
);
659 for (sip
= rfs4_cur_servinst
; sip
!= NULL
; sip
= sip
->prev
)
660 if (rfs4_servinst_in_grace(sip
))
661 rfs4_grace_start(sip
);
662 mutex_exit(&rfs4_servinst_lock
);
666 * start any new instances' grace periods
669 rfs4_grace_start_new(void)
671 rfs4_servinst_t
*sip
;
673 mutex_enter(&rfs4_servinst_lock
);
674 for (sip
= rfs4_cur_servinst
; sip
!= NULL
; sip
= sip
->prev
)
675 if (rfs4_servinst_grace_new(sip
))
676 rfs4_grace_start(sip
);
677 mutex_exit(&rfs4_servinst_lock
);
680 static rfs4_dss_path_t
*
681 rfs4_dss_newpath(rfs4_servinst_t
*sip
, char *path
, unsigned index
)
684 rfs4_dss_path_t
*dss_path
;
686 dss_path
= kmem_alloc(sizeof (rfs4_dss_path_t
), KM_SLEEP
);
689 * Take a copy of the string, since the original may be overwritten.
690 * Sadly, no strdup() in the kernel.
693 len
= strlen(path
) + 1;
694 dss_path
->path
= kmem_alloc(len
, KM_SLEEP
);
695 (void) strlcpy(dss_path
->path
, path
, len
);
697 /* associate with servinst */
699 dss_path
->index
= index
;
702 * Add to list of served paths.
703 * No locking required, as we're only ever called at startup.
705 if (rfs4_dss_pathlist
== NULL
) {
706 /* this is the first dss_path_t */
708 /* needed for insque/remque */
709 dss_path
->next
= dss_path
->prev
= dss_path
;
711 rfs4_dss_pathlist
= dss_path
;
713 insque(dss_path
, rfs4_dss_pathlist
);
720 * Create a new server instance, and make it the currently active instance.
721 * Note that starting the grace period too early will reduce the clients'
725 rfs4_servinst_create(int start_grace
, int dss_npaths
, char **dss_paths
)
728 rfs4_servinst_t
*sip
;
729 rfs4_oldstate_t
*oldstate
;
731 sip
= kmem_alloc(sizeof (rfs4_servinst_t
), KM_SLEEP
);
732 rw_init(&sip
->rwlock
, NULL
, RW_DEFAULT
, NULL
);
734 sip
->start_time
= (time_t)0;
735 sip
->grace_period
= (time_t)0;
739 rw_init(&sip
->oldstate_lock
, NULL
, RW_DEFAULT
, NULL
);
741 * This initial dummy entry is required to setup for insque/remque.
742 * It must be skipped over whenever the list is traversed.
744 oldstate
= kmem_alloc(sizeof (rfs4_oldstate_t
), KM_SLEEP
);
745 /* insque/remque require initial list entry to be self-terminated */
746 oldstate
->next
= oldstate
;
747 oldstate
->prev
= oldstate
;
748 sip
->oldstate
= oldstate
;
751 sip
->dss_npaths
= dss_npaths
;
752 sip
->dss_paths
= kmem_alloc(dss_npaths
*
753 sizeof (rfs4_dss_path_t
*), KM_SLEEP
);
755 for (i
= 0; i
< dss_npaths
; i
++) {
756 sip
->dss_paths
[i
] = rfs4_dss_newpath(sip
, dss_paths
[i
], i
);
759 mutex_enter(&rfs4_servinst_lock
);
760 if (rfs4_cur_servinst
!= NULL
) {
761 /* add to linked list */
762 sip
->prev
= rfs4_cur_servinst
;
763 rfs4_cur_servinst
->next
= sip
;
766 rfs4_grace_start(sip
);
767 /* make the new instance "current" */
768 rfs4_cur_servinst
= sip
;
770 mutex_exit(&rfs4_servinst_lock
);
774 * In future, we might add a rfs4_servinst_destroy(sip) but, for now, destroy
775 * all instances directly.
778 rfs4_servinst_destroy_all(void)
780 rfs4_servinst_t
*sip
, *prev
, *current
;
785 mutex_enter(&rfs4_servinst_lock
);
786 ASSERT(rfs4_cur_servinst
!= NULL
);
787 current
= rfs4_cur_servinst
;
788 rfs4_cur_servinst
= NULL
;
789 for (sip
= current
; sip
!= NULL
; sip
= prev
) {
791 rw_destroy(&sip
->rwlock
);
793 kmem_free(sip
->oldstate
, sizeof (rfs4_oldstate_t
));
795 kmem_free(sip
->dss_paths
,
796 sip
->dss_npaths
* sizeof (rfs4_dss_path_t
*));
797 kmem_free(sip
, sizeof (rfs4_servinst_t
));
802 mutex_exit(&rfs4_servinst_lock
);
806 * Assign the current server instance to a client_t.
807 * Should be called with cp->rc_dbe held.
810 rfs4_servinst_assign(rfs4_client_t
*cp
, rfs4_servinst_t
*sip
)
812 ASSERT(rfs4_dbe_refcnt(cp
->rc_dbe
) > 0);
815 * The lock ensures that if the current instance is in the process
816 * of changing, we will see the new one.
818 mutex_enter(&rfs4_servinst_lock
);
819 cp
->rc_server_instance
= sip
;
820 mutex_exit(&rfs4_servinst_lock
);
824 rfs4_servinst(rfs4_client_t
*cp
)
826 ASSERT(rfs4_dbe_refcnt(cp
->rc_dbe
) > 0);
828 return (cp
->rc_server_instance
);
833 nullfree(caddr_t resop
)
838 * This is a fall-through for invalid or not implemented (yet) ops
842 rfs4_op_inval(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
843 struct compound_state
*cs
)
845 *cs
->statusp
= *((nfsstat4
*)&(resop
)->nfs_resop4_u
) = NFS4ERR_INVAL
;
849 * Check if the security flavor, nfsnum, is in the flavor_list.
852 in_flavor_list(int nfsnum
, int *flavor_list
, int count
)
856 for (i
= 0; i
< count
; i
++) {
857 if (nfsnum
== flavor_list
[i
])
864 * Used by rfs4_op_secinfo to get the security information from the
865 * export structure associated with the component.
869 do_rfs4_op_secinfo(struct compound_state
*cs
, char *nm
, SECINFO4res
*resp
)
871 int error
, different_export
= 0;
872 vnode_t
*dvp
, *vp
, *tvp
;
873 struct exportinfo
*exi
= NULL
;
877 struct secinfo
*secp
;
879 bool_t did_traverse
= FALSE
;
883 dotdot
= (nm
[0] == '.' && nm
[1] == '.' && nm
[2] == '\0');
886 * If dotdotting, then need to check whether it's above the
887 * root of a filesystem, or above an export point.
892 * If dotdotting at the root of a filesystem, then
893 * need to traverse back to the mounted-on filesystem
894 * and do the dotdot lookup there.
896 if (cs
->vp
->v_flag
& VROOT
) {
899 * If at the system root, then can
902 if (VN_CMP(dvp
, rootdir
))
903 return (puterrno4(ENOENT
));
906 * Traverse back to the mounted-on filesystem
908 dvp
= untraverse(cs
->vp
);
911 * Set the different_export flag so we remember
912 * to pick up a new exportinfo entry for
913 * this new filesystem.
915 different_export
= 1;
919 * If dotdotting above an export point then set
920 * the different_export to get new export info.
922 different_export
= nfs_exported(cs
->exi
, cs
->vp
);
927 * Get the vnode for the component "nm".
929 error
= VOP_LOOKUP(dvp
, nm
, &vp
, NULL
, 0, NULL
, cs
->cr
,
932 return (puterrno4(error
));
935 * If the vnode is in a pseudo filesystem, or if the security flavor
936 * used in the request is valid but not an explicitly shared flavor,
937 * or the access bit indicates that this is a limited access,
938 * check whether this vnode is visible.
940 if (!different_export
&&
941 (PSEUDO(cs
->exi
) || ! is_exported_sec(cs
->nfsflavor
, cs
->exi
) ||
942 cs
->access
& CS_ACCESS_LIMITED
)) {
943 if (! nfs_visible(cs
->exi
, vp
, &different_export
)) {
945 return (puterrno4(ENOENT
));
950 * If it's a mountpoint, then traverse it.
952 if (vn_ismntpt(vp
)) {
954 if ((error
= traverse(&tvp
)) != 0) {
956 return (puterrno4(error
));
958 /* remember that we had to traverse mountpoint */
961 different_export
= 1;
962 } else if (vp
->v_vfsp
!= dvp
->v_vfsp
) {
964 * If vp isn't a mountpoint and the vfs ptrs aren't the same,
965 * then vp is probably an LOFS object. We don't need the
966 * realvp, we just need to know that we might have crossed
967 * a server fs boundary and need to call checkexport4.
968 * (LOFS lookup hides server fs mountpoints, and actually calls
971 different_export
= 1;
975 * Get the export information for it.
977 if (different_export
) {
979 bzero(&fid
, sizeof (fid
));
980 fid
.fid_len
= MAXFIDSZ
;
981 error
= vop_fid_pseudo(vp
, &fid
);
984 return (puterrno4(error
));
988 exi
= nfs_vptoexi(NULL
, vp
, cs
->cr
, &walk
, NULL
, TRUE
);
990 exi
= checkexport4(&vp
->v_vfsp
->vfs_fsid
, &fid
, vp
);
993 if (did_traverse
== TRUE
) {
995 * If this vnode is a mounted-on vnode,
996 * but the mounted-on file system is not
997 * exported, send back the secinfo for
998 * the exported node that the mounted-on
1004 return (puterrno4(EACCES
));
1010 ASSERT(exi
!= NULL
);
1014 * Create the secinfo result based on the security information
1015 * from the exportinfo structure (exi).
1017 * Return all flavors for a pseudo node.
1018 * For a real export node, return the flavor that the client
1021 ASSERT(RW_LOCK_HELD(&exported_lock
));
1023 count
= exi
->exi_export
.ex_seccnt
; /* total sec count */
1024 resok_val
= kmem_alloc(count
* sizeof (secinfo4
), KM_SLEEP
);
1025 secp
= exi
->exi_export
.ex_secinfo
;
1027 for (i
= 0; i
< count
; i
++) {
1028 si
= &secp
[i
].s_secinfo
;
1029 resok_val
[i
].flavor
= si
->sc_rpcnum
;
1030 if (resok_val
[i
].flavor
== RPCSEC_GSS
) {
1031 rpcsec_gss_info
*info
;
1033 info
= &resok_val
[i
].flavor_info
;
1034 info
->qop
= si
->sc_qop
;
1035 info
->service
= (rpc_gss_svc_t
)si
->sc_service
;
1037 /* get oid opaque data */
1038 info
->oid
.sec_oid4_len
=
1039 si
->sc_gss_mech_type
->length
;
1040 info
->oid
.sec_oid4_val
= kmem_alloc(
1041 si
->sc_gss_mech_type
->length
, KM_SLEEP
);
1043 si
->sc_gss_mech_type
->elements
,
1044 info
->oid
.sec_oid4_val
,
1045 info
->oid
.sec_oid4_len
);
1048 resp
->SECINFO4resok_len
= count
;
1049 resp
->SECINFO4resok_val
= resok_val
;
1051 int ret_cnt
= 0, k
= 0;
1054 count
= exi
->exi_export
.ex_seccnt
; /* total sec count */
1055 secp
= exi
->exi_export
.ex_secinfo
;
1057 flavor_list
= kmem_alloc(count
* sizeof (int), KM_SLEEP
);
1058 /* find out which flavors to return */
1059 for (i
= 0; i
< count
; i
++) {
1060 int access
, flavor
, perm
;
1062 flavor
= secp
[i
].s_secinfo
.sc_nfsnum
;
1063 perm
= secp
[i
].s_flags
;
1065 access
= nfsauth4_secinfo_access(exi
, cs
->req
,
1068 if (! (access
& NFSAUTH_DENIED
) &&
1069 ! (access
& NFSAUTH_WRONGSEC
)) {
1070 flavor_list
[ret_cnt
] = flavor
;
1075 /* Create the returning SECINFO value */
1076 resok_val
= kmem_alloc(ret_cnt
* sizeof (secinfo4
), KM_SLEEP
);
1078 for (i
= 0; i
< count
; i
++) {
1080 * If the flavor is in the flavor list,
1081 * fill in resok_val.
1083 si
= &secp
[i
].s_secinfo
;
1084 if (in_flavor_list(si
->sc_nfsnum
,
1085 flavor_list
, ret_cnt
)) {
1086 resok_val
[k
].flavor
= si
->sc_rpcnum
;
1087 if (resok_val
[k
].flavor
== RPCSEC_GSS
) {
1088 rpcsec_gss_info
*info
;
1090 info
= &resok_val
[k
].flavor_info
;
1091 info
->qop
= si
->sc_qop
;
1092 info
->service
= (rpc_gss_svc_t
)
1095 /* get oid opaque data */
1096 info
->oid
.sec_oid4_len
=
1097 si
->sc_gss_mech_type
->length
;
1098 info
->oid
.sec_oid4_val
= kmem_alloc(
1099 si
->sc_gss_mech_type
->length
,
1101 bcopy(si
->sc_gss_mech_type
->elements
,
1102 info
->oid
.sec_oid4_val
,
1103 info
->oid
.sec_oid4_len
);
1110 resp
->SECINFO4resok_len
= ret_cnt
;
1111 resp
->SECINFO4resok_val
= resok_val
;
1112 kmem_free(flavor_list
, count
* sizeof (int));
1120 * SECINFO (Operation 33): Obtain required security information on
1121 * the component name in the format of (security-mechanism-oid, qop, service)
1126 rfs4_op_secinfo(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1127 struct compound_state
*cs
)
1129 SECINFO4args
*args
= &argop
->nfs_argop4_u
.opsecinfo
;
1130 SECINFO4res
*resp
= &resop
->nfs_resop4_u
.opsecinfo
;
1131 utf8string
*utfnm
= &args
->name
;
1134 struct sockaddr
*ca
;
1136 nfsstat4 status
= NFS4_OK
;
1138 DTRACE_NFSV4_2(op__secinfo__start
, struct compound_state
*, cs
,
1139 SECINFO4args
*, args
);
1142 * Current file handle (cfh) should have been set before getting
1143 * into this function. If not, return error.
1145 if (cs
->vp
== NULL
) {
1146 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1150 if (cs
->vp
->v_type
!= VDIR
) {
1151 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
1156 * Verify the component name. If failed, error out, but
1157 * do not error out if the component name is a "..".
1158 * SECINFO will return its parents secinfo data for SECINFO "..".
1160 status
= utf8_dir_verify(utfnm
);
1161 if (status
!= NFS4_OK
) {
1162 if (utfnm
->utf8string_len
!= 2 ||
1163 utfnm
->utf8string_val
[0] != '.' ||
1164 utfnm
->utf8string_val
[1] != '.') {
1165 *cs
->statusp
= resp
->status
= status
;
1170 nm
= utf8_to_str(utfnm
, &len
, NULL
);
1172 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1176 if (len
> MAXNAMELEN
) {
1177 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
1182 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
1183 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
1187 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1193 *cs
->statusp
= resp
->status
= do_rfs4_op_secinfo(cs
, name
, resp
);
1196 kmem_free(name
, MAXPATHLEN
+ 1);
1200 DTRACE_NFSV4_2(op__secinfo__done
, struct compound_state
*, cs
,
1201 SECINFO4res
*, resp
);
1205 * Free SECINFO result.
1209 rfs4_op_secinfo_free(nfs_resop4
*resop
)
1211 SECINFO4res
*resp
= &resop
->nfs_resop4_u
.opsecinfo
;
1213 secinfo4
*resok_val
;
1215 /* If this is not an Ok result, nothing to free. */
1216 if (resp
->status
!= NFS4_OK
) {
1220 count
= resp
->SECINFO4resok_len
;
1221 resok_val
= resp
->SECINFO4resok_val
;
1223 for (i
= 0; i
< count
; i
++) {
1224 if (resok_val
[i
].flavor
== RPCSEC_GSS
) {
1225 rpcsec_gss_info
*info
;
1227 info
= &resok_val
[i
].flavor_info
;
1228 kmem_free(info
->oid
.sec_oid4_val
,
1229 info
->oid
.sec_oid4_len
);
1232 kmem_free(resok_val
, count
* sizeof (secinfo4
));
1233 resp
->SECINFO4resok_len
= 0;
1234 resp
->SECINFO4resok_val
= NULL
;
1239 rfs4_op_access(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1240 struct compound_state
*cs
)
1242 ACCESS4args
*args
= &argop
->nfs_argop4_u
.opaccess
;
1243 ACCESS4res
*resp
= &resop
->nfs_resop4_u
.opaccess
;
1248 cred_t
*cr
= cs
->cr
;
1249 bslabel_t
*clabel
, *slabel
;
1250 ts_label_t
*tslabel
;
1251 boolean_t admin_low_client
;
1253 DTRACE_NFSV4_2(op__access__start
, struct compound_state
*, cs
,
1254 ACCESS4args
*, args
);
1256 #if 0 /* XXX allow access even if !cs->access. Eventually only pseudo fs */
1257 if (cs
->access
== CS_ACCESS_DENIED
) {
1258 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1262 if (cs
->vp
== NULL
) {
1263 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1272 * If the file system is exported read only, it is not appropriate
1273 * to check write permissions for regular files and directories.
1274 * Special files are interpreted by the client, so the underlying
1275 * permissions are sent back to the client for interpretation.
1277 if (rdonly4(cs
->exi
, cs
->vp
, req
) &&
1278 (vp
->v_type
== VREG
|| vp
->v_type
== VDIR
))
1285 * We need the mode so that we can correctly determine access
1286 * permissions relative to a mandatory lock file. Access to
1287 * mandatory lock files is denied on the server, so it might
1288 * as well be reflected to the server during the open.
1290 va
.va_mask
= AT_MODE
;
1291 error
= VOP_GETATTR(vp
, &va
, 0, cr
, NULL
);
1293 *cs
->statusp
= resp
->status
= puterrno4(error
);
1297 resp
->supported
= 0;
1299 if (is_system_labeled()) {
1300 ASSERT(req
->rq_label
!= NULL
);
1301 clabel
= req
->rq_label
;
1302 DTRACE_PROBE2(tx__rfs4__log__info__opaccess__clabel
, char *,
1303 "got client label from request(1)",
1304 struct svc_req
*, req
);
1305 if (!blequal(&l_admin_low
->tsl_label
, clabel
)) {
1306 if ((tslabel
= nfs_getflabel(vp
, cs
->exi
)) == NULL
) {
1307 *cs
->statusp
= resp
->status
= puterrno4(EACCES
);
1310 slabel
= label2bslabel(tslabel
);
1311 DTRACE_PROBE3(tx__rfs4__log__info__opaccess__slabel
,
1312 char *, "got server label(1) for vp(2)",
1313 bslabel_t
*, slabel
, vnode_t
*, vp
);
1315 admin_low_client
= B_FALSE
;
1317 admin_low_client
= B_TRUE
;
1320 if (args
->access
& ACCESS4_READ
) {
1321 error
= VOP_ACCESS(vp
, VREAD
, 0, cr
, NULL
);
1322 if (!error
&& !MANDLOCK(vp
, va
.va_mode
) &&
1323 (!is_system_labeled() || admin_low_client
||
1324 bldominates(clabel
, slabel
)))
1325 resp
->access
|= ACCESS4_READ
;
1326 resp
->supported
|= ACCESS4_READ
;
1328 if ((args
->access
& ACCESS4_LOOKUP
) && vp
->v_type
== VDIR
) {
1329 error
= VOP_ACCESS(vp
, VEXEC
, 0, cr
, NULL
);
1330 if (!error
&& (!is_system_labeled() || admin_low_client
||
1331 bldominates(clabel
, slabel
)))
1332 resp
->access
|= ACCESS4_LOOKUP
;
1333 resp
->supported
|= ACCESS4_LOOKUP
;
1335 if (checkwriteperm
&&
1336 (args
->access
& (ACCESS4_MODIFY
|ACCESS4_EXTEND
))) {
1337 error
= VOP_ACCESS(vp
, VWRITE
, 0, cr
, NULL
);
1338 if (!error
&& !MANDLOCK(vp
, va
.va_mode
) &&
1339 (!is_system_labeled() || admin_low_client
||
1340 blequal(clabel
, slabel
)))
1342 (args
->access
& (ACCESS4_MODIFY
| ACCESS4_EXTEND
));
1344 resp
->access
& (ACCESS4_MODIFY
| ACCESS4_EXTEND
);
1347 if (checkwriteperm
&&
1348 (args
->access
& ACCESS4_DELETE
) && vp
->v_type
== VDIR
) {
1349 error
= VOP_ACCESS(vp
, VWRITE
, 0, cr
, NULL
);
1350 if (!error
&& (!is_system_labeled() || admin_low_client
||
1351 blequal(clabel
, slabel
)))
1352 resp
->access
|= ACCESS4_DELETE
;
1353 resp
->supported
|= ACCESS4_DELETE
;
1355 if (args
->access
& ACCESS4_EXECUTE
&& vp
->v_type
!= VDIR
) {
1356 error
= VOP_ACCESS(vp
, VEXEC
, 0, cr
, NULL
);
1357 if (!error
&& !MANDLOCK(vp
, va
.va_mode
) &&
1358 (!is_system_labeled() || admin_low_client
||
1359 bldominates(clabel
, slabel
)))
1360 resp
->access
|= ACCESS4_EXECUTE
;
1361 resp
->supported
|= ACCESS4_EXECUTE
;
1364 if (is_system_labeled() && !admin_low_client
)
1365 label_rele(tslabel
);
1367 *cs
->statusp
= resp
->status
= NFS4_OK
;
1369 DTRACE_NFSV4_2(op__access__done
, struct compound_state
*, cs
,
1370 ACCESS4res
*, resp
);
1375 rfs4_op_commit(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1376 struct compound_state
*cs
)
1378 COMMIT4args
*args
= &argop
->nfs_argop4_u
.opcommit
;
1379 COMMIT4res
*resp
= &resop
->nfs_resop4_u
.opcommit
;
1381 vnode_t
*vp
= cs
->vp
;
1382 cred_t
*cr
= cs
->cr
;
1385 DTRACE_NFSV4_2(op__commit__start
, struct compound_state
*, cs
,
1386 COMMIT4args
*, args
);
1389 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1392 if (cs
->access
== CS_ACCESS_DENIED
) {
1393 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1397 if (args
->offset
+ args
->count
< args
->offset
) {
1398 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1402 va
.va_mask
= AT_UID
;
1403 error
= VOP_GETATTR(vp
, &va
, 0, cr
, NULL
);
1406 * If we can't get the attributes, then we can't do the
1407 * right access checking. So, we'll fail the request.
1410 *cs
->statusp
= resp
->status
= puterrno4(error
);
1413 if (rdonly4(cs
->exi
, cs
->vp
, req
)) {
1414 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
1418 if (vp
->v_type
!= VREG
) {
1419 if (vp
->v_type
== VDIR
)
1420 resp
->status
= NFS4ERR_ISDIR
;
1422 resp
->status
= NFS4ERR_INVAL
;
1423 *cs
->statusp
= resp
->status
;
1427 if (crgetuid(cr
) != va
.va_uid
&&
1428 (error
= VOP_ACCESS(vp
, VWRITE
, 0, cs
->cr
, NULL
))) {
1429 *cs
->statusp
= resp
->status
= puterrno4(error
);
1433 error
= VOP_FSYNC(vp
, FSYNC
, cr
, NULL
);
1436 *cs
->statusp
= resp
->status
= puterrno4(error
);
1440 *cs
->statusp
= resp
->status
= NFS4_OK
;
1441 resp
->writeverf
= Write4verf
;
1443 DTRACE_NFSV4_2(op__commit__done
, struct compound_state
*, cs
,
1444 COMMIT4res
*, resp
);
1448 * rfs4_op_mknod is called from rfs4_op_create after all initial verification
1449 * was completed. It does the nfsv4 create for special files.
1453 do_rfs4_op_mknod(CREATE4args
*args
, CREATE4res
*resp
, struct svc_req
*req
,
1454 struct compound_state
*cs
, vattr_t
*vap
, char *nm
)
1457 cred_t
*cr
= cs
->cr
;
1458 vnode_t
*dvp
= cs
->vp
;
1463 switch (args
->type
) {
1466 if (secpolicy_sys_devices(cr
) != 0) {
1467 *cs
->statusp
= resp
->status
= NFS4ERR_PERM
;
1470 if (args
->type
== NF4CHR
)
1471 vap
->va_type
= VCHR
;
1473 vap
->va_type
= VBLK
;
1474 vap
->va_rdev
= makedevice(args
->ftype4_u
.devdata
.specdata1
,
1475 args
->ftype4_u
.devdata
.specdata2
);
1476 vap
->va_mask
|= AT_RDEV
;
1479 vap
->va_type
= VSOCK
;
1482 vap
->va_type
= VFIFO
;
1485 *cs
->statusp
= resp
->status
= NFS4ERR_BADTYPE
;
1490 * Must specify the mode.
1492 if (!(vap
->va_mask
& AT_MODE
)) {
1493 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1501 error
= VOP_CREATE(dvp
, nm
, vap
, excl
, mode
, &vp
, cr
, 0, NULL
, NULL
);
1503 *cs
->statusp
= resp
->status
= puterrno4(error
);
1510 * nfsv4 create is used to create non-regular files. For regular files,
1515 rfs4_op_create(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1516 struct compound_state
*cs
)
1518 CREATE4args
*args
= &argop
->nfs_argop4_u
.opcreate
;
1519 CREATE4res
*resp
= &resop
->nfs_resop4_u
.opcreate
;
1521 struct vattr bva
, iva
, iva2
, ava
, *vap
;
1522 cred_t
*cr
= cs
->cr
;
1523 vnode_t
*dvp
= cs
->vp
;
1529 struct nfs4_svgetit_arg sarg
;
1530 struct nfs4_ntov_table ntov
;
1531 struct statvfs64 sb
;
1533 struct sockaddr
*ca
;
1537 DTRACE_NFSV4_2(op__create__start
, struct compound_state
*, cs
,
1538 CREATE4args
*, args
);
1543 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1548 * If there is an unshared filesystem mounted on this vnode,
1549 * do not allow to create an object in this directory.
1551 if (vn_ismntpt(dvp
)) {
1552 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1556 /* Verify that type is correct */
1557 switch (args
->type
) {
1566 *cs
->statusp
= resp
->status
= NFS4ERR_BADTYPE
;
1570 if (cs
->access
== CS_ACCESS_DENIED
) {
1571 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1574 if (dvp
->v_type
!= VDIR
) {
1575 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
1578 status
= utf8_dir_verify(&args
->objname
);
1579 if (status
!= NFS4_OK
) {
1580 *cs
->statusp
= resp
->status
= status
;
1584 if (rdonly4(cs
->exi
, cs
->vp
, req
)) {
1585 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
1590 * Name of newly created object
1592 nm
= utf8_to_fn(&args
->objname
, &len
, NULL
);
1594 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1598 if (len
> MAXNAMELEN
) {
1599 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
1604 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
1605 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
1609 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1617 sarg
.is_referral
= B_FALSE
;
1618 nfs4_ntov_table_init(&ntov
);
1620 status
= do_rfs4_set_attrs(&resp
->attrset
,
1621 &args
->createattrs
, cs
, &sarg
, &ntov
, NFS4ATTR_SETIT
);
1623 if (sarg
.vap
->va_mask
== 0 && status
== NFS4_OK
)
1624 status
= NFS4ERR_INVAL
;
1626 if (status
!= NFS4_OK
) {
1627 *cs
->statusp
= resp
->status
= status
;
1629 kmem_free(name
, MAXPATHLEN
+ 1);
1631 nfs4_ntov_table_free(&ntov
, &sarg
);
1636 /* Get "before" change value */
1637 bva
.va_mask
= AT_CTIME
|AT_SEQ
|AT_MODE
;
1638 error
= VOP_GETATTR(dvp
, &bva
, 0, cr
, NULL
);
1640 *cs
->statusp
= resp
->status
= puterrno4(error
);
1642 kmem_free(name
, MAXPATHLEN
+ 1);
1644 nfs4_ntov_table_free(&ntov
, &sarg
);
1648 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.before
, bva
.va_ctime
)
1653 * Set the default initial values for attributes when the parent
1654 * directory does not have the VSUID/VSGID bit set and they have
1655 * not been specified in createattrs.
1657 if (!(bva
.va_mode
& VSUID
) && (vap
->va_mask
& AT_UID
) == 0) {
1658 vap
->va_uid
= crgetuid(cr
);
1659 vap
->va_mask
|= AT_UID
;
1661 if (!(bva
.va_mode
& VSGID
) && (vap
->va_mask
& AT_GID
) == 0) {
1662 vap
->va_gid
= crgetgid(cr
);
1663 vap
->va_mask
|= AT_GID
;
1666 vap
->va_mask
|= AT_TYPE
;
1667 switch (args
->type
) {
1669 vap
->va_type
= VDIR
;
1670 if ((vap
->va_mask
& AT_MODE
) == 0) {
1671 vap
->va_mode
= 0700; /* default: owner rwx only */
1672 vap
->va_mask
|= AT_MODE
;
1674 error
= VOP_MKDIR(dvp
, name
, vap
, &vp
, cr
, NULL
, 0, NULL
);
1679 * Get the initial "after" sequence number, if it fails,
1682 iva
.va_mask
= AT_SEQ
;
1683 if (VOP_GETATTR(dvp
, &iva
, 0, cs
->cr
, NULL
))
1687 vap
->va_type
= VLNK
;
1688 if ((vap
->va_mask
& AT_MODE
) == 0) {
1689 vap
->va_mode
= 0700; /* default: owner rwx only */
1690 vap
->va_mask
|= AT_MODE
;
1694 * symlink names must be treated as data
1696 lnm
= utf8_to_str(&args
->ftype4_u
.linkdata
, &llen
, NULL
);
1699 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1701 kmem_free(name
, MAXPATHLEN
+ 1);
1703 nfs4_ntov_table_free(&ntov
, &sarg
);
1708 if (llen
> MAXPATHLEN
) {
1709 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
1711 kmem_free(name
, MAXPATHLEN
+ 1);
1713 kmem_free(lnm
, llen
);
1714 nfs4_ntov_table_free(&ntov
, &sarg
);
1719 lname
= nfscmd_convname(ca
, cs
->exi
, lnm
,
1720 NFSCMD_CONV_INBOUND
, MAXPATHLEN
+ 1);
1722 if (lname
== NULL
) {
1723 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
1725 kmem_free(name
, MAXPATHLEN
+ 1);
1727 kmem_free(lnm
, llen
);
1728 nfs4_ntov_table_free(&ntov
, &sarg
);
1733 error
= VOP_SYMLINK(dvp
, name
, vap
, lname
, cr
, NULL
, 0);
1735 kmem_free(lname
, MAXPATHLEN
+ 1);
1736 kmem_free(lnm
, llen
);
1741 * Get the initial "after" sequence number, if it fails,
1744 iva
.va_mask
= AT_SEQ
;
1745 if (VOP_GETATTR(dvp
, &iva
, 0, cs
->cr
, NULL
))
1748 error
= VOP_LOOKUP(dvp
, name
, &vp
, NULL
, 0, NULL
, cr
,
1754 * va_seq is not safe over VOP calls, check it again
1755 * if it has changed zero out iva to force atomic = FALSE.
1757 iva2
.va_mask
= AT_SEQ
;
1758 if (VOP_GETATTR(dvp
, &iva2
, 0, cs
->cr
, NULL
) ||
1759 iva2
.va_seq
!= iva
.va_seq
)
1764 * probably a special file.
1766 if ((vap
->va_mask
& AT_MODE
) == 0) {
1767 vap
->va_mode
= 0600; /* default: owner rw only */
1768 vap
->va_mask
|= AT_MODE
;
1772 * We know this will only generate one VOP call
1774 vp
= do_rfs4_op_mknod(args
, resp
, req
, cs
, vap
, name
);
1778 kmem_free(name
, MAXPATHLEN
+ 1);
1780 nfs4_ntov_table_free(&ntov
, &sarg
);
1786 * Get the initial "after" sequence number, if it fails,
1789 iva
.va_mask
= AT_SEQ
;
1790 if (VOP_GETATTR(dvp
, &iva
, 0, cs
->cr
, NULL
))
1796 kmem_free(name
, MAXPATHLEN
+ 1);
1800 *cs
->statusp
= resp
->status
= puterrno4(error
);
1804 * Force modified data and metadata out to stable storage.
1806 (void) VOP_FSYNC(dvp
, 0, cr
, NULL
);
1808 if (resp
->status
!= NFS4_OK
) {
1811 nfs4_ntov_table_free(&ntov
, &sarg
);
1817 * Finish setup of cinfo response, "before" value already set.
1818 * Get "after" change value, if it fails, simply return the
1821 ava
.va_mask
= AT_CTIME
|AT_SEQ
;
1822 if (VOP_GETATTR(dvp
, &ava
, 0, cr
, NULL
)) {
1823 ava
.va_ctime
= bva
.va_ctime
;
1826 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.after
, ava
.va_ctime
);
1829 * True verification that object was created with correct
1830 * attrs is impossible. The attrs could have been changed
1831 * immediately after object creation. If attributes did
1832 * not verify, the only recourse for the server is to
1833 * destroy the object. Maybe if some attrs (like gid)
1834 * are set incorrectly, the object should be destroyed;
1835 * however, seems bad as a default policy. Do we really
1836 * want to destroy an object over one of the times not
1837 * verifying correctly? For these reasons, the server
1838 * currently sets bits in attrset for createattrs
1839 * that were set; however, no verification is done.
1841 * vmask_to_nmask accounts for vattr bits set on create
1842 * [do_rfs4_set_attrs() only sets resp bits for
1843 * non-vattr/vfs bits.]
1844 * Mask off any bits set by default so as not to return
1845 * more attrset bits than were requested in createattrs
1847 nfs4_vmask_to_nmask(sarg
.vap
->va_mask
, &resp
->attrset
);
1848 resp
->attrset
&= args
->createattrs
.attrmask
;
1849 nfs4_ntov_table_free(&ntov
, &sarg
);
1851 error
= makefh4(&cs
->fh
, vp
, cs
->exi
);
1853 *cs
->statusp
= resp
->status
= puterrno4(error
);
1857 * The cinfo.atomic = TRUE only if we got no errors, we have
1858 * non-zero va_seq's, and it has incremented by exactly one
1859 * during the creation and it didn't change during the VOP_LOOKUP
1862 if (!error
&& bva
.va_seq
&& iva
.va_seq
&& ava
.va_seq
&&
1863 iva
.va_seq
== (bva
.va_seq
+ 1) && iva
.va_seq
== ava
.va_seq
)
1864 resp
->cinfo
.atomic
= TRUE
;
1866 resp
->cinfo
.atomic
= FALSE
;
1869 * Force modified metadata out to stable storage.
1871 * if a underlying vp exists, pass it to VOP_FSYNC
1873 if (VOP_REALVP(vp
, &realvp
, NULL
) == 0)
1874 (void) VOP_FSYNC(realvp
, syncval
, cr
, NULL
);
1876 (void) VOP_FSYNC(vp
, syncval
, cr
, NULL
);
1878 if (resp
->status
!= NFS4_OK
) {
1886 *cs
->statusp
= resp
->status
= NFS4_OK
;
1888 DTRACE_NFSV4_2(op__create__done
, struct compound_state
*, cs
,
1889 CREATE4res
*, resp
);
1894 rfs4_op_delegpurge(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1895 struct compound_state
*cs
)
1897 DTRACE_NFSV4_2(op__delegpurge__start
, struct compound_state
*, cs
,
1898 DELEGPURGE4args
*, &argop
->nfs_argop4_u
.opdelegpurge
);
1900 rfs4_op_inval(argop
, resop
, req
, cs
);
1902 DTRACE_NFSV4_2(op__delegpurge__done
, struct compound_state
*, cs
,
1903 DELEGPURGE4res
*, &resop
->nfs_resop4_u
.opdelegpurge
);
1908 rfs4_op_delegreturn(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1909 struct compound_state
*cs
)
1911 DELEGRETURN4args
*args
= &argop
->nfs_argop4_u
.opdelegreturn
;
1912 DELEGRETURN4res
*resp
= &resop
->nfs_resop4_u
.opdelegreturn
;
1913 rfs4_deleg_state_t
*dsp
;
1916 DTRACE_NFSV4_2(op__delegreturn__start
, struct compound_state
*, cs
,
1917 DELEGRETURN4args
*, args
);
1919 status
= rfs4_get_deleg_state(&args
->deleg_stateid
, &dsp
);
1920 resp
->status
= *cs
->statusp
= status
;
1921 if (status
!= NFS4_OK
)
1924 /* Ensure specified filehandle matches */
1925 if (cs
->vp
!= dsp
->rds_finfo
->rf_vp
) {
1926 resp
->status
= *cs
->statusp
= NFS4ERR_BAD_STATEID
;
1928 rfs4_return_deleg(dsp
, FALSE
);
1930 rfs4_update_lease(dsp
->rds_client
);
1932 rfs4_deleg_state_rele(dsp
);
1934 DTRACE_NFSV4_2(op__delegreturn__done
, struct compound_state
*, cs
,
1935 DELEGRETURN4res
*, resp
);
1939 * Check to see if a given "flavor" is an explicitly shared flavor.
1940 * The assumption of this routine is the "flavor" is already a valid
1941 * flavor in the secinfo list of "exi".
1944 * # share -o sec=flavor1 /export
1945 * # share -o sec=flavor2 /export/home
1947 * flavor2 is not an explicitly shared flavor for /export,
1948 * however it is in the secinfo list for /export thru the
1949 * server namespace setup.
1952 is_exported_sec(int flavor
, struct exportinfo
*exi
)
1957 sp
= exi
->exi_export
.ex_secinfo
;
1958 for (i
= 0; i
< exi
->exi_export
.ex_seccnt
; i
++) {
1959 if (flavor
== sp
[i
].s_secinfo
.sc_nfsnum
||
1960 sp
[i
].s_secinfo
.sc_nfsnum
== AUTH_NONE
) {
1961 return (SEC_REF_EXPORTED(&sp
[i
]));
1965 /* Should not reach this point based on the assumption */
1970 * Check if the security flavor used in the request matches what is
1971 * required at the export point or at the root pseudo node (exi_root).
1973 * returns 1 if there's a match or if exported with AUTH_NONE; 0 otherwise.
1977 secinfo_match_or_authnone(struct compound_state
*cs
)
1983 * Check cs->nfsflavor (from the request) against
1984 * the current export data in cs->exi.
1986 sp
= cs
->exi
->exi_export
.ex_secinfo
;
1987 for (i
= 0; i
< cs
->exi
->exi_export
.ex_seccnt
; i
++) {
1988 if (cs
->nfsflavor
== sp
[i
].s_secinfo
.sc_nfsnum
||
1989 sp
[i
].s_secinfo
.sc_nfsnum
== AUTH_NONE
)
1997 * Check the access authority for the client and return the correct error.
2000 call_checkauth4(struct compound_state
*cs
, struct svc_req
*req
)
2005 * First, check if the security flavor used in the request
2006 * are among the flavors set in the server namespace.
2008 if (!secinfo_match_or_authnone(cs
)) {
2009 *cs
->statusp
= NFS4ERR_WRONGSEC
;
2010 return (*cs
->statusp
);
2013 authres
= checkauth4(cs
, req
);
2016 *cs
->statusp
= NFS4_OK
;
2017 if (! (cs
->access
& CS_ACCESS_LIMITED
))
2018 cs
->access
= CS_ACCESS_OK
;
2019 } else if (authres
== 0) {
2020 *cs
->statusp
= NFS4ERR_ACCESS
;
2021 } else if (authres
== -2) {
2022 *cs
->statusp
= NFS4ERR_WRONGSEC
;
2024 *cs
->statusp
= NFS4ERR_DELAY
;
2026 return (*cs
->statusp
);
2030 * bitmap4_to_attrmask is called by getattr and readdir.
2031 * It sets up the vattr mask and determines whether vfsstat call is needed
2032 * based on the input bitmap.
2033 * Returns nfsv4 status.
2036 bitmap4_to_attrmask(bitmap4 breq
, struct nfs4_svgetit_arg
*sargp
)
2040 struct statvfs64
*sbp
= sargp
->sbp
;
2044 sargp
->rdattr_error
= NFS4_OK
;
2045 sargp
->mntdfid_set
= FALSE
;
2047 sargp
->xattr
= get_fh4_flag(&sargp
->cs
->fh
,
2048 FH4_ATTRDIR
| FH4_NAMEDATTR
);
2053 * Set rdattr_error_req to true if return error per
2054 * failed entry rather than fail the readdir.
2056 if (breq
& FATTR4_RDATTR_ERROR_MASK
)
2057 sargp
->rdattr_error_req
= 1;
2059 sargp
->rdattr_error_req
= 0;
2062 * generate the va_mask
2063 * Handle the easy cases first
2066 case NFS4_NTOV_ATTR_MASK
:
2067 sargp
->vap
->va_mask
= NFS4_NTOV_ATTR_AT_MASK
;
2070 case NFS4_FS_ATTR_MASK
:
2071 sargp
->vap
->va_mask
= NFS4_FS_ATTR_AT_MASK
;
2075 case NFS4_NTOV_ATTR_CACHE_MASK
:
2076 sargp
->vap
->va_mask
= NFS4_NTOV_ATTR_CACHE_AT_MASK
;
2079 case FATTR4_LEASE_TIME_MASK
:
2080 sargp
->vap
->va_mask
= 0;
2085 for (i
= 0; i
< nfs4_ntov_map_size
; i
++) {
2086 if ((breq
& nfs4_ntov_map
[i
].fbit
) &&
2087 nfs4_ntov_map
[i
].vbit
)
2088 va_mask
|= nfs4_ntov_map
[i
].vbit
;
2092 * Check is vfsstat is needed
2094 if (breq
& NFS4_FS_ATTR_MASK
)
2097 sargp
->vap
->va_mask
= va_mask
;
2104 * bitmap4_get_sysattrs is called by getattr and readdir.
2105 * It calls both VOP_GETATTR and VFS_STATVFS calls to get the attrs.
2106 * Returns nfsv4 status.
2109 bitmap4_get_sysattrs(struct nfs4_svgetit_arg
*sargp
)
2112 struct compound_state
*cs
= sargp
->cs
;
2113 vnode_t
*vp
= cs
->vp
;
2115 if (sargp
->sbp
!= NULL
) {
2116 if (error
= VFS_STATVFS(vp
->v_vfsp
, sargp
->sbp
)) {
2117 sargp
->sbp
= NULL
; /* to identify error */
2118 return (puterrno4(error
));
2122 return (rfs4_vop_getattr(vp
, sargp
->vap
, 0, cs
->cr
));
2126 nfs4_ntov_table_init(struct nfs4_ntov_table
*ntovp
)
2128 ntovp
->na
= kmem_zalloc(sizeof (union nfs4_attr_u
) * nfs4_ntov_map_size
,
2131 ntovp
->vfsstat
= FALSE
;
2135 nfs4_ntov_table_free(struct nfs4_ntov_table
*ntovp
,
2136 struct nfs4_svgetit_arg
*sargp
)
2139 union nfs4_attr_u
*na
;
2143 * XXX Should do the same checks for whether the bit is set
2145 for (i
= 0, na
= ntovp
->na
, amap
= ntovp
->amap
;
2146 i
< ntovp
->attrcnt
; i
++, na
++, amap
++) {
2147 (void) (*nfs4_ntov_map
[*amap
].sv_getit
)(
2148 NFS4ATTR_FREEIT
, sargp
, na
);
2150 if ((sargp
->op
== NFS4ATTR_SETIT
) || (sargp
->op
== NFS4ATTR_VERIT
)) {
2152 * xdr_free for getattr will be done later
2154 for (i
= 0, na
= ntovp
->na
, amap
= ntovp
->amap
;
2155 i
< ntovp
->attrcnt
; i
++, na
++, amap
++) {
2156 xdr_free(nfs4_ntov_map
[*amap
].xfunc
, (caddr_t
)na
);
2159 kmem_free(ntovp
->na
, sizeof (union nfs4_attr_u
) * nfs4_ntov_map_size
);
2163 * do_rfs4_op_getattr gets the system attrs and converts into fattr4.
2166 do_rfs4_op_getattr(bitmap4 breq
, fattr4
*fattrp
,
2167 struct nfs4_svgetit_arg
*sargp
)
2171 struct nfs4_ntov_table ntov
;
2175 nfsstat4 status
= NFS4_OK
;
2176 nfsstat4 prev_rdattr_error
= sargp
->rdattr_error
;
2177 union nfs4_attr_u
*na
;
2180 sargp
->op
= NFS4ATTR_GETIT
;
2183 fattrp
->attrmask
= 0;
2184 /* if no bits requested, then return empty fattr4 */
2186 fattrp
->attrlist4_len
= 0;
2187 fattrp
->attrlist4
= NULL
;
2192 * return NFS4ERR_INVAL when client requests write-only attrs
2194 if (breq
& (FATTR4_TIME_ACCESS_SET_MASK
| FATTR4_TIME_MODIFY_SET_MASK
))
2195 return (NFS4ERR_INVAL
);
2197 nfs4_ntov_table_init(&ntov
);
2202 * Now loop to get or verify the attrs
2204 for (i
= 0; i
< nfs4_ntov_map_size
; i
++) {
2205 if (breq
& nfs4_ntov_map
[i
].fbit
) {
2206 if ((*nfs4_ntov_map
[i
].sv_getit
)(
2207 NFS4ATTR_SUPPORTED
, sargp
, NULL
) == 0) {
2209 error
= (*nfs4_ntov_map
[i
].sv_getit
)(
2210 NFS4ATTR_GETIT
, sargp
, na
);
2213 * Possible error values:
2214 * >0 if sv_getit failed to
2215 * get the attr; 0 if succeeded;
2216 * <0 if rdattr_error and the
2217 * attribute cannot be returned.
2219 if (error
&& !(sargp
->rdattr_error_req
))
2222 * If error then just for entry
2226 nfs4_ntov_map
[i
].fbit
;
2228 (uint8_t)nfs4_ntov_map
[i
].nval
;
2231 } else if ((error
> 0) &&
2232 (sargp
->rdattr_error
== NFS4_OK
)) {
2233 sargp
->rdattr_error
= puterrno4(error
);
2241 * If rdattr_error was set after the return value for it was assigned,
2244 if (prev_rdattr_error
!= sargp
->rdattr_error
) {
2247 for (i
= 0; i
< ntov
.attrcnt
; i
++, na
++, amap
++) {
2249 if (k
< FATTR4_RDATTR_ERROR
) {
2252 if ((k
== FATTR4_RDATTR_ERROR
) &&
2253 ((*nfs4_ntov_map
[k
].sv_getit
)(
2254 NFS4ATTR_SUPPORTED
, sargp
, NULL
) == 0)) {
2256 (void) (*nfs4_ntov_map
[k
].sv_getit
)(
2257 NFS4ATTR_GETIT
, sargp
, na
);
2266 for (i
= 0; i
< ntov
.attrcnt
; i
++, na
++, amap
++) {
2267 xdr_size
+= xdr_sizeof(nfs4_ntov_map
[*amap
].xfunc
, na
);
2270 fattrp
->attrlist4_len
= xdr_size
;
2272 /* freed by rfs4_op_getattr_free() */
2273 fattrp
->attrlist4
= xdr_attrs
= kmem_zalloc(xdr_size
, KM_SLEEP
);
2275 xdrmem_create(&xdr
, xdr_attrs
, xdr_size
, XDR_ENCODE
);
2279 for (i
= 0; i
< ntov
.attrcnt
; i
++, na
++, amap
++) {
2280 if (!(*nfs4_ntov_map
[*amap
].xfunc
)(&xdr
, na
)) {
2281 DTRACE_PROBE1(nfss__e__getattr4_encfail
,
2283 status
= NFS4ERR_SERVERFAULT
;
2287 /* xdrmem_destroy(&xdrs); */ /* NO-OP */
2289 fattrp
->attrlist4
= NULL
;
2293 nfs4_ntov_table_free(&ntov
, sargp
);
2296 status
= puterrno4(error
);
2303 rfs4_op_getattr(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2304 struct compound_state
*cs
)
2306 GETATTR4args
*args
= &argop
->nfs_argop4_u
.opgetattr
;
2307 GETATTR4res
*resp
= &resop
->nfs_resop4_u
.opgetattr
;
2308 struct nfs4_svgetit_arg sarg
;
2309 struct statvfs64 sb
;
2312 DTRACE_NFSV4_2(op__getattr__start
, struct compound_state
*, cs
,
2313 GETATTR4args
*, args
);
2315 if (cs
->vp
== NULL
) {
2316 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2320 if (cs
->access
== CS_ACCESS_DENIED
) {
2321 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2327 sarg
.is_referral
= B_FALSE
;
2329 status
= bitmap4_to_attrmask(args
->attr_request
, &sarg
);
2330 if (status
== NFS4_OK
) {
2332 status
= bitmap4_get_sysattrs(&sarg
);
2333 if (status
== NFS4_OK
) {
2335 /* Is this a referral? */
2336 if (vn_is_nfs_reparse(cs
->vp
, cs
->cr
)) {
2337 /* Older V4 Solaris client sees a link */
2338 if (client_is_downrev(req
))
2339 sarg
.vap
->va_type
= VLNK
;
2341 sarg
.is_referral
= B_TRUE
;
2344 status
= do_rfs4_op_getattr(args
->attr_request
,
2345 &resp
->obj_attributes
, &sarg
);
2348 *cs
->statusp
= resp
->status
= status
;
2350 DTRACE_NFSV4_2(op__getattr__done
, struct compound_state
*, cs
,
2351 GETATTR4res
*, resp
);
2355 rfs4_op_getattr_free(nfs_resop4
*resop
)
2357 GETATTR4res
*resp
= &resop
->nfs_resop4_u
.opgetattr
;
2359 nfs4_fattr4_free(&resp
->obj_attributes
);
2364 rfs4_op_getfh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2365 struct compound_state
*cs
)
2367 GETFH4res
*resp
= &resop
->nfs_resop4_u
.opgetfh
;
2369 DTRACE_NFSV4_1(op__getfh__start
, struct compound_state
*, cs
);
2371 if (cs
->vp
== NULL
) {
2372 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2375 if (cs
->access
== CS_ACCESS_DENIED
) {
2376 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2380 /* check for reparse point at the share point */
2381 if (cs
->exi
->exi_moved
|| vn_is_nfs_reparse(cs
->exi
->exi_vp
, cs
->cr
)) {
2383 cs
->exi
->exi_moved
= 1;
2384 *cs
->statusp
= resp
->status
= NFS4ERR_MOVED
;
2385 DTRACE_PROBE2(nfs4serv__func__referral__shared__moved
,
2386 vnode_t
*, cs
->vp
, char *, "rfs4_op_getfh");
2390 /* check for reparse point at vp */
2391 if (vn_is_nfs_reparse(cs
->vp
, cs
->cr
) && !client_is_downrev(req
)) {
2392 /* it's not all bad */
2393 *cs
->statusp
= resp
->status
= NFS4ERR_MOVED
;
2394 DTRACE_PROBE2(nfs4serv__func__referral__moved
,
2395 vnode_t
*, cs
->vp
, char *, "rfs4_op_getfh");
2399 resp
->object
.nfs_fh4_val
=
2400 kmem_alloc(cs
->fh
.nfs_fh4_len
, KM_SLEEP
);
2401 nfs_fh4_copy(&cs
->fh
, &resp
->object
);
2402 *cs
->statusp
= resp
->status
= NFS4_OK
;
2404 DTRACE_NFSV4_2(op__getfh__done
, struct compound_state
*, cs
,
2409 rfs4_op_getfh_free(nfs_resop4
*resop
)
2411 GETFH4res
*resp
= &resop
->nfs_resop4_u
.opgetfh
;
2413 if (resp
->status
== NFS4_OK
&&
2414 resp
->object
.nfs_fh4_val
!= NULL
) {
2415 kmem_free(resp
->object
.nfs_fh4_val
, resp
->object
.nfs_fh4_len
);
2416 resp
->object
.nfs_fh4_val
= NULL
;
2417 resp
->object
.nfs_fh4_len
= 0;
2422 * illegal: args: void
2423 * res : status (NFS4ERR_OP_ILLEGAL)
2427 rfs4_op_illegal(nfs_argop4
*argop
, nfs_resop4
*resop
,
2428 struct svc_req
*req
, struct compound_state
*cs
)
2430 ILLEGAL4res
*resp
= &resop
->nfs_resop4_u
.opillegal
;
2432 resop
->resop
= OP_ILLEGAL
;
2433 *cs
->statusp
= resp
->status
= NFS4ERR_OP_ILLEGAL
;
2437 * link: args: SAVED_FH: file, CURRENT_FH: target directory
2438 * res: status. If success - CURRENT_FH unchanged, return change_info
2442 rfs4_op_link(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2443 struct compound_state
*cs
)
2445 LINK4args
*args
= &argop
->nfs_argop4_u
.oplink
;
2446 LINK4res
*resp
= &resop
->nfs_resop4_u
.oplink
;
2450 struct vattr bdva
, idva
, adva
;
2453 struct sockaddr
*ca
;
2457 DTRACE_NFSV4_2(op__link__start
, struct compound_state
*, cs
,
2460 /* SAVED_FH: source object */
2463 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2467 /* CURRENT_FH: target directory */
2470 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2475 * If there is a non-shared filesystem mounted on this vnode,
2476 * do not allow to link any file in this directory.
2478 if (vn_ismntpt(dvp
)) {
2479 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2483 if (cs
->access
== CS_ACCESS_DENIED
) {
2484 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2488 /* Check source object's type validity */
2489 if (vp
->v_type
== VDIR
) {
2490 *cs
->statusp
= resp
->status
= NFS4ERR_ISDIR
;
2494 /* Check target directory's type */
2495 if (dvp
->v_type
!= VDIR
) {
2496 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
2500 if (cs
->saved_exi
!= cs
->exi
) {
2501 *cs
->statusp
= resp
->status
= NFS4ERR_XDEV
;
2505 status
= utf8_dir_verify(&args
->newname
);
2506 if (status
!= NFS4_OK
) {
2507 *cs
->statusp
= resp
->status
= status
;
2511 nm
= utf8_to_fn(&args
->newname
, &len
, NULL
);
2513 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2517 if (len
> MAXNAMELEN
) {
2518 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
2523 if (rdonly4(cs
->exi
, cs
->vp
, req
)) {
2524 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
2529 /* Get "before" change value */
2530 bdva
.va_mask
= AT_CTIME
|AT_SEQ
;
2531 error
= VOP_GETATTR(dvp
, &bdva
, 0, cs
->cr
, NULL
);
2533 *cs
->statusp
= resp
->status
= puterrno4(error
);
2538 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
2539 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
2543 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2548 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.before
, bdva
.va_ctime
)
2550 error
= VOP_LINK(dvp
, vp
, name
, cs
->cr
, NULL
, 0);
2553 kmem_free(name
, MAXPATHLEN
+ 1);
2557 * Get the initial "after" sequence number, if it fails, set to zero
2559 idva
.va_mask
= AT_SEQ
;
2560 if (VOP_GETATTR(dvp
, &idva
, 0, cs
->cr
, NULL
))
2564 * Force modified data and metadata out to stable storage.
2566 (void) VOP_FSYNC(vp
, FNODSYNC
, cs
->cr
, NULL
);
2567 (void) VOP_FSYNC(dvp
, 0, cs
->cr
, NULL
);
2570 *cs
->statusp
= resp
->status
= puterrno4(error
);
2575 * Get "after" change value, if it fails, simply return the
2578 adva
.va_mask
= AT_CTIME
|AT_SEQ
;
2579 if (VOP_GETATTR(dvp
, &adva
, 0, cs
->cr
, NULL
)) {
2580 adva
.va_ctime
= bdva
.va_ctime
;
2584 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.after
, adva
.va_ctime
)
2587 * The cinfo.atomic = TRUE only if we have
2588 * non-zero va_seq's, and it has incremented by exactly one
2589 * during the VOP_LINK and it didn't change during the VOP_FSYNC.
2591 if (bdva
.va_seq
&& idva
.va_seq
&& adva
.va_seq
&&
2592 idva
.va_seq
== (bdva
.va_seq
+ 1) && idva
.va_seq
== adva
.va_seq
)
2593 resp
->cinfo
.atomic
= TRUE
;
2595 resp
->cinfo
.atomic
= FALSE
;
2597 *cs
->statusp
= resp
->status
= NFS4_OK
;
2599 DTRACE_NFSV4_2(op__link__done
, struct compound_state
*, cs
,
2604 * Used by rfs4_op_lookup and rfs4_op_lookupp to do the actual work.
2609 do_rfs4_op_lookup(char *nm
, struct svc_req
*req
, struct compound_state
*cs
)
2612 int different_export
= 0;
2613 vnode_t
*vp
, *tvp
, *pre_tvp
= NULL
, *oldvp
= NULL
;
2614 struct exportinfo
*exi
= NULL
, *pre_exi
= NULL
;
2617 int attrdir
, dotdot
, walk
;
2618 bool_t is_newvp
= FALSE
;
2620 if (cs
->vp
->v_flag
& V_XATTRDIR
) {
2622 ASSERT(get_fh4_flag(&cs
->fh
, FH4_ATTRDIR
));
2625 ASSERT(! get_fh4_flag(&cs
->fh
, FH4_ATTRDIR
));
2628 dotdot
= (nm
[0] == '.' && nm
[1] == '.' && nm
[2] == '\0');
2631 * If dotdotting, then need to check whether it's
2632 * above the root of a filesystem, or above an
2638 * If dotdotting at the root of a filesystem, then
2639 * need to traverse back to the mounted-on filesystem
2640 * and do the dotdot lookup there.
2642 if (cs
->vp
->v_flag
& VROOT
) {
2645 * If at the system root, then can
2648 if (VN_CMP(cs
->vp
, rootdir
))
2649 return (puterrno4(ENOENT
));
2652 * Traverse back to the mounted-on filesystem
2654 cs
->vp
= untraverse(cs
->vp
);
2657 * Set the different_export flag so we remember
2658 * to pick up a new exportinfo entry for
2659 * this new filesystem.
2661 different_export
= 1;
2665 * If dotdotting above an export point then set
2666 * the different_export to get new export info.
2668 different_export
= nfs_exported(cs
->exi
, cs
->vp
);
2672 error
= VOP_LOOKUP(cs
->vp
, nm
, &vp
, NULL
, 0, NULL
, cs
->cr
,
2675 return (puterrno4(error
));
2678 * If the vnode is in a pseudo filesystem, check whether it is visible.
2680 * XXX if the vnode is a symlink and it is not visible in
2681 * a pseudo filesystem, return ENOENT (not following symlink).
2682 * V4 client can not mount such symlink. This is a regression
2685 * In the same exported filesystem, if the security flavor used
2686 * is not an explicitly shared flavor, limit the view to the visible
2687 * list entries only. This is not a WRONGSEC case because it's already
2688 * checked via PUTROOTFH/PUTPUBFH or PUTFH.
2690 if (!different_export
&&
2691 (PSEUDO(cs
->exi
) || ! is_exported_sec(cs
->nfsflavor
, cs
->exi
) ||
2692 cs
->access
& CS_ACCESS_LIMITED
)) {
2693 if (! nfs_visible(cs
->exi
, vp
, &different_export
)) {
2695 return (puterrno4(ENOENT
));
2700 * If it's a mountpoint, then traverse it.
2702 if (vn_ismntpt(vp
)) {
2703 pre_exi
= cs
->exi
; /* save pre-traversed exportinfo */
2704 pre_tvp
= vp
; /* save pre-traversed vnode */
2707 * hold pre_tvp to counteract rele by traverse. We will
2708 * need pre_tvp below if checkexport4 fails
2712 if ((error
= traverse(&tvp
)) != 0) {
2715 return (puterrno4(error
));
2718 different_export
= 1;
2719 } else if (vp
->v_vfsp
!= cs
->vp
->v_vfsp
) {
2721 * The vfsp comparison is to handle the case where
2722 * a LOFS mount is shared. lo_lookup traverses mount points,
2723 * and NFS is unaware of local fs transistions because
2724 * v_vfsmountedhere isn't set. For this special LOFS case,
2725 * the dir and the obj returned by lookup will have different
2728 different_export
= 1;
2731 if (different_export
) {
2733 bzero(&fid
, sizeof (fid
));
2734 fid
.fid_len
= MAXFIDSZ
;
2735 error
= vop_fid_pseudo(vp
, &fid
);
2740 return (puterrno4(error
));
2744 exi
= nfs_vptoexi(NULL
, vp
, cs
->cr
, &walk
, NULL
, TRUE
);
2746 exi
= checkexport4(&vp
->v_vfsp
->vfs_fsid
, &fid
, vp
);
2751 * If this vnode is a mounted-on vnode,
2752 * but the mounted-on file system is not
2753 * exported, send back the filehandle for
2754 * the mounted-on vnode, not the root of
2755 * the mounted-on file system.
2762 return (puterrno4(EACCES
));
2764 } else if (pre_tvp
) {
2765 /* we're done with pre_tvp now. release extra hold */
2772 * Now we do a checkauth4. The reason is that
2773 * this client/user may not have access to the new
2774 * exported file system, and if he does,
2775 * the client/user may be mapped to a different uid.
2777 * We start with a new cr, because the checkauth4 done
2778 * in the PUT*FH operation over wrote the cred's uid,
2779 * gid, etc, and we want the real thing before calling
2783 cs
->cr
= crdup(cs
->basecr
);
2789 stat
= call_checkauth4(cs
, req
);
2790 if (stat
!= NFS4_OK
) {
2798 * After various NFS checks, do a label check on the path
2799 * component. The label on this path should either be the
2800 * global zone's label or a zone's label. We are only
2801 * interested in the zone's label because exported files
2802 * in global zone is accessible (though read-only) to
2803 * clients. The exportability/visibility check is already
2804 * done before reaching this code.
2806 if (is_system_labeled()) {
2809 ASSERT(req
->rq_label
!= NULL
);
2810 clabel
= req
->rq_label
;
2811 DTRACE_PROBE2(tx__rfs4__log__info__oplookup__clabel
, char *,
2812 "got client label from request(1)", struct svc_req
*, req
);
2814 if (!blequal(&l_admin_low
->tsl_label
, clabel
)) {
2815 if (!do_rfs_label_check(clabel
, vp
, DOMINANCE_CHECK
,
2822 * We grant access to admin_low label clients
2823 * only if the client is trusted, i.e. also
2824 * running Solaris Trusted Extension.
2826 struct sockaddr
*ca
;
2831 ca
= (struct sockaddr
*)svc_getrpccaller(
2833 if (ca
->sa_family
== AF_INET
) {
2834 addr_type
= IPV4_VERSION
;
2835 ipaddr
= &((struct sockaddr_in
*)ca
)->sin_addr
;
2836 } else if (ca
->sa_family
== AF_INET6
) {
2837 addr_type
= IPV6_VERSION
;
2838 ipaddr
= &((struct sockaddr_in6
*)
2841 tp
= find_tpc(ipaddr
, addr_type
, B_FALSE
);
2842 if (tp
== NULL
|| tp
->tpc_tp
.tp_doi
!=
2843 l_admin_low
->tsl_doi
|| tp
->tpc_tp
.host_type
!=
2854 error
= makefh4(&cs
->fh
, vp
, cs
->exi
);
2863 return (puterrno4(error
));
2874 * if did lookup on attrdir and didn't lookup .., set named
2877 if (attrdir
&& ! dotdot
)
2878 set_fh4_flag(&cs
->fh
, FH4_NAMEDATTR
);
2880 /* Assume false for now, open proc will set this */
2881 cs
->mandlock
= FALSE
;
2888 rfs4_op_lookup(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2889 struct compound_state
*cs
)
2891 LOOKUP4args
*args
= &argop
->nfs_argop4_u
.oplookup
;
2892 LOOKUP4res
*resp
= &resop
->nfs_resop4_u
.oplookup
;
2895 struct sockaddr
*ca
;
2899 DTRACE_NFSV4_2(op__lookup__start
, struct compound_state
*, cs
,
2900 LOOKUP4args
*, args
);
2902 if (cs
->vp
== NULL
) {
2903 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2907 if (cs
->vp
->v_type
== VLNK
) {
2908 *cs
->statusp
= resp
->status
= NFS4ERR_SYMLINK
;
2912 if (cs
->vp
->v_type
!= VDIR
) {
2913 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
2917 status
= utf8_dir_verify(&args
->objname
);
2918 if (status
!= NFS4_OK
) {
2919 *cs
->statusp
= resp
->status
= status
;
2923 nm
= utf8_to_str(&args
->objname
, &len
, NULL
);
2925 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2929 if (len
> MAXNAMELEN
) {
2930 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
2935 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
2936 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
2940 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2945 *cs
->statusp
= resp
->status
= do_rfs4_op_lookup(name
, req
, cs
);
2948 kmem_free(name
, MAXPATHLEN
+ 1);
2952 DTRACE_NFSV4_2(op__lookup__done
, struct compound_state
*, cs
,
2953 LOOKUP4res
*, resp
);
2958 rfs4_op_lookupp(nfs_argop4
*args
, nfs_resop4
*resop
, struct svc_req
*req
,
2959 struct compound_state
*cs
)
2961 LOOKUPP4res
*resp
= &resop
->nfs_resop4_u
.oplookupp
;
2963 DTRACE_NFSV4_1(op__lookupp__start
, struct compound_state
*, cs
);
2965 if (cs
->vp
== NULL
) {
2966 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2970 if (cs
->vp
->v_type
!= VDIR
) {
2971 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
2975 *cs
->statusp
= resp
->status
= do_rfs4_op_lookup("..", req
, cs
);
2978 * From NFSV4 Specification, LOOKUPP should not check for
2979 * NFS4ERR_WRONGSEC. Retrun NFS4_OK instead.
2981 if (resp
->status
== NFS4ERR_WRONGSEC
) {
2982 *cs
->statusp
= resp
->status
= NFS4_OK
;
2986 DTRACE_NFSV4_2(op__lookupp__done
, struct compound_state
*, cs
,
2987 LOOKUPP4res
*, resp
);
2993 rfs4_op_openattr(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2994 struct compound_state
*cs
)
2996 OPENATTR4args
*args
= &argop
->nfs_argop4_u
.opopenattr
;
2997 OPENATTR4res
*resp
= &resop
->nfs_resop4_u
.opopenattr
;
2998 vnode_t
*avp
= NULL
;
2999 int lookup_flags
= LOOKUP_XATTR
, error
;
3002 DTRACE_NFSV4_2(op__openattr__start
, struct compound_state
*, cs
,
3003 OPENATTR4args
*, args
);
3005 if (cs
->vp
== NULL
) {
3006 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
3010 if ((cs
->vp
->v_vfsp
->vfs_flag
& VFS_XATTR
) == 0 &&
3011 !vfs_has_feature(cs
->vp
->v_vfsp
, VFSFT_SYSATTR_VIEWS
)) {
3012 *cs
->statusp
= resp
->status
= puterrno4(ENOTSUP
);
3017 * If file system supports passing ACE mask to VOP_ACCESS then
3018 * check for ACE_READ_NAMED_ATTRS, otherwise do legacy checks
3021 if (vfs_has_feature(cs
->vp
->v_vfsp
, VFSFT_ACEMASKONACCESS
))
3022 error
= VOP_ACCESS(cs
->vp
, ACE_READ_NAMED_ATTRS
,
3023 V_ACE_MASK
, cs
->cr
, NULL
);
3025 error
= ((VOP_ACCESS(cs
->vp
, VREAD
, 0, cs
->cr
, NULL
) != 0) &&
3026 (VOP_ACCESS(cs
->vp
, VWRITE
, 0, cs
->cr
, NULL
) != 0) &&
3027 (VOP_ACCESS(cs
->vp
, VEXEC
, 0, cs
->cr
, NULL
) != 0));
3030 *cs
->statusp
= resp
->status
= puterrno4(EACCES
);
3035 * The CREATE_XATTR_DIR VOP flag cannot be specified if
3036 * the file system is exported read-only -- regardless of
3037 * createdir flag. Otherwise the attrdir would be created
3038 * (assuming server fs isn't mounted readonly locally). If
3039 * VOP_LOOKUP returns ENOENT in this case, the error will
3040 * be translated into EROFS. ENOSYS is mapped to ENOTSUP
3041 * because specfs has no VOP_LOOKUP op, so the macro would
3042 * return ENOSYS. EINVAL is returned by all (current)
3043 * Solaris file system implementations when any of their
3044 * restrictions are violated (xattr(dir) can't have xattrdir).
3045 * Returning NOTSUPP is more appropriate in this case
3046 * because the object will never be able to have an attrdir.
3048 if (args
->createdir
&& ! (exp_ro
= rdonly4(cs
->exi
, cs
->vp
, req
)))
3049 lookup_flags
|= CREATE_XATTR_DIR
;
3051 error
= VOP_LOOKUP(cs
->vp
, "", &avp
, NULL
, lookup_flags
, NULL
, cs
->cr
,
3055 if (error
== ENOENT
&& args
->createdir
&& exp_ro
)
3056 *cs
->statusp
= resp
->status
= puterrno4(EROFS
);
3057 else if (error
== EINVAL
|| error
== ENOSYS
)
3058 *cs
->statusp
= resp
->status
= puterrno4(ENOTSUP
);
3060 *cs
->statusp
= resp
->status
= puterrno4(error
);
3064 ASSERT(avp
->v_flag
& V_XATTRDIR
);
3066 error
= makefh4(&cs
->fh
, avp
, cs
->exi
);
3070 *cs
->statusp
= resp
->status
= puterrno4(error
);
3078 * There is no requirement for an attrdir fh flag
3079 * because the attrdir has a vnode flag to distinguish
3080 * it from regular (non-xattr) directories. The
3081 * FH4_ATTRDIR flag is set for future sanity checks.
3083 set_fh4_flag(&cs
->fh
, FH4_ATTRDIR
);
3084 *cs
->statusp
= resp
->status
= NFS4_OK
;
3087 DTRACE_NFSV4_2(op__openattr__done
, struct compound_state
*, cs
,
3088 OPENATTR4res
*, resp
);
3092 do_io(int direction
, vnode_t
*vp
, struct uio
*uio
, int ioflag
, cred_t
*cred
,
3093 caller_context_t
*ct
)
3099 delaytime
= MSEC_TO_TICK_ROUNDUP(rfs4_lock_delay
);
3102 * Don't block on mandatory locks. If this routine returns
3103 * EAGAIN, the caller should return NFS4ERR_LOCKED.
3105 uio
->uio_fmode
= FNONBLOCK
;
3107 for (i
= 0; i
< rfs4_maxlock_tries
; i
++) {
3110 if (direction
== FREAD
) {
3111 (void) VOP_RWLOCK(vp
, V_WRITELOCK_FALSE
, ct
);
3112 error
= VOP_READ(vp
, uio
, ioflag
, cred
, ct
);
3113 VOP_RWUNLOCK(vp
, V_WRITELOCK_FALSE
, ct
);
3115 (void) VOP_RWLOCK(vp
, V_WRITELOCK_TRUE
, ct
);
3116 error
= VOP_WRITE(vp
, uio
, ioflag
, cred
, ct
);
3117 VOP_RWUNLOCK(vp
, V_WRITELOCK_TRUE
, ct
);
3120 if (error
!= EAGAIN
)
3123 if (i
< rfs4_maxlock_tries
- 1) {
3134 rfs4_op_read(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3135 struct compound_state
*cs
)
3137 READ4args
*args
= &argop
->nfs_argop4_u
.opread
;
3138 READ4res
*resp
= &resop
->nfs_resop4_u
.opread
;
3146 bool_t
*deleg
= &cs
->deleg
;
3153 caller_context_t ct
;
3156 DTRACE_NFSV4_2(op__read__start
, struct compound_state
*, cs
,
3161 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
3164 if (cs
->access
== CS_ACCESS_DENIED
) {
3165 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3169 if ((stat
= rfs4_check_stateid(FREAD
, vp
, &args
->stateid
, FALSE
,
3170 deleg
, TRUE
, &ct
)) != NFS4_OK
) {
3171 *cs
->statusp
= resp
->status
= stat
;
3176 * Enter the critical region before calling VOP_RWLOCK
3177 * to avoid a deadlock with write requests.
3179 if (nbl_need_check(vp
)) {
3180 nbl_start_crit(vp
, RW_READER
);
3182 if (nbl_conflict(vp
, NBL_READ
, args
->offset
, args
->count
, 0,
3184 *cs
->statusp
= resp
->status
= NFS4ERR_LOCKED
;
3189 if ((stat
= rfs4_check_stateid(FREAD
, vp
, &args
->stateid
, FALSE
,
3190 deleg
, TRUE
, &ct
)) != NFS4_OK
) {
3191 *cs
->statusp
= resp
->status
= stat
;
3196 if (args
->count
> clist_len(args
->wlist
)) {
3197 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3203 /* use loaned buffers for TCP */
3204 loaned_buffers
= (nfs_loaned_buffers
&& !rdma_used
) ? 1 : 0;
3206 va
.va_mask
= AT_MODE
|AT_SIZE
|AT_UID
;
3207 verror
= VOP_GETATTR(vp
, &va
, 0, cs
->cr
, &ct
);
3210 * If we can't get the attributes, then we can't do the
3211 * right access checking. So, we'll fail the request.
3214 *cs
->statusp
= resp
->status
= puterrno4(verror
);
3218 if (vp
->v_type
!= VREG
) {
3219 *cs
->statusp
= resp
->status
=
3220 ((vp
->v_type
== VDIR
) ? NFS4ERR_ISDIR
: NFS4ERR_INVAL
);
3224 if (crgetuid(cs
->cr
) != va
.va_uid
&&
3225 (error
= VOP_ACCESS(vp
, VREAD
, 0, cs
->cr
, &ct
)) &&
3226 (error
= VOP_ACCESS(vp
, VEXEC
, 0, cs
->cr
, &ct
))) {
3227 *cs
->statusp
= resp
->status
= puterrno4(error
);
3231 if (MANDLOCK(vp
, va
.va_mode
)) { /* XXX - V4 supports mand locking */
3232 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3236 offset
= args
->offset
;
3237 if (offset
>= va
.va_size
) {
3238 *cs
->statusp
= resp
->status
= NFS4_OK
;
3241 resp
->data_val
= NULL
;
3244 resp
->wlist
= args
->wlist
;
3245 resp
->wlist_len
= resp
->data_len
;
3246 *cs
->statusp
= resp
->status
= NFS4_OK
;
3248 clist_zero_len(resp
->wlist
);
3252 if (args
->count
== 0) {
3253 *cs
->statusp
= resp
->status
= NFS4_OK
;
3256 resp
->data_val
= NULL
;
3259 resp
->wlist
= args
->wlist
;
3260 resp
->wlist_len
= resp
->data_len
;
3262 clist_zero_len(resp
->wlist
);
3267 * Do not allocate memory more than maximum allowed
3270 if (args
->count
> rfs4_tsize(req
))
3271 args
->count
= rfs4_tsize(req
);
3273 if (loaned_buffers
) {
3274 uiop
= (uio_t
*)rfs_setup_xuio(vp
);
3275 ASSERT(uiop
!= NULL
);
3276 uiop
->uio_segflg
= UIO_SYSSPACE
;
3277 uiop
->uio_loffset
= args
->offset
;
3278 uiop
->uio_resid
= args
->count
;
3280 /* Jump to do the read if successful */
3281 if (!VOP_REQZCBUF(vp
, UIO_READ
, (xuio_t
*)uiop
, cs
->cr
, &ct
)) {
3283 * Need to hold the vnode until after VOP_RETZCBUF()
3290 DTRACE_PROBE2(nfss__i__reqzcbuf_failed
, int,
3291 uiop
->uio_loffset
, int, uiop
->uio_resid
);
3293 uiop
->uio_extflg
= 0;
3295 /* failure to setup for zero copy */
3296 rfs_free_xuio((void *)uiop
);
3301 * If returning data via RDMA Write, then grab the chunk list. If we
3302 * aren't returning READ data w/RDMA_WRITE, then grab a mblk.
3306 (void) rdma_get_wchunk(req
, &iov
, args
->wlist
);
3309 * mp will contain the data to be sent out in the read reply.
3310 * It will be freed after the reply has been sent. Let's
3311 * roundup the data to a BYTES_PER_XDR_UNIT multiple, so that
3312 * the call to xdrmblk_putmblk() never fails. If the first
3313 * alloc of the requested size fails, then decrease the size to
3314 * something more reasonable and wait for the allocation to
3317 mp
= allocb(RNDUP(args
->count
), BPRI_MED
);
3319 if (args
->count
> MAXBSIZE
)
3320 args
->count
= MAXBSIZE
;
3321 mp
= allocb_wait(RNDUP(args
->count
), BPRI_MED
,
3322 STR_NOSIG
, &alloc_err
);
3325 ASSERT(alloc_err
== 0);
3327 iov
.iov_base
= (caddr_t
)mp
->b_datap
->db_base
;
3328 iov
.iov_len
= args
->count
;
3333 uio
.uio_segflg
= UIO_SYSSPACE
;
3334 uio
.uio_extflg
= UIO_COPY_CACHED
;
3335 uio
.uio_loffset
= args
->offset
;
3336 uio
.uio_resid
= args
->count
;
3340 error
= do_io(FREAD
, vp
, uiop
, 0, cs
->cr
, &ct
);
3342 va
.va_mask
= AT_SIZE
;
3343 verror
= VOP_GETATTR(vp
, &va
, 0, cs
->cr
, &ct
);
3348 *cs
->statusp
= resp
->status
= puterrno4(error
);
3352 /* make mblk using zc buffers */
3353 if (loaned_buffers
) {
3354 mp
= uio_to_mblk(uiop
);
3358 *cs
->statusp
= resp
->status
= NFS4_OK
;
3360 ASSERT(uiop
->uio_resid
>= 0);
3361 resp
->data_len
= args
->count
- uiop
->uio_resid
;
3363 resp
->data_val
= (char *)mp
->b_datap
->db_base
;
3364 rfs_rndup_mblks(mp
, resp
->data_len
, loaned_buffers
);
3366 resp
->data_val
= (caddr_t
)iov
.iov_base
;
3371 if (!verror
&& offset
+ resp
->data_len
== va
.va_size
)
3377 if (!rdma_setup_read_data4(args
, resp
)) {
3378 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3388 DTRACE_NFSV4_2(op__read__done
, struct compound_state
*, cs
,
3393 rfs4_op_read_free(nfs_resop4
*resop
)
3395 READ4res
*resp
= &resop
->nfs_resop4_u
.opread
;
3397 if (resp
->status
== NFS4_OK
&& resp
->mblk
!= NULL
) {
3398 freemsg(resp
->mblk
);
3400 resp
->data_val
= NULL
;
3406 rfs4_op_readdir_free(nfs_resop4
* resop
)
3408 READDIR4res
*resp
= &resop
->nfs_resop4_u
.opreaddir
;
3410 if (resp
->status
== NFS4_OK
&& resp
->mblk
!= NULL
) {
3420 rfs4_op_putpubfh(nfs_argop4
*args
, nfs_resop4
*resop
, struct svc_req
*req
,
3421 struct compound_state
*cs
)
3423 PUTPUBFH4res
*resp
= &resop
->nfs_resop4_u
.opputpubfh
;
3426 struct exportinfo
*exi
, *sav_exi
;
3427 nfs_fh4_fmt_t
*fh_fmtp
;
3429 DTRACE_NFSV4_1(op__putpubfh__start
, struct compound_state
*, cs
);
3439 cs
->cr
= crdup(cs
->basecr
);
3441 vp
= exi_public
->exi_vp
;
3443 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
3447 error
= makefh4(&cs
->fh
, vp
, exi_public
);
3449 *cs
->statusp
= resp
->status
= puterrno4(error
);
3453 if (exi_public
== exi_root
) {
3455 * No filesystem is actually shared public, so we default
3456 * to exi_root. In this case, we must check whether root
3459 fh_fmtp
= (nfs_fh4_fmt_t
*)cs
->fh
.nfs_fh4_val
;
3462 * if root filesystem is exported, the exportinfo struct that we
3463 * should use is what checkexport4 returns, because root_exi is
3464 * actually a mostly empty struct.
3466 exi
= checkexport4(&fh_fmtp
->fh4_fsid
,
3467 (fid_t
*)&fh_fmtp
->fh4_xlen
, NULL
);
3468 cs
->exi
= ((exi
!= NULL
) ? exi
: exi_public
);
3471 * it's a properly shared filesystem
3473 cs
->exi
= exi_public
;
3476 if (is_system_labeled()) {
3479 ASSERT(req
->rq_label
!= NULL
);
3480 clabel
= req
->rq_label
;
3481 DTRACE_PROBE2(tx__rfs4__log__info__opputpubfh__clabel
, char *,
3482 "got client label from request(1)",
3483 struct svc_req
*, req
);
3484 if (!blequal(&l_admin_low
->tsl_label
, clabel
)) {
3485 if (!do_rfs_label_check(clabel
, vp
, DOMINANCE_CHECK
,
3487 *cs
->statusp
= resp
->status
=
3488 NFS4ERR_SERVERFAULT
;
3497 if ((resp
->status
= call_checkauth4(cs
, req
)) != NFS4_OK
) {
3504 *cs
->statusp
= resp
->status
= NFS4_OK
;
3506 DTRACE_NFSV4_2(op__putpubfh__done
, struct compound_state
*, cs
,
3507 PUTPUBFH4res
*, resp
);
3511 * XXX - issue with put*fh operations. Suppose /export/home is exported.
3512 * Suppose an NFS client goes to mount /export/home/joe. If /export, home,
3513 * or joe have restrictive search permissions, then we shouldn't let
3514 * the client get a file handle. This is easy to enforce. However, we
3515 * don't know what security flavor should be used until we resolve the
3516 * path name. Another complication is uid mapping. If root is
3517 * the user, then it will be mapped to the anonymous user by default,
3518 * but we won't know that till we've resolved the path name. And we won't
3519 * know what the anonymous user is.
3520 * Luckily, SECINFO is specified to take a full filename.
3521 * So what we will have to in rfs4_op_lookup is check that flavor of
3522 * the target object matches that of the request, and if root was the
3523 * caller, check for the root= and anon= options, and if necessary,
3524 * repeat the lookup using the right cred_t. But that's not done yet.
3528 rfs4_op_putfh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3529 struct compound_state
*cs
)
3531 PUTFH4args
*args
= &argop
->nfs_argop4_u
.opputfh
;
3532 PUTFH4res
*resp
= &resop
->nfs_resop4_u
.opputfh
;
3533 nfs_fh4_fmt_t
*fh_fmtp
;
3535 DTRACE_NFSV4_2(op__putfh__start
, struct compound_state
*, cs
,
3536 PUTFH4args
*, args
);
3549 if (args
->object
.nfs_fh4_len
< NFS_FH4_LEN
) {
3550 *cs
->statusp
= resp
->status
= NFS4ERR_BADHANDLE
;
3554 fh_fmtp
= (nfs_fh4_fmt_t
*)args
->object
.nfs_fh4_val
;
3555 cs
->exi
= checkexport4(&fh_fmtp
->fh4_fsid
, (fid_t
*)&fh_fmtp
->fh4_xlen
,
3558 if (cs
->exi
== NULL
) {
3559 *cs
->statusp
= resp
->status
= NFS4ERR_STALE
;
3563 cs
->cr
= crdup(cs
->basecr
);
3565 ASSERT(cs
->cr
!= NULL
);
3567 if (! (cs
->vp
= nfs4_fhtovp(&args
->object
, cs
->exi
, &resp
->status
))) {
3568 *cs
->statusp
= resp
->status
;
3572 if ((resp
->status
= call_checkauth4(cs
, req
)) != NFS4_OK
) {
3578 nfs_fh4_copy(&args
->object
, &cs
->fh
);
3579 *cs
->statusp
= resp
->status
= NFS4_OK
;
3583 DTRACE_NFSV4_2(op__putfh__done
, struct compound_state
*, cs
,
3589 rfs4_op_putrootfh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3590 struct compound_state
*cs
)
3592 PUTROOTFH4res
*resp
= &resop
->nfs_resop4_u
.opputrootfh
;
3595 struct exportinfo
*exi
, *sav_exi
;
3597 DTRACE_NFSV4_1(op__putrootfh__start
, struct compound_state
*, cs
);
3607 cs
->cr
= crdup(cs
->basecr
);
3610 * Using rootdir, the system root vnode,
3613 bzero(&fid
, sizeof (fid
));
3614 fid
.fid_len
= MAXFIDSZ
;
3615 error
= vop_fid_pseudo(rootdir
, &fid
);
3617 *cs
->statusp
= resp
->status
= puterrno4(error
);
3622 * Then use the root fsid & fid it to find out if it's exported
3624 * If the server root isn't exported directly, then
3625 * it should at least be a pseudo export based on
3626 * one or more exports further down in the server's
3629 exi
= checkexport4(&rootdir
->v_vfsp
->vfs_fsid
, &fid
, NULL
);
3630 if (exi
== NULL
|| exi
->exi_export
.ex_flags
& EX_PUBLIC
) {
3631 NFS4_DEBUG(rfs4_debug
,
3632 (CE_WARN
, "rfs4_op_putrootfh: export check failure"));
3633 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
3638 * Now make a filehandle based on the root
3639 * export and root vnode.
3641 error
= makefh4(&cs
->fh
, rootdir
, exi
);
3643 *cs
->statusp
= resp
->status
= puterrno4(error
);
3653 if ((resp
->status
= call_checkauth4(cs
, req
)) != NFS4_OK
) {
3660 *cs
->statusp
= resp
->status
= NFS4_OK
;
3663 DTRACE_NFSV4_2(op__putrootfh__done
, struct compound_state
*, cs
,
3664 PUTROOTFH4res
*, resp
);
3668 * A directory entry is a valid nfsv4 entry if
3669 * - it has a non-zero ino
3670 * - it is not a dot or dotdot name
3671 * - it is visible in a pseudo export or in a real export that can
3672 * only have a limited view.
3675 valid_nfs4_entry(struct exportinfo
*exi
, struct dirent64
*dp
,
3676 int *expseudo
, int check_visible
)
3678 if (dp
->d_ino
== 0 || NFS_IS_DOTNAME(dp
->d_name
)) {
3683 if (! check_visible
) {
3688 return (nfs_visible_inode(exi
, dp
->d_ino
, expseudo
));
3692 * set_rdattr_params sets up the variables used to manage what information
3693 * to get for each directory entry.
3696 set_rdattr_params(struct nfs4_svgetit_arg
*sargp
,
3697 bitmap4 attrs
, bool_t
*need_to_lookup
)
3703 status
= bitmap4_to_attrmask(attrs
, sargp
);
3704 if (status
!= NFS4_OK
) {
3706 * could not even figure attr mask
3710 va_mask
= sargp
->vap
->va_mask
;
3713 * dirent's d_ino is always correct value for mounted_on_fileid.
3714 * mntdfid_set is set once here, but mounted_on_fileid is
3715 * set in main dirent processing loop for each dirent.
3716 * The mntdfid_set is a simple optimization that lets the
3717 * server attr code avoid work when caller is readdir.
3719 sargp
->mntdfid_set
= TRUE
;
3722 * Lookup entry only if client asked for any of the following:
3725 * c) attrs w/per-object scope requested (change, filehandle, etc)
3726 * other than mounted_on_fileid (which we can take from dirent)
3728 objbits
= attrs
? attrs
& NFS4_VP_ATTR_MASK
: 0;
3730 if (va_mask
|| sargp
->sbp
|| (objbits
& ~FATTR4_MOUNTED_ON_FILEID_MASK
))
3731 *need_to_lookup
= TRUE
;
3733 *need_to_lookup
= FALSE
;
3735 if (sargp
->sbp
== NULL
)
3739 * If filesystem attrs are requested, get them now from the
3740 * directory vp, as most entries will have same filesystem. The only
3741 * exception are mounted over entries but we handle
3742 * those as we go (XXX mounted over detection not yet implemented).
3744 sargp
->vap
->va_mask
= 0; /* to avoid VOP_GETATTR */
3745 status
= bitmap4_get_sysattrs(sargp
);
3746 sargp
->vap
->va_mask
= va_mask
;
3748 if ((status
!= NFS4_OK
) && sargp
->rdattr_error_req
) {
3750 * Failed to get filesystem attributes.
3751 * Return a rdattr_error for each entry, but don't fail.
3752 * However, don't get any obj-dependent attrs.
3754 sargp
->rdattr_error
= status
; /* for rdattr_error */
3755 *need_to_lookup
= FALSE
;
3757 * At least get fileid for regular readdir output
3759 sargp
->vap
->va_mask
&= AT_NODEID
;
3767 * readlink: args: CURRENT_FH.
3768 * res: status. If success - CURRENT_FH unchanged, return linktext.
3773 rfs4_op_readlink(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3774 struct compound_state
*cs
)
3776 READLINK4res
*resp
= &resop
->nfs_resop4_u
.opreadlink
;
3783 struct sockaddr
*ca
;
3787 DTRACE_NFSV4_1(op__readlink__start
, struct compound_state
*, cs
);
3789 /* CURRENT_FH: directory */
3792 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
3796 if (cs
->access
== CS_ACCESS_DENIED
) {
3797 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3801 /* Is it a referral? */
3802 if (vn_is_nfs_reparse(vp
, cs
->cr
) && client_is_downrev(req
)) {
3810 if (vp
->v_type
== VDIR
) {
3811 *cs
->statusp
= resp
->status
= NFS4ERR_ISDIR
;
3815 if (vp
->v_type
!= VLNK
) {
3816 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3822 va
.va_mask
= AT_MODE
;
3823 error
= VOP_GETATTR(vp
, &va
, 0, cs
->cr
, NULL
);
3825 *cs
->statusp
= resp
->status
= puterrno4(error
);
3829 if (MANDLOCK(vp
, va
.va_mode
)) {
3830 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3834 data
= kmem_alloc(MAXPATHLEN
+ 1, KM_SLEEP
);
3840 /* Get an artificial symlink based on a referral */
3841 s
= build_symlink(vp
, cs
->cr
, &strsz
);
3842 global_svstat_ptr
[4][NFS_REFERLINKS
].value
.ui64
++;
3843 DTRACE_PROBE2(nfs4serv__func__referral__reflink
,
3844 vnode_t
*, vp
, char *, s
);
3849 (void) strlcpy(data
, s
, MAXPATHLEN
+ 1);
3850 kmem_free(s
, strsz
);
3855 iov
.iov_base
= data
;
3856 iov
.iov_len
= MAXPATHLEN
;
3859 uio
.uio_segflg
= UIO_SYSSPACE
;
3860 uio
.uio_extflg
= UIO_COPY_CACHED
;
3861 uio
.uio_loffset
= 0;
3862 uio
.uio_resid
= MAXPATHLEN
;
3864 error
= VOP_READLINK(vp
, &uio
, cs
->cr
, NULL
);
3867 *(data
+ MAXPATHLEN
- uio
.uio_resid
) = '\0';
3871 kmem_free((caddr_t
)data
, (uint_t
)MAXPATHLEN
+ 1);
3872 *cs
->statusp
= resp
->status
= puterrno4(error
);
3876 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
3877 name
= nfscmd_convname(ca
, cs
->exi
, data
, NFSCMD_CONV_OUTBOUND
,
3882 * Even though the conversion failed, we return
3883 * something. We just don't translate it.
3889 * treat link name as data
3891 (void) str_to_utf8(name
, &resp
->link
);
3894 kmem_free(name
, MAXPATHLEN
+ 1);
3895 kmem_free((caddr_t
)data
, (uint_t
)MAXPATHLEN
+ 1);
3896 *cs
->statusp
= resp
->status
= NFS4_OK
;
3899 DTRACE_NFSV4_2(op__readlink__done
, struct compound_state
*, cs
,
3900 READLINK4res
*, resp
);
3904 rfs4_op_readlink_free(nfs_resop4
*resop
)
3906 READLINK4res
*resp
= &resop
->nfs_resop4_u
.opreadlink
;
3907 utf8string
*symlink
= &resp
->link
;
3909 if (symlink
->utf8string_val
) {
3910 UTF8STRING_FREE(*symlink
)
3915 * release_lockowner:
3916 * Release any state associated with the supplied
3917 * lockowner. Note if any lo_state is holding locks we will not
3918 * rele that lo_state and thus the lockowner will not be destroyed.
3919 * A client using lock after the lock owner stateid has been released
3920 * will suffer the consequence of NFS4ERR_BAD_STATEID and would have
3921 * to reissue the lock with new_lock_owner set to TRUE.
3927 rfs4_op_release_lockowner(nfs_argop4
*argop
, nfs_resop4
*resop
,
3928 struct svc_req
*req
, struct compound_state
*cs
)
3930 RELEASE_LOCKOWNER4args
*ap
= &argop
->nfs_argop4_u
.oprelease_lockowner
;
3931 RELEASE_LOCKOWNER4res
*resp
= &resop
->nfs_resop4_u
.oprelease_lockowner
;
3932 rfs4_lockowner_t
*lo
;
3933 rfs4_openowner_t
*oo
;
3935 rfs4_lo_state_t
*lsp
;
3937 bool_t create
= FALSE
;
3941 DTRACE_NFSV4_2(op__release__lockowner__start
, struct compound_state
*,
3942 cs
, RELEASE_LOCKOWNER4args
*, ap
);
3944 /* Make sure there is a clientid around for this request */
3945 cp
= rfs4_findclient_by_id(ap
->lock_owner
.clientid
, FALSE
);
3948 *cs
->statusp
= resp
->status
=
3949 rfs4_check_clientid(&ap
->lock_owner
.clientid
, 0);
3952 rfs4_client_rele(cp
);
3954 lo
= rfs4_findlockowner(&ap
->lock_owner
, &create
);
3956 *cs
->statusp
= resp
->status
= NFS4_OK
;
3959 ASSERT(lo
->rl_client
!= NULL
);
3962 * Check for EXPIRED client. If so will reap state with in a lease
3963 * period or on next set_clientid_confirm step
3965 if (rfs4_lease_expired(lo
->rl_client
)) {
3966 rfs4_lockowner_rele(lo
);
3967 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
3972 * If no sysid has been assigned, then no locks exist; just return.
3974 rfs4_dbe_lock(lo
->rl_client
->rc_dbe
);
3975 if (lo
->rl_client
->rc_sysidt
== LM_NOSYSID
) {
3976 rfs4_lockowner_rele(lo
);
3977 rfs4_dbe_unlock(lo
->rl_client
->rc_dbe
);
3981 sysid
= lo
->rl_client
->rc_sysidt
;
3982 rfs4_dbe_unlock(lo
->rl_client
->rc_dbe
);
3985 * Mark the lockowner invalid.
3987 rfs4_dbe_hide(lo
->rl_dbe
);
3990 * sysid-pid pair should now not be used since the lockowner is
3991 * invalid. If the client were to instantiate the lockowner again
3992 * it would be assigned a new pid. Thus we can get the list of
3996 llist
= flk_get_active_locks(sysid
, lo
->rl_pid
);
3997 /* If we are still holding locks fail */
3998 if (llist
!= NULL
) {
4000 *cs
->statusp
= resp
->status
= NFS4ERR_LOCKS_HELD
;
4002 flk_free_locklist(llist
);
4004 * We need to unhide the lockowner so the client can
4005 * try it again. The bad thing here is if the client
4006 * has a logic error that took it here in the first place
4007 * he probably has lost accounting of the locks that it
4008 * is holding. So we may have dangling state until the
4009 * open owner state is reaped via close. One scenario
4010 * that could possibly occur is that the client has
4011 * sent the unlock request(s) in separate threads
4012 * and has not waited for the replies before sending the
4013 * RELEASE_LOCKOWNER request. Presumably, it would expect
4014 * and deal appropriately with NFS4ERR_LOCKS_HELD, by
4015 * reissuing the request.
4017 rfs4_dbe_unhide(lo
->rl_dbe
);
4018 rfs4_lockowner_rele(lo
);
4023 * For the corresponding client we need to check each open
4024 * owner for any opens that have lockowner state associated
4025 * with this lockowner.
4028 rfs4_dbe_lock(lo
->rl_client
->rc_dbe
);
4029 for (oo
= list_head(&lo
->rl_client
->rc_openownerlist
); oo
!= NULL
;
4030 oo
= list_next(&lo
->rl_client
->rc_openownerlist
, oo
)) {
4032 rfs4_dbe_lock(oo
->ro_dbe
);
4033 for (sp
= list_head(&oo
->ro_statelist
); sp
!= NULL
;
4034 sp
= list_next(&oo
->ro_statelist
, sp
)) {
4036 rfs4_dbe_lock(sp
->rs_dbe
);
4037 for (lsp
= list_head(&sp
->rs_lostatelist
);
4039 lsp
= list_next(&sp
->rs_lostatelist
, lsp
)) {
4040 if (lsp
->rls_locker
== lo
) {
4041 rfs4_dbe_lock(lsp
->rls_dbe
);
4042 rfs4_dbe_invalidate(lsp
->rls_dbe
);
4043 rfs4_dbe_unlock(lsp
->rls_dbe
);
4046 rfs4_dbe_unlock(sp
->rs_dbe
);
4048 rfs4_dbe_unlock(oo
->ro_dbe
);
4050 rfs4_dbe_unlock(lo
->rl_client
->rc_dbe
);
4052 rfs4_lockowner_rele(lo
);
4054 *cs
->statusp
= resp
->status
= NFS4_OK
;
4057 DTRACE_NFSV4_2(op__release__lockowner__done
, struct compound_state
*,
4058 cs
, RELEASE_LOCKOWNER4res
*, resp
);
4062 * short utility function to lookup a file and recall the delegation
4064 static rfs4_file_t
*
4065 rfs4_lookup_and_findfile(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
,
4066 int *lkup_error
, cred_t
*cr
)
4069 rfs4_file_t
*fp
= NULL
;
4070 bool_t fcreate
= FALSE
;
4076 if ((error
= VOP_LOOKUP(dvp
, nm
, &vp
, NULL
, 0, NULL
, cr
, NULL
, NULL
,
4078 if (vp
->v_type
== VREG
)
4079 fp
= rfs4_findfile(vp
, NULL
, &fcreate
);
4087 *lkup_error
= error
;
4093 * remove: args: CURRENT_FH: directory; name.
4094 * res: status. If success - CURRENT_FH unchanged, return change_info
4099 rfs4_op_remove(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
4100 struct compound_state
*cs
)
4102 REMOVE4args
*args
= &argop
->nfs_argop4_u
.opremove
;
4103 REMOVE4res
*resp
= &resop
->nfs_resop4_u
.opremove
;
4106 struct vattr bdva
, idva
, adva
;
4112 struct sockaddr
*ca
;
4116 DTRACE_NFSV4_2(op__remove__start
, struct compound_state
*, cs
,
4117 REMOVE4args
*, args
);
4119 /* CURRENT_FH: directory */
4122 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
4126 if (cs
->access
== CS_ACCESS_DENIED
) {
4127 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4132 * If there is an unshared filesystem mounted on this vnode,
4133 * Do not allow to remove anything in this directory.
4135 if (vn_ismntpt(dvp
)) {
4136 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4140 if (dvp
->v_type
!= VDIR
) {
4141 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
4145 status
= utf8_dir_verify(&args
->target
);
4146 if (status
!= NFS4_OK
) {
4147 *cs
->statusp
= resp
->status
= status
;
4152 * Lookup the file so that we can check if it's a directory
4154 nm
= utf8_to_fn(&args
->target
, &len
, NULL
);
4156 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4160 if (len
> MAXNAMELEN
) {
4161 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
4166 if (rdonly4(cs
->exi
, cs
->vp
, req
)) {
4167 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
4172 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
4173 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
4177 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4183 * Lookup the file to determine type and while we are see if
4184 * there is a file struct around and check for delegation.
4185 * We don't need to acquire va_seq before this lookup, if
4186 * it causes an update, cinfo.before will not match, which will
4187 * trigger a cache flush even if atomic is TRUE.
4189 if (fp
= rfs4_lookup_and_findfile(dvp
, name
, &vp
, &error
, cs
->cr
)) {
4190 if (rfs4_check_delegated_byfp(FWRITE
, fp
, TRUE
, TRUE
, TRUE
,
4194 *cs
->statusp
= resp
->status
= NFS4ERR_DELAY
;
4196 kmem_free(name
, MAXPATHLEN
+ 1);
4202 /* Didn't find anything to remove */
4204 *cs
->statusp
= resp
->status
= error
;
4206 kmem_free(name
, MAXPATHLEN
+ 1);
4211 if (nbl_need_check(vp
)) {
4212 nbl_start_crit(vp
, RW_READER
);
4214 if (nbl_conflict(vp
, NBL_REMOVE
, 0, 0, 0, NULL
)) {
4215 *cs
->statusp
= resp
->status
= NFS4ERR_FILE_OPEN
;
4217 kmem_free(name
, MAXPATHLEN
+ 1);
4222 rfs4_clear_dont_grant(fp
);
4229 /* check label before allowing removal */
4230 if (is_system_labeled()) {
4231 ASSERT(req
->rq_label
!= NULL
);
4232 clabel
= req
->rq_label
;
4233 DTRACE_PROBE2(tx__rfs4__log__info__opremove__clabel
, char *,
4234 "got client label from request(1)",
4235 struct svc_req
*, req
);
4236 if (!blequal(&l_admin_low
->tsl_label
, clabel
)) {
4237 if (!do_rfs_label_check(clabel
, vp
, EQUALITY_CHECK
,
4239 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4241 kmem_free(name
, MAXPATHLEN
+ 1);
4247 rfs4_clear_dont_grant(fp
);
4255 /* Get dir "before" change value */
4256 bdva
.va_mask
= AT_CTIME
|AT_SEQ
;
4257 error
= VOP_GETATTR(dvp
, &bdva
, 0, cs
->cr
, NULL
);
4259 *cs
->statusp
= resp
->status
= puterrno4(error
);
4261 kmem_free(name
, MAXPATHLEN
+ 1);
4267 rfs4_clear_dont_grant(fp
);
4272 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.before
, bdva
.va_ctime
)
4274 /* Actually do the REMOVE operation */
4275 if (vp
->v_type
== VDIR
) {
4277 * Can't remove a directory that has a mounted-on filesystem.
4279 if (vn_ismntpt(vp
)) {
4283 * System V defines rmdir to return EEXIST,
4284 * not ENOTEMPTY, if the directory is not
4285 * empty. A System V NFS server needs to map
4286 * NFS4ERR_EXIST to NFS4ERR_NOTEMPTY to
4287 * transmit over the wire.
4289 if ((error
= VOP_RMDIR(dvp
, name
, rootdir
, cs
->cr
,
4290 NULL
, 0)) == EEXIST
)
4294 if ((error
= VOP_REMOVE(dvp
, name
, cs
->cr
, NULL
, 0)) == 0 &&
4299 rfs4_dbe_lock(fp
->rf_dbe
);
4303 rfs4_dbe_unlock(fp
->rf_dbe
);
4307 * This is va_seq safe because we are not
4310 va
.va_mask
= AT_NLINK
;
4311 if (!VOP_GETATTR(tvp
, &va
, 0, cs
->cr
, NULL
) &&
4313 /* Remove state on file remove */
4318 rfs4_close_all_state(fp
);
4330 rfs4_clear_dont_grant(fp
);
4334 kmem_free(name
, MAXPATHLEN
+ 1);
4338 *cs
->statusp
= resp
->status
= puterrno4(error
);
4343 * Get the initial "after" sequence number, if it fails, set to zero
4345 idva
.va_mask
= AT_SEQ
;
4346 if (VOP_GETATTR(dvp
, &idva
, 0, cs
->cr
, NULL
))
4350 * Force modified data and metadata out to stable storage.
4352 (void) VOP_FSYNC(dvp
, 0, cs
->cr
, NULL
);
4355 * Get "after" change value, if it fails, simply return the
4358 adva
.va_mask
= AT_CTIME
|AT_SEQ
;
4359 if (VOP_GETATTR(dvp
, &adva
, 0, cs
->cr
, NULL
)) {
4360 adva
.va_ctime
= bdva
.va_ctime
;
4364 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.after
, adva
.va_ctime
)
4367 * The cinfo.atomic = TRUE only if we have
4368 * non-zero va_seq's, and it has incremented by exactly one
4369 * during the VOP_REMOVE/RMDIR and it didn't change during
4372 if (bdva
.va_seq
&& idva
.va_seq
&& adva
.va_seq
&&
4373 idva
.va_seq
== (bdva
.va_seq
+ 1) && idva
.va_seq
== adva
.va_seq
)
4374 resp
->cinfo
.atomic
= TRUE
;
4376 resp
->cinfo
.atomic
= FALSE
;
4378 *cs
->statusp
= resp
->status
= NFS4_OK
;
4381 DTRACE_NFSV4_2(op__remove__done
, struct compound_state
*, cs
,
4382 REMOVE4res
*, resp
);
4386 * rename: args: SAVED_FH: from directory, CURRENT_FH: target directory,
4387 * oldname and newname.
4388 * res: status. If success - CURRENT_FH unchanged, return change_info
4389 * for both from and target directories.
4393 rfs4_op_rename(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
4394 struct compound_state
*cs
)
4396 RENAME4args
*args
= &argop
->nfs_argop4_u
.oprename
;
4397 RENAME4res
*resp
= &resop
->nfs_resop4_u
.oprename
;
4401 vnode_t
*srcvp
, *targvp
;
4402 struct vattr obdva
, oidva
, oadva
;
4403 struct vattr nbdva
, nidva
, nadva
;
4406 rfs4_file_t
*fp
, *sfp
;
4407 int in_crit_src
, in_crit_targ
;
4408 int fp_rele_grant_hold
, sfp_rele_grant_hold
;
4410 struct sockaddr
*ca
;
4411 char *converted_onm
= NULL
;
4412 char *converted_nnm
= NULL
;
4415 DTRACE_NFSV4_2(op__rename__start
, struct compound_state
*, cs
,
4416 RENAME4args
*, args
);
4419 srcvp
= targvp
= NULL
;
4420 in_crit_src
= in_crit_targ
= 0;
4421 fp_rele_grant_hold
= sfp_rele_grant_hold
= 0;
4423 /* CURRENT_FH: target directory */
4426 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
4430 /* SAVED_FH: from directory */
4431 odvp
= cs
->saved_vp
;
4433 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
4437 if (cs
->access
== CS_ACCESS_DENIED
) {
4438 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4443 * If there is an unshared filesystem mounted on this vnode,
4444 * do not allow to rename objects in this directory.
4446 if (vn_ismntpt(odvp
)) {
4447 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4452 * If there is an unshared filesystem mounted on this vnode,
4453 * do not allow to rename to this directory.
4455 if (vn_ismntpt(ndvp
)) {
4456 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4460 if (odvp
->v_type
!= VDIR
|| ndvp
->v_type
!= VDIR
) {
4461 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
4465 if (cs
->saved_exi
!= cs
->exi
) {
4466 *cs
->statusp
= resp
->status
= NFS4ERR_XDEV
;
4470 status
= utf8_dir_verify(&args
->oldname
);
4471 if (status
!= NFS4_OK
) {
4472 *cs
->statusp
= resp
->status
= status
;
4476 status
= utf8_dir_verify(&args
->newname
);
4477 if (status
!= NFS4_OK
) {
4478 *cs
->statusp
= resp
->status
= status
;
4482 onm
= utf8_to_fn(&args
->oldname
, &olen
, NULL
);
4484 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4487 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
4488 nlen
= MAXPATHLEN
+ 1;
4489 converted_onm
= nfscmd_convname(ca
, cs
->exi
, onm
, NFSCMD_CONV_INBOUND
,
4492 if (converted_onm
== NULL
) {
4493 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4494 kmem_free(onm
, olen
);
4498 nnm
= utf8_to_fn(&args
->newname
, &nlen
, NULL
);
4500 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4501 if (onm
!= converted_onm
)
4502 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4503 kmem_free(onm
, olen
);
4506 converted_nnm
= nfscmd_convname(ca
, cs
->exi
, nnm
, NFSCMD_CONV_INBOUND
,
4509 if (converted_nnm
== NULL
) {
4510 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4511 kmem_free(nnm
, nlen
);
4513 if (onm
!= converted_onm
)
4514 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4515 kmem_free(onm
, olen
);
4520 if (olen
> MAXNAMELEN
|| nlen
> MAXNAMELEN
) {
4521 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
4522 kmem_free(onm
, olen
);
4523 kmem_free(nnm
, nlen
);
4528 if (rdonly4(cs
->exi
, cs
->vp
, req
)) {
4529 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
4530 if (onm
!= converted_onm
)
4531 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4532 kmem_free(onm
, olen
);
4533 if (nnm
!= converted_nnm
)
4534 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4535 kmem_free(nnm
, nlen
);
4539 /* check label of the target dir */
4540 if (is_system_labeled()) {
4541 ASSERT(req
->rq_label
!= NULL
);
4542 clabel
= req
->rq_label
;
4543 DTRACE_PROBE2(tx__rfs4__log__info__oprename__clabel
, char *,
4544 "got client label from request(1)",
4545 struct svc_req
*, req
);
4546 if (!blequal(&l_admin_low
->tsl_label
, clabel
)) {
4547 if (!do_rfs_label_check(clabel
, ndvp
,
4548 EQUALITY_CHECK
, cs
->exi
)) {
4549 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4556 * Is the source a file and have a delegation?
4557 * We don't need to acquire va_seq before these lookups, if
4558 * it causes an update, cinfo.before will not match, which will
4559 * trigger a cache flush even if atomic is TRUE.
4561 if (sfp
= rfs4_lookup_and_findfile(odvp
, converted_onm
, &srcvp
,
4563 if (rfs4_check_delegated_byfp(FWRITE
, sfp
, TRUE
, TRUE
, TRUE
,
4565 *cs
->statusp
= resp
->status
= NFS4ERR_DELAY
;
4570 if (srcvp
== NULL
) {
4571 *cs
->statusp
= resp
->status
= puterrno4(error
);
4572 if (onm
!= converted_onm
)
4573 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4574 kmem_free(onm
, olen
);
4575 if (nnm
!= converted_nnm
)
4576 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4577 kmem_free(nnm
, nlen
);
4581 sfp_rele_grant_hold
= 1;
4583 /* Does the destination exist and a file and have a delegation? */
4584 if (fp
= rfs4_lookup_and_findfile(ndvp
, converted_nnm
, &targvp
,
4586 if (rfs4_check_delegated_byfp(FWRITE
, fp
, TRUE
, TRUE
, TRUE
,
4588 *cs
->statusp
= resp
->status
= NFS4ERR_DELAY
;
4592 fp_rele_grant_hold
= 1;
4595 /* Check for NBMAND lock on both source and target */
4596 if (nbl_need_check(srcvp
)) {
4597 nbl_start_crit(srcvp
, RW_READER
);
4599 if (nbl_conflict(srcvp
, NBL_RENAME
, 0, 0, 0, NULL
)) {
4600 *cs
->statusp
= resp
->status
= NFS4ERR_FILE_OPEN
;
4605 if (targvp
&& nbl_need_check(targvp
)) {
4606 nbl_start_crit(targvp
, RW_READER
);
4608 if (nbl_conflict(targvp
, NBL_REMOVE
, 0, 0, 0, NULL
)) {
4609 *cs
->statusp
= resp
->status
= NFS4ERR_FILE_OPEN
;
4614 /* Get source "before" change value */
4615 obdva
.va_mask
= AT_CTIME
|AT_SEQ
;
4616 error
= VOP_GETATTR(odvp
, &obdva
, 0, cs
->cr
, NULL
);
4618 nbdva
.va_mask
= AT_CTIME
|AT_SEQ
;
4619 error
= VOP_GETATTR(ndvp
, &nbdva
, 0, cs
->cr
, NULL
);
4622 *cs
->statusp
= resp
->status
= puterrno4(error
);
4626 NFS4_SET_FATTR4_CHANGE(resp
->source_cinfo
.before
, obdva
.va_ctime
)
4627 NFS4_SET_FATTR4_CHANGE(resp
->target_cinfo
.before
, nbdva
.va_ctime
)
4629 if ((error
= VOP_RENAME(odvp
, converted_onm
, ndvp
, converted_nnm
,
4630 cs
->cr
, NULL
, 0)) == 0 && fp
!= NULL
) {
4634 rfs4_dbe_lock(fp
->rf_dbe
);
4638 rfs4_dbe_unlock(fp
->rf_dbe
);
4641 va
.va_mask
= AT_NLINK
;
4642 if (!VOP_GETATTR(tvp
, &va
, 0, cs
->cr
, NULL
) &&
4644 /* The file is gone and so should the state */
4646 nbl_end_crit(targvp
);
4649 rfs4_close_all_state(fp
);
4655 vn_renamepath(ndvp
, srcvp
, nnm
, nlen
- 1);
4658 nbl_end_crit(srcvp
);
4662 nbl_end_crit(targvp
);
4667 rfs4_clear_dont_grant(sfp
);
4668 rfs4_file_rele(sfp
);
4671 rfs4_clear_dont_grant(fp
);
4675 if (converted_onm
!= onm
)
4676 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4677 kmem_free(onm
, olen
);
4678 if (converted_nnm
!= nnm
)
4679 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4680 kmem_free(nnm
, nlen
);
4683 * Get the initial "after" sequence number, if it fails, set to zero
4685 oidva
.va_mask
= AT_SEQ
;
4686 if (VOP_GETATTR(odvp
, &oidva
, 0, cs
->cr
, NULL
))
4689 nidva
.va_mask
= AT_SEQ
;
4690 if (VOP_GETATTR(ndvp
, &nidva
, 0, cs
->cr
, NULL
))
4694 * Force modified data and metadata out to stable storage.
4696 (void) VOP_FSYNC(odvp
, 0, cs
->cr
, NULL
);
4697 (void) VOP_FSYNC(ndvp
, 0, cs
->cr
, NULL
);
4700 *cs
->statusp
= resp
->status
= puterrno4(error
);
4705 * Get "after" change values, if it fails, simply return the
4708 oadva
.va_mask
= AT_CTIME
|AT_SEQ
;
4709 if (VOP_GETATTR(odvp
, &oadva
, 0, cs
->cr
, NULL
)) {
4710 oadva
.va_ctime
= obdva
.va_ctime
;
4714 nadva
.va_mask
= AT_CTIME
|AT_SEQ
;
4715 if (VOP_GETATTR(odvp
, &nadva
, 0, cs
->cr
, NULL
)) {
4716 nadva
.va_ctime
= nbdva
.va_ctime
;
4720 NFS4_SET_FATTR4_CHANGE(resp
->source_cinfo
.after
, oadva
.va_ctime
)
4721 NFS4_SET_FATTR4_CHANGE(resp
->target_cinfo
.after
, nadva
.va_ctime
)
4724 * The cinfo.atomic = TRUE only if we have
4725 * non-zero va_seq's, and it has incremented by exactly one
4726 * during the VOP_RENAME and it didn't change during the VOP_FSYNC.
4728 if (obdva
.va_seq
&& oidva
.va_seq
&& oadva
.va_seq
&&
4729 oidva
.va_seq
== (obdva
.va_seq
+ 1) && oidva
.va_seq
== oadva
.va_seq
)
4730 resp
->source_cinfo
.atomic
= TRUE
;
4732 resp
->source_cinfo
.atomic
= FALSE
;
4734 if (nbdva
.va_seq
&& nidva
.va_seq
&& nadva
.va_seq
&&
4735 nidva
.va_seq
== (nbdva
.va_seq
+ 1) && nidva
.va_seq
== nadva
.va_seq
)
4736 resp
->target_cinfo
.atomic
= TRUE
;
4738 resp
->target_cinfo
.atomic
= FALSE
;
4740 #ifdef VOLATILE_FH_TEST
4742 extern void add_volrnm_fh(struct exportinfo
*, vnode_t
*);
4745 * Add the renamed file handle to the volatile rename list
4747 if (cs
->exi
->exi_export
.ex_flags
& EX_VOLRNM
) {
4748 /* file handles may expire on rename */
4751 nnm
= utf8_to_fn(&args
->newname
, &nlen
, NULL
);
4753 * Already know that nnm will be a valid string
4755 error
= VOP_LOOKUP(ndvp
, nnm
, &vp
, NULL
, 0, NULL
, cs
->cr
,
4757 kmem_free(nnm
, nlen
);
4759 add_volrnm_fh(cs
->exi
, vp
);
4764 #endif /* VOLATILE_FH_TEST */
4766 *cs
->statusp
= resp
->status
= NFS4_OK
;
4768 DTRACE_NFSV4_2(op__rename__done
, struct compound_state
*, cs
,
4769 RENAME4res
*, resp
);
4773 if (onm
!= converted_onm
)
4774 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4776 kmem_free(onm
, olen
);
4777 if (nnm
!= converted_nnm
)
4778 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4780 kmem_free(nnm
, nlen
);
4782 if (in_crit_src
) nbl_end_crit(srcvp
);
4783 if (in_crit_targ
) nbl_end_crit(targvp
);
4784 if (targvp
) VN_RELE(targvp
);
4785 if (srcvp
) VN_RELE(srcvp
);
4787 if (sfp_rele_grant_hold
) rfs4_clear_dont_grant(sfp
);
4788 rfs4_file_rele(sfp
);
4791 if (fp_rele_grant_hold
) rfs4_clear_dont_grant(fp
);
4795 DTRACE_NFSV4_2(op__rename__done
, struct compound_state
*, cs
,
4796 RENAME4res
*, resp
);
4801 rfs4_op_renew(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
4802 struct compound_state
*cs
)
4804 RENEW4args
*args
= &argop
->nfs_argop4_u
.oprenew
;
4805 RENEW4res
*resp
= &resop
->nfs_resop4_u
.oprenew
;
4808 DTRACE_NFSV4_2(op__renew__start
, struct compound_state
*, cs
,
4809 RENEW4args
*, args
);
4811 if ((cp
= rfs4_findclient_by_id(args
->clientid
, FALSE
)) == NULL
) {
4812 *cs
->statusp
= resp
->status
=
4813 rfs4_check_clientid(&args
->clientid
, 0);
4817 if (rfs4_lease_expired(cp
)) {
4818 rfs4_client_rele(cp
);
4819 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
4823 rfs4_update_lease(cp
);
4825 mutex_enter(cp
->rc_cbinfo
.cb_lock
);
4826 if (cp
->rc_cbinfo
.cb_notified_of_cb_path_down
== FALSE
) {
4827 cp
->rc_cbinfo
.cb_notified_of_cb_path_down
= TRUE
;
4828 *cs
->statusp
= resp
->status
= NFS4ERR_CB_PATH_DOWN
;
4830 *cs
->statusp
= resp
->status
= NFS4_OK
;
4832 mutex_exit(cp
->rc_cbinfo
.cb_lock
);
4834 rfs4_client_rele(cp
);
4837 DTRACE_NFSV4_2(op__renew__done
, struct compound_state
*, cs
,
4843 rfs4_op_restorefh(nfs_argop4
*args
, nfs_resop4
*resop
, struct svc_req
*req
,
4844 struct compound_state
*cs
)
4846 RESTOREFH4res
*resp
= &resop
->nfs_resop4_u
.oprestorefh
;
4848 DTRACE_NFSV4_1(op__restorefh__start
, struct compound_state
*, cs
);
4850 /* No need to check cs->access - we are not accessing any object */
4851 if ((cs
->saved_vp
== NULL
) || (cs
->saved_fh
.nfs_fh4_val
== NULL
)) {
4852 *cs
->statusp
= resp
->status
= NFS4ERR_RESTOREFH
;
4855 if (cs
->vp
!= NULL
) {
4858 cs
->vp
= cs
->saved_vp
;
4859 cs
->saved_vp
= NULL
;
4860 cs
->exi
= cs
->saved_exi
;
4861 nfs_fh4_copy(&cs
->saved_fh
, &cs
->fh
);
4862 *cs
->statusp
= resp
->status
= NFS4_OK
;
4866 DTRACE_NFSV4_2(op__restorefh__done
, struct compound_state
*, cs
,
4867 RESTOREFH4res
*, resp
);
4872 rfs4_op_savefh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
4873 struct compound_state
*cs
)
4875 SAVEFH4res
*resp
= &resop
->nfs_resop4_u
.opsavefh
;
4877 DTRACE_NFSV4_1(op__savefh__start
, struct compound_state
*, cs
);
4879 /* No need to check cs->access - we are not accessing any object */
4880 if (cs
->vp
== NULL
) {
4881 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
4884 if (cs
->saved_vp
!= NULL
) {
4885 VN_RELE(cs
->saved_vp
);
4887 cs
->saved_vp
= cs
->vp
;
4888 VN_HOLD(cs
->saved_vp
);
4889 cs
->saved_exi
= cs
->exi
;
4891 * since SAVEFH is fairly rare, don't alloc space for its fh
4894 if (cs
->saved_fh
.nfs_fh4_val
== NULL
) {
4895 cs
->saved_fh
.nfs_fh4_val
= kmem_alloc(NFS4_FHSIZE
, KM_SLEEP
);
4897 nfs_fh4_copy(&cs
->fh
, &cs
->saved_fh
);
4898 *cs
->statusp
= resp
->status
= NFS4_OK
;
4901 DTRACE_NFSV4_2(op__savefh__done
, struct compound_state
*, cs
,
4902 SAVEFH4res
*, resp
);
4906 * rfs4_verify_attr is called when nfsv4 Setattr failed, but we wish to
4907 * return the bitmap of attrs that were set successfully. It is also
4908 * called by Verify/Nverify to test the vattr/vfsstat attrs. It should
4909 * always be called only after rfs4_do_set_attrs().
4911 * Verify that the attributes are same as the expected ones. sargp->vap
4912 * and sargp->sbp contain the input attributes as translated from fattr4.
4914 * This function verifies only the attrs that correspond to a vattr or
4915 * vfsstat struct. That is because of the extra step needed to get the
4916 * corresponding system structs. Other attributes have already been set or
4917 * verified by do_rfs4_set_attrs.
4919 * Return 0 if all attrs match, -1 if some don't, error if error processing.
4922 rfs4_verify_attr(struct nfs4_svgetit_arg
*sargp
,
4923 bitmap4
*resp
, struct nfs4_ntov_table
*ntovp
)
4925 int error
, ret_error
= 0;
4927 uint_t sva_mask
= sargp
->vap
->va_mask
;
4929 union nfs4_attr_u
*na
;
4931 bool_t getsb
= ntovp
->vfsstat
;
4933 if (sva_mask
!= 0) {
4935 * Okay to overwrite sargp->vap because we verify based
4936 * on the incoming values.
4938 ret_error
= VOP_GETATTR(sargp
->cs
->vp
, sargp
->vap
, 0,
4939 sargp
->cs
->cr
, NULL
);
4944 * Must return bitmap of successful attrs
4946 sva_mask
= 0; /* to prevent checking vap later */
4949 * Some file systems clobber va_mask. it is probably
4950 * wrong of them to do so, nonethless we practice
4952 * See bug id 4276830.
4954 sargp
->vap
->va_mask
= sva_mask
;
4960 * Now get the superblock and loop on the bitmap, as there is
4961 * no simple way of translating from superblock to bitmap4.
4963 ret_error
= VFS_STATVFS(sargp
->cs
->vp
->v_vfsp
, sargp
->sbp
);
4972 * Now loop and verify each attribute which getattr returned
4973 * whether it's the same as the input.
4975 if (resp
== NULL
&& !getsb
&& (sva_mask
== 0))
4981 for (i
= 0; i
< ntovp
->attrcnt
; i
++, na
++, amap
++) {
4983 ASSERT(nfs4_ntov_map
[k
].nval
== k
);
4984 vbit
= nfs4_ntov_map
[k
].vbit
;
4987 * If vattr attribute but VOP_GETATTR failed, or it's
4988 * superblock attribute but VFS_STATVFS failed, skip
4991 if ((vbit
& sva_mask
) == 0)
4993 } else if (!(getsb
&& nfs4_ntov_map
[k
].vfsstat
)) {
4996 error
= (*nfs4_ntov_map
[k
].sv_getit
)(NFS4ATTR_VERIT
, sargp
, na
);
4999 ret_error
= -1; /* not all match */
5000 else /* update response bitmap */
5001 *resp
|= nfs4_ntov_map
[k
].fbit
;
5005 ret_error
= -1; /* not all match */
5014 * Decode the attribute to be set/verified. If the attr requires a sys op
5015 * (VOP_GETATTR, VFS_VFSSTAT), and the request is to verify, then don't
5016 * call the sv_getit function for it, because the sys op hasn't yet been done.
5017 * Return 0 for success, error code if failed.
5019 * Note: the decoded arg is not freed here but in nfs4_ntov_table_free.
5022 decode_fattr4_attr(nfs4_attr_cmd_t cmd
, struct nfs4_svgetit_arg
*sargp
,
5023 int k
, XDR
*xdrp
, bitmap4
*resp_bval
, union nfs4_attr_u
*nap
)
5028 sargp
->vap
->va_mask
|= nfs4_ntov_map
[k
].vbit
;
5030 if ((*nfs4_ntov_map
[k
].xfunc
)(xdrp
, nap
)) {
5031 set_later
= nfs4_ntov_map
[k
].vbit
|| nfs4_ntov_map
[k
].vfsstat
;
5033 * don't verify yet if a vattr or sb dependent attr,
5034 * because we don't have their sys values yet.
5035 * Will be done later.
5037 if (! (set_later
&& (cmd
== NFS4ATTR_VERIT
))) {
5039 * ACLs are a special case, since setting the MODE
5040 * conflicts with setting the ACL. We delay setting
5041 * the ACL until all other attributes have been set.
5042 * The ACL gets set in do_rfs4_op_setattr().
5044 if (nfs4_ntov_map
[k
].fbit
!= FATTR4_ACL_MASK
) {
5045 error
= (*nfs4_ntov_map
[k
].sv_getit
)(cmd
,
5048 xdr_free(nfs4_ntov_map
[k
].xfunc
,
5055 cmn_err(CE_NOTE
, "decode_fattr4_attr: error "
5056 "decoding attribute %d\n", k
);
5060 if (!error
&& resp_bval
&& !set_later
) {
5061 *resp_bval
|= nfs4_ntov_map
[k
].fbit
;
5068 * Set vattr based on incoming fattr4 attrs - used by setattr.
5069 * Set response mask. Ignore any values that are not writable vattr attrs.
5072 do_rfs4_set_attrs(bitmap4
*resp
, fattr4
*fattrp
, struct compound_state
*cs
,
5073 struct nfs4_svgetit_arg
*sargp
, struct nfs4_ntov_table
*ntovp
,
5074 nfs4_attr_cmd_t cmd
)
5078 char *attrs
= fattrp
->attrlist4
;
5079 uint32_t attrslen
= fattrp
->attrlist4_len
;
5081 nfsstat4 status
= NFS4_OK
;
5082 vnode_t
*vp
= cs
->vp
;
5083 union nfs4_attr_u
*na
;
5088 * Make sure that maximum attribute number can be expressed as an
5091 ASSERT(NFS4_MAXNUM_ATTRS
<= (UINT8_MAX
+ 1));
5097 return (NFS4ERR_NOFILEHANDLE
);
5099 if (cs
->access
== CS_ACCESS_DENIED
) {
5102 return (NFS4ERR_ACCESS
);
5107 sargp
->flag
= 0; /* may be set later */
5108 sargp
->vap
->va_mask
= 0;
5109 sargp
->rdattr_error
= NFS4_OK
;
5110 sargp
->rdattr_error_req
= FALSE
;
5111 /* sargp->sbp is set by the caller */
5113 xdrmem_create(&xdr
, attrs
, attrslen
, XDR_DECODE
);
5119 * The following loop iterates on the nfs4_ntov_map checking
5120 * if the fbit is set in the requested bitmap.
5121 * If set then we process the arguments using the
5122 * rfs4_fattr4 conversion functions to populate the setattr
5123 * vattr and va_mask. Any settable attrs that are not using vattr
5124 * will be set in this loop.
5126 for (i
= 0; i
< nfs4_ntov_map_size
; i
++) {
5127 if (!(fattrp
->attrmask
& nfs4_ntov_map
[i
].fbit
)) {
5131 * If setattr, must be a writable attr.
5132 * If verify/nverify, must be a readable attr.
5134 if ((error
= (*nfs4_ntov_map
[i
].sv_getit
)(
5135 NFS4ATTR_SUPPORTED
, sargp
, NULL
)) != 0) {
5137 * Client tries to set/verify an
5138 * unsupported attribute, tries to set
5139 * a read only attr or verify a write
5145 * Decode the attribute to set/verify
5147 error
= decode_fattr4_attr(cmd
, sargp
, nfs4_ntov_map
[i
].nval
,
5148 &xdr
, resp
? resp
: NULL
, na
);
5151 *amap
++ = (uint8_t)nfs4_ntov_map
[i
].nval
;
5154 if (nfs4_ntov_map
[i
].vfsstat
)
5155 ntovp
->vfsstat
= TRUE
;
5159 status
= (error
== ENOTSUP
? NFS4ERR_ATTRNOTSUPP
:
5161 /* xdrmem_destroy(&xdrs); */ /* NO-OP */
5166 do_rfs4_op_setattr(bitmap4
*resp
, fattr4
*fattrp
, struct compound_state
*cs
,
5170 struct nfs4_svgetit_arg sarg
;
5173 nfsstat4 status
= NFS4_OK
;
5174 cred_t
*cr
= cs
->cr
;
5175 vnode_t
*vp
= cs
->vp
;
5176 struct nfs4_ntov_table ntov
;
5177 struct statvfs64 sb
;
5181 uint_t saved_mask
= 0;
5182 caller_context_t ct
;
5186 sarg
.is_referral
= B_FALSE
;
5187 nfs4_ntov_table_init(&ntov
);
5188 status
= do_rfs4_set_attrs(resp
, fattrp
, cs
, &sarg
, &ntov
,
5190 if (status
!= NFS4_OK
) {
5196 if ((sarg
.vap
->va_mask
== 0) &&
5197 (! (fattrp
->attrmask
& FATTR4_ACL_MASK
))) {
5199 * no further work to be done
5205 * If we got a request to set the ACL and the MODE, only
5206 * allow changing VSUID, VSGID, and VSVTX. Attempting
5207 * to change any other bits, along with setting an ACL,
5208 * gives NFS4ERR_INVAL.
5210 if ((fattrp
->attrmask
& FATTR4_ACL_MASK
) &&
5211 (fattrp
->attrmask
& FATTR4_MODE_MASK
)) {
5214 va
.va_mask
= AT_MODE
;
5215 error
= VOP_GETATTR(vp
, &va
, 0, cs
->cr
, NULL
);
5217 status
= puterrno4(error
);
5220 if ((sarg
.vap
->va_mode
^ va
.va_mode
) &
5221 ~(VSUID
| VSGID
| VSVTX
)) {
5222 status
= NFS4ERR_INVAL
;
5227 /* Check stateid only if size has been set */
5228 if (sarg
.vap
->va_mask
& AT_SIZE
) {
5229 trunc
= (sarg
.vap
->va_size
== 0);
5230 status
= rfs4_check_stateid(FWRITE
, cs
->vp
, stateid
,
5231 trunc
, &cs
->deleg
, sarg
.vap
->va_mask
& AT_SIZE
, &ct
);
5232 if (status
!= NFS4_OK
)
5237 ct
.cc_caller_id
= nfs4_srv_caller_id
;
5238 ct
.cc_flags
= CC_DONTBLOCK
;
5241 /* XXX start of possible race with delegations */
5244 * We need to specially handle size changes because it is
5245 * possible for the client to create a file with read-only
5246 * modes, but with the file opened for writing. If the client
5247 * then tries to set the file size, e.g. ftruncate(3C),
5248 * fcntl(F_FREESP), the normal access checking done in
5249 * VOP_SETATTR would prevent the client from doing it even though
5250 * it should be allowed to do so. To get around this, we do the
5251 * access checking for ourselves and use VOP_SPACE which doesn't
5252 * do the access checking.
5253 * Also the client should not be allowed to change the file
5254 * size if there is a conflicting non-blocking mandatory lock in
5255 * the region of the change.
5257 if (vp
->v_type
== VREG
&& (sarg
.vap
->va_mask
& AT_SIZE
)) {
5262 * ufs_setattr clears AT_SIZE from vap->va_mask, but
5263 * before returning, sarg.vap->va_mask is used to
5264 * generate the setattr reply bitmap. We also clear
5265 * AT_SIZE below before calling VOP_SPACE. For both
5266 * of these cases, the va_mask needs to be saved here
5267 * and restored after calling VOP_SETATTR.
5269 saved_mask
= sarg
.vap
->va_mask
;
5272 * Check any possible conflict due to NBMAND locks.
5273 * Get into critical region before VOP_GETATTR, so the
5274 * size attribute is valid when checking conflicts.
5276 if (nbl_need_check(vp
)) {
5277 nbl_start_crit(vp
, RW_READER
);
5281 bva
.va_mask
= AT_UID
|AT_SIZE
;
5282 if (error
= VOP_GETATTR(vp
, &bva
, 0, cr
, &ct
)) {
5283 status
= puterrno4(error
);
5288 if (sarg
.vap
->va_size
< bva
.va_size
) {
5289 offset
= sarg
.vap
->va_size
;
5290 length
= bva
.va_size
- sarg
.vap
->va_size
;
5292 offset
= bva
.va_size
;
5293 length
= sarg
.vap
->va_size
- bva
.va_size
;
5295 if (nbl_conflict(vp
, NBL_WRITE
, offset
, length
, 0,
5297 status
= NFS4ERR_LOCKED
;
5302 if (crgetuid(cr
) == bva
.va_uid
) {
5303 sarg
.vap
->va_mask
&= ~AT_SIZE
;
5304 bf
.l_type
= F_WRLCK
;
5306 bf
.l_start
= (off64_t
)sarg
.vap
->va_size
;
5310 error
= VOP_SPACE(vp
, F_FREESP
, &bf
, FWRITE
,
5311 (offset_t
)sarg
.vap
->va_size
, cr
, &ct
);
5315 if (!error
&& sarg
.vap
->va_mask
!= 0)
5316 error
= VOP_SETATTR(vp
, sarg
.vap
, sarg
.flag
, cr
, &ct
);
5318 /* restore va_mask -- ufs_setattr clears AT_SIZE */
5319 if (saved_mask
& AT_SIZE
)
5320 sarg
.vap
->va_mask
|= AT_SIZE
;
5323 * If an ACL was being set, it has been delayed until now,
5324 * in order to set the mode (via the VOP_SETATTR() above) first.
5326 if ((! error
) && (fattrp
->attrmask
& FATTR4_ACL_MASK
)) {
5329 for (i
= 0; i
< NFS4_MAXNUM_ATTRS
; i
++)
5330 if (ntov
.amap
[i
] == FATTR4_ACL
)
5332 if (i
< NFS4_MAXNUM_ATTRS
) {
5333 error
= (*nfs4_ntov_map
[FATTR4_ACL
].sv_getit
)(
5334 NFS4ATTR_SETIT
, &sarg
, &ntov
.na
[i
]);
5336 *resp
|= FATTR4_ACL_MASK
;
5337 } else if (error
== ENOTSUP
) {
5338 (void) rfs4_verify_attr(&sarg
, resp
, &ntov
);
5339 status
= NFS4ERR_ATTRNOTSUPP
;
5343 NFS4_DEBUG(rfs4_debug
,
5344 (CE_NOTE
, "do_rfs4_op_setattr: "
5345 "unable to find ACL in fattr4"));
5351 /* check if a monitor detected a delegation conflict */
5352 if (error
== EAGAIN
&& (ct
.cc_flags
& CC_WOULDBLOCK
))
5353 status
= NFS4ERR_DELAY
;
5355 status
= puterrno4(error
);
5358 * Set the response bitmap when setattr failed.
5359 * If VOP_SETATTR partially succeeded, test by doing a
5360 * VOP_GETATTR on the object and comparing the data
5361 * to the setattr arguments.
5363 (void) rfs4_verify_attr(&sarg
, resp
, &ntov
);
5366 * Force modified metadata out to stable storage.
5368 (void) VOP_FSYNC(vp
, FNODSYNC
, cr
, &ct
);
5370 * Set response bitmap
5372 nfs4_vmask_to_nmask_set(sarg
.vap
->va_mask
, resp
);
5375 /* Return early and already have a NFSv4 error */
5378 * Except for nfs4_vmask_to_nmask_set(), vattr --> fattr
5379 * conversion sets both readable and writeable NFS4 attrs
5380 * for AT_MTIME and AT_ATIME. The line below masks out
5381 * unrequested attrs from the setattr result bitmap. This
5382 * is placed after the done: label to catch the ATTRNOTSUP
5385 *resp
&= fattrp
->attrmask
;
5390 nfs4_ntov_table_free(&ntov
, &sarg
);
5397 rfs4_op_setattr(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5398 struct compound_state
*cs
)
5400 SETATTR4args
*args
= &argop
->nfs_argop4_u
.opsetattr
;
5401 SETATTR4res
*resp
= &resop
->nfs_resop4_u
.opsetattr
;
5404 DTRACE_NFSV4_2(op__setattr__start
, struct compound_state
*, cs
,
5405 SETATTR4args
*, args
);
5407 if (cs
->vp
== NULL
) {
5408 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5413 * If there is an unshared filesystem mounted on this vnode,
5414 * do not allow to setattr on this vnode.
5416 if (vn_ismntpt(cs
->vp
)) {
5417 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
5423 if (rdonly4(cs
->exi
, cs
->vp
, req
)) {
5424 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
5428 /* check label before setting attributes */
5429 if (is_system_labeled()) {
5430 ASSERT(req
->rq_label
!= NULL
);
5431 clabel
= req
->rq_label
;
5432 DTRACE_PROBE2(tx__rfs4__log__info__opsetattr__clabel
, char *,
5433 "got client label from request(1)",
5434 struct svc_req
*, req
);
5435 if (!blequal(&l_admin_low
->tsl_label
, clabel
)) {
5436 if (!do_rfs_label_check(clabel
, cs
->vp
,
5437 EQUALITY_CHECK
, cs
->exi
)) {
5438 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
5444 *cs
->statusp
= resp
->status
=
5445 do_rfs4_op_setattr(&resp
->attrsset
, &args
->obj_attributes
, cs
,
5449 DTRACE_NFSV4_2(op__setattr__done
, struct compound_state
*, cs
,
5450 SETATTR4res
*, resp
);
5455 rfs4_op_verify(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5456 struct compound_state
*cs
)
5459 * verify and nverify are exactly the same, except that nverify
5460 * succeeds when some argument changed, and verify succeeds when
5461 * when none changed.
5464 VERIFY4args
*args
= &argop
->nfs_argop4_u
.opverify
;
5465 VERIFY4res
*resp
= &resop
->nfs_resop4_u
.opverify
;
5468 struct nfs4_svgetit_arg sarg
;
5469 struct statvfs64 sb
;
5470 struct nfs4_ntov_table ntov
;
5472 DTRACE_NFSV4_2(op__verify__start
, struct compound_state
*, cs
,
5473 VERIFY4args
*, args
);
5475 if (cs
->vp
== NULL
) {
5476 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5481 sarg
.is_referral
= B_FALSE
;
5482 nfs4_ntov_table_init(&ntov
);
5483 resp
->status
= do_rfs4_set_attrs(NULL
, &args
->obj_attributes
, cs
,
5484 &sarg
, &ntov
, NFS4ATTR_VERIT
);
5485 if (resp
->status
!= NFS4_OK
) {
5487 * do_rfs4_set_attrs will try to verify systemwide attrs,
5488 * so could return -1 for "no match".
5490 if (resp
->status
== -1)
5491 resp
->status
= NFS4ERR_NOT_SAME
;
5494 error
= rfs4_verify_attr(&sarg
, NULL
, &ntov
);
5497 resp
->status
= NFS4_OK
;
5500 resp
->status
= NFS4ERR_NOT_SAME
;
5503 resp
->status
= puterrno4(error
);
5507 *cs
->statusp
= resp
->status
;
5508 nfs4_ntov_table_free(&ntov
, &sarg
);
5510 DTRACE_NFSV4_2(op__verify__done
, struct compound_state
*, cs
,
5511 VERIFY4res
*, resp
);
5516 rfs4_op_nverify(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5517 struct compound_state
*cs
)
5520 * verify and nverify are exactly the same, except that nverify
5521 * succeeds when some argument changed, and verify succeeds when
5522 * when none changed.
5525 NVERIFY4args
*args
= &argop
->nfs_argop4_u
.opnverify
;
5526 NVERIFY4res
*resp
= &resop
->nfs_resop4_u
.opnverify
;
5529 struct nfs4_svgetit_arg sarg
;
5530 struct statvfs64 sb
;
5531 struct nfs4_ntov_table ntov
;
5533 DTRACE_NFSV4_2(op__nverify__start
, struct compound_state
*, cs
,
5534 NVERIFY4args
*, args
);
5536 if (cs
->vp
== NULL
) {
5537 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5538 DTRACE_NFSV4_2(op__nverify__done
, struct compound_state
*, cs
,
5539 NVERIFY4res
*, resp
);
5543 sarg
.is_referral
= B_FALSE
;
5544 nfs4_ntov_table_init(&ntov
);
5545 resp
->status
= do_rfs4_set_attrs(NULL
, &args
->obj_attributes
, cs
,
5546 &sarg
, &ntov
, NFS4ATTR_VERIT
);
5547 if (resp
->status
!= NFS4_OK
) {
5549 * do_rfs4_set_attrs will try to verify systemwide attrs,
5550 * so could return -1 for "no match".
5552 if (resp
->status
== -1)
5553 resp
->status
= NFS4_OK
;
5556 error
= rfs4_verify_attr(&sarg
, NULL
, &ntov
);
5559 resp
->status
= NFS4ERR_SAME
;
5562 resp
->status
= NFS4_OK
;
5565 resp
->status
= puterrno4(error
);
5569 *cs
->statusp
= resp
->status
;
5570 nfs4_ntov_table_free(&ntov
, &sarg
);
5572 DTRACE_NFSV4_2(op__nverify__done
, struct compound_state
*, cs
,
5573 NVERIFY4res
*, resp
);
5577 * XXX - This should live in an NFS header file.
5579 #define MAX_IOVECS 12
5583 rfs4_op_write(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5584 struct compound_state
*cs
)
5586 WRITE4args
*args
= &argop
->nfs_argop4_u
.opwrite
;
5587 WRITE4res
*resp
= &resop
->nfs_resop4_u
.opwrite
;
5593 struct iovec iov
[MAX_IOVECS
];
5597 cred_t
*savecred
, *cr
;
5598 bool_t
*deleg
= &cs
->deleg
;
5601 caller_context_t ct
;
5603 DTRACE_NFSV4_2(op__write__start
, struct compound_state
*, cs
,
5604 WRITE4args
*, args
);
5608 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5611 if (cs
->access
== CS_ACCESS_DENIED
) {
5612 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
5618 if ((stat
= rfs4_check_stateid(FWRITE
, vp
, &args
->stateid
, FALSE
,
5619 deleg
, TRUE
, &ct
)) != NFS4_OK
) {
5620 *cs
->statusp
= resp
->status
= stat
;
5625 * We have to enter the critical region before calling VOP_RWLOCK
5626 * to avoid a deadlock with ufs.
5628 if (nbl_need_check(vp
)) {
5629 nbl_start_crit(vp
, RW_READER
);
5631 if (nbl_conflict(vp
, NBL_WRITE
,
5632 args
->offset
, args
->data_len
, 0, &ct
)) {
5633 *cs
->statusp
= resp
->status
= NFS4ERR_LOCKED
;
5638 bva
.va_mask
= AT_MODE
| AT_UID
;
5639 error
= VOP_GETATTR(vp
, &bva
, 0, cr
, &ct
);
5642 * If we can't get the attributes, then we can't do the
5643 * right access checking. So, we'll fail the request.
5646 *cs
->statusp
= resp
->status
= puterrno4(error
);
5650 if (rdonly4(cs
->exi
, cs
->vp
, req
)) {
5651 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
5655 if (vp
->v_type
!= VREG
) {
5656 *cs
->statusp
= resp
->status
=
5657 ((vp
->v_type
== VDIR
) ? NFS4ERR_ISDIR
: NFS4ERR_INVAL
);
5661 if (crgetuid(cr
) != bva
.va_uid
&&
5662 (error
= VOP_ACCESS(vp
, VWRITE
, 0, cr
, &ct
))) {
5663 *cs
->statusp
= resp
->status
= puterrno4(error
);
5667 if (MANDLOCK(vp
, bva
.va_mode
)) {
5668 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
5672 if (args
->data_len
== 0) {
5673 *cs
->statusp
= resp
->status
= NFS4_OK
;
5675 resp
->committed
= args
->stable
;
5676 resp
->writeverf
= Write4verf
;
5680 if (args
->mblk
!= NULL
) {
5682 uint_t bytes
, round_len
;
5686 round_len
= roundup(args
->data_len
, BYTES_PER_XDR_UNIT
);
5687 for (m
= args
->mblk
;
5688 m
!= NULL
&& bytes
< round_len
;
5694 /* should have ended on an mblk boundary */
5695 if (bytes
!= round_len
) {
5696 printf("bytes=0x%x, round_len=0x%x, req len=0x%x\n",
5697 bytes
, round_len
, args
->data_len
);
5698 printf("args=%p, args->mblk=%p, m=%p", (void *)args
,
5699 (void *)args
->mblk
, (void *)m
);
5700 ASSERT(bytes
== round_len
);
5703 if (iovcnt
<= MAX_IOVECS
) {
5706 iovp
= kmem_alloc(sizeof (*iovp
) * iovcnt
, KM_SLEEP
);
5708 mblk_to_iov(args
->mblk
, iovcnt
, iovp
);
5709 } else if (args
->rlist
!= NULL
) {
5712 iovp
->iov_base
= (char *)((args
->rlist
)->u
.c_daddr3
);
5713 iovp
->iov_len
= args
->data_len
;
5717 iovp
->iov_base
= args
->data_val
;
5718 iovp
->iov_len
= args
->data_len
;
5722 uio
.uio_iovcnt
= iovcnt
;
5724 uio
.uio_segflg
= UIO_SYSSPACE
;
5725 uio
.uio_extflg
= UIO_COPY_DEFAULT
;
5726 uio
.uio_loffset
= args
->offset
;
5727 uio
.uio_resid
= args
->data_len
;
5728 uio
.uio_llimit
= curproc
->p_fsz_ctl
;
5729 rlimit
= uio
.uio_llimit
- args
->offset
;
5730 if (rlimit
< (u_offset_t
)uio
.uio_resid
)
5731 uio
.uio_resid
= (int)rlimit
;
5733 if (args
->stable
== UNSTABLE4
)
5735 else if (args
->stable
== FILE_SYNC4
)
5737 else if (args
->stable
== DATA_SYNC4
)
5741 kmem_free(iovp
, sizeof (*iovp
) * iovcnt
);
5742 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
5747 * We're changing creds because VM may fault and we need
5748 * the cred of the current thread to be used if quota
5749 * checking is enabled.
5751 savecred
= curthread
->t_cred
;
5752 curthread
->t_cred
= cr
;
5753 error
= do_io(FWRITE
, vp
, &uio
, ioflag
, cr
, &ct
);
5754 curthread
->t_cred
= savecred
;
5757 kmem_free(iovp
, sizeof (*iovp
) * iovcnt
);
5760 *cs
->statusp
= resp
->status
= puterrno4(error
);
5764 *cs
->statusp
= resp
->status
= NFS4_OK
;
5765 resp
->count
= args
->data_len
- uio
.uio_resid
;
5768 resp
->committed
= UNSTABLE4
;
5770 resp
->committed
= FILE_SYNC4
;
5772 resp
->writeverf
= Write4verf
;
5778 DTRACE_NFSV4_2(op__write__done
, struct compound_state
*, cs
,
5783 /* XXX put in a header file */
5784 extern int sec_svc_getcred(struct svc_req
*, cred_t
*, caddr_t
*, int *);
5787 rfs4_compound(COMPOUND4args
*args
, COMPOUND4res
*resp
, struct exportinfo
*exi
,
5788 struct svc_req
*req
, cred_t
*cr
, int *rv
)
5791 struct compound_state cs
;
5795 rfs4_init_compound_state(&cs
);
5797 * Form a reply tag by copying over the reqeuest tag.
5799 resp
->tag
.utf8string_val
=
5800 kmem_alloc(args
->tag
.utf8string_len
, KM_SLEEP
);
5801 resp
->tag
.utf8string_len
= args
->tag
.utf8string_len
;
5802 bcopy(args
->tag
.utf8string_val
, resp
->tag
.utf8string_val
,
5803 resp
->tag
.utf8string_len
);
5805 cs
.statusp
= &resp
->status
;
5808 resp
->array_len
= 0;
5810 resp
->status
= utf8_name_verify(&(resp
->tag
));
5811 if (resp
->status
!= NFS4_OK
)
5815 * XXX for now, minorversion should be zero
5817 if (args
->minorversion
!= NFS4_MINORVERSION
) {
5818 DTRACE_NFSV4_2(compound__start
, struct compound_state
*,
5819 &cs
, COMPOUND4args
*, args
);
5820 resp
->status
= NFS4ERR_MINOR_VERS_MISMATCH
;
5821 DTRACE_NFSV4_2(compound__done
, struct compound_state
*,
5822 &cs
, COMPOUND4res
*, resp
);
5826 if (args
->array_len
== 0) {
5827 resp
->status
= NFS4_OK
;
5831 ASSERT(exi
== NULL
);
5837 if (sec_svc_getcred(req
, cr
, &cs
.principal
, &cs
.nfsflavor
) == 0) {
5838 DTRACE_NFSV4_2(compound__start
, struct compound_state
*,
5839 &cs
, COMPOUND4args
*, args
);
5841 DTRACE_NFSV4_2(compound__done
, struct compound_state
*,
5842 &cs
, COMPOUND4res
*, resp
);
5843 svcerr_badcred(req
->rq_xprt
);
5848 resp
->array_len
= args
->array_len
;
5849 resp
->array
= kmem_zalloc(args
->array_len
* sizeof (nfs_resop4
),
5854 DTRACE_NFSV4_2(compound__start
, struct compound_state
*, &cs
,
5855 COMPOUND4args
*, args
);
5858 * For now, NFS4 compound processing must be protected by
5859 * exported_lock because it can access more than one exportinfo
5860 * per compound and share/unshare can now change multiple
5861 * exinfo structs. The NFS2/3 code only refs 1 exportinfo
5862 * per proc (excluding public exinfo), and exi_count design
5863 * is sufficient to protect concurrent execution of NFS2/3
5864 * ops along with unexport. This lock will be removed as
5865 * part of the NFSv4 phase 2 namespace redesign work.
5867 rw_enter(&exported_lock
, RW_READER
);
5870 * If this is the first compound we've seen, we need to start all
5871 * new instances' grace periods.
5873 if (rfs4_seen_first_compound
== 0) {
5874 rfs4_grace_start_new();
5876 * This must be set after rfs4_grace_start_new(), otherwise
5877 * another thread could proceed past here before the former
5880 rfs4_seen_first_compound
= 1;
5883 for (i
= 0; i
< args
->array_len
&& cs
.cont
; i
++) {
5888 argop
= &args
->array
[i
];
5889 resop
= &resp
->array
[i
];
5890 resop
->resop
= argop
->argop
;
5891 op
= (uint_t
)resop
->resop
;
5893 if (op
< rfsv4disp_cnt
) {
5895 * Count the individual ops here; NULL and COMPOUND
5896 * are counted in common_dispatch()
5898 rfsproccnt_v4_ptr
[op
].value
.ui64
++;
5900 NFS4_DEBUG(rfs4_debug
> 1,
5901 (CE_NOTE
, "Executing %s", rfs4_op_string
[op
]));
5902 (*rfsv4disptab
[op
].dis_proc
)(argop
, resop
, req
, &cs
);
5903 NFS4_DEBUG(rfs4_debug
> 1, (CE_NOTE
, "%s returned %d",
5904 rfs4_op_string
[op
], *cs
.statusp
));
5905 if (*cs
.statusp
!= NFS4_OK
)
5909 * This is effectively dead code since XDR code
5910 * will have already returned BADXDR if op doesn't
5911 * decode to legal value. This only done for a
5912 * day when XDR code doesn't verify v4 opcodes.
5915 rfsproccnt_v4_ptr
[OP_ILLEGAL_IDX
].value
.ui64
++;
5917 rfs4_op_illegal(argop
, resop
, req
, &cs
);
5922 * If not at last op, and if we are to stop, then
5923 * compact the results array.
5925 if ((i
+ 1) < args
->array_len
&& !cs
.cont
) {
5926 nfs_resop4
*new_res
= kmem_alloc(
5927 (i
+1) * sizeof (nfs_resop4
), KM_SLEEP
);
5929 new_res
, (i
+1) * sizeof (nfs_resop4
));
5930 kmem_free(resp
->array
,
5931 args
->array_len
* sizeof (nfs_resop4
));
5933 resp
->array_len
= i
+ 1;
5934 resp
->array
= new_res
;
5938 rw_exit(&exported_lock
);
5940 DTRACE_NFSV4_2(compound__done
, struct compound_state
*, &cs
,
5941 COMPOUND4res
*, resp
);
5946 VN_RELE(cs
.saved_vp
);
5947 if (cs
.saved_fh
.nfs_fh4_val
)
5948 kmem_free(cs
.saved_fh
.nfs_fh4_val
, NFS4_FHSIZE
);
5955 * done with this compound request, free the label
5958 if (req
->rq_label
!= NULL
) {
5959 kmem_free(req
->rq_label
, sizeof (bslabel_t
));
5960 req
->rq_label
= NULL
;
5965 * XXX because of what appears to be duplicate calls to rfs4_compound_free
5966 * XXX zero out the tag and array values. Need to investigate why the
5967 * XXX calls occur, but at least prevent the panic for now.
5970 rfs4_compound_free(COMPOUND4res
*resp
)
5974 if (resp
->tag
.utf8string_val
) {
5975 UTF8STRING_FREE(resp
->tag
)
5978 for (i
= 0; i
< resp
->array_len
; i
++) {
5982 resop
= &resp
->array
[i
];
5983 op
= (uint_t
)resop
->resop
;
5984 if (op
< rfsv4disp_cnt
) {
5985 (*rfsv4disptab
[op
].dis_resfree
)(resop
);
5988 if (resp
->array
!= NULL
) {
5989 kmem_free(resp
->array
, resp
->array_len
* sizeof (nfs_resop4
));
5994 * Process the value of the compound request rpc flags, as a bit-AND
5995 * of the individual per-op flags (idempotent, allowork, publicfh_ok)
5998 rfs4_compound_flagproc(COMPOUND4args
*args
, int *flagp
)
6003 for (i
= 0; flag
&& i
< args
->array_len
; i
++) {
6006 op
= (uint_t
)args
->array
[i
].argop
;
6008 if (op
< rfsv4disp_cnt
)
6009 flag
&= rfsv4disptab
[op
].dis_flags
;
6017 rfs4_client_sysid(rfs4_client_t
*cp
, sysid_t
*sp
)
6021 rfs4_dbe_lock(cp
->rc_dbe
);
6023 if (cp
->rc_sysidt
!= LM_NOSYSID
) {
6024 *sp
= cp
->rc_sysidt
;
6027 } else if ((cp
->rc_sysidt
= lm_alloc_sysidt()) != LM_NOSYSID
) {
6028 *sp
= cp
->rc_sysidt
;
6031 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
,
6032 "rfs4_client_sysid: allocated 0x%x\n", *sp
));
6036 rfs4_dbe_unlock(cp
->rc_dbe
);
6040 #if defined(DEBUG) && ! defined(lint)
6041 static void lock_print(char *str
, int operation
, struct flock64
*flk
)
6045 switch (operation
) {
6046 case F_GETLK
: op
= "F_GETLK";
6048 case F_SETLK
: op
= "F_SETLK";
6050 case F_SETLK_NBMAND
: op
= "F_SETLK_NBMAND";
6052 default: op
= "F_UNKNOWN";
6055 switch (flk
->l_type
) {
6056 case F_UNLCK
: type
= "F_UNLCK";
6058 case F_RDLCK
: type
= "F_RDLCK";
6060 case F_WRLCK
: type
= "F_WRLCK";
6062 default: type
= "F_UNKNOWN";
6066 ASSERT(flk
->l_whence
== 0);
6067 cmn_err(CE_NOTE
, "%s: %s, type = %s, off = %llx len = %llx pid = %d",
6068 str
, op
, type
, (longlong_t
)flk
->l_start
,
6069 flk
->l_len
? (longlong_t
)flk
->l_len
: ~0LL, flk
->l_pid
);
6072 #define LOCK_PRINT(d, s, t, f) if (d) lock_print(s, t, f)
6074 #define LOCK_PRINT(d, s, t, f)
6079 creds_ok(cred_set_t cr_set
, struct svc_req
*req
, struct compound_state
*cs
)
6085 * Look up the pathname using the vp in cs as the directory vnode.
6086 * cs->vp will be the vnode for the file on success
6090 rfs4_lookup(component4
*component
, struct svc_req
*req
,
6091 struct compound_state
*cs
)
6096 struct sockaddr
*ca
;
6099 if (cs
->vp
== NULL
) {
6100 return (NFS4ERR_NOFILEHANDLE
);
6102 if (cs
->vp
->v_type
!= VDIR
) {
6103 return (NFS4ERR_NOTDIR
);
6106 status
= utf8_dir_verify(component
);
6107 if (status
!= NFS4_OK
)
6110 nm
= utf8_to_fn(component
, &len
, NULL
);
6112 return (NFS4ERR_INVAL
);
6115 if (len
> MAXNAMELEN
) {
6117 return (NFS4ERR_NAMETOOLONG
);
6120 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
6121 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
6126 return (NFS4ERR_INVAL
);
6129 status
= do_rfs4_op_lookup(name
, req
, cs
);
6132 kmem_free(name
, MAXPATHLEN
+ 1);
6140 rfs4_lookupfile(component4
*component
, struct svc_req
*req
,
6141 struct compound_state
*cs
, uint32_t access
, change_info4
*cinfo
)
6144 vnode_t
*dvp
= cs
->vp
;
6145 vattr_t bva
, ava
, fva
;
6148 /* Get "before" change value */
6149 bva
.va_mask
= AT_CTIME
|AT_SEQ
;
6150 error
= VOP_GETATTR(dvp
, &bva
, 0, cs
->cr
, NULL
);
6152 return (puterrno4(error
));
6154 /* rfs4_lookup may VN_RELE directory */
6157 status
= rfs4_lookup(component
, req
, cs
);
6158 if (status
!= NFS4_OK
) {
6164 * Get "after" change value, if it fails, simply return the
6167 ava
.va_mask
= AT_CTIME
|AT_SEQ
;
6168 if (VOP_GETATTR(dvp
, &ava
, 0, cs
->cr
, NULL
)) {
6169 ava
.va_ctime
= bva
.va_ctime
;
6175 * Validate the file is a file
6177 fva
.va_mask
= AT_TYPE
|AT_MODE
;
6178 error
= VOP_GETATTR(cs
->vp
, &fva
, 0, cs
->cr
, NULL
);
6180 return (puterrno4(error
));
6182 if (fva
.va_type
!= VREG
) {
6183 if (fva
.va_type
== VDIR
)
6184 return (NFS4ERR_ISDIR
);
6185 if (fva
.va_type
== VLNK
)
6186 return (NFS4ERR_SYMLINK
);
6187 return (NFS4ERR_INVAL
);
6190 NFS4_SET_FATTR4_CHANGE(cinfo
->before
, bva
.va_ctime
);
6191 NFS4_SET_FATTR4_CHANGE(cinfo
->after
, ava
.va_ctime
);
6194 * It is undefined if VOP_LOOKUP will change va_seq, so
6195 * cinfo.atomic = TRUE only if we have
6196 * non-zero va_seq's, and they have not changed.
6198 if (bva
.va_seq
&& ava
.va_seq
&& ava
.va_seq
== bva
.va_seq
)
6199 cinfo
->atomic
= TRUE
;
6201 cinfo
->atomic
= FALSE
;
6203 /* Check for mandatory locking */
6204 cs
->mandlock
= MANDLOCK(cs
->vp
, fva
.va_mode
);
6205 return (check_open_access(access
, cs
, req
));
6209 create_vnode(vnode_t
*dvp
, char *nm
, vattr_t
*vap
, createmode4 mode
,
6210 timespec32_t
*mtime
, cred_t
*cr
, vnode_t
**vpp
, bool_t
*created
)
6213 nfsstat4 status
= NFS4_OK
;
6219 * The file open mode used is VWRITE. If the client needs
6220 * some other semantic, then it should do the access checking
6221 * itself. It would have been nice to have the file open mode
6222 * passed as part of the arguments.
6226 error
= VOP_CREATE(dvp
, nm
, vap
, EXCL
, VWRITE
, vpp
, cr
, 0, NULL
, NULL
);
6232 * If we got something other than file already exists
6233 * then just return this error. Otherwise, we got
6234 * EEXIST. If we were doing a GUARDED create, then
6235 * just return this error. Otherwise, we need to
6236 * make sure that this wasn't a duplicate of an
6237 * exclusive create request.
6239 * The assumption is made that a non-exclusive create
6240 * request will never return EEXIST.
6243 if (error
!= EEXIST
|| mode
== GUARDED4
) {
6244 status
= puterrno4(error
);
6247 error
= VOP_LOOKUP(dvp
, nm
, vpp
, NULL
, 0, NULL
, cr
,
6252 * We couldn't find the file that we thought that
6253 * we just created. So, we'll just try creating
6256 if (error
== ENOENT
)
6259 status
= puterrno4(error
);
6263 if (mode
== UNCHECKED4
) {
6264 /* existing object must be regular file */
6265 if ((*vpp
)->v_type
!= VREG
) {
6266 if ((*vpp
)->v_type
== VDIR
)
6267 status
= NFS4ERR_ISDIR
;
6268 else if ((*vpp
)->v_type
== VLNK
)
6269 status
= NFS4ERR_SYMLINK
;
6271 status
= NFS4ERR_INVAL
;
6279 /* Check for duplicate request */
6281 va
.va_mask
= AT_MTIME
;
6282 error
= VOP_GETATTR(*vpp
, &va
, 0, cr
, NULL
);
6284 /* We found the file */
6285 if (va
.va_mtime
.tv_sec
!= mtime
->tv_sec
||
6286 va
.va_mtime
.tv_nsec
!= mtime
->tv_nsec
) {
6287 /* but its not our creation */
6289 return (NFS4ERR_EXIST
);
6291 *created
= TRUE
; /* retrans of create == created */
6295 return (NFS4ERR_EXIST
);
6302 check_open_access(uint32_t access
, struct compound_state
*cs
,
6303 struct svc_req
*req
)
6308 cred_t
*cr
= cs
->cr
;
6310 /* For now we don't allow mandatory locking as per V2/V3 */
6311 if (cs
->access
== CS_ACCESS_DENIED
|| cs
->mandlock
) {
6312 return (NFS4ERR_ACCESS
);
6316 ASSERT(cr
!= NULL
&& vp
->v_type
== VREG
);
6319 * If the file system is exported read only and we are trying
6320 * to open for write, then return NFS4ERR_ROFS
6323 readonly
= rdonly4(cs
->exi
, cs
->vp
, req
);
6325 if ((access
& OPEN4_SHARE_ACCESS_WRITE
) && readonly
)
6326 return (NFS4ERR_ROFS
);
6328 if (access
& OPEN4_SHARE_ACCESS_READ
) {
6329 if ((VOP_ACCESS(vp
, VREAD
, 0, cr
, NULL
) != 0) &&
6330 (VOP_ACCESS(vp
, VEXEC
, 0, cr
, NULL
) != 0)) {
6331 return (NFS4ERR_ACCESS
);
6335 if (access
& OPEN4_SHARE_ACCESS_WRITE
) {
6336 error
= VOP_ACCESS(vp
, VWRITE
, 0, cr
, NULL
);
6338 return (NFS4ERR_ACCESS
);
6345 rfs4_createfile(OPEN4args
*args
, struct svc_req
*req
, struct compound_state
*cs
,
6346 change_info4
*cinfo
, bitmap4
*attrset
, clientid4 clientid
)
6348 struct nfs4_svgetit_arg sarg
;
6349 struct nfs4_ntov_table ntov
;
6351 bool_t ntov_table_init
= FALSE
;
6352 struct statvfs64 sb
;
6355 vattr_t bva
, ava
, iva
, cva
, *vap
;
6357 timespec32_t
*mtime
;
6361 bool_t setsize
= FALSE
;
6365 caller_context_t ct
;
6366 component4
*component
;
6368 struct sockaddr
*ca
;
6372 sarg
.is_referral
= B_FALSE
;
6376 /* Check if the file system is read only */
6377 if (rdonly4(cs
->exi
, dvp
, req
))
6378 return (NFS4ERR_ROFS
);
6380 /* check the label of including directory */
6381 if (is_system_labeled()) {
6382 ASSERT(req
->rq_label
!= NULL
);
6383 clabel
= req
->rq_label
;
6384 DTRACE_PROBE2(tx__rfs4__log__info__opremove__clabel
, char *,
6385 "got client label from request(1)",
6386 struct svc_req
*, req
);
6387 if (!blequal(&l_admin_low
->tsl_label
, clabel
)) {
6388 if (!do_rfs_label_check(clabel
, dvp
, EQUALITY_CHECK
,
6390 return (NFS4ERR_ACCESS
);
6396 * Get the last component of path name in nm. cs will reference
6397 * the including directory on success.
6399 component
= &args
->open_claim4_u
.file
;
6400 status
= utf8_dir_verify(component
);
6401 if (status
!= NFS4_OK
)
6404 nm
= utf8_to_fn(component
, &buflen
, NULL
);
6407 return (NFS4ERR_RESOURCE
);
6409 if (buflen
> MAXNAMELEN
) {
6410 kmem_free(nm
, buflen
);
6411 return (NFS4ERR_NAMETOOLONG
);
6414 bva
.va_mask
= AT_TYPE
|AT_CTIME
|AT_SEQ
;
6415 error
= VOP_GETATTR(dvp
, &bva
, 0, cs
->cr
, NULL
);
6417 kmem_free(nm
, buflen
);
6418 return (puterrno4(error
));
6421 if (bva
.va_type
!= VDIR
) {
6422 kmem_free(nm
, buflen
);
6423 return (NFS4ERR_NOTDIR
);
6426 NFS4_SET_FATTR4_CHANGE(cinfo
->before
, bva
.va_ctime
)
6428 switch (args
->mode
) {
6432 nfs4_ntov_table_init(&ntov
);
6433 ntov_table_init
= TRUE
;
6436 status
= do_rfs4_set_attrs(attrset
,
6437 &args
->createhow4_u
.createattrs
,
6438 cs
, &sarg
, &ntov
, NFS4ATTR_SETIT
);
6440 if (status
== NFS4_OK
&& (sarg
.vap
->va_mask
& AT_TYPE
) &&
6441 sarg
.vap
->va_type
!= VREG
) {
6442 if (sarg
.vap
->va_type
== VDIR
)
6443 status
= NFS4ERR_ISDIR
;
6444 else if (sarg
.vap
->va_type
== VLNK
)
6445 status
= NFS4ERR_SYMLINK
;
6447 status
= NFS4ERR_INVAL
;
6450 if (status
!= NFS4_OK
) {
6451 kmem_free(nm
, buflen
);
6452 nfs4_ntov_table_free(&ntov
, &sarg
);
6458 vap
->va_type
= VREG
;
6459 vap
->va_mask
|= AT_TYPE
;
6461 if ((vap
->va_mask
& AT_MODE
) == 0) {
6462 vap
->va_mask
|= AT_MODE
;
6463 vap
->va_mode
= (mode_t
)0600;
6466 if (vap
->va_mask
& AT_SIZE
) {
6468 /* Disallow create with a non-zero size */
6470 if ((reqsize
= sarg
.vap
->va_size
) != 0) {
6471 kmem_free(nm
, buflen
);
6472 nfs4_ntov_table_free(&ntov
, &sarg
);
6474 return (NFS4ERR_INVAL
);
6481 /* prohibit EXCL create of named attributes */
6482 if (dvp
->v_flag
& V_XATTRDIR
) {
6483 kmem_free(nm
, buflen
);
6485 return (NFS4ERR_INVAL
);
6488 cva
.va_mask
= AT_TYPE
| AT_MTIME
| AT_MODE
;
6491 * Ensure no time overflows. Assumes underlying
6492 * filesystem supports at least 32 bits.
6493 * Truncate nsec to usec resolution to allow valid
6494 * compares even if the underlying filesystem truncates.
6496 mtime
= (timespec32_t
*)&args
->createhow4_u
.createverf
;
6497 cva
.va_mtime
.tv_sec
= mtime
->tv_sec
% TIME32_MAX
;
6498 cva
.va_mtime
.tv_nsec
= (mtime
->tv_nsec
/ 1000) * 1000;
6499 cva
.va_mode
= (mode_t
)0;
6503 * For EXCL create, attrset is set to the server attr
6504 * used to cache the client's verifier.
6506 *attrset
= FATTR4_TIME_MODIFY_MASK
;
6510 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
6511 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
6515 kmem_free(nm
, buflen
);
6516 return (NFS4ERR_SERVERFAULT
);
6519 status
= create_vnode(dvp
, name
, vap
, args
->mode
, mtime
,
6520 cs
->cr
, &vp
, &created
);
6522 kmem_free(name
, MAXPATHLEN
+ 1);
6523 kmem_free(nm
, buflen
);
6525 if (status
!= NFS4_OK
) {
6526 if (ntov_table_init
)
6527 nfs4_ntov_table_free(&ntov
, &sarg
);
6532 trunc
= (setsize
&& !created
);
6534 if (args
->mode
!= EXCLUSIVE4
) {
6535 bitmap4 createmask
= args
->createhow4_u
.createattrs
.attrmask
;
6538 * True verification that object was created with correct
6539 * attrs is impossible. The attrs could have been changed
6540 * immediately after object creation. If attributes did
6541 * not verify, the only recourse for the server is to
6542 * destroy the object. Maybe if some attrs (like gid)
6543 * are set incorrectly, the object should be destroyed;
6544 * however, seems bad as a default policy. Do we really
6545 * want to destroy an object over one of the times not
6546 * verifying correctly? For these reasons, the server
6547 * currently sets bits in attrset for createattrs
6548 * that were set; however, no verification is done.
6550 * vmask_to_nmask accounts for vattr bits set on create
6551 * [do_rfs4_set_attrs() only sets resp bits for
6552 * non-vattr/vfs bits.]
6553 * Mask off any bits we set by default so as not to return
6554 * more attrset bits than were requested in createattrs
6557 nfs4_vmask_to_nmask(sarg
.vap
->va_mask
, attrset
);
6558 *attrset
&= createmask
;
6561 * We did not create the vnode (we tried but it
6562 * already existed). In this case, the only createattr
6563 * that the spec allows the server to set is size,
6564 * and even then, it can only be set if it is 0.
6568 *attrset
= FATTR4_SIZE_MASK
;
6571 if (ntov_table_init
)
6572 nfs4_ntov_table_free(&ntov
, &sarg
);
6575 * Get the initial "after" sequence number, if it fails,
6576 * set to zero, time to before.
6578 iva
.va_mask
= AT_CTIME
|AT_SEQ
;
6579 if (VOP_GETATTR(dvp
, &iva
, 0, cs
->cr
, NULL
)) {
6581 iva
.va_ctime
= bva
.va_ctime
;
6585 * create_vnode attempts to create the file exclusive,
6586 * if it already exists the VOP_CREATE will fail and
6587 * may not increase va_seq. It is atomic if
6588 * we haven't changed the directory, but if it has changed
6589 * we don't know what changed it.
6592 if (bva
.va_seq
&& iva
.va_seq
&&
6593 bva
.va_seq
== iva
.va_seq
)
6594 cinfo
->atomic
= TRUE
;
6596 cinfo
->atomic
= FALSE
;
6597 NFS4_SET_FATTR4_CHANGE(cinfo
->after
, iva
.va_ctime
);
6600 * The entry was created, we need to sync the
6601 * directory metadata.
6603 (void) VOP_FSYNC(dvp
, 0, cs
->cr
, NULL
);
6606 * Get "after" change value, if it fails, simply return the
6609 ava
.va_mask
= AT_CTIME
|AT_SEQ
;
6610 if (VOP_GETATTR(dvp
, &ava
, 0, cs
->cr
, NULL
)) {
6611 ava
.va_ctime
= bva
.va_ctime
;
6615 NFS4_SET_FATTR4_CHANGE(cinfo
->after
, ava
.va_ctime
);
6618 * The cinfo->atomic = TRUE only if we have
6619 * non-zero va_seq's, and it has incremented by exactly one
6620 * during the create_vnode and it didn't
6621 * change during the VOP_FSYNC.
6623 if (bva
.va_seq
&& iva
.va_seq
&& ava
.va_seq
&&
6624 iva
.va_seq
== (bva
.va_seq
+ 1) && iva
.va_seq
== ava
.va_seq
)
6625 cinfo
->atomic
= TRUE
;
6627 cinfo
->atomic
= FALSE
;
6630 /* Check for mandatory locking and that the size gets set. */
6631 cva
.va_mask
= AT_MODE
;
6633 cva
.va_mask
|= AT_SIZE
;
6635 /* Assume the worst */
6636 cs
->mandlock
= TRUE
;
6638 if (VOP_GETATTR(vp
, &cva
, 0, cs
->cr
, NULL
) == 0) {
6639 cs
->mandlock
= MANDLOCK(cs
->vp
, cva
.va_mode
);
6642 * Truncate the file if necessary; this would be
6643 * the case for create over an existing file.
6649 bool_t create
= FALSE
;
6652 * We are writing over an existing file.
6653 * Check to see if we need to recall a delegation.
6655 rfs4_hold_deleg_policy();
6656 if ((fp
= rfs4_findfile(vp
, NULL
, &create
)) != NULL
) {
6657 if (rfs4_check_delegated_byfp(FWRITE
, fp
,
6658 (reqsize
== 0), FALSE
, FALSE
, &clientid
)) {
6660 rfs4_rele_deleg_policy();
6663 return (NFS4ERR_DELAY
);
6667 rfs4_rele_deleg_policy();
6669 if (nbl_need_check(vp
)) {
6672 ASSERT(reqsize
== 0);
6674 nbl_start_crit(vp
, RW_READER
);
6675 if (nbl_conflict(vp
, NBL_WRITE
, 0,
6676 cva
.va_size
, 0, NULL
)) {
6681 return (NFS4ERR_ACCESS
);
6686 ct
.cc_caller_id
= nfs4_srv_caller_id
;
6687 ct
.cc_flags
= CC_DONTBLOCK
;
6689 cva
.va_mask
= AT_SIZE
;
6690 cva
.va_size
= reqsize
;
6691 (void) VOP_SETATTR(vp
, &cva
, 0, cs
->cr
, &ct
);
6697 error
= makefh4(&cs
->fh
, vp
, cs
->exi
);
6700 * Force modified data and metadata out to stable storage.
6702 (void) VOP_FSYNC(vp
, FNODSYNC
, cs
->cr
, NULL
);
6707 return (puterrno4(error
));
6710 /* if parent dir is attrdir, set namedattr fh flag */
6711 if (dvp
->v_flag
& V_XATTRDIR
)
6712 set_fh4_flag(&cs
->fh
, FH4_NAMEDATTR
);
6720 * if we did not create the file, we will need to check
6721 * the access bits on the file
6726 args
->share_access
|= OPEN4_SHARE_ACCESS_WRITE
;
6727 status
= check_open_access(args
->share_access
, cs
, req
);
6728 if (status
!= NFS4_OK
)
6736 rfs4_do_open(struct compound_state
*cs
, struct svc_req
*req
,
6737 rfs4_openowner_t
*oo
, delegreq_t deleg
,
6738 uint32_t access
, uint32_t deny
,
6739 OPEN4res
*resp
, int deleg_cur
)
6741 /* XXX Currently not using req */
6744 bool_t screate
= TRUE
;
6745 bool_t fcreate
= TRUE
;
6746 uint32_t open_a
, share_a
;
6747 uint32_t open_d
, share_d
;
6748 rfs4_deleg_state_t
*dsp
;
6751 caller_context_t ct
;
6757 /* get the file struct and hold a lock on it during initial open */
6758 fp
= rfs4_findfile_withlock(cs
->vp
, &cs
->fh
, &fcreate
);
6760 resp
->status
= NFS4ERR_RESOURCE
;
6761 DTRACE_PROBE1(nfss__e__do__open1
, nfsstat4
, resp
->status
);
6765 sp
= rfs4_findstate_by_owner_file(oo
, fp
, &screate
);
6767 resp
->status
= NFS4ERR_RESOURCE
;
6768 DTRACE_PROBE1(nfss__e__do__open2
, nfsstat4
, resp
->status
);
6769 /* No need to keep any reference */
6770 rw_exit(&fp
->rf_file_rwlock
);
6775 /* try to get the sysid before continuing */
6776 if ((status
= rfs4_client_sysid(oo
->ro_client
, &sysid
)) != NFS4_OK
) {
6777 resp
->status
= status
;
6779 /* Not a fully formed open; "close" it */
6780 if (screate
== TRUE
)
6781 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6782 rfs4_state_rele(sp
);
6786 /* Calculate the fflags for this OPEN. */
6787 if (access
& OPEN4_SHARE_ACCESS_READ
)
6789 if (access
& OPEN4_SHARE_ACCESS_WRITE
)
6792 rfs4_dbe_lock(sp
->rs_dbe
);
6795 * Calculate the new deny and access mode that this open is adding to
6796 * the file for this open owner;
6798 open_d
= (deny
& ~sp
->rs_open_deny
);
6799 open_a
= (access
& ~sp
->rs_open_access
);
6802 * Calculate the new share access and share deny modes that this open
6803 * is adding to the file for this open owner;
6805 share_a
= (access
& ~sp
->rs_share_access
);
6806 share_d
= (deny
& ~sp
->rs_share_deny
);
6808 first_open
= (sp
->rs_open_access
& OPEN4_SHARE_ACCESS_BOTH
) == 0;
6811 * Check to see the client has already sent an open for this
6812 * open owner on this file with the same share/deny modes.
6813 * If so, we don't need to check for a conflict and we don't
6814 * need to add another shrlock. If not, then we need to
6815 * check for conflicts in deny and access before checking for
6816 * conflicts in delegation. We don't want to recall a
6817 * delegation based on an open that will eventually fail based
6821 if (share_a
|| share_d
) {
6822 if ((err
= rfs4_share(sp
, access
, deny
)) != 0) {
6823 rfs4_dbe_unlock(sp
->rs_dbe
);
6827 /* Not a fully formed open; "close" it */
6828 if (screate
== TRUE
)
6829 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6830 rfs4_state_rele(sp
);
6835 rfs4_dbe_lock(fp
->rf_dbe
);
6838 * Check to see if this file is delegated and if so, if a
6839 * recall needs to be done.
6841 if (rfs4_check_recall(sp
, access
)) {
6842 rfs4_dbe_unlock(fp
->rf_dbe
);
6843 rfs4_dbe_unlock(sp
->rs_dbe
);
6844 rfs4_recall_deleg(fp
, FALSE
, sp
->rs_owner
->ro_client
);
6845 delay(NFS4_DELEGATION_CONFLICT_DELAY
);
6846 rfs4_dbe_lock(sp
->rs_dbe
);
6848 /* if state closed while lock was dropped */
6849 if (sp
->rs_closed
) {
6850 if (share_a
|| share_d
)
6851 (void) rfs4_unshare(sp
);
6852 rfs4_dbe_unlock(sp
->rs_dbe
);
6854 /* Not a fully formed open; "close" it */
6855 if (screate
== TRUE
)
6856 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6857 rfs4_state_rele(sp
);
6858 resp
->status
= NFS4ERR_OLD_STATEID
;
6862 rfs4_dbe_lock(fp
->rf_dbe
);
6863 /* Let's see if the delegation was returned */
6864 if (rfs4_check_recall(sp
, access
)) {
6865 rfs4_dbe_unlock(fp
->rf_dbe
);
6866 if (share_a
|| share_d
)
6867 (void) rfs4_unshare(sp
);
6868 rfs4_dbe_unlock(sp
->rs_dbe
);
6870 rfs4_update_lease(sp
->rs_owner
->ro_client
);
6872 /* Not a fully formed open; "close" it */
6873 if (screate
== TRUE
)
6874 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6875 rfs4_state_rele(sp
);
6876 resp
->status
= NFS4ERR_DELAY
;
6881 * the share check passed and any delegation conflict has been
6882 * taken care of, now call vop_open.
6883 * if this is the first open then call vop_open with fflags.
6884 * if not, call vn_open_upgrade with just the upgrade flags.
6886 * if the file has been opened already, it will have the current
6887 * access mode in the state struct. if it has no share access, then
6888 * this is a new open.
6890 * However, if this is open with CLAIM_DLEGATE_CUR, then don't
6891 * call VOP_OPEN(), just do the open upgrade.
6893 if (first_open
&& !deleg_cur
) {
6894 ct
.cc_sysid
= sysid
;
6895 ct
.cc_pid
= rfs4_dbe_getid(sp
->rs_owner
->ro_dbe
);
6896 ct
.cc_caller_id
= nfs4_srv_caller_id
;
6897 ct
.cc_flags
= CC_DONTBLOCK
;
6898 err
= VOP_OPEN(&cs
->vp
, fflags
, cs
->cr
, &ct
);
6900 rfs4_dbe_unlock(fp
->rf_dbe
);
6901 if (share_a
|| share_d
)
6902 (void) rfs4_unshare(sp
);
6903 rfs4_dbe_unlock(sp
->rs_dbe
);
6906 /* Not a fully formed open; "close" it */
6907 if (screate
== TRUE
)
6908 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6909 rfs4_state_rele(sp
);
6910 /* check if a monitor detected a delegation conflict */
6911 if (err
== EAGAIN
&& (ct
.cc_flags
& CC_WOULDBLOCK
))
6912 resp
->status
= NFS4ERR_DELAY
;
6914 resp
->status
= NFS4ERR_SERVERFAULT
;
6917 } else { /* open upgrade */
6919 * calculate the fflags for the new mode that is being added
6923 if (open_a
& OPEN4_SHARE_ACCESS_READ
)
6925 if (open_a
& OPEN4_SHARE_ACCESS_WRITE
)
6927 vn_open_upgrade(cs
->vp
, fflags
);
6929 sp
->rs_open_access
|= access
;
6930 sp
->rs_open_deny
|= deny
;
6932 if (open_d
& OPEN4_SHARE_DENY_READ
)
6934 if (open_d
& OPEN4_SHARE_DENY_WRITE
)
6935 fp
->rf_deny_write
++;
6936 fp
->rf_share_deny
|= deny
;
6938 if (open_a
& OPEN4_SHARE_ACCESS_READ
)
6939 fp
->rf_access_read
++;
6940 if (open_a
& OPEN4_SHARE_ACCESS_WRITE
)
6941 fp
->rf_access_write
++;
6942 fp
->rf_share_access
|= access
;
6945 * Check for delegation here. if the deleg argument is not
6946 * DELEG_ANY, then this is a reclaim from a client and
6947 * we must honor the delegation requested. If necessary we can
6948 * set the recall flag.
6951 dsp
= rfs4_grant_delegation(deleg
, sp
, &recall
);
6953 cs
->deleg
= (fp
->rf_dinfo
.rd_dtype
== OPEN_DELEGATE_WRITE
);
6955 next_stateid(&sp
->rs_stateid
);
6957 resp
->stateid
= sp
->rs_stateid
.stateid
;
6959 rfs4_dbe_unlock(fp
->rf_dbe
);
6960 rfs4_dbe_unlock(sp
->rs_dbe
);
6963 rfs4_set_deleg_response(dsp
, &resp
->delegation
, NULL
, recall
);
6964 rfs4_deleg_state_rele(dsp
);
6968 rfs4_state_rele(sp
);
6970 resp
->status
= NFS4_OK
;
6975 rfs4_do_opennull(struct compound_state
*cs
, struct svc_req
*req
,
6976 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
6978 change_info4
*cinfo
= &resp
->cinfo
;
6979 bitmap4
*attrset
= &resp
->attrset
;
6981 if (args
->opentype
== OPEN4_NOCREATE
)
6982 resp
->status
= rfs4_lookupfile(&args
->open_claim4_u
.file
,
6983 req
, cs
, args
->share_access
, cinfo
);
6985 /* inhibit delegation grants during exclusive create */
6987 if (args
->mode
== EXCLUSIVE4
)
6988 rfs4_disable_delegation();
6990 resp
->status
= rfs4_createfile(args
, req
, cs
, cinfo
, attrset
,
6991 oo
->ro_client
->rc_clientid
);
6994 if (resp
->status
== NFS4_OK
) {
6996 /* cs->vp cs->fh now reference the desired file */
6998 rfs4_do_open(cs
, req
, oo
,
6999 oo
->ro_need_confirm
? DELEG_NONE
: DELEG_ANY
,
7000 args
->share_access
, args
->share_deny
, resp
, 0);
7003 * If rfs4_createfile set attrset, we must
7004 * clear this attrset before the response is copied.
7006 if (resp
->status
!= NFS4_OK
&& resp
->attrset
) {
7011 *cs
->statusp
= resp
->status
;
7013 if (args
->mode
== EXCLUSIVE4
)
7014 rfs4_enable_delegation();
7019 rfs4_do_openprev(struct compound_state
*cs
, struct svc_req
*req
,
7020 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
7022 change_info4
*cinfo
= &resp
->cinfo
;
7024 vtype_t v_type
= cs
->vp
->v_type
;
7027 /* Verify that we have a regular file */
7028 if (v_type
!= VREG
) {
7030 resp
->status
= NFS4ERR_ISDIR
;
7031 else if (v_type
== VLNK
)
7032 resp
->status
= NFS4ERR_SYMLINK
;
7034 resp
->status
= NFS4ERR_INVAL
;
7038 va
.va_mask
= AT_MODE
|AT_UID
;
7039 error
= VOP_GETATTR(cs
->vp
, &va
, 0, cs
->cr
, NULL
);
7041 resp
->status
= puterrno4(error
);
7045 cs
->mandlock
= MANDLOCK(cs
->vp
, va
.va_mode
);
7048 * Check if we have access to the file, Note the the file
7049 * could have originally been open UNCHECKED or GUARDED
7050 * with mode bits that will now fail, but there is nothing
7051 * we can really do about that except in the case that the
7052 * owner of the file is the one requesting the open.
7054 if (crgetuid(cs
->cr
) != va
.va_uid
) {
7055 resp
->status
= check_open_access(args
->share_access
, cs
, req
);
7056 if (resp
->status
!= NFS4_OK
) {
7062 * cinfo on a CLAIM_PREVIOUS is undefined, initialize to zero
7066 cinfo
->atomic
= FALSE
;
7068 rfs4_do_open(cs
, req
, oo
,
7069 NFS4_DELEG4TYPE2REQTYPE(args
->open_claim4_u
.delegate_type
),
7070 args
->share_access
, args
->share_deny
, resp
, 0);
7074 rfs4_do_opendelcur(struct compound_state
*cs
, struct svc_req
*req
,
7075 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
7080 args
->open_claim4_u
.delegate_cur_info
.delegate_stateid
;
7081 rfs4_deleg_state_t
*dsp
;
7084 * Find the state info from the stateid and confirm that the
7085 * file is delegated. If the state openowner is the same as
7086 * the supplied openowner we're done. If not, get the file
7087 * info from the found state info. Use that file info to
7088 * create the state for this lock owner. Note solaris doen't
7089 * really need the pathname to find the file. We may want to
7090 * lookup the pathname and make sure that the vp exist and
7091 * matches the vp in the file structure. However it is
7092 * possible that the pathname nolonger exists (local process
7093 * unlinks the file), so this may not be that useful.
7096 status
= rfs4_get_deleg_state(&stateid
, &dsp
);
7097 if (status
!= NFS4_OK
) {
7098 resp
->status
= status
;
7102 ASSERT(dsp
->rds_finfo
->rf_dinfo
.rd_dtype
!= OPEN_DELEGATE_NONE
);
7105 * New lock owner, create state. Since this was probably called
7106 * in response to a CB_RECALL we set deleg to DELEG_NONE
7109 ASSERT(cs
->vp
!= NULL
);
7111 VN_HOLD(dsp
->rds_finfo
->rf_vp
);
7112 cs
->vp
= dsp
->rds_finfo
->rf_vp
;
7114 if (error
= makefh4(&cs
->fh
, cs
->vp
, cs
->exi
)) {
7115 rfs4_deleg_state_rele(dsp
);
7116 *cs
->statusp
= resp
->status
= puterrno4(error
);
7120 /* Mark progress for delegation returns */
7121 dsp
->rds_finfo
->rf_dinfo
.rd_time_lastwrite
= gethrestime_sec();
7122 rfs4_deleg_state_rele(dsp
);
7123 rfs4_do_open(cs
, req
, oo
, DELEG_NONE
,
7124 args
->share_access
, args
->share_deny
, resp
, 1);
7129 rfs4_do_opendelprev(struct compound_state
*cs
, struct svc_req
*req
,
7130 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
7133 * Lookup the pathname, it must already exist since this file
7136 * Find the file and state info for this vp and open owner pair.
7137 * check that they are in fact delegated.
7138 * check that the state access and deny modes are the same.
7140 * Return the delgation possibly seting the recall flag.
7144 bool_t create
= FALSE
;
7145 bool_t dcreate
= FALSE
;
7146 rfs4_deleg_state_t
*dsp
;
7149 /* Note we ignore oflags */
7150 resp
->status
= rfs4_lookupfile(&args
->open_claim4_u
.file_delegate_prev
,
7151 req
, cs
, args
->share_access
, &resp
->cinfo
);
7153 if (resp
->status
!= NFS4_OK
) {
7157 /* get the file struct and hold a lock on it during initial open */
7158 fp
= rfs4_findfile_withlock(cs
->vp
, NULL
, &create
);
7160 resp
->status
= NFS4ERR_RESOURCE
;
7161 DTRACE_PROBE1(nfss__e__do_opendelprev1
, nfsstat4
, resp
->status
);
7165 sp
= rfs4_findstate_by_owner_file(oo
, fp
, &create
);
7167 resp
->status
= NFS4ERR_SERVERFAULT
;
7168 DTRACE_PROBE1(nfss__e__do_opendelprev2
, nfsstat4
, resp
->status
);
7169 rw_exit(&fp
->rf_file_rwlock
);
7174 rfs4_dbe_lock(sp
->rs_dbe
);
7175 rfs4_dbe_lock(fp
->rf_dbe
);
7176 if (args
->share_access
!= sp
->rs_share_access
||
7177 args
->share_deny
!= sp
->rs_share_deny
||
7178 sp
->rs_finfo
->rf_dinfo
.rd_dtype
== OPEN_DELEGATE_NONE
) {
7179 NFS4_DEBUG(rfs4_debug
,
7180 (CE_NOTE
, "rfs4_do_opendelprev: state mixup"));
7181 rfs4_dbe_unlock(fp
->rf_dbe
);
7182 rfs4_dbe_unlock(sp
->rs_dbe
);
7184 rfs4_state_rele(sp
);
7185 resp
->status
= NFS4ERR_SERVERFAULT
;
7188 rfs4_dbe_unlock(fp
->rf_dbe
);
7189 rfs4_dbe_unlock(sp
->rs_dbe
);
7191 dsp
= rfs4_finddeleg(sp
, &dcreate
);
7193 rfs4_state_rele(sp
);
7195 resp
->status
= NFS4ERR_SERVERFAULT
;
7199 next_stateid(&sp
->rs_stateid
);
7201 resp
->stateid
= sp
->rs_stateid
.stateid
;
7203 resp
->delegation
.delegation_type
= dsp
->rds_dtype
;
7205 if (dsp
->rds_dtype
== OPEN_DELEGATE_READ
) {
7206 open_read_delegation4
*rv
=
7207 &resp
->delegation
.open_delegation4_u
.read
;
7209 rv
->stateid
= dsp
->rds_delegid
.stateid
;
7210 rv
->recall
= FALSE
; /* no policy in place to set to TRUE */
7211 ace
= &rv
->permissions
;
7213 open_write_delegation4
*rv
=
7214 &resp
->delegation
.open_delegation4_u
.write
;
7216 rv
->stateid
= dsp
->rds_delegid
.stateid
;
7217 rv
->recall
= FALSE
; /* no policy in place to set to TRUE */
7218 ace
= &rv
->permissions
;
7219 rv
->space_limit
.limitby
= NFS_LIMIT_SIZE
;
7220 rv
->space_limit
.nfs_space_limit4_u
.filesize
= UINT64_MAX
;
7224 ace
->type
= ACE4_ACCESS_ALLOWED_ACE_TYPE
;
7226 ace
->access_mask
= 0;
7227 ace
->who
.utf8string_len
= 0;
7228 ace
->who
.utf8string_val
= 0;
7230 rfs4_deleg_state_rele(dsp
);
7231 rfs4_state_rele(sp
);
7236 NFS4_CHKSEQ_OKAY
= 0,
7237 NFS4_CHKSEQ_REPLAY
= 1,
7242 * Generic function for sequence number checks.
7244 static rfs4_chkseq_t
7245 rfs4_check_seqid(seqid4 seqid
, nfs_resop4
*lastop
,
7246 seqid4 rqst_seq
, nfs_resop4
*resop
, bool_t copyres
)
7248 /* Same sequence ids and matching operations? */
7249 if (seqid
== rqst_seq
&& resop
->resop
== lastop
->resop
) {
7250 if (copyres
== TRUE
) {
7251 rfs4_free_reply(resop
);
7252 rfs4_copy_reply(resop
, lastop
);
7254 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
,
7255 "Replayed SEQID %d\n", seqid
));
7256 return (NFS4_CHKSEQ_REPLAY
);
7259 /* If the incoming sequence is not the next expected then it is bad */
7260 if (rqst_seq
!= seqid
+ 1) {
7261 if (rqst_seq
== seqid
) {
7262 NFS4_DEBUG(rfs4_debug
,
7263 (CE_NOTE
, "BAD SEQID: Replayed sequence id "
7264 "but last op was %d current op is %d\n",
7265 lastop
->resop
, resop
->resop
));
7266 return (NFS4_CHKSEQ_BAD
);
7268 NFS4_DEBUG(rfs4_debug
,
7269 (CE_NOTE
, "BAD SEQID: got %u expecting %u\n",
7271 return (NFS4_CHKSEQ_BAD
);
7274 /* Everything okay -- next expected */
7275 return (NFS4_CHKSEQ_OKAY
);
7279 static rfs4_chkseq_t
7280 rfs4_check_open_seqid(seqid4 seqid
, rfs4_openowner_t
*op
, nfs_resop4
*resop
)
7284 rfs4_dbe_lock(op
->ro_dbe
);
7285 rc
= rfs4_check_seqid(op
->ro_open_seqid
, &op
->ro_reply
, seqid
, resop
,
7287 rfs4_dbe_unlock(op
->ro_dbe
);
7289 if (rc
== NFS4_CHKSEQ_OKAY
)
7290 rfs4_update_lease(op
->ro_client
);
7295 static rfs4_chkseq_t
7296 rfs4_check_olo_seqid(seqid4 olo_seqid
, rfs4_openowner_t
*op
, nfs_resop4
*resop
)
7300 rfs4_dbe_lock(op
->ro_dbe
);
7301 rc
= rfs4_check_seqid(op
->ro_open_seqid
, &op
->ro_reply
,
7302 olo_seqid
, resop
, FALSE
);
7303 rfs4_dbe_unlock(op
->ro_dbe
);
7308 static rfs4_chkseq_t
7309 rfs4_check_lock_seqid(seqid4 seqid
, rfs4_lo_state_t
*lsp
, nfs_resop4
*resop
)
7311 rfs4_chkseq_t rc
= NFS4_CHKSEQ_OKAY
;
7313 rfs4_dbe_lock(lsp
->rls_dbe
);
7314 if (!lsp
->rls_skip_seqid_check
)
7315 rc
= rfs4_check_seqid(lsp
->rls_seqid
, &lsp
->rls_reply
, seqid
,
7317 rfs4_dbe_unlock(lsp
->rls_dbe
);
7323 rfs4_op_open(nfs_argop4
*argop
, nfs_resop4
*resop
,
7324 struct svc_req
*req
, struct compound_state
*cs
)
7326 OPEN4args
*args
= &argop
->nfs_argop4_u
.opopen
;
7327 OPEN4res
*resp
= &resop
->nfs_resop4_u
.opopen
;
7328 open_owner4
*owner
= &args
->owner
;
7329 open_claim_type4 claim
= args
->claim
;
7331 rfs4_openowner_t
*oo
;
7333 bool_t replay
= FALSE
;
7336 DTRACE_NFSV4_2(op__open__start
, struct compound_state
*, cs
,
7339 if (cs
->vp
== NULL
) {
7340 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
7345 * Need to check clientid and lease expiration first based on
7346 * error ordering and incrementing sequence id.
7348 cp
= rfs4_findclient_by_id(owner
->clientid
, FALSE
);
7350 *cs
->statusp
= resp
->status
=
7351 rfs4_check_clientid(&owner
->clientid
, 0);
7355 if (rfs4_lease_expired(cp
)) {
7356 rfs4_client_close(cp
);
7357 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
7360 can_reclaim
= cp
->rc_can_reclaim
;
7363 * Find the open_owner for use from this point forward. Take
7364 * care in updating the sequence id based on the type of error
7369 oo
= rfs4_findopenowner(owner
, &create
, args
->seqid
);
7371 *cs
->statusp
= resp
->status
= NFS4ERR_STALE_CLIENTID
;
7372 rfs4_client_rele(cp
);
7376 /* Hold off access to the sequence space while the open is done */
7377 rfs4_sw_enter(&oo
->ro_sw
);
7380 * If the open_owner existed before at the server, then check
7383 if (!create
&& !oo
->ro_postpone_confirm
) {
7384 switch (rfs4_check_open_seqid(args
->seqid
, oo
, resop
)) {
7385 case NFS4_CHKSEQ_BAD
:
7386 if ((args
->seqid
> oo
->ro_open_seqid
) &&
7387 oo
->ro_need_confirm
) {
7388 rfs4_free_opens(oo
, TRUE
, FALSE
);
7389 rfs4_sw_exit(&oo
->ro_sw
);
7390 rfs4_openowner_rele(oo
);
7393 resp
->status
= NFS4ERR_BAD_SEQID
;
7395 case NFS4_CHKSEQ_REPLAY
: /* replay of previous request */
7403 * Sequence was ok and open owner exists
7404 * check to see if we have yet to see an
7407 if (oo
->ro_need_confirm
) {
7408 rfs4_free_opens(oo
, TRUE
, FALSE
);
7409 rfs4_sw_exit(&oo
->ro_sw
);
7410 rfs4_openowner_rele(oo
);
7414 /* Grace only applies to regular-type OPENs */
7415 if (rfs4_clnt_in_grace(cp
) &&
7416 (claim
== CLAIM_NULL
|| claim
== CLAIM_DELEGATE_CUR
)) {
7417 *cs
->statusp
= resp
->status
= NFS4ERR_GRACE
;
7422 * If previous state at the server existed then can_reclaim
7423 * will be set. If not reply NFS4ERR_NO_GRACE to the
7426 if (rfs4_clnt_in_grace(cp
) && claim
== CLAIM_PREVIOUS
&& !can_reclaim
) {
7427 *cs
->statusp
= resp
->status
= NFS4ERR_NO_GRACE
;
7433 * Reject the open if the client has missed the grace period
7435 if (!rfs4_clnt_in_grace(cp
) && claim
== CLAIM_PREVIOUS
) {
7436 *cs
->statusp
= resp
->status
= NFS4ERR_NO_GRACE
;
7440 /* Couple of up-front bookkeeping items */
7441 if (oo
->ro_need_confirm
) {
7443 * If this is a reclaim OPEN then we should not ask
7444 * for a confirmation of the open_owner per the
7445 * protocol specification.
7447 if (claim
== CLAIM_PREVIOUS
)
7448 oo
->ro_need_confirm
= FALSE
;
7450 resp
->rflags
|= OPEN4_RESULT_CONFIRM
;
7452 resp
->rflags
|= OPEN4_RESULT_LOCKTYPE_POSIX
;
7455 * If there is an unshared filesystem mounted on this vnode,
7456 * do not allow to open/create in this directory.
7458 if (vn_ismntpt(cs
->vp
)) {
7459 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
7464 * access must READ, WRITE, or BOTH. No access is invalid.
7465 * deny can be READ, WRITE, BOTH, or NONE.
7466 * bits not defined for access/deny are invalid.
7468 if (! (args
->share_access
& OPEN4_SHARE_ACCESS_BOTH
) ||
7469 (args
->share_access
& ~OPEN4_SHARE_ACCESS_BOTH
) ||
7470 (args
->share_deny
& ~OPEN4_SHARE_DENY_BOTH
)) {
7471 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7477 * make sure attrset is zero before response is built.
7483 rfs4_do_opennull(cs
, req
, args
, oo
, resp
);
7485 case CLAIM_PREVIOUS
:
7486 rfs4_do_openprev(cs
, req
, args
, oo
, resp
);
7488 case CLAIM_DELEGATE_CUR
:
7489 rfs4_do_opendelcur(cs
, req
, args
, oo
, resp
);
7491 case CLAIM_DELEGATE_PREV
:
7492 rfs4_do_opendelprev(cs
, req
, args
, oo
, resp
);
7495 resp
->status
= NFS4ERR_INVAL
;
7500 rfs4_client_rele(cp
);
7502 /* Catch sequence id handling here to make it a little easier */
7503 switch (resp
->status
) {
7504 case NFS4ERR_BADXDR
:
7505 case NFS4ERR_BAD_SEQID
:
7506 case NFS4ERR_BAD_STATEID
:
7507 case NFS4ERR_NOFILEHANDLE
:
7508 case NFS4ERR_RESOURCE
:
7509 case NFS4ERR_STALE_CLIENTID
:
7510 case NFS4ERR_STALE_STATEID
:
7512 * The protocol states that if any of these errors are
7513 * being returned, the sequence id should not be
7514 * incremented. Any other return requires an
7519 /* Always update the lease in this case */
7520 rfs4_update_lease(oo
->ro_client
);
7522 /* Regular response - copy the result */
7524 rfs4_update_open_resp(oo
, resop
, &cs
->fh
);
7527 * REPLAY case: Only if the previous response was OK
7528 * do we copy the filehandle. If not OK, no
7529 * filehandle to copy.
7531 if (replay
== TRUE
&&
7532 resp
->status
== NFS4_OK
&&
7533 oo
->ro_reply_fh
.nfs_fh4_val
) {
7535 * If this is a replay, we must restore the
7536 * current filehandle/vp to that of what was
7537 * returned originally. Try our best to do
7540 nfs_fh4_fmt_t
*fh_fmtp
=
7541 (nfs_fh4_fmt_t
*)oo
->ro_reply_fh
.nfs_fh4_val
;
7543 cs
->exi
= checkexport4(&fh_fmtp
->fh4_fsid
,
7544 (fid_t
*)&fh_fmtp
->fh4_xlen
, NULL
);
7546 if (cs
->exi
== NULL
) {
7547 resp
->status
= NFS4ERR_STALE
;
7553 cs
->vp
= nfs4_fhtovp(&oo
->ro_reply_fh
, cs
->exi
,
7559 nfs_fh4_copy(&oo
->ro_reply_fh
, &cs
->fh
);
7563 * If this was a replay, no need to update the
7564 * sequence id. If the open_owner was not created on
7565 * this pass, then update. The first use of an
7566 * open_owner will not bump the sequence id.
7568 if (replay
== FALSE
&& !create
)
7569 rfs4_update_open_sequence(oo
);
7571 * If the client is receiving an error and the
7572 * open_owner needs to be confirmed, there is no way
7573 * to notify the client of this fact ignoring the fact
7574 * that the server has no method of returning a
7575 * stateid to confirm. Therefore, the server needs to
7576 * mark this open_owner in a way as to avoid the
7577 * sequence id checking the next time the client uses
7580 if (resp
->status
!= NFS4_OK
&& oo
->ro_need_confirm
)
7581 oo
->ro_postpone_confirm
= TRUE
;
7583 * If OK response then clear the postpone flag and
7584 * reset the sequence id to keep in sync with the
7587 if (resp
->status
== NFS4_OK
&& oo
->ro_postpone_confirm
) {
7588 oo
->ro_postpone_confirm
= FALSE
;
7589 oo
->ro_open_seqid
= args
->seqid
;
7595 *cs
->statusp
= resp
->status
;
7597 rfs4_sw_exit(&oo
->ro_sw
);
7598 rfs4_openowner_rele(oo
);
7601 DTRACE_NFSV4_2(op__open__done
, struct compound_state
*, cs
,
7607 rfs4_op_open_confirm(nfs_argop4
*argop
, nfs_resop4
*resop
,
7608 struct svc_req
*req
, struct compound_state
*cs
)
7610 OPEN_CONFIRM4args
*args
= &argop
->nfs_argop4_u
.opopen_confirm
;
7611 OPEN_CONFIRM4res
*resp
= &resop
->nfs_resop4_u
.opopen_confirm
;
7615 DTRACE_NFSV4_2(op__open__confirm__start
, struct compound_state
*, cs
,
7616 OPEN_CONFIRM4args
*, args
);
7618 if (cs
->vp
== NULL
) {
7619 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
7623 status
= rfs4_get_state(&args
->open_stateid
, &sp
, RFS4_DBS_VALID
);
7624 if (status
!= NFS4_OK
) {
7625 *cs
->statusp
= resp
->status
= status
;
7629 /* Ensure specified filehandle matches */
7630 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
7631 rfs4_state_rele(sp
);
7632 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7636 /* hold off other access to open_owner while we tinker */
7637 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
7639 switch (rfs4_check_stateid_seqid(sp
, &args
->open_stateid
)) {
7640 case NFS4_CHECK_STATEID_OKAY
:
7641 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7643 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7647 * If it is the appropriate stateid and determined to
7648 * be "OKAY" then this means that the stateid does not
7649 * need to be confirmed and the client is in error for
7650 * sending an OPEN_CONFIRM.
7652 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7654 case NFS4_CHECK_STATEID_OLD
:
7655 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7657 case NFS4_CHECK_STATEID_BAD
:
7658 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7660 case NFS4_CHECK_STATEID_EXPIRED
:
7661 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
7663 case NFS4_CHECK_STATEID_CLOSED
:
7664 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7666 case NFS4_CHECK_STATEID_REPLAY
:
7667 switch (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7669 case NFS4_CHKSEQ_OKAY
:
7671 * This is replayed stateid; if seqid matches
7672 * next expected, then client is using wrong seqid.
7675 case NFS4_CHKSEQ_BAD
:
7676 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7678 case NFS4_CHKSEQ_REPLAY
:
7680 * Note this case is the duplicate case so
7681 * resp->status is already set.
7683 *cs
->statusp
= resp
->status
;
7684 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7688 case NFS4_CHECK_STATEID_UNCONFIRMED
:
7689 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7690 resop
) != NFS4_CHKSEQ_OKAY
) {
7691 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7694 *cs
->statusp
= resp
->status
= NFS4_OK
;
7696 next_stateid(&sp
->rs_stateid
);
7697 resp
->open_stateid
= sp
->rs_stateid
.stateid
;
7698 sp
->rs_owner
->ro_need_confirm
= FALSE
;
7699 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7700 rfs4_update_open_sequence(sp
->rs_owner
);
7701 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
7705 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
7708 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
7709 rfs4_state_rele(sp
);
7712 DTRACE_NFSV4_2(op__open__confirm__done
, struct compound_state
*, cs
,
7713 OPEN_CONFIRM4res
*, resp
);
7718 rfs4_op_open_downgrade(nfs_argop4
*argop
, nfs_resop4
*resop
,
7719 struct svc_req
*req
, struct compound_state
*cs
)
7721 OPEN_DOWNGRADE4args
*args
= &argop
->nfs_argop4_u
.opopen_downgrade
;
7722 OPEN_DOWNGRADE4res
*resp
= &resop
->nfs_resop4_u
.opopen_downgrade
;
7723 uint32_t access
= args
->share_access
;
7724 uint32_t deny
= args
->share_deny
;
7730 DTRACE_NFSV4_2(op__open__downgrade__start
, struct compound_state
*, cs
,
7731 OPEN_DOWNGRADE4args
*, args
);
7733 if (cs
->vp
== NULL
) {
7734 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
7738 if (cs
->vp
->v_type
!= VREG
) {
7739 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7743 status
= rfs4_get_state(&args
->open_stateid
, &sp
, RFS4_DBS_VALID
);
7744 if (status
!= NFS4_OK
) {
7745 *cs
->statusp
= resp
->status
= status
;
7749 /* Ensure specified filehandle matches */
7750 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
7751 rfs4_state_rele(sp
);
7752 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7756 /* hold off other access to open_owner while we tinker */
7757 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
7759 switch (rfs4_check_stateid_seqid(sp
, &args
->open_stateid
)) {
7760 case NFS4_CHECK_STATEID_OKAY
:
7761 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7762 resop
) != NFS4_CHKSEQ_OKAY
) {
7763 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7767 case NFS4_CHECK_STATEID_OLD
:
7768 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7770 case NFS4_CHECK_STATEID_BAD
:
7771 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7773 case NFS4_CHECK_STATEID_EXPIRED
:
7774 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
7776 case NFS4_CHECK_STATEID_CLOSED
:
7777 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7779 case NFS4_CHECK_STATEID_UNCONFIRMED
:
7780 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7782 case NFS4_CHECK_STATEID_REPLAY
:
7783 /* Check the sequence id for the open owner */
7784 switch (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7786 case NFS4_CHKSEQ_OKAY
:
7788 * This is replayed stateid; if seqid matches
7789 * next expected, then client is using wrong seqid.
7792 case NFS4_CHKSEQ_BAD
:
7793 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7795 case NFS4_CHKSEQ_REPLAY
:
7797 * Note this case is the duplicate case so
7798 * resp->status is already set.
7800 *cs
->statusp
= resp
->status
;
7801 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7810 rfs4_dbe_lock(sp
->rs_dbe
);
7812 * Check that the new access modes and deny modes are valid.
7813 * Check that no invalid bits are set.
7815 if ((access
& ~(OPEN4_SHARE_ACCESS_READ
| OPEN4_SHARE_ACCESS_WRITE
)) ||
7816 (deny
& ~(OPEN4_SHARE_DENY_READ
| OPEN4_SHARE_DENY_WRITE
))) {
7817 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7818 rfs4_update_open_sequence(sp
->rs_owner
);
7819 rfs4_dbe_unlock(sp
->rs_dbe
);
7824 * The new modes must be a subset of the current modes and
7825 * the access must specify at least one mode. To test that
7826 * the new mode is a subset of the current modes we bitwise
7827 * AND them together and check that the result equals the new
7828 * mode. For example:
7829 * New mode, access == R and current mode, sp->rs_open_access == RW
7830 * access & sp->rs_open_access == R == access, so the new access mode
7831 * is valid. Consider access == RW, sp->rs_open_access = R
7832 * access & sp->rs_open_access == R != access, so the new access mode
7835 if ((access
& sp
->rs_open_access
) != access
||
7836 (deny
& sp
->rs_open_deny
) != deny
||
7838 (OPEN4_SHARE_ACCESS_READ
| OPEN4_SHARE_ACCESS_WRITE
)) == 0) {
7839 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7840 rfs4_update_open_sequence(sp
->rs_owner
);
7841 rfs4_dbe_unlock(sp
->rs_dbe
);
7846 * Release any share locks associated with this stateID.
7847 * Strictly speaking, this violates the spec because the
7848 * spec effectively requires that open downgrade be atomic.
7849 * At present, fs_shrlock does not have this capability.
7851 (void) rfs4_unshare(sp
);
7853 status
= rfs4_share(sp
, access
, deny
);
7854 if (status
!= NFS4_OK
) {
7855 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
7856 rfs4_update_open_sequence(sp
->rs_owner
);
7857 rfs4_dbe_unlock(sp
->rs_dbe
);
7862 rfs4_dbe_lock(fp
->rf_dbe
);
7865 * If the current mode has deny read and the new mode
7866 * does not, decrement the number of deny read mode bits
7867 * and if it goes to zero turn off the deny read bit
7870 if ((sp
->rs_open_deny
& OPEN4_SHARE_DENY_READ
) &&
7871 (deny
& OPEN4_SHARE_DENY_READ
) == 0) {
7873 if (fp
->rf_deny_read
== 0)
7874 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_READ
;
7878 * If the current mode has deny write and the new mode
7879 * does not, decrement the number of deny write mode bits
7880 * and if it goes to zero turn off the deny write bit
7883 if ((sp
->rs_open_deny
& OPEN4_SHARE_DENY_WRITE
) &&
7884 (deny
& OPEN4_SHARE_DENY_WRITE
) == 0) {
7885 fp
->rf_deny_write
--;
7886 if (fp
->rf_deny_write
== 0)
7887 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_WRITE
;
7891 * If the current mode has access read and the new mode
7892 * does not, decrement the number of access read mode bits
7893 * and if it goes to zero turn off the access read bit
7894 * on the file. set fflags to FREAD for the call to
7895 * vn_open_downgrade().
7897 if ((sp
->rs_open_access
& OPEN4_SHARE_ACCESS_READ
) &&
7898 (access
& OPEN4_SHARE_ACCESS_READ
) == 0) {
7899 fp
->rf_access_read
--;
7900 if (fp
->rf_access_read
== 0)
7901 fp
->rf_share_access
&= ~OPEN4_SHARE_ACCESS_READ
;
7906 * If the current mode has access write and the new mode
7907 * does not, decrement the number of access write mode bits
7908 * and if it goes to zero turn off the access write bit
7909 * on the file. set fflags to FWRITE for the call to
7910 * vn_open_downgrade().
7912 if ((sp
->rs_open_access
& OPEN4_SHARE_ACCESS_WRITE
) &&
7913 (access
& OPEN4_SHARE_ACCESS_WRITE
) == 0) {
7914 fp
->rf_access_write
--;
7915 if (fp
->rf_access_write
== 0)
7916 fp
->rf_share_deny
&= ~OPEN4_SHARE_ACCESS_WRITE
;
7920 /* Check that the file is still accessible */
7921 ASSERT(fp
->rf_share_access
);
7923 rfs4_dbe_unlock(fp
->rf_dbe
);
7925 /* now set the new open access and deny modes */
7926 sp
->rs_open_access
= access
;
7927 sp
->rs_open_deny
= deny
;
7930 * we successfully downgraded the share lock, now we need to downgrade
7931 * the open. it is possible that the downgrade was only for a deny
7932 * mode and we have nothing else to do.
7934 if ((fflags
& (FREAD
|FWRITE
)) != 0)
7935 vn_open_downgrade(cs
->vp
, fflags
);
7937 /* Update the stateid */
7938 next_stateid(&sp
->rs_stateid
);
7939 resp
->open_stateid
= sp
->rs_stateid
.stateid
;
7941 rfs4_dbe_unlock(sp
->rs_dbe
);
7943 *cs
->statusp
= resp
->status
= NFS4_OK
;
7944 /* Update the lease */
7945 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7946 /* And the sequence */
7947 rfs4_update_open_sequence(sp
->rs_owner
);
7948 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
7951 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
7952 rfs4_state_rele(sp
);
7954 DTRACE_NFSV4_2(op__open__downgrade__done
, struct compound_state
*, cs
,
7955 OPEN_DOWNGRADE4res
*, resp
);
7959 * The logic behind this function is detailed in the NFSv4 RFC in the
7960 * SETCLIENTID operation description under IMPLEMENTATION. Refer to
7961 * that section for explicit guidance to server behavior for
7965 rfs4_op_setclientid(nfs_argop4
*argop
, nfs_resop4
*resop
,
7966 struct svc_req
*req
, struct compound_state
*cs
)
7968 SETCLIENTID4args
*args
= &argop
->nfs_argop4_u
.opsetclientid
;
7969 SETCLIENTID4res
*res
= &resop
->nfs_resop4_u
.opsetclientid
;
7970 rfs4_client_t
*cp
, *newcp
, *cp_confirmed
, *cp_unconfirmed
;
7976 DTRACE_NFSV4_2(op__setclientid__start
, struct compound_state
*, cs
,
7977 SETCLIENTID4args
*, args
);
7979 newcp
= cp_confirmed
= cp_unconfirmed
= NULL
;
7982 * Save the caller's IP address
7984 args
->client
.cl_addr
=
7985 (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
7988 * Record if it is a Solaris client that cannot handle referrals.
7990 if (strstr(args
->client
.id_val
, "Solaris") &&
7991 !strstr(args
->client
.id_val
, "+referrals")) {
7992 /* Add a "yes, it's downrev" record */
7994 ci
= rfs4_find_clntip(args
->client
.cl_addr
, &create
);
7996 rfs4_dbe_rele(ci
->ri_dbe
);
7998 /* Remove any previous record */
7999 rfs4_invalidate_clntip(args
->client
.cl_addr
);
8003 * In search of an EXISTING client matching the incoming
8004 * request to establish a new client identifier at the server
8007 cp
= rfs4_findclient(&args
->client
, &create
, NULL
);
8009 /* Should never happen */
8013 *cs
->statusp
= res
->status
= NFS4ERR_SERVERFAULT
;
8018 * Easiest case. Client identifier is newly created and is
8019 * unconfirmed. Also note that for this case, no other
8020 * entries exist for the client identifier. Nothing else to
8021 * check. Just setup the response and respond.
8024 *cs
->statusp
= res
->status
= NFS4_OK
;
8025 res
->SETCLIENTID4res_u
.resok4
.clientid
= cp
->rc_clientid
;
8026 res
->SETCLIENTID4res_u
.resok4
.setclientid_confirm
=
8027 cp
->rc_confirm_verf
;
8028 /* Setup callback information; CB_NULL confirmation later */
8029 rfs4_client_setcb(cp
, &args
->callback
, args
->callback_ident
);
8031 rfs4_client_rele(cp
);
8036 * An existing, confirmed client may exist but it may not have
8037 * been active for at least one lease period. If so, then
8038 * "close" the client and create a new client identifier
8040 if (rfs4_lease_expired(cp
)) {
8041 rfs4_client_close(cp
);
8045 if (cp
->rc_need_confirm
== TRUE
)
8046 cp_unconfirmed
= cp
;
8053 * We have a confirmed client, now check for an
8057 /* If creds don't match then client identifier is inuse */
8058 if (!creds_ok(cp_confirmed
->rc_cr_set
, req
, cs
)) {
8061 * Some one else has established this client
8062 * id. Try and say * who they are. We will use
8063 * the call back address supplied by * the
8066 *cs
->statusp
= res
->status
= NFS4ERR_CLID_INUSE
;
8068 addr
= netid
= NULL
;
8070 cbp
= &cp_confirmed
->rc_cbinfo
;
8071 if (cbp
->cb_callback
.cb_location
.r_addr
&&
8072 cbp
->cb_callback
.cb_location
.r_netid
) {
8073 cb_client4
*cbcp
= &cbp
->cb_callback
;
8075 len
= strlen(cbcp
->cb_location
.r_addr
)+1;
8076 addr
= kmem_alloc(len
, KM_SLEEP
);
8077 bcopy(cbcp
->cb_location
.r_addr
, addr
, len
);
8078 len
= strlen(cbcp
->cb_location
.r_netid
)+1;
8079 netid
= kmem_alloc(len
, KM_SLEEP
);
8080 bcopy(cbcp
->cb_location
.r_netid
, netid
, len
);
8083 res
->SETCLIENTID4res_u
.client_using
.r_addr
= addr
;
8084 res
->SETCLIENTID4res_u
.client_using
.r_netid
= netid
;
8086 rfs4_client_rele(cp_confirmed
);
8090 * Confirmed, creds match, and verifier matches; must
8091 * be an update of the callback info
8093 if (cp_confirmed
->rc_nfs_client
.verifier
==
8094 args
->client
.verifier
) {
8095 /* Setup callback information */
8096 rfs4_client_setcb(cp_confirmed
, &args
->callback
,
8097 args
->callback_ident
);
8099 /* everything okay -- move ahead */
8100 *cs
->statusp
= res
->status
= NFS4_OK
;
8101 res
->SETCLIENTID4res_u
.resok4
.clientid
=
8102 cp_confirmed
->rc_clientid
;
8104 /* update the confirm_verifier and return it */
8105 rfs4_client_scv_next(cp_confirmed
);
8106 res
->SETCLIENTID4res_u
.resok4
.setclientid_confirm
=
8107 cp_confirmed
->rc_confirm_verf
;
8109 rfs4_client_rele(cp_confirmed
);
8114 * Creds match but the verifier doesn't. Must search
8115 * for an unconfirmed client that would be replaced by
8119 cp_unconfirmed
= rfs4_findclient(&args
->client
, &create
,
8124 * At this point, we have taken care of the brand new client
8125 * struct, INUSE case, update of an existing, and confirmed
8130 * check to see if things have changed while we originally
8131 * picked up the client struct. If they have, then return and
8132 * retry the processing of this SETCLIENTID request.
8134 if (cp_unconfirmed
) {
8135 rfs4_dbe_lock(cp_unconfirmed
->rc_dbe
);
8136 if (!cp_unconfirmed
->rc_need_confirm
) {
8137 rfs4_dbe_unlock(cp_unconfirmed
->rc_dbe
);
8138 rfs4_client_rele(cp_unconfirmed
);
8140 rfs4_client_rele(cp_confirmed
);
8143 /* do away with the old unconfirmed one */
8144 rfs4_dbe_invalidate(cp_unconfirmed
->rc_dbe
);
8145 rfs4_dbe_unlock(cp_unconfirmed
->rc_dbe
);
8146 rfs4_client_rele(cp_unconfirmed
);
8147 cp_unconfirmed
= NULL
;
8151 * This search will temporarily hide the confirmed client
8152 * struct while a new client struct is created as the
8156 newcp
= rfs4_findclient(&args
->client
, &create
, cp_confirmed
);
8158 ASSERT(newcp
!= NULL
);
8160 if (newcp
== NULL
) {
8161 *cs
->statusp
= res
->status
= NFS4ERR_SERVERFAULT
;
8162 rfs4_client_rele(cp_confirmed
);
8167 * If one was not created, then a similar request must be in
8168 * process so release and start over with this one
8170 if (create
!= TRUE
) {
8171 rfs4_client_rele(newcp
);
8173 rfs4_client_rele(cp_confirmed
);
8177 *cs
->statusp
= res
->status
= NFS4_OK
;
8178 res
->SETCLIENTID4res_u
.resok4
.clientid
= newcp
->rc_clientid
;
8179 res
->SETCLIENTID4res_u
.resok4
.setclientid_confirm
=
8180 newcp
->rc_confirm_verf
;
8181 /* Setup callback information; CB_NULL confirmation later */
8182 rfs4_client_setcb(newcp
, &args
->callback
, args
->callback_ident
);
8184 newcp
->rc_cp_confirmed
= cp_confirmed
;
8186 rfs4_client_rele(newcp
);
8189 DTRACE_NFSV4_2(op__setclientid__done
, struct compound_state
*, cs
,
8190 SETCLIENTID4res
*, res
);
8195 rfs4_op_setclientid_confirm(nfs_argop4
*argop
, nfs_resop4
*resop
,
8196 struct svc_req
*req
, struct compound_state
*cs
)
8198 SETCLIENTID_CONFIRM4args
*args
=
8199 &argop
->nfs_argop4_u
.opsetclientid_confirm
;
8200 SETCLIENTID_CONFIRM4res
*res
=
8201 &resop
->nfs_resop4_u
.opsetclientid_confirm
;
8202 rfs4_client_t
*cp
, *cptoclose
= NULL
;
8204 DTRACE_NFSV4_2(op__setclientid__confirm__start
,
8205 struct compound_state
*, cs
,
8206 SETCLIENTID_CONFIRM4args
*, args
);
8208 *cs
->statusp
= res
->status
= NFS4_OK
;
8210 cp
= rfs4_findclient_by_id(args
->clientid
, TRUE
);
8213 *cs
->statusp
= res
->status
=
8214 rfs4_check_clientid(&args
->clientid
, 1);
8218 if (!creds_ok(cp
, req
, cs
)) {
8219 *cs
->statusp
= res
->status
= NFS4ERR_CLID_INUSE
;
8220 rfs4_client_rele(cp
);
8224 /* If the verifier doesn't match, the record doesn't match */
8225 if (cp
->rc_confirm_verf
!= args
->setclientid_confirm
) {
8226 *cs
->statusp
= res
->status
= NFS4ERR_STALE_CLIENTID
;
8227 rfs4_client_rele(cp
);
8231 rfs4_dbe_lock(cp
->rc_dbe
);
8232 cp
->rc_need_confirm
= FALSE
;
8233 if (cp
->rc_cp_confirmed
) {
8234 cptoclose
= cp
->rc_cp_confirmed
;
8235 cptoclose
->rc_ss_remove
= 1;
8236 cp
->rc_cp_confirmed
= NULL
;
8240 * Update the client's associated server instance, if it's changed
8241 * since the client was created.
8243 if (rfs4_servinst(cp
) != rfs4_cur_servinst
)
8244 rfs4_servinst_assign(cp
, rfs4_cur_servinst
);
8247 * Record clientid in stable storage.
8248 * Must be done after server instance has been assigned.
8252 rfs4_dbe_unlock(cp
->rc_dbe
);
8255 /* don't need to rele, client_close does it */
8256 rfs4_client_close(cptoclose
);
8258 /* If needed, initiate CB_NULL call for callback path */
8259 rfs4_deleg_cb_check(cp
);
8260 rfs4_update_lease(cp
);
8263 * Check to see if client can perform reclaims
8265 rfs4_ss_chkclid(cp
);
8267 rfs4_client_rele(cp
);
8270 DTRACE_NFSV4_2(op__setclientid__confirm__done
,
8271 struct compound_state
*, cs
,
8272 SETCLIENTID_CONFIRM4
*, res
);
8278 rfs4_op_close(nfs_argop4
*argop
, nfs_resop4
*resop
,
8279 struct svc_req
*req
, struct compound_state
*cs
)
8281 CLOSE4args
*args
= &argop
->nfs_argop4_u
.opclose
;
8282 CLOSE4res
*resp
= &resop
->nfs_resop4_u
.opclose
;
8286 DTRACE_NFSV4_2(op__close__start
, struct compound_state
*, cs
,
8287 CLOSE4args
*, args
);
8289 if (cs
->vp
== NULL
) {
8290 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
8294 status
= rfs4_get_state(&args
->open_stateid
, &sp
, RFS4_DBS_INVALID
);
8295 if (status
!= NFS4_OK
) {
8296 *cs
->statusp
= resp
->status
= status
;
8300 /* Ensure specified filehandle matches */
8301 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
8302 rfs4_state_rele(sp
);
8303 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8307 /* hold off other access to open_owner while we tinker */
8308 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
8310 switch (rfs4_check_stateid_seqid(sp
, &args
->open_stateid
)) {
8311 case NFS4_CHECK_STATEID_OKAY
:
8312 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
8313 resop
) != NFS4_CHKSEQ_OKAY
) {
8314 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8318 case NFS4_CHECK_STATEID_OLD
:
8319 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8321 case NFS4_CHECK_STATEID_BAD
:
8322 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8324 case NFS4_CHECK_STATEID_EXPIRED
:
8325 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
8327 case NFS4_CHECK_STATEID_CLOSED
:
8328 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8330 case NFS4_CHECK_STATEID_UNCONFIRMED
:
8331 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8333 case NFS4_CHECK_STATEID_REPLAY
:
8334 /* Check the sequence id for the open owner */
8335 switch (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
8337 case NFS4_CHKSEQ_OKAY
:
8339 * This is replayed stateid; if seqid matches
8340 * next expected, then client is using wrong seqid.
8343 case NFS4_CHKSEQ_BAD
:
8344 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8346 case NFS4_CHKSEQ_REPLAY
:
8348 * Note this case is the duplicate case so
8349 * resp->status is already set.
8351 *cs
->statusp
= resp
->status
;
8352 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8361 rfs4_dbe_lock(sp
->rs_dbe
);
8363 /* Update the stateid. */
8364 next_stateid(&sp
->rs_stateid
);
8365 resp
->open_stateid
= sp
->rs_stateid
.stateid
;
8367 rfs4_dbe_unlock(sp
->rs_dbe
);
8369 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8370 rfs4_update_open_sequence(sp
->rs_owner
);
8371 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
8373 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
8375 *cs
->statusp
= resp
->status
= status
;
8378 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
8379 rfs4_state_rele(sp
);
8381 DTRACE_NFSV4_2(op__close__done
, struct compound_state
*, cs
,
8386 * Manage the counts on the file struct and close all file locks
8390 rfs4_release_share_lock_state(rfs4_state_t
*sp
, cred_t
*cr
,
8391 bool_t close_of_client
)
8393 rfs4_file_t
*fp
= sp
->rs_finfo
;
8394 rfs4_lo_state_t
*lsp
;
8398 * If this call is part of the larger closing down of client
8399 * state then it is just easier to release all locks
8400 * associated with this client instead of going through each
8401 * individual file and cleaning locks there.
8403 if (close_of_client
) {
8404 if (sp
->rs_owner
->ro_client
->rc_unlksys_completed
== FALSE
&&
8405 !list_is_empty(&sp
->rs_lostatelist
) &&
8406 sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
) {
8407 /* Is the PxFS kernel module loaded? */
8408 if (lm_remove_file_locks
!= NULL
) {
8411 /* Encode the cluster nodeid in new sysid */
8412 new_sysid
= sp
->rs_owner
->ro_client
->rc_sysidt
;
8413 lm_set_nlmid_flk(&new_sysid
);
8416 * This PxFS routine removes file locks for a
8417 * client over all nodes of a cluster.
8419 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
,
8420 "lm_remove_file_locks(sysid=0x%x)\n",
8422 (*lm_remove_file_locks
)(new_sysid
);
8426 /* Release all locks for this client */
8427 flk
.l_type
= F_UNLKSYS
;
8432 sp
->rs_owner
->ro_client
->rc_sysidt
;
8434 (void) VOP_FRLOCK(sp
->rs_finfo
->rf_vp
, F_SETLK
,
8435 &flk
, F_REMOTELOCK
| FREAD
| FWRITE
,
8436 (u_offset_t
)0, NULL
, CRED(), NULL
);
8439 sp
->rs_owner
->ro_client
->rc_unlksys_completed
= TRUE
;
8444 * Release all locks on this file by this lock owner or at
8445 * least mark the locks as having been released
8447 for (lsp
= list_head(&sp
->rs_lostatelist
); lsp
!= NULL
;
8448 lsp
= list_next(&sp
->rs_lostatelist
, lsp
)) {
8449 lsp
->rls_locks_cleaned
= TRUE
;
8451 /* Was this already taken care of above? */
8452 if (!close_of_client
&&
8453 sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
)
8454 (void) cleanlocks(sp
->rs_finfo
->rf_vp
,
8455 lsp
->rls_locker
->rl_pid
,
8456 lsp
->rls_locker
->rl_client
->rc_sysidt
);
8460 * Release any shrlocks associated with this open state ID.
8461 * This must be done before the rfs4_state gets marked closed.
8463 if (sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
)
8464 (void) rfs4_unshare(sp
);
8466 if (sp
->rs_open_access
) {
8467 rfs4_dbe_lock(fp
->rf_dbe
);
8470 * Decrement the count for each access and deny bit that this
8471 * state has contributed to the file.
8472 * If the file counts go to zero
8473 * clear the appropriate bit in the appropriate mask.
8475 if (sp
->rs_open_access
& OPEN4_SHARE_ACCESS_READ
) {
8476 fp
->rf_access_read
--;
8478 if (fp
->rf_access_read
== 0)
8479 fp
->rf_share_access
&= ~OPEN4_SHARE_ACCESS_READ
;
8481 if (sp
->rs_open_access
& OPEN4_SHARE_ACCESS_WRITE
) {
8482 fp
->rf_access_write
--;
8484 if (fp
->rf_access_write
== 0)
8485 fp
->rf_share_access
&=
8486 ~OPEN4_SHARE_ACCESS_WRITE
;
8488 if (sp
->rs_open_deny
& OPEN4_SHARE_DENY_READ
) {
8490 if (fp
->rf_deny_read
== 0)
8491 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_READ
;
8493 if (sp
->rs_open_deny
& OPEN4_SHARE_DENY_WRITE
) {
8494 fp
->rf_deny_write
--;
8495 if (fp
->rf_deny_write
== 0)
8496 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_WRITE
;
8499 (void) VOP_CLOSE(fp
->rf_vp
, fflags
, 1, (offset_t
)0, cr
, NULL
);
8501 rfs4_dbe_unlock(fp
->rf_dbe
);
8503 sp
->rs_open_access
= 0;
8504 sp
->rs_open_deny
= 0;
8509 * lock_denied: Fill in a LOCK4deneid structure given an flock64 structure.
8512 lock_denied(LOCK4denied
*dp
, struct flock64
*flk
)
8514 rfs4_lockowner_t
*lo
;
8518 lo
= rfs4_findlockowner_by_pid(flk
->l_pid
);
8521 if (rfs4_lease_expired(cp
)) {
8522 rfs4_lockowner_rele(lo
);
8523 rfs4_dbe_hold(cp
->rc_dbe
);
8524 rfs4_client_close(cp
);
8525 return (NFS4ERR_EXPIRED
);
8527 dp
->owner
.clientid
= lo
->rl_owner
.clientid
;
8528 len
= lo
->rl_owner
.owner_len
;
8529 dp
->owner
.owner_val
= kmem_alloc(len
, KM_SLEEP
);
8530 bcopy(lo
->rl_owner
.owner_val
, dp
->owner
.owner_val
, len
);
8531 dp
->owner
.owner_len
= len
;
8532 rfs4_lockowner_rele(lo
);
8537 * Its not a NFS4 lock. We take advantage that the upper 32 bits
8538 * of the client id contain the boot time for a NFS4 lock. So we
8539 * fabricate and identity by setting clientid to the sysid, and
8540 * the lock owner to the pid.
8542 dp
->owner
.clientid
= flk
->l_sysid
;
8543 len
= sizeof (pid_t
);
8544 dp
->owner
.owner_len
= len
;
8545 dp
->owner
.owner_val
= kmem_alloc(len
, KM_SLEEP
);
8546 bcopy(&flk
->l_pid
, dp
->owner
.owner_val
, len
);
8548 dp
->offset
= flk
->l_start
;
8549 dp
->length
= flk
->l_len
;
8551 if (flk
->l_type
== F_RDLCK
)
8552 dp
->locktype
= READ_LT
;
8553 else if (flk
->l_type
== F_WRLCK
)
8554 dp
->locktype
= WRITE_LT
;
8556 return (NFS4ERR_INVAL
); /* no mapping from POSIX ltype to v4 */
8562 setlock(vnode_t
*vp
, struct flock64
*flock
, int flag
, cred_t
*cred
)
8570 cmd
= nbl_need_check(vp
) ? F_SETLK_NBMAND
: F_SETLK
;
8572 delaytime
= MSEC_TO_TICK_ROUNDUP(rfs4_lock_delay
);
8574 for (i
= 0; i
< rfs4_maxlock_tries
; i
++) {
8575 LOCK_PRINT(rfs4_debug
, "setlock", cmd
, flock
);
8576 error
= VOP_FRLOCK(vp
, cmd
,
8577 flock
, flag
, (u_offset_t
)0, NULL
, cred
, NULL
);
8579 if (error
!= EAGAIN
&& error
!= EACCES
)
8582 if (i
< rfs4_maxlock_tries
- 1) {
8588 if (error
== EAGAIN
|| error
== EACCES
) {
8589 /* Get the owner of the lock */
8591 LOCK_PRINT(rfs4_debug
, "setlock", F_GETLK
, &flk
);
8592 if (VOP_FRLOCK(vp
, F_GETLK
, &flk
, flag
,
8593 (u_offset_t
)0, NULL
, cred
, NULL
) == 0) {
8594 if (flk
.l_type
== F_UNLCK
) {
8595 /* No longer locked, retry */
8599 LOCK_PRINT(rfs4_debug
, "setlock(blocking lock)",
8609 rfs4_do_lock(rfs4_lo_state_t
*lsp
, nfs_lock_type4 locktype
,
8610 offset4 offset
, length4 length
, cred_t
*cred
, nfs_resop4
*resop
)
8613 rfs4_lockowner_t
*lo
= lsp
->rls_locker
;
8614 rfs4_state_t
*sp
= lsp
->rls_state
;
8615 struct flock64 flock
;
8622 if (rfs4_lease_expired(lo
->rl_client
)) {
8623 return (NFS4ERR_EXPIRED
);
8626 if ((status
= rfs4_client_sysid(lo
->rl_client
, &sysid
)) != NFS4_OK
)
8629 /* Check for zero length. To lock to end of file use all ones for V4 */
8631 return (NFS4ERR_INVAL
);
8632 else if (length
== (length4
)(~0))
8633 length
= 0; /* Posix to end of file */
8636 rfs4_dbe_lock(sp
->rs_dbe
);
8637 if (sp
->rs_closed
) {
8638 rfs4_dbe_unlock(sp
->rs_dbe
);
8639 return (NFS4ERR_OLD_STATEID
);
8642 if (resop
->resop
!= OP_LOCKU
) {
8646 if ((sp
->rs_share_access
8647 & OPEN4_SHARE_ACCESS_READ
) == 0) {
8648 rfs4_dbe_unlock(sp
->rs_dbe
);
8650 return (NFS4ERR_OPENMODE
);
8656 if ((sp
->rs_share_access
8657 & OPEN4_SHARE_ACCESS_WRITE
) == 0) {
8658 rfs4_dbe_unlock(sp
->rs_dbe
);
8660 return (NFS4ERR_OPENMODE
);
8668 flock
.l_type
= ltype
;
8669 flock
.l_whence
= 0; /* SEEK_SET */
8670 flock
.l_start
= offset
;
8671 flock
.l_len
= length
;
8672 flock
.l_sysid
= sysid
;
8673 flock
.l_pid
= lsp
->rls_locker
->rl_pid
;
8675 /* Note that length4 is uint64_t but l_len and l_start are off64_t */
8676 if (flock
.l_len
< 0 || flock
.l_start
< 0) {
8677 rfs4_dbe_unlock(sp
->rs_dbe
);
8678 return (NFS4ERR_INVAL
);
8682 * N.B. FREAD has the same value as OPEN4_SHARE_ACCESS_READ and
8683 * FWRITE has the same value as OPEN4_SHARE_ACCESS_WRITE.
8685 flag
= (int)sp
->rs_share_access
| F_REMOTELOCK
;
8687 error
= setlock(sp
->rs_finfo
->rf_vp
, &flock
, flag
, cred
);
8689 rfs4_dbe_lock(lsp
->rls_dbe
);
8690 next_stateid(&lsp
->rls_lockid
);
8691 rfs4_dbe_unlock(lsp
->rls_dbe
);
8694 rfs4_dbe_unlock(sp
->rs_dbe
);
8697 * N.B. We map error values to nfsv4 errors. This is differrent
8698 * than puterrno4 routine.
8705 case EACCES
: /* Old value */
8706 /* Can only get here if op is OP_LOCK */
8707 ASSERT(resop
->resop
== OP_LOCK
);
8708 lres
= &resop
->nfs_resop4_u
.oplock
;
8709 status
= NFS4ERR_DENIED
;
8710 if (lock_denied(&lres
->LOCK4res_u
.denied
, &flock
)
8715 status
= NFS4ERR_DELAY
;
8718 status
= NFS4ERR_INVAL
;
8721 status
= NFS4ERR_NOTSUPP
;
8724 status
= NFS4ERR_SERVERFAULT
;
8733 rfs4_op_lock(nfs_argop4
*argop
, nfs_resop4
*resop
,
8734 struct svc_req
*req
, struct compound_state
*cs
)
8736 LOCK4args
*args
= &argop
->nfs_argop4_u
.oplock
;
8737 LOCK4res
*resp
= &resop
->nfs_resop4_u
.oplock
;
8740 rfs4_lockowner_t
*lo
;
8742 rfs4_state_t
*sp
= NULL
;
8743 rfs4_lo_state_t
*lsp
= NULL
;
8744 bool_t ls_sw_held
= FALSE
;
8745 bool_t create
= TRUE
;
8746 bool_t lcreate
= TRUE
;
8747 bool_t dup_lock
= FALSE
;
8750 DTRACE_NFSV4_2(op__lock__start
, struct compound_state
*, cs
,
8753 if (cs
->vp
== NULL
) {
8754 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
8755 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8756 cs
, LOCK4res
*, resp
);
8760 if (args
->locker
.new_lock_owner
) {
8761 /* Create a new lockowner for this instance */
8762 open_to_lock_owner4
*olo
= &args
->locker
.locker4_u
.open_owner
;
8764 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
, "Creating new lock owner"));
8766 stateid
= &olo
->open_stateid
;
8767 status
= rfs4_get_state(stateid
, &sp
, RFS4_DBS_VALID
);
8768 if (status
!= NFS4_OK
) {
8769 NFS4_DEBUG(rfs4_debug
,
8770 (CE_NOTE
, "Get state failed in lock %d", status
));
8771 *cs
->statusp
= resp
->status
= status
;
8772 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8773 cs
, LOCK4res
*, resp
);
8777 /* Ensure specified filehandle matches */
8778 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
8779 rfs4_state_rele(sp
);
8780 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8781 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8782 cs
, LOCK4res
*, resp
);
8786 /* hold off other access to open_owner while we tinker */
8787 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
8789 switch (rc
= rfs4_check_stateid_seqid(sp
, stateid
)) {
8790 case NFS4_CHECK_STATEID_OLD
:
8791 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8793 case NFS4_CHECK_STATEID_BAD
:
8794 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8796 case NFS4_CHECK_STATEID_EXPIRED
:
8797 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
8799 case NFS4_CHECK_STATEID_UNCONFIRMED
:
8800 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8802 case NFS4_CHECK_STATEID_CLOSED
:
8803 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8805 case NFS4_CHECK_STATEID_OKAY
:
8806 case NFS4_CHECK_STATEID_REPLAY
:
8807 switch (rfs4_check_olo_seqid(olo
->open_seqid
,
8808 sp
->rs_owner
, resop
)) {
8809 case NFS4_CHKSEQ_OKAY
:
8810 if (rc
== NFS4_CHECK_STATEID_OKAY
)
8813 * This is replayed stateid; if seqid
8814 * matches next expected, then client
8815 * is using wrong seqid.
8818 case NFS4_CHKSEQ_BAD
:
8819 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8821 case NFS4_CHKSEQ_REPLAY
:
8822 /* This is a duplicate LOCK request */
8826 * For a duplicate we do not want to
8827 * create a new lockowner as it should
8829 * Turn off the lockowner create flag.
8836 lo
= rfs4_findlockowner(&olo
->lock_owner
, &lcreate
);
8838 NFS4_DEBUG(rfs4_debug
,
8839 (CE_NOTE
, "rfs4_op_lock: no lock owner"));
8840 *cs
->statusp
= resp
->status
= NFS4ERR_RESOURCE
;
8844 lsp
= rfs4_findlo_state_by_owner(lo
, sp
, &create
);
8846 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8848 * Only update theh open_seqid if this is not
8849 * a duplicate request
8851 if (dup_lock
== FALSE
) {
8852 rfs4_update_open_sequence(sp
->rs_owner
);
8855 NFS4_DEBUG(rfs4_debug
,
8856 (CE_NOTE
, "rfs4_op_lock: no state"));
8857 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
8858 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
8859 rfs4_lockowner_rele(lo
);
8864 * This is the new_lock_owner branch and the client is
8865 * supposed to be associating a new lock_owner with
8866 * the open file at this point. If we find that a
8867 * lock_owner/state association already exists and a
8868 * successful LOCK request was returned to the client,
8869 * an error is returned to the client since this is
8870 * not appropriate. The client should be using the
8871 * existing lock_owner branch.
8873 if (dup_lock
== FALSE
&& create
== FALSE
) {
8874 if (lsp
->rls_lock_completed
== TRUE
) {
8876 resp
->status
= NFS4ERR_BAD_SEQID
;
8877 rfs4_lockowner_rele(lo
);
8882 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8885 * Only update theh open_seqid if this is not
8886 * a duplicate request
8888 if (dup_lock
== FALSE
) {
8889 rfs4_update_open_sequence(sp
->rs_owner
);
8893 * If this is a duplicate lock request, just copy the
8894 * previously saved reply and return.
8896 if (dup_lock
== TRUE
) {
8897 /* verify that lock_seqid's match */
8898 if (lsp
->rls_seqid
!= olo
->lock_seqid
) {
8899 NFS4_DEBUG(rfs4_debug
,
8900 (CE_NOTE
, "rfs4_op_lock: Dup-Lock seqid bad"
8901 "lsp->seqid=%d old->seqid=%d",
8902 lsp
->rls_seqid
, olo
->lock_seqid
));
8903 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8905 rfs4_copy_reply(resop
, &lsp
->rls_reply
);
8907 * Make sure to copy the just
8908 * retrieved reply status into the
8909 * overall compound status
8911 *cs
->statusp
= resp
->status
;
8913 rfs4_lockowner_rele(lo
);
8917 rfs4_dbe_lock(lsp
->rls_dbe
);
8919 /* Make sure to update the lock sequence id */
8920 lsp
->rls_seqid
= olo
->lock_seqid
;
8922 NFS4_DEBUG(rfs4_debug
,
8923 (CE_NOTE
, "Lock seqid established as %d", lsp
->rls_seqid
));
8926 * This is used to signify the newly created lockowner
8927 * stateid and its sequence number. The checks for
8928 * sequence number and increment don't occur on the
8929 * very first lock request for a lockowner.
8931 lsp
->rls_skip_seqid_check
= TRUE
;
8933 /* hold off other access to lsp while we tinker */
8934 rfs4_sw_enter(&lsp
->rls_sw
);
8937 rfs4_dbe_unlock(lsp
->rls_dbe
);
8939 rfs4_lockowner_rele(lo
);
8941 stateid
= &args
->locker
.locker4_u
.lock_owner
.lock_stateid
;
8942 /* get lsp and hold the lock on the underlying file struct */
8943 if ((status
= rfs4_get_lo_state(stateid
, &lsp
, TRUE
))
8945 *cs
->statusp
= resp
->status
= status
;
8946 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8947 cs
, LOCK4res
*, resp
);
8950 create
= FALSE
; /* We didn't create lsp */
8952 /* Ensure specified filehandle matches */
8953 if (cs
->vp
!= lsp
->rls_state
->rs_finfo
->rf_vp
) {
8954 rfs4_lo_state_rele(lsp
, TRUE
);
8955 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8956 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8957 cs
, LOCK4res
*, resp
);
8961 /* hold off other access to lsp while we tinker */
8962 rfs4_sw_enter(&lsp
->rls_sw
);
8965 switch (rfs4_check_lo_stateid_seqid(lsp
, stateid
)) {
8967 * The stateid looks like it was okay (expected to be
8970 case NFS4_CHECK_STATEID_OKAY
:
8972 * The sequence id is now checked. Determine
8973 * if this is a replay or if it is in the
8974 * expected (next) sequence. In the case of a
8975 * replay, there are two replay conditions
8976 * that may occur. The first is the normal
8977 * condition where a LOCK is done with a
8978 * NFS4_OK response and the stateid is
8979 * updated. That case is handled below when
8980 * the stateid is identified as a REPLAY. The
8981 * second is the case where an error is
8982 * returned, like NFS4ERR_DENIED, and the
8983 * sequence number is updated but the stateid
8984 * is not updated. This second case is dealt
8985 * with here. So it may seem odd that the
8986 * stateid is okay but the sequence id is a
8987 * replay but it is okay.
8989 switch (rfs4_check_lock_seqid(
8990 args
->locker
.locker4_u
.lock_owner
.lock_seqid
,
8992 case NFS4_CHKSEQ_REPLAY
:
8993 if (resp
->status
!= NFS4_OK
) {
8995 * Here is our replay and need
8996 * to verify that the last
8997 * response was an error.
8999 *cs
->statusp
= resp
->status
;
9003 * This is done since the sequence id
9004 * looked like a replay but it didn't
9005 * pass our check so a BAD_SEQID is
9006 * returned as a result.
9009 case NFS4_CHKSEQ_BAD
:
9010 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
9012 case NFS4_CHKSEQ_OKAY
:
9013 /* Everything looks okay move ahead */
9017 case NFS4_CHECK_STATEID_OLD
:
9018 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
9020 case NFS4_CHECK_STATEID_BAD
:
9021 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
9023 case NFS4_CHECK_STATEID_EXPIRED
:
9024 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
9026 case NFS4_CHECK_STATEID_CLOSED
:
9027 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
9029 case NFS4_CHECK_STATEID_REPLAY
:
9030 switch (rfs4_check_lock_seqid(
9031 args
->locker
.locker4_u
.lock_owner
.lock_seqid
,
9033 case NFS4_CHKSEQ_OKAY
:
9035 * This is a replayed stateid; if
9036 * seqid matches the next expected,
9037 * then client is using wrong seqid.
9039 case NFS4_CHKSEQ_BAD
:
9040 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
9042 case NFS4_CHKSEQ_REPLAY
:
9043 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
9044 *cs
->statusp
= status
= resp
->status
;
9053 rfs4_update_lock_sequence(lsp
);
9054 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
9058 * NFS4 only allows locking on regular files, so
9059 * verify type of object.
9061 if (cs
->vp
->v_type
!= VREG
) {
9062 if (cs
->vp
->v_type
== VDIR
)
9063 status
= NFS4ERR_ISDIR
;
9065 status
= NFS4ERR_INVAL
;
9069 cp
= lsp
->rls_state
->rs_owner
->ro_client
;
9071 if (rfs4_clnt_in_grace(cp
) && !args
->reclaim
) {
9072 status
= NFS4ERR_GRACE
;
9076 if (rfs4_clnt_in_grace(cp
) && args
->reclaim
&& !cp
->rc_can_reclaim
) {
9077 status
= NFS4ERR_NO_GRACE
;
9081 if (!rfs4_clnt_in_grace(cp
) && args
->reclaim
) {
9082 status
= NFS4ERR_NO_GRACE
;
9086 if (lsp
->rls_state
->rs_finfo
->rf_dinfo
.rd_dtype
== OPEN_DELEGATE_WRITE
)
9089 status
= rfs4_do_lock(lsp
, args
->locktype
,
9090 args
->offset
, args
->length
, cs
->cr
, resop
);
9093 lsp
->rls_skip_seqid_check
= FALSE
;
9095 *cs
->statusp
= resp
->status
= status
;
9097 if (status
== NFS4_OK
) {
9098 resp
->LOCK4res_u
.lock_stateid
= lsp
->rls_lockid
.stateid
;
9099 lsp
->rls_lock_completed
= TRUE
;
9102 * Only update the "OPEN" response here if this was a new
9106 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
9108 rfs4_update_lock_resp(lsp
, resop
);
9113 rfs4_sw_exit(&lsp
->rls_sw
);
9115 * If an sp obtained, then the lsp does not represent
9116 * a lock on the file struct.
9119 rfs4_lo_state_rele(lsp
, FALSE
);
9121 rfs4_lo_state_rele(lsp
, TRUE
);
9124 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
9125 rfs4_state_rele(sp
);
9128 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*, cs
,
9132 /* free function for LOCK/LOCKT */
9134 lock_denied_free(nfs_resop4
*resop
)
9136 LOCK4denied
*dp
= NULL
;
9138 switch (resop
->resop
) {
9140 if (resop
->nfs_resop4_u
.oplock
.status
== NFS4ERR_DENIED
)
9141 dp
= &resop
->nfs_resop4_u
.oplock
.LOCK4res_u
.denied
;
9144 if (resop
->nfs_resop4_u
.oplockt
.status
== NFS4ERR_DENIED
)
9145 dp
= &resop
->nfs_resop4_u
.oplockt
.denied
;
9152 kmem_free(dp
->owner
.owner_val
, dp
->owner
.owner_len
);
9157 rfs4_op_locku(nfs_argop4
*argop
, nfs_resop4
*resop
,
9158 struct svc_req
*req
, struct compound_state
*cs
)
9160 LOCKU4args
*args
= &argop
->nfs_argop4_u
.oplocku
;
9161 LOCKU4res
*resp
= &resop
->nfs_resop4_u
.oplocku
;
9163 stateid4
*stateid
= &args
->lock_stateid
;
9164 rfs4_lo_state_t
*lsp
;
9166 DTRACE_NFSV4_2(op__locku__start
, struct compound_state
*, cs
,
9167 LOCKU4args
*, args
);
9169 if (cs
->vp
== NULL
) {
9170 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
9171 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
9176 if ((status
= rfs4_get_lo_state(stateid
, &lsp
, TRUE
)) != NFS4_OK
) {
9177 *cs
->statusp
= resp
->status
= status
;
9178 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
9183 /* Ensure specified filehandle matches */
9184 if (cs
->vp
!= lsp
->rls_state
->rs_finfo
->rf_vp
) {
9185 rfs4_lo_state_rele(lsp
, TRUE
);
9186 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
9187 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
9192 /* hold off other access to lsp while we tinker */
9193 rfs4_sw_enter(&lsp
->rls_sw
);
9195 switch (rfs4_check_lo_stateid_seqid(lsp
, stateid
)) {
9196 case NFS4_CHECK_STATEID_OKAY
:
9197 if (rfs4_check_lock_seqid(args
->seqid
, lsp
, resop
)
9198 != NFS4_CHKSEQ_OKAY
) {
9199 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
9203 case NFS4_CHECK_STATEID_OLD
:
9204 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
9206 case NFS4_CHECK_STATEID_BAD
:
9207 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
9209 case NFS4_CHECK_STATEID_EXPIRED
:
9210 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
9212 case NFS4_CHECK_STATEID_CLOSED
:
9213 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
9215 case NFS4_CHECK_STATEID_REPLAY
:
9216 switch (rfs4_check_lock_seqid(args
->seqid
, lsp
, resop
)) {
9217 case NFS4_CHKSEQ_OKAY
:
9219 * This is a replayed stateid; if
9220 * seqid matches the next expected,
9221 * then client is using wrong seqid.
9223 case NFS4_CHKSEQ_BAD
:
9224 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
9226 case NFS4_CHKSEQ_REPLAY
:
9227 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
9228 *cs
->statusp
= status
= resp
->status
;
9237 rfs4_update_lock_sequence(lsp
);
9238 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
9241 * NFS4 only allows locking on regular files, so
9242 * verify type of object.
9244 if (cs
->vp
->v_type
!= VREG
) {
9245 if (cs
->vp
->v_type
== VDIR
)
9246 status
= NFS4ERR_ISDIR
;
9248 status
= NFS4ERR_INVAL
;
9252 if (rfs4_clnt_in_grace(lsp
->rls_state
->rs_owner
->ro_client
)) {
9253 status
= NFS4ERR_GRACE
;
9257 status
= rfs4_do_lock(lsp
, args
->locktype
,
9258 args
->offset
, args
->length
, cs
->cr
, resop
);
9261 *cs
->statusp
= resp
->status
= status
;
9263 if (status
== NFS4_OK
)
9264 resp
->lock_stateid
= lsp
->rls_lockid
.stateid
;
9266 rfs4_update_lock_resp(lsp
, resop
);
9269 rfs4_sw_exit(&lsp
->rls_sw
);
9270 rfs4_lo_state_rele(lsp
, TRUE
);
9272 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
9277 * LOCKT is a best effort routine, the client can not be guaranteed that
9278 * the status return is still in effect by the time the reply is received.
9279 * They are numerous race conditions in this routine, but we are not required
9280 * and can not be accurate.
9284 rfs4_op_lockt(nfs_argop4
*argop
, nfs_resop4
*resop
,
9285 struct svc_req
*req
, struct compound_state
*cs
)
9287 LOCKT4args
*args
= &argop
->nfs_argop4_u
.oplockt
;
9288 LOCKT4res
*resp
= &resop
->nfs_resop4_u
.oplockt
;
9289 rfs4_lockowner_t
*lo
;
9291 bool_t create
= FALSE
;
9294 int flag
= FREAD
| FWRITE
;
9296 length4 posix_length
;
9300 DTRACE_NFSV4_2(op__lockt__start
, struct compound_state
*, cs
,
9301 LOCKT4args
*, args
);
9303 if (cs
->vp
== NULL
) {
9304 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
9309 * NFS4 only allows locking on regular files, so
9310 * verify type of object.
9312 if (cs
->vp
->v_type
!= VREG
) {
9313 if (cs
->vp
->v_type
== VDIR
)
9314 *cs
->statusp
= resp
->status
= NFS4ERR_ISDIR
;
9316 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
9321 * Check out the clientid to ensure the server knows about it
9322 * so that we correctly inform the client of a server reboot.
9324 if ((cp
= rfs4_findclient_by_id(args
->owner
.clientid
, FALSE
))
9326 *cs
->statusp
= resp
->status
=
9327 rfs4_check_clientid(&args
->owner
.clientid
, 0);
9330 if (rfs4_lease_expired(cp
)) {
9331 rfs4_client_close(cp
);
9333 * Protocol doesn't allow returning NFS4ERR_STALE as
9334 * other operations do on this check so STALE_CLIENTID
9335 * is returned instead
9337 *cs
->statusp
= resp
->status
= NFS4ERR_STALE_CLIENTID
;
9341 if (rfs4_clnt_in_grace(cp
) && !(cp
->rc_can_reclaim
)) {
9342 *cs
->statusp
= resp
->status
= NFS4ERR_GRACE
;
9343 rfs4_client_rele(cp
);
9346 rfs4_client_rele(cp
);
9348 resp
->status
= NFS4_OK
;
9350 switch (args
->locktype
) {
9361 posix_length
= args
->length
;
9362 /* Check for zero length. To lock to end of file use all ones for V4 */
9363 if (posix_length
== 0) {
9364 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
9366 } else if (posix_length
== (length4
)(~0)) {
9367 posix_length
= 0; /* Posix to end of file */
9370 /* Find or create a lockowner */
9371 lo
= rfs4_findlockowner(&args
->owner
, &create
);
9376 rfs4_client_sysid(lo
->rl_client
, &sysid
)) != NFS4_OK
)
9380 sysid
= lockt_sysid
;
9384 flk
.l_whence
= 0; /* SEEK_SET */
9385 flk
.l_start
= args
->offset
;
9386 flk
.l_len
= posix_length
;
9387 flk
.l_sysid
= sysid
;
9389 flag
|= F_REMOTELOCK
;
9391 LOCK_PRINT(rfs4_debug
, "rfs4_op_lockt", F_GETLK
, &flk
);
9393 /* Note that length4 is uint64_t but l_len and l_start are off64_t */
9394 if (flk
.l_len
< 0 || flk
.l_start
< 0) {
9395 resp
->status
= NFS4ERR_INVAL
;
9398 error
= VOP_FRLOCK(cs
->vp
, F_GETLK
, &flk
, flag
, (u_offset_t
)0,
9399 NULL
, cs
->cr
, NULL
);
9402 * N.B. We map error values to nfsv4 errors. This is differrent
9403 * than puterrno4 routine.
9407 if (flk
.l_type
== F_UNLCK
)
9408 resp
->status
= NFS4_OK
;
9410 if (lock_denied(&resp
->denied
, &flk
) == NFS4ERR_EXPIRED
)
9412 resp
->status
= NFS4ERR_DENIED
;
9416 resp
->status
= NFS4ERR_INVAL
;
9419 resp
->status
= NFS4ERR_NOTSUPP
;
9422 cmn_err(CE_WARN
, "rfs4_op_lockt: unexpected errno (%d)",
9424 resp
->status
= NFS4ERR_SERVERFAULT
;
9430 rfs4_lockowner_rele(lo
);
9431 *cs
->statusp
= resp
->status
;
9433 DTRACE_NFSV4_2(op__lockt__done
, struct compound_state
*, cs
,
9438 rfs4_share(rfs4_state_t
*sp
, uint32_t access
, uint32_t deny
)
9444 struct shr_locowner shr_loco
;
9447 ASSERT(rfs4_dbe_islocked(sp
->rs_dbe
));
9448 ASSERT(sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
);
9451 return (NFS4ERR_OLD_STATEID
);
9453 vp
= sp
->rs_finfo
->rf_vp
;
9456 shr
.s_access
= shr
.s_deny
= 0;
9458 if (access
& OPEN4_SHARE_ACCESS_READ
) {
9460 shr
.s_access
|= F_RDACC
;
9462 if (access
& OPEN4_SHARE_ACCESS_WRITE
) {
9464 shr
.s_access
|= F_WRACC
;
9466 ASSERT(shr
.s_access
);
9468 if (deny
& OPEN4_SHARE_DENY_READ
)
9469 shr
.s_deny
|= F_RDDNY
;
9470 if (deny
& OPEN4_SHARE_DENY_WRITE
)
9471 shr
.s_deny
|= F_WRDNY
;
9473 shr
.s_pid
= rfs4_dbe_getid(sp
->rs_owner
->ro_dbe
);
9474 shr
.s_sysid
= sp
->rs_owner
->ro_client
->rc_sysidt
;
9475 shr_loco
.sl_pid
= shr
.s_pid
;
9476 shr_loco
.sl_id
= shr
.s_sysid
;
9477 shr
.s_owner
= (caddr_t
)&shr_loco
;
9478 shr
.s_own_len
= sizeof (shr_loco
);
9480 cmd
= nbl_need_check(vp
) ? F_SHARE_NBMAND
: F_SHARE
;
9482 err
= VOP_SHRLOCK(vp
, cmd
, &shr
, fflags
, CRED(), NULL
);
9485 err
= NFS4ERR_SHARE_DENIED
;
9487 err
= puterrno4(err
);
9491 sp
->rs_share_access
|= access
;
9492 sp
->rs_share_deny
|= deny
;
9498 rfs4_unshare(rfs4_state_t
*sp
)
9502 struct shr_locowner shr_loco
;
9504 ASSERT(rfs4_dbe_islocked(sp
->rs_dbe
));
9506 if (sp
->rs_closed
|| sp
->rs_share_access
== 0)
9509 ASSERT(sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
);
9510 ASSERT(sp
->rs_finfo
->rf_vp
);
9512 shr
.s_access
= shr
.s_deny
= 0;
9513 shr
.s_pid
= rfs4_dbe_getid(sp
->rs_owner
->ro_dbe
);
9514 shr
.s_sysid
= sp
->rs_owner
->ro_client
->rc_sysidt
;
9515 shr_loco
.sl_pid
= shr
.s_pid
;
9516 shr_loco
.sl_id
= shr
.s_sysid
;
9517 shr
.s_owner
= (caddr_t
)&shr_loco
;
9518 shr
.s_own_len
= sizeof (shr_loco
);
9520 err
= VOP_SHRLOCK(sp
->rs_finfo
->rf_vp
, F_UNSHARE
, &shr
, 0, CRED(),
9523 err
= puterrno4(err
);
9527 sp
->rs_share_access
= 0;
9528 sp
->rs_share_deny
= 0;
9535 rdma_setup_read_data4(READ4args
*args
, READ4res
*rok
)
9538 count4 count
= rok
->data_len
;
9542 if (rdma_setup_read_chunks(wcl
, count
, &wlist_len
) == FALSE
) {
9546 rok
->wlist_len
= wlist_len
;
9551 /* tunable to disable server referrals */
9552 int rfs4_no_referrals
= 0;
9555 * Find an NFS record in reparse point data.
9556 * Returns 0 for success and <0 or an errno value on failure.
9559 vn_find_nfs_record(vnode_t
*vp
, nvlist_t
**nvlp
, char **svcp
, char **datap
)
9566 if ((nvl
= reparse_init()) == NULL
)
9569 if ((err
= reparse_vnode_parse(vp
, nvl
)) != 0) {
9575 while ((curr
= nvlist_next_nvpair(nvl
, curr
)) != NULL
) {
9576 if ((stype
= nvpair_name(curr
)) == NULL
) {
9580 if (strncasecmp(stype
, "NFS", 3) == 0)
9584 if ((curr
== NULL
) ||
9585 (nvpair_value_string(curr
, &val
))) {
9596 vn_is_nfs_reparse(vnode_t
*vp
, cred_t
*cr
)
9601 if (rfs4_no_referrals
!= 0)
9604 if (vn_is_reparse(vp
, cr
, NULL
) == B_FALSE
)
9607 if (vn_find_nfs_record(vp
, &nvl
, &s
, &d
) != 0)
9616 * There is a user-level copy of this routine in ref_subr.c.
9617 * Changes should be kept in sync.
9620 nfs4_create_components(char *path
, component4
*comp4
)
9622 int slen
, plen
, ncomp
;
9623 char *ori_path
, *nxtc
, buf
[MAXNAMELEN
];
9628 plen
= strlen(path
) + 1; /* include the terminator */
9632 /* count number of components in the path */
9633 for (nxtc
= path
; nxtc
< ori_path
+ plen
; nxtc
++) {
9634 if (*nxtc
== '/' || *nxtc
== '\0' || *nxtc
== '\n') {
9635 if ((slen
= nxtc
- path
) == 0) {
9640 if (comp4
!= NULL
) {
9641 bcopy(path
, buf
, slen
);
9643 (void) str_to_utf8(buf
, &comp4
[ncomp
]);
9646 ncomp
++; /* 1 valid component */
9649 if (*nxtc
== '\0' || *nxtc
== '\n')
9657 * There is a user-level copy of this routine in ref_subr.c.
9658 * Changes should be kept in sync.
9661 make_pathname4(char *path
, pathname4
*pathname
)
9666 if (pathname
== NULL
)
9670 pathname
->pathname4_val
= NULL
;
9671 pathname
->pathname4_len
= 0;
9675 /* count number of components to alloc buffer */
9676 if ((ncomp
= nfs4_create_components(path
, NULL
)) == 0) {
9677 pathname
->pathname4_val
= NULL
;
9678 pathname
->pathname4_len
= 0;
9681 comp4
= kmem_zalloc(ncomp
* sizeof (component4
), KM_SLEEP
);
9683 /* copy components into allocated buffer */
9684 ncomp
= nfs4_create_components(path
, comp4
);
9686 pathname
->pathname4_val
= comp4
;
9687 pathname
->pathname4_len
= ncomp
;
9692 #define xdr_fs_locations4 xdr_fattr4_fs_locations
9695 fetch_referral(vnode_t
*vp
, cred_t
*cr
)
9698 char *stype
, *sdata
;
9699 fs_locations4
*result
;
9706 * Check attrs to ensure it's a reparse point
9708 if (vn_is_reparse(vp
, cr
, NULL
) == B_FALSE
)
9712 * Look for an NFS record and get the type and data
9714 if (vn_find_nfs_record(vp
, &nvl
, &stype
, &sdata
) != 0)
9718 * With the type and data, upcall to get the referral
9720 bufsize
= sizeof (buf
);
9721 bzero(buf
, sizeof (buf
));
9722 err
= reparse_kderef((const char *)stype
, (const char *)sdata
,
9726 DTRACE_PROBE4(nfs4serv__func__referral__upcall
,
9727 char *, stype
, char *, sdata
, char *, buf
, int, err
);
9730 "reparsed daemon not running: unable to get referral (%d)",
9736 * We get an XDR'ed record back from the kderef call
9738 xdrmem_create(&xdr
, buf
, bufsize
, XDR_DECODE
);
9739 result
= kmem_alloc(sizeof (fs_locations4
), KM_SLEEP
);
9740 err
= xdr_fs_locations4(&xdr
, result
);
9743 DTRACE_PROBE1(nfs4serv__func__referral__upcall__xdrfail
,
9749 * Look at path to recover fs_root, ignoring the leading '/'
9751 (void) make_pathname4(vp
->v_path
, &result
->fs_root
);
9757 build_symlink(vnode_t
*vp
, cred_t
*cr
, size_t *strsz
)
9761 char *server
, *path
, *symbuf
;
9762 static char *prefix
= "/net/";
9763 int i
, size
, npaths
;
9766 /* Get the referral */
9767 if ((fsl
= fetch_referral(vp
, cr
)) == NULL
)
9770 /* Deal with only the first location and first server */
9771 fs
= &fsl
->locations_val
[0];
9772 server
= utf8_to_str(&fs
->server_val
[0], &len
, NULL
);
9773 if (server
== NULL
) {
9774 rfs4_free_fs_locations4(fsl
);
9775 kmem_free(fsl
, sizeof (fs_locations4
));
9779 /* Figure out size for "/net/" + host + /path/path/path + NULL */
9780 size
= strlen(prefix
) + len
;
9781 for (i
= 0; i
< fs
->rootpath
.pathname4_len
; i
++)
9782 size
+= fs
->rootpath
.pathname4_val
[i
].utf8string_len
+ 1;
9784 /* Allocate the symlink buffer and fill it */
9785 symbuf
= kmem_zalloc(size
, KM_SLEEP
);
9786 (void) strcat(symbuf
, prefix
);
9787 (void) strcat(symbuf
, server
);
9788 kmem_free(server
, len
);
9791 for (i
= 0; i
< fs
->rootpath
.pathname4_len
; i
++) {
9792 path
= utf8_to_str(&fs
->rootpath
.pathname4_val
[i
], &len
, NULL
);
9795 (void) strcat(symbuf
, "/");
9796 (void) strcat(symbuf
, path
);
9798 kmem_free(path
, len
);
9801 rfs4_free_fs_locations4(fsl
);
9802 kmem_free(fsl
, sizeof (fs_locations4
));
9810 * Check to see if we have a downrev Solaris client, so that we
9811 * can send it a symlink instead of a referral.
9814 client_is_downrev(struct svc_req
*req
)
9816 struct sockaddr
*ca
;
9818 bool_t create
= FALSE
;
9821 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
9823 ci
= rfs4_find_clntip(ca
, &create
);
9826 is_downrev
= ci
->ri_no_referrals
;
9827 rfs4_dbe_rele(ci
->ri_dbe
);
9828 return (is_downrev
);