1 Index: linux-2.6.18-53.1.21/fs/ext3/iopen.c
2 ===================================================================
4 +++ linux-2.6.18-53.1.21/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_FIRST_INO(dir->i_sb)) ||
79 + ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
80 + return ERR_PTR(-ENOENT);
82 + inode = iget(dir->i_sb, ino);
84 + return ERR_PTR(-EACCES);
85 + if (is_bad_inode(inode)) {
87 + return ERR_PTR(-ENOENT);
90 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
91 + assert(d_unhashed(dentry)); /* d_rehash */
93 + /* preferrably return a connected dentry */
94 + spin_lock(&dcache_lock);
95 + list_for_each(lp, &inode->i_dentry) {
96 + alternate = list_entry(lp, struct dentry, d_alias);
97 + assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
100 + if (!list_empty(&inode->i_dentry)) {
101 + alternate = list_entry(inode->i_dentry.next,
102 + struct dentry, d_alias);
103 + dget_locked(alternate);
104 + spin_lock(&alternate->d_lock);
105 + alternate->d_flags |= DCACHE_REFERENCED;
106 + spin_unlock(&alternate->d_lock);
108 + spin_unlock(&dcache_lock);
111 + dentry->d_flags |= DCACHE_DISCONNECTED;
113 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
114 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
115 + dentry->d_inode = inode;
117 + d_rehash_cond(dentry, 0);
118 + spin_unlock(&dcache_lock);
123 +/* This function is spliced into ext3_lookup and does the move of a
124 + * disconnected dentry (if it exists) to a connected dentry.
126 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
129 + struct dentry *tmp, *goal = NULL;
130 + struct list_head *lp;
132 + /* verify this dentry is really new */
133 + assert(dentry->d_inode == NULL);
134 + assert(list_empty(&dentry->d_alias)); /* d_instantiate */
136 + assert(d_unhashed(dentry)); /* d_rehash */
137 + assert(list_empty(&dentry->d_subdirs));
139 + spin_lock(&dcache_lock);
143 + if (!test_opt(inode->i_sb, IOPEN))
144 + goto do_instantiate;
146 + /* preferrably return a connected dentry */
147 + list_for_each(lp, &inode->i_dentry) {
148 + tmp = list_entry(lp, struct dentry, d_alias);
149 + if (tmp->d_flags & DCACHE_DISCONNECTED) {
150 + assert(tmp->d_alias.next == &inode->i_dentry);
151 + assert(tmp->d_alias.prev == &inode->i_dentry);
159 + goto do_instantiate;
161 + /* Move the goal to the de hash queue */
162 + goal->d_flags &= ~DCACHE_DISCONNECTED;
163 + security_d_instantiate(goal, inode);
165 + d_rehash_cond(dentry, 0);
166 + d_move_locked(goal, dentry);
167 + spin_unlock(&dcache_lock);
172 + /* d_add(), but don't drop dcache_lock before adding dentry to inode */
174 + list_add(&dentry->d_alias, &inode->i_dentry); /* d_instantiate */
175 + dentry->d_inode = inode;
178 + d_rehash_cond(dentry, 0);
179 + spin_unlock(&dcache_lock);
185 + * Similar as d_instantiate() except that it drops the disconnected
188 +void iopen_d_instantiate(struct dentry *dentry, struct inode * inode)
190 + struct dentry *dis_dentry;
192 + /* verify this dentry is really new */
193 + assert(dentry->d_inode == NULL);
194 + assert(list_empty(&dentry->d_alias));
196 + spin_lock(&dcache_lock);
197 + if (!inode || !test_opt(inode->i_sb, IOPEN) ||
198 + list_empty(&inode->i_dentry))
199 + goto do_instantiate;
201 + /* a disconnected dentry has been added in our back,
202 + * we have to drop this dentry, see bug 16362/15713*/
203 + dis_dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
204 + spin_lock(&dis_dentry->d_lock);
205 + assert(dis_dentry->d_alias.next == &inode->i_dentry);
206 + assert(dis_dentry->d_alias.prev == &inode->i_dentry);
207 + assert(dis_dentry->d_flags & DCACHE_DISCONNECTED);
208 + __d_drop(dis_dentry);
209 + list_del_init(&dis_dentry->d_alias);
210 + spin_unlock(&dis_dentry->d_lock);
214 + list_add(&dentry->d_alias, &inode->i_dentry);
215 + dentry->d_inode = inode;
216 + spin_unlock(&dcache_lock);
217 + security_d_instantiate(dentry, inode);
221 + * These are the special structures for the iopen pseudo directory.
224 +static struct inode_operations iopen_inode_operations = {
225 + lookup: iopen_lookup, /* BKL held */
228 +static struct file_operations iopen_file_operations = {
229 + read: generic_read_dir,
232 +static int match_dentry(struct dentry *dentry, const char *name)
236 + len = strlen(name);
237 + if (dentry->d_name.len != len)
239 + if (strncmp(dentry->d_name.name, name, len))
245 + * This function is spliced into ext3_lookup and returns 1 the file
246 + * name is __iopen__ and dentry has been filled in appropriately.
248 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
250 + struct inode *inode;
252 + if (dir->i_ino != EXT3_ROOT_INO ||
253 + !test_opt(dir->i_sb, IOPEN) ||
254 + !match_dentry(dentry, "__iopen__"))
257 + inode = iget(dir->i_sb, EXT3_BAD_INO);
261 + d_add(dentry, inode);
266 + * This function is spliced into read_inode; it returns 1 if inode
267 + * number is the one for /__iopen__, in which case the inode is filled
268 + * in appropriately. Otherwise, this fuction returns 0.
270 +int ext3_iopen_get_inode(struct inode *inode)
272 + if (inode->i_ino != EXT3_BAD_INO)
275 + inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
276 + if (test_opt(inode->i_sb, IOPEN_NOPRIV))
277 + inode->i_mode |= 0777;
280 + inode->i_nlink = 1;
281 + inode->i_size = 4096;
282 + inode->i_atime = CURRENT_TIME;
283 + inode->i_ctime = CURRENT_TIME;
284 + inode->i_mtime = CURRENT_TIME;
285 + EXT3_I(inode)->i_dtime = 0;
286 + EXT3_I(inode)->i_file_acl = 0;
287 + inode->i_blocks = 0;
288 + inode->i_version = 1;
289 + inode->i_generation = 0;
291 + inode->i_op = &iopen_inode_operations;
292 + inode->i_fop = &iopen_file_operations;
293 + inode->i_mapping->a_ops = 0;
297 Index: linux-2.6.18-53.1.21/fs/ext3/iopen.h
298 ===================================================================
300 +++ linux-2.6.18-53.1.21/fs/ext3/iopen.h
305 + * Special support for opening files by inode number.
307 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
309 + * This file may be redistributed under the terms of the GNU General
313 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
314 +extern int ext3_iopen_get_inode(struct inode *inode);
315 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
316 + struct inode *inode, int rehash);
317 +extern void iopen_d_instantiate(struct dentry *dentry, struct inode * inode);
318 Index: linux-2.6.18-53.1.21/fs/ext3/inode.c
319 ===================================================================
320 --- linux-2.6.18-53.1.21.orig/fs/ext3/inode.c
321 +++ linux-2.6.18-53.1.21/fs/ext3/inode.c
323 #include <linux/mpage.h>
324 #include <linux/uio.h>
329 static int ext3_writepage_trans_blocks(struct inode *inode);
330 @@ -2593,6 +2594,8 @@ void ext3_read_inode(struct inode * inod
331 ei->i_default_acl = EXT3_ACL_NOT_CACHED;
333 ei->i_block_alloc_info = NULL;
334 + if (ext3_iopen_get_inode(inode))
337 if (__ext3_get_inode_loc(inode, &iloc, 0))
339 Index: linux-2.6.18-53.1.21/fs/ext3/super.c
340 ===================================================================
341 --- linux-2.6.18-53.1.21.orig/fs/ext3/super.c
342 +++ linux-2.6.18-53.1.21/fs/ext3/super.c
343 @@ -677,6 +677,7 @@ enum {
344 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
345 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
346 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
347 + Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
351 @@ -726,6 +727,9 @@ static match_table_t tokens = {
352 {Opt_noquota, "noquota"},
353 {Opt_quota, "quota"},
354 {Opt_usrquota, "usrquota"},
355 + {Opt_iopen, "iopen"},
356 + {Opt_noiopen, "noiopen"},
357 + {Opt_iopen_nopriv, "iopen_nopriv"},
358 {Opt_barrier, "barrier=%u"},
360 {Opt_resize, "resize"},
361 @@ -1041,6 +1045,18 @@ clear_qf_name:
363 clear_opt(sbi->s_mount_opt, BARRIER);
366 + set_opt (sbi->s_mount_opt, IOPEN);
367 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
370 + clear_opt (sbi->s_mount_opt, IOPEN);
371 + clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
373 + case Opt_iopen_nopriv:
374 + set_opt (sbi->s_mount_opt, IOPEN);
375 + set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
380 Index: linux-2.6.18-53.1.21/fs/ext3/namei.c
381 ===================================================================
382 --- linux-2.6.18-53.1.21.orig/fs/ext3/namei.c
383 +++ linux-2.6.18-53.1.21/fs/ext3/namei.c
392 @@ -1020,6 +1021,9 @@ static struct dentry *ext3_lookup(struct
393 if (dentry->d_name.len > EXT3_NAME_LEN)
394 return ERR_PTR(-ENAMETOOLONG);
396 + if (ext3_check_for_iopen(dir, dentry))
399 bh = ext3_find_entry(dentry, &de);
402 @@ -1035,7 +1039,8 @@ static struct dentry *ext3_lookup(struct
404 return ERR_PTR(-EACCES);
406 - return d_splice_alias(inode, dentry);
408 + return iopen_connect_dentry(dentry, inode, 1);
412 @@ -1678,7 +1683,7 @@ static int ext3_add_nondir(handle_t *han
413 int err = ext3_add_entry(handle, dentry, inode);
415 ext3_mark_inode_dirty(handle, inode);
416 - d_instantiate(dentry, inode);
417 + iopen_d_instantiate(dentry, inode);
420 ext3_dec_count(handle, inode);
421 @@ -1840,7 +1845,7 @@ retry:
423 ext3_update_dx_flag(dir);
424 ext3_mark_inode_dirty(handle, dir);
425 - d_instantiate(dentry, inode);
426 + iopen_d_instantiate(dentry, inode);
428 ext3_journal_stop(handle);
429 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
430 @@ -2108,10 +2113,6 @@ static int ext3_rmdir (struct inode * di
434 - /* There's no need to set i_disksize: the fact that i_nlink is
435 - * zero will ensure that the right thing happens during any
438 ext3_orphan_add(handle, inode);
439 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
440 ext3_mark_inode_dirty(handle, inode);
441 @@ -2235,6 +2236,23 @@ out_stop:
445 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
446 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
447 + struct inode *inode)
449 + int err = ext3_add_entry(handle, dentry, inode);
451 + err = ext3_mark_inode_dirty(handle, inode);
453 + dput(iopen_connect_dentry(dentry, inode, 0));
457 + ext3_dec_count(handle, inode);
462 static int ext3_link (struct dentry * old_dentry,
463 struct inode * dir, struct dentry *dentry)
465 @@ -2264,7 +2282,8 @@ retry:
466 ext3_inc_count(handle, inode);
467 atomic_inc(&inode->i_count);
469 - err = ext3_add_nondir(handle, dentry, inode);
470 + err = ext3_add_link(handle, dentry, inode);
471 + ext3_orphan_del(handle, inode);
472 ext3_journal_stop(handle);
473 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
475 Index: linux-2.6.18-53.1.21/fs/ext3/Makefile
476 ===================================================================
477 --- linux-2.6.18-53.1.21.orig/fs/ext3/Makefile
478 +++ linux-2.6.18-53.1.21/fs/ext3/Makefile
481 obj-$(CONFIG_EXT3_FS) += ext3.o
483 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
484 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
485 ioctl.o namei.o super.o symlink.o hash.o resize.o
487 ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
488 Index: linux-2.6.18-53.1.21/include/linux/ext3_fs.h
489 ===================================================================
490 --- linux-2.6.18-53.1.21.orig/include/linux/ext3_fs.h
491 +++ linux-2.6.18-53.1.21/include/linux/ext3_fs.h
492 @@ -371,6 +371,8 @@ struct ext3_inode {
493 #define EXT3_MOUNT_QUOTA 0x80000 /* Some quota option set */
494 #define EXT3_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
495 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
496 +#define EXT3_MOUNT_IOPEN 0x400000 /* Allow access via iopen */
497 +#define EXT3_MOUNT_IOPEN_NOPRIV 0x800000/* Make iopen world-readable */
499 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
500 #ifndef _LINUX_EXT2_FS_H