1 Index: linux-2.6.5-7.311/fs/ext3/Makefile
2 ===================================================================
3 --- linux-2.6.5-7.311.orig/fs/ext3/Makefile
4 +++ linux-2.6.5-7.311/fs/ext3/Makefile
7 obj-$(CONFIG_EXT3_FS) += ext3.o
9 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
10 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
11 ioctl.o namei.o super.o symlink.o hash.o
13 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
14 Index: linux-2.6.5-7.311/fs/ext3/inode.c
15 ===================================================================
16 --- linux-2.6.5-7.311.orig/fs/ext3/inode.c
17 +++ linux-2.6.5-7.311/fs/ext3/inode.c
19 #include <linux/mpage.h>
20 #include <linux/uio.h>
26 @@ -2419,6 +2420,9 @@ void ext3_read_inode(struct inode * inod
28 ei->i_rsv_window.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED;
30 + if (ext3_iopen_get_inode(inode))
33 if (ext3_get_inode_loc(inode, &iloc, 0))
36 Index: linux-2.6.5-7.311/fs/ext3/iopen.c
37 ===================================================================
39 +++ linux-2.6.5-7.311/fs/ext3/iopen.c
42 + * linux/fs/ext3/iopen.c
44 + * Special support for open by inode number
46 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
48 + * This file may be redistributed under the terms of the GNU General
53 + * - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
54 + * for an inode at one time.
55 + * - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
56 + * aliases on an inode at the same time.
58 + * If we have any connected dentry aliases for an inode, use one of those
59 + * in iopen_lookup(). Otherwise, we instantiate a single NFSD_DISCONNECTED
60 + * dentry for this inode, which thereafter will be found by the dcache
61 + * when looking up this inode number in __iopen__, so we don't return here
64 + * If we get an inode via a regular name lookup, then we "rename" the
65 + * NFSD_DISCONNECTED dentry to the proper name and parent. This ensures
66 + * existing users of the disconnected dentry will continue to use the same
67 + * dentry as the connected users, and there will never be both kinds of
68 + * dentry aliases at one time.
71 +#include <linux/sched.h>
72 +#include <linux/fs.h>
73 +#include <linux/ext3_jbd.h>
74 +#include <linux/jbd.h>
75 +#include <linux/ext3_fs.h>
76 +#include <linux/smp_lock.h>
77 +#include <linux/dcache.h>
78 +#include <linux/security.h>
82 +#define assert(test) J_ASSERT(test)
85 +#define IOPEN_NAME_LEN 32
88 + * This implements looking up an inode by number.
90 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
91 + struct nameidata *nd)
93 + struct inode *inode;
95 + struct list_head *lp;
96 + struct dentry *alternate;
97 + char buf[IOPEN_NAME_LEN];
99 + if (dentry->d_name.len >= IOPEN_NAME_LEN)
100 + return ERR_PTR(-ENAMETOOLONG);
102 + memcpy(buf, dentry->d_name.name, dentry->d_name.len);
103 + buf[dentry->d_name.len] = 0;
105 + if (strcmp(buf, ".") == 0)
107 + else if (strcmp(buf, "..") == 0)
108 + ino = EXT3_ROOT_INO;
110 + ino = simple_strtoul(buf, 0, 0);
112 + if ((ino != EXT3_ROOT_INO &&
113 + //ino != EXT3_ACL_IDX_INO &&
114 + //ino != EXT3_ACL_DATA_INO &&
115 + ino < EXT3_FIRST_INO(dir->i_sb)) ||
116 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
117 + return ERR_PTR(-ENOENT);
119 + inode = iget(dir->i_sb, ino);
121 + return ERR_PTR(-EACCES);
122 + if (is_bad_inode(inode)) {
124 + return ERR_PTR(-ENOENT);
127 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
128 + assert(d_unhashed(dentry)); /* d_rehash */
130 + /* preferrably return a connected dentry */
131 + spin_lock(&dcache_lock);
132 + list_for_each(lp, &inode->i_dentry) {
133 + alternate = list_entry(lp, struct dentry, d_alias);
134 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
137 + if (!list_empty(&inode->i_dentry)) {
138 + alternate = list_entry(inode->i_dentry.next,
139 + struct dentry, d_alias);
140 + dget_locked(alternate);
141 + spin_lock(&alternate->d_lock);
142 + alternate->d_vfs_flags |= DCACHE_REFERENCED;
143 + spin_unlock(&alternate->d_lock);
145 + spin_unlock(&dcache_lock);
148 + dentry->d_flags |= DCACHE_DISCONNECTED;
150 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
151 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
152 + dentry->d_inode = inode;
154 + d_rehash_cond(dentry, 0);
155 + spin_unlock(&dcache_lock);
160 +#define do_switch(x,y) do { \
161 + __typeof__ (x) __tmp = x; \
162 + x = y; y = __tmp; } while (0)
164 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
166 + const unsigned char *old_name, *new_name;
168 + memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
169 + old_name = target->d_name.name;
170 + new_name = dentry->d_name.name;
171 + if (old_name == target->d_iname)
172 + old_name = dentry->d_iname;
173 + if (new_name == dentry->d_iname)
174 + new_name = target->d_iname;
175 + target->d_name.name = new_name;
176 + dentry->d_name.name = old_name;
179 +/* This function is spliced into ext3_lookup and does the move of a
180 + * disconnected dentry (if it exists) to a connected dentry.
182 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
185 + struct dentry *tmp, *goal = NULL;
186 + struct list_head *lp;
188 + /* verify this dentry is really new */
189 + assert(dentry->d_inode == NULL);
190 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
192 + assert(d_unhashed(dentry)); /* d_rehash */
193 + assert(list_empty(&dentry->d_subdirs));
195 + spin_lock(&dcache_lock);
199 + if (!test_opt(inode->i_sb, IOPEN))
200 + goto do_instantiate;
202 + /* preferrably return a connected dentry */
203 + list_for_each(lp, &inode->i_dentry) {
204 + tmp = list_entry(lp, struct dentry, d_alias);
205 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
206 + assert(tmp->d_alias.next == &inode->i_dentry);
207 + assert(tmp->d_alias.prev == &inode->i_dentry);
215 + goto do_instantiate;
217 + /* Move the goal to the de hash queue */
218 + goal->d_flags &= ~DCACHE_DISCONNECTED;
219 + security_d_instantiate(goal, inode);
221 + d_rehash_cond(dentry, 0);
222 + d_move_locked(goal, dentry);
223 + spin_unlock(&dcache_lock);
228 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
230 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
231 + dentry->d_inode = inode;
234 + d_rehash_cond(dentry, 0);
235 + spin_unlock(&dcache_lock);
241 + * Similar as d_instantiate() except that it drops the disconnected
244 +void iopen_d_instantiate(struct dentry *dentry, struct inode * inode)
246 + struct dentry *dis_dentry;
248 + /* verify this dentry is really new */
249 + assert(dentry->d_inode == NULL);
250 + assert(list_empty(&dentry->d_alias));
252 + spin_lock(&dcache_lock);
253 + if (!inode || !test_opt(inode->i_sb, IOPEN) ||
254 + list_empty(&inode->i_dentry))
255 + goto do_instantiate;
257 + /* a disconnected dentry has been added in our back,
258 + * we have to drop this dentry, see bug 16362/15713*/
259 + dis_dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
260 + spin_lock(&dis_dentry->d_lock);
261 + assert(dis_dentry->d_alias.next == &inode->i_dentry);
262 + assert(dis_dentry->d_alias.prev == &inode->i_dentry);
263 + assert(dis_dentry->d_flags & DCACHE_DISCONNECTED);
264 + __d_drop(dis_dentry);
265 + list_del_init(&dis_dentry->d_alias);
266 + spin_unlock(&dis_dentry->d_lock);
270 + list_add(&dentry->d_alias, &inode->i_dentry);
271 + dentry->d_inode = inode;
272 + spin_unlock(&dcache_lock);
273 + security_d_instantiate(dentry, inode);
277 + * These are the special structures for the iopen pseudo directory.
280 +static struct inode_operations iopen_inode_operations = {
281 + lookup: iopen_lookup, /* BKL held */
284 +static struct file_operations iopen_file_operations = {
285 + read: generic_read_dir,
288 +static int match_dentry(struct dentry *dentry, const char *name)
292 + len = strlen(name);
293 + if (dentry->d_name.len != len)
295 + if (strncmp(dentry->d_name.name, name, len))
301 + * This function is spliced into ext3_lookup and returns 1 the file
302 + * name is __iopen__ and dentry has been filled in appropriately.
304 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
306 + struct inode *inode;
308 + if (dir->i_ino != EXT3_ROOT_INO ||
309 + !test_opt(dir->i_sb, IOPEN) ||
310 + !match_dentry(dentry, "__iopen__"))
313 + inode = iget(dir->i_sb, EXT3_BAD_INO);
317 + d_add(dentry, inode);
322 + * This function is spliced into read_inode; it returns 1 if inode
323 + * number is the one for /__iopen__, in which case the inode is filled
324 + * in appropriately. Otherwise, this fuction returns 0.
326 +int ext3_iopen_get_inode(struct inode *inode)
328 + if (inode->i_ino != EXT3_BAD_INO)
331 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
332 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
333 + inode->i_mode |= 0777;
336 + inode->i_nlink = 1;
337 + inode->i_size = 4096;
338 + inode->i_atime = CURRENT_TIME;
339 + inode->i_ctime = CURRENT_TIME;
340 + inode->i_mtime = CURRENT_TIME;
341 + EXT3_I(inode)->i_dtime = 0;
342 + EXT3_I(inode)->i_file_acl = 0;
343 + inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size
344 + * (for stat), not the fs block
346 + inode->i_blocks = 0;
347 + inode->i_version = 1;
348 + inode->i_generation = 0;
350 + inode->i_op = &iopen_inode_operations;
351 + inode->i_fop = &iopen_file_operations;
352 + inode->i_mapping->a_ops = 0;
356 Index: linux-2.6.5-7.311/fs/ext3/iopen.h
357 ===================================================================
359 +++ linux-2.6.5-7.311/fs/ext3/iopen.h
364 + * Special support for opening files by inode number.
366 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
368 + * This file may be redistributed under the terms of the GNU General
372 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
373 +extern int ext3_iopen_get_inode(struct inode *inode);
374 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
375 + struct inode *inode, int rehash);
376 +extern void iopen_d_instantiate(struct dentry *dentry, struct inode * inode);
378 +#if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
379 +#define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
382 +#if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
383 +#define d_move_locked(dentry, target) __d_move(dentry, target)
385 Index: linux-2.6.5-7.311/fs/ext3/namei.c
386 ===================================================================
387 --- linux-2.6.5-7.311.orig/fs/ext3/namei.c
388 +++ linux-2.6.5-7.311/fs/ext3/namei.c
390 #include <linux/buffer_head.h>
391 #include <linux/smp_lock.h>
397 @@ -1024,6 +1025,9 @@ static struct dentry *ext3_lookup(struct
398 if (dentry->d_name.len > EXT3_NAME_LEN)
399 return ERR_PTR(-ENAMETOOLONG);
401 + if (ext3_check_for_iopen(dir, dentry))
404 bh = ext3_find_entry(dentry, &de);
407 @@ -1034,10 +1038,8 @@ static struct dentry *ext3_lookup(struct
409 return ERR_PTR(-EACCES);
412 - return d_splice_alias(inode, dentry);
413 - d_add(dentry, inode);
416 + return iopen_connect_dentry(dentry, inode, 1);
420 @@ -1653,7 +1655,7 @@ static int ext3_add_nondir(handle_t *han
422 err = ext3_mark_inode_dirty(handle, inode);
424 - d_instantiate(dentry, inode);
425 + iopen_d_instantiate(dentry, inode);
429 @@ -1814,7 +1816,7 @@ retry:
431 ext3_update_dx_flag(dir);
432 ext3_mark_inode_dirty(handle, dir);
433 - d_instantiate(dentry, inode);
434 + iopen_d_instantiate(dentry, inode);
436 ext3_journal_stop(handle);
437 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
438 @@ -2075,10 +2077,6 @@ static int ext3_rmdir (struct inode * di
442 - /* There's no need to set i_disksize: the fact that i_nlink is
443 - * zero will ensure that the right thing happens during any
446 ext3_orphan_add(handle, inode);
447 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
448 ext3_mark_inode_dirty(handle, inode);
449 @@ -2199,6 +2197,23 @@ out_stop:
453 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
454 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
455 + struct inode *inode)
457 + int err = ext3_add_entry(handle, dentry, inode);
459 + err = ext3_mark_inode_dirty(handle, inode);
461 + dput(iopen_connect_dentry(dentry, inode, 0));
465 + ext3_dec_count(handle, inode);
470 static int ext3_link (struct dentry * old_dentry,
471 struct inode * dir, struct dentry *dentry)
473 @@ -2222,7 +2237,8 @@ retry:
474 ext3_inc_count(handle, inode);
475 atomic_inc(&inode->i_count);
477 - err = ext3_add_nondir(handle, dentry, inode);
478 + err = ext3_add_link(handle, dentry, inode);
479 + ext3_orphan_del(handle, inode);
480 ext3_journal_stop(handle);
481 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
483 Index: linux-2.6.5-7.311/fs/ext3/super.c
484 ===================================================================
485 --- linux-2.6.5-7.311.orig/fs/ext3/super.c
486 +++ linux-2.6.5-7.311/fs/ext3/super.c
487 @@ -581,6 +581,7 @@ enum {
488 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
489 Opt_ignore, Opt_barrier,
491 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
494 static match_table_t tokens = {
495 @@ -621,6 +622,9 @@ static match_table_t tokens = {
496 {Opt_ignore, "noquota"},
497 {Opt_ignore, "quota"},
498 {Opt_ignore, "usrquota"},
499 + {Opt_iopen, "iopen"},
500 + {Opt_noiopen, "noiopen"},
501 + {Opt_iopen_nopriv, "iopen_nopriv"},
502 {Opt_barrier, "barrier=%u"},
505 @@ -823,6 +827,18 @@ static int parse_options (char * options
507 clear_opt(sbi->s_mount_opt, BARRIER);
510 + set_opt (sbi->s_mount_opt, IOPEN);
511 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
514 + clear_opt (sbi->s_mount_opt, IOPEN);
515 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
517 + case Opt_iopen_nopriv:
518 + set_opt (sbi->s_mount_opt, IOPEN);
519 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
524 Index: linux-2.6.5-7.311/include/linux/ext3_fs.h
525 ===================================================================
526 --- linux-2.6.5-7.311.orig/include/linux/ext3_fs.h
527 +++ linux-2.6.5-7.311/include/linux/ext3_fs.h
528 @@ -329,6 +329,8 @@ struct ext3_inode {
529 #define EXT3_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
530 #define EXT3_MOUNT_RESERVATION 0x10000 /* Preallocation */
531 #define EXT3_MOUNT_BARRIER 0x20000 /* Use block barriers */
532 +#define EXT3_MOUNT_IOPEN 0x80000 /* Allow access via iopen */
533 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x100000/* Make iopen world-readable */
535 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
536 #ifndef _LINUX_EXT2_FS_H