Skip to contentSkip to conversation

ino lookup patch

PATCH Peter Braam 1 participant 1 message May 23, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Ted,

I've taken your patch for inode lookup. We use it in a slightly different form in Lustre now as a file handle cache.

Your patch could get into trouble if the ino that you find under __iopen__ is a directory and you populate that with sub-dentries, while also using a named dentry for the same inode.

What we do now is similar to NFS file handle handling. I hope it's useful.

- Peter -

 Documentation/filesystems/ext2.txt |   16 ++
 fs/ext3/Makefile                   |    2 
 fs/ext3/inode.c                    |    4 
 fs/ext3/iopen.c                    |  240 +++++++++++++++++++++++++++++++++++++
 fs/ext3/iopen.h                    |   15 ++
 fs/ext3/namei.c                    |   13 +-
 fs/ext3/super.c                    |   11 +
 include/linux/ext3_fs.h            |    2 
 8 files changed, 301 insertions(+), 2 deletions(-)
Documentation/filesystems/ext2.txt renamed from Documentation/filesystems/ext2.txt~iopen +16 -0
@@ -35,6 +35,22 @@ resgid=n			The group ID which may use th
 
 sb=n				Use alternate superblock at this location.
 
+iopen				Makes an invisible pseudo-directory called 
+				__iopen__ available in the root directory
+				of the filesystem.  Allows open-by-inode-
+				number.  i.e., inode 3145 can be accessed
+				via /mntpt/__iopen__/3145
+
+iopen_nopriv			This option makes the iopen directory be
+				world-readable.  This may be safer since it
+				allows daemons to run as an unprivileged user,
+				however it significantly changes the security
+				model of a Unix filesystem, since previously
+				all files under a mode 700 directory were not
+				generally avilable even if the
+				permissions on the file itself is
+				world-readable.
+
 grpquota,noquota,quota,usrquota	Quota options are silently ignored by ext2.
 
 
fs/ext3/Makefile renamed from fs/ext3/Makefile~iopen +1 -1
@@ -11,7 +11,7 @@ O_TARGET := ext3.o
 
 export-objs := ext3-exports.o
 
-obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
+obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
 		ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
 obj-m    := $(O_TARGET)
 
fs/ext3/inode.c renamed from fs/ext3/inode.c~iopen +4 -0
@@ -31,6 +31,7 @@
 #include <linux/highuid.h>
 #include <linux/quotaops.h>
 #include <linux/module.h>
+#include "iopen.h"
 
 /*
  * SEARCH_FROM_ZERO forces each block allocation to search from the start
@@ -2137,6 +2138,9 @@ void ext3_read_inode(struct inode * inod
 	struct buffer_head *bh;
 	int block;
 	
+	if (ext3_iopen_get_inode(inode))
+		return;
+	
 	if(ext3_get_inode_loc(inode, &iloc))
 		goto bad_inode;
 	bh = iloc.bh;
fs/ext3/iopen.c new file +240 -0

240 lines not on this page · raw message

fs/ext3/iopen.h new file +15 -0
@@ -0,0 +1,15 @@
+/*
+ * iopen.h
+ *
+ * Special support for opening files by inode number.
+ * 
+ * Copyright (C) 2001 by Theodore Ts'o ([email protected]).
+ * 
+ * This file may be redistributed under the terms of the GNU General
+ * Public License.
+ */
+
+extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
+extern int ext3_iopen_get_inode(struct inode * inode);
+
+
fs/ext3/namei.c renamed from fs/ext3/namei.c~iopen +12 -1
@@ -35,7 +35,7 @@
 #include <linux/string.h>
 #include <linux/locks.h>
 #include <linux/quotaops.h>
-
+#include "iopen.h"
 
 /*
  * define how far ahead to read directories while searching them.
@@ -921,16 +921,21 @@ errout:
 	return NULL;
 }
 #endif
+struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
 
 static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry)
 {
 	struct inode * inode;
 	struct ext3_dir_entry_2 * de;
 	struct buffer_head * bh;
+        struct dentry *alternate = NULL;
 
 	if (dentry->d_name.len > EXT3_NAME_LEN)
 		return ERR_PTR(-ENAMETOOLONG);
 
+	if (ext3_check_for_iopen(dir, dentry))
+		return NULL;
+
 	bh = ext3_find_entry(dentry, &de);
 	inode = NULL;
 	if (bh) {
@@ -942,6 +947,12 @@ static struct dentry *ext3_lookup(struct
 			return ERR_PTR(-EACCES);
 		}
 	}
+                
+        if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
+                iput(inode);
+                return alternate;
+        }
+
 	d_add(dentry, inode);
 	return NULL;
 }
fs/ext3/super.c renamed from fs/ext3/super.c~iopen +11 -0
@@ -820,6 +820,17 @@ static int parse_options (char * options
 		         || !strcmp (this_char, "quota")
 		         || !strcmp (this_char, "usrquota"))
 			/* Don't do anything ;-) */ ;
+		else if (!strcmp (this_char, "iopen")) {
+			set_opt (sbi->s_mount_opt, IOPEN);
+			clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
+		} else if (!strcmp (this_char, "noiopen")) {
+			clear_opt (sbi->s_mount_opt, IOPEN);
+			clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
+		}
+		else if (!strcmp (this_char, "iopen_nopriv")) {
+			set_opt (sbi->s_mount_opt, IOPEN);
+			set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
+		}
 		else if (!strcmp (this_char, "journal")) {
 			/* @@@ FIXME */
 			/* Eventually we will want to be able to create
include/linux/ext3_fs.h renamed from include/linux/ext3_fs.h~iopen +2 -0
@@ -322,6 +322,8 @@ struct ext3_inode {
 #define EXT3_MOUNT_UPDATE_JOURNAL	0x1000	/* Update the journal format */
 #define EXT3_MOUNT_NO_UID32		0x2000  /* Disable 32-bit UIDs */
 #define EXT3_MOUNT_XATTR_USER		0x4000	/* Extended user attributes */
+#define EXT3_MOUNT_IOPEN		0x8000  /* Allow access via iopen */
+#define EXT3_MOUNT_IOPEN_NOPRIV		0x10000  /* Make iopen world-readable */
 #define EXT3_MOUNT_ASYNCDEL	       0x20000  /* Delayed deletion */
 
 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */

_