Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/fs/tmpfs - Simplify tmpfs_update(), eliminate tmpfs_note...
details: https://anonhg.NetBSD.org/src/rev/aa392a5c5d1b
branches: trunk
changeset: 791560:aa392a5c5d1b
user: rmind <rmind%NetBSD.org@localhost>
date: Sat Nov 23 16:35:32 2013 +0000
description:
- Simplify tmpfs_update(), eliminate tmpfs_note_t::tn_status and deferred
timestamp updates. Fix some incorrect updates and plug some missing ones.
Should fix PR/48385.
- tmpfs_rmdir: avoid O(n) scan when the directory is not empty and whiteout
entries were never added.
diffstat:
sys/fs/tmpfs/tmpfs.h | 27 +++-----
sys/fs/tmpfs/tmpfs_fifoops.c | 12 +--
sys/fs/tmpfs/tmpfs_rename.c | 28 ++++----
sys/fs/tmpfs/tmpfs_specops.c | 12 +--
sys/fs/tmpfs/tmpfs_subr.c | 126 +++++++++++++++++-------------------------
sys/fs/tmpfs/tmpfs_vfsops.c | 10 ++-
sys/fs/tmpfs/tmpfs_vnops.c | 115 +++++++++++++++++++++-----------------
7 files changed, 156 insertions(+), 174 deletions(-)
diffs (truncated from 937 to 300 lines):
diff -r cb21a3fc82c8 -r aa392a5c5d1b sys/fs/tmpfs/tmpfs.h
--- a/sys/fs/tmpfs/tmpfs.h Sat Nov 23 16:15:24 2013 +0000
+++ b/sys/fs/tmpfs/tmpfs.h Sat Nov 23 16:35:32 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs.h,v 1.47 2013/11/18 01:39:34 rmind Exp $ */
+/* $NetBSD: tmpfs.h,v 1.48 2013/11/23 16:35:32 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -101,9 +101,6 @@
ino_t tn_id;
uint32_t tn_gen;
- /* Inode status flags (for operations in delayed manner). */
- unsigned tn_status;
-
/* The inode size. */
off_t tn_size;
@@ -183,20 +180,18 @@
/* Mark to indicate that the number is not set. */
#define TMPFS_DIRSEQ_NONE (1U << 31)
-/* Status flags. */
-#define TMPFS_NODE_ACCESSED 0x01
-#define TMPFS_NODE_MODIFIED 0x02
-#define TMPFS_NODE_CHANGED 0x04
-
-#define TMPFS_NODE_STATUSALL \
- (TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED | TMPFS_NODE_CHANGED)
+/* Flags: time update requests. */
+#define TMPFS_UPDATE_ATIME 0x01
+#define TMPFS_UPDATE_MTIME 0x02
+#define TMPFS_UPDATE_CTIME 0x04
/*
- * Bit indicating vnode reclamation.
+ * Bits indicating vnode reclamation and whiteout use for the directory.
* We abuse tmpfs_node_t::tn_gen for that.
*/
#define TMPFS_RECLAIMING_BIT (1U << 31)
-#define TMPFS_NODE_GEN_MASK (TMPFS_RECLAIMING_BIT - 1)
+#define TMPFS_WHITEOUT_BIT (1U << 30)
+#define TMPFS_NODE_GEN_MASK (TMPFS_WHITEOUT_BIT - 1)
#define TMPFS_NODE_RECLAIMING(node) \
(((node)->tn_gen & TMPFS_RECLAIMING_BIT) != 0)
@@ -249,7 +244,7 @@
mode_t, char *, dev_t, tmpfs_node_t **);
void tmpfs_free_node(tmpfs_mount_t *, tmpfs_node_t *);
-int tmpfs_alloc_file(vnode_t *, vnode_t **, struct vattr *,
+int tmpfs_construct_node(vnode_t *, vnode_t **, struct vattr *,
struct componentname *, char *);
int tmpfs_vnode_get(struct mount *, tmpfs_node_t *, vnode_t **);
@@ -268,7 +263,6 @@
int tmpfs_dir_getdents(tmpfs_node_t *, struct uio *, off_t *);
int tmpfs_reg_resize(vnode_t *, off_t);
-int tmpfs_truncate(vnode_t *, off_t);
int tmpfs_chflags(vnode_t *, int, kauth_cred_t, lwp_t *);
int tmpfs_chmod(vnode_t *, mode_t, kauth_cred_t, lwp_t *);
@@ -277,8 +271,7 @@
int tmpfs_chtimes(vnode_t *, const struct timespec *,
const struct timespec *, const struct timespec *, int,
kauth_cred_t, lwp_t *);
-void tmpfs_update(vnode_t *, const struct timespec *,
- const struct timespec *, const struct timespec *, int);
+void tmpfs_update(vnode_t *, unsigned);
/*
* Prototypes for tmpfs_mem.c.
diff -r cb21a3fc82c8 -r aa392a5c5d1b sys/fs/tmpfs/tmpfs_fifoops.c
--- a/sys/fs/tmpfs/tmpfs_fifoops.c Sat Nov 23 16:15:24 2013 +0000
+++ b/sys/fs/tmpfs/tmpfs_fifoops.c Sat Nov 23 16:35:32 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_fifoops.c,v 1.9 2011/05/24 20:17:49 rmind Exp $ */
+/* $NetBSD: tmpfs_fifoops.c,v 1.10 2013/11/23 16:35:32 rmind Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_fifoops.c,v 1.9 2011/05/24 20:17:49 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_fifoops.c,v 1.10 2013/11/23 16:35:32 rmind Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
@@ -103,10 +103,8 @@
struct vnode *a_vp;
int a_fflag;
kauth_cred_t a_cred;
- } */ *ap = v;
- vnode_t *vp = ap->a_vp;
+ } */ *ap __unused = v;
- tmpfs_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
return VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), v);
}
@@ -121,7 +119,7 @@
} */ *ap = v;
vnode_t *vp = ap->a_vp;
- VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_ACCESSED;
+ tmpfs_update(vp, TMPFS_UPDATE_ATIME);
return VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), v);
}
@@ -136,6 +134,6 @@
} */ *ap = v;
vnode_t *vp = ap->a_vp;
- VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_MODIFIED;
+ tmpfs_update(vp, TMPFS_UPDATE_MTIME);
return VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), v);
}
diff -r cb21a3fc82c8 -r aa392a5c5d1b sys/fs/tmpfs/tmpfs_rename.c
--- a/sys/fs/tmpfs/tmpfs_rename.c Sat Nov 23 16:15:24 2013 +0000
+++ b/sys/fs/tmpfs/tmpfs_rename.c Sat Nov 23 16:35:32 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_rename.c,v 1.5 2013/11/08 15:44:23 rmind Exp $ */
+/* $NetBSD: tmpfs_rename.c,v 1.6 2013/11/23 16:35:32 rmind Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_rename.c,v 1.5 2013/11/08 15:44:23 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_rename.c,v 1.6 2013/11/23 16:35:32 rmind Exp $");
#include <sys/param.h>
#include <sys/errno.h>
@@ -266,6 +266,8 @@
struct vnode *tdvp, struct componentname *tcnp,
void *tde, struct vnode *tvp)
{
+ tmpfs_node_t *fdnode = VP_TO_TMPFS_DIR(fdvp);
+ tmpfs_node_t *tdnode = VP_TO_TMPFS_DIR(tdvp);
struct tmpfs_dirent **fdep = fde;
struct tmpfs_dirent **tdep = tde;
char *newname;
@@ -313,9 +315,6 @@
* source entry and reattach it to the target directory.
*/
if (fdvp != tdvp) {
- tmpfs_node_t *fdnode = VP_TO_TMPFS_DIR(fdvp);
- tmpfs_node_t *tdnode = VP_TO_TMPFS_DIR(tdvp);
-
tmpfs_dir_detach(fdnode, *fdep);
tmpfs_dir_attach(tdnode, *fdep, VP_TO_TMPFS_NODE(fvp));
} else if (tvp == NULL) {
@@ -334,7 +333,7 @@
* XXX What if the target is a directory with whiteout entries?
*/
if (tvp != NULL) {
- tmpfs_node_t *tdnode = VP_TO_TMPFS_DIR(tdvp);
+ tdnode = VP_TO_TMPFS_DIR(tdvp);
KASSERT((*tdep) != NULL);
KASSERT((*tdep)->td_node == VP_TO_TMPFS_NODE(tvp));
@@ -346,11 +345,6 @@
/*
* Decrement the extra link count for `.' so
* the vnode will be recycled when released.
- *
- * XXX Why not just release directory vnodes
- * when their link count is 1 instead of 0 in
- * tmpfs_inactive, since `.' is being treated
- * specially anyway?
*/
VP_TO_TMPFS_NODE(tvp)->tn_links--;
}
@@ -373,10 +367,15 @@
(*fdep)->td_namelen = (uint16_t)tcnp->cn_namelen;
(void)memcpy(newname, tcnp->cn_nameptr, tcnp->cn_namelen);
(*fdep)->td_name = newname;
+ }
- VP_TO_TMPFS_NODE(fvp)->tn_status |= TMPFS_NODE_CHANGED;
- VP_TO_TMPFS_NODE(tdvp)->tn_status |= TMPFS_NODE_MODIFIED;
- }
+ /*
+ * Update the timestamps of both parent directories and
+ * the renamed file itself.
+ */
+ tmpfs_update(fdvp, TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME);
+ tmpfs_update(tdvp, TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME);
+ tmpfs_update(fvp, TMPFS_UPDATE_CTIME);
VN_KNOTE(fvp, NOTE_RENAME);
@@ -412,6 +411,7 @@
tmpfs_dir_detach(dnode, *dep);
tmpfs_free_dirent(VFS_TO_TMPFS(mp), *dep);
+ tmpfs_update(dvp, TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME);
return 0;
}
diff -r cb21a3fc82c8 -r aa392a5c5d1b sys/fs/tmpfs/tmpfs_specops.c
--- a/sys/fs/tmpfs/tmpfs_specops.c Sat Nov 23 16:15:24 2013 +0000
+++ b/sys/fs/tmpfs/tmpfs_specops.c Sat Nov 23 16:35:32 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_specops.c,v 1.10 2011/05/24 20:17:49 rmind Exp $ */
+/* $NetBSD: tmpfs_specops.c,v 1.11 2013/11/23 16:35:32 rmind Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_specops.c,v 1.10 2011/05/24 20:17:49 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_specops.c,v 1.11 2013/11/23 16:35:32 rmind Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
@@ -106,10 +106,8 @@
struct vnode *a_vp;
int a_fflag;
kauth_cred_t a_cred;
- } */ *ap = v;
- vnode_t *vp = ap->a_vp;
+ } */ *ap __unused = v;
- tmpfs_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
return VOCALL(spec_vnodeop_p, VOFFSET(vop_close), v);
}
@@ -124,7 +122,7 @@
} */ *ap = v;
vnode_t *vp = ap->a_vp;
- VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_ACCESSED;
+ tmpfs_update(vp, TMPFS_UPDATE_ATIME);
return VOCALL(spec_vnodeop_p, VOFFSET(vop_read), v);
}
@@ -139,6 +137,6 @@
} */ *ap = v;
vnode_t *vp = ap->a_vp;
- VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_MODIFIED;
+ tmpfs_update(vp, TMPFS_UPDATE_MTIME);
return VOCALL(spec_vnodeop_p, VOFFSET(vop_write), v);
}
diff -r cb21a3fc82c8 -r aa392a5c5d1b sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Sat Nov 23 16:15:24 2013 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Sat Nov 23 16:35:32 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_subr.c,v 1.89 2013/11/21 14:39:09 rmind Exp $ */
+/* $NetBSD: tmpfs_subr.c,v 1.90 2013/11/23 16:35:32 rmind Exp $ */
/*
* Copyright (c) 2005-2013 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
* reference counting and link counting. That is, an inode can only be
* destroyed if its associated vnode is inactive. The destruction is
* done on vnode reclamation i.e. tmpfs_reclaim(). It should be noted
- * that tmpfs_node_t::tn_links being 0 is a destruction criterion.
+ * that tmpfs_node_t::tn_links being 0 is a destruction criterion.
*
* If an inode has references within the file system (tn_links > 0) and
* its inactive vnode gets reclaimed/recycled - then the association is
@@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.89 2013/11/21 14:39:09 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.90 2013/11/23 16:35:32 rmind Exp $");
#include <sys/param.h>
#include <sys/cprng.h>
@@ -132,7 +132,6 @@
/* Generic initialization. */
nnode->tn_type = type;
nnode->tn_size = 0;
- nnode->tn_status = 0;
nnode->tn_flags = 0;
nnode->tn_lockf = NULL;
@@ -244,6 +243,7 @@
}
break;
case VDIR:
+ KASSERT(node->tn_size == 0);
KASSERT(node->tn_spec.tn_dir.tn_seq_arena == NULL);
KASSERT(TAILQ_EMPTY(&node->tn_spec.tn_dir.tn_dir));
KASSERT(node->tn_spec.tn_dir.tn_parent == NULL ||
@@ -252,6 +252,7 @@
default:
break;
}
Home |
Main Index |
Thread Index |
Old Index