Whamcloud - gitweb
Branch b1_6
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / iopen-2.6.18-rhel5.patch
1 Index: linux-2.6.18.8/fs/ext3/iopen.c
2 ===================================================================
3 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.18.8/fs/ext3/iopen.c      2007-07-24 14:00:57.000000000 +0200
5 @@ -0,0 +1,254 @@
6 +/*
7 + * linux/fs/ext3/iopen.c
8 + *
9 + * Special support for open by inode number
10 + *
11 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
12 + *
13 + * This file may be redistributed under the terms of the GNU General
14 + * Public License.
15 + *
16 + *
17 + * Invariants:
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.
22 + *
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
27 + * until it is gone.
28 + *
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.
34 + */
35 +
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>
44 +#include "iopen.h"
45 +
46 +#ifndef assert
47 +#define assert(test) J_ASSERT(test)
48 +#endif
49 +
50 +#define IOPEN_NAME_LEN 32
51 +
52 +/*
53 + * This implements looking up an inode by number.
54 + */
55 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
56 +                                  struct nameidata *nd)
57 +{
58 +       struct inode *inode;
59 +       unsigned long ino;
60 +       struct list_head *lp;
61 +       struct dentry *alternate;
62 +       char buf[IOPEN_NAME_LEN];
63 +
64 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
65 +               return ERR_PTR(-ENAMETOOLONG);
66 +
67 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
68 +       buf[dentry->d_name.len] = 0;
69 +
70 +       if (strcmp(buf, ".") == 0)
71 +               ino = dir->i_ino;
72 +       else if (strcmp(buf, "..") == 0)
73 +               ino = EXT3_ROOT_INO;
74 +       else
75 +               ino = simple_strtoul(buf, 0, 0);
76 +
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);
81 +
82 +       inode = iget(dir->i_sb, ino);
83 +       if (!inode)
84 +               return ERR_PTR(-EACCES);
85 +       if (is_bad_inode(inode)) {
86 +               iput(inode);
87 +               return ERR_PTR(-ENOENT);
88 +       }
89 +
90 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
91 +       assert(d_unhashed(dentry));                     /* d_rehash */
92 +
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));
98 +       }
99 +
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);
107 +               iput(inode);
108 +               spin_unlock(&dcache_lock);
109 +               return alternate;
110 +       }
111 +       dentry->d_flags |= DCACHE_DISCONNECTED;
112 +
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;
116 +
117 +       d_rehash_cond(dentry, 0);
118 +       spin_unlock(&dcache_lock);
119 +
120 +       return NULL;
121 +}
122 +
123 +/* This function is spliced into ext3_lookup and does the move of a
124 + * disconnected dentry (if it exists) to a connected dentry.
125 + */
126 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
127 +                                   int rehash)
128 +{
129 +       struct dentry *tmp, *goal = NULL;
130 +       struct list_head *lp;
131 +
132 +       /* verify this dentry is really new */
133 +       assert(dentry->d_inode == NULL);
134 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
135 +       if (rehash)
136 +               assert(d_unhashed(dentry));             /* d_rehash */
137 +       assert(list_empty(&dentry->d_subdirs));
138 +
139 +       spin_lock(&dcache_lock);
140 +       if (!inode)
141 +               goto do_rehash;
142 +
143 +       if (!test_opt(inode->i_sb, IOPEN))
144 +               goto do_instantiate;
145 +
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);
152 +                       goal = tmp;
153 +                       dget_locked(goal);
154 +                       break;
155 +               }
156 +       }
157 +
158 +       if (!goal)
159 +               goto do_instantiate;
160 +
161 +       /* Move the goal to the de hash queue */
162 +       goal->d_flags &= ~DCACHE_DISCONNECTED;
163 +       security_d_instantiate(goal, inode);
164 +       __d_drop(dentry);
165 +       d_rehash_cond(dentry, 0);
166 +       __d_move(goal, dentry);
167 +       spin_unlock(&dcache_lock);
168 +       iput(inode);
169 +
170 +       return goal;
171 +
172 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
173 +do_instantiate:
174 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
175 +       dentry->d_inode = inode;
176 +do_rehash:
177 +       if (rehash)
178 +               d_rehash_cond(dentry, 0);
179 +       spin_unlock(&dcache_lock);
180 +
181 +       return NULL;
182 +}
183 +
184 +/*
185 + * These are the special structures for the iopen pseudo directory.
186 + */
187 +
188 +static struct inode_operations iopen_inode_operations = {
189 +       lookup:         iopen_lookup,           /* BKL held */
190 +};
191 +
192 +static struct file_operations iopen_file_operations = {
193 +       read:           generic_read_dir,
194 +};
195 +
196 +static int match_dentry(struct dentry *dentry, const char *name)
197 +{
198 +       int     len;
199 +
200 +       len = strlen(name);
201 +       if (dentry->d_name.len != len)
202 +               return 0;
203 +       if (strncmp(dentry->d_name.name, name, len))
204 +               return 0;
205 +       return 1;
206 +}
207 +
208 +/*
209 + * This function is spliced into ext3_lookup and returns 1 the file
210 + * name is __iopen__ and dentry has been filled in appropriately.
211 + */
212 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
213 +{
214 +       struct inode *inode;
215 +
216 +       if (dir->i_ino != EXT3_ROOT_INO ||
217 +           !test_opt(dir->i_sb, IOPEN) ||
218 +           !match_dentry(dentry, "__iopen__"))
219 +               return 0;
220 +
221 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
222 +
223 +       if (!inode)
224 +               return 0;
225 +       d_add(dentry, inode);
226 +       return 1;
227 +}
228 +
229 +/*
230 + * This function is spliced into read_inode; it returns 1 if inode
231 + * number is the one for /__iopen__, in which case the inode is filled
232 + * in appropriately.  Otherwise, this fuction returns 0.
233 + */
234 +int ext3_iopen_get_inode(struct inode *inode)
235 +{
236 +       if (inode->i_ino != EXT3_BAD_INO)
237 +               return 0;
238 +
239 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
240 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
241 +               inode->i_mode |= 0777;
242 +       inode->i_uid = 0;
243 +       inode->i_gid = 0;
244 +       inode->i_nlink = 1;
245 +       inode->i_size = 4096;
246 +       inode->i_atime = CURRENT_TIME;
247 +       inode->i_ctime = CURRENT_TIME;
248 +       inode->i_mtime = CURRENT_TIME;
249 +       EXT3_I(inode)->i_dtime = 0;
250 +       inode->i_blocks = 0;
251 +       inode->i_version = 1;
252 +       inode->i_generation = 0;
253 +
254 +       inode->i_op = &iopen_inode_operations;
255 +       inode->i_fop = &iopen_file_operations;
256 +       inode->i_mapping->a_ops = 0;
257 +
258 +       return 1;
259 +}
260 Index: linux-2.6.18.8/fs/ext3/iopen.h
261 ===================================================================
262 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
263 +++ linux-2.6.18.8/fs/ext3/iopen.h      2007-07-24 13:59:56.000000000 +0200
264 @@ -0,0 +1,15 @@
265 +/*
266 + * iopen.h
267 + *
268 + * Special support for opening files by inode number.
269 + *
270 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
271 + *
272 + * This file may be redistributed under the terms of the GNU General
273 + * Public License.
274 + */
275 +
276 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
277 +extern int ext3_iopen_get_inode(struct inode *inode);
278 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
279 +                                          struct inode *inode, int rehash);
280 Index: linux-2.6.18.8/fs/ext3/inode.c
281 ===================================================================
282 --- linux-2.6.18.8.orig/fs/ext3/inode.c 2007-07-24 12:25:00.000000000 +0200
283 +++ linux-2.6.18.8/fs/ext3/inode.c      2007-07-24 13:59:56.000000000 +0200
284 @@ -37,6 +37,7 @@
285  #include <linux/mpage.h>
286  #include <linux/uio.h>
287  #include "xattr.h"
288 +#include "iopen.h"
289  #include "acl.h"
290  
291  static int ext3_writepage_trans_blocks(struct inode *inode);
292 @@ -2593,6 +2594,8 @@ void ext3_read_inode(struct inode * inod
293         ei->i_default_acl = EXT3_ACL_NOT_CACHED;
294  #endif
295         ei->i_block_alloc_info = NULL;
296 +       if (ext3_iopen_get_inode(inode))
297 +               return;
298  
299         if (__ext3_get_inode_loc(inode, &iloc, 0))
300                 goto bad_inode;
301 Index: linux-2.6.18.8/fs/ext3/super.c
302 ===================================================================
303 --- linux-2.6.18.8.orig/fs/ext3/super.c 2007-07-24 12:25:00.000000000 +0200
304 +++ linux-2.6.18.8/fs/ext3/super.c      2007-07-24 13:59:56.000000000 +0200
305 @@ -677,6 +677,7 @@ enum {
306         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
307         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
308         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
309 +       Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
310         Opt_grpquota
311  };
312  
313 @@ -726,6 +727,9 @@ static match_table_t tokens = {
314         {Opt_noquota, "noquota"},
315         {Opt_quota, "quota"},
316         {Opt_usrquota, "usrquota"},
317 +       {Opt_iopen, "iopen"},
318 +       {Opt_noiopen, "noiopen"},
319 +       {Opt_iopen_nopriv, "iopen_nopriv"},
320         {Opt_barrier, "barrier=%u"},
321         {Opt_err, NULL},
322         {Opt_resize, "resize"},
323 @@ -1041,6 +1045,18 @@ clear_qf_name:
324                         else
325                                 clear_opt(sbi->s_mount_opt, BARRIER);
326                         break;
327 +               case Opt_iopen:
328 +                       set_opt (sbi->s_mount_opt, IOPEN);
329 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
330 +                       break;
331 +               case Opt_noiopen:
332 +                       clear_opt (sbi->s_mount_opt, IOPEN);
333 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
334 +                       break;
335 +               case Opt_iopen_nopriv:
336 +                       set_opt (sbi->s_mount_opt, IOPEN);
337 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
338 +                       break;
339                 case Opt_ignore:
340                         break;
341                 case Opt_resize:
342 Index: linux-2.6.18.8/fs/ext3/namei.c
343 ===================================================================
344 --- linux-2.6.18.8.orig/fs/ext3/namei.c 2007-07-24 13:59:54.000000000 +0200
345 +++ linux-2.6.18.8/fs/ext3/namei.c      2007-07-24 13:59:56.000000000 +0200
346 @@ -39,6 +39,7 @@
347  
348  #include "namei.h"
349  #include "xattr.h"
350 +#include "iopen.h"
351  #include "acl.h"
352  
353  /*
354 @@ -1013,6 +1014,9 @@ static struct dentry *ext3_lookup(struct
355         if (dentry->d_name.len > EXT3_NAME_LEN)
356                 return ERR_PTR(-ENAMETOOLONG);
357  
358 +       if (ext3_check_for_iopen(dir, dentry))
359 +               return NULL;
360 +
361         bh = ext3_find_entry(dentry, &de);
362         inode = NULL;
363         if (bh) {
364 @@ -1028,7 +1032,7 @@ static struct dentry *ext3_lookup(struct
365                 if (!inode)
366                         return ERR_PTR(-EACCES);
367         }
368 -       return d_splice_alias(inode, dentry);
369 +       return iopen_connect_dentry(dentry, inode, 1);
370  }
371  
372  
373 @@ -2077,10 +2081,6 @@ static int ext3_rmdir (struct inode * di
374                               inode->i_nlink);
375         inode->i_version++;
376         inode->i_nlink = 0;
377 -       /* There's no need to set i_disksize: the fact that i_nlink is
378 -        * zero will ensure that the right thing happens during any
379 -        * recovery. */
380 -       inode->i_size = 0;
381         ext3_orphan_add(handle, inode);
382         inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
383         ext3_mark_inode_dirty(handle, inode);
384 @@ -2204,6 +2204,23 @@ out_stop:
385         return err;
386  }
387  
388 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
389 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
390 +                        struct inode *inode)
391 +{
392 +       int err = ext3_add_entry(handle, dentry, inode);
393 +       if (!err) {
394 +               err = ext3_mark_inode_dirty(handle, inode);
395 +               if (err == 0) {
396 +                       dput(iopen_connect_dentry(dentry, inode, 0));
397 +                       return 0;
398 +               }
399 +       }
400 +       ext3_dec_count(handle, inode);
401 +       iput(inode);
402 +       return err;
403 +}
404 +
405  static int ext3_link (struct dentry * old_dentry,
406                 struct inode * dir, struct dentry *dentry)
407  {
408 @@ -2233,7 +2250,8 @@ retry:
409         ext3_inc_count(handle, inode);
410         atomic_inc(&inode->i_count);
411  
412 -       err = ext3_add_nondir(handle, dentry, inode);
413 +       err = ext3_add_link(handle, dentry, inode);
414 +       ext3_orphan_del(handle, inode);
415         ext3_journal_stop(handle);
416         if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
417                 goto retry;
418 Index: linux-2.6.18.8/fs/ext3/Makefile
419 ===================================================================
420 --- linux-2.6.18.8.orig/fs/ext3/Makefile        2007-07-24 12:25:00.000000000 +0200
421 +++ linux-2.6.18.8/fs/ext3/Makefile     2007-07-24 13:59:56.000000000 +0200
422 @@ -4,7 +4,7 @@
423  
424  obj-$(CONFIG_EXT3_FS) += ext3.o
425  
426 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
427 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
428            ioctl.o namei.o super.o symlink.o hash.o resize.o
429  
430  ext3-$(CONFIG_EXT3_FS_XATTR)    += xattr.o xattr_user.o xattr_trusted.o
431 Index: linux-2.6.18.8/include/linux/ext3_fs.h
432 ===================================================================
433 --- linux-2.6.18.8.orig/include/linux/ext3_fs.h 2007-07-24 13:59:54.000000000 +0200
434 +++ linux-2.6.18.8/include/linux/ext3_fs.h      2007-07-24 13:59:56.000000000 +0200
435 @@ -371,6 +371,8 @@ struct ext3_inode {
436  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
437  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
438  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
439 +#define EXT3_MOUNT_IOPEN               0x400000        /* Allow access via iopen */
440 +#define EXT3_MOUNT_IOPEN_NOPRIV                0x800000/* Make iopen world-readable */
441  
442  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
443  #ifndef _LINUX_EXT2_FS_H