linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: hooanon05@yahoo.co.jp
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Junjiro Okajima <hooanon05@yahoo.co.jp>
Subject: [PATCH 45/67] aufs inode functions
Date: Fri, 16 May 2008 23:32:59 +0900	[thread overview]
Message-ID: <1210948402867-git-send-email-hooanon05@yahoo.co.jp> (raw)
In-Reply-To: <12109484022004-git-send-email-hooanon05@yahoo.co.jp>

From: Junjiro Okajima <hooanon05@yahoo.co.jp>

	initial commit
	aufs inode functions

Signed-off-by: Junjiro Okajima <hooanon05@yahoo.co.jp>
---
 fs/aufs/inode.c |  425 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 425 insertions(+), 0 deletions(-)

diff --git a/fs/aufs/inode.c b/fs/aufs/inode.c
new file mode 100644
index 0000000..7bab2cc
--- /dev/null
+++ b/fs/aufs/inode.c
@@ -0,0 +1,425 @@
+/*
+ * Copyright (C) 2005-2008 Junjiro Okajima
+ *
+ * This program, aufs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/*
+ * inode functions
+ *
+ * $Id: inode.c,v 1.3 2008/04/28 03:04:12 sfjro Exp $
+ */
+
+#include "aufs.h"
+
+int au_refresh_hinode_self(struct inode *inode)
+{
+	int err, new_sz, update;
+	struct inode *first;
+	struct au_hinode *p, *q, tmp;
+	struct super_block *sb;
+	struct au_iinfo *iinfo;
+	aufs_bindex_t bindex, bend, new_bindex;
+
+	LKTRTrace("i%lu\n", inode->i_ino);
+	IiMustWriteLock(inode);
+
+	err = -ENOMEM;
+	update = 0;
+	sb = inode->i_sb;
+	bend = au_sbend(sb);
+	new_sz = sizeof(*iinfo->ii_hinode) * (bend + 1);
+	iinfo = au_ii(inode);
+	p = au_kzrealloc(iinfo->ii_hinode, sizeof(*p) * (iinfo->ii_bend + 1),
+			 new_sz, GFP_KERNEL);
+	//p = NULL;
+	if (unlikely(!p))
+		goto out;
+
+	iinfo->ii_hinode = p;
+	p = iinfo->ii_hinode + iinfo->ii_bstart;
+	first = p->hi_inode;
+	err = 0;
+	for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
+	     bindex++, p++) {
+		if (!p->hi_inode)
+			continue;
+
+		new_bindex = au_br_index(sb, p->hi_id);
+		if (new_bindex == bindex)
+			continue;
+		if (new_bindex < 0) {
+			update++;
+			au_hiput(p);
+			p->hi_inode = NULL;
+			continue;
+		}
+
+		if (new_bindex < iinfo->ii_bstart)
+			iinfo->ii_bstart = new_bindex;
+		if (iinfo->ii_bend < new_bindex)
+			iinfo->ii_bend = new_bindex;
+		/* swap two hidden inode, and loop again */
+		q = iinfo->ii_hinode + new_bindex;
+		tmp = *q;
+		*q = *p;
+		*p = tmp;
+		if (tmp.hi_inode) {
+			bindex--;
+			p--;
+		}
+	}
+	au_update_brange(inode, /*do_put_zero*/0);
+
+	if (unlikely(err))
+		goto out;
+
+	if (1 || first != au_h_iptr(inode, iinfo->ii_bstart))
+		au_cpup_attr_all(inode);
+	if (update && S_ISDIR(inode->i_mode))
+		inode->i_version++;
+	au_update_iigen(inode);
+
+ out:
+	AuTraceErr(err);
+	return err;
+}
+
+int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
+{
+	int err, update, isdir;
+	struct inode *first;
+	struct au_hinode *p;
+	struct super_block *sb;
+	struct au_iinfo *iinfo;
+	aufs_bindex_t bindex, bend;
+	unsigned int flags;
+
+	LKTRTrace("%.*s\n", AuDLNPair(dentry));
+	IiMustWriteLock(inode);
+
+	err = au_refresh_hinode_self(inode);
+	if (unlikely(err))
+		goto out;
+
+	sb = dentry->d_sb;
+	bend = au_sbend(sb);
+	iinfo = au_ii(inode);
+	update = 0;
+	p = iinfo->ii_hinode + iinfo->ii_bstart;
+	first = p->hi_inode;
+	isdir = S_ISDIR(inode->i_mode);
+	flags = au_hi_flags(inode, isdir);
+	bend = au_dbend(dentry);
+	for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
+		struct inode *hi;
+		struct dentry *hd;
+
+		hd = au_h_dptr(dentry, bindex);
+		if (!hd || !hd->d_inode)
+			continue;
+
+		if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
+			hi = au_h_iptr(inode, bindex);
+			if (hi) {
+				if (hi == hd->d_inode)
+					continue;
+				err = -ESTALE;
+				break;
+			}
+		}
+		if (bindex < iinfo->ii_bstart)
+			iinfo->ii_bstart = bindex;
+		if (iinfo->ii_bend < bindex)
+			iinfo->ii_bend = bindex;
+		au_set_h_iptr(inode, bindex, igrab(hd->d_inode), flags);
+		update++;
+	}
+	au_update_brange(inode, /*do_put_zero*/0);
+
+	if (unlikely(err))
+		goto out;
+
+	if (1 || first != au_h_iptr(inode, iinfo->ii_bstart))
+		au_cpup_attr_all(inode);
+	if (update && isdir)
+		inode->i_version++;
+	au_update_iigen(inode);
+
+ out:
+	AuTraceErr(err);
+	return err;
+}
+
+static int set_inode(struct inode *inode, struct dentry *dentry)
+{
+	int err, isdir;
+	struct dentry *h_dentry;
+	struct inode *h_inode;
+	umode_t mode;
+	aufs_bindex_t bindex, bstart, btail;
+	struct au_iinfo *iinfo;
+	unsigned int flags;
+
+	LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(dentry));
+	AuDebugOn(!(inode->i_state & I_NEW));
+	IiMustWriteLock(inode);
+	bstart = au_dbstart(dentry);
+	h_dentry = au_h_dptr(dentry, bstart);
+	AuDebugOn(!h_dentry);
+	h_inode = h_dentry->d_inode;
+	AuDebugOn(!h_inode);
+
+	err = 0;
+	isdir = 0;
+	mode = h_inode->i_mode;
+	switch (mode & S_IFMT) {
+	case S_IFREG:
+		btail = au_dbtail(dentry);
+		break;
+	case S_IFDIR:
+		isdir = 1;
+		btail = au_dbtaildir(dentry);
+		inode->i_op = &aufs_dir_iop;
+		inode->i_fop = &aufs_dir_fop;
+		break;
+	case S_IFLNK:
+		btail = au_dbtail(dentry);
+		inode->i_op = &aufs_symlink_iop;
+		break;
+	case S_IFBLK:
+	case S_IFCHR:
+	case S_IFIFO:
+	case S_IFSOCK:
+		btail = au_dbtail(dentry);
+		init_special_inode(inode, mode,
+				   au_h_rdev(h_inode, /*h_mnt*/NULL, h_dentry));
+		break;
+	default:
+		AuIOErr("Unknown file type 0%o\n", mode);
+		err = -EIO;
+		goto out;
+	}
+
+	flags = au_hi_flags(inode, isdir);
+	iinfo = au_ii(inode);
+	iinfo->ii_bstart = bstart;
+	iinfo->ii_bend = btail;
+	for (bindex = bstart; bindex <= btail; bindex++) {
+		h_dentry = au_h_dptr(dentry, bindex);
+		if (!h_dentry)
+			continue;
+		AuDebugOn(!h_dentry->d_inode);
+		au_set_h_iptr(inode, bindex, igrab(h_dentry->d_inode), flags);
+	}
+	au_cpup_attr_all(inode);
+
+ out:
+	AuTraceErr(err);
+	return err;
+}
+
+/* successful returns with iinfo write_locked */
+//todo: return with unlocked?
+static int reval_inode(struct inode *inode, struct dentry *dentry, int *matched)
+{
+	int err;
+	struct inode *h_inode, *h_dinode;
+	aufs_bindex_t bindex, bend;
+#if 0
+	const int hinotify = au_opt_test(au_mntflags(inode->i_sb),
+					 UDBA_INOTIFY);
+#endif
+
+	LKTRTrace("i%lu, %.*s\n", inode->i_ino, AuDLNPair(dentry));
+
+	*matched = 0;
+
+	/*
+	 * before this function, if aufs got any iinfo lock, it must be only
+	 * one, the parent dir.
+	 * it can happen by UDBA and the obsoleted inode number.
+	 */
+	err = -EIO;
+	if (unlikely(inode->i_ino == parent_ino(dentry)))
+		goto out;
+
+	err = 0;
+	h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
+	mutex_lock_nested(&inode->i_mutex, AuLsc_I_CHILD);
+	ii_write_lock_new(inode);
+	bend = au_ibend(inode);
+	for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
+		h_inode = au_h_iptr(inode, bindex);
+		if (h_inode && h_inode == h_dinode) {
+			//&& (ibs != bstart || !au_test_higen(inode, h_inode)));
+			*matched = 1;
+			err = 0;
+			if (unlikely(au_iigen(inode) != au_digen(dentry)))
+				err = au_refresh_hinode(inode, dentry);
+			break;
+		}
+	}
+	if (unlikely(err))
+		ii_write_unlock(inode);
+	mutex_unlock(&inode->i_mutex);
+
+ out:
+	AuTraceErr(err);
+	return err;
+}
+
+/* successful returns with iinfo write_locked */
+//todo: return with unlocked?
+struct inode *au_new_inode(struct dentry *dentry)
+{
+	struct inode *inode, *h_inode;
+	struct dentry *h_dentry;
+	ino_t h_ino;
+	struct super_block *sb;
+	int err, match;
+	aufs_bindex_t bstart;
+	struct au_xino_entry xinoe;
+
+	LKTRTrace("%.*s\n", AuDLNPair(dentry));
+	sb = dentry->d_sb;
+	bstart = au_dbstart(dentry);
+	h_dentry = au_h_dptr(dentry, bstart);
+	AuDebugOn(!h_dentry);
+	h_inode = h_dentry->d_inode;
+	AuDebugOn(!h_inode);
+
+	h_ino = h_inode->i_ino;
+	err = au_xino_read(sb, bstart, h_ino, &xinoe);
+	//err = -1;
+	inode = ERR_PTR(err);
+	if (unlikely(err))
+		goto out;
+ new_ino:
+	if (!xinoe.ino) {
+		xinoe.ino = au_xino_new_ino(sb);
+		if (!xinoe.ino) {
+			inode = ERR_PTR(-EIO);
+			goto out;
+		}
+	}
+
+	LKTRTrace("i%lu\n", xinoe.ino);
+	inode = au_iget_locked(sb, xinoe.ino);
+	err = PTR_ERR(inode);
+	if (IS_ERR(inode))
+		goto out;
+
+	LKTRTrace("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
+	if (inode->i_state & I_NEW) {
+		ii_write_lock_new(inode);
+		err = set_inode(inode, dentry);
+		//err = -1;
+		unlock_new_inode(inode);
+		if (!err)
+			goto out; /* success */
+		iget_failed(inode);
+		ii_write_unlock(inode);
+		goto out_iput;
+	} else {
+		//todo: remove this
+		AuDebugOn(inode->i_state & I_LOCK);
+		err = reval_inode(inode, dentry, &match);
+		if (!err)
+			goto out; /* success */
+		else if (match)
+			goto out_iput;
+	}
+
+	if (unlikely(au_test_unique_ino(h_dentry, h_ino)))
+		AuWarn1("Un-notified UDBA or repeatedly renamed dir,"
+			" b%d, %s, %.*s, hi%lu, i%lu.\n",
+			bstart, au_sbtype(h_dentry->d_sb), AuDLNPair(dentry),
+			h_ino, xinoe.ino);
+#if 0 // debug
+	{
+		static unsigned char c;
+		if (!c++) {
+			struct dentry *d = d_find_alias(inode);
+			au_debug_on();
+			DbgDentry(dentry);
+			DbgInode(inode);
+			if (d) {
+				DbgDentry(d);
+				dput(d);
+			}
+			au_debug_off();
+		}
+	}
+#endif
+	xinoe.ino = 0;
+	err = au_xino_write0(sb, bstart, h_ino, 0);
+	if (!err) {
+		iput(inode);
+		goto new_ino;
+	}
+	/* force noxino? */
+
+ out_iput:
+	iput(inode);
+	inode = ERR_PTR(err);
+ out:
+	AuTraceErrPtr(inode);
+	return inode;
+}
+
+/* ---------------------------------------------------------------------- */
+
+int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
+	       struct inode *inode)
+{
+	int err;
+
+	err = au_br_rdonly(au_sbr(sb, bindex));
+
+	/* pseudo-link after flushed may out of bounds */
+	if (!err
+	    && inode
+	    && au_ibstart(inode) <= bindex
+	    && bindex <= au_ibend(inode)) {
+		/*
+		 * permission check is unnecessary since vfsub routine
+		 * will be called later
+		 */
+		struct inode *hi = au_h_iptr(inode, bindex);
+		if (hi)
+			err = IS_IMMUTABLE(hi) ? -EROFS : 0;
+	}
+
+	AuTraceErr(err);
+	return err;
+}
+
+int au_test_h_perm(struct inode *h_inode, int mask, int dlgt)
+{
+	if (!current->fsuid)
+		return 0;
+	//todo: fake nameidata
+	return vfsub_permission(h_inode, mask, NULL, dlgt);
+}
+
+int au_test_h_perm_sio(struct inode *h_inode, int mask, int dlgt)
+{
+	if (unlikely(au_test_nfs(h_inode->i_sb)
+		     && (mask & MAY_WRITE)
+		     && S_ISDIR(h_inode->i_mode)))
+		mask |= MAY_READ; /* force permission check */
+	return au_test_h_perm(h_inode, mask, dlgt);
+}
-- 
1.4.4.4


  reply	other threads:[~2008-05-16 14:42 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-16 14:32 [PATCH 1/67] aufs document hooanon05
2008-05-16 14:32 ` [PATCH 2/67] aufs manual hooanon05
2008-05-16 14:32   ` [PATCH 3/67] aufs global header file hooanon05
2008-05-16 14:32     ` [PATCH 4/67] aufs configuration hooanon05
2008-05-16 14:32       ` [PATCH 5/67] aufs Makefile hooanon05
2008-05-16 14:32         ` [PATCH 6/67] aufs main header file hooanon05
2008-05-16 14:32           ` [PATCH 7/67] aufs module initialization and module-global hooanon05
2008-05-16 14:32             ` [PATCH 8/67] aufs module global variables and operations hooanon05
2008-05-16 14:32               ` [PATCH 9/67] aufs super_block operations hooanon05
2008-05-16 14:32                 ` [PATCH 10/67] aufs mount and " hooanon05
2008-05-16 14:32                   ` [PATCH 11/67] aufs superblock private data hooanon05
2008-05-16 14:32                     ` [PATCH 12/67] aufs branch filesystems and xino for them hooanon05
2008-05-16 14:32                       ` [PATCH 13/67] aufs branch management hooanon05
2008-05-16 14:32                         ` [PATCH 14/67] aufs external inode number translation table and bitmap hooanon05
2008-05-16 14:32                           ` [PATCH 15/67] aufs special handling for inode attributes on FUSE branch hooanon05
2008-05-16 14:32                             ` [PATCH 16/67] aufs lookup functions for NFS branch in linux-2.6.19 and later hooanon05
2008-05-16 14:32                               ` [PATCH 17/67] aufs special handling inode attributes on XFS branch in linux-2.6.24 " hooanon05
2008-05-16 14:32                                 ` [PATCH 18/67] aufs sysfs interface and lifetime management, header hooanon05
2008-05-16 14:32                                   ` [PATCH 19/67] aufs sysfs interface and lifetime management, source hooanon05
2008-05-16 14:32                                     ` [PATCH 20/67] aufs mount options/flags, header hooanon05
2008-05-16 14:32                                       ` [PATCH 21/67] aufs mount options/flags, source hooanon05
2008-05-16 14:32                                         ` [PATCH 22/67] aufs workqueue for asynchronous/super-io/delegated operations, header hooanon05
2008-05-16 14:32                                           ` [PATCH 23/67] aufs workqueue for asynchronous/super-io/delegated operations, source hooanon05
2008-05-16 14:32                                             ` [PATCH 24/67] aufs sub-VFS, header hooanon05
2008-05-16 14:32                                               ` [PATCH 25/67] aufs sub-VFS, source hooanon05
2008-05-16 14:32                                                 ` [PATCH 26/67] aufs sub-dcache, header hooanon05
2008-05-16 14:32                                                   ` [PATCH 27/67] aufs sub-dcache, source hooanon05
2008-05-16 14:32                                                     ` [PATCH 28/67] aufs copy-up/down functions hooanon05
2008-05-16 14:32                                                       ` [PATCH 29/67] aufs copy-up functions, see wbr_policy.c for copy-down hooanon05
2008-05-16 14:32                                                         ` [PATCH 30/67] aufs whiteout for logical deletion and opaque directory, header hooanon05
2008-05-16 14:32                                                           ` [PATCH 31/67] aufs whiteout for logical deletion and opaque directory, source hooanon05
2008-05-16 14:32                                                             ` [PATCH 32/67] aufs pseudo-link hooanon05
2008-05-16 14:32                                                               ` [PATCH 33/67] aufs policies for selecting one among multiple writable branches hooanon05
2008-05-16 14:32                                                                 ` [PATCH 34/67] aufs lookup and dentry operations, header hooanon05
2008-05-16 14:32                                                                   ` [PATCH 35/67] aufs lookup and dentry operations, source hooanon05
2008-05-16 14:32                                                                     ` [PATCH 36/67] aufs dentry private data hooanon05
2008-05-16 14:32                                                                       ` [PATCH 37/67] aufs file operations hooanon05
2008-05-16 14:32                                                                         ` [PATCH 38/67] aufs handling file/dir, and address_space operation hooanon05
2008-05-16 14:32                                                                           ` [PATCH 39/67] aufs file private data hooanon05
2008-05-16 14:32                                                                             ` [PATCH 40/67] aufs file and vm operations hooanon05
2008-05-16 14:32                                                                               ` [PATCH 41/67] aufs directory operations, header hooanon05
2008-05-16 14:32                                                                                 ` [PATCH 42/67] aufs directory operations, source hooanon05
2008-05-16 14:32                                                                                   ` [PATCH 43/67] aufs virtual or vertical directory hooanon05
2008-05-16 14:32                                                                                     ` [PATCH 44/67] aufs inode operations hooanon05
2008-05-16 14:32                                                                                       ` hooanon05 [this message]
2008-05-16 14:33                                                                                         ` [PATCH 46/67] aufs inode private data hooanon05
2008-05-16 14:33                                                                                           ` [PATCH 47/67] aufs inode operations (except add/del/rename) hooanon05
2008-05-16 14:33                                                                                             ` [PATCH 48/67] aufs inode operations (add entry) hooanon05
2008-05-16 14:33                                                                                               ` [PATCH 49/67] aufs inode operations (del entry) hooanon05
2008-05-16 14:33                                                                                                 ` [PATCH 50/67] aufs inode operation (rename entry) hooanon05
2008-05-16 14:33                                                                                                   ` [PATCH 51/67] aufs lower (branch filesystem) inode and setting inotify hooanon05
2008-05-16 14:33                                                                                                     ` [PATCH 52/67] aufs inotify handler hooanon05
2008-05-16 14:33                                                                                                       ` [PATCH 53/67] aufs sub-routines for vfs in hinotify or dlgt mode hooanon05
2008-05-16 14:33                                                                                                         ` [PATCH 54/67] aufs lookup functions in 'delegate' mode hooanon05
2008-05-16 14:33                                                                                                           ` [PATCH 55/67] aufs export via nfs hooanon05
2008-05-16 14:33                                                                                                             ` [PATCH 56/67] aufs 'robr', aufs as readonly branch of another aufs hooanon05
2008-05-16 14:33                                                                                                               ` [PATCH 57/67] aufs sysfs interface hooanon05
2008-05-16 14:33                                                                                                                 ` [PATCH 58/67] aufs misc functions, header hooanon05
2008-05-16 14:33                                                                                                                   ` [PATCH 59/67] aufs misc functions, source hooanon05
2008-05-16 14:33                                                                                                                     ` [PATCH 60/67] aufs debug print functions, header hooanon05
2008-05-16 14:33                                                                                                                       ` [PATCH 61/67] aufs debug print functions, source hooanon05
2008-05-16 14:33                                                                                                                         ` [PATCH 62/67] aufs magic sysrq handler hooanon05
2008-05-16 14:33                                                                                                                           ` [PATCH 63/67] aufs mount helper hooanon05
2008-05-16 14:33                                                                                                                             ` [PATCH 64/67] aufs pseudo-link helper hooanon05
2008-05-16 14:33                                                                                                                               ` [PATCH 65/67] aufs pseudo-link helper for symlink hooanon05
2008-05-16 14:33                                                                                                                                 ` [PATCH 66/67] aufs umount helper hooanon05
2008-05-16 14:33                                                                                                                                   ` [PATCH 67/67] merge aufs hooanon05
2008-05-16 15:36               ` [PATCH 8/67] aufs module global variables and operations Jan Engelhardt
2008-05-16 15:33           ` [PATCH 6/67] aufs main header file Jan Engelhardt
2008-05-16 17:25         ` [PATCH 5/67] aufs Makefile Sam Ravnborg
2008-05-19  2:27           ` hooanon05
2008-05-16 15:28       ` [PATCH 4/67] aufs configuration Jan Engelhardt
2008-05-19  2:23         ` hooanon05
2008-05-16 14:59 ` [PATCH 1/67] aufs document Dave Quigley
2008-05-16 15:32   ` Jan Engelhardt
2008-05-16 21:07     ` Josef 'Jeff' Sipek
2008-05-19  2:25     ` hooanon05
2008-05-16 15:45   ` hooanon05
2008-05-16 16:09     ` Dave Quigley
2008-05-17  2:06       ` hooanon05

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1210948402867-git-send-email-hooanon05@yahoo.co.jp \
    --to=hooanon05@yahoo.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).