summaryrefslogtreecommitdiffstats
path: root/sys/fs/tmpfs/tmpfs_vnops.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2007-08-10 11:00:30 +0000
committerdelphij <delphij@FreeBSD.org>2007-08-10 11:00:30 +0000
commit54967434093c09d04d57a4a94ba75d232e82d375 (patch)
treeb2c92a38ae0ffd170371166c775ddb77348fb7e8 /sys/fs/tmpfs/tmpfs_vnops.c
parentf0f8d2f251df46a5b0ae281920fcbcc216664a9b (diff)
downloadFreeBSD-src-54967434093c09d04d57a4a94ba75d232e82d375.zip
FreeBSD-src-54967434093c09d04d57a4a94ba75d232e82d375.tar.gz
MFp4:
- LK_RETRY prohibits vget() and vn_lock() to return error. Remove associated code. [1] - Properly use vhold() and vdrop() instead of their unlocked versions, we are guaranteed to have the vnode's interlock unheld. [1] - Fix a pseudo-infinite loop caused by 64/32-bit arithmetic with the same way used in modern NetBSD versions. [2] - Reorganize tmpfs_readdir to reduce duplicated code. Submitted by: kib [1] Obtained from: NetBSD [2] Approved by: re (tmpfs blanket)
Diffstat (limited to 'sys/fs/tmpfs/tmpfs_vnops.c')
-rw-r--r--sys/fs/tmpfs/tmpfs_vnops.c63
1 files changed, 22 insertions, 41 deletions
diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c
index d43e267..1d38ed9 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -1,7 +1,7 @@
-/* $NetBSD: tmpfs_vnops.c,v 1.35 2007/01/04 15:42:37 elad Exp $ */
+/* $NetBSD: tmpfs_vnops.c,v 1.39 2007/07/23 15:41:01 jmmv Exp $ */
/*
- * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -98,17 +98,14 @@ tmpfs_lookup(struct vop_cachedlookup_args *v)
int ltype = 0;
ltype = VOP_ISLOCKED(dvp, td);
- vholdl(dvp);
+ vhold(dvp);
VOP_UNLOCK(dvp, 0, td);
/* Allocate a new vnode on the matching entry. */
error = tmpfs_alloc_vp(dvp->v_mount, dnode->tn_dir.tn_parent,
cnp->cn_lkflags, vpp, td);
vn_lock(dvp, ltype | LK_RETRY, td);
- if (ltype & LK_INTERLOCK)
- vdropl(dvp);
- else
- vdrop(dvp);
+ vdrop(dvp);
dnode->tn_dir.tn_parent->tn_lookup_dirent = NULL;
} else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
@@ -1211,49 +1208,35 @@ tmpfs_readdir(struct vop_readdir_args *v)
int error;
off_t startoff;
- off_t cnt;
+ off_t cnt = 0;
struct tmpfs_node *node;
/* This operation only makes sense on directory nodes. */
- if (vp->v_type != VDIR) {
- error = ENOTDIR;
- goto out;
- }
+ if (vp->v_type != VDIR)
+ return ENOTDIR;
node = VP_TO_TMPFS_DIR(vp);
startoff = uio->uio_offset;
- cnt = 0;
- if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) {
+ switch (startoff) {
+ case TMPFS_DIRCOOKIE_DOT:
error = tmpfs_dir_getdotdent(node, uio);
- if (error == -1) {
- error = 0;
- goto outok;
- } else if (error != 0)
- goto outok;
- cnt++;
- }
-
- if (uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT) {
+ if (error == 0)
+ cnt++;
+ break;
+ case TMPFS_DIRCOOKIE_DOTDOT:
error = tmpfs_dir_getdotdotdent(node, uio);
- if (error == -1) {
- error = 0;
- goto outok;
- } else if (error != 0)
- goto outok;
- cnt++;
+ if (error == 0)
+ cnt++;
+ break;
+ default:
+ error = tmpfs_dir_getdents(node, uio, &cnt);
+ MPASS(error >= -1);
}
- error = tmpfs_dir_getdents(node, uio, &cnt);
if (error == -1)
error = 0;
- MPASS(error >= 0);
-
-outok:
- /* This label assumes that startoff has been
- * initialized. If the compiler didn't spit out warnings, we'd
- * simply make this one be 'out' and drop 'outok'. */
if (eofflag != NULL)
*eofflag =
@@ -1283,11 +1266,10 @@ outok:
MPASS(de != NULL);
de = TAILQ_NEXT(de, td_entries);
}
- if (de == NULL) {
+ if (de == NULL)
off = TMPFS_DIRCOOKIE_EOF;
- } else {
- off = TMPFS_DIRCOOKIE(de);
- }
+ else
+ off = tmpfs_dircookie(de);
}
(*cookies)[i] = off;
@@ -1295,7 +1277,6 @@ outok:
MPASS(uio->uio_offset == off);
}
-out:
return error;
}
OpenPOWER on IntegriCloud