1 Index: linux-2.6.22.19/fs/ext3/iopen.c
2 ===================================================================
4 +++ linux-2.6.22.19/fs/ext3/iopen.c
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);
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_locked(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);
181 + spin_unlock(&dcache_lock);
187 + * Similar as d_instantiate() except that it drops the disconnected
190 +void iopen_d_instantiate(struct dentry *dentry, struct inode * inode)
192 + struct dentry *dis_dentry;
194 + /* verify this dentry is really new */
195 + assert(dentry->d_inode == NULL);
196 + assert(list_empty(&dentry->d_alias));
198 + spin_lock(&dcache_lock);
199 + if (!inode || !test_opt(inode->i_sb, IOPEN) ||
200 + list_empty(&inode->i_dentry))
201 + goto do_instantiate;
203 + /* a disconnected dentry has been added in our back,
204 + * we have to drop this dentry, see bug 16362/15713*/
205 + dis_dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
206 + spin_lock(&dis_dentry->d_lock);
207 + assert(dis_dentry->d_alias.next == &inode->i_dentry);
208 + assert(dis_dentry->d_alias.prev == &inode->i_dentry);
209 + assert(dis_dentry->d_flags & DCACHE_DISCONNECTED);
210 + __d_drop(dis_dentry);
211 + list_del_init(&dis_dentry->d_alias);
212 + spin_unlock(&dis_dentry->d_lock);
216 + list_add(&dentry->d_alias, &inode->i_dentry);
217 + dentry->d_inode = inode;
218 + spin_unlock(&dcache_lock);
219 + security_d_instantiate(dentry, inode);
223 + * These are the special structures for the iopen pseudo directory.
226 +static struct inode_operations iopen_inode_operations = {
227 + lookup: iopen_lookup, /* BKL held */
230 +static struct file_operations iopen_file_operations = {
231 + read: generic_read_dir,
234 +static int match_dentry(struct dentry *dentry, const char *name)
238 + len = strlen(name);
239 + if (dentry->d_name.len != len)
241 + if (strncmp(dentry->d_name.name, name, len))
247 + * This function is spliced into ext3_lookup and returns 1 the file
248 + * name is __iopen__ and dentry has been filled in appropriately.
250 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
252 + struct inode *inode;
254 + if (dir->i_ino != EXT3_ROOT_INO ||
255 + !test_opt(dir->i_sb, IOPEN) ||
256 + !match_dentry(dentry, "__iopen__"))
259 + inode = iget(dir->i_sb, EXT3_BAD_INO);
263 + d_add(dentry, inode);
268 + * This function is spliced into read_inode; it returns 1 if inode
269 + * number is the one for /__iopen__, in which case the inode is filled
270 + * in appropriately. Otherwise, this fuction returns 0.
272 +int ext3_iopen_get_inode(struct inode *inode)
274 + if (inode->i_ino != EXT3_BAD_INO)
277 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
278 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
279 + inode->i_mode |= 0777;
282 + inode->i_nlink = 1;
283 + inode->i_size = 4096;
284 + inode->i_atime = CURRENT_TIME;
285 + inode->i_ctime = CURRENT_TIME;
286 + inode->i_mtime = CURRENT_TIME;
287 + EXT3_I(inode)->i_dtime = 0;
288 + EXT3_I(inode)->i_file_acl = 0;
289 + inode->i_blocks = 0;
290 + inode->i_version = 1;
291 + inode->i_generation = 0;
293 + inode->i_op = &iopen_inode_operations;
294 + inode->i_fop = &iopen_file_operations;
295 + inode->i_mapping->a_ops = 0;
299 Index: linux-2.6.22.19/fs/ext3/iopen.h
300 ===================================================================
302 +++ linux-2.6.22.19/fs/ext3/iopen.h
307 + * Special support for opening files by inode number.
309 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
311 + * This file may be redistributed under the terms of the GNU General
315 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
316 +extern int ext3_iopen_get_inode(struct inode *inode);
317 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
318 + struct inode *inode, int rehash);
319 +extern void iopen_d_instantiate(struct dentry *dentry, struct inode * inode);
321 +#if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
322 +#define d_move_locked(dentry, target) __d_move(dentry, target)
324 Index: linux-2.6.22.19/fs/ext3/inode.c
325 ===================================================================
326 --- linux-2.6.22.19.orig/fs/ext3/inode.c
327 +++ linux-2.6.22.19/fs/ext3/inode.c
329 #include <linux/uio.h>
330 #include <linux/bio.h>
335 static int ext3_writepage_trans_blocks(struct inode *inode);
336 @@ -2604,6 +2605,8 @@ void ext3_read_inode(struct inode * inod
337 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
339 ei->i_block_alloc_info = NULL;
340 + if (ext3_iopen_get_inode(inode))
343 if (__ext3_get_inode_loc(inode, &iloc, 0))
345 Index: linux-2.6.22.19/fs/ext3/super.c
346 ===================================================================
347 --- linux-2.6.22.19.orig/fs/ext3/super.c
348 +++ linux-2.6.22.19/fs/ext3/super.c
349 @@ -674,6 +674,7 @@ enum {
350 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
351 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
352 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
353 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
357 @@ -723,6 +724,9 @@ static match_table_t tokens = {
358 {Opt_noquota, "noquota"},
359 {Opt_quota, "quota"},
360 {Opt_usrquota, "usrquota"},
361 + {Opt_iopen, "iopen"},
362 + {Opt_noiopen, "noiopen"},
363 + {Opt_iopen_nopriv, "iopen_nopriv"},
364 {Opt_barrier, "barrier=%u"},
366 {Opt_resize, "resize"},
367 @@ -1038,6 +1042,18 @@ clear_qf_name:
369 clear_opt(sbi->s_mount_opt, BARRIER);
372 + set_opt (sbi->s_mount_opt, IOPEN);
373 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
376 + clear_opt (sbi->s_mount_opt, IOPEN);
377 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
379 + case Opt_iopen_nopriv:
380 + set_opt (sbi->s_mount_opt, IOPEN);
381 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
386 Index: linux-2.6.22.19/fs/ext3/namei.c
387 ===================================================================
388 --- linux-2.6.22.19.orig/fs/ext3/namei.c
389 +++ linux-2.6.22.19/fs/ext3/namei.c
398 @@ -1047,6 +1048,9 @@ static struct dentry *ext3_lookup(struct
399 if (dentry->d_name.len > EXT3_NAME_LEN)
400 return ERR_PTR(-ENAMETOOLONG);
402 + if (ext3_check_for_iopen(dir, dentry))
405 bh = ext3_find_entry(dentry, &de);
408 @@ -1062,7 +1066,8 @@ static struct dentry *ext3_lookup(struct
410 return ERR_PTR(-EACCES);
412 - return d_splice_alias(inode, dentry);
414 + return iopen_connect_dentry(dentry, inode, 1);
418 @@ -1693,7 +1698,7 @@ static int ext3_add_nondir(handle_t *han
419 int err = ext3_add_entry(handle, dentry, inode);
421 ext3_mark_inode_dirty(handle, inode);
422 - d_instantiate(dentry, inode);
423 + iopen_d_instantiate(dentry, inode);
427 @@ -1855,7 +1860,7 @@ retry:
429 ext3_update_dx_flag(dir);
430 ext3_mark_inode_dirty(handle, dir);
431 - d_instantiate(dentry, inode);
432 + iopen_d_instantiate(dentry, inode);
434 ext3_journal_stop(handle);
435 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
436 @@ -2123,10 +2128,6 @@ static int ext3_rmdir (struct inode * di
440 - /* There's no need to set i_disksize: the fact that i_nlink is
441 - * zero will ensure that the right thing happens during any
444 ext3_orphan_add(handle, inode);
445 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
446 ext3_mark_inode_dirty(handle, inode);
447 @@ -2250,6 +2251,23 @@ out_stop:
451 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
452 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
453 + struct inode *inode)
455 + int err = ext3_add_entry(handle, dentry, inode);
457 + err = ext3_mark_inode_dirty(handle, inode);
459 + dput(iopen_connect_dentry(dentry, inode, 0));
463 + ext3_dec_count(handle, inode);
468 static int ext3_link (struct dentry * old_dentry,
469 struct inode * dir, struct dentry *dentry)
471 @@ -2279,7 +2297,8 @@ retry:
473 atomic_inc(&inode->i_count);
475 - err = ext3_add_nondir(handle, dentry, inode);
476 + err = ext3_add_link(handle, dentry, inode);
477 + ext3_orphan_del(handle, inode);
478 ext3_journal_stop(handle);
479 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
481 Index: linux-2.6.22.19/fs/ext3/Makefile
482 ===================================================================
483 --- linux-2.6.22.19.orig/fs/ext3/Makefile
484 +++ linux-2.6.22.19/fs/ext3/Makefile
487 obj-$(CONFIG_EXT3_FS) += ext3.o
489 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
490 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
491 ioctl.o namei.o super.o symlink.o hash.o resize.o ext3_jbd.o
493 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
494 Index: linux-2.6.22.19/include/linux/ext3_fs.h
495 ===================================================================
496 --- linux-2.6.22.19.orig/include/linux/ext3_fs.h
497 +++ linux-2.6.22.19/include/linux/ext3_fs.h
498 @@ -384,6 +384,8 @@ struct ext3_inode {
499 #define EXT3_MOUNT_QUOTA 0x80000 /* Some quota option set */
500 #define EXT3_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
501 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
502 +#define EXT3_MOUNT_IOPEN 0x400000 /* Allow access via iopen */
503 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x800000/* Make iopen world-readable */
505 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
506 #ifndef _LINUX_EXT2_FS_H