Module Name:    src
Committed By:   pooka
Date:           Thu Jan 13 13:35:12 UTC 2011

Modified Files:
        src/sys/fs/tmpfs: tmpfs.h tmpfs_subr.c tmpfs_vnops.c tmpfs_vnops.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/fs/tmpfs/tmpfs.h
cvs rdiff -u -r1.61 -r1.62 src/sys/fs/tmpfs/tmpfs_subr.c
cvs rdiff -u -r1.75 -r1.76 src/sys/fs/tmpfs/tmpfs_vnops.c
cvs rdiff -u -r1.11 -r1.12 src/sys/fs/tmpfs/tmpfs_vnops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/fs/tmpfs/tmpfs.h
diff -u src/sys/fs/tmpfs/tmpfs.h:1.38 src/sys/fs/tmpfs/tmpfs.h:1.39
--- src/sys/fs/tmpfs/tmpfs.h:1.38	Tue Jun 22 18:32:07 2010
+++ src/sys/fs/tmpfs/tmpfs.h	Thu Jan 13 13:35:11 2011
@@ -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);

Index: src/sys/fs/tmpfs/tmpfs_subr.c
diff -u src/sys/fs/tmpfs/tmpfs_subr.c:1.61 src/sys/fs/tmpfs/tmpfs_subr.c:1.62
--- src/sys/fs/tmpfs/tmpfs_subr.c:1.61	Tue Nov 30 10:43:04 2010
+++ src/sys/fs/tmpfs/tmpfs_subr.c	Thu Jan 13 13:35:12 2011
@@ -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;
+		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 VDIR:
-			dentp->d_type = DT_DIR;
-			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 VFIFO:
+				dentp->d_type = DT_FIFO;
+				break;
+
+			case VLNK:
+				dentp->d_type = DT_LNK;
+				break;
+
+			case VREG:
+				dentp->d_type = DT_REG;
+				break;
 
-		case VLNK:
-			dentp->d_type = DT_LNK;
+			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));

Index: src/sys/fs/tmpfs/tmpfs_vnops.c
diff -u src/sys/fs/tmpfs/tmpfs_vnops.c:1.75 src/sys/fs/tmpfs/tmpfs_vnops.c:1.76
--- src/sys/fs/tmpfs/tmpfs_vnops.c:1.75	Tue Nov 30 10:43:04 2010
+++ src/sys/fs/tmpfs/tmpfs_vnops.c	Thu Jan 13 13:35:12 2011
@@ -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

Index: src/sys/fs/tmpfs/tmpfs_vnops.h
diff -u src/sys/fs/tmpfs/tmpfs_vnops.h:1.11 src/sys/fs/tmpfs/tmpfs_vnops.h:1.12
--- src/sys/fs/tmpfs/tmpfs_vnops.h:1.11	Mon Apr 28 20:24:02 2008
+++ src/sys/fs/tmpfs/tmpfs_vnops.h	Thu Jan 13 13:35:12 2011
@@ -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 *);
 
 /* --------------------------------------------------------------------- */
 

Reply via email to