xref: /netbsd-src/sys/fs/tmpfs/tmpfs_rename.c (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1 /*	$NetBSD: tmpfs_rename.c,v 1.2 2012/05/09 22:46:25 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2012 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Taylor R Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * tmpfs rename
34  */
35 
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: tmpfs_rename.c,v 1.2 2012/05/09 22:46:25 riastradh Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/errno.h>
41 #include <sys/kauth.h>
42 #include <sys/mount.h>
43 #include <sys/namei.h>
44 #include <sys/stat.h>
45 #include <sys/vnode.h>
46 #include <sys/vnode_if.h>
47 
48 #include <miscfs/genfs/genfs.h>
49 
50 #include <fs/tmpfs/tmpfs_vnops.h>
51 #include <fs/tmpfs/tmpfs.h>
52 
53 /*
54  * Forward declarations
55  */
56 
57 static int tmpfs_sane_rename(struct vnode *, struct componentname *,
58     struct vnode *, struct componentname *,
59     kauth_cred_t, bool);
60 static bool tmpfs_rmdired_p(struct vnode *);
61 static int tmpfs_gro_lock_directory(struct mount *, struct vnode *);
62 
63 static const struct genfs_rename_ops tmpfs_genfs_rename_ops;
64 
65 /*
66  * tmpfs_sane_rename: The hairiest vop, with the saner API.
67  *
68  * Arguments:
69  *
70  * . fdvp (from directory vnode),
71  * . fcnp (from component name),
72  * . tdvp (to directory vnode),
73  * . tcnp (to component name),
74  * . cred (credentials structure), and
75  * . posixly_correct (flag for behaviour if target & source link same file).
76  *
77  * fdvp and tdvp may be the same, and must be referenced and unlocked.
78  */
79 static int
80 tmpfs_sane_rename(
81     struct vnode *fdvp, struct componentname *fcnp,
82     struct vnode *tdvp, struct componentname *tcnp,
83     kauth_cred_t cred, bool posixly_correct)
84 {
85 	struct tmpfs_dirent *fdirent, *tdirent;
86 
87 	return genfs_sane_rename(&tmpfs_genfs_rename_ops,
88 	    fdvp, fcnp, &fdirent, tdvp, tcnp, &tdirent,
89 	    cred, posixly_correct);
90 }
91 
92 /*
93  * tmpfs_rename: The hairiest vop, with the insanest API.  Defer to
94  * genfs_insane_rename immediately.
95  */
96 int
97 tmpfs_rename(void *v)
98 {
99 
100 	return genfs_insane_rename(v, &tmpfs_sane_rename);
101 }
102 
103 /*
104  * tmpfs_gro_directory_empty_p: Return true if the directory vp is
105  * empty.  dvp is its parent.
106  *
107  * vp and dvp must be locked and referenced.
108  */
109 static bool
110 tmpfs_gro_directory_empty_p(struct mount *mp, kauth_cred_t cred,
111     struct vnode *vp, struct vnode *dvp)
112 {
113 
114 	(void)mp;
115 	(void)cred;
116 	(void)dvp;
117 	KASSERT(mp != NULL);
118 	KASSERT(vp != NULL);
119 	KASSERT(dvp != NULL);
120 	KASSERT(vp != dvp);
121 	KASSERT(vp->v_mount == mp);
122 	KASSERT(dvp->v_mount == mp);
123 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
124 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
125 
126 	return (VP_TO_TMPFS_NODE(vp)->tn_size == 0);
127 }
128 
129 /*
130  * tmpfs_gro_rename_check_possible: Check whether a rename is possible
131  * independent of credentials.
132  */
133 static int
134 tmpfs_gro_rename_check_possible(struct mount *mp,
135     struct vnode *fdvp, struct vnode *fvp,
136     struct vnode *tdvp, struct vnode *tvp)
137 {
138 
139 	(void)mp;
140 	KASSERT(mp != NULL);
141 	KASSERT(fdvp != NULL);
142 	KASSERT(fvp != NULL);
143 	KASSERT(tdvp != NULL);
144 	KASSERT(fdvp != fvp);
145 	KASSERT(fdvp != tvp);
146 	KASSERT(tdvp != fvp);
147 	KASSERT(tdvp != tvp);
148 	KASSERT(fvp != tvp);
149 	KASSERT(fdvp->v_type == VDIR);
150 	KASSERT(tdvp->v_type == VDIR);
151 	KASSERT(fdvp->v_mount == mp);
152 	KASSERT(fvp->v_mount == mp);
153 	KASSERT(tdvp->v_mount == mp);
154 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
155 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
156 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
157 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
158 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
159 
160 	return genfs_ufslike_rename_check_possible(
161 	    VP_TO_TMPFS_NODE(fdvp)->tn_flags, VP_TO_TMPFS_NODE(fvp)->tn_flags,
162 	    VP_TO_TMPFS_NODE(tdvp)->tn_flags,
163 	    (tvp? VP_TO_TMPFS_NODE(tvp)->tn_flags : 0), (tvp != NULL),
164 	    IMMUTABLE, APPEND);
165 }
166 
167 /*
168  * tmpfs_gro_rename_check_permitted: Check whether a rename is
169  * permitted given our credentials.
170  */
171 static int
172 tmpfs_gro_rename_check_permitted(struct mount *mp, kauth_cred_t cred,
173     struct vnode *fdvp, struct vnode *fvp,
174     struct vnode *tdvp, struct vnode *tvp)
175 {
176 
177 	(void)mp;
178 	KASSERT(mp != NULL);
179 	KASSERT(fdvp != NULL);
180 	KASSERT(fvp != NULL);
181 	KASSERT(tdvp != NULL);
182 	KASSERT(fdvp != fvp);
183 	KASSERT(fdvp != tvp);
184 	KASSERT(tdvp != fvp);
185 	KASSERT(tdvp != tvp);
186 	KASSERT(fvp != tvp);
187 	KASSERT(fdvp->v_type == VDIR);
188 	KASSERT(tdvp->v_type == VDIR);
189 	KASSERT(fdvp->v_mount == mp);
190 	KASSERT(fvp->v_mount == mp);
191 	KASSERT(tdvp->v_mount == mp);
192 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
193 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
194 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
195 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
196 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
197 
198 	return genfs_ufslike_rename_check_permitted(cred,
199 	    fdvp, VP_TO_TMPFS_NODE(fdvp)->tn_mode,
200 	    VP_TO_TMPFS_NODE(fdvp)->tn_uid,
201 	    fvp, VP_TO_TMPFS_NODE(fvp)->tn_uid,
202 	    tdvp, VP_TO_TMPFS_NODE(tdvp)->tn_mode,
203 	    VP_TO_TMPFS_NODE(tdvp)->tn_uid,
204 	    tvp, (tvp? VP_TO_TMPFS_NODE(tvp)->tn_uid : 0));
205 }
206 
207 /*
208  * tmpfs_gro_remove_check_possible: Check whether a remove is possible
209  * independent of credentials.
210  */
211 static int
212 tmpfs_gro_remove_check_possible(struct mount *mp,
213     struct vnode *dvp, struct vnode *vp)
214 {
215 
216 	(void)mp;
217 	KASSERT(mp != NULL);
218 	KASSERT(dvp != NULL);
219 	KASSERT(vp != NULL);
220 	KASSERT(dvp != vp);
221 	KASSERT(dvp->v_type == VDIR);
222 	KASSERT(vp->v_type != VDIR);
223 	KASSERT(dvp->v_mount == mp);
224 	KASSERT(vp->v_mount == mp);
225 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
226 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
227 
228 	return genfs_ufslike_remove_check_possible(
229 	    VP_TO_TMPFS_NODE(dvp)->tn_flags, VP_TO_TMPFS_NODE(vp)->tn_flags,
230 	    IMMUTABLE, APPEND);
231 }
232 
233 /*
234  * tmpfs_gro_remove_check_permitted: Check whether a remove is
235  * permitted given our credentials.
236  */
237 static int
238 tmpfs_gro_remove_check_permitted(struct mount *mp, kauth_cred_t cred,
239     struct vnode *dvp, struct vnode *vp)
240 {
241 
242 	(void)mp;
243 	KASSERT(mp != NULL);
244 	KASSERT(dvp != NULL);
245 	KASSERT(vp != NULL);
246 	KASSERT(dvp != vp);
247 	KASSERT(dvp->v_type == VDIR);
248 	KASSERT(vp->v_type != VDIR);
249 	KASSERT(dvp->v_mount == mp);
250 	KASSERT(vp->v_mount == mp);
251 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
252 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
253 
254 	return genfs_ufslike_remove_check_permitted(cred,
255 	    dvp, VP_TO_TMPFS_NODE(dvp)->tn_mode, VP_TO_TMPFS_NODE(dvp)->tn_uid,
256 	    vp, VP_TO_TMPFS_NODE(vp)->tn_uid);
257 }
258 
259 /*
260  * tmpfs_gro_rename: Actually perform the rename operation.
261  */
262 static int
263 tmpfs_gro_rename(struct mount *mp, kauth_cred_t cred,
264     struct vnode *fdvp, struct componentname *fcnp,
265     void *fde, struct vnode *fvp,
266     struct vnode *tdvp, struct componentname *tcnp,
267     void *tde, struct vnode *tvp)
268 {
269 	struct tmpfs_dirent **fdep = fde;
270 	struct tmpfs_dirent **tdep = tde;
271 	char *newname;
272 
273 	(void)cred;
274 	KASSERT(mp != NULL);
275 	KASSERT(fdvp != NULL);
276 	KASSERT(fcnp != NULL);
277 	KASSERT(fdep != NULL);
278 	KASSERT(fvp != NULL);
279 	KASSERT(tdvp != NULL);
280 	KASSERT(tcnp != NULL);
281 	KASSERT(tdep != NULL);
282 	KASSERT(fdep != tdep);
283 	KASSERT((*fdep) != (*tdep));
284 	KASSERT((*fdep) != NULL);
285 	KASSERT((*fdep)->td_node == VP_TO_TMPFS_NODE(fvp));
286 	KASSERT((tvp == NULL) || ((*tdep) != NULL));
287 	KASSERT((tvp == NULL) || ((*tdep)->td_node == VP_TO_TMPFS_NODE(tvp)));
288 	KASSERT(fdvp != fvp);
289 	KASSERT(fdvp != tvp);
290 	KASSERT(tdvp != fvp);
291 	KASSERT(tdvp != tvp);
292 	KASSERT(fvp != tvp);
293 	KASSERT(fdvp->v_mount == mp);
294 	KASSERT(fvp->v_mount == mp);
295 	KASSERT(tdvp->v_mount == mp);
296 	KASSERT((tvp == NULL) || (tvp->v_mount == mp));
297 	KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
298 	KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
299 	KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
300 	KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
301 
302 	if (tmpfs_strname_neqlen(fcnp, tcnp)) {
303 		newname = tmpfs_strname_alloc(VFS_TO_TMPFS(mp),
304 		    tcnp->cn_namelen);
305 		if (newname == NULL)
306 			return ENOSPC;
307 	} else {
308 		newname = NULL;
309 	}
310 
311 	/*
312 	 * If we are moving from one directory to another, detach the
313 	 * source entry and reattach it to the target directory.
314 	 */
315 	if (fdvp != tdvp) {
316 		tmpfs_dir_detach(fdvp, *fdep);
317 		tmpfs_dir_attach(tdvp, *fdep, VP_TO_TMPFS_NODE(fvp));
318 	} else if (tvp == NULL) {
319 		/*
320 		 * We are changing the directory.  tmpfs_dir_attach and
321 		 * tmpfs_dir_detach note the events for us, but for
322 		 * this case we don't call them, so we must note the
323 		 * event explicitly.
324 		 */
325 		VN_KNOTE(fdvp, NOTE_WRITE);
326 	}
327 
328 	/*
329 	 * If we are replacing an existing target entry, delete it.
330 	 *
331 	 * XXX What if the target is a directory with whiteout entries?
332 	 */
333 	if (tvp != NULL) {
334 		KASSERT((*tdep) != NULL);
335 		KASSERT((*tdep)->td_node == VP_TO_TMPFS_NODE(tvp));
336 		KASSERT((fvp->v_type == VDIR) == (tvp->v_type == VDIR));
337 		if (tvp->v_type == VDIR) {
338 			KASSERT(VP_TO_TMPFS_NODE(tvp)->tn_size == 0);
339 			KASSERT(VP_TO_TMPFS_NODE(tvp)->tn_links == 2);
340 
341 			/*
342 			 * Decrement the extra link count for `.' so
343 			 * the vnode will be recycled when released.
344 			 *
345 			 * XXX Why not just release directory vnodes
346 			 * when their link count is 1 instead of 0 in
347 			 * tmpfs_inactive, since `.' is being treated
348 			 * specially anyway?
349 			 */
350 			VP_TO_TMPFS_NODE(tvp)->tn_links--;
351 		}
352 		tmpfs_dir_detach(tdvp, *tdep);
353 		tmpfs_free_dirent(VFS_TO_TMPFS(mp), *tdep);
354 	}
355 
356 	/*
357 	 * Update the directory entry's name if necessary, and flag
358 	 * metadata updates.  A memory allocation failure here is not
359 	 * OK because we've already committed some changes that we
360 	 * can't back out at this point, hence the early allocation
361 	 * above.
362 	 */
363 	if (newname != NULL) {
364 		KASSERT(tcnp->cn_namelen <= TMPFS_MAXNAMLEN);
365 
366 		tmpfs_strname_free(VFS_TO_TMPFS(mp), (*fdep)->td_name,
367 		    (*fdep)->td_namelen);
368 		(*fdep)->td_namelen = (uint16_t)tcnp->cn_namelen;
369 		(void)memcpy(newname, tcnp->cn_nameptr, tcnp->cn_namelen);
370 		(*fdep)->td_name = newname;
371 
372 		VP_TO_TMPFS_NODE(fvp)->tn_status |= TMPFS_NODE_CHANGED;
373 		VP_TO_TMPFS_NODE(tdvp)->tn_status |= TMPFS_NODE_MODIFIED;
374 	}
375 
376 	VN_KNOTE(fvp, NOTE_RENAME);
377 
378 #if 0				/* XXX */
379 	genfs_rename_cache_purge(fdvp, fvp, tdvp, tvp);
380 #endif
381 
382 	return 0;
383 }
384 
385 /*
386  * tmpfs_gro_remove: Rename an object over another link to itself,
387  * effectively removing just the original link.
388  */
389 static int
390 tmpfs_gro_remove(struct mount *mp, kauth_cred_t cred,
391     struct vnode *dvp, struct componentname *cnp, void *de, struct vnode *vp)
392 {
393 	struct tmpfs_dirent **dep = de;
394 
395 	(void)vp;
396 	KASSERT(mp != NULL);
397 	KASSERT(dvp != NULL);
398 	KASSERT(cnp != NULL);
399 	KASSERT(dep != NULL);
400 	KASSERT(vp != NULL);
401 	KASSERT(dvp != vp);
402 	KASSERT(dvp->v_mount == mp);
403 	KASSERT(vp->v_mount == mp);
404 	KASSERT(dvp->v_type == VDIR);
405 	KASSERT(vp->v_type != VDIR);
406 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
407 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
408 
409 	tmpfs_dir_detach(dvp, *dep);
410 	tmpfs_free_dirent(VFS_TO_TMPFS(mp), *dep);
411 
412 	return 0;
413 }
414 
415 /*
416  * tmpfs_gro_lookup: Look up and save the lookup results.
417  */
418 static int
419 tmpfs_gro_lookup(struct mount *mp, struct vnode *dvp,
420     struct componentname *cnp, void *de_ret, struct vnode **vp_ret)
421 {
422 	struct tmpfs_dirent *dirent, **dep_ret = de_ret;
423 	struct vnode *vp;
424 	int error;
425 
426 	(void)mp;
427 	KASSERT(mp != NULL);
428 	KASSERT(dvp != NULL);
429 	KASSERT(cnp != NULL);
430 	KASSERT(dep_ret != NULL);
431 	KASSERT(vp_ret != NULL);
432 	KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
433 
434 	dirent = tmpfs_dir_lookup(VP_TO_TMPFS_NODE(dvp), cnp);
435 	if (dirent == NULL)
436 		return ENOENT;
437 
438 	mutex_enter(&dirent->td_node->tn_vlock);
439 	error = tmpfs_vnode_get(mp, dirent->td_node, &vp);
440 	/* Note: tmpfs_vnode_get always releases dirent->td_node->tn_vlock.  */
441 	if (error)
442 		return error;
443 
444 	KASSERT(vp != NULL);
445 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
446 
447 	/*
448 	 * tmpfs_vnode_get returns this locked for us, which would be
449 	 * convenient but for lossage in other file systems.  So, for
450 	 * hysterical raisins, we have to unlock it here.  The caller
451 	 * will lock it again, and we don't rely on any interesting
452 	 * invariants in the interim, beyond that it won't vanish from
453 	 * under us, which it won't because it's referenced.
454 	 *
455 	 * XXX Once namei is fixed, we can change the genfs_rename
456 	 * protocol so that this unlock is not necessary.
457 	 */
458 	VOP_UNLOCK(vp);
459 
460 	*dep_ret = dirent;
461 	*vp_ret = vp;
462 	return 0;
463 }
464 
465 /*
466  * tmpfs_rmdired_p: Check whether the directory vp has been rmdired.
467  *
468  * vp must be locked and referenced.
469  */
470 static bool
471 tmpfs_rmdired_p(struct vnode *vp)
472 {
473 
474 	KASSERT(vp != NULL);
475 	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
476 	KASSERT(vp->v_type == VDIR);
477 
478 	return (VP_TO_TMPFS_NODE(vp)->tn_spec.tn_dir.tn_parent == NULL);
479 }
480 
481 /*
482  * tmpfs_gro_genealogy: Analyze the genealogy of the source and target
483  * directories.
484  */
485 static int
486 tmpfs_gro_genealogy(struct mount *mp, kauth_cred_t cred,
487     struct vnode *fdvp, struct vnode *tdvp,
488     struct vnode **intermediate_node_ret)
489 {
490 	struct vnode *vp;
491 	struct tmpfs_node *dnode;
492 	int error;
493 
494 	(void)cred;
495 	KASSERT(mp != NULL);
496 	KASSERT(fdvp != NULL);
497 	KASSERT(tdvp != NULL);
498 	KASSERT(fdvp != tdvp);
499 	KASSERT(intermediate_node_ret != NULL);
500 	KASSERT(fdvp->v_mount == mp);
501 	KASSERT(tdvp->v_mount == mp);
502 	KASSERT(fdvp->v_type == VDIR);
503 	KASSERT(tdvp->v_type == VDIR);
504 
505 	/*
506 	 * We need to provisionally lock tdvp to keep rmdir from
507 	 * deleting it -- or any ancestor -- at an inopportune moment.
508 	 */
509 	error = tmpfs_gro_lock_directory(mp, tdvp);
510 	if (error)
511 		return error;
512 
513 	vp = tdvp;
514 	vref(vp);
515 
516 	for (;;) {
517 		KASSERT(vp != NULL);
518 		KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
519 		KASSERT(vp->v_mount == mp);
520 		KASSERT(vp->v_type == VDIR);
521 		KASSERT(!tmpfs_rmdired_p(vp));
522 
523 		dnode = VP_TO_TMPFS_NODE(vp)->tn_spec.tn_dir.tn_parent;
524 
525 		/*
526 		 * If dnode is null then vp has been rmdir'd, which is
527 		 * not supposed to happen because we have it locked.
528 		 */
529 		KASSERT(dnode != NULL);
530 
531 		/* Did we hit the root without finding fdvp?  */
532 		if (dnode == VP_TO_TMPFS_NODE(vp)) {
533 			vput(vp);
534 			*intermediate_node_ret = NULL;
535 			return 0;
536 		}
537 
538 		/* Did we find that fdvp is an ancestor of tdvp? */
539 		if (dnode == VP_TO_TMPFS_NODE(fdvp)) {
540 			KASSERT(dnode->tn_vnode == fdvp);
541 			/* Unlock vp, but keep it referenced.  */
542 			VOP_UNLOCK(vp);
543 			*intermediate_node_ret = vp;
544 			return 0;
545 		}
546 
547 		/* Neither -- keep ascending the family tree.  */
548 		mutex_enter(&dnode->tn_vlock);
549 		vput(vp);
550 		vp = NULL;	/* Just in case, for the kassert above...  */
551 		error = tmpfs_vnode_get(mp, dnode, &vp);
552 		if (error)
553 			return error;
554 	}
555 }
556 
557 /*
558  * tmpfs_gro_lock_directory: Lock the directory vp, but fail if it has
559  * been rmdir'd.
560  */
561 static int
562 tmpfs_gro_lock_directory(struct mount *mp, struct vnode *vp)
563 {
564 
565 	(void)mp;
566 	KASSERT(mp != NULL);
567 	KASSERT(vp != NULL);
568 	KASSERT(vp->v_mount == mp);
569 
570 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
571 
572 	if (tmpfs_rmdired_p(vp)) {
573 		VOP_UNLOCK(vp);
574 		return ENOENT;
575 	}
576 
577 	return 0;
578 }
579 
580 static const struct genfs_rename_ops tmpfs_genfs_rename_ops = {
581 	.gro_directory_empty_p		= tmpfs_gro_directory_empty_p,
582 	.gro_rename_check_possible	= tmpfs_gro_rename_check_possible,
583 	.gro_rename_check_permitted	= tmpfs_gro_rename_check_permitted,
584 	.gro_remove_check_possible	= tmpfs_gro_remove_check_possible,
585 	.gro_remove_check_permitted	= tmpfs_gro_remove_check_permitted,
586 	.gro_rename			= tmpfs_gro_rename,
587 	.gro_remove			= tmpfs_gro_remove,
588 	.gro_lookup			= tmpfs_gro_lookup,
589 	.gro_genealogy			= tmpfs_gro_genealogy,
590 	.gro_lock_directory		= tmpfs_gro_lock_directory,
591 };
592