head	1.1;
access;
symbols
	LKML-branch:1.1.0.2;
locks; strict;
comment	@# @;


1.1
date	2006.10.24.06.14.17;	author jsipek;	state dead;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2006.10.24.06.14.17;	author jsipek;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2006.11.07.06.13.33;	author jsipek;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2006.11.28.08.30.13;	author jsipek;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2006.12.01.02.28.38;	author jsipek;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2006.12.01.02.36.12;	author jsipek;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2006.12.03.21.49.41;	author jsipek;	state Exp;
branches;
next	1.1.2.7;

1.1.2.7
date	2006.12.11.14.23.59;	author jsipek;	state Exp;
branches;
next	1.1.2.8;

1.1.2.8
date	2007.01.05.08.50.39;	author jsipek;	state Exp;
branches;
next	1.1.2.9;

1.1.2.9
date	2007.01.21.23.59.13;	author jsipek;	state Exp;
branches;
next	1.1.2.10;

1.1.2.10
date	2007.01.25.08.38.30;	author jsipek;	state Exp;
branches;
next	1.1.2.11;

1.1.2.11
date	2007.01.28.22.24.33;	author jsipek;	state Exp;
branches;
next	;


desc
@@


1.1
log
@file dops was initially added on branch LKML-branch.
@
text
@@


1.1.2.1
log
@Move unionfs specific bits into a subdir
@
text
@a0 258
Unionfs: Dentry operations

From: Josef "Jeff" Sipek <jsipek@@cs.sunysb.edu>

This patch contains the dentry operations for Unionfs.

Signed-off-by: Josef "Jeff" Sipek <jsipek@@cs.sunysb.edu>
Signed-off-by: David Quigley <dquigley@@fsl.cs.sunysb.edu>
Signed-off-by: Erez Zadok <ezk@@cs.sunysb.edu>

