1 Index: linux-2.6.16.27-0.9/fs/ext3/iopen.c
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.16.27-0.9/fs/ext3/iopen.c 2007-06-29 08:33:12.000000000 +0200
7 + * linux/fs/ext3/iopen.c
9 + * Special support for open by inode number
11 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
13 + * This file may be redistributed under the terms of the GNU General
18 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
19 + * for an inode at one time.
20 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
21 + * aliases on an inode at the same time.
23 + * If we have any connected dentry aliases for an inode, use one of those
24 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
25 + * dentry for this inode, which thereafter will be found by the dcache
26 + * when looking up this inode number in __iopen__, so we don't return here
29 + * If we get an inode via a regular name lookup, then we "rename" the
30 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
31 + * existing users of the disconnected dentry will continue to use the same
32 + * dentry as the connected users, and there will never be both kinds of
33 + * dentry aliases at one time.
36 +#include <linux/sched.h>
37 +#include <linux/fs.h>
38 +#include <linux/ext3_jbd.h>
39 +#include <linux/jbd.h>
40 +#include <linux/ext3_fs.h>
41 +#include <linux/smp_lock.h>
42 +#include <linux/dcache.h>
43 +#include <linux/security.h>
47 +#define assert(test) J_ASSERT(test)
50 +#define IOPEN_NAME_LEN 32
53 + * This implements looking up an inode by number.
55 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
56 + struct nameidata *nd)
58 + struct inode *inode;
60 + struct list_head *lp;
61 + struct dentry *alternate;
62 + char buf[IOPEN_NAME_LEN];
64 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
65 + return ERR_PTR(-ENAMETOOLONG);
67 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
68 + buf[dentry->d_name.len] = 0;
70 + if (strcmp(buf, ".") == 0)
72 + else if (strcmp(buf, "..") == 0)
73 + ino = EXT3_ROOT_INO;
75 + ino = simple_strtoul(buf, 0, 0);
77 + if ((ino != EXT3_ROOT_INO &&
78 + //ino != EXT3_ACL_IDX_INO &&
79 + //ino != EXT3_ACL_DATA_INO &&
80 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
81 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
82 + return ERR_PTR(-ENOENT);
84 + inode = iget(dir->i_sb, ino);
86 + return ERR_PTR(-EACCES);
87 + if (is_bad_inode(inode)) {
89 + return ERR_PTR(-ENOENT);
92 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
93 + assert(d_unhashed(dentry)); /* d_rehash */
95 + /* preferrably return a connected dentry */
96 + spin_lock(&dcache_lock);
97 + list_for_each(lp, &inode->i_dentry) {
98 + alternate = list_entry(lp, struct dentry, d_alias);
99 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
102 + if (!list_empty(&inode->i_dentry)) {
103 + alternate = list_entry(inode->i_dentry.next,
104 + struct dentry, d_alias);
105 + dget_locked(alternate);
106 + spin_lock(&alternate->d_lock);
107 + alternate->d_flags |= DCACHE_REFERENCED;
108 + spin_unlock(&alternate->d_lock);
110 + spin_unlock(&dcache_lock);
113 + dentry->d_flags |= DCACHE_DISCONNECTED;
115 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
116 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
117 + dentry->d_inode = inode;
119 + d_rehash_cond(dentry, 0); /* d_rehash */
120 + spin_unlock(&dcache_lock);
125 +/* This function is spliced into ext3_lookup and does the move of a
126 + * disconnected dentry (if it exists) to a connected dentry.
128 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
131 + struct dentry *tmp, *goal = NULL;
132 + struct list_head *lp;
134 + /* verify this dentry is really new */
135 + assert(dentry->d_inode == NULL);
136 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
138 + assert(d_unhashed(dentry)); /* d_rehash */
139 + assert(list_empty(&dentry->d_subdirs));
141 + spin_lock(&dcache_lock);
145 + if (!test_opt(inode->i_sb, IOPEN))
146 + goto do_instantiate;
148 + /* preferrably return a connected dentry */
149 + list_for_each(lp, &inode->i_dentry) {
150 + tmp = list_entry(lp, struct dentry, d_alias);
151 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
152 + assert(tmp->d_alias.next == &inode->i_dentry);
153 + assert(tmp->d_alias.prev == &inode->i_dentry);
161 + goto do_instantiate;
163 + /* Move the goal to the de hash queue */
164 + goal->d_flags &= ~DCACHE_DISCONNECTED;
165 + security_d_instantiate(goal, inode);
167 + d_rehash_cond(dentry, 0);
168 + __d_move(goal, dentry);
169 + spin_unlock(&dcache_lock);
174 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
176 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
177 + dentry->d_inode = inode;
180 + d_rehash_cond(dentry, 0); /* d_rehash */
181 + spin_unlock(&dcache_lock);
187 + * These are the special structures for the iopen pseudo directory.
190 +static struct inode_operations iopen_inode_operations = {
191 + lookup: iopen_lookup, /* BKL held */
194 +static struct file_operations iopen_file_operations = {
195 + read: generic_read_dir,
198 +static int match_dentry(struct dentry *dentry, const char *name)
202 + len = strlen(name);
203 + if (dentry->d_name.len != len)
205 + if (strncmp(dentry->d_name.name, name, len))
211 + * This function is spliced into ext3_lookup and returns 1 the file
212 + * name is __iopen__ and dentry has been filled in appropriately.
214 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
216 + struct inode *inode;
218 + if (dir->i_ino != EXT3_ROOT_INO ||
219 + !test_opt(dir->i_sb, IOPEN) ||
220 + !match_dentry(dentry, "__iopen__"))
223 + inode = iget(dir->i_sb, EXT3_BAD_INO);
227 + d_add(dentry, inode);
232 + * This function is spliced into read_inode; it returns 1 if inode
233 + * number is the one for /__iopen__, in which case the inode is filled
234 + * in appropriately. Otherwise, this fuction returns 0.
236 +int ext3_iopen_get_inode(struct inode *inode)
238 + if (inode->i_ino != EXT3_BAD_INO)
241 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
242 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
243 + inode->i_mode |= 0777;
246 + inode->i_nlink = 1;
247 + inode->i_size = 4096;
248 + inode->i_atime = CURRENT_TIME;
249 + inode->i_ctime = CURRENT_TIME;
250 + inode->i_mtime = CURRENT_TIME;
251 + EXT3_I(inode)->i_dtime = 0;
252 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
253 + * (for stat), not the fs block
255 + inode->i_blocks = 0;
256 + inode->i_version = 1;
257 + inode->i_generation = 0;
259 + inode->i_op = &iopen_inode_operations;
260 + inode->i_fop = &iopen_file_operations;
261 + inode->i_mapping->a_ops = 0;
265 Index: linux-2.6.16.27-0.9/fs/ext3/iopen.h
266 ===================================================================
267 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
268 +++ linux-2.6.16.27-0.9/fs/ext3/iopen.h 2007-06-29 08:24:49.000000000 +0200
273 + * Special support for opening files by inode number.
275 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
277 + * This file may be redistributed under the terms of the GNU General
281 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
282 +extern int ext3_iopen_get_inode(struct inode *inode);
283 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
284 + struct inode *inode, int rehash);
285 Index: linux-2.6.16.27-0.9/fs/ext3/inode.c
286 ===================================================================
287 --- linux-2.6.16.27-0.9.orig/fs/ext3/inode.c 2007-06-29 08:24:48.000000000 +0200
288 +++ linux-2.6.16.27-0.9/fs/ext3/inode.c 2007-06-29 08:24:52.000000000 +0200
290 #include <linux/mpage.h>
291 #include <linux/uio.h>
296 static int ext3_writepage_trans_blocks(struct inode *inode);
297 @@ -2448,6 +2449,8 @@ void ext3_read_inode(struct inode * inod
298 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
300 ei->i_block_alloc_info = NULL;
301 + if (ext3_iopen_get_inode(inode))
304 if (__ext3_get_inode_loc(inode, &iloc, 0))
306 Index: linux-2.6.16.27-0.9/fs/ext3/super.c
307 ===================================================================
308 --- linux-2.6.16.27-0.9.orig/fs/ext3/super.c 2007-06-29 08:24:48.000000000 +0200
309 +++ linux-2.6.16.27-0.9/fs/ext3/super.c 2007-06-29 08:24:52.000000000 +0200
310 @@ -678,6 +678,7 @@ enum {
311 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
312 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
313 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
314 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
318 @@ -726,6 +727,9 @@ static match_table_t tokens = {
319 {Opt_noquota, "noquota"},
320 {Opt_quota, "quota"},
321 {Opt_usrquota, "usrquota"},
322 + {Opt_iopen, "iopen"},
323 + {Opt_noiopen, "noiopen"},
324 + {Opt_iopen_nopriv, "iopen_nopriv"},
325 {Opt_barrier, "barrier=%u"},
327 {Opt_resize, "resize"},
328 @@ -1040,6 +1044,18 @@ clear_qf_name:
330 clear_opt(sbi->s_mount_opt, BARRIER);
333 + set_opt (sbi->s_mount_opt, IOPEN);
334 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
337 + clear_opt (sbi->s_mount_opt, IOPEN);
338 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
340 + case Opt_iopen_nopriv:
341 + set_opt (sbi->s_mount_opt, IOPEN);
342 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
347 Index: linux-2.6.16.27-0.9/fs/ext3/namei.c
348 ===================================================================
349 --- linux-2.6.16.27-0.9.orig/fs/ext3/namei.c 2007-06-29 08:24:47.000000000 +0200
350 +++ linux-2.6.16.27-0.9/fs/ext3/namei.c 2007-06-29 08:24:49.000000000 +0200
359 @@ -1004,6 +1005,9 @@ static struct dentry *ext3_lookup(struct
360 if (dentry->d_name.len > EXT3_NAME_LEN)
361 return ERR_PTR(-ENAMETOOLONG);
363 + if (ext3_check_for_iopen(dir, dentry))
366 bh = ext3_find_entry(dentry, &de);
369 @@ -1014,7 +1018,7 @@ static struct dentry *ext3_lookup(struct
371 return ERR_PTR(-EACCES);
373 - return d_splice_alias(inode, dentry);
374 + return iopen_connect_dentry(dentry, inode, 1);
378 @@ -2058,10 +2062,6 @@ static int ext3_rmdir (struct inode * di
382 - /* There's no need to set i_disksize: the fact that i_nlink is
383 - * zero will ensure that the right thing happens during any
386 ext3_orphan_add(handle, inode);
387 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
388 ext3_mark_inode_dirty(handle, inode);
389 @@ -2185,6 +2185,23 @@ out_stop:
393 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
394 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
395 + struct inode *inode)
397 + int err = ext3_add_entry(handle, dentry, inode);
399 + err = ext3_mark_inode_dirty(handle, inode);
401 + dput(iopen_connect_dentry(dentry, inode, 0));
405 + ext3_dec_count(handle, inode);
410 static int ext3_link (struct dentry * old_dentry,
411 struct inode * dir, struct dentry *dentry)
413 @@ -2208,7 +2225,8 @@ retry:
414 ext3_inc_count(handle, inode);
415 atomic_inc(&inode->i_count);
417 - err = ext3_add_nondir(handle, dentry, inode);
418 + err = ext3_add_link(handle, dentry, inode);
419 + ext3_orphan_del(handle, inode);
420 ext3_journal_stop(handle);
421 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
423 Index: linux-2.6.16.27-0.9/fs/ext3/Makefile
424 ===================================================================
425 --- linux-2.6.16.27-0.9.orig/fs/ext3/Makefile 2007-03-13 00:56:52.000000000 +0100
426 +++ linux-2.6.16.27-0.9/fs/ext3/Makefile 2007-06-29 08:24:49.000000000 +0200
429 obj-$(CONFIG_EXT3_FS) += ext3.o
431 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
432 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
433 ioctl.o namei.o super.o symlink.o hash.o resize.o
435 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
436 Index: linux-2.6.16.27-0.9/include/linux/ext3_fs.h
437 ===================================================================
438 --- linux-2.6.16.27-0.9.orig/include/linux/ext3_fs.h 2007-06-29 08:24:47.000000000 +0200
439 +++ linux-2.6.16.27-0.9/include/linux/ext3_fs.h 2007-06-29 08:24:49.000000000 +0200
440 @@ -375,6 +375,8 @@ struct ext3_inode {
441 #define EXT3_MOUNT_QUOTA 0x80000 /* Some quota option set */
442 #define EXT3_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
443 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
444 +#define EXT3_MOUNT_IOPEN 0x400000 /* Allow access via iopen */
445 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x800000/* Make iopen world-readable */
447 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
448 #ifndef _LINUX_EXT2_FS_H