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]
23 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
29 * Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/systm.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 <sys/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 #define RFS4_MAXLOCK_TRIES 4 /* Try to get the lock this many times */
81 static int rfs4_maxlock_tries
= RFS4_MAXLOCK_TRIES
;
82 #define RFS4_LOCK_DELAY 10 /* Milliseconds */
83 static clock_t rfs4_lock_delay
= RFS4_LOCK_DELAY
;
84 extern struct svc_ops rdma_svc_ops
;
85 extern int nfs_loaned_buffers
;
88 static int rdma_setup_read_data4(READ4args
*, READ4res
*);
91 * Used to bump the stateid4.seqid value and show changes in the stateid
93 #define next_stateid(sp) (++(sp)->bits.chgseq)
96 * RFS4_MINLEN_ENTRY4: XDR-encoded size of smallest possible dirent.
97 * This is used to return NFS4ERR_TOOSMALL when clients specify
98 * maxcount that isn't large enough to hold the smallest possible
101 * sizeof cookie (8 bytes) +
102 * sizeof name_len (4 bytes) +
103 * sizeof smallest (padded) name (4 bytes) +
104 * sizeof bitmap4_len (12 bytes) + NOTE: we always encode len=2 bm4
105 * sizeof attrlist4_len (4 bytes) +
106 * sizeof next boolean (4 bytes)
108 * RFS4_MINLEN_RDDIR4: XDR-encoded size of READDIR op reply containing
109 * the smallest possible entry4 (assumes no attrs requested).
110 * sizeof nfsstat4 (4 bytes) +
111 * sizeof verifier4 (8 bytes) +
112 * sizeof entry4list bool (4 bytes) +
113 * sizeof entry4 (36 bytes) +
114 * sizeof eof bool (4 bytes)
116 * RFS4_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
117 * fop_readdir. Its value is the size of the maximum possible dirent
118 * for solaris. The DIRENT_RECLEN macro returns the size of dirent
119 * required for a given name length. MAXNAMELEN is the maximum
120 * filename length allowed in Solaris. The first two DIRENT_RECLEN()
121 * macros are to allow for . and .. entries -- just a minor tweak to try
122 * and guarantee that buffer we give to fop_readdir will be large enough
123 * to hold ., .., and the largest possible solaris dirent64.
125 #define RFS4_MINLEN_ENTRY4 36
126 #define RFS4_MINLEN_RDDIR4 (4 + NFS4_VERIFIER_SIZE + 4 + RFS4_MINLEN_ENTRY4 + 4)
127 #define RFS4_MINLEN_RDDIR_BUF \
128 (DIRENT_RECLEN(1) + DIRENT_RECLEN(2) + DIRENT_RECLEN(MAXNAMELEN))
131 * It would be better to pad to 4 bytes since that's what XDR would do,
132 * but the dirents UFS gives us are already padded to 8, so just take
133 * what we're given. Dircount is only a hint anyway. Currently the
134 * solaris kernel is ASCII only, so there's no point in calling the
137 * dirent64: named padded to provide 8 byte struct alignment
138 * d_ino(8) + d_off(8) + d_reclen(2) + d_name(namelen + null(1) + pad)
140 * cookie: uint64_t + utf8namelen: uint_t + utf8name padded to 8 bytes
143 #define DIRENT64_TO_DIRCOUNT(dp) \
144 (3 * BYTES_PER_XDR_UNIT + DIRENT_NAMELEN((dp)->d_reclen))
146 time_t rfs4_start_time
; /* Initialized in rfs4_srvrinit */
148 static sysid_t lockt_sysid
; /* dummy sysid for all LOCKT calls */
150 u_longlong_t nfs4_srv_caller_id
;
151 uint_t nfs4_srv_vkey
= 0;
153 verifier4 Write4verf
;
154 verifier4 Readdir4verf
;
156 void rfs4_init_compound_state(struct compound_state
*);
158 static void nullfree(caddr_t
);
159 static void rfs4_op_inval(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
160 struct compound_state
*);
161 static void rfs4_op_access(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
162 struct compound_state
*);
163 static void rfs4_op_close(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
164 struct compound_state
*);
165 static void rfs4_op_commit(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
166 struct compound_state
*);
167 static void rfs4_op_create(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
168 struct compound_state
*);
169 static void rfs4_op_create_free(nfs_resop4
*resop
);
170 static void rfs4_op_delegreturn(nfs_argop4
*, nfs_resop4
*,
171 struct svc_req
*, struct compound_state
*);
172 static void rfs4_op_delegpurge(nfs_argop4
*, nfs_resop4
*,
173 struct svc_req
*, struct compound_state
*);
174 static void rfs4_op_getattr(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
175 struct compound_state
*);
176 static void rfs4_op_getattr_free(nfs_resop4
*);
177 static void rfs4_op_getfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
178 struct compound_state
*);
179 static void rfs4_op_getfh_free(nfs_resop4
*);
180 static void rfs4_op_illegal(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
181 struct compound_state
*);
182 static void rfs4_op_link(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
183 struct compound_state
*);
184 static void rfs4_op_lock(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
185 struct compound_state
*);
186 static void lock_denied_free(nfs_resop4
*);
187 static void rfs4_op_locku(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
188 struct compound_state
*);
189 static void rfs4_op_lockt(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
190 struct compound_state
*);
191 static void rfs4_op_lookup(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
192 struct compound_state
*);
193 static void rfs4_op_lookupp(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
194 struct compound_state
*);
195 static void rfs4_op_openattr(nfs_argop4
*argop
, nfs_resop4
*resop
,
196 struct svc_req
*req
, struct compound_state
*cs
);
197 static void rfs4_op_nverify(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
198 struct compound_state
*);
199 static void rfs4_op_open(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
200 struct compound_state
*);
201 static void rfs4_op_open_confirm(nfs_argop4
*, nfs_resop4
*,
202 struct svc_req
*, struct compound_state
*);
203 static void rfs4_op_open_downgrade(nfs_argop4
*, nfs_resop4
*,
204 struct svc_req
*, struct compound_state
*);
205 static void rfs4_op_putfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
206 struct compound_state
*);
207 static void rfs4_op_putpubfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
208 struct compound_state
*);
209 static void rfs4_op_putrootfh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
210 struct compound_state
*);
211 static void rfs4_op_read(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
212 struct compound_state
*);
213 static void rfs4_op_read_free(nfs_resop4
*);
214 static void rfs4_op_readdir_free(nfs_resop4
*resop
);
215 static void rfs4_op_readlink(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
216 struct compound_state
*);
217 static void rfs4_op_readlink_free(nfs_resop4
*);
218 static void rfs4_op_release_lockowner(nfs_argop4
*, nfs_resop4
*,
219 struct svc_req
*, struct compound_state
*);
220 static void rfs4_op_remove(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
221 struct compound_state
*);
222 static void rfs4_op_rename(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
223 struct compound_state
*);
224 static void rfs4_op_renew(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
225 struct compound_state
*);
226 static void rfs4_op_restorefh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
227 struct compound_state
*);
228 static void rfs4_op_savefh(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
229 struct compound_state
*);
230 static void rfs4_op_setattr(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
231 struct compound_state
*);
232 static void rfs4_op_verify(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
233 struct compound_state
*);
234 static void rfs4_op_write(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
235 struct compound_state
*);
236 static void rfs4_op_setclientid(nfs_argop4
*, nfs_resop4
*,
237 struct svc_req
*, struct compound_state
*);
238 static void rfs4_op_setclientid_confirm(nfs_argop4
*, nfs_resop4
*,
239 struct svc_req
*req
, struct compound_state
*);
240 static void rfs4_op_secinfo(nfs_argop4
*, nfs_resop4
*, struct svc_req
*,
241 struct compound_state
*);
242 static void rfs4_op_secinfo_free(nfs_resop4
*);
244 static nfsstat4
check_open_access(uint32_t,
245 struct compound_state
*, struct svc_req
*);
246 nfsstat4
rfs4_client_sysid(rfs4_client_t
*, sysid_t
*);
247 void rfs4_ss_clid(rfs4_client_t
*);
250 * translation table for attrs
252 struct nfs4_ntov_table
{
253 union nfs4_attr_u
*na
;
254 uint8_t amap
[NFS4_MAXNUM_ATTRS
];
259 static void nfs4_ntov_table_init(struct nfs4_ntov_table
*ntovp
);
260 static void nfs4_ntov_table_free(struct nfs4_ntov_table
*ntovp
,
261 struct nfs4_svgetit_arg
*sargp
);
263 static nfsstat4
do_rfs4_set_attrs(bitmap4
*resp
, fattr4
*fattrp
,
264 struct compound_state
*cs
, struct nfs4_svgetit_arg
*sargp
,
265 struct nfs4_ntov_table
*ntovp
, nfs4_attr_cmd_t cmd
);
267 rfs4_servinst_t
*rfs4_cur_servinst
= NULL
; /* current server instance */
268 kmutex_t rfs4_servinst_lock
; /* protects linked list */
269 int rfs4_seen_first_compound
; /* set first time we see one */
272 * NFS4 op dispatch table
276 void (*dis_proc
)(); /* proc to call */
277 void (*dis_resfree
)(); /* frees space allocated by proc */
278 int dis_flags
; /* RPC_IDEMPOTENT, etc... */
281 static struct rfsv4disp rfsv4disptab
[] = {
287 {rfs4_op_illegal
, nullfree
, 0},
290 {rfs4_op_illegal
, nullfree
, 0},
293 {rfs4_op_illegal
, nullfree
, 0},
296 {rfs4_op_access
, nullfree
, RPC_IDEMPOTENT
},
299 {rfs4_op_close
, nullfree
, 0},
302 {rfs4_op_commit
, nullfree
, RPC_IDEMPOTENT
},
305 {rfs4_op_create
, nullfree
, 0},
307 /* OP_DELEGPURGE = 7 */
308 {rfs4_op_delegpurge
, nullfree
, 0},
310 /* OP_DELEGRETURN = 8 */
311 {rfs4_op_delegreturn
, nullfree
, 0},
314 {rfs4_op_getattr
, rfs4_op_getattr_free
, RPC_IDEMPOTENT
},
317 {rfs4_op_getfh
, rfs4_op_getfh_free
, RPC_ALL
},
320 {rfs4_op_link
, nullfree
, 0},
323 {rfs4_op_lock
, lock_denied_free
, 0},
326 {rfs4_op_lockt
, lock_denied_free
, 0},
329 {rfs4_op_locku
, nullfree
, 0},
332 {rfs4_op_lookup
, nullfree
, (RPC_IDEMPOTENT
| RPC_PUBLICFH_OK
)},
334 /* OP_LOOKUPP = 16 */
335 {rfs4_op_lookupp
, nullfree
, (RPC_IDEMPOTENT
| RPC_PUBLICFH_OK
)},
337 /* OP_NVERIFY = 17 */
338 {rfs4_op_nverify
, nullfree
, RPC_IDEMPOTENT
},
341 {rfs4_op_open
, rfs4_free_reply
, 0},
343 /* OP_OPENATTR = 19 */
344 {rfs4_op_openattr
, nullfree
, 0},
346 /* OP_OPEN_CONFIRM = 20 */
347 {rfs4_op_open_confirm
, nullfree
, 0},
349 /* OP_OPEN_DOWNGRADE = 21 */
350 {rfs4_op_open_downgrade
, nullfree
, 0},
352 /* OP_OPEN_PUTFH = 22 */
353 {rfs4_op_putfh
, nullfree
, RPC_ALL
},
355 /* OP_PUTPUBFH = 23 */
356 {rfs4_op_putpubfh
, nullfree
, RPC_ALL
},
358 /* OP_PUTROOTFH = 24 */
359 {rfs4_op_putrootfh
, nullfree
, RPC_ALL
},
362 {rfs4_op_read
, rfs4_op_read_free
, RPC_IDEMPOTENT
},
364 /* OP_READDIR = 26 */
365 {rfs4_op_readdir
, rfs4_op_readdir_free
, RPC_IDEMPOTENT
},
367 /* OP_READLINK = 27 */
368 {rfs4_op_readlink
, rfs4_op_readlink_free
, RPC_IDEMPOTENT
},
371 {rfs4_op_remove
, nullfree
, 0},
374 {rfs4_op_rename
, nullfree
, 0},
377 {rfs4_op_renew
, nullfree
, 0},
379 /* OP_RESTOREFH = 31 */
380 {rfs4_op_restorefh
, nullfree
, RPC_ALL
},
383 {rfs4_op_savefh
, nullfree
, RPC_ALL
},
385 /* OP_SECINFO = 33 */
386 {rfs4_op_secinfo
, rfs4_op_secinfo_free
, 0},
388 /* OP_SETATTR = 34 */
389 {rfs4_op_setattr
, nullfree
, 0},
391 /* OP_SETCLIENTID = 35 */
392 {rfs4_op_setclientid
, nullfree
, 0},
394 /* OP_SETCLIENTID_CONFIRM = 36 */
395 {rfs4_op_setclientid_confirm
, nullfree
, 0},
398 {rfs4_op_verify
, nullfree
, RPC_IDEMPOTENT
},
401 {rfs4_op_write
, nullfree
, 0},
403 /* OP_RELEASE_LOCKOWNER = 39 */
404 {rfs4_op_release_lockowner
, nullfree
, 0},
407 static uint_t rfsv4disp_cnt
= sizeof (rfsv4disptab
) / sizeof (rfsv4disptab
[0]);
409 #define OP_ILLEGAL_IDX (rfsv4disp_cnt)
413 int rfs4_fillone_debug
= 0;
414 int rfs4_no_stub_access
= 1;
415 int rfs4_rddir_debug
= 0;
417 static char *rfs4_op_string
[] = {
425 "rfs4_op_delegpurge",
426 "rfs4_op_delegreturn",
438 "rfs4_op_open_confirm",
439 "rfs4_op_open_downgrade",
453 "rfs4_op_setclientid",
454 "rfs4_op_setclient_confirm",
457 "rfs4_op_release_lockowner",
462 void rfs4_ss_chkclid(rfs4_client_t
*);
464 extern size_t strlcpy(char *dst
, const char *src
, size_t dstsize
);
466 extern void rfs4_free_fs_locations4(fs_locations4
*);
471 #define nextdp(dp) ((struct dirent *)((char *)(dp) + (dp)->d_reclen))
473 fem_t deleg_rdops
= {
474 .name
= "deleg_rdops",
475 .femop_open
= deleg_rd_open
,
476 .femop_write
= deleg_rd_write
,
477 .femop_setattr
= deleg_rd_setattr
,
478 .femop_rwlock
= deleg_rd_rwlock
,
479 .femop_space
= deleg_rd_space
,
480 .femop_setsecattr
= deleg_rd_setsecattr
,
481 .femop_vnevent
= deleg_rd_vnevent
,
484 fem_t deleg_wrops
= {
485 .name
= "deleg_wrops",
486 .femop_open
= deleg_wr_open
,
487 .femop_read
= deleg_wr_read
,
488 .femop_write
= deleg_wr_write
,
489 .femop_setattr
= deleg_wr_setattr
,
490 .femop_rwlock
= deleg_wr_rwlock
,
491 .femop_space
= deleg_wr_space
,
492 .femop_setsecattr
= deleg_wr_setsecattr
,
493 .femop_vnevent
= deleg_wr_vnevent
,
501 extern void rfs4_attr_init();
502 extern krwlock_t rfs4_deleg_policy_lock
;
505 * The following algorithm attempts to find a unique verifier
506 * to be used as the write verifier returned from the server
507 * to the client. It is important that this verifier change
508 * whenever the server reboots. Of secondary importance, it
509 * is important for the verifier to be unique between two
512 * Thus, an attempt is made to use the system hostid and the
513 * current time in seconds when the nfssrv kernel module is
514 * loaded. It is assumed that an NFS server will not be able
515 * to boot and then to reboot in less than a second. If the
516 * hostid has not been set, then the current high resolution
517 * time is used. This will ensure different verifiers each
518 * time the server reboots and minimize the chances that two
519 * different servers will have the same verifier.
520 * XXX - this is broken on LP64 kernels.
522 verf
.tv_sec
= (time_t)zone_get_hostid(NULL
);
523 if (verf
.tv_sec
!= 0) {
524 verf
.tv_nsec
= gethrestime_sec();
529 verf
.tv_sec
= (time_t)tverf
.tv_sec
;
530 verf
.tv_nsec
= tverf
.tv_nsec
;
533 Write4verf
= *(uint64_t *)&verf
;
536 mutex_init(&rfs4_deleg_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
538 /* Used to manage create/destroy of server state */
539 mutex_init(&rfs4_state_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
541 /* Used to manage access to server instance linked list */
542 mutex_init(&rfs4_servinst_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
544 /* Used to manage access to rfs4_deleg_policy */
545 rw_init(&rfs4_deleg_policy_lock
, NULL
, RW_DEFAULT
, NULL
);
547 nfs4_srv_caller_id
= fs_new_caller_id();
549 lockt_sysid
= lm_alloc_sysidt();
551 vsd_create(&nfs4_srv_vkey
, NULL
);
559 extern krwlock_t rfs4_deleg_policy_lock
;
561 if (lockt_sysid
!= LM_NOSYSID
) {
562 lm_free_sysidt(lockt_sysid
);
563 lockt_sysid
= LM_NOSYSID
;
566 mutex_destroy(&rfs4_deleg_lock
);
567 mutex_destroy(&rfs4_state_lock
);
568 rw_destroy(&rfs4_deleg_policy_lock
);
572 rfs4_init_compound_state(struct compound_state
*cs
)
574 bzero(cs
, sizeof (*cs
));
576 cs
->access
= CS_ACCESS_DENIED
;
578 cs
->mandlock
= FALSE
;
579 cs
->fh
.nfs_fh4_val
= cs
->fhbuf
;
583 rfs4_grace_start(rfs4_servinst_t
*sip
)
585 rw_enter(&sip
->rwlock
, RW_WRITER
);
586 sip
->start_time
= (time_t)TICK_TO_SEC(ddi_get_lbolt());
587 sip
->grace_period
= rfs4_grace_period
;
588 rw_exit(&sip
->rwlock
);
592 * returns true if the instance's grace period has never been started
595 rfs4_servinst_grace_new(rfs4_servinst_t
*sip
)
599 rw_enter(&sip
->rwlock
, RW_READER
);
600 start_time
= sip
->start_time
;
601 rw_exit(&sip
->rwlock
);
603 return (start_time
== 0);
607 * Indicates if server instance is within the
611 rfs4_servinst_in_grace(rfs4_servinst_t
*sip
)
615 rw_enter(&sip
->rwlock
, RW_READER
);
616 grace_expiry
= sip
->start_time
+ sip
->grace_period
;
617 rw_exit(&sip
->rwlock
);
619 return (((time_t)TICK_TO_SEC(ddi_get_lbolt())) < grace_expiry
);
623 rfs4_clnt_in_grace(rfs4_client_t
*cp
)
625 ASSERT(rfs4_dbe_refcnt(cp
->rc_dbe
) > 0);
627 return (rfs4_servinst_in_grace(cp
->rc_server_instance
));
631 * reset all currently active grace periods
634 rfs4_grace_reset_all(void)
636 rfs4_servinst_t
*sip
;
638 mutex_enter(&rfs4_servinst_lock
);
639 for (sip
= rfs4_cur_servinst
; sip
!= NULL
; sip
= sip
->prev
)
640 if (rfs4_servinst_in_grace(sip
))
641 rfs4_grace_start(sip
);
642 mutex_exit(&rfs4_servinst_lock
);
646 * start any new instances' grace periods
649 rfs4_grace_start_new(void)
651 rfs4_servinst_t
*sip
;
653 mutex_enter(&rfs4_servinst_lock
);
654 for (sip
= rfs4_cur_servinst
; sip
!= NULL
; sip
= sip
->prev
)
655 if (rfs4_servinst_grace_new(sip
))
656 rfs4_grace_start(sip
);
657 mutex_exit(&rfs4_servinst_lock
);
660 static rfs4_dss_path_t
*
661 rfs4_dss_newpath(rfs4_servinst_t
*sip
, char *path
, unsigned index
)
664 rfs4_dss_path_t
*dss_path
;
666 dss_path
= kmem_alloc(sizeof (rfs4_dss_path_t
), KM_SLEEP
);
669 * Take a copy of the string, since the original may be overwritten.
670 * Sadly, no strdup() in the kernel.
673 len
= strlen(path
) + 1;
674 dss_path
->path
= kmem_alloc(len
, KM_SLEEP
);
675 (void) strlcpy(dss_path
->path
, path
, len
);
677 /* associate with servinst */
679 dss_path
->index
= index
;
682 * Add to list of served paths.
683 * No locking required, as we're only ever called at startup.
685 if (rfs4_dss_pathlist
== NULL
) {
686 /* this is the first dss_path_t */
688 /* needed for insque/remque */
689 dss_path
->next
= dss_path
->prev
= dss_path
;
691 rfs4_dss_pathlist
= dss_path
;
693 insque(dss_path
, rfs4_dss_pathlist
);
700 * Create a new server instance, and make it the currently active instance.
701 * Note that starting the grace period too early will reduce the clients'
705 rfs4_servinst_create(int start_grace
, int dss_npaths
, char **dss_paths
)
708 rfs4_servinst_t
*sip
;
709 rfs4_oldstate_t
*oldstate
;
711 sip
= kmem_alloc(sizeof (rfs4_servinst_t
), KM_SLEEP
);
712 rw_init(&sip
->rwlock
, NULL
, RW_DEFAULT
, NULL
);
714 sip
->start_time
= (time_t)0;
715 sip
->grace_period
= (time_t)0;
719 rw_init(&sip
->oldstate_lock
, NULL
, RW_DEFAULT
, NULL
);
721 * This initial dummy entry is required to setup for insque/remque.
722 * It must be skipped over whenever the list is traversed.
724 oldstate
= kmem_alloc(sizeof (rfs4_oldstate_t
), KM_SLEEP
);
725 /* insque/remque require initial list entry to be self-terminated */
726 oldstate
->next
= oldstate
;
727 oldstate
->prev
= oldstate
;
728 sip
->oldstate
= oldstate
;
731 sip
->dss_npaths
= dss_npaths
;
732 sip
->dss_paths
= kmem_alloc(dss_npaths
*
733 sizeof (rfs4_dss_path_t
*), KM_SLEEP
);
735 for (i
= 0; i
< dss_npaths
; i
++) {
736 sip
->dss_paths
[i
] = rfs4_dss_newpath(sip
, dss_paths
[i
], i
);
739 mutex_enter(&rfs4_servinst_lock
);
740 if (rfs4_cur_servinst
!= NULL
) {
741 /* add to linked list */
742 sip
->prev
= rfs4_cur_servinst
;
743 rfs4_cur_servinst
->next
= sip
;
746 rfs4_grace_start(sip
);
747 /* make the new instance "current" */
748 rfs4_cur_servinst
= sip
;
750 mutex_exit(&rfs4_servinst_lock
);
754 * In future, we might add a rfs4_servinst_destroy(sip) but, for now, destroy
755 * all instances directly.
758 rfs4_servinst_destroy_all(void)
760 rfs4_servinst_t
*sip
, *prev
, *current
;
765 mutex_enter(&rfs4_servinst_lock
);
766 ASSERT(rfs4_cur_servinst
!= NULL
);
767 current
= rfs4_cur_servinst
;
768 rfs4_cur_servinst
= NULL
;
769 for (sip
= current
; sip
!= NULL
; sip
= prev
) {
771 rw_destroy(&sip
->rwlock
);
773 kmem_free(sip
->oldstate
, sizeof (rfs4_oldstate_t
));
775 kmem_free(sip
->dss_paths
,
776 sip
->dss_npaths
* sizeof (rfs4_dss_path_t
*));
777 kmem_free(sip
, sizeof (rfs4_servinst_t
));
782 mutex_exit(&rfs4_servinst_lock
);
786 * Assign the current server instance to a client_t.
787 * Should be called with cp->rc_dbe held.
790 rfs4_servinst_assign(rfs4_client_t
*cp
, rfs4_servinst_t
*sip
)
792 ASSERT(rfs4_dbe_refcnt(cp
->rc_dbe
) > 0);
795 * The lock ensures that if the current instance is in the process
796 * of changing, we will see the new one.
798 mutex_enter(&rfs4_servinst_lock
);
799 cp
->rc_server_instance
= sip
;
800 mutex_exit(&rfs4_servinst_lock
);
804 rfs4_servinst(rfs4_client_t
*cp
)
806 ASSERT(rfs4_dbe_refcnt(cp
->rc_dbe
) > 0);
808 return (cp
->rc_server_instance
);
813 nullfree(caddr_t resop
)
818 * This is a fall-through for invalid or not implemented (yet) ops
822 rfs4_op_inval(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
823 struct compound_state
*cs
)
825 *cs
->statusp
= *((nfsstat4
*)&(resop
)->nfs_resop4_u
) = NFS4ERR_INVAL
;
829 * Check if the security flavor, nfsnum, is in the flavor_list.
832 in_flavor_list(int nfsnum
, int *flavor_list
, int count
)
836 for (i
= 0; i
< count
; i
++) {
837 if (nfsnum
== flavor_list
[i
])
844 * Used by rfs4_op_secinfo to get the security information from the
845 * export structure associated with the component.
849 do_rfs4_op_secinfo(struct compound_state
*cs
, char *nm
, SECINFO4res
*resp
)
851 int error
, different_export
= 0;
853 struct exportinfo
*exi
= NULL
;
857 struct secinfo
*secp
;
859 bool_t did_traverse
= FALSE
;
863 dotdot
= (nm
[0] == '.' && nm
[1] == '.' && nm
[2] == '\0');
866 * If dotdotting, then need to check whether it's above the
867 * root of a filesystem, or above an export point.
872 * If dotdotting at the root of a filesystem, then
873 * need to traverse back to the mounted-on filesystem
874 * and do the dotdot lookup there.
876 if (cs
->vp
->v_flag
& VROOT
) {
879 * If at the system root, then can
882 if (VN_CMP(dvp
, rootdir
))
883 return (puterrno4(ENOENT
));
886 * Traverse back to the mounted-on filesystem
888 dvp
= untraverse(cs
->vp
);
891 * Set the different_export flag so we remember
892 * to pick up a new exportinfo entry for
893 * this new filesystem.
895 different_export
= 1;
899 * If dotdotting above an export point then set
900 * the different_export to get new export info.
902 different_export
= nfs_exported(cs
->exi
, cs
->vp
);
907 * Get the vnode for the component "nm".
909 error
= fop_lookup(dvp
, nm
, &vp
, NULL
, 0, NULL
, cs
->cr
,
912 return (puterrno4(error
));
915 * If the vnode is in a pseudo filesystem, or if the security flavor
916 * used in the request is valid but not an explicitly shared flavor,
917 * or the access bit indicates that this is a limited access,
918 * check whether this vnode is visible.
920 if (!different_export
&&
921 (PSEUDO(cs
->exi
) || ! is_exported_sec(cs
->nfsflavor
, cs
->exi
) ||
922 cs
->access
& CS_ACCESS_LIMITED
)) {
923 if (! nfs_visible(cs
->exi
, vp
, &different_export
)) {
925 return (puterrno4(ENOENT
));
930 * If it's a mountpoint, then traverse it.
932 if (vn_ismntpt(vp
)) {
933 if ((error
= traverse(&vp
)) != 0) {
935 return (puterrno4(error
));
937 /* remember that we had to traverse mountpoint */
939 different_export
= 1;
940 } else if (vp
->v_vfsp
!= dvp
->v_vfsp
) {
942 * If vp isn't a mountpoint and the vfs ptrs aren't the same,
943 * then vp is probably an LOFS object. We don't need the
944 * realvp, we just need to know that we might have crossed
945 * a server fs boundary and need to call checkexport4.
946 * (LOFS lookup hides server fs mountpoints, and actually calls
949 different_export
= 1;
953 * Get the export information for it.
955 if (different_export
) {
957 bzero(&fid
, sizeof (fid
));
958 fid
.fid_len
= MAXFIDSZ
;
959 error
= vop_fid_pseudo(vp
, &fid
);
962 return (puterrno4(error
));
966 exi
= nfs_vptoexi(NULL
, vp
, cs
->cr
, &walk
, NULL
, TRUE
);
968 exi
= checkexport4(&vp
->v_vfsp
->vfs_fsid
, &fid
, vp
);
971 if (did_traverse
== TRUE
) {
973 * If this vnode is a mounted-on vnode,
974 * but the mounted-on file system is not
975 * exported, send back the secinfo for
976 * the exported node that the mounted-on
982 return (puterrno4(EACCES
));
992 * Create the secinfo result based on the security information
993 * from the exportinfo structure (exi).
995 * Return all flavors for a pseudo node.
996 * For a real export node, return the flavor that the client
999 ASSERT(RW_LOCK_HELD(&exported_lock
));
1001 count
= exi
->exi_export
.ex_seccnt
; /* total sec count */
1002 resok_val
= kmem_alloc(count
* sizeof (secinfo4
), KM_SLEEP
);
1003 secp
= exi
->exi_export
.ex_secinfo
;
1005 for (i
= 0; i
< count
; i
++) {
1006 si
= &secp
[i
].s_secinfo
;
1007 resok_val
[i
].flavor
= si
->sc_rpcnum
;
1008 if (resok_val
[i
].flavor
== RPCSEC_GSS
) {
1009 rpcsec_gss_info
*info
;
1011 info
= &resok_val
[i
].flavor_info
;
1012 info
->qop
= si
->sc_qop
;
1013 info
->service
= (rpc_gss_svc_t
)si
->sc_service
;
1015 /* get oid opaque data */
1016 info
->oid
.sec_oid4_len
=
1017 si
->sc_gss_mech_type
->length
;
1018 info
->oid
.sec_oid4_val
= kmem_alloc(
1019 si
->sc_gss_mech_type
->length
, KM_SLEEP
);
1021 si
->sc_gss_mech_type
->elements
,
1022 info
->oid
.sec_oid4_val
,
1023 info
->oid
.sec_oid4_len
);
1026 resp
->SECINFO4resok_len
= count
;
1027 resp
->SECINFO4resok_val
= resok_val
;
1029 int ret_cnt
= 0, k
= 0;
1032 count
= exi
->exi_export
.ex_seccnt
; /* total sec count */
1033 secp
= exi
->exi_export
.ex_secinfo
;
1035 flavor_list
= kmem_alloc(count
* sizeof (int), KM_SLEEP
);
1036 /* find out which flavors to return */
1037 for (i
= 0; i
< count
; i
++) {
1038 int access
, flavor
, perm
;
1040 flavor
= secp
[i
].s_secinfo
.sc_nfsnum
;
1041 perm
= secp
[i
].s_flags
;
1043 access
= nfsauth4_secinfo_access(exi
, cs
->req
,
1044 flavor
, perm
, cs
->basecr
);
1046 if (! (access
& NFSAUTH_DENIED
) &&
1047 ! (access
& NFSAUTH_WRONGSEC
)) {
1048 flavor_list
[ret_cnt
] = flavor
;
1053 /* Create the returning SECINFO value */
1054 resok_val
= kmem_alloc(ret_cnt
* sizeof (secinfo4
), KM_SLEEP
);
1056 for (i
= 0; i
< count
; i
++) {
1058 * If the flavor is in the flavor list,
1059 * fill in resok_val.
1061 si
= &secp
[i
].s_secinfo
;
1062 if (in_flavor_list(si
->sc_nfsnum
,
1063 flavor_list
, ret_cnt
)) {
1064 resok_val
[k
].flavor
= si
->sc_rpcnum
;
1065 if (resok_val
[k
].flavor
== RPCSEC_GSS
) {
1066 rpcsec_gss_info
*info
;
1068 info
= &resok_val
[k
].flavor_info
;
1069 info
->qop
= si
->sc_qop
;
1070 info
->service
= (rpc_gss_svc_t
)
1073 /* get oid opaque data */
1074 info
->oid
.sec_oid4_len
=
1075 si
->sc_gss_mech_type
->length
;
1076 info
->oid
.sec_oid4_val
= kmem_alloc(
1077 si
->sc_gss_mech_type
->length
,
1079 bcopy(si
->sc_gss_mech_type
->elements
,
1080 info
->oid
.sec_oid4_val
,
1081 info
->oid
.sec_oid4_len
);
1088 resp
->SECINFO4resok_len
= ret_cnt
;
1089 resp
->SECINFO4resok_val
= resok_val
;
1090 kmem_free(flavor_list
, count
* sizeof (int));
1098 * SECINFO (Operation 33): Obtain required security information on
1099 * the component name in the format of (security-mechanism-oid, qop, service)
1104 rfs4_op_secinfo(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1105 struct compound_state
*cs
)
1107 SECINFO4args
*args
= &argop
->nfs_argop4_u
.opsecinfo
;
1108 SECINFO4res
*resp
= &resop
->nfs_resop4_u
.opsecinfo
;
1109 utf8string
*utfnm
= &args
->name
;
1112 struct sockaddr
*ca
;
1114 nfsstat4 status
= NFS4_OK
;
1116 DTRACE_NFSV4_2(op__secinfo__start
, struct compound_state
*, cs
,
1117 SECINFO4args
*, args
);
1120 * Current file handle (cfh) should have been set before getting
1121 * into this function. If not, return error.
1123 if (cs
->vp
== NULL
) {
1124 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1128 if (cs
->vp
->v_type
!= VDIR
) {
1129 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
1134 * Verify the component name. If failed, error out, but
1135 * do not error out if the component name is a "..".
1136 * SECINFO will return its parents secinfo data for SECINFO "..".
1138 status
= utf8_dir_verify(utfnm
);
1139 if (status
!= NFS4_OK
) {
1140 if (utfnm
->utf8string_len
!= 2 ||
1141 utfnm
->utf8string_val
[0] != '.' ||
1142 utfnm
->utf8string_val
[1] != '.') {
1143 *cs
->statusp
= resp
->status
= status
;
1148 nm
= utf8_to_str(utfnm
, &len
, NULL
);
1150 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1154 if (len
> MAXNAMELEN
) {
1155 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
1160 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
1161 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
1165 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1171 *cs
->statusp
= resp
->status
= do_rfs4_op_secinfo(cs
, name
, resp
);
1174 kmem_free(name
, MAXPATHLEN
+ 1);
1178 DTRACE_NFSV4_2(op__secinfo__done
, struct compound_state
*, cs
,
1179 SECINFO4res
*, resp
);
1183 * Free SECINFO result.
1187 rfs4_op_secinfo_free(nfs_resop4
*resop
)
1189 SECINFO4res
*resp
= &resop
->nfs_resop4_u
.opsecinfo
;
1191 secinfo4
*resok_val
;
1193 /* If this is not an Ok result, nothing to free. */
1194 if (resp
->status
!= NFS4_OK
) {
1198 count
= resp
->SECINFO4resok_len
;
1199 resok_val
= resp
->SECINFO4resok_val
;
1201 for (i
= 0; i
< count
; i
++) {
1202 if (resok_val
[i
].flavor
== RPCSEC_GSS
) {
1203 rpcsec_gss_info
*info
;
1205 info
= &resok_val
[i
].flavor_info
;
1206 kmem_free(info
->oid
.sec_oid4_val
,
1207 info
->oid
.sec_oid4_len
);
1210 kmem_free(resok_val
, count
* sizeof (secinfo4
));
1211 resp
->SECINFO4resok_len
= 0;
1212 resp
->SECINFO4resok_val
= NULL
;
1217 rfs4_op_access(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1218 struct compound_state
*cs
)
1220 ACCESS4args
*args
= &argop
->nfs_argop4_u
.opaccess
;
1221 ACCESS4res
*resp
= &resop
->nfs_resop4_u
.opaccess
;
1226 cred_t
*cr
= cs
->cr
;
1228 DTRACE_NFSV4_2(op__access__start
, struct compound_state
*, cs
,
1229 ACCESS4args
*, args
);
1231 #if 0 /* XXX allow access even if !cs->access. Eventually only pseudo fs */
1232 if (cs
->access
== CS_ACCESS_DENIED
) {
1233 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1237 if (cs
->vp
== NULL
) {
1238 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1247 * If the file system is exported read only, it is not appropriate
1248 * to check write permissions for regular files and directories.
1249 * Special files are interpreted by the client, so the underlying
1250 * permissions are sent back to the client for interpretation.
1252 if (rdonly4(req
, cs
) &&
1253 (vp
->v_type
== VREG
|| vp
->v_type
== VDIR
))
1260 * We need the mode so that we can correctly determine access
1261 * permissions relative to a mandatory lock file. Access to
1262 * mandatory lock files is denied on the server, so it might
1263 * as well be reflected to the server during the open.
1265 va
.va_mask
= VATTR_MODE
;
1266 error
= fop_getattr(vp
, &va
, 0, cr
, NULL
);
1268 *cs
->statusp
= resp
->status
= puterrno4(error
);
1272 resp
->supported
= 0;
1274 if (args
->access
& ACCESS4_READ
) {
1275 error
= fop_access(vp
, VREAD
, 0, cr
, NULL
);
1276 if (!error
&& !MANDLOCK(vp
, va
.va_mode
))
1277 resp
->access
|= ACCESS4_READ
;
1278 resp
->supported
|= ACCESS4_READ
;
1280 if ((args
->access
& ACCESS4_LOOKUP
) && vp
->v_type
== VDIR
) {
1281 error
= fop_access(vp
, VEXEC
, 0, cr
, NULL
);
1283 resp
->access
|= ACCESS4_LOOKUP
;
1284 resp
->supported
|= ACCESS4_LOOKUP
;
1286 if (checkwriteperm
&&
1287 (args
->access
& (ACCESS4_MODIFY
|ACCESS4_EXTEND
))) {
1288 error
= fop_access(vp
, VWRITE
, 0, cr
, NULL
);
1289 if (!error
&& !MANDLOCK(vp
, va
.va_mode
))
1291 (args
->access
& (ACCESS4_MODIFY
| ACCESS4_EXTEND
));
1293 resp
->access
& (ACCESS4_MODIFY
| ACCESS4_EXTEND
);
1296 if (checkwriteperm
&&
1297 (args
->access
& ACCESS4_DELETE
) && vp
->v_type
== VDIR
) {
1298 error
= fop_access(vp
, VWRITE
, 0, cr
, NULL
);
1300 resp
->access
|= ACCESS4_DELETE
;
1301 resp
->supported
|= ACCESS4_DELETE
;
1303 if (args
->access
& ACCESS4_EXECUTE
&& vp
->v_type
!= VDIR
) {
1304 error
= fop_access(vp
, VEXEC
, 0, cr
, NULL
);
1305 if (!error
&& !MANDLOCK(vp
, va
.va_mode
))
1306 resp
->access
|= ACCESS4_EXECUTE
;
1307 resp
->supported
|= ACCESS4_EXECUTE
;
1310 *cs
->statusp
= resp
->status
= NFS4_OK
;
1312 DTRACE_NFSV4_2(op__access__done
, struct compound_state
*, cs
,
1313 ACCESS4res
*, resp
);
1318 rfs4_op_commit(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1319 struct compound_state
*cs
)
1321 COMMIT4args
*args
= &argop
->nfs_argop4_u
.opcommit
;
1322 COMMIT4res
*resp
= &resop
->nfs_resop4_u
.opcommit
;
1324 vnode_t
*vp
= cs
->vp
;
1325 cred_t
*cr
= cs
->cr
;
1328 DTRACE_NFSV4_2(op__commit__start
, struct compound_state
*, cs
,
1329 COMMIT4args
*, args
);
1332 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1335 if (cs
->access
== CS_ACCESS_DENIED
) {
1336 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1340 if (args
->offset
+ args
->count
< args
->offset
) {
1341 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1345 va
.va_mask
= VATTR_UID
;
1346 error
= fop_getattr(vp
, &va
, 0, cr
, NULL
);
1349 * If we can't get the attributes, then we can't do the
1350 * right access checking. So, we'll fail the request.
1353 *cs
->statusp
= resp
->status
= puterrno4(error
);
1356 if (rdonly4(req
, cs
)) {
1357 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
1361 if (vp
->v_type
!= VREG
) {
1362 if (vp
->v_type
== VDIR
)
1363 resp
->status
= NFS4ERR_ISDIR
;
1365 resp
->status
= NFS4ERR_INVAL
;
1366 *cs
->statusp
= resp
->status
;
1370 if (crgetuid(cr
) != va
.va_uid
&&
1371 (error
= fop_access(vp
, VWRITE
, 0, cs
->cr
, NULL
))) {
1372 *cs
->statusp
= resp
->status
= puterrno4(error
);
1376 error
= fop_fsync(vp
, FSYNC
, cr
, NULL
);
1379 *cs
->statusp
= resp
->status
= puterrno4(error
);
1383 *cs
->statusp
= resp
->status
= NFS4_OK
;
1384 resp
->writeverf
= Write4verf
;
1386 DTRACE_NFSV4_2(op__commit__done
, struct compound_state
*, cs
,
1387 COMMIT4res
*, resp
);
1391 * rfs4_op_mknod is called from rfs4_op_create after all initial verification
1392 * was completed. It does the nfsv4 create for special files.
1396 do_rfs4_op_mknod(CREATE4args
*args
, CREATE4res
*resp
, struct svc_req
*req
,
1397 struct compound_state
*cs
, vattr_t
*vap
, char *nm
)
1400 cred_t
*cr
= cs
->cr
;
1401 vnode_t
*dvp
= cs
->vp
;
1406 switch (args
->type
) {
1409 if (secpolicy_sys_devices(cr
) != 0) {
1410 *cs
->statusp
= resp
->status
= NFS4ERR_PERM
;
1413 if (args
->type
== NF4CHR
)
1414 vap
->va_type
= VCHR
;
1416 vap
->va_type
= VBLK
;
1417 vap
->va_rdev
= makedevice(args
->ftype4_u
.devdata
.specdata1
,
1418 args
->ftype4_u
.devdata
.specdata2
);
1419 vap
->va_mask
|= VATTR_RDEV
;
1422 vap
->va_type
= VSOCK
;
1425 vap
->va_type
= VFIFO
;
1428 *cs
->statusp
= resp
->status
= NFS4ERR_BADTYPE
;
1433 * Must specify the mode.
1435 if (!(vap
->va_mask
& VATTR_MODE
)) {
1436 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1444 error
= fop_create(dvp
, nm
, vap
, excl
, mode
, &vp
, cr
, 0, NULL
, NULL
);
1446 *cs
->statusp
= resp
->status
= puterrno4(error
);
1453 * nfsv4 create is used to create non-regular files. For regular files,
1458 rfs4_op_create(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1459 struct compound_state
*cs
)
1461 CREATE4args
*args
= &argop
->nfs_argop4_u
.opcreate
;
1462 CREATE4res
*resp
= &resop
->nfs_resop4_u
.opcreate
;
1464 struct vattr bva
, iva
, iva2
, ava
, *vap
;
1465 cred_t
*cr
= cs
->cr
;
1466 vnode_t
*dvp
= cs
->vp
;
1472 struct nfs4_svgetit_arg sarg
;
1473 struct nfs4_ntov_table ntov
;
1474 struct statvfs64 sb
;
1476 struct sockaddr
*ca
;
1480 DTRACE_NFSV4_2(op__create__start
, struct compound_state
*, cs
,
1481 CREATE4args
*, args
);
1486 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
1491 * If there is an unshared filesystem mounted on this vnode,
1492 * do not allow to create an object in this directory.
1494 if (vn_ismntpt(dvp
)) {
1495 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1499 /* Verify that type is correct */
1500 switch (args
->type
) {
1509 *cs
->statusp
= resp
->status
= NFS4ERR_BADTYPE
;
1513 if (cs
->access
== CS_ACCESS_DENIED
) {
1514 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
1517 if (dvp
->v_type
!= VDIR
) {
1518 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
1521 status
= utf8_dir_verify(&args
->objname
);
1522 if (status
!= NFS4_OK
) {
1523 *cs
->statusp
= resp
->status
= status
;
1527 if (rdonly4(req
, cs
)) {
1528 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
1533 * Name of newly created object
1535 nm
= utf8_to_fn(&args
->objname
, &len
, NULL
);
1537 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1541 if (len
> MAXNAMELEN
) {
1542 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
1547 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
1548 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
1552 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1560 sarg
.is_referral
= B_FALSE
;
1561 nfs4_ntov_table_init(&ntov
);
1563 status
= do_rfs4_set_attrs(&resp
->attrset
,
1564 &args
->createattrs
, cs
, &sarg
, &ntov
, NFS4ATTR_SETIT
);
1566 if (sarg
.vap
->va_mask
== 0 && status
== NFS4_OK
)
1567 status
= NFS4ERR_INVAL
;
1569 if (status
!= NFS4_OK
) {
1570 *cs
->statusp
= resp
->status
= status
;
1572 kmem_free(name
, MAXPATHLEN
+ 1);
1574 nfs4_ntov_table_free(&ntov
, &sarg
);
1579 /* Get "before" change value */
1580 bva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
|VATTR_MODE
;
1581 error
= fop_getattr(dvp
, &bva
, 0, cr
, NULL
);
1583 *cs
->statusp
= resp
->status
= puterrno4(error
);
1585 kmem_free(name
, MAXPATHLEN
+ 1);
1587 nfs4_ntov_table_free(&ntov
, &sarg
);
1591 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.before
, bva
.va_ctime
)
1596 * Set the default initial values for attributes when the parent
1597 * directory does not have the VSUID/VSGID bit set and they have
1598 * not been specified in createattrs.
1600 if (!(bva
.va_mode
& VSUID
) && (vap
->va_mask
& VATTR_UID
) == 0) {
1601 vap
->va_uid
= crgetuid(cr
);
1602 vap
->va_mask
|= VATTR_UID
;
1604 if (!(bva
.va_mode
& VSGID
) && (vap
->va_mask
& VATTR_GID
) == 0) {
1605 vap
->va_gid
= crgetgid(cr
);
1606 vap
->va_mask
|= VATTR_GID
;
1609 vap
->va_mask
|= VATTR_TYPE
;
1610 switch (args
->type
) {
1612 vap
->va_type
= VDIR
;
1613 if ((vap
->va_mask
& VATTR_MODE
) == 0) {
1614 vap
->va_mode
= 0700; /* default: owner rwx only */
1615 vap
->va_mask
|= VATTR_MODE
;
1617 error
= fop_mkdir(dvp
, name
, vap
, &vp
, cr
, NULL
, 0, NULL
);
1622 * Get the initial "after" sequence number, if it fails,
1625 iva
.va_mask
= VATTR_SEQ
;
1626 if (fop_getattr(dvp
, &iva
, 0, cs
->cr
, NULL
))
1630 vap
->va_type
= VLNK
;
1631 if ((vap
->va_mask
& VATTR_MODE
) == 0) {
1632 vap
->va_mode
= 0700; /* default: owner rwx only */
1633 vap
->va_mask
|= VATTR_MODE
;
1637 * symlink names must be treated as data
1639 lnm
= utf8_to_str((utf8string
*)&args
->ftype4_u
.linkdata
,
1643 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
1645 kmem_free(name
, MAXPATHLEN
+ 1);
1647 nfs4_ntov_table_free(&ntov
, &sarg
);
1652 if (llen
> MAXPATHLEN
) {
1653 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
1655 kmem_free(name
, MAXPATHLEN
+ 1);
1657 kmem_free(lnm
, llen
);
1658 nfs4_ntov_table_free(&ntov
, &sarg
);
1663 lname
= nfscmd_convname(ca
, cs
->exi
, lnm
,
1664 NFSCMD_CONV_INBOUND
, MAXPATHLEN
+ 1);
1666 if (lname
== NULL
) {
1667 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
1669 kmem_free(name
, MAXPATHLEN
+ 1);
1671 kmem_free(lnm
, llen
);
1672 nfs4_ntov_table_free(&ntov
, &sarg
);
1677 error
= fop_symlink(dvp
, name
, vap
, lname
, cr
, NULL
, 0);
1679 kmem_free(lname
, MAXPATHLEN
+ 1);
1680 kmem_free(lnm
, llen
);
1685 * Get the initial "after" sequence number, if it fails,
1688 iva
.va_mask
= VATTR_SEQ
;
1689 if (fop_getattr(dvp
, &iva
, 0, cs
->cr
, NULL
))
1692 error
= fop_lookup(dvp
, name
, &vp
, NULL
, 0, NULL
, cr
,
1698 * va_seq is not safe over VOP calls, check it again
1699 * if it has changed zero out iva to force atomic = FALSE.
1701 iva2
.va_mask
= VATTR_SEQ
;
1702 if (fop_getattr(dvp
, &iva2
, 0, cs
->cr
, NULL
) ||
1703 iva2
.va_seq
!= iva
.va_seq
)
1708 * probably a special file.
1710 if ((vap
->va_mask
& VATTR_MODE
) == 0) {
1711 vap
->va_mode
= 0600; /* default: owner rw only */
1712 vap
->va_mask
|= VATTR_MODE
;
1716 * We know this will only generate one VOP call
1718 vp
= do_rfs4_op_mknod(args
, resp
, req
, cs
, vap
, name
);
1722 kmem_free(name
, MAXPATHLEN
+ 1);
1724 nfs4_ntov_table_free(&ntov
, &sarg
);
1730 * Get the initial "after" sequence number, if it fails,
1733 iva
.va_mask
= VATTR_SEQ
;
1734 if (fop_getattr(dvp
, &iva
, 0, cs
->cr
, NULL
))
1740 kmem_free(name
, MAXPATHLEN
+ 1);
1744 *cs
->statusp
= resp
->status
= puterrno4(error
);
1748 * Force modified data and metadata out to stable storage.
1750 (void) fop_fsync(dvp
, 0, cr
, NULL
);
1752 if (resp
->status
!= NFS4_OK
) {
1755 nfs4_ntov_table_free(&ntov
, &sarg
);
1761 * Finish setup of cinfo response, "before" value already set.
1762 * Get "after" change value, if it fails, simply return the
1765 ava
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
1766 if (fop_getattr(dvp
, &ava
, 0, cr
, NULL
)) {
1767 ava
.va_ctime
= bva
.va_ctime
;
1770 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.after
, ava
.va_ctime
);
1773 * True verification that object was created with correct
1774 * attrs is impossible. The attrs could have been changed
1775 * immediately after object creation. If attributes did
1776 * not verify, the only recourse for the server is to
1777 * destroy the object. Maybe if some attrs (like gid)
1778 * are set incorrectly, the object should be destroyed;
1779 * however, seems bad as a default policy. Do we really
1780 * want to destroy an object over one of the times not
1781 * verifying correctly? For these reasons, the server
1782 * currently sets bits in attrset for createattrs
1783 * that were set; however, no verification is done.
1785 * vmask_to_nmask accounts for vattr bits set on create
1786 * [do_rfs4_set_attrs() only sets resp bits for
1787 * non-vattr/vfs bits.]
1788 * Mask off any bits set by default so as not to return
1789 * more attrset bits than were requested in createattrs
1791 nfs4_vmask_to_nmask(sarg
.vap
->va_mask
, &resp
->attrset
);
1792 resp
->attrset
&= args
->createattrs
.attrmask
;
1793 nfs4_ntov_table_free(&ntov
, &sarg
);
1795 error
= makefh4(&cs
->fh
, vp
, cs
->exi
);
1797 *cs
->statusp
= resp
->status
= puterrno4(error
);
1801 * The cinfo.atomic = TRUE only if we got no errors, we have
1802 * non-zero va_seq's, and it has incremented by exactly one
1803 * during the creation and it didn't change during the fop_lookup
1806 if (!error
&& bva
.va_seq
&& iva
.va_seq
&& ava
.va_seq
&&
1807 iva
.va_seq
== (bva
.va_seq
+ 1) && iva
.va_seq
== ava
.va_seq
)
1808 resp
->cinfo
.atomic
= TRUE
;
1810 resp
->cinfo
.atomic
= FALSE
;
1813 * Force modified metadata out to stable storage.
1815 * if a underlying vp exists, pass it to fop_fsync
1817 if (fop_realvp(vp
, &realvp
, NULL
) == 0)
1818 (void) fop_fsync(realvp
, syncval
, cr
, NULL
);
1820 (void) fop_fsync(vp
, syncval
, cr
, NULL
);
1822 if (resp
->status
!= NFS4_OK
) {
1830 *cs
->statusp
= resp
->status
= NFS4_OK
;
1832 DTRACE_NFSV4_2(op__create__done
, struct compound_state
*, cs
,
1833 CREATE4res
*, resp
);
1838 rfs4_op_delegpurge(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1839 struct compound_state
*cs
)
1841 DTRACE_NFSV4_2(op__delegpurge__start
, struct compound_state
*, cs
,
1842 DELEGPURGE4args
*, &argop
->nfs_argop4_u
.opdelegpurge
);
1844 rfs4_op_inval(argop
, resop
, req
, cs
);
1846 DTRACE_NFSV4_2(op__delegpurge__done
, struct compound_state
*, cs
,
1847 DELEGPURGE4res
*, &resop
->nfs_resop4_u
.opdelegpurge
);
1852 rfs4_op_delegreturn(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
1853 struct compound_state
*cs
)
1855 DELEGRETURN4args
*args
= &argop
->nfs_argop4_u
.opdelegreturn
;
1856 DELEGRETURN4res
*resp
= &resop
->nfs_resop4_u
.opdelegreturn
;
1857 rfs4_deleg_state_t
*dsp
;
1860 DTRACE_NFSV4_2(op__delegreturn__start
, struct compound_state
*, cs
,
1861 DELEGRETURN4args
*, args
);
1863 status
= rfs4_get_deleg_state(&args
->deleg_stateid
, &dsp
);
1864 resp
->status
= *cs
->statusp
= status
;
1865 if (status
!= NFS4_OK
)
1868 /* Ensure specified filehandle matches */
1869 if (cs
->vp
!= dsp
->rds_finfo
->rf_vp
) {
1870 resp
->status
= *cs
->statusp
= NFS4ERR_BAD_STATEID
;
1872 rfs4_return_deleg(dsp
, FALSE
);
1874 rfs4_update_lease(dsp
->rds_client
);
1876 rfs4_deleg_state_rele(dsp
);
1878 DTRACE_NFSV4_2(op__delegreturn__done
, struct compound_state
*, cs
,
1879 DELEGRETURN4res
*, resp
);
1883 * Check to see if a given "flavor" is an explicitly shared flavor.
1884 * The assumption of this routine is the "flavor" is already a valid
1885 * flavor in the secinfo list of "exi".
1888 * # share -o sec=flavor1 /export
1889 * # share -o sec=flavor2 /export/home
1891 * flavor2 is not an explicitly shared flavor for /export,
1892 * however it is in the secinfo list for /export thru the
1893 * server namespace setup.
1896 is_exported_sec(int flavor
, struct exportinfo
*exi
)
1901 sp
= exi
->exi_export
.ex_secinfo
;
1902 for (i
= 0; i
< exi
->exi_export
.ex_seccnt
; i
++) {
1903 if (flavor
== sp
[i
].s_secinfo
.sc_nfsnum
||
1904 sp
[i
].s_secinfo
.sc_nfsnum
== AUTH_NONE
) {
1905 return (SEC_REF_EXPORTED(&sp
[i
]));
1909 /* Should not reach this point based on the assumption */
1914 * Check if the security flavor used in the request matches what is
1915 * required at the export point or at the root pseudo node (exi_root).
1917 * returns 1 if there's a match or if exported with AUTH_NONE; 0 otherwise.
1921 secinfo_match_or_authnone(struct compound_state
*cs
)
1927 * Check cs->nfsflavor (from the request) against
1928 * the current export data in cs->exi.
1930 sp
= cs
->exi
->exi_export
.ex_secinfo
;
1931 for (i
= 0; i
< cs
->exi
->exi_export
.ex_seccnt
; i
++) {
1932 if (cs
->nfsflavor
== sp
[i
].s_secinfo
.sc_nfsnum
||
1933 sp
[i
].s_secinfo
.sc_nfsnum
== AUTH_NONE
)
1941 * Check the access authority for the client and return the correct error.
1944 call_checkauth4(struct compound_state
*cs
, struct svc_req
*req
)
1949 * First, check if the security flavor used in the request
1950 * are among the flavors set in the server namespace.
1952 if (!secinfo_match_or_authnone(cs
)) {
1953 *cs
->statusp
= NFS4ERR_WRONGSEC
;
1954 return (*cs
->statusp
);
1957 authres
= checkauth4(cs
, req
);
1960 *cs
->statusp
= NFS4_OK
;
1961 if (! (cs
->access
& CS_ACCESS_LIMITED
))
1962 cs
->access
= CS_ACCESS_OK
;
1963 } else if (authres
== 0) {
1964 *cs
->statusp
= NFS4ERR_ACCESS
;
1965 } else if (authres
== -2) {
1966 *cs
->statusp
= NFS4ERR_WRONGSEC
;
1968 *cs
->statusp
= NFS4ERR_DELAY
;
1970 return (*cs
->statusp
);
1974 * bitmap4_to_attrmask is called by getattr and readdir.
1975 * It sets up the vattr mask and determines whether vfsstat call is needed
1976 * based on the input bitmap.
1977 * Returns nfsv4 status.
1980 bitmap4_to_attrmask(bitmap4 breq
, struct nfs4_svgetit_arg
*sargp
)
1984 struct statvfs64
*sbp
= sargp
->sbp
;
1988 sargp
->rdattr_error
= NFS4_OK
;
1989 sargp
->mntdfid_set
= FALSE
;
1991 sargp
->xattr
= get_fh4_flag(&sargp
->cs
->fh
,
1992 FH4_ATTRDIR
| FH4_NAMEDATTR
);
1997 * Set rdattr_error_req to true if return error per
1998 * failed entry rather than fail the readdir.
2000 if (breq
& FATTR4_RDATTR_ERROR_MASK
)
2001 sargp
->rdattr_error_req
= 1;
2003 sargp
->rdattr_error_req
= 0;
2006 * generate the va_mask
2007 * Handle the easy cases first
2010 case NFS4_NTOV_ATTR_MASK
:
2011 sargp
->vap
->va_mask
= NFS4_NTOV_ATTR_AT_MASK
;
2014 case NFS4_FS_ATTR_MASK
:
2015 sargp
->vap
->va_mask
= NFS4_FS_ATTR_AT_MASK
;
2019 case NFS4_NTOV_ATTR_CACHE_MASK
:
2020 sargp
->vap
->va_mask
= NFS4_NTOV_ATTR_CACHE_AT_MASK
;
2023 case FATTR4_LEASE_TIME_MASK
:
2024 sargp
->vap
->va_mask
= 0;
2029 for (i
= 0; i
< nfs4_ntov_map_size
; i
++) {
2030 if ((breq
& nfs4_ntov_map
[i
].fbit
) &&
2031 nfs4_ntov_map
[i
].vbit
)
2032 va_mask
|= nfs4_ntov_map
[i
].vbit
;
2036 * Check is vfsstat is needed
2038 if (breq
& NFS4_FS_ATTR_MASK
)
2041 sargp
->vap
->va_mask
= va_mask
;
2048 * bitmap4_get_sysattrs is called by getattr and readdir.
2049 * It calls both fop_getattr and VFS_STATVFS calls to get the attrs.
2050 * Returns nfsv4 status.
2053 bitmap4_get_sysattrs(struct nfs4_svgetit_arg
*sargp
)
2056 struct compound_state
*cs
= sargp
->cs
;
2057 vnode_t
*vp
= cs
->vp
;
2059 if (sargp
->sbp
!= NULL
) {
2060 if (error
= VFS_STATVFS(vp
->v_vfsp
, sargp
->sbp
)) {
2061 sargp
->sbp
= NULL
; /* to identify error */
2062 return (puterrno4(error
));
2066 return (rfs4_vop_getattr(vp
, sargp
->vap
, 0, cs
->cr
));
2070 nfs4_ntov_table_init(struct nfs4_ntov_table
*ntovp
)
2072 ntovp
->na
= kmem_zalloc(sizeof (union nfs4_attr_u
) * nfs4_ntov_map_size
,
2075 ntovp
->vfsstat
= FALSE
;
2079 nfs4_ntov_table_free(struct nfs4_ntov_table
*ntovp
,
2080 struct nfs4_svgetit_arg
*sargp
)
2083 union nfs4_attr_u
*na
;
2087 * XXX Should do the same checks for whether the bit is set
2089 for (i
= 0, na
= ntovp
->na
, amap
= ntovp
->amap
;
2090 i
< ntovp
->attrcnt
; i
++, na
++, amap
++) {
2091 (void) (*nfs4_ntov_map
[*amap
].sv_getit
)(
2092 NFS4ATTR_FREEIT
, sargp
, na
);
2094 if ((sargp
->op
== NFS4ATTR_SETIT
) || (sargp
->op
== NFS4ATTR_VERIT
)) {
2096 * xdr_free for getattr will be done later
2098 for (i
= 0, na
= ntovp
->na
, amap
= ntovp
->amap
;
2099 i
< ntovp
->attrcnt
; i
++, na
++, amap
++) {
2100 xdr_free(nfs4_ntov_map
[*amap
].xfunc
, (caddr_t
)na
);
2103 kmem_free(ntovp
->na
, sizeof (union nfs4_attr_u
) * nfs4_ntov_map_size
);
2107 * do_rfs4_op_getattr gets the system attrs and converts into fattr4.
2110 do_rfs4_op_getattr(bitmap4 breq
, fattr4
*fattrp
,
2111 struct nfs4_svgetit_arg
*sargp
)
2115 struct nfs4_ntov_table ntov
;
2119 nfsstat4 status
= NFS4_OK
;
2120 nfsstat4 prev_rdattr_error
= sargp
->rdattr_error
;
2121 union nfs4_attr_u
*na
;
2124 sargp
->op
= NFS4ATTR_GETIT
;
2127 fattrp
->attrmask
= 0;
2128 /* if no bits requested, then return empty fattr4 */
2130 fattrp
->attrlist4_len
= 0;
2131 fattrp
->attrlist4
= NULL
;
2136 * return NFS4ERR_INVAL when client requests write-only attrs
2138 if (breq
& (FATTR4_TIME_ACCESS_SET_MASK
| FATTR4_TIME_MODIFY_SET_MASK
))
2139 return (NFS4ERR_INVAL
);
2141 nfs4_ntov_table_init(&ntov
);
2146 * Now loop to get or verify the attrs
2148 for (i
= 0; i
< nfs4_ntov_map_size
; i
++) {
2149 if (breq
& nfs4_ntov_map
[i
].fbit
) {
2150 if ((*nfs4_ntov_map
[i
].sv_getit
)(
2151 NFS4ATTR_SUPPORTED
, sargp
, NULL
) == 0) {
2153 error
= (*nfs4_ntov_map
[i
].sv_getit
)(
2154 NFS4ATTR_GETIT
, sargp
, na
);
2157 * Possible error values:
2158 * >0 if sv_getit failed to
2159 * get the attr; 0 if succeeded;
2160 * <0 if rdattr_error and the
2161 * attribute cannot be returned.
2163 if (error
&& !(sargp
->rdattr_error_req
))
2166 * If error then just for entry
2170 nfs4_ntov_map
[i
].fbit
;
2172 (uint8_t)nfs4_ntov_map
[i
].nval
;
2175 } else if ((error
> 0) &&
2176 (sargp
->rdattr_error
== NFS4_OK
)) {
2177 sargp
->rdattr_error
= puterrno4(error
);
2185 * If rdattr_error was set after the return value for it was assigned,
2188 if (prev_rdattr_error
!= sargp
->rdattr_error
) {
2191 for (i
= 0; i
< ntov
.attrcnt
; i
++, na
++, amap
++) {
2193 if (k
< FATTR4_RDATTR_ERROR
) {
2196 if ((k
== FATTR4_RDATTR_ERROR
) &&
2197 ((*nfs4_ntov_map
[k
].sv_getit
)(
2198 NFS4ATTR_SUPPORTED
, sargp
, NULL
) == 0)) {
2200 (void) (*nfs4_ntov_map
[k
].sv_getit
)(
2201 NFS4ATTR_GETIT
, sargp
, na
);
2210 for (i
= 0; i
< ntov
.attrcnt
; i
++, na
++, amap
++) {
2211 xdr_size
+= xdr_sizeof(nfs4_ntov_map
[*amap
].xfunc
, na
);
2214 fattrp
->attrlist4_len
= xdr_size
;
2216 /* freed by rfs4_op_getattr_free() */
2217 fattrp
->attrlist4
= xdr_attrs
= kmem_zalloc(xdr_size
, KM_SLEEP
);
2219 xdrmem_create(&xdr
, xdr_attrs
, xdr_size
, XDR_ENCODE
);
2223 for (i
= 0; i
< ntov
.attrcnt
; i
++, na
++, amap
++) {
2224 if (!(*nfs4_ntov_map
[*amap
].xfunc
)(&xdr
, na
)) {
2225 DTRACE_PROBE1(nfss__e__getattr4_encfail
,
2227 status
= NFS4ERR_SERVERFAULT
;
2231 /* xdrmem_destroy(&xdrs); */ /* NO-OP */
2233 fattrp
->attrlist4
= NULL
;
2237 nfs4_ntov_table_free(&ntov
, sargp
);
2240 status
= puterrno4(error
);
2247 rfs4_op_getattr(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2248 struct compound_state
*cs
)
2250 GETATTR4args
*args
= &argop
->nfs_argop4_u
.opgetattr
;
2251 GETATTR4res
*resp
= &resop
->nfs_resop4_u
.opgetattr
;
2252 struct nfs4_svgetit_arg sarg
;
2253 struct statvfs64 sb
;
2256 DTRACE_NFSV4_2(op__getattr__start
, struct compound_state
*, cs
,
2257 GETATTR4args
*, args
);
2259 if (cs
->vp
== NULL
) {
2260 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2264 if (cs
->access
== CS_ACCESS_DENIED
) {
2265 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2271 sarg
.is_referral
= B_FALSE
;
2273 status
= bitmap4_to_attrmask(args
->attr_request
, &sarg
);
2274 if (status
== NFS4_OK
) {
2276 status
= bitmap4_get_sysattrs(&sarg
);
2277 if (status
== NFS4_OK
) {
2279 /* Is this a referral? */
2280 if (vn_is_nfs_reparse(cs
->vp
, cs
->cr
)) {
2281 /* Older V4 Solaris client sees a link */
2282 if (client_is_downrev(req
))
2283 sarg
.vap
->va_type
= VLNK
;
2285 sarg
.is_referral
= B_TRUE
;
2288 status
= do_rfs4_op_getattr(args
->attr_request
,
2289 &resp
->obj_attributes
, &sarg
);
2292 *cs
->statusp
= resp
->status
= status
;
2294 DTRACE_NFSV4_2(op__getattr__done
, struct compound_state
*, cs
,
2295 GETATTR4res
*, resp
);
2299 rfs4_op_getattr_free(nfs_resop4
*resop
)
2301 GETATTR4res
*resp
= &resop
->nfs_resop4_u
.opgetattr
;
2303 nfs4_fattr4_free(&resp
->obj_attributes
);
2308 rfs4_op_getfh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2309 struct compound_state
*cs
)
2311 GETFH4res
*resp
= &resop
->nfs_resop4_u
.opgetfh
;
2313 DTRACE_NFSV4_1(op__getfh__start
, struct compound_state
*, cs
);
2315 if (cs
->vp
== NULL
) {
2316 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2319 if (cs
->access
== CS_ACCESS_DENIED
) {
2320 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2324 /* check for reparse point at the share point */
2325 if (cs
->exi
->exi_moved
|| vn_is_nfs_reparse(cs
->exi
->exi_vp
, cs
->cr
)) {
2327 cs
->exi
->exi_moved
= 1;
2328 *cs
->statusp
= resp
->status
= NFS4ERR_MOVED
;
2329 DTRACE_PROBE2(nfs4serv__func__referral__shared__moved
,
2330 vnode_t
*, cs
->vp
, char *, "rfs4_op_getfh");
2334 /* check for reparse point at vp */
2335 if (vn_is_nfs_reparse(cs
->vp
, cs
->cr
) && !client_is_downrev(req
)) {
2336 /* it's not all bad */
2337 *cs
->statusp
= resp
->status
= NFS4ERR_MOVED
;
2338 DTRACE_PROBE2(nfs4serv__func__referral__moved
,
2339 vnode_t
*, cs
->vp
, char *, "rfs4_op_getfh");
2343 resp
->object
.nfs_fh4_val
=
2344 kmem_alloc(cs
->fh
.nfs_fh4_len
, KM_SLEEP
);
2345 nfs_fh4_copy(&cs
->fh
, &resp
->object
);
2346 *cs
->statusp
= resp
->status
= NFS4_OK
;
2348 DTRACE_NFSV4_2(op__getfh__done
, struct compound_state
*, cs
,
2353 rfs4_op_getfh_free(nfs_resop4
*resop
)
2355 GETFH4res
*resp
= &resop
->nfs_resop4_u
.opgetfh
;
2357 if (resp
->status
== NFS4_OK
&&
2358 resp
->object
.nfs_fh4_val
!= NULL
) {
2359 kmem_free(resp
->object
.nfs_fh4_val
, resp
->object
.nfs_fh4_len
);
2360 resp
->object
.nfs_fh4_val
= NULL
;
2361 resp
->object
.nfs_fh4_len
= 0;
2366 * illegal: args: void
2367 * res : status (NFS4ERR_OP_ILLEGAL)
2371 rfs4_op_illegal(nfs_argop4
*argop
, nfs_resop4
*resop
,
2372 struct svc_req
*req
, struct compound_state
*cs
)
2374 ILLEGAL4res
*resp
= &resop
->nfs_resop4_u
.opillegal
;
2376 resop
->resop
= OP_ILLEGAL
;
2377 *cs
->statusp
= resp
->status
= NFS4ERR_OP_ILLEGAL
;
2381 * link: args: SAVED_FH: file, CURRENT_FH: target directory
2382 * res: status. If success - CURRENT_FH unchanged, return change_info
2386 rfs4_op_link(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2387 struct compound_state
*cs
)
2389 LINK4args
*args
= &argop
->nfs_argop4_u
.oplink
;
2390 LINK4res
*resp
= &resop
->nfs_resop4_u
.oplink
;
2394 struct vattr bdva
, idva
, adva
;
2397 struct sockaddr
*ca
;
2401 DTRACE_NFSV4_2(op__link__start
, struct compound_state
*, cs
,
2404 /* SAVED_FH: source object */
2407 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2411 /* CURRENT_FH: target directory */
2414 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2419 * If there is a non-shared filesystem mounted on this vnode,
2420 * do not allow to link any file in this directory.
2422 if (vn_ismntpt(dvp
)) {
2423 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2427 if (cs
->access
== CS_ACCESS_DENIED
) {
2428 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
2432 /* Check source object's type validity */
2433 if (vp
->v_type
== VDIR
) {
2434 *cs
->statusp
= resp
->status
= NFS4ERR_ISDIR
;
2438 /* Check target directory's type */
2439 if (dvp
->v_type
!= VDIR
) {
2440 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
2444 if (cs
->saved_exi
!= cs
->exi
) {
2445 *cs
->statusp
= resp
->status
= NFS4ERR_XDEV
;
2449 status
= utf8_dir_verify(&args
->newname
);
2450 if (status
!= NFS4_OK
) {
2451 *cs
->statusp
= resp
->status
= status
;
2455 nm
= utf8_to_fn(&args
->newname
, &len
, NULL
);
2457 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2461 if (len
> MAXNAMELEN
) {
2462 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
2467 if (rdonly4(req
, cs
)) {
2468 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
2473 /* Get "before" change value */
2474 bdva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
2475 error
= fop_getattr(dvp
, &bdva
, 0, cs
->cr
, NULL
);
2477 *cs
->statusp
= resp
->status
= puterrno4(error
);
2482 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
2483 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
2487 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2492 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.before
, bdva
.va_ctime
)
2494 error
= fop_link(dvp
, vp
, name
, cs
->cr
, NULL
, 0);
2497 kmem_free(name
, MAXPATHLEN
+ 1);
2501 * Get the initial "after" sequence number, if it fails, set to zero
2503 idva
.va_mask
= VATTR_SEQ
;
2504 if (fop_getattr(dvp
, &idva
, 0, cs
->cr
, NULL
))
2508 * Force modified data and metadata out to stable storage.
2510 (void) fop_fsync(vp
, FNODSYNC
, cs
->cr
, NULL
);
2511 (void) fop_fsync(dvp
, 0, cs
->cr
, NULL
);
2514 *cs
->statusp
= resp
->status
= puterrno4(error
);
2519 * Get "after" change value, if it fails, simply return the
2522 adva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
2523 if (fop_getattr(dvp
, &adva
, 0, cs
->cr
, NULL
)) {
2524 adva
.va_ctime
= bdva
.va_ctime
;
2528 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.after
, adva
.va_ctime
)
2531 * The cinfo.atomic = TRUE only if we have
2532 * non-zero va_seq's, and it has incremented by exactly one
2533 * during the fop_link and it didn't change during the fop_fsync.
2535 if (bdva
.va_seq
&& idva
.va_seq
&& adva
.va_seq
&&
2536 idva
.va_seq
== (bdva
.va_seq
+ 1) && idva
.va_seq
== adva
.va_seq
)
2537 resp
->cinfo
.atomic
= TRUE
;
2539 resp
->cinfo
.atomic
= FALSE
;
2541 *cs
->statusp
= resp
->status
= NFS4_OK
;
2543 DTRACE_NFSV4_2(op__link__done
, struct compound_state
*, cs
,
2548 * Used by rfs4_op_lookup and rfs4_op_lookupp to do the actual work.
2553 do_rfs4_op_lookup(char *nm
, struct svc_req
*req
, struct compound_state
*cs
)
2556 int different_export
= 0;
2557 vnode_t
*vp
, *pre_tvp
= NULL
, *oldvp
= NULL
;
2558 struct exportinfo
*exi
= NULL
, *pre_exi
= NULL
;
2561 int attrdir
, dotdot
, walk
;
2562 bool_t is_newvp
= FALSE
;
2564 if (cs
->vp
->v_flag
& V_XATTRDIR
) {
2566 ASSERT(get_fh4_flag(&cs
->fh
, FH4_ATTRDIR
));
2569 ASSERT(! get_fh4_flag(&cs
->fh
, FH4_ATTRDIR
));
2572 dotdot
= (nm
[0] == '.' && nm
[1] == '.' && nm
[2] == '\0');
2575 * If dotdotting, then need to check whether it's
2576 * above the root of a filesystem, or above an
2582 * If dotdotting at the root of a filesystem, then
2583 * need to traverse back to the mounted-on filesystem
2584 * and do the dotdot lookup there.
2586 if (cs
->vp
->v_flag
& VROOT
) {
2589 * If at the system root, then can
2592 if (VN_CMP(cs
->vp
, rootdir
))
2593 return (puterrno4(ENOENT
));
2596 * Traverse back to the mounted-on filesystem
2598 cs
->vp
= untraverse(cs
->vp
);
2601 * Set the different_export flag so we remember
2602 * to pick up a new exportinfo entry for
2603 * this new filesystem.
2605 different_export
= 1;
2609 * If dotdotting above an export point then set
2610 * the different_export to get new export info.
2612 different_export
= nfs_exported(cs
->exi
, cs
->vp
);
2616 error
= fop_lookup(cs
->vp
, nm
, &vp
, NULL
, 0, NULL
, cs
->cr
,
2619 return (puterrno4(error
));
2622 * If the vnode is in a pseudo filesystem, check whether it is visible.
2624 * XXX if the vnode is a symlink and it is not visible in
2625 * a pseudo filesystem, return ENOENT (not following symlink).
2626 * V4 client can not mount such symlink. This is a regression
2629 * In the same exported filesystem, if the security flavor used
2630 * is not an explicitly shared flavor, limit the view to the visible
2631 * list entries only. This is not a WRONGSEC case because it's already
2632 * checked via PUTROOTFH/PUTPUBFH or PUTFH.
2634 if (!different_export
&&
2635 (PSEUDO(cs
->exi
) || ! is_exported_sec(cs
->nfsflavor
, cs
->exi
) ||
2636 cs
->access
& CS_ACCESS_LIMITED
)) {
2637 if (! nfs_visible(cs
->exi
, vp
, &different_export
)) {
2639 return (puterrno4(ENOENT
));
2644 * If it's a mountpoint, then traverse it.
2646 if (vn_ismntpt(vp
)) {
2647 pre_exi
= cs
->exi
; /* save pre-traversed exportinfo */
2648 pre_tvp
= vp
; /* save pre-traversed vnode */
2651 * hold pre_tvp to counteract rele by traverse. We will
2652 * need pre_tvp below if checkexport4 fails
2655 if ((error
= traverse(&vp
)) != 0) {
2658 return (puterrno4(error
));
2660 different_export
= 1;
2661 } else if (vp
->v_vfsp
!= cs
->vp
->v_vfsp
) {
2663 * The vfsp comparison is to handle the case where
2664 * a LOFS mount is shared. lo_lookup traverses mount points,
2665 * and NFS is unaware of local fs transistions because
2666 * v_vfsmountedhere isn't set. For this special LOFS case,
2667 * the dir and the obj returned by lookup will have different
2670 different_export
= 1;
2673 if (different_export
) {
2675 bzero(&fid
, sizeof (fid
));
2676 fid
.fid_len
= MAXFIDSZ
;
2677 error
= vop_fid_pseudo(vp
, &fid
);
2682 return (puterrno4(error
));
2686 exi
= nfs_vptoexi(NULL
, vp
, cs
->cr
, &walk
, NULL
, TRUE
);
2688 exi
= checkexport4(&vp
->v_vfsp
->vfs_fsid
, &fid
, vp
);
2693 * If this vnode is a mounted-on vnode,
2694 * but the mounted-on file system is not
2695 * exported, send back the filehandle for
2696 * the mounted-on vnode, not the root of
2697 * the mounted-on file system.
2704 return (puterrno4(EACCES
));
2706 } else if (pre_tvp
) {
2707 /* we're done with pre_tvp now. release extra hold */
2714 * Now we do a checkauth4. The reason is that
2715 * this client/user may not have access to the new
2716 * exported file system, and if they do,
2717 * the client/user may be mapped to a different uid.
2719 * We start with a new cr, because the checkauth4 done
2720 * in the PUT*FH operation over wrote the cred's uid,
2721 * gid, etc, and we want the real thing before calling
2725 cs
->cr
= crdup(cs
->basecr
);
2731 stat
= call_checkauth4(cs
, req
);
2732 if (stat
!= NFS4_OK
) {
2739 error
= makefh4(&cs
->fh
, vp
, cs
->exi
);
2748 return (puterrno4(error
));
2759 * if did lookup on attrdir and didn't lookup .., set named
2762 if (attrdir
&& ! dotdot
)
2763 set_fh4_flag(&cs
->fh
, FH4_NAMEDATTR
);
2765 /* Assume false for now, open proc will set this */
2766 cs
->mandlock
= FALSE
;
2773 rfs4_op_lookup(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2774 struct compound_state
*cs
)
2776 LOOKUP4args
*args
= &argop
->nfs_argop4_u
.oplookup
;
2777 LOOKUP4res
*resp
= &resop
->nfs_resop4_u
.oplookup
;
2780 struct sockaddr
*ca
;
2784 DTRACE_NFSV4_2(op__lookup__start
, struct compound_state
*, cs
,
2785 LOOKUP4args
*, args
);
2787 if (cs
->vp
== NULL
) {
2788 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2792 if (cs
->vp
->v_type
== VLNK
) {
2793 *cs
->statusp
= resp
->status
= NFS4ERR_SYMLINK
;
2797 if (cs
->vp
->v_type
!= VDIR
) {
2798 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
2802 status
= utf8_dir_verify(&args
->objname
);
2803 if (status
!= NFS4_OK
) {
2804 *cs
->statusp
= resp
->status
= status
;
2808 nm
= utf8_to_str(&args
->objname
, &len
, NULL
);
2810 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2814 if (len
> MAXNAMELEN
) {
2815 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
2820 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
2821 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
2825 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
2830 *cs
->statusp
= resp
->status
= do_rfs4_op_lookup(name
, req
, cs
);
2833 kmem_free(name
, MAXPATHLEN
+ 1);
2837 DTRACE_NFSV4_2(op__lookup__done
, struct compound_state
*, cs
,
2838 LOOKUP4res
*, resp
);
2843 rfs4_op_lookupp(nfs_argop4
*args
, nfs_resop4
*resop
, struct svc_req
*req
,
2844 struct compound_state
*cs
)
2846 LOOKUPP4res
*resp
= &resop
->nfs_resop4_u
.oplookupp
;
2848 DTRACE_NFSV4_1(op__lookupp__start
, struct compound_state
*, cs
);
2850 if (cs
->vp
== NULL
) {
2851 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2855 if (cs
->vp
->v_type
!= VDIR
) {
2856 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
2860 *cs
->statusp
= resp
->status
= do_rfs4_op_lookup("..", req
, cs
);
2863 * From NFSV4 Specification, LOOKUPP should not check for
2864 * NFS4ERR_WRONGSEC. Retrun NFS4_OK instead.
2866 if (resp
->status
== NFS4ERR_WRONGSEC
) {
2867 *cs
->statusp
= resp
->status
= NFS4_OK
;
2871 DTRACE_NFSV4_2(op__lookupp__done
, struct compound_state
*, cs
,
2872 LOOKUPP4res
*, resp
);
2878 rfs4_op_openattr(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
2879 struct compound_state
*cs
)
2881 OPENATTR4args
*args
= &argop
->nfs_argop4_u
.opopenattr
;
2882 OPENATTR4res
*resp
= &resop
->nfs_resop4_u
.opopenattr
;
2883 vnode_t
*avp
= NULL
;
2884 int lookup_flags
= LOOKUP_XATTR
, error
;
2887 DTRACE_NFSV4_2(op__openattr__start
, struct compound_state
*, cs
,
2888 OPENATTR4args
*, args
);
2890 if (cs
->vp
== NULL
) {
2891 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
2895 if ((cs
->vp
->v_vfsp
->vfs_flag
& VFS_XATTR
) == 0 &&
2896 !vfs_has_feature(cs
->vp
->v_vfsp
, VFSFT_SYSATTR_VIEWS
)) {
2897 *cs
->statusp
= resp
->status
= puterrno4(ENOTSUP
);
2902 * If file system supports passing ACE mask to fop_access then
2903 * check for ACE_READ_NAMED_ATTRS, otherwise do legacy checks
2906 if (vfs_has_feature(cs
->vp
->v_vfsp
, VFSFT_ACEMASKONACCESS
))
2907 error
= fop_access(cs
->vp
, ACE_READ_NAMED_ATTRS
,
2908 V_ACE_MASK
, cs
->cr
, NULL
);
2910 error
= ((fop_access(cs
->vp
, VREAD
, 0, cs
->cr
, NULL
) != 0) &&
2911 (fop_access(cs
->vp
, VWRITE
, 0, cs
->cr
, NULL
) != 0) &&
2912 (fop_access(cs
->vp
, VEXEC
, 0, cs
->cr
, NULL
) != 0));
2915 *cs
->statusp
= resp
->status
= puterrno4(EACCES
);
2920 * The CREATE_XATTR_DIR VOP flag cannot be specified if
2921 * the file system is exported read-only -- regardless of
2922 * createdir flag. Otherwise the attrdir would be created
2923 * (assuming server fs isn't mounted readonly locally). If
2924 * fop_lookup returns ENOENT in this case, the error will
2925 * be translated into EROFS. ENOSYS is mapped to ENOTSUP
2926 * because specfs has no fop_lookup op, so the macro would
2927 * return ENOSYS. EINVAL is returned by all (current)
2928 * Solaris file system implementations when any of their
2929 * restrictions are violated (xattr(dir) can't have xattrdir).
2930 * Returning NOTSUPP is more appropriate in this case
2931 * because the object will never be able to have an attrdir.
2933 if (args
->createdir
&& ! (exp_ro
= rdonly4(req
, cs
)))
2934 lookup_flags
|= CREATE_XATTR_DIR
;
2936 error
= fop_lookup(cs
->vp
, "", &avp
, NULL
, lookup_flags
, NULL
, cs
->cr
,
2940 if (error
== ENOENT
&& args
->createdir
&& exp_ro
)
2941 *cs
->statusp
= resp
->status
= puterrno4(EROFS
);
2942 else if (error
== EINVAL
|| error
== ENOSYS
)
2943 *cs
->statusp
= resp
->status
= puterrno4(ENOTSUP
);
2945 *cs
->statusp
= resp
->status
= puterrno4(error
);
2949 ASSERT(avp
->v_flag
& V_XATTRDIR
);
2951 error
= makefh4(&cs
->fh
, avp
, cs
->exi
);
2955 *cs
->statusp
= resp
->status
= puterrno4(error
);
2963 * There is no requirement for an attrdir fh flag
2964 * because the attrdir has a vnode flag to distinguish
2965 * it from regular (non-xattr) directories. The
2966 * FH4_ATTRDIR flag is set for future sanity checks.
2968 set_fh4_flag(&cs
->fh
, FH4_ATTRDIR
);
2969 *cs
->statusp
= resp
->status
= NFS4_OK
;
2972 DTRACE_NFSV4_2(op__openattr__done
, struct compound_state
*, cs
,
2973 OPENATTR4res
*, resp
);
2977 do_io(int direction
, vnode_t
*vp
, struct uio
*uio
, int ioflag
, cred_t
*cred
,
2978 caller_context_t
*ct
)
2984 delaytime
= MSEC_TO_TICK_ROUNDUP(rfs4_lock_delay
);
2987 * Don't block on mandatory locks. If this routine returns
2988 * EAGAIN, the caller should return NFS4ERR_LOCKED.
2990 uio
->uio_fmode
= FNONBLOCK
;
2992 for (i
= 0; i
< rfs4_maxlock_tries
; i
++) {
2995 if (direction
== FREAD
) {
2996 (void) fop_rwlock(vp
, V_WRITELOCK_FALSE
, ct
);
2997 error
= fop_read(vp
, uio
, ioflag
, cred
, ct
);
2998 fop_rwunlock(vp
, V_WRITELOCK_FALSE
, ct
);
3000 (void) fop_rwlock(vp
, V_WRITELOCK_TRUE
, ct
);
3001 error
= fop_write(vp
, uio
, ioflag
, cred
, ct
);
3002 fop_rwunlock(vp
, V_WRITELOCK_TRUE
, ct
);
3005 if (error
!= EAGAIN
)
3008 if (i
< rfs4_maxlock_tries
- 1) {
3019 rfs4_op_read(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3020 struct compound_state
*cs
)
3022 READ4args
*args
= &argop
->nfs_argop4_u
.opread
;
3023 READ4res
*resp
= &resop
->nfs_resop4_u
.opread
;
3028 struct iovec iov
, *iovp
= NULL
;
3032 bool_t
*deleg
= &cs
->deleg
;
3039 caller_context_t ct
;
3042 DTRACE_NFSV4_2(op__read__start
, struct compound_state
*, cs
,
3047 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
3050 if (cs
->access
== CS_ACCESS_DENIED
) {
3051 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3055 if ((stat
= rfs4_check_stateid(FREAD
, vp
, &args
->stateid
, FALSE
,
3056 deleg
, TRUE
, &ct
)) != NFS4_OK
) {
3057 *cs
->statusp
= resp
->status
= stat
;
3062 * Enter the critical region before calling fop_rwlock
3063 * to avoid a deadlock with write requests.
3065 if (nbl_need_check(vp
)) {
3066 nbl_start_crit(vp
, RW_READER
);
3068 if (nbl_conflict(vp
, NBL_READ
, args
->offset
, args
->count
, 0,
3070 *cs
->statusp
= resp
->status
= NFS4ERR_LOCKED
;
3076 if (args
->count
> clist_len(args
->wlist
)) {
3077 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3083 /* use loaned buffers for TCP */
3084 loaned_buffers
= (nfs_loaned_buffers
&& !rdma_used
) ? 1 : 0;
3086 va
.va_mask
= VATTR_MODE
|VATTR_SIZE
|VATTR_UID
;
3087 verror
= fop_getattr(vp
, &va
, 0, cs
->cr
, &ct
);
3090 * If we can't get the attributes, then we can't do the
3091 * right access checking. So, we'll fail the request.
3094 *cs
->statusp
= resp
->status
= puterrno4(verror
);
3098 if (vp
->v_type
!= VREG
) {
3099 *cs
->statusp
= resp
->status
=
3100 ((vp
->v_type
== VDIR
) ? NFS4ERR_ISDIR
: NFS4ERR_INVAL
);
3104 if (crgetuid(cs
->cr
) != va
.va_uid
&&
3105 (error
= fop_access(vp
, VREAD
, 0, cs
->cr
, &ct
)) &&
3106 (error
= fop_access(vp
, VEXEC
, 0, cs
->cr
, &ct
))) {
3107 *cs
->statusp
= resp
->status
= puterrno4(error
);
3111 if (MANDLOCK(vp
, va
.va_mode
)) { /* XXX - V4 supports mand locking */
3112 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3116 offset
= args
->offset
;
3117 if (offset
>= va
.va_size
) {
3118 *cs
->statusp
= resp
->status
= NFS4_OK
;
3121 resp
->data_val
= NULL
;
3124 resp
->wlist
= args
->wlist
;
3125 resp
->wlist_len
= resp
->data_len
;
3126 *cs
->statusp
= resp
->status
= NFS4_OK
;
3128 clist_zero_len(resp
->wlist
);
3132 if (args
->count
== 0) {
3133 *cs
->statusp
= resp
->status
= NFS4_OK
;
3136 resp
->data_val
= NULL
;
3139 resp
->wlist
= args
->wlist
;
3140 resp
->wlist_len
= resp
->data_len
;
3142 clist_zero_len(resp
->wlist
);
3147 * Do not allocate memory more than maximum allowed
3150 if (args
->count
> rfs4_tsize(req
))
3151 args
->count
= rfs4_tsize(req
);
3153 if (loaned_buffers
) {
3154 uiop
= (uio_t
*)rfs_setup_xuio(vp
);
3155 ASSERT(uiop
!= NULL
);
3156 uiop
->uio_segflg
= UIO_SYSSPACE
;
3157 uiop
->uio_loffset
= args
->offset
;
3158 uiop
->uio_resid
= args
->count
;
3160 /* Jump to do the read if successful */
3161 if (!fop_reqzcbuf(vp
, UIO_READ
, (xuio_t
*)uiop
, cs
->cr
, &ct
)) {
3163 * Need to hold the vnode until after fop_retzcbuf()
3170 DTRACE_PROBE2(nfss__i__reqzcbuf_failed
, int,
3171 uiop
->uio_loffset
, int, uiop
->uio_resid
);
3173 uiop
->uio_extflg
= 0;
3175 /* failure to setup for zero copy */
3176 rfs_free_xuio((void *)uiop
);
3181 * If returning data via RDMA Write, then grab the chunk list. If we
3182 * aren't returning READ data w/RDMA_WRITE, then grab a mblk.
3186 (void) rdma_get_wchunk(req
, &iov
, args
->wlist
);
3191 * mp will contain the data to be sent out in the read reply.
3192 * It will be freed after the reply has been sent.
3194 mp
= rfs_read_alloc(args
->count
, &iovp
, &iovcnt
);
3196 ASSERT(alloc_err
== 0);
3198 uio
.uio_iovcnt
= iovcnt
;
3201 uio
.uio_segflg
= UIO_SYSSPACE
;
3202 uio
.uio_extflg
= UIO_COPY_CACHED
;
3203 uio
.uio_loffset
= args
->offset
;
3204 uio
.uio_resid
= args
->count
;
3208 error
= do_io(FREAD
, vp
, uiop
, 0, cs
->cr
, &ct
);
3210 va
.va_mask
= VATTR_SIZE
;
3211 verror
= fop_getattr(vp
, &va
, 0, cs
->cr
, &ct
);
3216 *cs
->statusp
= resp
->status
= puterrno4(error
);
3220 /* make mblk using zc buffers */
3221 if (loaned_buffers
) {
3222 mp
= uio_to_mblk(uiop
);
3226 *cs
->statusp
= resp
->status
= NFS4_OK
;
3228 ASSERT(uiop
->uio_resid
>= 0);
3229 resp
->data_len
= args
->count
- uiop
->uio_resid
;
3231 resp
->data_val
= (char *)mp
->b_datap
->db_base
;
3232 rfs_rndup_mblks(mp
, resp
->data_len
, loaned_buffers
);
3234 resp
->data_val
= (caddr_t
)iov
.iov_base
;
3239 if (!verror
&& offset
+ resp
->data_len
== va
.va_size
)
3245 if (!rdma_setup_read_data4(args
, resp
)) {
3246 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3257 kmem_free(iovp
, iovcnt
* sizeof (struct iovec
));
3259 DTRACE_NFSV4_2(op__read__done
, struct compound_state
*, cs
,
3264 rfs4_op_read_free(nfs_resop4
*resop
)
3266 READ4res
*resp
= &resop
->nfs_resop4_u
.opread
;
3268 if (resp
->status
== NFS4_OK
&& resp
->mblk
!= NULL
) {
3269 freemsg(resp
->mblk
);
3271 resp
->data_val
= NULL
;
3277 rfs4_op_readdir_free(nfs_resop4
* resop
)
3279 READDIR4res
*resp
= &resop
->nfs_resop4_u
.opreaddir
;
3281 if (resp
->status
== NFS4_OK
&& resp
->mblk
!= NULL
) {
3291 rfs4_op_putpubfh(nfs_argop4
*args
, nfs_resop4
*resop
, struct svc_req
*req
,
3292 struct compound_state
*cs
)
3294 PUTPUBFH4res
*resp
= &resop
->nfs_resop4_u
.opputpubfh
;
3297 struct exportinfo
*exi
, *sav_exi
;
3298 nfs_fh4_fmt_t
*fh_fmtp
;
3300 DTRACE_NFSV4_1(op__putpubfh__start
, struct compound_state
*, cs
);
3310 cs
->cr
= crdup(cs
->basecr
);
3312 vp
= exi_public
->exi_vp
;
3314 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
3318 error
= makefh4(&cs
->fh
, vp
, exi_public
);
3320 *cs
->statusp
= resp
->status
= puterrno4(error
);
3324 if (exi_public
== exi_root
) {
3326 * No filesystem is actually shared public, so we default
3327 * to exi_root. In this case, we must check whether root
3330 fh_fmtp
= (nfs_fh4_fmt_t
*)cs
->fh
.nfs_fh4_val
;
3333 * if root filesystem is exported, the exportinfo struct that we
3334 * should use is what checkexport4 returns, because root_exi is
3335 * actually a mostly empty struct.
3337 exi
= checkexport4(&fh_fmtp
->fh4_fsid
,
3338 (fid_t
*)&fh_fmtp
->fh4_xlen
, NULL
);
3339 cs
->exi
= ((exi
!= NULL
) ? exi
: exi_public
);
3342 * it's a properly shared filesystem
3344 cs
->exi
= exi_public
;
3350 if ((resp
->status
= call_checkauth4(cs
, req
)) != NFS4_OK
) {
3357 *cs
->statusp
= resp
->status
= NFS4_OK
;
3359 DTRACE_NFSV4_2(op__putpubfh__done
, struct compound_state
*, cs
,
3360 PUTPUBFH4res
*, resp
);
3364 * XXX - issue with put*fh operations. Suppose /export/home is exported.
3365 * Suppose an NFS client goes to mount /export/home/joe. If /export, home,
3366 * or joe have restrictive search permissions, then we shouldn't let
3367 * the client get a file handle. This is easy to enforce. However, we
3368 * don't know what security flavor should be used until we resolve the
3369 * path name. Another complication is uid mapping. If root is
3370 * the user, then it will be mapped to the anonymous user by default,
3371 * but we won't know that till we've resolved the path name. And we won't
3372 * know what the anonymous user is.
3373 * Luckily, SECINFO is specified to take a full filename.
3374 * So what we will have to in rfs4_op_lookup is check that flavor of
3375 * the target object matches that of the request, and if root was the
3376 * caller, check for the root= and anon= options, and if necessary,
3377 * repeat the lookup using the right cred_t. But that's not done yet.
3381 rfs4_op_putfh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3382 struct compound_state
*cs
)
3384 PUTFH4args
*args
= &argop
->nfs_argop4_u
.opputfh
;
3385 PUTFH4res
*resp
= &resop
->nfs_resop4_u
.opputfh
;
3386 nfs_fh4_fmt_t
*fh_fmtp
;
3388 DTRACE_NFSV4_2(op__putfh__start
, struct compound_state
*, cs
,
3389 PUTFH4args
*, args
);
3402 if (args
->object
.nfs_fh4_len
< NFS_FH4_LEN
) {
3403 *cs
->statusp
= resp
->status
= NFS4ERR_BADHANDLE
;
3407 fh_fmtp
= (nfs_fh4_fmt_t
*)args
->object
.nfs_fh4_val
;
3408 cs
->exi
= checkexport4(&fh_fmtp
->fh4_fsid
, (fid_t
*)&fh_fmtp
->fh4_xlen
,
3411 if (cs
->exi
== NULL
) {
3412 *cs
->statusp
= resp
->status
= NFS4ERR_STALE
;
3416 cs
->cr
= crdup(cs
->basecr
);
3418 ASSERT(cs
->cr
!= NULL
);
3420 if (! (cs
->vp
= nfs4_fhtovp(&args
->object
, cs
->exi
, &resp
->status
))) {
3421 *cs
->statusp
= resp
->status
;
3425 if ((resp
->status
= call_checkauth4(cs
, req
)) != NFS4_OK
) {
3431 nfs_fh4_copy(&args
->object
, &cs
->fh
);
3432 *cs
->statusp
= resp
->status
= NFS4_OK
;
3436 DTRACE_NFSV4_2(op__putfh__done
, struct compound_state
*, cs
,
3442 rfs4_op_putrootfh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3443 struct compound_state
*cs
)
3445 PUTROOTFH4res
*resp
= &resop
->nfs_resop4_u
.opputrootfh
;
3448 struct exportinfo
*exi
, *sav_exi
;
3450 DTRACE_NFSV4_1(op__putrootfh__start
, struct compound_state
*, cs
);
3460 cs
->cr
= crdup(cs
->basecr
);
3463 * Using rootdir, the system root vnode,
3466 bzero(&fid
, sizeof (fid
));
3467 fid
.fid_len
= MAXFIDSZ
;
3468 error
= vop_fid_pseudo(rootdir
, &fid
);
3470 *cs
->statusp
= resp
->status
= puterrno4(error
);
3475 * Then use the root fsid & fid it to find out if it's exported
3477 * If the server root isn't exported directly, then
3478 * it should at least be a pseudo export based on
3479 * one or more exports further down in the server's
3482 exi
= checkexport4(&rootdir
->v_vfsp
->vfs_fsid
, &fid
, NULL
);
3483 if (exi
== NULL
|| exi
->exi_export
.ex_flags
& EX_PUBLIC
) {
3484 NFS4_DEBUG(rfs4_debug
,
3485 (CE_WARN
, "rfs4_op_putrootfh: export check failure"));
3486 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
3491 * Now make a filehandle based on the root
3492 * export and root vnode.
3494 error
= makefh4(&cs
->fh
, rootdir
, exi
);
3496 *cs
->statusp
= resp
->status
= puterrno4(error
);
3506 if ((resp
->status
= call_checkauth4(cs
, req
)) != NFS4_OK
) {
3513 *cs
->statusp
= resp
->status
= NFS4_OK
;
3516 DTRACE_NFSV4_2(op__putrootfh__done
, struct compound_state
*, cs
,
3517 PUTROOTFH4res
*, resp
);
3521 * readlink: args: CURRENT_FH.
3522 * res: status. If success - CURRENT_FH unchanged, return linktext.
3527 rfs4_op_readlink(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3528 struct compound_state
*cs
)
3530 READLINK4res
*resp
= &resop
->nfs_resop4_u
.opreadlink
;
3537 struct sockaddr
*ca
;
3541 DTRACE_NFSV4_1(op__readlink__start
, struct compound_state
*, cs
);
3543 /* CURRENT_FH: directory */
3546 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
3550 if (cs
->access
== CS_ACCESS_DENIED
) {
3551 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3555 /* Is it a referral? */
3556 if (vn_is_nfs_reparse(vp
, cs
->cr
) && client_is_downrev(req
)) {
3564 if (vp
->v_type
== VDIR
) {
3565 *cs
->statusp
= resp
->status
= NFS4ERR_ISDIR
;
3569 if (vp
->v_type
!= VLNK
) {
3570 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3576 va
.va_mask
= VATTR_MODE
;
3577 error
= fop_getattr(vp
, &va
, 0, cs
->cr
, NULL
);
3579 *cs
->statusp
= resp
->status
= puterrno4(error
);
3583 if (MANDLOCK(vp
, va
.va_mode
)) {
3584 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3588 data
= kmem_alloc(MAXPATHLEN
+ 1, KM_SLEEP
);
3594 /* Get an artificial symlink based on a referral */
3595 s
= build_symlink(vp
, cs
->cr
, &strsz
);
3596 global_svstat_ptr
[4][NFS_REFERLINKS
].value
.ui64
++;
3597 DTRACE_PROBE2(nfs4serv__func__referral__reflink
,
3598 vnode_t
*, vp
, char *, s
);
3603 (void) strlcpy(data
, s
, MAXPATHLEN
+ 1);
3604 kmem_free(s
, strsz
);
3609 iov
.iov_base
= data
;
3610 iov
.iov_len
= MAXPATHLEN
;
3613 uio
.uio_segflg
= UIO_SYSSPACE
;
3614 uio
.uio_extflg
= UIO_COPY_CACHED
;
3615 uio
.uio_loffset
= 0;
3616 uio
.uio_resid
= MAXPATHLEN
;
3618 error
= fop_readlink(vp
, &uio
, cs
->cr
, NULL
);
3621 *(data
+ MAXPATHLEN
- uio
.uio_resid
) = '\0';
3625 kmem_free((caddr_t
)data
, (uint_t
)MAXPATHLEN
+ 1);
3626 *cs
->statusp
= resp
->status
= puterrno4(error
);
3630 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
3631 name
= nfscmd_convname(ca
, cs
->exi
, data
, NFSCMD_CONV_OUTBOUND
,
3636 * Even though the conversion failed, we return
3637 * something. We just don't translate it.
3643 * treat link name as data
3645 (void) str_to_utf8(name
, (utf8string
*)&resp
->link
);
3648 kmem_free(name
, MAXPATHLEN
+ 1);
3649 kmem_free((caddr_t
)data
, (uint_t
)MAXPATHLEN
+ 1);
3650 *cs
->statusp
= resp
->status
= NFS4_OK
;
3653 DTRACE_NFSV4_2(op__readlink__done
, struct compound_state
*, cs
,
3654 READLINK4res
*, resp
);
3658 rfs4_op_readlink_free(nfs_resop4
*resop
)
3660 READLINK4res
*resp
= &resop
->nfs_resop4_u
.opreadlink
;
3661 utf8string
*symlink
= (utf8string
*)&resp
->link
;
3663 if (symlink
->utf8string_val
) {
3664 UTF8STRING_FREE(*symlink
)
3669 * release_lockowner:
3670 * Release any state associated with the supplied
3671 * lockowner. Note if any lo_state is holding locks we will not
3672 * rele that lo_state and thus the lockowner will not be destroyed.
3673 * A client using lock after the lock owner stateid has been released
3674 * will suffer the consequence of NFS4ERR_BAD_STATEID and would have
3675 * to reissue the lock with new_lock_owner set to TRUE.
3681 rfs4_op_release_lockowner(nfs_argop4
*argop
, nfs_resop4
*resop
,
3682 struct svc_req
*req
, struct compound_state
*cs
)
3684 RELEASE_LOCKOWNER4args
*ap
= &argop
->nfs_argop4_u
.oprelease_lockowner
;
3685 RELEASE_LOCKOWNER4res
*resp
= &resop
->nfs_resop4_u
.oprelease_lockowner
;
3686 rfs4_lockowner_t
*lo
;
3687 rfs4_openowner_t
*oo
;
3689 rfs4_lo_state_t
*lsp
;
3691 bool_t create
= FALSE
;
3695 DTRACE_NFSV4_2(op__release__lockowner__start
, struct compound_state
*,
3696 cs
, RELEASE_LOCKOWNER4args
*, ap
);
3698 /* Make sure there is a clientid around for this request */
3699 cp
= rfs4_findclient_by_id(ap
->lock_owner
.clientid
, FALSE
);
3702 *cs
->statusp
= resp
->status
=
3703 rfs4_check_clientid(&ap
->lock_owner
.clientid
, 0);
3706 rfs4_client_rele(cp
);
3708 lo
= rfs4_findlockowner(&ap
->lock_owner
, &create
);
3710 *cs
->statusp
= resp
->status
= NFS4_OK
;
3713 ASSERT(lo
->rl_client
!= NULL
);
3716 * Check for EXPIRED client. If so will reap state with in a lease
3717 * period or on next set_clientid_confirm step
3719 if (rfs4_lease_expired(lo
->rl_client
)) {
3720 rfs4_lockowner_rele(lo
);
3721 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
3726 * If no sysid has been assigned, then no locks exist; just return.
3728 rfs4_dbe_lock(lo
->rl_client
->rc_dbe
);
3729 if (lo
->rl_client
->rc_sysidt
== LM_NOSYSID
) {
3730 rfs4_lockowner_rele(lo
);
3731 rfs4_dbe_unlock(lo
->rl_client
->rc_dbe
);
3735 sysid
= lo
->rl_client
->rc_sysidt
;
3736 rfs4_dbe_unlock(lo
->rl_client
->rc_dbe
);
3739 * Mark the lockowner invalid.
3741 rfs4_dbe_hide(lo
->rl_dbe
);
3744 * sysid-pid pair should now not be used since the lockowner is
3745 * invalid. If the client were to instantiate the lockowner again
3746 * it would be assigned a new pid. Thus we can get the list of
3750 llist
= flk_get_active_locks(sysid
, lo
->rl_pid
);
3751 /* If we are still holding locks fail */
3752 if (llist
!= NULL
) {
3754 *cs
->statusp
= resp
->status
= NFS4ERR_LOCKS_HELD
;
3756 flk_free_locklist(llist
);
3758 * We need to unhide the lockowner so the client can
3759 * try it again. The bad thing here is if the client
3760 * has a logic error that took it here in the first place
3761 * they probably have lost accounting of the locks that it
3762 * is holding. So we may have dangling state until the
3763 * open owner state is reaped via close. One scenario
3764 * that could possibly occur is that the client has
3765 * sent the unlock request(s) in separate threads
3766 * and has not waited for the replies before sending the
3767 * RELEASE_LOCKOWNER request. Presumably, it would expect
3768 * and deal appropriately with NFS4ERR_LOCKS_HELD, by
3769 * reissuing the request.
3771 rfs4_dbe_unhide(lo
->rl_dbe
);
3772 rfs4_lockowner_rele(lo
);
3777 * For the corresponding client we need to check each open
3778 * owner for any opens that have lockowner state associated
3779 * with this lockowner.
3782 rfs4_dbe_lock(lo
->rl_client
->rc_dbe
);
3783 for (oo
= list_head(&lo
->rl_client
->rc_openownerlist
); oo
!= NULL
;
3784 oo
= list_next(&lo
->rl_client
->rc_openownerlist
, oo
)) {
3786 rfs4_dbe_lock(oo
->ro_dbe
);
3787 for (sp
= list_head(&oo
->ro_statelist
); sp
!= NULL
;
3788 sp
= list_next(&oo
->ro_statelist
, sp
)) {
3790 rfs4_dbe_lock(sp
->rs_dbe
);
3791 for (lsp
= list_head(&sp
->rs_lostatelist
);
3793 lsp
= list_next(&sp
->rs_lostatelist
, lsp
)) {
3794 if (lsp
->rls_locker
== lo
) {
3795 rfs4_dbe_lock(lsp
->rls_dbe
);
3796 rfs4_dbe_invalidate(lsp
->rls_dbe
);
3797 rfs4_dbe_unlock(lsp
->rls_dbe
);
3800 rfs4_dbe_unlock(sp
->rs_dbe
);
3802 rfs4_dbe_unlock(oo
->ro_dbe
);
3804 rfs4_dbe_unlock(lo
->rl_client
->rc_dbe
);
3806 rfs4_lockowner_rele(lo
);
3808 *cs
->statusp
= resp
->status
= NFS4_OK
;
3811 DTRACE_NFSV4_2(op__release__lockowner__done
, struct compound_state
*,
3812 cs
, RELEASE_LOCKOWNER4res
*, resp
);
3816 * short utility function to lookup a file and recall the delegation
3818 static rfs4_file_t
*
3819 rfs4_lookup_and_findfile(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
,
3820 int *lkup_error
, cred_t
*cr
)
3823 rfs4_file_t
*fp
= NULL
;
3824 bool_t fcreate
= FALSE
;
3830 if ((error
= fop_lookup(dvp
, nm
, &vp
, NULL
, 0, NULL
, cr
, NULL
, NULL
,
3832 if (vp
->v_type
== VREG
)
3833 fp
= rfs4_findfile(vp
, NULL
, &fcreate
);
3841 *lkup_error
= error
;
3847 * remove: args: CURRENT_FH: directory; name.
3848 * res: status. If success - CURRENT_FH unchanged, return change_info
3853 rfs4_op_remove(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
3854 struct compound_state
*cs
)
3856 REMOVE4args
*args
= &argop
->nfs_argop4_u
.opremove
;
3857 REMOVE4res
*resp
= &resop
->nfs_resop4_u
.opremove
;
3860 struct vattr bdva
, idva
, adva
;
3865 struct sockaddr
*ca
;
3869 DTRACE_NFSV4_2(op__remove__start
, struct compound_state
*, cs
,
3870 REMOVE4args
*, args
);
3872 /* CURRENT_FH: directory */
3875 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
3879 if (cs
->access
== CS_ACCESS_DENIED
) {
3880 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3885 * If there is an unshared filesystem mounted on this vnode,
3886 * Do not allow to remove anything in this directory.
3888 if (vn_ismntpt(dvp
)) {
3889 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
3893 if (dvp
->v_type
!= VDIR
) {
3894 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
3898 status
= utf8_dir_verify(&args
->target
);
3899 if (status
!= NFS4_OK
) {
3900 *cs
->statusp
= resp
->status
= status
;
3905 * Lookup the file so that we can check if it's a directory
3907 nm
= utf8_to_fn(&args
->target
, &len
, NULL
);
3909 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3913 if (len
> MAXNAMELEN
) {
3914 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
3919 if (rdonly4(req
, cs
)) {
3920 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
3925 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
3926 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
3930 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
3936 * Lookup the file to determine type and while we are see if
3937 * there is a file struct around and check for delegation.
3938 * We don't need to acquire va_seq before this lookup, if
3939 * it causes an update, cinfo.before will not match, which will
3940 * trigger a cache flush even if atomic is TRUE.
3942 if (fp
= rfs4_lookup_and_findfile(dvp
, name
, &vp
, &error
, cs
->cr
)) {
3943 if (rfs4_check_delegated_byfp(FWRITE
, fp
, TRUE
, TRUE
, TRUE
,
3947 *cs
->statusp
= resp
->status
= NFS4ERR_DELAY
;
3949 kmem_free(name
, MAXPATHLEN
+ 1);
3955 /* Didn't find anything to remove */
3957 *cs
->statusp
= resp
->status
= error
;
3959 kmem_free(name
, MAXPATHLEN
+ 1);
3964 if (nbl_need_check(vp
)) {
3965 nbl_start_crit(vp
, RW_READER
);
3967 if (nbl_conflict(vp
, NBL_REMOVE
, 0, 0, 0, NULL
)) {
3968 *cs
->statusp
= resp
->status
= NFS4ERR_FILE_OPEN
;
3970 kmem_free(name
, MAXPATHLEN
+ 1);
3975 rfs4_clear_dont_grant(fp
);
3982 /* Get dir "before" change value */
3983 bdva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
3984 error
= fop_getattr(dvp
, &bdva
, 0, cs
->cr
, NULL
);
3986 *cs
->statusp
= resp
->status
= puterrno4(error
);
3988 kmem_free(name
, MAXPATHLEN
+ 1);
3994 rfs4_clear_dont_grant(fp
);
3999 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.before
, bdva
.va_ctime
)
4001 /* Actually do the REMOVE operation */
4002 if (vp
->v_type
== VDIR
) {
4004 * Can't remove a directory that has a mounted-on filesystem.
4006 if (vn_ismntpt(vp
)) {
4010 * System V defines rmdir to return EEXIST,
4011 * not ENOTEMPTY, if the directory is not
4012 * empty. A System V NFS server needs to map
4013 * NFS4ERR_EXIST to NFS4ERR_NOTEMPTY to
4014 * transmit over the wire.
4016 if ((error
= fop_rmdir(dvp
, name
, rootdir
, cs
->cr
,
4017 NULL
, 0)) == EEXIST
)
4021 if ((error
= fop_remove(dvp
, name
, cs
->cr
, NULL
, 0)) == 0 &&
4026 rfs4_dbe_lock(fp
->rf_dbe
);
4030 rfs4_dbe_unlock(fp
->rf_dbe
);
4034 * This is va_seq safe because we are not
4037 va
.va_mask
= VATTR_NLINK
;
4038 if (!fop_getattr(tvp
, &va
, 0, cs
->cr
, NULL
) &&
4040 /* Remove state on file remove */
4045 rfs4_close_all_state(fp
);
4057 rfs4_clear_dont_grant(fp
);
4061 kmem_free(name
, MAXPATHLEN
+ 1);
4065 *cs
->statusp
= resp
->status
= puterrno4(error
);
4070 * Get the initial "after" sequence number, if it fails, set to zero
4072 idva
.va_mask
= VATTR_SEQ
;
4073 if (fop_getattr(dvp
, &idva
, 0, cs
->cr
, NULL
))
4077 * Force modified data and metadata out to stable storage.
4079 (void) fop_fsync(dvp
, 0, cs
->cr
, NULL
);
4082 * Get "after" change value, if it fails, simply return the
4085 adva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
4086 if (fop_getattr(dvp
, &adva
, 0, cs
->cr
, NULL
)) {
4087 adva
.va_ctime
= bdva
.va_ctime
;
4091 NFS4_SET_FATTR4_CHANGE(resp
->cinfo
.after
, adva
.va_ctime
)
4094 * The cinfo.atomic = TRUE only if we have
4095 * non-zero va_seq's, and it has incremented by exactly one
4096 * during the fop_remove/RMDIR and it didn't change during
4099 if (bdva
.va_seq
&& idva
.va_seq
&& adva
.va_seq
&&
4100 idva
.va_seq
== (bdva
.va_seq
+ 1) && idva
.va_seq
== adva
.va_seq
)
4101 resp
->cinfo
.atomic
= TRUE
;
4103 resp
->cinfo
.atomic
= FALSE
;
4105 *cs
->statusp
= resp
->status
= NFS4_OK
;
4108 DTRACE_NFSV4_2(op__remove__done
, struct compound_state
*, cs
,
4109 REMOVE4res
*, resp
);
4113 * rename: args: SAVED_FH: from directory, CURRENT_FH: target directory,
4114 * oldname and newname.
4115 * res: status. If success - CURRENT_FH unchanged, return change_info
4116 * for both from and target directories.
4120 rfs4_op_rename(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
4121 struct compound_state
*cs
)
4123 RENAME4args
*args
= &argop
->nfs_argop4_u
.oprename
;
4124 RENAME4res
*resp
= &resop
->nfs_resop4_u
.oprename
;
4128 vnode_t
*srcvp
, *targvp
;
4129 struct vattr obdva
, oidva
, oadva
;
4130 struct vattr nbdva
, nidva
, nadva
;
4133 rfs4_file_t
*fp
, *sfp
;
4134 int in_crit_src
, in_crit_targ
;
4135 int fp_rele_grant_hold
, sfp_rele_grant_hold
;
4136 struct sockaddr
*ca
;
4137 char *converted_onm
= NULL
;
4138 char *converted_nnm
= NULL
;
4141 DTRACE_NFSV4_2(op__rename__start
, struct compound_state
*, cs
,
4142 RENAME4args
*, args
);
4145 srcvp
= targvp
= NULL
;
4146 in_crit_src
= in_crit_targ
= 0;
4147 fp_rele_grant_hold
= sfp_rele_grant_hold
= 0;
4149 /* CURRENT_FH: target directory */
4152 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
4156 /* SAVED_FH: from directory */
4157 odvp
= cs
->saved_vp
;
4159 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
4163 if (cs
->access
== CS_ACCESS_DENIED
) {
4164 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4169 * If there is an unshared filesystem mounted on this vnode,
4170 * do not allow to rename objects in this directory.
4172 if (vn_ismntpt(odvp
)) {
4173 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4178 * If there is an unshared filesystem mounted on this vnode,
4179 * do not allow to rename to this directory.
4181 if (vn_ismntpt(ndvp
)) {
4182 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
4186 if (odvp
->v_type
!= VDIR
|| ndvp
->v_type
!= VDIR
) {
4187 *cs
->statusp
= resp
->status
= NFS4ERR_NOTDIR
;
4191 if (cs
->saved_exi
!= cs
->exi
) {
4192 *cs
->statusp
= resp
->status
= NFS4ERR_XDEV
;
4196 status
= utf8_dir_verify(&args
->oldname
);
4197 if (status
!= NFS4_OK
) {
4198 *cs
->statusp
= resp
->status
= status
;
4202 status
= utf8_dir_verify(&args
->newname
);
4203 if (status
!= NFS4_OK
) {
4204 *cs
->statusp
= resp
->status
= status
;
4208 onm
= utf8_to_fn(&args
->oldname
, &olen
, NULL
);
4210 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4213 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
4214 nlen
= MAXPATHLEN
+ 1;
4215 converted_onm
= nfscmd_convname(ca
, cs
->exi
, onm
, NFSCMD_CONV_INBOUND
,
4218 if (converted_onm
== NULL
) {
4219 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4220 kmem_free(onm
, olen
);
4224 nnm
= utf8_to_fn(&args
->newname
, &nlen
, NULL
);
4226 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4227 if (onm
!= converted_onm
)
4228 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4229 kmem_free(onm
, olen
);
4232 converted_nnm
= nfscmd_convname(ca
, cs
->exi
, nnm
, NFSCMD_CONV_INBOUND
,
4235 if (converted_nnm
== NULL
) {
4236 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
4237 kmem_free(nnm
, nlen
);
4239 if (onm
!= converted_onm
)
4240 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4241 kmem_free(onm
, olen
);
4246 if (olen
> MAXNAMELEN
|| nlen
> MAXNAMELEN
) {
4247 *cs
->statusp
= resp
->status
= NFS4ERR_NAMETOOLONG
;
4248 kmem_free(onm
, olen
);
4249 kmem_free(nnm
, nlen
);
4254 if (rdonly4(req
, cs
)) {
4255 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
4256 if (onm
!= converted_onm
)
4257 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4258 kmem_free(onm
, olen
);
4259 if (nnm
!= converted_nnm
)
4260 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4261 kmem_free(nnm
, nlen
);
4266 * Is the source a file and have a delegation?
4267 * We don't need to acquire va_seq before these lookups, if
4268 * it causes an update, cinfo.before will not match, which will
4269 * trigger a cache flush even if atomic is TRUE.
4271 if (sfp
= rfs4_lookup_and_findfile(odvp
, converted_onm
, &srcvp
,
4273 if (rfs4_check_delegated_byfp(FWRITE
, sfp
, TRUE
, TRUE
, TRUE
,
4275 *cs
->statusp
= resp
->status
= NFS4ERR_DELAY
;
4280 if (srcvp
== NULL
) {
4281 *cs
->statusp
= resp
->status
= puterrno4(error
);
4282 if (onm
!= converted_onm
)
4283 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4284 kmem_free(onm
, olen
);
4285 if (nnm
!= converted_nnm
)
4286 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4287 kmem_free(nnm
, nlen
);
4291 sfp_rele_grant_hold
= 1;
4293 /* Does the destination exist and a file and have a delegation? */
4294 if (fp
= rfs4_lookup_and_findfile(ndvp
, converted_nnm
, &targvp
,
4296 if (rfs4_check_delegated_byfp(FWRITE
, fp
, TRUE
, TRUE
, TRUE
,
4298 *cs
->statusp
= resp
->status
= NFS4ERR_DELAY
;
4302 fp_rele_grant_hold
= 1;
4305 /* Check for NBMAND lock on both source and target */
4306 if (nbl_need_check(srcvp
)) {
4307 nbl_start_crit(srcvp
, RW_READER
);
4309 if (nbl_conflict(srcvp
, NBL_RENAME
, 0, 0, 0, NULL
)) {
4310 *cs
->statusp
= resp
->status
= NFS4ERR_FILE_OPEN
;
4315 if (targvp
&& nbl_need_check(targvp
)) {
4316 nbl_start_crit(targvp
, RW_READER
);
4318 if (nbl_conflict(targvp
, NBL_REMOVE
, 0, 0, 0, NULL
)) {
4319 *cs
->statusp
= resp
->status
= NFS4ERR_FILE_OPEN
;
4324 /* Get source "before" change value */
4325 obdva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
4326 error
= fop_getattr(odvp
, &obdva
, 0, cs
->cr
, NULL
);
4328 nbdva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
4329 error
= fop_getattr(ndvp
, &nbdva
, 0, cs
->cr
, NULL
);
4332 *cs
->statusp
= resp
->status
= puterrno4(error
);
4336 NFS4_SET_FATTR4_CHANGE(resp
->source_cinfo
.before
, obdva
.va_ctime
)
4337 NFS4_SET_FATTR4_CHANGE(resp
->target_cinfo
.before
, nbdva
.va_ctime
)
4339 if ((error
= fop_rename(odvp
, converted_onm
, ndvp
, converted_nnm
,
4340 cs
->cr
, NULL
, 0)) == 0 && fp
!= NULL
) {
4344 rfs4_dbe_lock(fp
->rf_dbe
);
4348 rfs4_dbe_unlock(fp
->rf_dbe
);
4351 va
.va_mask
= VATTR_NLINK
;
4352 if (!fop_getattr(tvp
, &va
, 0, cs
->cr
, NULL
) &&
4354 /* The file is gone and so should the state */
4356 nbl_end_crit(targvp
);
4359 rfs4_close_all_state(fp
);
4365 vn_renamepath(ndvp
, srcvp
, nnm
, nlen
- 1);
4368 nbl_end_crit(srcvp
);
4372 nbl_end_crit(targvp
);
4377 rfs4_clear_dont_grant(sfp
);
4378 rfs4_file_rele(sfp
);
4381 rfs4_clear_dont_grant(fp
);
4385 if (converted_onm
!= onm
)
4386 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4387 kmem_free(onm
, olen
);
4388 if (converted_nnm
!= nnm
)
4389 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4390 kmem_free(nnm
, nlen
);
4393 * Get the initial "after" sequence number, if it fails, set to zero
4395 oidva
.va_mask
= VATTR_SEQ
;
4396 if (fop_getattr(odvp
, &oidva
, 0, cs
->cr
, NULL
))
4399 nidva
.va_mask
= VATTR_SEQ
;
4400 if (fop_getattr(ndvp
, &nidva
, 0, cs
->cr
, NULL
))
4404 * Force modified data and metadata out to stable storage.
4406 (void) fop_fsync(odvp
, 0, cs
->cr
, NULL
);
4407 (void) fop_fsync(ndvp
, 0, cs
->cr
, NULL
);
4410 *cs
->statusp
= resp
->status
= puterrno4(error
);
4415 * Get "after" change values, if it fails, simply return the
4418 oadva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
4419 if (fop_getattr(odvp
, &oadva
, 0, cs
->cr
, NULL
)) {
4420 oadva
.va_ctime
= obdva
.va_ctime
;
4424 nadva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
4425 if (fop_getattr(odvp
, &nadva
, 0, cs
->cr
, NULL
)) {
4426 nadva
.va_ctime
= nbdva
.va_ctime
;
4430 NFS4_SET_FATTR4_CHANGE(resp
->source_cinfo
.after
, oadva
.va_ctime
)
4431 NFS4_SET_FATTR4_CHANGE(resp
->target_cinfo
.after
, nadva
.va_ctime
)
4434 * The cinfo.atomic = TRUE only if we have
4435 * non-zero va_seq's, and it has incremented by exactly one
4436 * during the fop_rename and it didn't change during the fop_fsync.
4438 if (obdva
.va_seq
&& oidva
.va_seq
&& oadva
.va_seq
&&
4439 oidva
.va_seq
== (obdva
.va_seq
+ 1) && oidva
.va_seq
== oadva
.va_seq
)
4440 resp
->source_cinfo
.atomic
= TRUE
;
4442 resp
->source_cinfo
.atomic
= FALSE
;
4444 if (nbdva
.va_seq
&& nidva
.va_seq
&& nadva
.va_seq
&&
4445 nidva
.va_seq
== (nbdva
.va_seq
+ 1) && nidva
.va_seq
== nadva
.va_seq
)
4446 resp
->target_cinfo
.atomic
= TRUE
;
4448 resp
->target_cinfo
.atomic
= FALSE
;
4450 #ifdef VOLATILE_FH_TEST
4452 extern void add_volrnm_fh(struct exportinfo
*, vnode_t
*);
4455 * Add the renamed file handle to the volatile rename list
4457 if (cs
->exi
->exi_export
.ex_flags
& EX_VOLRNM
) {
4458 /* file handles may expire on rename */
4461 nnm
= utf8_to_fn(&args
->newname
, &nlen
, NULL
);
4463 * Already know that nnm will be a valid string
4465 error
= fop_lookup(ndvp
, nnm
, &vp
, NULL
, 0, NULL
, cs
->cr
,
4467 kmem_free(nnm
, nlen
);
4469 add_volrnm_fh(cs
->exi
, vp
);
4474 #endif /* VOLATILE_FH_TEST */
4476 *cs
->statusp
= resp
->status
= NFS4_OK
;
4478 DTRACE_NFSV4_2(op__rename__done
, struct compound_state
*, cs
,
4479 RENAME4res
*, resp
);
4483 if (onm
!= converted_onm
)
4484 kmem_free(converted_onm
, MAXPATHLEN
+ 1);
4486 kmem_free(onm
, olen
);
4487 if (nnm
!= converted_nnm
)
4488 kmem_free(converted_nnm
, MAXPATHLEN
+ 1);
4490 kmem_free(nnm
, nlen
);
4492 if (in_crit_src
) nbl_end_crit(srcvp
);
4493 if (in_crit_targ
) nbl_end_crit(targvp
);
4494 if (targvp
) VN_RELE(targvp
);
4495 if (srcvp
) VN_RELE(srcvp
);
4497 if (sfp_rele_grant_hold
) rfs4_clear_dont_grant(sfp
);
4498 rfs4_file_rele(sfp
);
4501 if (fp_rele_grant_hold
) rfs4_clear_dont_grant(fp
);
4505 DTRACE_NFSV4_2(op__rename__done
, struct compound_state
*, cs
,
4506 RENAME4res
*, resp
);
4511 rfs4_op_renew(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
4512 struct compound_state
*cs
)
4514 RENEW4args
*args
= &argop
->nfs_argop4_u
.oprenew
;
4515 RENEW4res
*resp
= &resop
->nfs_resop4_u
.oprenew
;
4518 DTRACE_NFSV4_2(op__renew__start
, struct compound_state
*, cs
,
4519 RENEW4args
*, args
);
4521 if ((cp
= rfs4_findclient_by_id(args
->clientid
, FALSE
)) == NULL
) {
4522 *cs
->statusp
= resp
->status
=
4523 rfs4_check_clientid(&args
->clientid
, 0);
4527 if (rfs4_lease_expired(cp
)) {
4528 rfs4_client_rele(cp
);
4529 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
4533 rfs4_update_lease(cp
);
4535 mutex_enter(cp
->rc_cbinfo
.cb_lock
);
4536 if (cp
->rc_cbinfo
.cb_notified_of_cb_path_down
== FALSE
) {
4537 cp
->rc_cbinfo
.cb_notified_of_cb_path_down
= TRUE
;
4538 *cs
->statusp
= resp
->status
= NFS4ERR_CB_PATH_DOWN
;
4540 *cs
->statusp
= resp
->status
= NFS4_OK
;
4542 mutex_exit(cp
->rc_cbinfo
.cb_lock
);
4544 rfs4_client_rele(cp
);
4547 DTRACE_NFSV4_2(op__renew__done
, struct compound_state
*, cs
,
4553 rfs4_op_restorefh(nfs_argop4
*args
, nfs_resop4
*resop
, struct svc_req
*req
,
4554 struct compound_state
*cs
)
4556 RESTOREFH4res
*resp
= &resop
->nfs_resop4_u
.oprestorefh
;
4558 DTRACE_NFSV4_1(op__restorefh__start
, struct compound_state
*, cs
);
4560 /* No need to check cs->access - we are not accessing any object */
4561 if ((cs
->saved_vp
== NULL
) || (cs
->saved_fh
.nfs_fh4_val
== NULL
)) {
4562 *cs
->statusp
= resp
->status
= NFS4ERR_RESTOREFH
;
4565 if (cs
->vp
!= NULL
) {
4568 cs
->vp
= cs
->saved_vp
;
4569 cs
->saved_vp
= NULL
;
4570 cs
->exi
= cs
->saved_exi
;
4571 nfs_fh4_copy(&cs
->saved_fh
, &cs
->fh
);
4572 *cs
->statusp
= resp
->status
= NFS4_OK
;
4576 DTRACE_NFSV4_2(op__restorefh__done
, struct compound_state
*, cs
,
4577 RESTOREFH4res
*, resp
);
4582 rfs4_op_savefh(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
4583 struct compound_state
*cs
)
4585 SAVEFH4res
*resp
= &resop
->nfs_resop4_u
.opsavefh
;
4587 DTRACE_NFSV4_1(op__savefh__start
, struct compound_state
*, cs
);
4589 /* No need to check cs->access - we are not accessing any object */
4590 if (cs
->vp
== NULL
) {
4591 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
4594 if (cs
->saved_vp
!= NULL
) {
4595 VN_RELE(cs
->saved_vp
);
4597 cs
->saved_vp
= cs
->vp
;
4598 VN_HOLD(cs
->saved_vp
);
4599 cs
->saved_exi
= cs
->exi
;
4601 * since SAVEFH is fairly rare, don't alloc space for its fh
4604 if (cs
->saved_fh
.nfs_fh4_val
== NULL
) {
4605 cs
->saved_fh
.nfs_fh4_val
= kmem_alloc(NFS4_FHSIZE
, KM_SLEEP
);
4607 nfs_fh4_copy(&cs
->fh
, &cs
->saved_fh
);
4608 *cs
->statusp
= resp
->status
= NFS4_OK
;
4611 DTRACE_NFSV4_2(op__savefh__done
, struct compound_state
*, cs
,
4612 SAVEFH4res
*, resp
);
4616 * rfs4_verify_attr is called when nfsv4 Setattr failed, but we wish to
4617 * return the bitmap of attrs that were set successfully. It is also
4618 * called by Verify/Nverify to test the vattr/vfsstat attrs. It should
4619 * always be called only after rfs4_do_set_attrs().
4621 * Verify that the attributes are same as the expected ones. sargp->vap
4622 * and sargp->sbp contain the input attributes as translated from fattr4.
4624 * This function verifies only the attrs that correspond to a vattr or
4625 * vfsstat struct. That is because of the extra step needed to get the
4626 * corresponding system structs. Other attributes have already been set or
4627 * verified by do_rfs4_set_attrs.
4629 * Return 0 if all attrs match, -1 if some don't, error if error processing.
4632 rfs4_verify_attr(struct nfs4_svgetit_arg
*sargp
,
4633 bitmap4
*resp
, struct nfs4_ntov_table
*ntovp
)
4635 int error
, ret_error
= 0;
4637 uint_t sva_mask
= sargp
->vap
->va_mask
;
4639 union nfs4_attr_u
*na
;
4641 bool_t getsb
= ntovp
->vfsstat
;
4643 if (sva_mask
!= 0) {
4645 * Okay to overwrite sargp->vap because we verify based
4646 * on the incoming values.
4648 ret_error
= fop_getattr(sargp
->cs
->vp
, sargp
->vap
, 0,
4649 sargp
->cs
->cr
, NULL
);
4654 * Must return bitmap of successful attrs
4656 sva_mask
= 0; /* to prevent checking vap later */
4659 * Some file systems clobber va_mask. it is probably
4660 * wrong of them to do so, nonethless we practice
4662 * See bug id 4276830.
4664 sargp
->vap
->va_mask
= sva_mask
;
4670 * Now get the superblock and loop on the bitmap, as there is
4671 * no simple way of translating from superblock to bitmap4.
4673 ret_error
= VFS_STATVFS(sargp
->cs
->vp
->v_vfsp
, sargp
->sbp
);
4682 * Now loop and verify each attribute which getattr returned
4683 * whether it's the same as the input.
4685 if (resp
== NULL
&& !getsb
&& (sva_mask
== 0))
4691 for (i
= 0; i
< ntovp
->attrcnt
; i
++, na
++, amap
++) {
4693 ASSERT(nfs4_ntov_map
[k
].nval
== k
);
4694 vbit
= nfs4_ntov_map
[k
].vbit
;
4697 * If vattr attribute but fop_getattr failed, or it's
4698 * superblock attribute but VFS_STATVFS failed, skip
4701 if ((vbit
& sva_mask
) == 0)
4703 } else if (!(getsb
&& nfs4_ntov_map
[k
].vfsstat
)) {
4706 error
= (*nfs4_ntov_map
[k
].sv_getit
)(NFS4ATTR_VERIT
, sargp
, na
);
4709 ret_error
= -1; /* not all match */
4710 else /* update response bitmap */
4711 *resp
|= nfs4_ntov_map
[k
].fbit
;
4715 ret_error
= -1; /* not all match */
4724 * Decode the attribute to be set/verified. If the attr requires a sys op
4725 * (fop_getattr, VFS_VFSSTAT), and the request is to verify, then don't
4726 * call the sv_getit function for it, because the sys op hasn't yet been done.
4727 * Return 0 for success, error code if failed.
4729 * Note: the decoded arg is not freed here but in nfs4_ntov_table_free.
4732 decode_fattr4_attr(nfs4_attr_cmd_t cmd
, struct nfs4_svgetit_arg
*sargp
,
4733 int k
, XDR
*xdrp
, bitmap4
*resp_bval
, union nfs4_attr_u
*nap
)
4738 sargp
->vap
->va_mask
|= nfs4_ntov_map
[k
].vbit
;
4740 if ((*nfs4_ntov_map
[k
].xfunc
)(xdrp
, nap
)) {
4741 set_later
= nfs4_ntov_map
[k
].vbit
|| nfs4_ntov_map
[k
].vfsstat
;
4743 * don't verify yet if a vattr or sb dependent attr,
4744 * because we don't have their sys values yet.
4745 * Will be done later.
4747 if (! (set_later
&& (cmd
== NFS4ATTR_VERIT
))) {
4749 * ACLs are a special case, since setting the MODE
4750 * conflicts with setting the ACL. We delay setting
4751 * the ACL until all other attributes have been set.
4752 * The ACL gets set in do_rfs4_op_setattr().
4754 if (nfs4_ntov_map
[k
].fbit
!= FATTR4_ACL_MASK
) {
4755 error
= (*nfs4_ntov_map
[k
].sv_getit
)(cmd
,
4758 xdr_free(nfs4_ntov_map
[k
].xfunc
,
4765 cmn_err(CE_NOTE
, "decode_fattr4_attr: error "
4766 "decoding attribute %d\n", k
);
4770 if (!error
&& resp_bval
&& !set_later
) {
4771 *resp_bval
|= nfs4_ntov_map
[k
].fbit
;
4778 * Set vattr based on incoming fattr4 attrs - used by setattr.
4779 * Set response mask. Ignore any values that are not writable vattr attrs.
4782 do_rfs4_set_attrs(bitmap4
*resp
, fattr4
*fattrp
, struct compound_state
*cs
,
4783 struct nfs4_svgetit_arg
*sargp
, struct nfs4_ntov_table
*ntovp
,
4784 nfs4_attr_cmd_t cmd
)
4788 char *attrs
= fattrp
->attrlist4
;
4789 uint32_t attrslen
= fattrp
->attrlist4_len
;
4791 nfsstat4 status
= NFS4_OK
;
4792 vnode_t
*vp
= cs
->vp
;
4793 union nfs4_attr_u
*na
;
4797 * Make sure that maximum attribute number can be expressed as an
4800 ASSERT(NFS4_MAXNUM_ATTRS
<= (UINT8_MAX
+ 1));
4805 return (NFS4ERR_NOFILEHANDLE
);
4807 if (cs
->access
== CS_ACCESS_DENIED
) {
4810 return (NFS4ERR_ACCESS
);
4815 sargp
->flag
= 0; /* may be set later */
4816 sargp
->vap
->va_mask
= 0;
4817 sargp
->rdattr_error
= NFS4_OK
;
4818 sargp
->rdattr_error_req
= FALSE
;
4819 /* sargp->sbp is set by the caller */
4821 xdrmem_create(&xdr
, attrs
, attrslen
, XDR_DECODE
);
4827 * The following loop iterates on the nfs4_ntov_map checking
4828 * if the fbit is set in the requested bitmap.
4829 * If set then we process the arguments using the
4830 * rfs4_fattr4 conversion functions to populate the setattr
4831 * vattr and va_mask. Any settable attrs that are not using vattr
4832 * will be set in this loop.
4834 for (i
= 0; i
< nfs4_ntov_map_size
; i
++) {
4835 if (!(fattrp
->attrmask
& nfs4_ntov_map
[i
].fbit
)) {
4839 * If setattr, must be a writable attr.
4840 * If verify/nverify, must be a readable attr.
4842 if ((error
= (*nfs4_ntov_map
[i
].sv_getit
)(
4843 NFS4ATTR_SUPPORTED
, sargp
, NULL
)) != 0) {
4845 * Client tries to set/verify an
4846 * unsupported attribute, tries to set
4847 * a read only attr or verify a write
4853 * Decode the attribute to set/verify
4855 error
= decode_fattr4_attr(cmd
, sargp
, nfs4_ntov_map
[i
].nval
,
4856 &xdr
, resp
? resp
: NULL
, na
);
4859 *amap
++ = (uint8_t)nfs4_ntov_map
[i
].nval
;
4862 if (nfs4_ntov_map
[i
].vfsstat
)
4863 ntovp
->vfsstat
= TRUE
;
4867 status
= (error
== ENOTSUP
? NFS4ERR_ATTRNOTSUPP
:
4869 /* xdrmem_destroy(&xdrs); */ /* NO-OP */
4874 do_rfs4_op_setattr(bitmap4
*resp
, fattr4
*fattrp
, struct compound_state
*cs
,
4878 struct nfs4_svgetit_arg sarg
;
4881 nfsstat4 status
= NFS4_OK
;
4882 cred_t
*cr
= cs
->cr
;
4883 vnode_t
*vp
= cs
->vp
;
4884 struct nfs4_ntov_table ntov
;
4885 struct statvfs64 sb
;
4889 uint_t saved_mask
= 0;
4890 caller_context_t ct
;
4894 sarg
.is_referral
= B_FALSE
;
4895 nfs4_ntov_table_init(&ntov
);
4896 status
= do_rfs4_set_attrs(resp
, fattrp
, cs
, &sarg
, &ntov
,
4898 if (status
!= NFS4_OK
) {
4904 if ((sarg
.vap
->va_mask
== 0) &&
4905 (! (fattrp
->attrmask
& FATTR4_ACL_MASK
))) {
4907 * no further work to be done
4913 * If we got a request to set the ACL and the MODE, only
4914 * allow changing VSUID, VSGID, and VSVTX. Attempting
4915 * to change any other bits, along with setting an ACL,
4916 * gives NFS4ERR_INVAL.
4918 if ((fattrp
->attrmask
& FATTR4_ACL_MASK
) &&
4919 (fattrp
->attrmask
& FATTR4_MODE_MASK
)) {
4922 va
.va_mask
= VATTR_MODE
;
4923 error
= fop_getattr(vp
, &va
, 0, cs
->cr
, NULL
);
4925 status
= puterrno4(error
);
4928 if ((sarg
.vap
->va_mode
^ va
.va_mode
) &
4929 ~(VSUID
| VSGID
| VSVTX
)) {
4930 status
= NFS4ERR_INVAL
;
4935 /* Check stateid only if size has been set */
4936 if (sarg
.vap
->va_mask
& VATTR_SIZE
) {
4937 trunc
= (sarg
.vap
->va_size
== 0);
4938 status
= rfs4_check_stateid(FWRITE
, cs
->vp
, stateid
,
4939 trunc
, &cs
->deleg
, sarg
.vap
->va_mask
& VATTR_SIZE
, &ct
);
4940 if (status
!= NFS4_OK
)
4945 ct
.cc_caller_id
= nfs4_srv_caller_id
;
4946 ct
.cc_flags
= CC_DONTBLOCK
;
4949 /* XXX start of possible race with delegations */
4952 * We need to specially handle size changes because it is
4953 * possible for the client to create a file with read-only
4954 * modes, but with the file opened for writing. If the client
4955 * then tries to set the file size, e.g. ftruncate(3C),
4956 * fcntl(F_FREESP), the normal access checking done in
4957 * fop_setattr would prevent the client from doing it even though
4958 * it should be allowed to do so. To get around this, we do the
4959 * access checking for ourselves and use fop_space which doesn't
4960 * do the access checking.
4961 * Also the client should not be allowed to change the file
4962 * size if there is a conflicting non-blocking mandatory lock in
4963 * the region of the change.
4965 if (vp
->v_type
== VREG
&& (sarg
.vap
->va_mask
& VATTR_SIZE
)) {
4970 * ufs_setattr clears VATTR_SIZE from vap->va_mask, but
4971 * before returning, sarg.vap->va_mask is used to
4972 * generate the setattr reply bitmap. We also clear
4973 * VATTR_SIZE below before calling fop_space. For both
4974 * of these cases, the va_mask needs to be saved here
4975 * and restored after calling fop_setattr.
4977 saved_mask
= sarg
.vap
->va_mask
;
4980 * Check any possible conflict due to NBMAND locks.
4981 * Get into critical region before fop_getattr, so the
4982 * size attribute is valid when checking conflicts.
4984 if (nbl_need_check(vp
)) {
4985 nbl_start_crit(vp
, RW_READER
);
4989 bva
.va_mask
= VATTR_UID
|VATTR_SIZE
;
4990 if (error
= fop_getattr(vp
, &bva
, 0, cr
, &ct
)) {
4991 status
= puterrno4(error
);
4996 if (sarg
.vap
->va_size
< bva
.va_size
) {
4997 offset
= sarg
.vap
->va_size
;
4998 length
= bva
.va_size
- sarg
.vap
->va_size
;
5000 offset
= bva
.va_size
;
5001 length
= sarg
.vap
->va_size
- bva
.va_size
;
5003 if (nbl_conflict(vp
, NBL_WRITE
, offset
, length
, 0,
5005 status
= NFS4ERR_LOCKED
;
5010 if (crgetuid(cr
) == bva
.va_uid
) {
5011 sarg
.vap
->va_mask
&= ~VATTR_SIZE
;
5012 bf
.l_type
= F_WRLCK
;
5014 bf
.l_start
= (off64_t
)sarg
.vap
->va_size
;
5018 error
= fop_space(vp
, F_FREESP
, &bf
, FWRITE
,
5019 (offset_t
)sarg
.vap
->va_size
, cr
, &ct
);
5023 if (!error
&& sarg
.vap
->va_mask
!= 0)
5024 error
= fop_setattr(vp
, sarg
.vap
, sarg
.flag
, cr
, &ct
);
5026 /* restore va_mask -- ufs_setattr clears VATTR_SIZE */
5027 if (saved_mask
& VATTR_SIZE
)
5028 sarg
.vap
->va_mask
|= VATTR_SIZE
;
5031 * If an ACL was being set, it has been delayed until now,
5032 * in order to set the mode (via the fop_setattr() above) first.
5034 if ((! error
) && (fattrp
->attrmask
& FATTR4_ACL_MASK
)) {
5037 for (i
= 0; i
< NFS4_MAXNUM_ATTRS
; i
++)
5038 if (ntov
.amap
[i
] == FATTR4_ACL
)
5040 if (i
< NFS4_MAXNUM_ATTRS
) {
5041 error
= (*nfs4_ntov_map
[FATTR4_ACL
].sv_getit
)(
5042 NFS4ATTR_SETIT
, &sarg
, &ntov
.na
[i
]);
5044 *resp
|= FATTR4_ACL_MASK
;
5045 } else if (error
== ENOTSUP
) {
5046 (void) rfs4_verify_attr(&sarg
, resp
, &ntov
);
5047 status
= NFS4ERR_ATTRNOTSUPP
;
5051 NFS4_DEBUG(rfs4_debug
,
5052 (CE_NOTE
, "do_rfs4_op_setattr: "
5053 "unable to find ACL in fattr4"));
5059 /* check if a monitor detected a delegation conflict */
5060 if (error
== EAGAIN
&& (ct
.cc_flags
& CC_WOULDBLOCK
))
5061 status
= NFS4ERR_DELAY
;
5063 status
= puterrno4(error
);
5066 * Set the response bitmap when setattr failed.
5067 * If fop_setattr partially succeeded, test by doing a
5068 * fop_getattr on the object and comparing the data
5069 * to the setattr arguments.
5071 (void) rfs4_verify_attr(&sarg
, resp
, &ntov
);
5074 * Force modified metadata out to stable storage.
5076 (void) fop_fsync(vp
, FNODSYNC
, cr
, &ct
);
5078 * Set response bitmap
5080 nfs4_vmask_to_nmask_set(sarg
.vap
->va_mask
, resp
);
5083 /* Return early and already have a NFSv4 error */
5086 * Except for nfs4_vmask_to_nmask_set(), vattr --> fattr
5087 * conversion sets both readable and writeable NFS4 attrs
5088 * for VATTR_MTIME and VATTR_ATIME. The line below masks out
5089 * unrequested attrs from the setattr result bitmap. This
5090 * is placed after the done: label to catch the ATTRNOTSUP
5093 *resp
&= fattrp
->attrmask
;
5098 nfs4_ntov_table_free(&ntov
, &sarg
);
5105 rfs4_op_setattr(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5106 struct compound_state
*cs
)
5108 SETATTR4args
*args
= &argop
->nfs_argop4_u
.opsetattr
;
5109 SETATTR4res
*resp
= &resop
->nfs_resop4_u
.opsetattr
;
5111 DTRACE_NFSV4_2(op__setattr__start
, struct compound_state
*, cs
,
5112 SETATTR4args
*, args
);
5114 if (cs
->vp
== NULL
) {
5115 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5120 * If there is an unshared filesystem mounted on this vnode,
5121 * do not allow to setattr on this vnode.
5123 if (vn_ismntpt(cs
->vp
)) {
5124 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
5130 if (rdonly4(req
, cs
)) {
5131 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
5135 *cs
->statusp
= resp
->status
=
5136 do_rfs4_op_setattr(&resp
->attrsset
, &args
->obj_attributes
, cs
,
5140 DTRACE_NFSV4_2(op__setattr__done
, struct compound_state
*, cs
,
5141 SETATTR4res
*, resp
);
5146 rfs4_op_verify(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5147 struct compound_state
*cs
)
5150 * verify and nverify are exactly the same, except that nverify
5151 * succeeds when some argument changed, and verify succeeds when
5152 * when none changed.
5155 VERIFY4args
*args
= &argop
->nfs_argop4_u
.opverify
;
5156 VERIFY4res
*resp
= &resop
->nfs_resop4_u
.opverify
;
5159 struct nfs4_svgetit_arg sarg
;
5160 struct statvfs64 sb
;
5161 struct nfs4_ntov_table ntov
;
5163 DTRACE_NFSV4_2(op__verify__start
, struct compound_state
*, cs
,
5164 VERIFY4args
*, args
);
5166 if (cs
->vp
== NULL
) {
5167 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5172 sarg
.is_referral
= B_FALSE
;
5173 nfs4_ntov_table_init(&ntov
);
5174 resp
->status
= do_rfs4_set_attrs(NULL
, &args
->obj_attributes
, cs
,
5175 &sarg
, &ntov
, NFS4ATTR_VERIT
);
5176 if (resp
->status
!= NFS4_OK
) {
5178 * do_rfs4_set_attrs will try to verify systemwide attrs,
5179 * so could return -1 for "no match".
5181 if (resp
->status
== -1)
5182 resp
->status
= NFS4ERR_NOT_SAME
;
5185 error
= rfs4_verify_attr(&sarg
, NULL
, &ntov
);
5188 resp
->status
= NFS4_OK
;
5191 resp
->status
= NFS4ERR_NOT_SAME
;
5194 resp
->status
= puterrno4(error
);
5198 *cs
->statusp
= resp
->status
;
5199 nfs4_ntov_table_free(&ntov
, &sarg
);
5201 DTRACE_NFSV4_2(op__verify__done
, struct compound_state
*, cs
,
5202 VERIFY4res
*, resp
);
5207 rfs4_op_nverify(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5208 struct compound_state
*cs
)
5211 * verify and nverify are exactly the same, except that nverify
5212 * succeeds when some argument changed, and verify succeeds when
5213 * when none changed.
5216 NVERIFY4args
*args
= &argop
->nfs_argop4_u
.opnverify
;
5217 NVERIFY4res
*resp
= &resop
->nfs_resop4_u
.opnverify
;
5220 struct nfs4_svgetit_arg sarg
;
5221 struct statvfs64 sb
;
5222 struct nfs4_ntov_table ntov
;
5224 DTRACE_NFSV4_2(op__nverify__start
, struct compound_state
*, cs
,
5225 NVERIFY4args
*, args
);
5227 if (cs
->vp
== NULL
) {
5228 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5229 DTRACE_NFSV4_2(op__nverify__done
, struct compound_state
*, cs
,
5230 NVERIFY4res
*, resp
);
5234 sarg
.is_referral
= B_FALSE
;
5235 nfs4_ntov_table_init(&ntov
);
5236 resp
->status
= do_rfs4_set_attrs(NULL
, &args
->obj_attributes
, cs
,
5237 &sarg
, &ntov
, NFS4ATTR_VERIT
);
5238 if (resp
->status
!= NFS4_OK
) {
5240 * do_rfs4_set_attrs will try to verify systemwide attrs,
5241 * so could return -1 for "no match".
5243 if (resp
->status
== -1)
5244 resp
->status
= NFS4_OK
;
5247 error
= rfs4_verify_attr(&sarg
, NULL
, &ntov
);
5250 resp
->status
= NFS4ERR_SAME
;
5253 resp
->status
= NFS4_OK
;
5256 resp
->status
= puterrno4(error
);
5260 *cs
->statusp
= resp
->status
;
5261 nfs4_ntov_table_free(&ntov
, &sarg
);
5263 DTRACE_NFSV4_2(op__nverify__done
, struct compound_state
*, cs
,
5264 NVERIFY4res
*, resp
);
5268 * XXX - This should live in an NFS header file.
5270 #define MAX_IOVECS 12
5274 rfs4_op_write(nfs_argop4
*argop
, nfs_resop4
*resop
, struct svc_req
*req
,
5275 struct compound_state
*cs
)
5277 WRITE4args
*args
= &argop
->nfs_argop4_u
.opwrite
;
5278 WRITE4res
*resp
= &resop
->nfs_resop4_u
.opwrite
;
5284 struct iovec iov
[MAX_IOVECS
];
5288 cred_t
*savecred
, *cr
;
5289 bool_t
*deleg
= &cs
->deleg
;
5292 caller_context_t ct
;
5294 DTRACE_NFSV4_2(op__write__start
, struct compound_state
*, cs
,
5295 WRITE4args
*, args
);
5299 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
5302 if (cs
->access
== CS_ACCESS_DENIED
) {
5303 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
5309 if ((stat
= rfs4_check_stateid(FWRITE
, vp
, &args
->stateid
, FALSE
,
5310 deleg
, TRUE
, &ct
)) != NFS4_OK
) {
5311 *cs
->statusp
= resp
->status
= stat
;
5316 * We have to enter the critical region before calling fop_rwlock
5317 * to avoid a deadlock with ufs.
5319 if (nbl_need_check(vp
)) {
5320 nbl_start_crit(vp
, RW_READER
);
5322 if (nbl_conflict(vp
, NBL_WRITE
,
5323 args
->offset
, args
->data_len
, 0, &ct
)) {
5324 *cs
->statusp
= resp
->status
= NFS4ERR_LOCKED
;
5329 bva
.va_mask
= VATTR_MODE
| VATTR_UID
;
5330 error
= fop_getattr(vp
, &bva
, 0, cr
, &ct
);
5333 * If we can't get the attributes, then we can't do the
5334 * right access checking. So, we'll fail the request.
5337 *cs
->statusp
= resp
->status
= puterrno4(error
);
5341 if (rdonly4(req
, cs
)) {
5342 *cs
->statusp
= resp
->status
= NFS4ERR_ROFS
;
5346 if (vp
->v_type
!= VREG
) {
5347 *cs
->statusp
= resp
->status
=
5348 ((vp
->v_type
== VDIR
) ? NFS4ERR_ISDIR
: NFS4ERR_INVAL
);
5352 if (crgetuid(cr
) != bva
.va_uid
&&
5353 (error
= fop_access(vp
, VWRITE
, 0, cr
, &ct
))) {
5354 *cs
->statusp
= resp
->status
= puterrno4(error
);
5358 if (MANDLOCK(vp
, bva
.va_mode
)) {
5359 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
5363 if (args
->data_len
== 0) {
5364 *cs
->statusp
= resp
->status
= NFS4_OK
;
5366 resp
->committed
= args
->stable
;
5367 resp
->writeverf
= Write4verf
;
5371 if (args
->mblk
!= NULL
) {
5373 uint_t bytes
, round_len
;
5377 round_len
= roundup(args
->data_len
, BYTES_PER_XDR_UNIT
);
5378 for (m
= args
->mblk
;
5379 m
!= NULL
&& bytes
< round_len
;
5385 /* should have ended on an mblk boundary */
5386 if (bytes
!= round_len
) {
5387 printf("bytes=0x%x, round_len=0x%x, req len=0x%x\n",
5388 bytes
, round_len
, args
->data_len
);
5389 printf("args=%p, args->mblk=%p, m=%p", (void *)args
,
5390 (void *)args
->mblk
, (void *)m
);
5391 ASSERT(bytes
== round_len
);
5394 if (iovcnt
<= MAX_IOVECS
) {
5397 iovp
= kmem_alloc(sizeof (*iovp
) * iovcnt
, KM_SLEEP
);
5399 mblk_to_iov(args
->mblk
, iovcnt
, iovp
);
5400 } else if (args
->rlist
!= NULL
) {
5403 iovp
->iov_base
= (char *)((args
->rlist
)->u
.c_daddr3
);
5404 iovp
->iov_len
= args
->data_len
;
5408 iovp
->iov_base
= args
->data_val
;
5409 iovp
->iov_len
= args
->data_len
;
5413 uio
.uio_iovcnt
= iovcnt
;
5415 uio
.uio_segflg
= UIO_SYSSPACE
;
5416 uio
.uio_extflg
= UIO_COPY_DEFAULT
;
5417 uio
.uio_loffset
= args
->offset
;
5418 uio
.uio_resid
= args
->data_len
;
5419 uio
.uio_llimit
= curproc
->p_fsz_ctl
;
5420 rlimit
= uio
.uio_llimit
- args
->offset
;
5421 if (rlimit
< (uoff_t
)uio
.uio_resid
)
5422 uio
.uio_resid
= (int)rlimit
;
5424 if (args
->stable
== UNSTABLE4
)
5426 else if (args
->stable
== FILE_SYNC4
)
5428 else if (args
->stable
== DATA_SYNC4
)
5432 kmem_free(iovp
, sizeof (*iovp
) * iovcnt
);
5433 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
5438 * We're changing creds because VM may fault and we need
5439 * the cred of the current thread to be used if quota
5440 * checking is enabled.
5442 savecred
= curthread
->t_cred
;
5443 curthread
->t_cred
= cr
;
5444 error
= do_io(FWRITE
, vp
, &uio
, ioflag
, cr
, &ct
);
5445 curthread
->t_cred
= savecred
;
5448 kmem_free(iovp
, sizeof (*iovp
) * iovcnt
);
5451 *cs
->statusp
= resp
->status
= puterrno4(error
);
5455 *cs
->statusp
= resp
->status
= NFS4_OK
;
5456 resp
->count
= args
->data_len
- uio
.uio_resid
;
5459 resp
->committed
= UNSTABLE4
;
5461 resp
->committed
= FILE_SYNC4
;
5463 resp
->writeverf
= Write4verf
;
5469 DTRACE_NFSV4_2(op__write__done
, struct compound_state
*, cs
,
5474 /* XXX put in a header file */
5475 extern int sec_svc_getcred(struct svc_req
*, cred_t
*, caddr_t
*, int *);
5478 rfs4_compound(COMPOUND4args
*args
, COMPOUND4res
*resp
, struct exportinfo
*exi
,
5479 struct svc_req
*req
, cred_t
*cr
, int *rv
)
5482 struct compound_state cs
;
5486 rfs4_init_compound_state(&cs
);
5488 * Form a reply tag by copying over the reqeuest tag.
5490 resp
->tag
.utf8string_val
=
5491 kmem_alloc(args
->tag
.utf8string_len
, KM_SLEEP
);
5492 resp
->tag
.utf8string_len
= args
->tag
.utf8string_len
;
5493 bcopy(args
->tag
.utf8string_val
, resp
->tag
.utf8string_val
,
5494 resp
->tag
.utf8string_len
);
5496 cs
.statusp
= &resp
->status
;
5499 resp
->array_len
= 0;
5502 * XXX for now, minorversion should be zero
5504 if (args
->minorversion
!= NFS4_MINORVERSION
) {
5505 DTRACE_NFSV4_2(compound__start
, struct compound_state
*,
5506 &cs
, COMPOUND4args
*, args
);
5507 resp
->status
= NFS4ERR_MINOR_VERS_MISMATCH
;
5508 DTRACE_NFSV4_2(compound__done
, struct compound_state
*,
5509 &cs
, COMPOUND4res
*, resp
);
5513 if (args
->array_len
== 0) {
5514 resp
->status
= NFS4_OK
;
5518 ASSERT(exi
== NULL
);
5524 if (sec_svc_getcred(req
, cr
, &cs
.principal
, &cs
.nfsflavor
) == 0) {
5525 DTRACE_NFSV4_2(compound__start
, struct compound_state
*,
5526 &cs
, COMPOUND4args
*, args
);
5528 DTRACE_NFSV4_2(compound__done
, struct compound_state
*,
5529 &cs
, COMPOUND4res
*, resp
);
5530 svcerr_badcred(req
->rq_xprt
);
5535 resp
->array_len
= args
->array_len
;
5536 resp
->array
= kmem_zalloc(args
->array_len
* sizeof (nfs_resop4
),
5541 DTRACE_NFSV4_2(compound__start
, struct compound_state
*, &cs
,
5542 COMPOUND4args
*, args
);
5545 * For now, NFS4 compound processing must be protected by
5546 * exported_lock because it can access more than one exportinfo
5547 * per compound and share/unshare can now change multiple
5548 * exinfo structs. The NFS2/3 code only refs 1 exportinfo
5549 * per proc (excluding public exinfo), and exi_count design
5550 * is sufficient to protect concurrent execution of NFS2/3
5551 * ops along with unexport. This lock will be removed as
5552 * part of the NFSv4 phase 2 namespace redesign work.
5554 rw_enter(&exported_lock
, RW_READER
);
5557 * If this is the first compound we've seen, we need to start all
5558 * new instances' grace periods.
5560 if (rfs4_seen_first_compound
== 0) {
5561 rfs4_grace_start_new();
5563 * This must be set after rfs4_grace_start_new(), otherwise
5564 * another thread could proceed past here before the former
5567 rfs4_seen_first_compound
= 1;
5570 for (i
= 0; i
< args
->array_len
&& cs
.cont
; i
++) {
5575 argop
= &args
->array
[i
];
5576 resop
= &resp
->array
[i
];
5577 resop
->resop
= argop
->argop
;
5578 op
= (uint_t
)resop
->resop
;
5580 if (op
< rfsv4disp_cnt
) {
5582 * Count the individual ops here; NULL and COMPOUND
5583 * are counted in common_dispatch()
5585 rfsproccnt_v4_ptr
[op
].value
.ui64
++;
5587 NFS4_DEBUG(rfs4_debug
> 1,
5588 (CE_NOTE
, "Executing %s", rfs4_op_string
[op
]));
5589 (*rfsv4disptab
[op
].dis_proc
)(argop
, resop
, req
, &cs
);
5590 NFS4_DEBUG(rfs4_debug
> 1, (CE_NOTE
, "%s returned %d",
5591 rfs4_op_string
[op
], *cs
.statusp
));
5592 if (*cs
.statusp
!= NFS4_OK
)
5596 * This is effectively dead code since XDR code
5597 * will have already returned BADXDR if op doesn't
5598 * decode to legal value. This only done for a
5599 * day when XDR code doesn't verify v4 opcodes.
5602 rfsproccnt_v4_ptr
[OP_ILLEGAL_IDX
].value
.ui64
++;
5604 rfs4_op_illegal(argop
, resop
, req
, &cs
);
5609 * If not at last op, and if we are to stop, then
5610 * compact the results array.
5612 if ((i
+ 1) < args
->array_len
&& !cs
.cont
) {
5613 nfs_resop4
*new_res
= kmem_alloc(
5614 (i
+1) * sizeof (nfs_resop4
), KM_SLEEP
);
5616 new_res
, (i
+1) * sizeof (nfs_resop4
));
5617 kmem_free(resp
->array
,
5618 args
->array_len
* sizeof (nfs_resop4
));
5620 resp
->array_len
= i
+ 1;
5621 resp
->array
= new_res
;
5625 rw_exit(&exported_lock
);
5627 DTRACE_NFSV4_2(compound__done
, struct compound_state
*, &cs
,
5628 COMPOUND4res
*, resp
);
5633 VN_RELE(cs
.saved_vp
);
5634 if (cs
.saved_fh
.nfs_fh4_val
)
5635 kmem_free(cs
.saved_fh
.nfs_fh4_val
, NFS4_FHSIZE
);
5644 * XXX because of what appears to be duplicate calls to rfs4_compound_free
5645 * XXX zero out the tag and array values. Need to investigate why the
5646 * XXX calls occur, but at least prevent the panic for now.
5649 rfs4_compound_free(COMPOUND4res
*resp
)
5653 if (resp
->tag
.utf8string_val
) {
5654 UTF8STRING_FREE(resp
->tag
)
5657 for (i
= 0; i
< resp
->array_len
; i
++) {
5661 resop
= &resp
->array
[i
];
5662 op
= (uint_t
)resop
->resop
;
5663 if (op
< rfsv4disp_cnt
) {
5664 (*rfsv4disptab
[op
].dis_resfree
)(resop
);
5667 if (resp
->array
!= NULL
) {
5668 kmem_free(resp
->array
, resp
->array_len
* sizeof (nfs_resop4
));
5673 * Process the value of the compound request rpc flags, as a bit-AND
5674 * of the individual per-op flags (idempotent, allowork, publicfh_ok)
5677 rfs4_compound_flagproc(COMPOUND4args
*args
, int *flagp
)
5682 for (i
= 0; flag
&& i
< args
->array_len
; i
++) {
5685 op
= (uint_t
)args
->array
[i
].argop
;
5687 if (op
< rfsv4disp_cnt
)
5688 flag
&= rfsv4disptab
[op
].dis_flags
;
5696 rfs4_client_sysid(rfs4_client_t
*cp
, sysid_t
*sp
)
5700 rfs4_dbe_lock(cp
->rc_dbe
);
5702 if (cp
->rc_sysidt
!= LM_NOSYSID
) {
5703 *sp
= cp
->rc_sysidt
;
5706 } else if ((cp
->rc_sysidt
= lm_alloc_sysidt()) != LM_NOSYSID
) {
5707 *sp
= cp
->rc_sysidt
;
5710 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
,
5711 "rfs4_client_sysid: allocated 0x%x\n", *sp
));
5715 rfs4_dbe_unlock(cp
->rc_dbe
);
5719 #if defined(DEBUG) && ! defined(lint)
5720 static void lock_print(char *str
, int operation
, struct flock64
*flk
)
5724 switch (operation
) {
5725 case F_GETLK
: op
= "F_GETLK";
5727 case F_SETLK
: op
= "F_SETLK";
5729 case F_SETLK_NBMAND
: op
= "F_SETLK_NBMAND";
5731 default: op
= "F_UNKNOWN";
5734 switch (flk
->l_type
) {
5735 case F_UNLCK
: type
= "F_UNLCK";
5737 case F_RDLCK
: type
= "F_RDLCK";
5739 case F_WRLCK
: type
= "F_WRLCK";
5741 default: type
= "F_UNKNOWN";
5745 ASSERT(flk
->l_whence
== 0);
5746 cmn_err(CE_NOTE
, "%s: %s, type = %s, off = %llx len = %llx pid = %d",
5747 str
, op
, type
, (longlong_t
)flk
->l_start
,
5748 flk
->l_len
? (longlong_t
)flk
->l_len
: ~0LL, flk
->l_pid
);
5751 #define LOCK_PRINT(d, s, t, f) if (d) lock_print(s, t, f)
5753 #define LOCK_PRINT(d, s, t, f)
5758 creds_ok(cred_set_t cr_set
, struct svc_req
*req
, struct compound_state
*cs
)
5764 * Look up the pathname using the vp in cs as the directory vnode.
5765 * cs->vp will be the vnode for the file on success
5769 rfs4_lookup(component4
*component
, struct svc_req
*req
,
5770 struct compound_state
*cs
)
5775 struct sockaddr
*ca
;
5778 if (cs
->vp
== NULL
) {
5779 return (NFS4ERR_NOFILEHANDLE
);
5781 if (cs
->vp
->v_type
!= VDIR
) {
5782 return (NFS4ERR_NOTDIR
);
5785 status
= utf8_dir_verify(component
);
5786 if (status
!= NFS4_OK
)
5789 nm
= utf8_to_fn(component
, &len
, NULL
);
5791 return (NFS4ERR_INVAL
);
5794 if (len
> MAXNAMELEN
) {
5796 return (NFS4ERR_NAMETOOLONG
);
5799 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
5800 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
5805 return (NFS4ERR_INVAL
);
5808 status
= do_rfs4_op_lookup(name
, req
, cs
);
5811 kmem_free(name
, MAXPATHLEN
+ 1);
5819 rfs4_lookupfile(component4
*component
, struct svc_req
*req
,
5820 struct compound_state
*cs
, uint32_t access
, change_info4
*cinfo
)
5823 vnode_t
*dvp
= cs
->vp
;
5824 vattr_t bva
, ava
, fva
;
5827 /* Get "before" change value */
5828 bva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
5829 error
= fop_getattr(dvp
, &bva
, 0, cs
->cr
, NULL
);
5831 return (puterrno4(error
));
5833 /* rfs4_lookup may VN_RELE directory */
5836 status
= rfs4_lookup(component
, req
, cs
);
5837 if (status
!= NFS4_OK
) {
5843 * Get "after" change value, if it fails, simply return the
5846 ava
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
5847 if (fop_getattr(dvp
, &ava
, 0, cs
->cr
, NULL
)) {
5848 ava
.va_ctime
= bva
.va_ctime
;
5854 * Validate the file is a file
5856 fva
.va_mask
= VATTR_TYPE
|VATTR_MODE
;
5857 error
= fop_getattr(cs
->vp
, &fva
, 0, cs
->cr
, NULL
);
5859 return (puterrno4(error
));
5861 if (fva
.va_type
!= VREG
) {
5862 if (fva
.va_type
== VDIR
)
5863 return (NFS4ERR_ISDIR
);
5864 if (fva
.va_type
== VLNK
)
5865 return (NFS4ERR_SYMLINK
);
5866 return (NFS4ERR_INVAL
);
5869 NFS4_SET_FATTR4_CHANGE(cinfo
->before
, bva
.va_ctime
);
5870 NFS4_SET_FATTR4_CHANGE(cinfo
->after
, ava
.va_ctime
);
5873 * It is undefined if fop_lookup will change va_seq, so
5874 * cinfo.atomic = TRUE only if we have
5875 * non-zero va_seq's, and they have not changed.
5877 if (bva
.va_seq
&& ava
.va_seq
&& ava
.va_seq
== bva
.va_seq
)
5878 cinfo
->atomic
= TRUE
;
5880 cinfo
->atomic
= FALSE
;
5882 /* Check for mandatory locking */
5883 cs
->mandlock
= MANDLOCK(cs
->vp
, fva
.va_mode
);
5884 return (check_open_access(access
, cs
, req
));
5888 create_vnode(vnode_t
*dvp
, char *nm
, vattr_t
*vap
, createmode4 mode
,
5889 cred_t
*cr
, vnode_t
**vpp
, bool_t
*created
)
5892 nfsstat4 status
= NFS4_OK
;
5898 * The file open mode used is VWRITE. If the client needs
5899 * some other semantic, then it should do the access checking
5900 * itself. It would have been nice to have the file open mode
5901 * passed as part of the arguments.
5905 error
= fop_create(dvp
, nm
, vap
, EXCL
, VWRITE
, vpp
, cr
, 0, NULL
, NULL
);
5911 * If we got something other than file already exists
5912 * then just return this error. Otherwise, we got
5913 * EEXIST. If we were doing a GUARDED create, then
5914 * just return this error. Otherwise, we need to
5915 * make sure that this wasn't a duplicate of an
5916 * exclusive create request.
5918 * The assumption is made that a non-exclusive create
5919 * request will never return EEXIST.
5922 if (error
!= EEXIST
|| mode
== GUARDED4
) {
5923 status
= puterrno4(error
);
5926 error
= fop_lookup(dvp
, nm
, vpp
, NULL
, 0, NULL
, cr
,
5931 * We couldn't find the file that we thought that
5932 * we just created. So, we'll just try creating
5935 if (error
== ENOENT
)
5938 status
= puterrno4(error
);
5942 if (mode
== UNCHECKED4
) {
5943 /* existing object must be regular file */
5944 if ((*vpp
)->v_type
!= VREG
) {
5945 if ((*vpp
)->v_type
== VDIR
)
5946 status
= NFS4ERR_ISDIR
;
5947 else if ((*vpp
)->v_type
== VLNK
)
5948 status
= NFS4ERR_SYMLINK
;
5950 status
= NFS4ERR_INVAL
;
5958 /* Check for duplicate request */
5959 va
.va_mask
= VATTR_MTIME
;
5960 error
= fop_getattr(*vpp
, &va
, 0, cr
, NULL
);
5962 /* We found the file */
5963 const timestruc_t
*mtime
= &vap
->va_mtime
;
5965 if (va
.va_mtime
.tv_sec
!= mtime
->tv_sec
||
5966 va
.va_mtime
.tv_nsec
!= mtime
->tv_nsec
) {
5967 /* but its not our creation */
5969 return (NFS4ERR_EXIST
);
5971 *created
= TRUE
; /* retrans of create == created */
5975 return (NFS4ERR_EXIST
);
5982 check_open_access(uint32_t access
, struct compound_state
*cs
,
5983 struct svc_req
*req
)
5988 cred_t
*cr
= cs
->cr
;
5990 /* For now we don't allow mandatory locking as per V2/V3 */
5991 if (cs
->access
== CS_ACCESS_DENIED
|| cs
->mandlock
) {
5992 return (NFS4ERR_ACCESS
);
5996 ASSERT(cr
!= NULL
&& vp
->v_type
== VREG
);
5999 * If the file system is exported read only and we are trying
6000 * to open for write, then return NFS4ERR_ROFS
6003 readonly
= rdonly4(req
, cs
);
6005 if ((access
& OPEN4_SHARE_ACCESS_WRITE
) && readonly
)
6006 return (NFS4ERR_ROFS
);
6008 if (access
& OPEN4_SHARE_ACCESS_READ
) {
6009 if ((fop_access(vp
, VREAD
, 0, cr
, NULL
) != 0) &&
6010 (fop_access(vp
, VEXEC
, 0, cr
, NULL
) != 0)) {
6011 return (NFS4ERR_ACCESS
);
6015 if (access
& OPEN4_SHARE_ACCESS_WRITE
) {
6016 error
= fop_access(vp
, VWRITE
, 0, cr
, NULL
);
6018 return (NFS4ERR_ACCESS
);
6025 rfs4_createfile(OPEN4args
*args
, struct svc_req
*req
, struct compound_state
*cs
,
6026 change_info4
*cinfo
, bitmap4
*attrset
, clientid4 clientid
)
6028 struct nfs4_svgetit_arg sarg
;
6029 struct nfs4_ntov_table ntov
;
6031 bool_t ntov_table_init
= FALSE
;
6032 struct statvfs64 sb
;
6035 vattr_t bva
, ava
, iva
, cva
, *vap
;
6037 timespec32_t
*mtime
;
6041 bool_t setsize
= FALSE
;
6045 caller_context_t ct
;
6046 component4
*component
;
6047 struct sockaddr
*ca
;
6051 sarg
.is_referral
= B_FALSE
;
6055 /* Check if the file system is read only */
6056 if (rdonly4(req
, cs
))
6057 return (NFS4ERR_ROFS
);
6060 * Get the last component of path name in nm. cs will reference
6061 * the including directory on success.
6063 component
= &args
->open_claim4_u
.file
;
6064 status
= utf8_dir_verify(component
);
6065 if (status
!= NFS4_OK
)
6068 nm
= utf8_to_fn(component
, &buflen
, NULL
);
6071 return (NFS4ERR_RESOURCE
);
6073 if (buflen
> MAXNAMELEN
) {
6074 kmem_free(nm
, buflen
);
6075 return (NFS4ERR_NAMETOOLONG
);
6078 bva
.va_mask
= VATTR_TYPE
|VATTR_CTIME
|VATTR_SEQ
;
6079 error
= fop_getattr(dvp
, &bva
, 0, cs
->cr
, NULL
);
6081 kmem_free(nm
, buflen
);
6082 return (puterrno4(error
));
6085 if (bva
.va_type
!= VDIR
) {
6086 kmem_free(nm
, buflen
);
6087 return (NFS4ERR_NOTDIR
);
6090 NFS4_SET_FATTR4_CHANGE(cinfo
->before
, bva
.va_ctime
)
6092 switch (args
->mode
) {
6096 nfs4_ntov_table_init(&ntov
);
6097 ntov_table_init
= TRUE
;
6100 status
= do_rfs4_set_attrs(attrset
,
6101 &args
->createhow4_u
.createattrs
,
6102 cs
, &sarg
, &ntov
, NFS4ATTR_SETIT
);
6104 if (status
== NFS4_OK
&& (sarg
.vap
->va_mask
& VATTR_TYPE
) &&
6105 sarg
.vap
->va_type
!= VREG
) {
6106 if (sarg
.vap
->va_type
== VDIR
)
6107 status
= NFS4ERR_ISDIR
;
6108 else if (sarg
.vap
->va_type
== VLNK
)
6109 status
= NFS4ERR_SYMLINK
;
6111 status
= NFS4ERR_INVAL
;
6114 if (status
!= NFS4_OK
) {
6115 kmem_free(nm
, buflen
);
6116 nfs4_ntov_table_free(&ntov
, &sarg
);
6122 vap
->va_type
= VREG
;
6123 vap
->va_mask
|= VATTR_TYPE
;
6125 if ((vap
->va_mask
& VATTR_MODE
) == 0) {
6126 vap
->va_mask
|= VATTR_MODE
;
6127 vap
->va_mode
= (mode_t
)0600;
6130 if (vap
->va_mask
& VATTR_SIZE
) {
6132 /* Disallow create with a non-zero size */
6134 if ((reqsize
= sarg
.vap
->va_size
) != 0) {
6135 kmem_free(nm
, buflen
);
6136 nfs4_ntov_table_free(&ntov
, &sarg
);
6138 return (NFS4ERR_INVAL
);
6145 /* prohibit EXCL create of named attributes */
6146 if (dvp
->v_flag
& V_XATTRDIR
) {
6147 kmem_free(nm
, buflen
);
6149 return (NFS4ERR_INVAL
);
6152 cva
.va_mask
= VATTR_TYPE
| VATTR_MTIME
| VATTR_MODE
;
6155 * Ensure no time overflows. Assumes underlying
6156 * filesystem supports at least 32 bits.
6157 * Truncate nsec to usec resolution to allow valid
6158 * compares even if the underlying filesystem truncates.
6160 mtime
= (timespec32_t
*)&args
->createhow4_u
.createverf
;
6161 cva
.va_mtime
.tv_sec
= mtime
->tv_sec
% TIME32_MAX
;
6162 cva
.va_mtime
.tv_nsec
= (mtime
->tv_nsec
/ 1000) * 1000;
6163 cva
.va_mode
= (mode_t
)0;
6167 * For EXCL create, attrset is set to the server attr
6168 * used to cache the client's verifier.
6170 *attrset
= FATTR4_TIME_MODIFY_MASK
;
6174 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
6175 name
= nfscmd_convname(ca
, cs
->exi
, nm
, NFSCMD_CONV_INBOUND
,
6179 kmem_free(nm
, buflen
);
6180 return (NFS4ERR_SERVERFAULT
);
6183 status
= create_vnode(dvp
, name
, vap
, args
->mode
,
6184 cs
->cr
, &vp
, &created
);
6186 kmem_free(name
, MAXPATHLEN
+ 1);
6187 kmem_free(nm
, buflen
);
6189 if (status
!= NFS4_OK
) {
6190 if (ntov_table_init
)
6191 nfs4_ntov_table_free(&ntov
, &sarg
);
6196 trunc
= (setsize
&& !created
);
6198 if (args
->mode
!= EXCLUSIVE4
) {
6199 bitmap4 createmask
= args
->createhow4_u
.createattrs
.attrmask
;
6202 * True verification that object was created with correct
6203 * attrs is impossible. The attrs could have been changed
6204 * immediately after object creation. If attributes did
6205 * not verify, the only recourse for the server is to
6206 * destroy the object. Maybe if some attrs (like gid)
6207 * are set incorrectly, the object should be destroyed;
6208 * however, seems bad as a default policy. Do we really
6209 * want to destroy an object over one of the times not
6210 * verifying correctly? For these reasons, the server
6211 * currently sets bits in attrset for createattrs
6212 * that were set; however, no verification is done.
6214 * vmask_to_nmask accounts for vattr bits set on create
6215 * [do_rfs4_set_attrs() only sets resp bits for
6216 * non-vattr/vfs bits.]
6217 * Mask off any bits we set by default so as not to return
6218 * more attrset bits than were requested in createattrs
6221 nfs4_vmask_to_nmask(sarg
.vap
->va_mask
, attrset
);
6222 *attrset
&= createmask
;
6225 * We did not create the vnode (we tried but it
6226 * already existed). In this case, the only createattr
6227 * that the spec allows the server to set is size,
6228 * and even then, it can only be set if it is 0.
6232 *attrset
= FATTR4_SIZE_MASK
;
6235 if (ntov_table_init
)
6236 nfs4_ntov_table_free(&ntov
, &sarg
);
6239 * Get the initial "after" sequence number, if it fails,
6240 * set to zero, time to before.
6242 iva
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
6243 if (fop_getattr(dvp
, &iva
, 0, cs
->cr
, NULL
)) {
6245 iva
.va_ctime
= bva
.va_ctime
;
6249 * create_vnode attempts to create the file exclusive,
6250 * if it already exists the fop_create will fail and
6251 * may not increase va_seq. It is atomic if
6252 * we haven't changed the directory, but if it has changed
6253 * we don't know what changed it.
6256 if (bva
.va_seq
&& iva
.va_seq
&&
6257 bva
.va_seq
== iva
.va_seq
)
6258 cinfo
->atomic
= TRUE
;
6260 cinfo
->atomic
= FALSE
;
6261 NFS4_SET_FATTR4_CHANGE(cinfo
->after
, iva
.va_ctime
);
6264 * The entry was created, we need to sync the
6265 * directory metadata.
6267 (void) fop_fsync(dvp
, 0, cs
->cr
, NULL
);
6270 * Get "after" change value, if it fails, simply return the
6273 ava
.va_mask
= VATTR_CTIME
|VATTR_SEQ
;
6274 if (fop_getattr(dvp
, &ava
, 0, cs
->cr
, NULL
)) {
6275 ava
.va_ctime
= bva
.va_ctime
;
6279 NFS4_SET_FATTR4_CHANGE(cinfo
->after
, ava
.va_ctime
);
6282 * The cinfo->atomic = TRUE only if we have
6283 * non-zero va_seq's, and it has incremented by exactly one
6284 * during the create_vnode and it didn't
6285 * change during the fop_fsync.
6287 if (bva
.va_seq
&& iva
.va_seq
&& ava
.va_seq
&&
6288 iva
.va_seq
== (bva
.va_seq
+ 1) && iva
.va_seq
== ava
.va_seq
)
6289 cinfo
->atomic
= TRUE
;
6291 cinfo
->atomic
= FALSE
;
6294 /* Check for mandatory locking and that the size gets set. */
6295 cva
.va_mask
= VATTR_MODE
;
6297 cva
.va_mask
|= VATTR_SIZE
;
6299 /* Assume the worst */
6300 cs
->mandlock
= TRUE
;
6302 if (fop_getattr(vp
, &cva
, 0, cs
->cr
, NULL
) == 0) {
6303 cs
->mandlock
= MANDLOCK(cs
->vp
, cva
.va_mode
);
6306 * Truncate the file if necessary; this would be
6307 * the case for create over an existing file.
6313 bool_t create
= FALSE
;
6316 * We are writing over an existing file.
6317 * Check to see if we need to recall a delegation.
6319 rfs4_hold_deleg_policy();
6320 if ((fp
= rfs4_findfile(vp
, NULL
, &create
)) != NULL
) {
6321 if (rfs4_check_delegated_byfp(FWRITE
, fp
,
6322 (reqsize
== 0), FALSE
, FALSE
, &clientid
)) {
6324 rfs4_rele_deleg_policy();
6327 return (NFS4ERR_DELAY
);
6331 rfs4_rele_deleg_policy();
6333 if (nbl_need_check(vp
)) {
6336 ASSERT(reqsize
== 0);
6338 nbl_start_crit(vp
, RW_READER
);
6339 if (nbl_conflict(vp
, NBL_WRITE
, 0,
6340 cva
.va_size
, 0, NULL
)) {
6345 return (NFS4ERR_ACCESS
);
6350 ct
.cc_caller_id
= nfs4_srv_caller_id
;
6351 ct
.cc_flags
= CC_DONTBLOCK
;
6353 cva
.va_mask
= VATTR_SIZE
;
6354 cva
.va_size
= reqsize
;
6355 (void) fop_setattr(vp
, &cva
, 0, cs
->cr
, &ct
);
6361 error
= makefh4(&cs
->fh
, vp
, cs
->exi
);
6364 * Force modified data and metadata out to stable storage.
6366 (void) fop_fsync(vp
, FNODSYNC
, cs
->cr
, NULL
);
6371 return (puterrno4(error
));
6374 /* if parent dir is attrdir, set namedattr fh flag */
6375 if (dvp
->v_flag
& V_XATTRDIR
)
6376 set_fh4_flag(&cs
->fh
, FH4_NAMEDATTR
);
6384 * if we did not create the file, we will need to check
6385 * the access bits on the file
6390 args
->share_access
|= OPEN4_SHARE_ACCESS_WRITE
;
6391 status
= check_open_access(args
->share_access
, cs
, req
);
6392 if (status
!= NFS4_OK
)
6400 rfs4_do_open(struct compound_state
*cs
, struct svc_req
*req
,
6401 rfs4_openowner_t
*oo
, delegreq_t deleg
,
6402 uint32_t access
, uint32_t deny
,
6403 OPEN4res
*resp
, int deleg_cur
)
6405 /* XXX Currently not using req */
6408 bool_t screate
= TRUE
;
6409 bool_t fcreate
= TRUE
;
6410 uint32_t open_a
, share_a
;
6411 uint32_t open_d
, share_d
;
6412 rfs4_deleg_state_t
*dsp
;
6415 caller_context_t ct
;
6421 /* get the file struct and hold a lock on it during initial open */
6422 fp
= rfs4_findfile_withlock(cs
->vp
, &cs
->fh
, &fcreate
);
6424 resp
->status
= NFS4ERR_RESOURCE
;
6425 DTRACE_PROBE1(nfss__e__do__open1
, nfsstat4
, resp
->status
);
6429 sp
= rfs4_findstate_by_owner_file(oo
, fp
, &screate
);
6431 resp
->status
= NFS4ERR_RESOURCE
;
6432 DTRACE_PROBE1(nfss__e__do__open2
, nfsstat4
, resp
->status
);
6433 /* No need to keep any reference */
6434 rw_exit(&fp
->rf_file_rwlock
);
6439 /* try to get the sysid before continuing */
6440 if ((status
= rfs4_client_sysid(oo
->ro_client
, &sysid
)) != NFS4_OK
) {
6441 resp
->status
= status
;
6443 /* Not a fully formed open; "close" it */
6444 if (screate
== TRUE
)
6445 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6446 rfs4_state_rele(sp
);
6450 /* Calculate the fflags for this OPEN. */
6451 if (access
& OPEN4_SHARE_ACCESS_READ
)
6453 if (access
& OPEN4_SHARE_ACCESS_WRITE
)
6456 rfs4_dbe_lock(sp
->rs_dbe
);
6459 * Calculate the new deny and access mode that this open is adding to
6460 * the file for this open owner;
6462 open_d
= (deny
& ~sp
->rs_open_deny
);
6463 open_a
= (access
& ~sp
->rs_open_access
);
6466 * Calculate the new share access and share deny modes that this open
6467 * is adding to the file for this open owner;
6469 share_a
= (access
& ~sp
->rs_share_access
);
6470 share_d
= (deny
& ~sp
->rs_share_deny
);
6472 first_open
= (sp
->rs_open_access
& OPEN4_SHARE_ACCESS_BOTH
) == 0;
6475 * Check to see the client has already sent an open for this
6476 * open owner on this file with the same share/deny modes.
6477 * If so, we don't need to check for a conflict and we don't
6478 * need to add another shrlock. If not, then we need to
6479 * check for conflicts in deny and access before checking for
6480 * conflicts in delegation. We don't want to recall a
6481 * delegation based on an open that will eventually fail based
6485 if (share_a
|| share_d
) {
6486 if ((err
= rfs4_share(sp
, access
, deny
)) != 0) {
6487 rfs4_dbe_unlock(sp
->rs_dbe
);
6491 /* Not a fully formed open; "close" it */
6492 if (screate
== TRUE
)
6493 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6494 rfs4_state_rele(sp
);
6499 rfs4_dbe_lock(fp
->rf_dbe
);
6502 * Check to see if this file is delegated and if so, if a
6503 * recall needs to be done.
6505 if (rfs4_check_recall(sp
, access
)) {
6506 rfs4_dbe_unlock(fp
->rf_dbe
);
6507 rfs4_dbe_unlock(sp
->rs_dbe
);
6508 rfs4_recall_deleg(fp
, FALSE
, sp
->rs_owner
->ro_client
);
6509 delay(NFS4_DELEGATION_CONFLICT_DELAY
);
6510 rfs4_dbe_lock(sp
->rs_dbe
);
6512 /* if state closed while lock was dropped */
6513 if (sp
->rs_closed
) {
6514 if (share_a
|| share_d
)
6515 (void) rfs4_unshare(sp
);
6516 rfs4_dbe_unlock(sp
->rs_dbe
);
6518 /* Not a fully formed open; "close" it */
6519 if (screate
== TRUE
)
6520 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6521 rfs4_state_rele(sp
);
6522 resp
->status
= NFS4ERR_OLD_STATEID
;
6526 rfs4_dbe_lock(fp
->rf_dbe
);
6527 /* Let's see if the delegation was returned */
6528 if (rfs4_check_recall(sp
, access
)) {
6529 rfs4_dbe_unlock(fp
->rf_dbe
);
6530 if (share_a
|| share_d
)
6531 (void) rfs4_unshare(sp
);
6532 rfs4_dbe_unlock(sp
->rs_dbe
);
6534 rfs4_update_lease(sp
->rs_owner
->ro_client
);
6536 /* Not a fully formed open; "close" it */
6537 if (screate
== TRUE
)
6538 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6539 rfs4_state_rele(sp
);
6540 resp
->status
= NFS4ERR_DELAY
;
6545 * the share check passed and any delegation conflict has been
6546 * taken care of, now call vop_open.
6547 * if this is the first open then call vop_open with fflags.
6548 * if not, call vn_open_upgrade with just the upgrade flags.
6550 * if the file has been opened already, it will have the current
6551 * access mode in the state struct. if it has no share access, then
6552 * this is a new open.
6554 * However, if this is open with CLAIM_DLEGATE_CUR, then don't
6555 * call fop_open(), just do the open upgrade.
6557 if (first_open
&& !deleg_cur
) {
6558 ct
.cc_sysid
= sysid
;
6559 ct
.cc_pid
= rfs4_dbe_getid(sp
->rs_owner
->ro_dbe
);
6560 ct
.cc_caller_id
= nfs4_srv_caller_id
;
6561 ct
.cc_flags
= CC_DONTBLOCK
;
6562 err
= fop_open(&cs
->vp
, fflags
, cs
->cr
, &ct
);
6564 rfs4_dbe_unlock(fp
->rf_dbe
);
6565 if (share_a
|| share_d
)
6566 (void) rfs4_unshare(sp
);
6567 rfs4_dbe_unlock(sp
->rs_dbe
);
6570 /* Not a fully formed open; "close" it */
6571 if (screate
== TRUE
)
6572 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
6573 rfs4_state_rele(sp
);
6574 /* check if a monitor detected a delegation conflict */
6575 if (err
== EAGAIN
&& (ct
.cc_flags
& CC_WOULDBLOCK
))
6576 resp
->status
= NFS4ERR_DELAY
;
6578 resp
->status
= NFS4ERR_SERVERFAULT
;
6581 } else { /* open upgrade */
6583 * calculate the fflags for the new mode that is being added
6587 if (open_a
& OPEN4_SHARE_ACCESS_READ
)
6589 if (open_a
& OPEN4_SHARE_ACCESS_WRITE
)
6591 vn_open_upgrade(cs
->vp
, fflags
);
6593 sp
->rs_open_access
|= access
;
6594 sp
->rs_open_deny
|= deny
;
6596 if (open_d
& OPEN4_SHARE_DENY_READ
)
6598 if (open_d
& OPEN4_SHARE_DENY_WRITE
)
6599 fp
->rf_deny_write
++;
6600 fp
->rf_share_deny
|= deny
;
6602 if (open_a
& OPEN4_SHARE_ACCESS_READ
)
6603 fp
->rf_access_read
++;
6604 if (open_a
& OPEN4_SHARE_ACCESS_WRITE
)
6605 fp
->rf_access_write
++;
6606 fp
->rf_share_access
|= access
;
6609 * Check for delegation here. if the deleg argument is not
6610 * DELEG_ANY, then this is a reclaim from a client and
6611 * we must honor the delegation requested. If necessary we can
6612 * set the recall flag.
6615 dsp
= rfs4_grant_delegation(deleg
, sp
, &recall
);
6617 cs
->deleg
= (fp
->rf_dinfo
.rd_dtype
== OPEN_DELEGATE_WRITE
);
6619 next_stateid(&sp
->rs_stateid
);
6621 resp
->stateid
= sp
->rs_stateid
.stateid
;
6623 rfs4_dbe_unlock(fp
->rf_dbe
);
6624 rfs4_dbe_unlock(sp
->rs_dbe
);
6627 rfs4_set_deleg_response(dsp
, &resp
->delegation
, NULL
, recall
);
6628 rfs4_deleg_state_rele(dsp
);
6632 rfs4_state_rele(sp
);
6634 resp
->status
= NFS4_OK
;
6639 rfs4_do_opennull(struct compound_state
*cs
, struct svc_req
*req
,
6640 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
6642 change_info4
*cinfo
= &resp
->cinfo
;
6643 bitmap4
*attrset
= &resp
->attrset
;
6645 if (args
->opentype
== OPEN4_NOCREATE
)
6646 resp
->status
= rfs4_lookupfile(&args
->open_claim4_u
.file
,
6647 req
, cs
, args
->share_access
, cinfo
);
6649 /* inhibit delegation grants during exclusive create */
6651 if (args
->mode
== EXCLUSIVE4
)
6652 rfs4_disable_delegation();
6654 resp
->status
= rfs4_createfile(args
, req
, cs
, cinfo
, attrset
,
6655 oo
->ro_client
->rc_clientid
);
6658 if (resp
->status
== NFS4_OK
) {
6660 /* cs->vp cs->fh now reference the desired file */
6662 rfs4_do_open(cs
, req
, oo
,
6663 oo
->ro_need_confirm
? DELEG_NONE
: DELEG_ANY
,
6664 args
->share_access
, args
->share_deny
, resp
, 0);
6667 * If rfs4_createfile set attrset, we must
6668 * clear this attrset before the response is copied.
6670 if (resp
->status
!= NFS4_OK
&& resp
->attrset
) {
6675 *cs
->statusp
= resp
->status
;
6677 if (args
->mode
== EXCLUSIVE4
)
6678 rfs4_enable_delegation();
6683 rfs4_do_openprev(struct compound_state
*cs
, struct svc_req
*req
,
6684 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
6686 change_info4
*cinfo
= &resp
->cinfo
;
6688 vtype_t v_type
= cs
->vp
->v_type
;
6691 /* Verify that we have a regular file */
6692 if (v_type
!= VREG
) {
6694 resp
->status
= NFS4ERR_ISDIR
;
6695 else if (v_type
== VLNK
)
6696 resp
->status
= NFS4ERR_SYMLINK
;
6698 resp
->status
= NFS4ERR_INVAL
;
6702 va
.va_mask
= VATTR_MODE
|VATTR_UID
;
6703 error
= fop_getattr(cs
->vp
, &va
, 0, cs
->cr
, NULL
);
6705 resp
->status
= puterrno4(error
);
6709 cs
->mandlock
= MANDLOCK(cs
->vp
, va
.va_mode
);
6712 * Check if we have access to the file, Note the the file
6713 * could have originally been open UNCHECKED or GUARDED
6714 * with mode bits that will now fail, but there is nothing
6715 * we can really do about that except in the case that the
6716 * owner of the file is the one requesting the open.
6718 if (crgetuid(cs
->cr
) != va
.va_uid
) {
6719 resp
->status
= check_open_access(args
->share_access
, cs
, req
);
6720 if (resp
->status
!= NFS4_OK
) {
6726 * cinfo on a CLAIM_PREVIOUS is undefined, initialize to zero
6730 cinfo
->atomic
= FALSE
;
6732 rfs4_do_open(cs
, req
, oo
,
6733 NFS4_DELEG4TYPE2REQTYPE(args
->open_claim4_u
.delegate_type
),
6734 args
->share_access
, args
->share_deny
, resp
, 0);
6738 rfs4_do_opendelcur(struct compound_state
*cs
, struct svc_req
*req
,
6739 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
6744 args
->open_claim4_u
.delegate_cur_info
.delegate_stateid
;
6745 rfs4_deleg_state_t
*dsp
;
6748 * Find the state info from the stateid and confirm that the
6749 * file is delegated. If the state openowner is the same as
6750 * the supplied openowner we're done. If not, get the file
6751 * info from the found state info. Use that file info to
6752 * create the state for this lock owner. Note solaris doen't
6753 * really need the pathname to find the file. We may want to
6754 * lookup the pathname and make sure that the vp exist and
6755 * matches the vp in the file structure. However it is
6756 * possible that the pathname nolonger exists (local process
6757 * unlinks the file), so this may not be that useful.
6760 status
= rfs4_get_deleg_state(&stateid
, &dsp
);
6761 if (status
!= NFS4_OK
) {
6762 resp
->status
= status
;
6766 ASSERT(dsp
->rds_finfo
->rf_dinfo
.rd_dtype
!= OPEN_DELEGATE_NONE
);
6769 * New lock owner, create state. Since this was probably called
6770 * in response to a CB_RECALL we set deleg to DELEG_NONE
6773 ASSERT(cs
->vp
!= NULL
);
6775 VN_HOLD(dsp
->rds_finfo
->rf_vp
);
6776 cs
->vp
= dsp
->rds_finfo
->rf_vp
;
6778 if (error
= makefh4(&cs
->fh
, cs
->vp
, cs
->exi
)) {
6779 rfs4_deleg_state_rele(dsp
);
6780 *cs
->statusp
= resp
->status
= puterrno4(error
);
6784 /* Mark progress for delegation returns */
6785 dsp
->rds_finfo
->rf_dinfo
.rd_time_lastwrite
= gethrestime_sec();
6786 rfs4_deleg_state_rele(dsp
);
6787 rfs4_do_open(cs
, req
, oo
, DELEG_NONE
,
6788 args
->share_access
, args
->share_deny
, resp
, 1);
6793 rfs4_do_opendelprev(struct compound_state
*cs
, struct svc_req
*req
,
6794 OPEN4args
*args
, rfs4_openowner_t
*oo
, OPEN4res
*resp
)
6797 * Lookup the pathname, it must already exist since this file
6800 * Find the file and state info for this vp and open owner pair.
6801 * check that they are in fact delegated.
6802 * check that the state access and deny modes are the same.
6804 * Return the delgation possibly seting the recall flag.
6808 bool_t create
= FALSE
;
6809 bool_t dcreate
= FALSE
;
6810 rfs4_deleg_state_t
*dsp
;
6813 /* Note we ignore oflags */
6814 resp
->status
= rfs4_lookupfile(&args
->open_claim4_u
.file_delegate_prev
,
6815 req
, cs
, args
->share_access
, &resp
->cinfo
);
6817 if (resp
->status
!= NFS4_OK
) {
6821 /* get the file struct and hold a lock on it during initial open */
6822 fp
= rfs4_findfile_withlock(cs
->vp
, NULL
, &create
);
6824 resp
->status
= NFS4ERR_RESOURCE
;
6825 DTRACE_PROBE1(nfss__e__do_opendelprev1
, nfsstat4
, resp
->status
);
6829 sp
= rfs4_findstate_by_owner_file(oo
, fp
, &create
);
6831 resp
->status
= NFS4ERR_SERVERFAULT
;
6832 DTRACE_PROBE1(nfss__e__do_opendelprev2
, nfsstat4
, resp
->status
);
6833 rw_exit(&fp
->rf_file_rwlock
);
6838 rfs4_dbe_lock(sp
->rs_dbe
);
6839 rfs4_dbe_lock(fp
->rf_dbe
);
6840 if (args
->share_access
!= sp
->rs_share_access
||
6841 args
->share_deny
!= sp
->rs_share_deny
||
6842 sp
->rs_finfo
->rf_dinfo
.rd_dtype
== OPEN_DELEGATE_NONE
) {
6843 NFS4_DEBUG(rfs4_debug
,
6844 (CE_NOTE
, "rfs4_do_opendelprev: state mixup"));
6845 rfs4_dbe_unlock(fp
->rf_dbe
);
6846 rfs4_dbe_unlock(sp
->rs_dbe
);
6848 rfs4_state_rele(sp
);
6849 resp
->status
= NFS4ERR_SERVERFAULT
;
6852 rfs4_dbe_unlock(fp
->rf_dbe
);
6853 rfs4_dbe_unlock(sp
->rs_dbe
);
6855 dsp
= rfs4_finddeleg(sp
, &dcreate
);
6857 rfs4_state_rele(sp
);
6859 resp
->status
= NFS4ERR_SERVERFAULT
;
6863 next_stateid(&sp
->rs_stateid
);
6865 resp
->stateid
= sp
->rs_stateid
.stateid
;
6867 resp
->delegation
.delegation_type
= dsp
->rds_dtype
;
6869 if (dsp
->rds_dtype
== OPEN_DELEGATE_READ
) {
6870 open_read_delegation4
*rv
=
6871 &resp
->delegation
.open_delegation4_u
.read
;
6873 rv
->stateid
= dsp
->rds_delegid
.stateid
;
6874 rv
->recall
= FALSE
; /* no policy in place to set to TRUE */
6875 ace
= &rv
->permissions
;
6877 open_write_delegation4
*rv
=
6878 &resp
->delegation
.open_delegation4_u
.write
;
6880 rv
->stateid
= dsp
->rds_delegid
.stateid
;
6881 rv
->recall
= FALSE
; /* no policy in place to set to TRUE */
6882 ace
= &rv
->permissions
;
6883 rv
->space_limit
.limitby
= NFS_LIMIT_SIZE
;
6884 rv
->space_limit
.nfs_space_limit4_u
.filesize
= UINT64_MAX
;
6888 ace
->type
= ACE4_ACCESS_ALLOWED_ACE_TYPE
;
6890 ace
->access_mask
= 0;
6891 ace
->who
.utf8string_len
= 0;
6892 ace
->who
.utf8string_val
= 0;
6894 rfs4_deleg_state_rele(dsp
);
6895 rfs4_state_rele(sp
);
6900 NFS4_CHKSEQ_OKAY
= 0,
6901 NFS4_CHKSEQ_REPLAY
= 1,
6906 * Generic function for sequence number checks.
6908 static rfs4_chkseq_t
6909 rfs4_check_seqid(seqid4 seqid
, nfs_resop4
*lastop
,
6910 seqid4 rqst_seq
, nfs_resop4
*resop
, bool_t copyres
)
6912 /* Same sequence ids and matching operations? */
6913 if (seqid
== rqst_seq
&& resop
->resop
== lastop
->resop
) {
6914 if (copyres
== TRUE
) {
6915 rfs4_free_reply(resop
);
6916 rfs4_copy_reply(resop
, lastop
);
6918 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
,
6919 "Replayed SEQID %d\n", seqid
));
6920 return (NFS4_CHKSEQ_REPLAY
);
6923 /* If the incoming sequence is not the next expected then it is bad */
6924 if (rqst_seq
!= seqid
+ 1) {
6925 if (rqst_seq
== seqid
) {
6926 NFS4_DEBUG(rfs4_debug
,
6927 (CE_NOTE
, "BAD SEQID: Replayed sequence id "
6928 "but last op was %d current op is %d\n",
6929 lastop
->resop
, resop
->resop
));
6930 return (NFS4_CHKSEQ_BAD
);
6932 NFS4_DEBUG(rfs4_debug
,
6933 (CE_NOTE
, "BAD SEQID: got %u expecting %u\n",
6935 return (NFS4_CHKSEQ_BAD
);
6938 /* Everything okay -- next expected */
6939 return (NFS4_CHKSEQ_OKAY
);
6943 static rfs4_chkseq_t
6944 rfs4_check_open_seqid(seqid4 seqid
, rfs4_openowner_t
*op
, nfs_resop4
*resop
)
6948 rfs4_dbe_lock(op
->ro_dbe
);
6949 rc
= rfs4_check_seqid(op
->ro_open_seqid
, &op
->ro_reply
, seqid
, resop
,
6951 rfs4_dbe_unlock(op
->ro_dbe
);
6953 if (rc
== NFS4_CHKSEQ_OKAY
)
6954 rfs4_update_lease(op
->ro_client
);
6959 static rfs4_chkseq_t
6960 rfs4_check_olo_seqid(seqid4 olo_seqid
, rfs4_openowner_t
*op
, nfs_resop4
*resop
)
6964 rfs4_dbe_lock(op
->ro_dbe
);
6965 rc
= rfs4_check_seqid(op
->ro_open_seqid
, &op
->ro_reply
,
6966 olo_seqid
, resop
, FALSE
);
6967 rfs4_dbe_unlock(op
->ro_dbe
);
6972 static rfs4_chkseq_t
6973 rfs4_check_lock_seqid(seqid4 seqid
, rfs4_lo_state_t
*lsp
, nfs_resop4
*resop
)
6975 rfs4_chkseq_t rc
= NFS4_CHKSEQ_OKAY
;
6977 rfs4_dbe_lock(lsp
->rls_dbe
);
6978 if (!lsp
->rls_skip_seqid_check
)
6979 rc
= rfs4_check_seqid(lsp
->rls_seqid
, &lsp
->rls_reply
, seqid
,
6981 rfs4_dbe_unlock(lsp
->rls_dbe
);
6987 rfs4_op_open(nfs_argop4
*argop
, nfs_resop4
*resop
,
6988 struct svc_req
*req
, struct compound_state
*cs
)
6990 OPEN4args
*args
= &argop
->nfs_argop4_u
.opopen
;
6991 OPEN4res
*resp
= &resop
->nfs_resop4_u
.opopen
;
6992 open_owner4
*owner
= &args
->owner
;
6993 open_claim_type4 claim
= args
->claim
;
6995 rfs4_openowner_t
*oo
;
6997 bool_t replay
= FALSE
;
7000 DTRACE_NFSV4_2(op__open__start
, struct compound_state
*, cs
,
7003 if (cs
->vp
== NULL
) {
7004 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
7009 * Need to check clientid and lease expiration first based on
7010 * error ordering and incrementing sequence id.
7012 cp
= rfs4_findclient_by_id(owner
->clientid
, FALSE
);
7014 *cs
->statusp
= resp
->status
=
7015 rfs4_check_clientid(&owner
->clientid
, 0);
7019 if (rfs4_lease_expired(cp
)) {
7020 rfs4_client_close(cp
);
7021 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
7024 can_reclaim
= cp
->rc_can_reclaim
;
7027 * Find the open_owner for use from this point forward. Take
7028 * care in updating the sequence id based on the type of error
7033 oo
= rfs4_findopenowner(owner
, &create
, args
->seqid
);
7035 *cs
->statusp
= resp
->status
= NFS4ERR_RESOURCE
;
7036 rfs4_client_rele(cp
);
7040 /* Hold off access to the sequence space while the open is done */
7041 rfs4_sw_enter(&oo
->ro_sw
);
7044 * If the open_owner existed before at the server, then check
7047 if (!create
&& !oo
->ro_postpone_confirm
) {
7048 switch (rfs4_check_open_seqid(args
->seqid
, oo
, resop
)) {
7049 case NFS4_CHKSEQ_BAD
:
7050 if ((args
->seqid
> oo
->ro_open_seqid
) &&
7051 oo
->ro_need_confirm
) {
7052 rfs4_free_opens(oo
, TRUE
, FALSE
);
7053 rfs4_sw_exit(&oo
->ro_sw
);
7054 rfs4_openowner_rele(oo
);
7057 resp
->status
= NFS4ERR_BAD_SEQID
;
7059 case NFS4_CHKSEQ_REPLAY
: /* replay of previous request */
7067 * Sequence was ok and open owner exists
7068 * check to see if we have yet to see an
7071 if (oo
->ro_need_confirm
) {
7072 rfs4_free_opens(oo
, TRUE
, FALSE
);
7073 rfs4_sw_exit(&oo
->ro_sw
);
7074 rfs4_openowner_rele(oo
);
7078 /* Grace only applies to regular-type OPENs */
7079 if (rfs4_clnt_in_grace(cp
) &&
7080 (claim
== CLAIM_NULL
|| claim
== CLAIM_DELEGATE_CUR
)) {
7081 *cs
->statusp
= resp
->status
= NFS4ERR_GRACE
;
7086 * If previous state at the server existed then can_reclaim
7087 * will be set. If not reply NFS4ERR_NO_GRACE to the
7090 if (rfs4_clnt_in_grace(cp
) && claim
== CLAIM_PREVIOUS
&& !can_reclaim
) {
7091 *cs
->statusp
= resp
->status
= NFS4ERR_NO_GRACE
;
7097 * Reject the open if the client has missed the grace period
7099 if (!rfs4_clnt_in_grace(cp
) && claim
== CLAIM_PREVIOUS
) {
7100 *cs
->statusp
= resp
->status
= NFS4ERR_NO_GRACE
;
7104 /* Couple of up-front bookkeeping items */
7105 if (oo
->ro_need_confirm
) {
7107 * If this is a reclaim OPEN then we should not ask
7108 * for a confirmation of the open_owner per the
7109 * protocol specification.
7111 if (claim
== CLAIM_PREVIOUS
)
7112 oo
->ro_need_confirm
= FALSE
;
7114 resp
->rflags
|= OPEN4_RESULT_CONFIRM
;
7116 resp
->rflags
|= OPEN4_RESULT_LOCKTYPE_POSIX
;
7119 * If there is an unshared filesystem mounted on this vnode,
7120 * do not allow to open/create in this directory.
7122 if (vn_ismntpt(cs
->vp
)) {
7123 *cs
->statusp
= resp
->status
= NFS4ERR_ACCESS
;
7128 * access must READ, WRITE, or BOTH. No access is invalid.
7129 * deny can be READ, WRITE, BOTH, or NONE.
7130 * bits not defined for access/deny are invalid.
7132 if (! (args
->share_access
& OPEN4_SHARE_ACCESS_BOTH
) ||
7133 (args
->share_access
& ~OPEN4_SHARE_ACCESS_BOTH
) ||
7134 (args
->share_deny
& ~OPEN4_SHARE_DENY_BOTH
)) {
7135 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7141 * make sure attrset is zero before response is built.
7147 rfs4_do_opennull(cs
, req
, args
, oo
, resp
);
7149 case CLAIM_PREVIOUS
:
7150 rfs4_do_openprev(cs
, req
, args
, oo
, resp
);
7152 case CLAIM_DELEGATE_CUR
:
7153 rfs4_do_opendelcur(cs
, req
, args
, oo
, resp
);
7155 case CLAIM_DELEGATE_PREV
:
7156 rfs4_do_opendelprev(cs
, req
, args
, oo
, resp
);
7159 resp
->status
= NFS4ERR_INVAL
;
7164 rfs4_client_rele(cp
);
7166 /* Catch sequence id handling here to make it a little easier */
7167 switch (resp
->status
) {
7168 case NFS4ERR_BADXDR
:
7169 case NFS4ERR_BAD_SEQID
:
7170 case NFS4ERR_BAD_STATEID
:
7171 case NFS4ERR_NOFILEHANDLE
:
7172 case NFS4ERR_RESOURCE
:
7173 case NFS4ERR_STALE_CLIENTID
:
7174 case NFS4ERR_STALE_STATEID
:
7176 * The protocol states that if any of these errors are
7177 * being returned, the sequence id should not be
7178 * incremented. Any other return requires an
7183 /* Always update the lease in this case */
7184 rfs4_update_lease(oo
->ro_client
);
7186 /* Regular response - copy the result */
7188 rfs4_update_open_resp(oo
, resop
, &cs
->fh
);
7191 * REPLAY case: Only if the previous response was OK
7192 * do we copy the filehandle. If not OK, no
7193 * filehandle to copy.
7195 if (replay
== TRUE
&&
7196 resp
->status
== NFS4_OK
&&
7197 oo
->ro_reply_fh
.nfs_fh4_val
) {
7199 * If this is a replay, we must restore the
7200 * current filehandle/vp to that of what was
7201 * returned originally. Try our best to do
7204 nfs_fh4_fmt_t
*fh_fmtp
=
7205 (nfs_fh4_fmt_t
*)oo
->ro_reply_fh
.nfs_fh4_val
;
7207 cs
->exi
= checkexport4(&fh_fmtp
->fh4_fsid
,
7208 (fid_t
*)&fh_fmtp
->fh4_xlen
, NULL
);
7210 if (cs
->exi
== NULL
) {
7211 resp
->status
= NFS4ERR_STALE
;
7217 cs
->vp
= nfs4_fhtovp(&oo
->ro_reply_fh
, cs
->exi
,
7223 nfs_fh4_copy(&oo
->ro_reply_fh
, &cs
->fh
);
7227 * If this was a replay, no need to update the
7228 * sequence id. If the open_owner was not created on
7229 * this pass, then update. The first use of an
7230 * open_owner will not bump the sequence id.
7232 if (replay
== FALSE
&& !create
)
7233 rfs4_update_open_sequence(oo
);
7235 * If the client is receiving an error and the
7236 * open_owner needs to be confirmed, there is no way
7237 * to notify the client of this fact ignoring the fact
7238 * that the server has no method of returning a
7239 * stateid to confirm. Therefore, the server needs to
7240 * mark this open_owner in a way as to avoid the
7241 * sequence id checking the next time the client uses
7244 if (resp
->status
!= NFS4_OK
&& oo
->ro_need_confirm
)
7245 oo
->ro_postpone_confirm
= TRUE
;
7247 * If OK response then clear the postpone flag and
7248 * reset the sequence id to keep in sync with the
7251 if (resp
->status
== NFS4_OK
&& oo
->ro_postpone_confirm
) {
7252 oo
->ro_postpone_confirm
= FALSE
;
7253 oo
->ro_open_seqid
= args
->seqid
;
7259 *cs
->statusp
= resp
->status
;
7261 rfs4_sw_exit(&oo
->ro_sw
);
7262 rfs4_openowner_rele(oo
);
7265 DTRACE_NFSV4_2(op__open__done
, struct compound_state
*, cs
,
7271 rfs4_op_open_confirm(nfs_argop4
*argop
, nfs_resop4
*resop
,
7272 struct svc_req
*req
, struct compound_state
*cs
)
7274 OPEN_CONFIRM4args
*args
= &argop
->nfs_argop4_u
.opopen_confirm
;
7275 OPEN_CONFIRM4res
*resp
= &resop
->nfs_resop4_u
.opopen_confirm
;
7279 DTRACE_NFSV4_2(op__open__confirm__start
, struct compound_state
*, cs
,
7280 OPEN_CONFIRM4args
*, args
);
7282 if (cs
->vp
== NULL
) {
7283 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
7287 if (cs
->vp
->v_type
!= VREG
) {
7288 *cs
->statusp
= resp
->status
=
7289 cs
->vp
->v_type
== VDIR
? NFS4ERR_ISDIR
: NFS4ERR_INVAL
;
7293 status
= rfs4_get_state(&args
->open_stateid
, &sp
, RFS4_DBS_VALID
);
7294 if (status
!= NFS4_OK
) {
7295 *cs
->statusp
= resp
->status
= status
;
7299 /* Ensure specified filehandle matches */
7300 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
7301 rfs4_state_rele(sp
);
7302 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7306 /* hold off other access to open_owner while we tinker */
7307 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
7309 switch (rfs4_check_stateid_seqid(sp
, &args
->open_stateid
)) {
7310 case NFS4_CHECK_STATEID_OKAY
:
7311 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7313 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7317 * If it is the appropriate stateid and determined to
7318 * be "OKAY" then this means that the stateid does not
7319 * need to be confirmed and the client is in error for
7320 * sending an OPEN_CONFIRM.
7322 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7324 case NFS4_CHECK_STATEID_OLD
:
7325 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7327 case NFS4_CHECK_STATEID_BAD
:
7328 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7330 case NFS4_CHECK_STATEID_EXPIRED
:
7331 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
7333 case NFS4_CHECK_STATEID_CLOSED
:
7334 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7336 case NFS4_CHECK_STATEID_REPLAY
:
7337 switch (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7339 case NFS4_CHKSEQ_OKAY
:
7341 * This is replayed stateid; if seqid matches
7342 * next expected, then client is using wrong seqid.
7345 case NFS4_CHKSEQ_BAD
:
7346 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7348 case NFS4_CHKSEQ_REPLAY
:
7350 * Note this case is the duplicate case so
7351 * resp->status is already set.
7353 *cs
->statusp
= resp
->status
;
7354 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7358 case NFS4_CHECK_STATEID_UNCONFIRMED
:
7359 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7360 resop
) != NFS4_CHKSEQ_OKAY
) {
7361 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7364 *cs
->statusp
= resp
->status
= NFS4_OK
;
7366 next_stateid(&sp
->rs_stateid
);
7367 resp
->open_stateid
= sp
->rs_stateid
.stateid
;
7368 sp
->rs_owner
->ro_need_confirm
= FALSE
;
7369 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7370 rfs4_update_open_sequence(sp
->rs_owner
);
7371 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
7375 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
7378 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
7379 rfs4_state_rele(sp
);
7382 DTRACE_NFSV4_2(op__open__confirm__done
, struct compound_state
*, cs
,
7383 OPEN_CONFIRM4res
*, resp
);
7388 rfs4_op_open_downgrade(nfs_argop4
*argop
, nfs_resop4
*resop
,
7389 struct svc_req
*req
, struct compound_state
*cs
)
7391 OPEN_DOWNGRADE4args
*args
= &argop
->nfs_argop4_u
.opopen_downgrade
;
7392 OPEN_DOWNGRADE4res
*resp
= &resop
->nfs_resop4_u
.opopen_downgrade
;
7393 uint32_t access
= args
->share_access
;
7394 uint32_t deny
= args
->share_deny
;
7400 DTRACE_NFSV4_2(op__open__downgrade__start
, struct compound_state
*, cs
,
7401 OPEN_DOWNGRADE4args
*, args
);
7403 if (cs
->vp
== NULL
) {
7404 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
7408 if (cs
->vp
->v_type
!= VREG
) {
7409 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7413 status
= rfs4_get_state(&args
->open_stateid
, &sp
, RFS4_DBS_VALID
);
7414 if (status
!= NFS4_OK
) {
7415 *cs
->statusp
= resp
->status
= status
;
7419 /* Ensure specified filehandle matches */
7420 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
7421 rfs4_state_rele(sp
);
7422 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7426 /* hold off other access to open_owner while we tinker */
7427 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
7429 switch (rfs4_check_stateid_seqid(sp
, &args
->open_stateid
)) {
7430 case NFS4_CHECK_STATEID_OKAY
:
7431 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7432 resop
) != NFS4_CHKSEQ_OKAY
) {
7433 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7437 case NFS4_CHECK_STATEID_OLD
:
7438 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7440 case NFS4_CHECK_STATEID_BAD
:
7441 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7443 case NFS4_CHECK_STATEID_EXPIRED
:
7444 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
7446 case NFS4_CHECK_STATEID_CLOSED
:
7447 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
7449 case NFS4_CHECK_STATEID_UNCONFIRMED
:
7450 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7452 case NFS4_CHECK_STATEID_REPLAY
:
7453 /* Check the sequence id for the open owner */
7454 switch (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7456 case NFS4_CHKSEQ_OKAY
:
7458 * This is replayed stateid; if seqid matches
7459 * next expected, then client is using wrong seqid.
7462 case NFS4_CHKSEQ_BAD
:
7463 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
7465 case NFS4_CHKSEQ_REPLAY
:
7467 * Note this case is the duplicate case so
7468 * resp->status is already set.
7470 *cs
->statusp
= resp
->status
;
7471 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7480 rfs4_dbe_lock(sp
->rs_dbe
);
7482 * Check that the new access modes and deny modes are valid.
7483 * Check that no invalid bits are set.
7485 if ((access
& ~(OPEN4_SHARE_ACCESS_READ
| OPEN4_SHARE_ACCESS_WRITE
)) ||
7486 (deny
& ~(OPEN4_SHARE_DENY_READ
| OPEN4_SHARE_DENY_WRITE
))) {
7487 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7488 rfs4_update_open_sequence(sp
->rs_owner
);
7489 rfs4_dbe_unlock(sp
->rs_dbe
);
7494 * The new modes must be a subset of the current modes and
7495 * the access must specify at least one mode. To test that
7496 * the new mode is a subset of the current modes we bitwise
7497 * AND them together and check that the result equals the new
7498 * mode. For example:
7499 * New mode, access == R and current mode, sp->rs_open_access == RW
7500 * access & sp->rs_open_access == R == access, so the new access mode
7501 * is valid. Consider access == RW, sp->rs_open_access = R
7502 * access & sp->rs_open_access == R != access, so the new access mode
7505 if ((access
& sp
->rs_open_access
) != access
||
7506 (deny
& sp
->rs_open_deny
) != deny
||
7508 (OPEN4_SHARE_ACCESS_READ
| OPEN4_SHARE_ACCESS_WRITE
)) == 0) {
7509 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
7510 rfs4_update_open_sequence(sp
->rs_owner
);
7511 rfs4_dbe_unlock(sp
->rs_dbe
);
7516 * Release any share locks associated with this stateID.
7517 * Strictly speaking, this violates the spec because the
7518 * spec effectively requires that open downgrade be atomic.
7519 * At present, fs_shrlock does not have this capability.
7521 (void) rfs4_unshare(sp
);
7523 status
= rfs4_share(sp
, access
, deny
);
7524 if (status
!= NFS4_OK
) {
7525 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
7526 rfs4_update_open_sequence(sp
->rs_owner
);
7527 rfs4_dbe_unlock(sp
->rs_dbe
);
7532 rfs4_dbe_lock(fp
->rf_dbe
);
7535 * If the current mode has deny read and the new mode
7536 * does not, decrement the number of deny read mode bits
7537 * and if it goes to zero turn off the deny read bit
7540 if ((sp
->rs_open_deny
& OPEN4_SHARE_DENY_READ
) &&
7541 (deny
& OPEN4_SHARE_DENY_READ
) == 0) {
7543 if (fp
->rf_deny_read
== 0)
7544 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_READ
;
7548 * If the current mode has deny write and the new mode
7549 * does not, decrement the number of deny write mode bits
7550 * and if it goes to zero turn off the deny write bit
7553 if ((sp
->rs_open_deny
& OPEN4_SHARE_DENY_WRITE
) &&
7554 (deny
& OPEN4_SHARE_DENY_WRITE
) == 0) {
7555 fp
->rf_deny_write
--;
7556 if (fp
->rf_deny_write
== 0)
7557 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_WRITE
;
7561 * If the current mode has access read and the new mode
7562 * does not, decrement the number of access read mode bits
7563 * and if it goes to zero turn off the access read bit
7564 * on the file. set fflags to FREAD for the call to
7565 * vn_open_downgrade().
7567 if ((sp
->rs_open_access
& OPEN4_SHARE_ACCESS_READ
) &&
7568 (access
& OPEN4_SHARE_ACCESS_READ
) == 0) {
7569 fp
->rf_access_read
--;
7570 if (fp
->rf_access_read
== 0)
7571 fp
->rf_share_access
&= ~OPEN4_SHARE_ACCESS_READ
;
7576 * If the current mode has access write and the new mode
7577 * does not, decrement the number of access write mode bits
7578 * and if it goes to zero turn off the access write bit
7579 * on the file. set fflags to FWRITE for the call to
7580 * vn_open_downgrade().
7582 if ((sp
->rs_open_access
& OPEN4_SHARE_ACCESS_WRITE
) &&
7583 (access
& OPEN4_SHARE_ACCESS_WRITE
) == 0) {
7584 fp
->rf_access_write
--;
7585 if (fp
->rf_access_write
== 0)
7586 fp
->rf_share_deny
&= ~OPEN4_SHARE_ACCESS_WRITE
;
7590 /* Check that the file is still accessible */
7591 ASSERT(fp
->rf_share_access
);
7593 rfs4_dbe_unlock(fp
->rf_dbe
);
7595 /* now set the new open access and deny modes */
7596 sp
->rs_open_access
= access
;
7597 sp
->rs_open_deny
= deny
;
7600 * we successfully downgraded the share lock, now we need to downgrade
7601 * the open. it is possible that the downgrade was only for a deny
7602 * mode and we have nothing else to do.
7604 if ((fflags
& (FREAD
|FWRITE
)) != 0)
7605 vn_open_downgrade(cs
->vp
, fflags
);
7607 /* Update the stateid */
7608 next_stateid(&sp
->rs_stateid
);
7609 resp
->open_stateid
= sp
->rs_stateid
.stateid
;
7611 rfs4_dbe_unlock(sp
->rs_dbe
);
7613 *cs
->statusp
= resp
->status
= NFS4_OK
;
7614 /* Update the lease */
7615 rfs4_update_lease(sp
->rs_owner
->ro_client
);
7616 /* And the sequence */
7617 rfs4_update_open_sequence(sp
->rs_owner
);
7618 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
7621 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
7622 rfs4_state_rele(sp
);
7624 DTRACE_NFSV4_2(op__open__downgrade__done
, struct compound_state
*, cs
,
7625 OPEN_DOWNGRADE4res
*, resp
);
7629 memstr(const void *s1
, const char *s2
, size_t n
)
7631 size_t l
= strlen(s2
);
7632 char *p
= (char *)s1
;
7635 if (bcmp(p
, s2
, l
) == 0)
7645 * The logic behind this function is detailed in the NFSv4 RFC in the
7646 * SETCLIENTID operation description under IMPLEMENTATION. Refer to
7647 * that section for explicit guidance to server behavior for
7651 rfs4_op_setclientid(nfs_argop4
*argop
, nfs_resop4
*resop
,
7652 struct svc_req
*req
, struct compound_state
*cs
)
7654 SETCLIENTID4args
*args
= &argop
->nfs_argop4_u
.opsetclientid
;
7655 SETCLIENTID4res
*res
= &resop
->nfs_resop4_u
.opsetclientid
;
7656 rfs4_client_t
*cp
, *newcp
, *cp_confirmed
, *cp_unconfirmed
;
7662 DTRACE_NFSV4_2(op__setclientid__start
, struct compound_state
*, cs
,
7663 SETCLIENTID4args
*, args
);
7665 newcp
= cp_confirmed
= cp_unconfirmed
= NULL
;
7668 * Save the caller's IP address
7670 args
->client
.cl_addr
=
7671 (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
7674 * Record if it is a Solaris client that cannot handle referrals.
7676 if (memstr(args
->client
.id_val
, "Solaris", args
->client
.id_len
) &&
7677 !memstr(args
->client
.id_val
, "+referrals", args
->client
.id_len
)) {
7678 /* Add a "yes, it's downrev" record */
7680 ci
= rfs4_find_clntip(args
->client
.cl_addr
, &create
);
7682 rfs4_dbe_rele(ci
->ri_dbe
);
7684 /* Remove any previous record */
7685 rfs4_invalidate_clntip(args
->client
.cl_addr
);
7689 * In search of an EXISTING client matching the incoming
7690 * request to establish a new client identifier at the server
7693 cp
= rfs4_findclient(&args
->client
, &create
, NULL
);
7695 /* Should never happen */
7699 *cs
->statusp
= res
->status
= NFS4ERR_SERVERFAULT
;
7704 * Easiest case. Client identifier is newly created and is
7705 * unconfirmed. Also note that for this case, no other
7706 * entries exist for the client identifier. Nothing else to
7707 * check. Just setup the response and respond.
7710 *cs
->statusp
= res
->status
= NFS4_OK
;
7711 res
->SETCLIENTID4res_u
.resok4
.clientid
= cp
->rc_clientid
;
7712 res
->SETCLIENTID4res_u
.resok4
.setclientid_confirm
=
7713 cp
->rc_confirm_verf
;
7714 /* Setup callback information; CB_NULL confirmation later */
7715 rfs4_client_setcb(cp
, &args
->callback
, args
->callback_ident
);
7717 rfs4_client_rele(cp
);
7722 * An existing, confirmed client may exist but it may not have
7723 * been active for at least one lease period. If so, then
7724 * "close" the client and create a new client identifier
7726 if (rfs4_lease_expired(cp
)) {
7727 rfs4_client_close(cp
);
7731 if (cp
->rc_need_confirm
== TRUE
)
7732 cp_unconfirmed
= cp
;
7739 * We have a confirmed client, now check for an
7743 /* If creds don't match then client identifier is inuse */
7744 if (!creds_ok(cp_confirmed
->rc_cr_set
, req
, cs
)) {
7747 * Some one else has established this client
7748 * id. Try and say * who they are. We will use
7749 * the call back address supplied by * the
7752 *cs
->statusp
= res
->status
= NFS4ERR_CLID_INUSE
;
7754 addr
= netid
= NULL
;
7756 cbp
= &cp_confirmed
->rc_cbinfo
;
7757 if (cbp
->cb_callback
.cb_location
.r_addr
&&
7758 cbp
->cb_callback
.cb_location
.r_netid
) {
7759 cb_client4
*cbcp
= &cbp
->cb_callback
;
7761 len
= strlen(cbcp
->cb_location
.r_addr
)+1;
7762 addr
= kmem_alloc(len
, KM_SLEEP
);
7763 bcopy(cbcp
->cb_location
.r_addr
, addr
, len
);
7764 len
= strlen(cbcp
->cb_location
.r_netid
)+1;
7765 netid
= kmem_alloc(len
, KM_SLEEP
);
7766 bcopy(cbcp
->cb_location
.r_netid
, netid
, len
);
7769 res
->SETCLIENTID4res_u
.client_using
.r_addr
= addr
;
7770 res
->SETCLIENTID4res_u
.client_using
.r_netid
= netid
;
7772 rfs4_client_rele(cp_confirmed
);
7776 * Confirmed, creds match, and verifier matches; must
7777 * be an update of the callback info
7779 if (cp_confirmed
->rc_nfs_client
.verifier
==
7780 args
->client
.verifier
) {
7781 /* Setup callback information */
7782 rfs4_client_setcb(cp_confirmed
, &args
->callback
,
7783 args
->callback_ident
);
7785 /* everything okay -- move ahead */
7786 *cs
->statusp
= res
->status
= NFS4_OK
;
7787 res
->SETCLIENTID4res_u
.resok4
.clientid
=
7788 cp_confirmed
->rc_clientid
;
7790 /* update the confirm_verifier and return it */
7791 rfs4_client_scv_next(cp_confirmed
);
7792 res
->SETCLIENTID4res_u
.resok4
.setclientid_confirm
=
7793 cp_confirmed
->rc_confirm_verf
;
7795 rfs4_client_rele(cp_confirmed
);
7800 * Creds match but the verifier doesn't. Must search
7801 * for an unconfirmed client that would be replaced by
7805 cp_unconfirmed
= rfs4_findclient(&args
->client
, &create
,
7810 * At this point, we have taken care of the brand new client
7811 * struct, INUSE case, update of an existing, and confirmed
7816 * check to see if things have changed while we originally
7817 * picked up the client struct. If they have, then return and
7818 * retry the processing of this SETCLIENTID request.
7820 if (cp_unconfirmed
) {
7821 rfs4_dbe_lock(cp_unconfirmed
->rc_dbe
);
7822 if (!cp_unconfirmed
->rc_need_confirm
) {
7823 rfs4_dbe_unlock(cp_unconfirmed
->rc_dbe
);
7824 rfs4_client_rele(cp_unconfirmed
);
7826 rfs4_client_rele(cp_confirmed
);
7829 /* do away with the old unconfirmed one */
7830 rfs4_dbe_invalidate(cp_unconfirmed
->rc_dbe
);
7831 rfs4_dbe_unlock(cp_unconfirmed
->rc_dbe
);
7832 rfs4_client_rele(cp_unconfirmed
);
7833 cp_unconfirmed
= NULL
;
7837 * This search will temporarily hide the confirmed client
7838 * struct while a new client struct is created as the
7842 newcp
= rfs4_findclient(&args
->client
, &create
, cp_confirmed
);
7844 ASSERT(newcp
!= NULL
);
7846 if (newcp
== NULL
) {
7847 *cs
->statusp
= res
->status
= NFS4ERR_SERVERFAULT
;
7848 rfs4_client_rele(cp_confirmed
);
7853 * If one was not created, then a similar request must be in
7854 * process so release and start over with this one
7856 if (create
!= TRUE
) {
7857 rfs4_client_rele(newcp
);
7859 rfs4_client_rele(cp_confirmed
);
7863 *cs
->statusp
= res
->status
= NFS4_OK
;
7864 res
->SETCLIENTID4res_u
.resok4
.clientid
= newcp
->rc_clientid
;
7865 res
->SETCLIENTID4res_u
.resok4
.setclientid_confirm
=
7866 newcp
->rc_confirm_verf
;
7867 /* Setup callback information; CB_NULL confirmation later */
7868 rfs4_client_setcb(newcp
, &args
->callback
, args
->callback_ident
);
7870 newcp
->rc_cp_confirmed
= cp_confirmed
;
7872 rfs4_client_rele(newcp
);
7875 DTRACE_NFSV4_2(op__setclientid__done
, struct compound_state
*, cs
,
7876 SETCLIENTID4res
*, res
);
7881 rfs4_op_setclientid_confirm(nfs_argop4
*argop
, nfs_resop4
*resop
,
7882 struct svc_req
*req
, struct compound_state
*cs
)
7884 SETCLIENTID_CONFIRM4args
*args
=
7885 &argop
->nfs_argop4_u
.opsetclientid_confirm
;
7886 SETCLIENTID_CONFIRM4res
*res
=
7887 &resop
->nfs_resop4_u
.opsetclientid_confirm
;
7888 rfs4_client_t
*cp
, *cptoclose
= NULL
;
7890 DTRACE_NFSV4_2(op__setclientid__confirm__start
,
7891 struct compound_state
*, cs
,
7892 SETCLIENTID_CONFIRM4args
*, args
);
7894 *cs
->statusp
= res
->status
= NFS4_OK
;
7896 cp
= rfs4_findclient_by_id(args
->clientid
, TRUE
);
7899 *cs
->statusp
= res
->status
=
7900 rfs4_check_clientid(&args
->clientid
, 1);
7904 if (!creds_ok(cp
, req
, cs
)) {
7905 *cs
->statusp
= res
->status
= NFS4ERR_CLID_INUSE
;
7906 rfs4_client_rele(cp
);
7910 /* If the verifier doesn't match, the record doesn't match */
7911 if (cp
->rc_confirm_verf
!= args
->setclientid_confirm
) {
7912 *cs
->statusp
= res
->status
= NFS4ERR_STALE_CLIENTID
;
7913 rfs4_client_rele(cp
);
7917 rfs4_dbe_lock(cp
->rc_dbe
);
7918 cp
->rc_need_confirm
= FALSE
;
7919 if (cp
->rc_cp_confirmed
) {
7920 cptoclose
= cp
->rc_cp_confirmed
;
7921 cptoclose
->rc_ss_remove
= 1;
7922 cp
->rc_cp_confirmed
= NULL
;
7926 * Update the client's associated server instance, if it's changed
7927 * since the client was created.
7929 if (rfs4_servinst(cp
) != rfs4_cur_servinst
)
7930 rfs4_servinst_assign(cp
, rfs4_cur_servinst
);
7933 * Record clientid in stable storage.
7934 * Must be done after server instance has been assigned.
7938 rfs4_dbe_unlock(cp
->rc_dbe
);
7941 /* don't need to rele, client_close does it */
7942 rfs4_client_close(cptoclose
);
7944 /* If needed, initiate CB_NULL call for callback path */
7945 rfs4_deleg_cb_check(cp
);
7946 rfs4_update_lease(cp
);
7949 * Check to see if client can perform reclaims
7951 rfs4_ss_chkclid(cp
);
7953 rfs4_client_rele(cp
);
7956 DTRACE_NFSV4_2(op__setclientid__confirm__done
,
7957 struct compound_state
*, cs
,
7958 SETCLIENTID_CONFIRM4
*, res
);
7964 rfs4_op_close(nfs_argop4
*argop
, nfs_resop4
*resop
,
7965 struct svc_req
*req
, struct compound_state
*cs
)
7967 CLOSE4args
*args
= &argop
->nfs_argop4_u
.opclose
;
7968 CLOSE4res
*resp
= &resop
->nfs_resop4_u
.opclose
;
7972 DTRACE_NFSV4_2(op__close__start
, struct compound_state
*, cs
,
7973 CLOSE4args
*, args
);
7975 if (cs
->vp
== NULL
) {
7976 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
7980 status
= rfs4_get_state(&args
->open_stateid
, &sp
, RFS4_DBS_INVALID
);
7981 if (status
!= NFS4_OK
) {
7982 *cs
->statusp
= resp
->status
= status
;
7986 /* Ensure specified filehandle matches */
7987 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
7988 rfs4_state_rele(sp
);
7989 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
7993 /* hold off other access to open_owner while we tinker */
7994 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
7996 switch (rfs4_check_stateid_seqid(sp
, &args
->open_stateid
)) {
7997 case NFS4_CHECK_STATEID_OKAY
:
7998 if (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
7999 resop
) != NFS4_CHKSEQ_OKAY
) {
8000 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8004 case NFS4_CHECK_STATEID_OLD
:
8005 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8007 case NFS4_CHECK_STATEID_BAD
:
8008 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8010 case NFS4_CHECK_STATEID_EXPIRED
:
8011 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
8013 case NFS4_CHECK_STATEID_CLOSED
:
8014 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8016 case NFS4_CHECK_STATEID_UNCONFIRMED
:
8017 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8019 case NFS4_CHECK_STATEID_REPLAY
:
8020 /* Check the sequence id for the open owner */
8021 switch (rfs4_check_open_seqid(args
->seqid
, sp
->rs_owner
,
8023 case NFS4_CHKSEQ_OKAY
:
8025 * This is replayed stateid; if seqid matches
8026 * next expected, then client is using wrong seqid.
8029 case NFS4_CHKSEQ_BAD
:
8030 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8032 case NFS4_CHKSEQ_REPLAY
:
8034 * Note this case is the duplicate case so
8035 * resp->status is already set.
8037 *cs
->statusp
= resp
->status
;
8038 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8047 rfs4_dbe_lock(sp
->rs_dbe
);
8049 /* Update the stateid. */
8050 next_stateid(&sp
->rs_stateid
);
8051 resp
->open_stateid
= sp
->rs_stateid
.stateid
;
8053 rfs4_dbe_unlock(sp
->rs_dbe
);
8055 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8056 rfs4_update_open_sequence(sp
->rs_owner
);
8057 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
8059 rfs4_state_close(sp
, FALSE
, FALSE
, cs
->cr
);
8061 *cs
->statusp
= resp
->status
= status
;
8064 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
8065 rfs4_state_rele(sp
);
8067 DTRACE_NFSV4_2(op__close__done
, struct compound_state
*, cs
,
8072 * Manage the counts on the file struct and close all file locks
8076 rfs4_release_share_lock_state(rfs4_state_t
*sp
, cred_t
*cr
,
8077 bool_t close_of_client
)
8079 rfs4_file_t
*fp
= sp
->rs_finfo
;
8080 rfs4_lo_state_t
*lsp
;
8084 * If this call is part of the larger closing down of client
8085 * state then it is just easier to release all locks
8086 * associated with this client instead of going through each
8087 * individual file and cleaning locks there.
8089 if (close_of_client
) {
8090 if (sp
->rs_owner
->ro_client
->rc_unlksys_completed
== FALSE
&&
8091 !list_is_empty(&sp
->rs_lostatelist
) &&
8092 sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
) {
8093 /* Is the PxFS kernel module loaded? */
8094 if (lm_remove_file_locks
!= NULL
) {
8097 /* Encode the cluster nodeid in new sysid */
8098 new_sysid
= sp
->rs_owner
->ro_client
->rc_sysidt
;
8099 lm_set_nlmid_flk(&new_sysid
);
8102 * This PxFS routine removes file locks for a
8103 * client over all nodes of a cluster.
8105 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
,
8106 "lm_remove_file_locks(sysid=0x%x)\n",
8108 (*lm_remove_file_locks
)(new_sysid
);
8112 /* Release all locks for this client */
8113 flk
.l_type
= F_UNLKSYS
;
8118 sp
->rs_owner
->ro_client
->rc_sysidt
;
8120 (void) fop_frlock(sp
->rs_finfo
->rf_vp
, F_SETLK
,
8121 &flk
, F_REMOTELOCK
| FREAD
| FWRITE
,
8122 0, NULL
, CRED(), NULL
);
8125 sp
->rs_owner
->ro_client
->rc_unlksys_completed
= TRUE
;
8130 * Release all locks on this file by this lock owner or at
8131 * least mark the locks as having been released
8133 for (lsp
= list_head(&sp
->rs_lostatelist
); lsp
!= NULL
;
8134 lsp
= list_next(&sp
->rs_lostatelist
, lsp
)) {
8135 lsp
->rls_locks_cleaned
= TRUE
;
8137 /* Was this already taken care of above? */
8138 if (!close_of_client
&&
8139 sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
)
8140 (void) cleanlocks(sp
->rs_finfo
->rf_vp
,
8141 lsp
->rls_locker
->rl_pid
,
8142 lsp
->rls_locker
->rl_client
->rc_sysidt
);
8146 * Release any shrlocks associated with this open state ID.
8147 * This must be done before the rfs4_state gets marked closed.
8149 if (sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
)
8150 (void) rfs4_unshare(sp
);
8152 if (sp
->rs_open_access
) {
8153 rfs4_dbe_lock(fp
->rf_dbe
);
8156 * Decrement the count for each access and deny bit that this
8157 * state has contributed to the file.
8158 * If the file counts go to zero
8159 * clear the appropriate bit in the appropriate mask.
8161 if (sp
->rs_open_access
& OPEN4_SHARE_ACCESS_READ
) {
8162 fp
->rf_access_read
--;
8164 if (fp
->rf_access_read
== 0)
8165 fp
->rf_share_access
&= ~OPEN4_SHARE_ACCESS_READ
;
8167 if (sp
->rs_open_access
& OPEN4_SHARE_ACCESS_WRITE
) {
8168 fp
->rf_access_write
--;
8170 if (fp
->rf_access_write
== 0)
8171 fp
->rf_share_access
&=
8172 ~OPEN4_SHARE_ACCESS_WRITE
;
8174 if (sp
->rs_open_deny
& OPEN4_SHARE_DENY_READ
) {
8176 if (fp
->rf_deny_read
== 0)
8177 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_READ
;
8179 if (sp
->rs_open_deny
& OPEN4_SHARE_DENY_WRITE
) {
8180 fp
->rf_deny_write
--;
8181 if (fp
->rf_deny_write
== 0)
8182 fp
->rf_share_deny
&= ~OPEN4_SHARE_DENY_WRITE
;
8185 (void) fop_close(fp
->rf_vp
, fflags
, 1, 0, cr
, NULL
);
8187 rfs4_dbe_unlock(fp
->rf_dbe
);
8189 sp
->rs_open_access
= 0;
8190 sp
->rs_open_deny
= 0;
8195 * lock_denied: Fill in a LOCK4deneid structure given an flock64 structure.
8198 lock_denied(LOCK4denied
*dp
, struct flock64
*flk
)
8200 rfs4_lockowner_t
*lo
;
8204 lo
= rfs4_findlockowner_by_pid(flk
->l_pid
);
8207 if (rfs4_lease_expired(cp
)) {
8208 rfs4_lockowner_rele(lo
);
8209 rfs4_dbe_hold(cp
->rc_dbe
);
8210 rfs4_client_close(cp
);
8211 return (NFS4ERR_EXPIRED
);
8213 dp
->owner
.clientid
= lo
->rl_owner
.clientid
;
8214 len
= lo
->rl_owner
.owner_len
;
8215 dp
->owner
.owner_val
= kmem_alloc(len
, KM_SLEEP
);
8216 bcopy(lo
->rl_owner
.owner_val
, dp
->owner
.owner_val
, len
);
8217 dp
->owner
.owner_len
= len
;
8218 rfs4_lockowner_rele(lo
);
8223 * Its not a NFS4 lock. We take advantage that the upper 32 bits
8224 * of the client id contain the boot time for a NFS4 lock. So we
8225 * fabricate and identity by setting clientid to the sysid, and
8226 * the lock owner to the pid.
8228 dp
->owner
.clientid
= flk
->l_sysid
;
8229 len
= sizeof (pid_t
);
8230 dp
->owner
.owner_len
= len
;
8231 dp
->owner
.owner_val
= kmem_alloc(len
, KM_SLEEP
);
8232 bcopy(&flk
->l_pid
, dp
->owner
.owner_val
, len
);
8234 dp
->offset
= flk
->l_start
;
8235 dp
->length
= flk
->l_len
;
8237 if (flk
->l_type
== F_RDLCK
)
8238 dp
->locktype
= READ_LT
;
8239 else if (flk
->l_type
== F_WRLCK
)
8240 dp
->locktype
= WRITE_LT
;
8242 return (NFS4ERR_INVAL
); /* no mapping from POSIX ltype to v4 */
8248 * The NFSv4.0 LOCK operation does not support the blocking lock (at the
8249 * NFSv4.0 protocol level) so the client needs to resend the LOCK request in a
8250 * case the lock is denied by the NFSv4.0 server. NFSv4.0 clients are prepared
8251 * for that (obviously); they are sending the LOCK requests with some delays
8252 * between the attempts. See nfs4frlock() and nfs4_block_and_wait() for the
8253 * locking and delay implementation at the client side.
8255 * To make the life of the clients easier, the NFSv4.0 server tries to do some
8256 * fast retries on its own (the for loop below) in a hope the lock will be
8257 * available soon. And if not, the client won't need to resend the LOCK
8258 * requests so fast to check the lock availability. This basically saves some
8259 * network traffic and tries to make sure the client gets the lock ASAP.
8262 setlock(vnode_t
*vp
, struct flock64
*flock
, int flag
, cred_t
*cred
)
8271 cmd
= nbl_need_check(vp
) ? F_SETLK_NBMAND
: F_SETLK
;
8273 delaytime
= MSEC_TO_TICK_ROUNDUP(rfs4_lock_delay
);
8275 for (i
= 0; i
< rfs4_maxlock_tries
; i
++) {
8276 LOCK_PRINT(rfs4_debug
, "setlock", cmd
, flock
);
8277 error
= fop_frlock(vp
, cmd
,
8278 flock
, flag
, 0, NULL
, cred
, NULL
);
8280 if (error
!= EAGAIN
&& error
!= EACCES
)
8283 if (i
< rfs4_maxlock_tries
- 1) {
8289 if (error
== EAGAIN
|| error
== EACCES
) {
8290 /* Get the owner of the lock */
8292 LOCK_PRINT(rfs4_debug
, "setlock", F_GETLK
, &flk
);
8293 if (fop_frlock(vp
, F_GETLK
, &flk
, flag
, 0, NULL
, cred
,
8296 * There's a race inherent in the current fop_frlock
8298 * a: "other guy" takes a lock that conflicts with a
8300 * b: we attempt to take our lock (non-blocking) and
8301 * the attempt fails.
8302 * c: "other guy" releases the conflicting lock
8303 * d: we ask what lock conflicts with the lock we want,
8304 * getting F_UNLCK (no lock blocks us)
8306 * If we retry the non-blocking lock attempt in this
8307 * case (restart at step 'b') there's some possibility
8308 * that many such attempts might fail. However a test
8309 * designed to actually provoke this race shows that
8310 * the vast majority of cases require no retry, and
8311 * only a few took as many as three retries. Here's
8314 * number of retries how many times we needed
8321 * Given those empirical results, we arbitrarily limit
8322 * the retry count to ten.
8324 * If we actually make to ten retries and give up,
8325 * nothing catastrophic happens, but we're unable to
8326 * return the information about the conflicting lock to
8327 * the NFS client. That's an acceptable trade off vs.
8328 * letting this retry loop run forever.
8330 if (flk
.l_type
== F_UNLCK
) {
8331 if (spin_cnt
++ < 10) {
8332 /* No longer locked, retry */
8337 LOCK_PRINT(rfs4_debug
, "setlock(blocking lock)",
8348 rfs4_do_lock(rfs4_lo_state_t
*lsp
, nfs_lock_type4 locktype
,
8349 offset4 offset
, length4 length
, cred_t
*cred
, nfs_resop4
*resop
)
8352 rfs4_lockowner_t
*lo
= lsp
->rls_locker
;
8353 rfs4_state_t
*sp
= lsp
->rls_state
;
8354 struct flock64 flock
;
8362 if (rfs4_lease_expired(lo
->rl_client
)) {
8363 return (NFS4ERR_EXPIRED
);
8366 if ((status
= rfs4_client_sysid(lo
->rl_client
, &sysid
)) != NFS4_OK
)
8369 /* Check for zero length. To lock to end of file use all ones for V4 */
8371 return (NFS4ERR_INVAL
);
8372 else if (length
== (length4
)(~0))
8373 length
= 0; /* Posix to end of file */
8376 rfs4_dbe_lock(sp
->rs_dbe
);
8377 if (sp
->rs_closed
== TRUE
) {
8378 rfs4_dbe_unlock(sp
->rs_dbe
);
8379 return (NFS4ERR_OLD_STATEID
);
8382 if (resop
->resop
!= OP_LOCKU
) {
8386 if ((sp
->rs_share_access
8387 & OPEN4_SHARE_ACCESS_READ
) == 0) {
8388 rfs4_dbe_unlock(sp
->rs_dbe
);
8390 return (NFS4ERR_OPENMODE
);
8396 if ((sp
->rs_share_access
8397 & OPEN4_SHARE_ACCESS_WRITE
) == 0) {
8398 rfs4_dbe_unlock(sp
->rs_dbe
);
8400 return (NFS4ERR_OPENMODE
);
8408 flock
.l_type
= ltype
;
8409 flock
.l_whence
= 0; /* SEEK_SET */
8410 flock
.l_start
= offset
;
8411 flock
.l_len
= length
;
8412 flock
.l_sysid
= sysid
;
8413 flock
.l_pid
= lsp
->rls_locker
->rl_pid
;
8415 /* Note that length4 is uint64_t but l_len and l_start are off64_t */
8416 if (flock
.l_len
< 0 || flock
.l_start
< 0) {
8417 rfs4_dbe_unlock(sp
->rs_dbe
);
8418 return (NFS4ERR_INVAL
);
8422 * N.B. FREAD has the same value as OPEN4_SHARE_ACCESS_READ and
8423 * FWRITE has the same value as OPEN4_SHARE_ACCESS_WRITE.
8425 flag
= (int)sp
->rs_share_access
| F_REMOTELOCK
;
8427 vp
= sp
->rs_finfo
->rf_vp
;
8431 * We need to unlock sp before we call the underlying filesystem to
8432 * acquire the file lock.
8434 rfs4_dbe_unlock(sp
->rs_dbe
);
8436 error
= setlock(vp
, &flock
, flag
, cred
);
8439 * Make sure the file is still open. In a case the file was closed in
8440 * the meantime, clean the lock we acquired using the setlock() call
8441 * above, and return the appropriate error.
8443 rfs4_dbe_lock(sp
->rs_dbe
);
8444 if (sp
->rs_closed
== TRUE
) {
8445 cleanlocks(vp
, lsp
->rls_locker
->rl_pid
, sysid
);
8446 rfs4_dbe_unlock(sp
->rs_dbe
);
8450 return (NFS4ERR_OLD_STATEID
);
8452 rfs4_dbe_unlock(sp
->rs_dbe
);
8457 rfs4_dbe_lock(lsp
->rls_dbe
);
8458 next_stateid(&lsp
->rls_lockid
);
8459 rfs4_dbe_unlock(lsp
->rls_dbe
);
8463 * N.B. We map error values to nfsv4 errors. This is differrent
8464 * than puterrno4 routine.
8471 case EACCES
: /* Old value */
8472 /* Can only get here if op is OP_LOCK */
8473 ASSERT(resop
->resop
== OP_LOCK
);
8474 lres
= &resop
->nfs_resop4_u
.oplock
;
8475 status
= NFS4ERR_DENIED
;
8476 if (lock_denied(&lres
->LOCK4res_u
.denied
, &flock
)
8481 status
= NFS4ERR_DELAY
;
8484 status
= NFS4ERR_INVAL
;
8487 status
= NFS4ERR_NOTSUPP
;
8490 status
= NFS4ERR_SERVERFAULT
;
8499 rfs4_op_lock(nfs_argop4
*argop
, nfs_resop4
*resop
,
8500 struct svc_req
*req
, struct compound_state
*cs
)
8502 LOCK4args
*args
= &argop
->nfs_argop4_u
.oplock
;
8503 LOCK4res
*resp
= &resop
->nfs_resop4_u
.oplock
;
8506 rfs4_lockowner_t
*lo
;
8508 rfs4_state_t
*sp
= NULL
;
8509 rfs4_lo_state_t
*lsp
= NULL
;
8510 bool_t ls_sw_held
= FALSE
;
8511 bool_t create
= TRUE
;
8512 bool_t lcreate
= TRUE
;
8513 bool_t dup_lock
= FALSE
;
8516 DTRACE_NFSV4_2(op__lock__start
, struct compound_state
*, cs
,
8519 if (cs
->vp
== NULL
) {
8520 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
8521 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8522 cs
, LOCK4res
*, resp
);
8526 if (args
->locker
.new_lock_owner
) {
8527 /* Create a new lockowner for this instance */
8528 open_to_lock_owner4
*olo
= &args
->locker
.locker4_u
.open_owner
;
8530 NFS4_DEBUG(rfs4_debug
, (CE_NOTE
, "Creating new lock owner"));
8532 stateid
= &olo
->open_stateid
;
8533 status
= rfs4_get_state(stateid
, &sp
, RFS4_DBS_VALID
);
8534 if (status
!= NFS4_OK
) {
8535 NFS4_DEBUG(rfs4_debug
,
8536 (CE_NOTE
, "Get state failed in lock %d", status
));
8537 *cs
->statusp
= resp
->status
= status
;
8538 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8539 cs
, LOCK4res
*, resp
);
8543 /* Ensure specified filehandle matches */
8544 if (cs
->vp
!= sp
->rs_finfo
->rf_vp
) {
8545 rfs4_state_rele(sp
);
8546 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8547 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8548 cs
, LOCK4res
*, resp
);
8552 /* hold off other access to open_owner while we tinker */
8553 rfs4_sw_enter(&sp
->rs_owner
->ro_sw
);
8555 switch (rc
= rfs4_check_stateid_seqid(sp
, stateid
)) {
8556 case NFS4_CHECK_STATEID_OLD
:
8557 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8559 case NFS4_CHECK_STATEID_BAD
:
8560 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8562 case NFS4_CHECK_STATEID_EXPIRED
:
8563 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
8565 case NFS4_CHECK_STATEID_UNCONFIRMED
:
8566 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8568 case NFS4_CHECK_STATEID_CLOSED
:
8569 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8571 case NFS4_CHECK_STATEID_OKAY
:
8572 case NFS4_CHECK_STATEID_REPLAY
:
8573 switch (rfs4_check_olo_seqid(olo
->open_seqid
,
8574 sp
->rs_owner
, resop
)) {
8575 case NFS4_CHKSEQ_OKAY
:
8576 if (rc
== NFS4_CHECK_STATEID_OKAY
)
8579 * This is replayed stateid; if seqid
8580 * matches next expected, then client
8581 * is using wrong seqid.
8584 case NFS4_CHKSEQ_BAD
:
8585 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8587 case NFS4_CHKSEQ_REPLAY
:
8588 /* This is a duplicate LOCK request */
8592 * For a duplicate we do not want to
8593 * create a new lockowner as it should
8595 * Turn off the lockowner create flag.
8602 lo
= rfs4_findlockowner(&olo
->lock_owner
, &lcreate
);
8604 NFS4_DEBUG(rfs4_debug
,
8605 (CE_NOTE
, "rfs4_op_lock: no lock owner"));
8606 *cs
->statusp
= resp
->status
= NFS4ERR_RESOURCE
;
8610 lsp
= rfs4_findlo_state_by_owner(lo
, sp
, &create
);
8612 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8614 * Only update theh open_seqid if this is not
8615 * a duplicate request
8617 if (dup_lock
== FALSE
) {
8618 rfs4_update_open_sequence(sp
->rs_owner
);
8621 NFS4_DEBUG(rfs4_debug
,
8622 (CE_NOTE
, "rfs4_op_lock: no state"));
8623 *cs
->statusp
= resp
->status
= NFS4ERR_SERVERFAULT
;
8624 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
8625 rfs4_lockowner_rele(lo
);
8630 * This is the new_lock_owner branch and the client is
8631 * supposed to be associating a new lock_owner with
8632 * the open file at this point. If we find that a
8633 * lock_owner/state association already exists and a
8634 * successful LOCK request was returned to the client,
8635 * an error is returned to the client since this is
8636 * not appropriate. The client should be using the
8637 * existing lock_owner branch.
8639 if (dup_lock
== FALSE
&& create
== FALSE
) {
8640 if (lsp
->rls_lock_completed
== TRUE
) {
8642 resp
->status
= NFS4ERR_BAD_SEQID
;
8643 rfs4_lockowner_rele(lo
);
8648 rfs4_update_lease(sp
->rs_owner
->ro_client
);
8651 * Only update theh open_seqid if this is not
8652 * a duplicate request
8654 if (dup_lock
== FALSE
) {
8655 rfs4_update_open_sequence(sp
->rs_owner
);
8659 * If this is a duplicate lock request, just copy the
8660 * previously saved reply and return.
8662 if (dup_lock
== TRUE
) {
8663 /* verify that lock_seqid's match */
8664 if (lsp
->rls_seqid
!= olo
->lock_seqid
) {
8665 NFS4_DEBUG(rfs4_debug
,
8666 (CE_NOTE
, "rfs4_op_lock: Dup-Lock seqid bad"
8667 "lsp->seqid=%d old->seqid=%d",
8668 lsp
->rls_seqid
, olo
->lock_seqid
));
8669 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8671 rfs4_copy_reply(resop
, &lsp
->rls_reply
);
8673 * Make sure to copy the just
8674 * retrieved reply status into the
8675 * overall compound status
8677 *cs
->statusp
= resp
->status
;
8679 rfs4_lockowner_rele(lo
);
8683 rfs4_dbe_lock(lsp
->rls_dbe
);
8685 /* Make sure to update the lock sequence id */
8686 lsp
->rls_seqid
= olo
->lock_seqid
;
8688 NFS4_DEBUG(rfs4_debug
,
8689 (CE_NOTE
, "Lock seqid established as %d", lsp
->rls_seqid
));
8692 * This is used to signify the newly created lockowner
8693 * stateid and its sequence number. The checks for
8694 * sequence number and increment don't occur on the
8695 * very first lock request for a lockowner.
8697 lsp
->rls_skip_seqid_check
= TRUE
;
8699 /* hold off other access to lsp while we tinker */
8700 rfs4_sw_enter(&lsp
->rls_sw
);
8703 rfs4_dbe_unlock(lsp
->rls_dbe
);
8705 rfs4_lockowner_rele(lo
);
8707 stateid
= &args
->locker
.locker4_u
.lock_owner
.lock_stateid
;
8708 /* get lsp and hold the lock on the underlying file struct */
8709 if ((status
= rfs4_get_lo_state(stateid
, &lsp
, TRUE
))
8711 *cs
->statusp
= resp
->status
= status
;
8712 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8713 cs
, LOCK4res
*, resp
);
8716 create
= FALSE
; /* We didn't create lsp */
8718 /* Ensure specified filehandle matches */
8719 if (cs
->vp
!= lsp
->rls_state
->rs_finfo
->rf_vp
) {
8720 rfs4_lo_state_rele(lsp
, TRUE
);
8721 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8722 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*,
8723 cs
, LOCK4res
*, resp
);
8727 /* hold off other access to lsp while we tinker */
8728 rfs4_sw_enter(&lsp
->rls_sw
);
8731 switch (rfs4_check_lo_stateid_seqid(lsp
, stateid
)) {
8733 * The stateid looks like it was okay (expected to be
8736 case NFS4_CHECK_STATEID_OKAY
:
8738 * The sequence id is now checked. Determine
8739 * if this is a replay or if it is in the
8740 * expected (next) sequence. In the case of a
8741 * replay, there are two replay conditions
8742 * that may occur. The first is the normal
8743 * condition where a LOCK is done with a
8744 * NFS4_OK response and the stateid is
8745 * updated. That case is handled below when
8746 * the stateid is identified as a REPLAY. The
8747 * second is the case where an error is
8748 * returned, like NFS4ERR_DENIED, and the
8749 * sequence number is updated but the stateid
8750 * is not updated. This second case is dealt
8751 * with here. So it may seem odd that the
8752 * stateid is okay but the sequence id is a
8753 * replay but it is okay.
8755 switch (rfs4_check_lock_seqid(
8756 args
->locker
.locker4_u
.lock_owner
.lock_seqid
,
8758 case NFS4_CHKSEQ_REPLAY
:
8759 if (resp
->status
!= NFS4_OK
) {
8761 * Here is our replay and need
8762 * to verify that the last
8763 * response was an error.
8765 *cs
->statusp
= resp
->status
;
8769 * This is done since the sequence id
8770 * looked like a replay but it didn't
8771 * pass our check so a BAD_SEQID is
8772 * returned as a result.
8775 case NFS4_CHKSEQ_BAD
:
8776 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8778 case NFS4_CHKSEQ_OKAY
:
8779 /* Everything looks okay move ahead */
8783 case NFS4_CHECK_STATEID_OLD
:
8784 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8786 case NFS4_CHECK_STATEID_BAD
:
8787 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8789 case NFS4_CHECK_STATEID_EXPIRED
:
8790 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
8792 case NFS4_CHECK_STATEID_CLOSED
:
8793 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8795 case NFS4_CHECK_STATEID_REPLAY
:
8796 switch (rfs4_check_lock_seqid(
8797 args
->locker
.locker4_u
.lock_owner
.lock_seqid
,
8799 case NFS4_CHKSEQ_OKAY
:
8801 * This is a replayed stateid; if
8802 * seqid matches the next expected,
8803 * then client is using wrong seqid.
8805 case NFS4_CHKSEQ_BAD
:
8806 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8808 case NFS4_CHKSEQ_REPLAY
:
8809 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
8810 *cs
->statusp
= status
= resp
->status
;
8819 rfs4_update_lock_sequence(lsp
);
8820 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
8824 * NFS4 only allows locking on regular files, so
8825 * verify type of object.
8827 if (cs
->vp
->v_type
!= VREG
) {
8828 if (cs
->vp
->v_type
== VDIR
)
8829 status
= NFS4ERR_ISDIR
;
8831 status
= NFS4ERR_INVAL
;
8835 cp
= lsp
->rls_state
->rs_owner
->ro_client
;
8837 if (rfs4_clnt_in_grace(cp
) && !args
->reclaim
) {
8838 status
= NFS4ERR_GRACE
;
8842 if (rfs4_clnt_in_grace(cp
) && args
->reclaim
&& !cp
->rc_can_reclaim
) {
8843 status
= NFS4ERR_NO_GRACE
;
8847 if (!rfs4_clnt_in_grace(cp
) && args
->reclaim
) {
8848 status
= NFS4ERR_NO_GRACE
;
8852 if (lsp
->rls_state
->rs_finfo
->rf_dinfo
.rd_dtype
== OPEN_DELEGATE_WRITE
)
8855 status
= rfs4_do_lock(lsp
, args
->locktype
,
8856 args
->offset
, args
->length
, cs
->cr
, resop
);
8859 lsp
->rls_skip_seqid_check
= FALSE
;
8861 *cs
->statusp
= resp
->status
= status
;
8863 if (status
== NFS4_OK
) {
8864 resp
->LOCK4res_u
.lock_stateid
= lsp
->rls_lockid
.stateid
;
8865 lsp
->rls_lock_completed
= TRUE
;
8868 * Only update the "OPEN" response here if this was a new
8872 rfs4_update_open_resp(sp
->rs_owner
, resop
, NULL
);
8874 rfs4_update_lock_resp(lsp
, resop
);
8879 rfs4_sw_exit(&lsp
->rls_sw
);
8881 * If an sp obtained, then the lsp does not represent
8882 * a lock on the file struct.
8885 rfs4_lo_state_rele(lsp
, FALSE
);
8887 rfs4_lo_state_rele(lsp
, TRUE
);
8890 rfs4_sw_exit(&sp
->rs_owner
->ro_sw
);
8891 rfs4_state_rele(sp
);
8894 DTRACE_NFSV4_2(op__lock__done
, struct compound_state
*, cs
,
8898 /* free function for LOCK/LOCKT */
8900 lock_denied_free(nfs_resop4
*resop
)
8902 LOCK4denied
*dp
= NULL
;
8904 switch (resop
->resop
) {
8906 if (resop
->nfs_resop4_u
.oplock
.status
== NFS4ERR_DENIED
)
8907 dp
= &resop
->nfs_resop4_u
.oplock
.LOCK4res_u
.denied
;
8910 if (resop
->nfs_resop4_u
.oplockt
.status
== NFS4ERR_DENIED
)
8911 dp
= &resop
->nfs_resop4_u
.oplockt
.denied
;
8918 kmem_free(dp
->owner
.owner_val
, dp
->owner
.owner_len
);
8923 rfs4_op_locku(nfs_argop4
*argop
, nfs_resop4
*resop
,
8924 struct svc_req
*req
, struct compound_state
*cs
)
8926 LOCKU4args
*args
= &argop
->nfs_argop4_u
.oplocku
;
8927 LOCKU4res
*resp
= &resop
->nfs_resop4_u
.oplocku
;
8929 stateid4
*stateid
= &args
->lock_stateid
;
8930 rfs4_lo_state_t
*lsp
;
8932 DTRACE_NFSV4_2(op__locku__start
, struct compound_state
*, cs
,
8933 LOCKU4args
*, args
);
8935 if (cs
->vp
== NULL
) {
8936 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
8937 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
8942 if ((status
= rfs4_get_lo_state(stateid
, &lsp
, TRUE
)) != NFS4_OK
) {
8943 *cs
->statusp
= resp
->status
= status
;
8944 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
8949 /* Ensure specified filehandle matches */
8950 if (cs
->vp
!= lsp
->rls_state
->rs_finfo
->rf_vp
) {
8951 rfs4_lo_state_rele(lsp
, TRUE
);
8952 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8953 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
8958 /* hold off other access to lsp while we tinker */
8959 rfs4_sw_enter(&lsp
->rls_sw
);
8961 switch (rfs4_check_lo_stateid_seqid(lsp
, stateid
)) {
8962 case NFS4_CHECK_STATEID_OKAY
:
8963 if (rfs4_check_lock_seqid(args
->seqid
, lsp
, resop
)
8964 != NFS4_CHKSEQ_OKAY
) {
8965 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8969 case NFS4_CHECK_STATEID_OLD
:
8970 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8972 case NFS4_CHECK_STATEID_BAD
:
8973 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_STATEID
;
8975 case NFS4_CHECK_STATEID_EXPIRED
:
8976 *cs
->statusp
= resp
->status
= NFS4ERR_EXPIRED
;
8978 case NFS4_CHECK_STATEID_CLOSED
:
8979 *cs
->statusp
= resp
->status
= NFS4ERR_OLD_STATEID
;
8981 case NFS4_CHECK_STATEID_REPLAY
:
8982 switch (rfs4_check_lock_seqid(args
->seqid
, lsp
, resop
)) {
8983 case NFS4_CHKSEQ_OKAY
:
8985 * This is a replayed stateid; if
8986 * seqid matches the next expected,
8987 * then client is using wrong seqid.
8989 case NFS4_CHKSEQ_BAD
:
8990 *cs
->statusp
= resp
->status
= NFS4ERR_BAD_SEQID
;
8992 case NFS4_CHKSEQ_REPLAY
:
8993 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
8994 *cs
->statusp
= status
= resp
->status
;
9003 rfs4_update_lock_sequence(lsp
);
9004 rfs4_update_lease(lsp
->rls_locker
->rl_client
);
9007 * NFS4 only allows locking on regular files, so
9008 * verify type of object.
9010 if (cs
->vp
->v_type
!= VREG
) {
9011 if (cs
->vp
->v_type
== VDIR
)
9012 status
= NFS4ERR_ISDIR
;
9014 status
= NFS4ERR_INVAL
;
9018 if (rfs4_clnt_in_grace(lsp
->rls_state
->rs_owner
->ro_client
)) {
9019 status
= NFS4ERR_GRACE
;
9023 status
= rfs4_do_lock(lsp
, args
->locktype
,
9024 args
->offset
, args
->length
, cs
->cr
, resop
);
9027 *cs
->statusp
= resp
->status
= status
;
9029 if (status
== NFS4_OK
)
9030 resp
->lock_stateid
= lsp
->rls_lockid
.stateid
;
9032 rfs4_update_lock_resp(lsp
, resop
);
9035 rfs4_sw_exit(&lsp
->rls_sw
);
9036 rfs4_lo_state_rele(lsp
, TRUE
);
9038 DTRACE_NFSV4_2(op__locku__done
, struct compound_state
*, cs
,
9043 * LOCKT is a best effort routine, the client can not be guaranteed that
9044 * the status return is still in effect by the time the reply is received.
9045 * They are numerous race conditions in this routine, but we are not required
9046 * and can not be accurate.
9050 rfs4_op_lockt(nfs_argop4
*argop
, nfs_resop4
*resop
,
9051 struct svc_req
*req
, struct compound_state
*cs
)
9053 LOCKT4args
*args
= &argop
->nfs_argop4_u
.oplockt
;
9054 LOCKT4res
*resp
= &resop
->nfs_resop4_u
.oplockt
;
9055 rfs4_lockowner_t
*lo
;
9057 bool_t create
= FALSE
;
9060 int flag
= FREAD
| FWRITE
;
9062 length4 posix_length
;
9066 DTRACE_NFSV4_2(op__lockt__start
, struct compound_state
*, cs
,
9067 LOCKT4args
*, args
);
9069 if (cs
->vp
== NULL
) {
9070 *cs
->statusp
= resp
->status
= NFS4ERR_NOFILEHANDLE
;
9075 * NFS4 only allows locking on regular files, so
9076 * verify type of object.
9078 if (cs
->vp
->v_type
!= VREG
) {
9079 if (cs
->vp
->v_type
== VDIR
)
9080 *cs
->statusp
= resp
->status
= NFS4ERR_ISDIR
;
9082 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
9087 * Check out the clientid to ensure the server knows about it
9088 * so that we correctly inform the client of a server reboot.
9090 if ((cp
= rfs4_findclient_by_id(args
->owner
.clientid
, FALSE
))
9092 *cs
->statusp
= resp
->status
=
9093 rfs4_check_clientid(&args
->owner
.clientid
, 0);
9096 if (rfs4_lease_expired(cp
)) {
9097 rfs4_client_close(cp
);
9099 * Protocol doesn't allow returning NFS4ERR_STALE as
9100 * other operations do on this check so STALE_CLIENTID
9101 * is returned instead
9103 *cs
->statusp
= resp
->status
= NFS4ERR_STALE_CLIENTID
;
9107 if (rfs4_clnt_in_grace(cp
) && !(cp
->rc_can_reclaim
)) {
9108 *cs
->statusp
= resp
->status
= NFS4ERR_GRACE
;
9109 rfs4_client_rele(cp
);
9112 rfs4_client_rele(cp
);
9114 resp
->status
= NFS4_OK
;
9116 switch (args
->locktype
) {
9127 posix_length
= args
->length
;
9128 /* Check for zero length. To lock to end of file use all ones for V4 */
9129 if (posix_length
== 0) {
9130 *cs
->statusp
= resp
->status
= NFS4ERR_INVAL
;
9132 } else if (posix_length
== (length4
)(~0)) {
9133 posix_length
= 0; /* Posix to end of file */
9136 /* Find or create a lockowner */
9137 lo
= rfs4_findlockowner(&args
->owner
, &create
);
9142 rfs4_client_sysid(lo
->rl_client
, &sysid
)) != NFS4_OK
)
9146 sysid
= lockt_sysid
;
9150 flk
.l_whence
= 0; /* SEEK_SET */
9151 flk
.l_start
= args
->offset
;
9152 flk
.l_len
= posix_length
;
9153 flk
.l_sysid
= sysid
;
9155 flag
|= F_REMOTELOCK
;
9157 LOCK_PRINT(rfs4_debug
, "rfs4_op_lockt", F_GETLK
, &flk
);
9159 /* Note that length4 is uint64_t but l_len and l_start are off64_t */
9160 if (flk
.l_len
< 0 || flk
.l_start
< 0) {
9161 resp
->status
= NFS4ERR_INVAL
;
9164 error
= fop_frlock(cs
->vp
, F_GETLK
, &flk
, flag
, 0,
9165 NULL
, cs
->cr
, NULL
);
9168 * N.B. We map error values to nfsv4 errors. This is differrent
9169 * than puterrno4 routine.
9173 if (flk
.l_type
== F_UNLCK
)
9174 resp
->status
= NFS4_OK
;
9176 if (lock_denied(&resp
->denied
, &flk
) == NFS4ERR_EXPIRED
)
9178 resp
->status
= NFS4ERR_DENIED
;
9182 resp
->status
= NFS4ERR_INVAL
;
9185 resp
->status
= NFS4ERR_NOTSUPP
;
9188 cmn_err(CE_WARN
, "rfs4_op_lockt: unexpected errno (%d)",
9190 resp
->status
= NFS4ERR_SERVERFAULT
;
9196 rfs4_lockowner_rele(lo
);
9197 *cs
->statusp
= resp
->status
;
9199 DTRACE_NFSV4_2(op__lockt__done
, struct compound_state
*, cs
,
9204 rfs4_share(rfs4_state_t
*sp
, uint32_t access
, uint32_t deny
)
9210 struct shr_locowner shr_loco
;
9213 ASSERT(rfs4_dbe_islocked(sp
->rs_dbe
));
9214 ASSERT(sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
);
9217 return (NFS4ERR_OLD_STATEID
);
9219 vp
= sp
->rs_finfo
->rf_vp
;
9222 shr
.s_access
= shr
.s_deny
= 0;
9224 if (access
& OPEN4_SHARE_ACCESS_READ
) {
9226 shr
.s_access
|= F_RDACC
;
9228 if (access
& OPEN4_SHARE_ACCESS_WRITE
) {
9230 shr
.s_access
|= F_WRACC
;
9232 ASSERT(shr
.s_access
);
9234 if (deny
& OPEN4_SHARE_DENY_READ
)
9235 shr
.s_deny
|= F_RDDNY
;
9236 if (deny
& OPEN4_SHARE_DENY_WRITE
)
9237 shr
.s_deny
|= F_WRDNY
;
9239 shr
.s_pid
= rfs4_dbe_getid(sp
->rs_owner
->ro_dbe
);
9240 shr
.s_sysid
= sp
->rs_owner
->ro_client
->rc_sysidt
;
9241 shr_loco
.sl_pid
= shr
.s_pid
;
9242 shr_loco
.sl_id
= shr
.s_sysid
;
9243 shr
.s_owner
= (caddr_t
)&shr_loco
;
9244 shr
.s_own_len
= sizeof (shr_loco
);
9246 cmd
= nbl_need_check(vp
) ? F_SHARE_NBMAND
: F_SHARE
;
9248 err
= fop_shrlock(vp
, cmd
, &shr
, fflags
, CRED(), NULL
);
9251 err
= NFS4ERR_SHARE_DENIED
;
9253 err
= puterrno4(err
);
9257 sp
->rs_share_access
|= access
;
9258 sp
->rs_share_deny
|= deny
;
9264 rfs4_unshare(rfs4_state_t
*sp
)
9268 struct shr_locowner shr_loco
;
9270 ASSERT(rfs4_dbe_islocked(sp
->rs_dbe
));
9272 if (sp
->rs_closed
|| sp
->rs_share_access
== 0)
9275 ASSERT(sp
->rs_owner
->ro_client
->rc_sysidt
!= LM_NOSYSID
);
9276 ASSERT(sp
->rs_finfo
->rf_vp
);
9278 shr
.s_access
= shr
.s_deny
= 0;
9279 shr
.s_pid
= rfs4_dbe_getid(sp
->rs_owner
->ro_dbe
);
9280 shr
.s_sysid
= sp
->rs_owner
->ro_client
->rc_sysidt
;
9281 shr_loco
.sl_pid
= shr
.s_pid
;
9282 shr_loco
.sl_id
= shr
.s_sysid
;
9283 shr
.s_owner
= (caddr_t
)&shr_loco
;
9284 shr
.s_own_len
= sizeof (shr_loco
);
9286 err
= fop_shrlock(sp
->rs_finfo
->rf_vp
, F_UNSHARE
, &shr
, 0, CRED(),
9289 err
= puterrno4(err
);
9293 sp
->rs_share_access
= 0;
9294 sp
->rs_share_deny
= 0;
9301 rdma_setup_read_data4(READ4args
*args
, READ4res
*rok
)
9304 count4 count
= rok
->data_len
;
9308 if (rdma_setup_read_chunks(wcl
, count
, &wlist_len
) == FALSE
) {
9312 rok
->wlist_len
= wlist_len
;
9317 /* tunable to disable server referrals */
9318 int rfs4_no_referrals
= 0;
9321 * Find an NFS record in reparse point data.
9322 * Returns 0 for success and <0 or an errno value on failure.
9325 vn_find_nfs_record(vnode_t
*vp
, nvlist_t
**nvlp
, char **svcp
, char **datap
)
9332 if ((nvl
= reparse_init()) == NULL
)
9335 if ((err
= reparse_vnode_parse(vp
, nvl
)) != 0) {
9341 while ((curr
= nvlist_next_nvpair(nvl
, curr
)) != NULL
) {
9342 if ((stype
= nvpair_name(curr
)) == NULL
) {
9346 if (strncasecmp(stype
, "NFS", 3) == 0)
9350 if ((curr
== NULL
) ||
9351 (nvpair_value_string(curr
, &val
))) {
9362 vn_is_nfs_reparse(vnode_t
*vp
, cred_t
*cr
)
9367 if (rfs4_no_referrals
!= 0)
9370 if (vn_is_reparse(vp
, cr
, NULL
) == B_FALSE
)
9373 if (vn_find_nfs_record(vp
, &nvl
, &s
, &d
) != 0)
9382 * There is a user-level copy of this routine in ref_subr.c.
9383 * Changes should be kept in sync.
9386 nfs4_create_components(char *path
, component4
*comp4
)
9388 int slen
, plen
, ncomp
;
9389 char *ori_path
, *nxtc
, buf
[MAXNAMELEN
];
9394 plen
= strlen(path
) + 1; /* include the terminator */
9398 /* count number of components in the path */
9399 for (nxtc
= path
; nxtc
< ori_path
+ plen
; nxtc
++) {
9400 if (*nxtc
== '/' || *nxtc
== '\0' || *nxtc
== '\n') {
9401 if ((slen
= nxtc
- path
) == 0) {
9406 if (comp4
!= NULL
) {
9407 bcopy(path
, buf
, slen
);
9409 (void) str_to_utf8(buf
, &comp4
[ncomp
]);
9412 ncomp
++; /* 1 valid component */
9415 if (*nxtc
== '\0' || *nxtc
== '\n')
9423 * There is a user-level copy of this routine in ref_subr.c.
9424 * Changes should be kept in sync.
9427 make_pathname4(char *path
, pathname4
*pathname
)
9432 if (pathname
== NULL
)
9436 pathname
->pathname4_val
= NULL
;
9437 pathname
->pathname4_len
= 0;
9441 /* count number of components to alloc buffer */
9442 if ((ncomp
= nfs4_create_components(path
, NULL
)) == 0) {
9443 pathname
->pathname4_val
= NULL
;
9444 pathname
->pathname4_len
= 0;
9447 comp4
= kmem_zalloc(ncomp
* sizeof (component4
), KM_SLEEP
);
9449 /* copy components into allocated buffer */
9450 ncomp
= nfs4_create_components(path
, comp4
);
9452 pathname
->pathname4_val
= comp4
;
9453 pathname
->pathname4_len
= ncomp
;
9458 #define xdr_fs_locations4 xdr_fattr4_fs_locations
9461 fetch_referral(vnode_t
*vp
, cred_t
*cr
)
9464 char *stype
, *sdata
;
9465 fs_locations4
*result
;
9472 * Check attrs to ensure it's a reparse point
9474 if (vn_is_reparse(vp
, cr
, NULL
) == B_FALSE
)
9478 * Look for an NFS record and get the type and data
9480 if (vn_find_nfs_record(vp
, &nvl
, &stype
, &sdata
) != 0)
9484 * With the type and data, upcall to get the referral
9486 bufsize
= sizeof (buf
);
9487 bzero(buf
, sizeof (buf
));
9488 err
= reparse_kderef((const char *)stype
, (const char *)sdata
,
9492 DTRACE_PROBE4(nfs4serv__func__referral__upcall
,
9493 char *, stype
, char *, sdata
, char *, buf
, int, err
);
9496 "reparsed daemon not running: unable to get referral (%d)",
9502 * We get an XDR'ed record back from the kderef call
9504 xdrmem_create(&xdr
, buf
, bufsize
, XDR_DECODE
);
9505 result
= kmem_alloc(sizeof (fs_locations4
), KM_SLEEP
);
9506 err
= xdr_fs_locations4(&xdr
, result
);
9509 DTRACE_PROBE1(nfs4serv__func__referral__upcall__xdrfail
,
9515 * Look at path to recover fs_root, ignoring the leading '/'
9517 (void) make_pathname4(vp
->v_path
, &result
->fs_root
);
9523 build_symlink(vnode_t
*vp
, cred_t
*cr
, size_t *strsz
)
9527 char *server
, *path
, *symbuf
;
9528 static char *prefix
= "/net/";
9529 int i
, size
, npaths
;
9532 /* Get the referral */
9533 if ((fsl
= fetch_referral(vp
, cr
)) == NULL
)
9536 /* Deal with only the first location and first server */
9537 fs
= &fsl
->locations_val
[0];
9538 server
= utf8_to_str(&fs
->server_val
[0], &len
, NULL
);
9539 if (server
== NULL
) {
9540 rfs4_free_fs_locations4(fsl
);
9541 kmem_free(fsl
, sizeof (fs_locations4
));
9545 /* Figure out size for "/net/" + host + /path/path/path + NULL */
9546 size
= strlen(prefix
) + len
;
9547 for (i
= 0; i
< fs
->rootpath
.pathname4_len
; i
++)
9548 size
+= fs
->rootpath
.pathname4_val
[i
].utf8string_len
+ 1;
9550 /* Allocate the symlink buffer and fill it */
9551 symbuf
= kmem_zalloc(size
, KM_SLEEP
);
9552 (void) strcat(symbuf
, prefix
);
9553 (void) strcat(symbuf
, server
);
9554 kmem_free(server
, len
);
9557 for (i
= 0; i
< fs
->rootpath
.pathname4_len
; i
++) {
9558 path
= utf8_to_str(&fs
->rootpath
.pathname4_val
[i
], &len
, NULL
);
9561 (void) strcat(symbuf
, "/");
9562 (void) strcat(symbuf
, path
);
9564 kmem_free(path
, len
);
9567 rfs4_free_fs_locations4(fsl
);
9568 kmem_free(fsl
, sizeof (fs_locations4
));
9576 * Check to see if we have a downrev Solaris client, so that we
9577 * can send it a symlink instead of a referral.
9580 client_is_downrev(struct svc_req
*req
)
9582 struct sockaddr
*ca
;
9584 bool_t create
= FALSE
;
9587 ca
= (struct sockaddr
*)svc_getrpccaller(req
->rq_xprt
)->buf
;
9589 ci
= rfs4_find_clntip(ca
, &create
);
9592 is_downrev
= ci
->ri_no_referrals
;
9593 rfs4_dbe_rele(ci
->ri_dbe
);
9594 return (is_downrev
);