diff -r 4f458391a116 fs/unionfs/dentry.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fs/unionfs/dentry.c	Sat Oct 07 00:22:20 2006 -0400
@@@@ -0,0 +1,244 @@@@
+/*
+ * Copyright (c) 2003-2006 Erez Zadok
+ * Copyright (c) 2003-2006 Charles P. Wright
+ * Copyright (c) 2005-2006 Josef 'Jeff' Sipek
+ * Copyright (c) 2005-2006 Junjiro Okajima
+ * Copyright (c) 2005      Arun M. Krishnakumar
+ * Copyright (c) 2004-2006 David P. Quigley
+ * Copyright (c) 2003-2004 Mohammad Nayyer Zubair
+ * Copyright (c) 2003      Puja Gupta
+ * Copyright (c) 2003      Harikesavan Krishnan
+ * Copyright (c) 2003-2006 Stony Brook University
+ * Copyright (c) 2003-2006 The Research Foundation of State University of New York
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "union.h"
+
+/* declarations added for "sparse" */
+extern int unionfs_d_revalidate_wrap(struct dentry *dentry,
+				     struct nameidata *nd);
+extern void unionfs_d_release(struct dentry *dentry);
+extern void unionfs_d_iput(struct dentry *dentry, struct inode *inode);
+
+/*
+ * returns 1 if valid, 0 otherwise.
+ */
+int unionfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
+{
+	int valid = 1;		/* default is valid (1); invalid is 0. */
+	struct dentry *hidden_dentry;
+	int bindex, bstart, bend;
+	int sbgen, dgen;
+	int positive = 0;
+	int locked = 0;
+	int restart = 0;
+	int interpose_flag;
+
+	struct nameidata lowernd;
+
+	if (nd)
+		memcpy(&lowernd, nd, sizeof(struct nameidata));
+	else
+		memset(&lowernd, 0, sizeof(struct nameidata));
+
+restart:
+	verify_locked(dentry);
+
+	/* if the dentry is unhashed, do NOT revalidate */
+	if (d_deleted(dentry)) {
+		printk(KERN_DEBUG "unhashed dentry being revalidated: %*s\n",
+		       dentry->d_name.len, dentry->d_name.name);
+		goto out;
+	}
+
+	BUG_ON(dbstart(dentry) == -1);
+	if (dentry->d_inode)
+		positive = 1;
+	dgen = atomic_read(&dtopd(dentry)->udi_generation);
+	sbgen = atomic_read(&stopd(dentry->d_sb)->usi_generation);
+	/* If we are working on an unconnected dentry, then there is no
+	 * revalidation to be done, because this file does not exist within the
+	 * namespace, and Unionfs operates on the namespace, not data.
+	 */
+	if (sbgen != dgen) {
+		struct dentry *result;
+		int pdgen;
+
+		unionfs_read_lock(dentry->d_sb);
+		locked = 1;
+
+		/* The root entry should always be valid */
+		BUG_ON(IS_ROOT(dentry));
+
+		/* We can't work correctly if our parent isn't valid. */
+		pdgen = atomic_read(&dtopd(dentry->d_parent)->udi_generation);
+		if (!restart && (pdgen != sbgen)) {
+			unionfs_read_unlock(dentry->d_sb);
+			locked = 0;
+			/* We must be locked before our parent. */
+			if (!
+			    (dentry->d_parent->d_op->
+			     d_revalidate(dentry->d_parent, nd))) {
+				valid = 0;
+				goto out;
+			}
+			restart = 1;
+			goto restart;
+		}
+		BUG_ON(pdgen != sbgen);
+
+		/* Free the pointers for our inodes and this dentry. */
+		bstart = dbstart(dentry);
+		bend = dbend(dentry);
+		if (bstart >= 0) {
+			struct dentry *hidden_dentry;
+			for (bindex = bstart; bindex <= bend; bindex++) {
+				hidden_dentry =
+				    dtohd_index_nocheck(dentry, bindex);
+				if (!hidden_dentry)
+					continue;
+				dput(hidden_dentry);
+			}
+		}
+		set_dbstart(dentry, -1);
+		set_dbend(dentry, -1);
+
+		interpose_flag = INTERPOSE_REVAL_NEG;
+		if (positive) {
+			interpose_flag = INTERPOSE_REVAL;
+			mutex_lock(&dentry->d_inode->i_mutex);
+			bstart = ibstart(dentry->d_inode);
+			bend = ibend(dentry->d_inode);
+			if (bstart >= 0) {
+				struct inode *hidden_inode;
+				for (bindex = bstart; bindex <= bend; bindex++) {
+					hidden_inode =
+					    itohi_index(dentry->d_inode,
+							bindex);
+					if (!hidden_inode)
+						continue;
+					iput(hidden_inode);
+				}
+			}
+			kfree(itohi_ptr(dentry->d_inode));
+			itohi_ptr(dentry->d_inode) = NULL;
+			ibstart(dentry->d_inode) = -1;
+			ibend(dentry->d_inode) = -1;
+			mutex_unlock(&dentry->d_inode->i_mutex);
+		}
+
+		result = unionfs_lookup_backend(dentry, &lowernd, interpose_flag);
+		if (result) {
+			if (IS_ERR(result)) {
+				valid = 0;
+				goto out;
+			}
+			/* current unionfs_lookup_backend() doesn't return
+			   a valid dentry */
+			dput(dentry);
+			dentry = result;
+		}
+
+		if (positive && itopd(dentry->d_inode)->uii_stale) {
+			make_stale_inode(dentry->d_inode);
+			d_drop(dentry);
+			valid = 0;
+			goto out;
+		}
+		goto out;
+	}
+
+	/* The revalidation must occur across all branches */
+	bstart = dbstart(dentry);
+	bend = dbend(dentry);
+	BUG_ON(bstart == -1);
+	for (bindex = bstart; bindex <= bend; bindex++) {
+		hidden_dentry = dtohd_index(dentry, bindex);
+		if (!hidden_dentry || !hidden_dentry->d_op
+		    || !hidden_dentry->d_op->d_revalidate)
+			continue;
+
+		if (!hidden_dentry->d_op->d_revalidate(hidden_dentry, nd))
+			valid = 0;
+	}
+
+	if (!dentry->d_inode)
+		valid = 0;
+	if (valid)
+		fist_copy_attr_all(dentry->d_inode, itohi(dentry->d_inode));
+
+out:
+	if (locked)
+		unionfs_read_unlock(dentry->d_sb);
+	return valid;
+}
+
+int unionfs_d_revalidate_wrap(struct dentry *dentry, struct nameidata *nd)
+{
+	int err;
+
+	lock_dentry(dentry);
+
+	err = unionfs_d_revalidate(dentry, nd);
+
+	unlock_dentry(dentry);
+	return err;
+}
+
+void unionfs_d_release(struct dentry *dentry)
+{
+	int bindex, bstart, bend;
+
+	/* There is no reason to lock the dentry, because we have the only
+	 * reference, but the printing functions verify that we have a lock
+	 * on the dentry before calling dbstart, etc. */
+	lock_dentry(dentry);
+
+	/* this could be a negative dentry, so check first */
+	if (!dtopd(dentry)) {
+		printk(KERN_DEBUG "dentry without private data: %.*s",
+		       dentry->d_name.len, dentry->d_name.name);
+		goto out;
+	} else if (dbstart(dentry) < 0) {
+		/* this is due to a failed lookup */
+		/* the failed lookup has a dtohd_ptr set to null,
+		   but this is a better check */
+		printk(KERN_DEBUG "dentry without hidden dentries : %.*s",
+		       dentry->d_name.len, dentry->d_name.name);
+		goto out_free;
+	}
+
+	/* Release all the hidden dentries */
+	bstart = dbstart(dentry);
+	bend = dbend(dentry);
+	for (bindex = bstart; bindex <= bend; bindex++) {
+		dput(dtohd_index(dentry, bindex));
+		mntput(dtohm_index(dentry, bindex));
+
+		set_dtohd_index(dentry, bindex, NULL);
+		set_dtohm_index(dentry, bindex, NULL);
+	}
+	/* free private data (unionfs_dentry_info) here */
+	kfree(dtohd_ptr(dentry));
+	kfree(dtohm_ptr(dentry));
+	dtohd_ptr(dentry) = NULL;
+	dtohm_ptr(dentry) = NULL;
+
+out_free:
+	/* No need to unlock it, because it is disappeared. */
+	free_dentry_private_data(dtopd(dentry));
+	dtopd_lhs(dentry) = NULL;	/* just to be safe */
+
+out:
+	return;
+}
+
+struct dentry_operations unionfs_dops = {
+	.d_revalidate = unionfs_d_revalidate_wrap,
+	.d_release = unionfs_d_release,
+};
+
@


