Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/tmpfs Add some support for unionfs (not built by defa...



details:   https://anonhg.NetBSD.org/src/rev/41a547b9342a
branches:  trunk
changeset: 760812:41a547b9342a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Thu Jan 13 13:35:11 2011 +0000

description:
Add some support for unionfs (not built by default).  It's still
missing at least opaque directory support, but until someone figures
out how that should work on ffs (see PR kern/kern/44383), there's
no point in trying to figure out how it should work here.

diffstat:

 sys/fs/tmpfs/tmpfs.h       |   3 +-
 sys/fs/tmpfs/tmpfs_subr.c  |  73 +++++++++++++++++++++++++--------------------
 sys/fs/tmpfs/tmpfs_vnops.c |  51 ++++++++++++++++++++++++++++++-
 sys/fs/tmpfs/tmpfs_vnops.h |   3 +-
 4 files changed, 92 insertions(+), 38 deletions(-)

diffs (244 lines):

diff -r 3920619268fb -r 41a547b9342a sys/fs/tmpfs/tmpfs.h
--- a/sys/fs/tmpfs/tmpfs.h      Thu Jan 13 13:13:31 2011 +0000
+++ b/sys/fs/tmpfs/tmpfs.h      Thu Jan 13 13:35:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs.h,v 1.38 2010/06/22 18:32:07 rmind Exp $ */
+/*     $NetBSD: tmpfs.h,v 1.39 2011/01/13 13:35:11 pooka Exp $ */
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -262,6 +262,7 @@
                } tn_reg;
        } tn_spec;
 };
+#define TMPFS_NODE_WHITEOUT ((struct tmpfs_node *)-1)
 
 #if defined(_KERNEL)
 LIST_HEAD(tmpfs_node_list, tmpfs_node);
diff -r 3920619268fb -r 41a547b9342a sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 13 13:13:31 2011 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Thu Jan 13 13:35:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_subr.c,v 1.61 2010/11/30 10:43:04 dholland Exp $ */
+/*     $NetBSD: tmpfs_subr.c,v 1.62 2011/01/13 13:35:12 pooka Exp $    */
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.61 2010/11/30 10:43:04 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.62 2011/01/13 13:35:12 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -279,9 +279,11 @@
        memcpy(nde->td_name, name, len);
        nde->td_node = node;
 
-       node->tn_links++;
-       if (node->tn_links > 1 && node->tn_vnode != NULL)
-               VN_KNOTE(node->tn_vnode, NOTE_LINK);
+       if (node != TMPFS_NODE_WHITEOUT) {
+               node->tn_links++;
+               if (node->tn_links > 1 && node->tn_vnode != NULL)
+                       VN_KNOTE(node->tn_vnode, NOTE_LINK);
+       }
        *de = nde;
 
        return 0;
