Deleted Added
full compact
tmpfs_subr.c (194766) tmpfs_subr.c (197953)
1/* $NetBSD: tmpfs_subr.c,v 1.35 2007/07/09 21:10:50 ad Exp $ */
2
3/*-
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code

--- 20 unchanged lines hidden (view full) ---

29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * Efficient memory file system supporting functions.
35 */
36#include <sys/cdefs.h>
1/* $NetBSD: tmpfs_subr.c,v 1.35 2007/07/09 21:10:50 ad Exp $ */
2
3/*-
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code

--- 20 unchanged lines hidden (view full) ---

29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * Efficient memory file system supporting functions.
35 */
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_subr.c 194766 2009-06-23 20:45:22Z kib $");
37__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_subr.c 197953 2009-10-11 07:03:56Z delphij $");
38
39#include <sys/param.h>
40#include <sys/namei.h>
41#include <sys/priv.h>
42#include <sys/proc.h>
43#include <sys/stat.h>
44#include <sys/systm.h>
45#include <sys/vnode.h>

--- 73 unchanged lines hidden (view full) ---

119 case VDIR:
120 TAILQ_INIT(&nnode->tn_dir.tn_dirhead);
121 MPASS(parent != nnode);
122 MPASS(IMPLIES(parent == NULL, tmp->tm_root == NULL));
123 nnode->tn_dir.tn_parent = (parent == NULL) ? nnode : parent;
124 nnode->tn_dir.tn_readdir_lastn = 0;
125 nnode->tn_dir.tn_readdir_lastp = NULL;
126 nnode->tn_links++;
38
39#include <sys/param.h>
40#include <sys/namei.h>
41#include <sys/priv.h>
42#include <sys/proc.h>
43#include <sys/stat.h>
44#include <sys/systm.h>
45#include <sys/vnode.h>

--- 73 unchanged lines hidden (view full) ---

119 case VDIR:
120 TAILQ_INIT(&nnode->tn_dir.tn_dirhead);
121 MPASS(parent != nnode);
122 MPASS(IMPLIES(parent == NULL, tmp->tm_root == NULL));
123 nnode->tn_dir.tn_parent = (parent == NULL) ? nnode : parent;
124 nnode->tn_dir.tn_readdir_lastn = 0;
125 nnode->tn_dir.tn_readdir_lastp = NULL;
126 nnode->tn_links++;
127 TMPFS_NODE_LOCK(nnode->tn_dir.tn_parent);
127 nnode->tn_dir.tn_parent->tn_links++;
128 nnode->tn_dir.tn_parent->tn_links++;
129 TMPFS_NODE_UNLOCK(nnode->tn_dir.tn_parent);
128 break;
129
130 case VFIFO:
131 /* FALLTHROUGH */
132 case VSOCK:
133 break;
134
135 case VLNK:

--- 46 unchanged lines hidden (view full) ---