1.1.2.2
log
@Git generates slightly different diffs - same information, just little
different
@
text
@d11 3
a13 5
diff --git a/fs/unionfs/dentry.c b/fs/unionfs/dentry.c
new file mode 100644
index 0000000..9b5abc3
--- /dev/null
+++ b/fs/unionfs/dentry.c
@


1.1.2.3
log
@Collapsed: struct_path-unionfs unionfs-fix-comments unionfs-kill-wrappers
@
text
@d14 3
a16 5

diff -r 72f151c3065b fs/unionfs/dentry.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fs/unionfs/dentry.c	Tue Nov 28 03:21:11 2006 -0500
@@@@ -0,0 +1,242 @@@@
d242 4
a245 2
+	kfree(dtohp_ptr(dentry));
+	dtohp_ptr(dentry) = NULL;
@


1.1.2.4
log
@Sync
@
text
@d17 2
a18 2
+++ b/fs/unionfs/dentry.c	Thu Nov 30 21:12:10 2006 -0500
@@@@ -0,0 +1,243 @@@@
d190 1
a190 2
+		fsstack_copy_attr_all(dentry->d_inode, itohi(dentry->d_inode),
+				unionfs_get_nlinks);
@


1.1.2.5
log
@Remove git crud & nicer makefile
@
text
@d11 4
@