@@ -306,7 +308,7 @@
 tmpfs_free_dirent(struct tmpfs_mount *tmp, struct tmpfs_dirent *de,
     bool node_exists)
 {
-       if (node_exists) {
+       if (node_exists && de->td_node != TMPFS_NODE_WHITEOUT) {
                struct tmpfs_node *node;
 
                node = de->td_node;
@@ -769,38 +771,43 @@
        do {
                /* Create a dirent structure representing the current
                 * tmpfs_node and fill it. */
-               dentp->d_fileno = de->td_node->tn_id;
-               switch (de->td_node->tn_type) {
-               case VBLK:
-                       dentp->d_type = DT_BLK;
-                       break;
-
-               case VCHR:
-                       dentp->d_type = DT_CHR;
-                       break;
-
-               case VDIR:
-                       dentp->d_type = DT_DIR;
+               if (de->td_node == TMPFS_NODE_WHITEOUT) {
+                       dentp->d_fileno = 1;
+                       dentp->d_type = DT_WHT;
+               } else {
+                       dentp->d_fileno = de->td_node->tn_id;
+                       switch (de->td_node->tn_type) {
+                       case VBLK:
+                               dentp->d_type = DT_BLK;
                        break;
 
-               case VFIFO:
-                       dentp->d_type = DT_FIFO;
-                       break;
+                       case VCHR:
+                               dentp->d_type = DT_CHR;
+                               break;
+
+                       case VDIR:
+                               dentp->d_type = DT_DIR;
+                               break;
 
-               case VLNK:
-                       dentp->d_type = DT_LNK;
+                       case VFIFO:
+                               dentp->d_type = DT_FIFO;
+                               break;
+
+                       case VLNK:
+                               dentp->d_type = DT_LNK;
+                               break;
+
+                       case VREG:
+                               dentp->d_type = DT_REG;
+                               break;
+
+                       case VSOCK:
+                               dentp->d_type = DT_SOCK;
                        break;
 
-               case VREG:
-                       dentp->d_type = DT_REG;
-                       break;
-
-               case VSOCK:
-                       dentp->d_type = DT_SOCK;
-                       break;
-
-               default:
-                       KASSERT(0);
+                       default:
+                               KASSERT(0);
+                       }
                }
                dentp->d_namlen = de->td_namelen;
                KASSERT(de->td_namelen < sizeof(dentp->d_name));
diff -r 3920619268fb -r 41a547b9342a sys/fs/tmpfs/tmpfs_vnops.c
--- a/sys/fs/tmpfs/tmpfs_vnops.c        Thu Jan 13 13:13:31 2011 +0000
+++ b/sys/fs/tmpfs/tmpfs_vnops.c        Thu Jan 13 13:35:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_vnops.c,v 1.75 2010/11/30 10:43:04 dholland Exp $        */
+/*     $NetBSD: tmpfs_vnops.c,v 1.76 2011/01/13 13:35:12 pooka Exp $   */
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.75 2010/11/30 10:43:04 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.76 2011/01/13 13:35:12 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -106,6 +106,9 @@
        { &vop_bwrite_desc,             tmpfs_bwrite },
        { &vop_getpages_desc,           tmpfs_getpages },
        { &vop_putpages_desc,           tmpfs_putpages },
+#if TMPFS_WHITEOUT
+       { &vop_whiteout_desc,           tmpfs_whiteout },
+#endif
        { NULL, NULL }
 };
 const struct vnodeopv_desc tmpfs_vnodeop_opv_desc =
@@ -191,7 +194,7 @@
        }
 
        de = tmpfs_dir_lookup(dnode, cnp);
-       if (de == NULL) {
+       if (de == NULL || de->td_node == TMPFS_NODE_WHITEOUT) {
                /*
                 * The entry was not found in the directory.  This is valid
                 * if we are creating or renaming an entry and are working
@@ -207,6 +210,10 @@
                } else {
                        error = ENOENT;
                }
+               if (de) {
+                       KASSERT(de->td_node == TMPFS_NODE_WHITEOUT);
+                       cnp->cn_flags |= ISWHITEOUT;
+               }
        } else {
                struct tmpfs_node *tnode = de->td_node;
 
@@ -267,6 +274,7 @@
 out:
        KASSERT(IFF(error == 0, *vpp != NULL && VOP_ISLOCKED(*vpp)));
        KASSERT(VOP_ISLOCKED(dvp));
+
        return error;
 }
 
@@ -1510,3 +1518,40 @@
 
        return error;
 }
+
+/* --------------------------------------------------------------------- */
+
+#ifdef TMPFS_WHITEOUT
+int
+tmpfs_whiteout(void *v)
+{
+       struct vnode *dvp = ((struct vop_whiteout_args *)v)->a_dvp;
+       struct componentname *cnp = ((struct vop_whiteout_args *)v)->a_cnp;
+       int flags = ((struct vop_whiteout_args *)v)->a_flags;
+       struct tmpfs_mount *tmp = VFS_TO_TMPFS(dvp->v_mount);
+       struct tmpfs_dirent *de;
+       int error;
+
+       switch (flags) {
+       case LOOKUP:
+               break;
+       case CREATE:
+               error = tmpfs_alloc_dirent(tmp, TMPFS_NODE_WHITEOUT,
+                   cnp->cn_nameptr, cnp->cn_namelen, &de);
+               if (error)
+                       return error;
+               tmpfs_dir_attach(dvp, de);
+               break;
+       case DELETE:
+               cnp->cn_flags &= ~DOWHITEOUT; /* when in doubt, cargo cult */
+               de = tmpfs_dir_lookup(VP_TO_TMPFS_DIR(dvp), cnp);
+               if (de == NULL)
+                       return ENOENT;
+               tmpfs_dir_detach(dvp, de);
+               tmpfs_free_dirent(tmp, de, true);
+               break;
+       }
+
+       return 0;
+}
+#endif
diff -r 3920619268fb -r 41a547b9342a sys/fs/tmpfs/tmpfs_vnops.h
--- a/sys/fs/tmpfs/tmpfs_vnops.h        Thu Jan 13 13:13:31 2011 +0000
+++ b/sys/fs/tmpfs/tmpfs_vnops.h        Thu Jan 13 13:35:11 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_vnops.h,v 1.11 2008/04/28 20:24:02 martin Exp $  */
+/*     $NetBSD: tmpfs_vnops.h,v 1.12 2011/01/13 13:35:12 pooka Exp $   */
 
 /*
  * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@@ -87,6 +87,7 @@
 #define        tmpfs_bwrite            genfs_nullop
 int    tmpfs_getpages          (void *);
 int    tmpfs_putpages          (void *);
+int    tmpfs_whiteout          (void *);
 
 /* --------------------------------------------------------------------- */
 



Home | Main Index | Thread Index | Old Index