182void
183tmpfs_free_node(struct tmpfs_mount *tmp, struct tmpfs_node *node)
184{
185 size_t pages = 0;
186
187#ifdef INVARIANTS
188 TMPFS_NODE_LOCK(node);
189 MPASS(node->tn_vnode == NULL);
130 break;
131
132 case VFIFO:
133 /* FALLTHROUGH */
134 case VSOCK:
135 break;
136
137 case VLNK:

--- 46 unchanged lines hidden (view full) ---

184void
185tmpfs_free_node(struct tmpfs_mount *tmp, struct tmpfs_node *node)
186{
187 size_t pages = 0;
188
189#ifdef INVARIANTS
190 TMPFS_NODE_LOCK(node);
191 MPASS(node->tn_vnode == NULL);
192 MPASS((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0);
190 TMPFS_NODE_UNLOCK(node);
191#endif
192
193 TMPFS_LOCK(tmp);
194 LIST_REMOVE(node, tn_entries);
195 tmp->tm_nodes_inuse--;
196 TMPFS_UNLOCK(tmp);
197

--- 109 unchanged lines hidden (view full) ---

307 struct vnode **vpp)
308{
309 int error = 0;
310 struct vnode *vp;
311
312loop:
313 TMPFS_NODE_LOCK(node);
314 if ((vp = node->tn_vnode) != NULL) {
193 TMPFS_NODE_UNLOCK(node);
194#endif
195
196 TMPFS_LOCK(tmp);
197 LIST_REMOVE(node, tn_entries);
198 tmp->tm_nodes_inuse--;
199 TMPFS_UNLOCK(tmp);
200

--- 109 unchanged lines hidden (view full) ---

310 struct vnode **vpp)
311{
312 int error = 0;
313 struct vnode *vp;
314
315loop:
316 TMPFS_NODE_LOCK(node);
317 if ((vp = node->tn_vnode) != NULL) {
318 MPASS((node->tn_vpstate & TMPFS_VNODE_DOOMED) == 0);
315 VI_LOCK(vp);
316 TMPFS_NODE_UNLOCK(node);
317 vholdl(vp);
318 (void) vget(vp, lkflag | LK_INTERLOCK | LK_RETRY, curthread);
319 vdrop(vp);
320
321 /*
322 * Make sure the vnode is still there after
323 * getting the interlock to avoid racing a free.
324 */
325 if (node->tn_vnode == NULL || node->tn_vnode != vp) {
326 vput(vp);
327 goto loop;
328 }
329
330 goto out;
331 }
332
319 VI_LOCK(vp);
320 TMPFS_NODE_UNLOCK(node);
321 vholdl(vp);
322 (void) vget(vp, lkflag | LK_INTERLOCK | LK_RETRY, curthread);
323 vdrop(vp);
324
325 /*
326 * Make sure the vnode is still there after
327 * getting the interlock to avoid racing a free.
328 */
329 if (node->tn_vnode == NULL || node->tn_vnode != vp) {
330 vput(vp);
331 goto loop;
332 }
333
334 goto out;
335 }
336
337 if ((node->tn_vpstate & TMPFS_VNODE_DOOMED) ||
338 (node->tn_type == VDIR && node->tn_dir.tn_parent == NULL)) {
339 TMPFS_NODE_UNLOCK(node);
340 error = ENOENT;
341 vp = NULL;
342 goto out;
343 }
344
333 /*
334 * otherwise lock the vp list while we call getnewvnode
335 * since that can block.
336 */
337 if (node->tn_vpstate & TMPFS_VNODE_ALLOCATING) {
338 node->tn_vpstate |= TMPFS_VNODE_WANT;
339 error = msleep((caddr_t) &node->tn_vpstate,
340 TMPFS_NODE_MTX(node), PDROP | PCATCH,

--- 29 unchanged lines hidden (view full) ---

370 case VREG:
371 /* FALLTHROUGH */
372 case VSOCK:
373 break;
374 case VFIFO:
375 vp->v_op = &tmpfs_fifoop_entries;
376 break;
377 case VDIR:
345 /*
346 * otherwise lock the vp list while we call getnewvnode
347 * since that can block.
348 */
349 if (node->tn_vpstate & TMPFS_VNODE_ALLOCATING) {
350 node->tn_vpstate |= TMPFS_VNODE_WANT;
351 error = msleep((caddr_t) &node->tn_vpstate,
352 TMPFS_NODE_MTX(node), PDROP | PCATCH,

--- 29 unchanged lines hidden (view full) ---

382 case VREG:
383 /* FALLTHROUGH */
384 case VSOCK:
385 break;
386 case VFIFO:
387 vp->v_op = &tmpfs_fifoop_entries;
388 break;
389 case VDIR:
390 MPASS(node->tn_dir.tn_parent != NULL);
378 if (node->tn_dir.tn_parent == node)
379 vp->v_vflag |= VV_ROOT;
380 break;
381
382 default:
383 panic("tmpfs_alloc_vp: type %p %d", node, (int)node->tn_type);
384 }
385

--- 37 unchanged lines hidden (view full) ---

423 */
424void
425tmpfs_free_vp(struct vnode *vp)
426{
427 struct tmpfs_node *node;
428
429 node = VP_TO_TMPFS_NODE(vp);
430
391 if (node->tn_dir.tn_parent == node)
392 vp->v_vflag |= VV_ROOT;
393 break;
394
395 default:
396 panic("tmpfs_alloc_vp: type %p %d", node, (int)node->tn_type);
397 }
398

--- 37 unchanged lines hidden (view full) ---

436 */
437void
438tmpfs_free_vp(struct vnode *vp)
439{
440 struct tmpfs_node *node;
441
442 node = VP_TO_TMPFS_NODE(vp);
443
431 TMPFS_NODE_LOCK(node);
444 mtx_assert(TMPFS_NODE_MTX(node), MA_OWNED);
432 node->tn_vnode = NULL;
433 vp->v_data = NULL;
445 node->tn_vnode = NULL;
446 vp->v_data = NULL;
434 TMPFS_NODE_UNLOCK(node);
435}
436
437/* --------------------------------------------------------------------- */
438
439/*
440 * Allocates a new file of type 'type' and adds it to the parent directory
441 * 'dvp'; this addition is done using the component name given in 'cnp'.
442 * The ownership of the new file is automatically assigned based on the

--- 205 unchanged lines hidden (view full) ---

648tmpfs_dir_getdotdotdent(struct tmpfs_node *node, struct uio *uio)
649{
650 int error;
651 struct dirent dent;
652
653 TMPFS_VALIDATE_DIR(node);
654 MPASS(uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT);
655
447}
448
449/* --------------------------------------------------------------------- */
450
451/*
452 * Allocates a new file of type 'type' and adds it to the parent directory
453 * 'dvp'; this addition is done using the component name given in 'cnp'.
454 * The ownership of the new file is automatically assigned based on the

--- 205 unchanged lines hidden (view full) ---

660tmpfs_dir_getdotdotdent(struct tmpfs_node *node, struct uio *uio)
661{
662 int error;
663 struct dirent dent;
664
665 TMPFS_VALIDATE_DIR(node);
666 MPASS(uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT);
667
668 /*
669 * Return ENOENT if the current node is already removed.
670 */
671 TMPFS_ASSERT_LOCKED(node);
672 if (node->tn_dir.tn_parent == NULL) {
673 return (ENOENT);
674 }
675
676 TMPFS_NODE_LOCK(node->tn_dir.tn_parent);
656 dent.d_fileno = node->tn_dir.tn_parent->tn_id;
677 dent.d_fileno = node->tn_dir.tn_parent->tn_id;
678 TMPFS_NODE_UNLOCK(node->tn_dir.tn_parent);
679
657 dent.d_type = DT_DIR;
658 dent.d_namlen = 2;
659 dent.d_name[0] = '.';
660 dent.d_name[1] = '.';
661 dent.d_name[2] = '\0';
662 dent.d_reclen = GENERIC_DIRSIZ(&dent);
663
664 if (dent.d_reclen > uio->uio_resid)

--- 613 unchanged lines hidden ---
680 dent.d_type = DT_DIR;
681 dent.d_namlen = 2;
682 dent.d_name[0] = '.';
683 dent.d_name[1] = '.';
684 dent.d_name[2] = '\0';
685 dent.d_reclen = GENERIC_DIRSIZ(&dent);
686
687 if (dent.d_reclen > uio->uio_resid)

--- 613 unchanged lines hidden ---