1.1.2.6
log
@Collapsed macro patch into unionfs proper
@
text
@d11 1
a11 1
diff -r f0be90ec65a9 fs/unionfs/dentry.c
d13 2
a14 2
+++ b/fs/unionfs/dentry.c	Sun Dec 03 16:36:57 2006 -0500
@@@@ -0,0 +1,236 @@@@
d55 1
a55 1
+	struct nameidata lowernd; /* TODO: be gentler to the stack */
d75 2
a76 2
+	dgen = atomic_read(&UNIONFS_D(dentry)->generation);
+	sbgen = atomic_read(&UNIONFS_SB(dentry->d_sb)->generation);
d92 1
a92 1
+		pdgen = atomic_read(&UNIONFS_D(dentry->d_parent)->generation);
d115 3
a117 1
+				    unionfs_lower_dentry_idx(dentry, bindex);
d134 1
a134 1
+					    unionfs_lower_inode_idx(dentry->d_inode,
d136 2
d141 2
a142 2
+			kfree(UNIONFS_I(dentry->d_inode)->lower_inodes);
+			UNIONFS_I(dentry->d_inode)->lower_inodes = NULL;
d160 1
a160 1
+		if (positive && UNIONFS_I(dentry->d_inode)->stale) {
d174 1
a174 1
+		hidden_dentry = unionfs_lower_dentry_idx(dentry, bindex);
d186 1
a186 1
+		fsstack_copy_attr_all(dentry->d_inode, unionfs_lower_inode(dentry->d_inode),
d200 1
d202 1
a203 1
+
d217 1
a217 1
+	if (!UNIONFS_D(dentry)) {
d223 2
d234 2
a235 2
+		dput(unionfs_lower_dentry_idx(dentry, bindex));
+		mntput(unionfs_lower_mnt_idx(dentry, bindex));
d237 2
a238 2
+		unionfs_set_lower_dentry_idx(dentry, bindex, NULL);
+		unionfs_set_lower_mnt_idx(dentry, bindex, NULL);
d241 2
a242 2
+	kfree(UNIONFS_D(dentry)->lower_paths);
+	UNIONFS_D(dentry)->lower_paths = NULL;
d246 2
a247 2
+	free_dentry_private_data(UNIONFS_D(dentry));
+	dentry->d_fsdata = NULL;	/* just to be safe */
@


1.1.2.7
log
@Folded unionfs-lkml-comments-jan
@
text
@d11 1
a11 1
diff -r 8b47a9db56d1 fs/unionfs/dentry.c
d13 2
a14 2
+++ b/fs/unionfs/dentry.c	Mon Dec 11 09:02:29 2006 -0500
@@@@ -0,0 +1,239 @@@@
d151 1
a151 2
+			 * a valid dentry
+			 */
d182 1
a182 2
+		fsstack_copy_attr_all(dentry->d_inode,
+				unionfs_lower_inode(dentry->d_inode),
d208 1
a208 2
+	 * on the dentry before calling dbstart, etc.
+	 */
d247 2
a248 2
+	.d_revalidate	= unionfs_d_revalidate_wrap,
+	.d_release	= unionfs_d_release,
@


1.1.2.8
log
@Fix up unionfs wrt commit ba3ff12f...
@
text
@d11 4
a14 6
diff --git a/fs/unionfs/dentry.c b/fs/unionfs/dentry.c
new file mode 100644
index 0000000..740c000
--- /dev/null
+++ b/fs/unionfs/dentry.c
@@@@ -0,0 +1,243 @@@@
d182 1
a182 2
+
+	if (valid) {
a185 3
+		fsstack_copy_inode_size(dentry->d_inode,
+				unionfs_lower_inode(dentry->d_inode));
+	}
@


1.1.2.9
log
@A. Bunk's patch, more akpm comments, new copyright
@
text
@d13 1
a13 1
index 0000000..78de9c9
d18 1
a18 1
+ * Copyright (c) 2003-2007 Erez Zadok
d20 1
a20 1
+ * Copyright (c) 2005-2007 Josef 'Jeff' Sipek
d27 2
a28 2
+ * Copyright (c) 2003-2007 Stony Brook University
+ * Copyright (c) 2003-2007 The Research Foundation of State University of New York
@


1.1.2.10
log
@Removed stale_inode.c & associated patches

stale_inode.c seemed to be completely superfluous, and needed to be synced
up with current version of bad_inode.c or dropped. Dropping is considerably
cleaner.
@
text
@d13 1
a13 1
index 0000000..0b002d1
d160 1
a160 1
+			make_bad_inode(dentry->d_inode);
@


1.1.2.11
log
@Remove stale_inode.c the proper way - separate patch
@
text
@d13 1
a13 1
index 0000000..78de9c9
d160 1
a160 1
+			make_stale_inode(dentry->d_inode);
@


