Whamcloud - gitweb
Branch b1_8
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / iopen-2.6-rhel4.patch
1 Index: linux-2.6.9-67/fs/ext3/Makefile
2 ===================================================================
3 --- linux-2.6.9-67.orig/fs/ext3/Makefile
4 +++ linux-2.6.9-67/fs/ext3/Makefile
5 @@ -4,7 +4,7 @@
6  
7  obj-$(CONFIG_EXT3_FS) += ext3.o
8  
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 resize.o
12  
13  ext3-$(CONFIG_EXT3_FS_XATTR)    += xattr.o xattr_user.o xattr_trusted.o
14 Index: linux-2.6.9-67/fs/ext3/inode.c
15 ===================================================================
16 --- linux-2.6.9-67.orig/fs/ext3/inode.c
17 +++ linux-2.6.9-67/fs/ext3/inode.c
18 @@ -37,6 +37,7 @@
19  #include <linux/mpage.h>
20  #include <linux/uio.h>
21  #include "xattr.h"
22 +#include "iopen.h"
23  #include "acl.h"
24  
25  /*
26 @@ -2409,6 +2410,8 @@ void ext3_read_inode(struct inode * inod
27         ei->i_default_acl = EXT3_ACL_NOT_CACHED;
28  #endif
29         ei->i_rsv_window.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED;
30 +       if (ext3_iopen_get_inode(inode))
31 +               return;
32  
33         if (ext3_get_inode_loc(inode, &iloc, 0))
34                 goto bad_inode;
35 Index: linux-2.6.9-67/fs/ext3/iopen.c
36 ===================================================================
37 --- /dev/null
38 +++ linux-2.6.9-67/fs/ext3/iopen.c
39 @@ -0,0 +1,315 @@
40 +/*
41 + * linux/fs/ext3/iopen.c
42 + *
43 + * Special support for open by inode number
44 + *
45 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
46 + *
47 + * This file may be redistributed under the terms of the GNU General
48 + * Public License.
49 + *
50 + *
51 + * Invariants:
52 + *   - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
53 + *     for an inode at one time.
54 + *   - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
55 + *     aliases on an inode at the same time.
56 + *
57 + * If we have any connected dentry aliases for an inode, use one of those
58 + * in iopen_lookup().  Otherwise, we instantiate a single NFSD_DISCONNECTED
59 + * dentry for this inode, which thereafter will be found by the dcache
60 + * when looking up this inode number in __iopen__, so we don't return here
61 + * until it is gone.
62 + *
63 + * If we get an inode via a regular name lookup, then we "rename" the
64 + * NFSD_DISCONNECTED dentry to the proper name and parent.  This ensures
65 + * existing users of the disconnected dentry will continue to use the same
66 + * dentry as the connected users, and there will never be both kinds of
67 + * dentry aliases at one time.
68 + */
69 +
70 +#include <linux/sched.h>
71 +#include <linux/fs.h>
72 +#include <linux/ext3_jbd.h>
73 +#include <linux/jbd.h>
74 +#include <linux/ext3_fs.h>
75 +#include <linux/smp_lock.h>
76 +#include <linux/dcache.h>
77 +#include <linux/security.h>
78 +#include "iopen.h"
79 +
80 +#ifndef assert
81 +#define assert(test) J_ASSERT(test)
82 +#endif
83 +
84 +#define IOPEN_NAME_LEN 32
85 +
86 +/*
87 + * This implements looking up an inode by number.
88 + */
89 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
90 +                                  struct nameidata *nd)
91 +{
92 +       struct inode *inode;
93 +       unsigned long ino;
94 +       struct list_head *lp;
95 +       struct dentry *alternate;
96 +       char buf[IOPEN_NAME_LEN];
97 +
98 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
99 +               return ERR_PTR(-ENAMETOOLONG);
100 +
101 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
102 +       buf[dentry->d_name.len] = 0;
103 +
104 +       if (strcmp(buf, ".") == 0)
105 +               ino = dir->i_ino;
106 +       else if (strcmp(buf, "..") == 0)
107 +               ino = EXT3_ROOT_INO;
108 +       else
109 +               ino = simple_strtoul(buf, 0, 0);
110 +
111 +       if ((ino != EXT3_ROOT_INO &&
112 +            //ino != EXT3_ACL_IDX_INO &&
113 +            //ino != EXT3_ACL_DATA_INO &&
114 +            ino < EXT3_FIRST_INO(dir->i_sb)) ||
115 +           ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
116 +               return ERR_PTR(-ENOENT);
117 +
118 +       inode = iget(dir->i_sb, ino);
119 +       if (!inode)
120 +               return ERR_PTR(-EACCES);
121 +       if (is_bad_inode(inode)) {
122 +               iput(inode);
123 +               return ERR_PTR(-ENOENT);
124 +       }
125 +
126 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
127 +       assert(d_unhashed(dentry));                     /* d_rehash */
128 +
129 +       /* preferrably return a connected dentry */
130 +       spin_lock(&dcache_lock);
131 +       list_for_each(lp, &inode->i_dentry) {
132 +               alternate = list_entry(lp, struct dentry, d_alias);
133 +               assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
134 +       }
135 +
136 +       if (!list_empty(&inode->i_dentry)) {
137 +               alternate = list_entry(inode->i_dentry.next,
138 +                                      struct dentry, d_alias);
139 +               dget_locked(alternate);
140 +               spin_lock(&alternate->d_lock);
141 +               alternate->d_flags |= DCACHE_REFERENCED;
142 +               spin_unlock(&alternate->d_lock);
143 +               iput(inode);
144 +               spin_unlock(&dcache_lock);
145 +               return alternate;
146 +       }
147 +       dentry->d_flags |= DCACHE_DISCONNECTED;
148 +
149 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
150 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
151 +       dentry->d_inode = inode;
152 +
153 +       d_rehash_cond(dentry, 0);                               /* d_rehash */
154 +       spin_unlock(&dcache_lock);
155 +
156 +       return NULL;
157 +}
158 +
159 +#define do_switch(x,y) do { \
160 +       __typeof__ (x) __tmp = x; \
161 +       x = y; y = __tmp; } while (0)
162 +
163 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
164 +{
165 +       const unsigned char *old_name, *new_name;
166 +
167 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN_MIN);
168 +       old_name = target->d_name.name;
169 +       new_name = dentry->d_name.name;
170 +       if (old_name == target->d_iname)
171 +               old_name = dentry->d_iname;
172 +       if (new_name == dentry->d_iname)
173 +               new_name = target->d_iname;
174 +       target->d_name.name = new_name;
175 +       dentry->d_name.name = old_name;
176 +}
177 +
178 +/* This function is spliced into ext3_lookup and does the move of a
179 + * disconnected dentry (if it exists) to a connected dentry.
180 + */
181 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
182 +                                   int rehash)
183 +{
184 +       struct dentry *tmp, *goal = NULL;
185 +       struct list_head *lp;
186 +
187 +       /* verify this dentry is really new */
188 +       assert(dentry->d_inode == NULL);
189 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
190 +       if (rehash)
191 +               assert(d_unhashed(dentry));             /* d_rehash */
192 +       assert(list_empty(&dentry->d_subdirs));
193 +
194 +       spin_lock(&dcache_lock);
195 +       if (!inode)
196 +               goto do_rehash;
197 +
198 +       if (!test_opt(inode->i_sb, IOPEN))
199 +               goto do_instantiate;
200 +
201 +       /* preferrably return a connected dentry */
202 +       list_for_each(lp, &inode->i_dentry) {
203 +               tmp = list_entry(lp, struct dentry, d_alias);
204 +               if (tmp->d_flags & DCACHE_DISCONNECTED) {
205 +                       assert(tmp->d_alias.next == &inode->i_dentry);
206 +                       assert(tmp->d_alias.prev == &inode->i_dentry);
207 +                       goal = tmp;
208 +                       dget_locked(goal);
209 +                       break;
210 +               }
211 +       }
212 +
213 +       if (!goal)
214 +               goto do_instantiate;
215 +
216 +       /* Move the goal to the de hash queue */
217 +       goal->d_flags &= ~DCACHE_DISCONNECTED;
218 +       security_d_instantiate(goal, inode);
219 +       __d_drop(dentry);
220 +       d_rehash_cond(dentry, 0);
221 +       d_move_locked(goal, dentry);
222 +       spin_unlock(&dcache_lock);
223 +       iput(inode);
224 +
225 +       return goal;
226 +
227 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
228 +do_instantiate:
229 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
230 +       dentry->d_inode = inode;
231 +do_rehash:
232 +       if (rehash)
233 +               d_rehash_cond(dentry, 0);                       /* d_rehash */
234 +       spin_unlock(&dcache_lock);
235 +
236 +       return NULL;
237 +}
238 +
239 +/*
240 + * Similar as d_instantiate() except that it drops the disconnected
241 + * dentry if any.
242 + */
243 +void iopen_d_instantiate(struct dentry *dentry, struct inode * inode)
244 +{
245 +       struct dentry *dis_dentry;
246 +
247 +       /* verify this dentry is really new */
248 +       assert(dentry->d_inode == NULL);
249 +       assert(list_empty(&dentry->d_alias));
250 +
251 +       spin_lock(&dcache_lock);
252 +       if (!inode || !test_opt(inode->i_sb, IOPEN) ||
253 +           list_empty(&inode->i_dentry))
254 +               goto do_instantiate;
255 +
256 +       /* a disconnected dentry has been added in our back,
257 +        * we have to drop this dentry, see bug 16362/15713*/
258 +       dis_dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
259 +       spin_lock(&dis_dentry->d_lock);
260 +       assert(dis_dentry->d_alias.next == &inode->i_dentry);
261 +       assert(dis_dentry->d_alias.prev == &inode->i_dentry);
262 +       assert(dis_dentry->d_flags & DCACHE_DISCONNECTED);
263 +       __d_drop(dis_dentry);
264 +       list_del_init(&dis_dentry->d_alias);
265 +       spin_unlock(&dis_dentry->d_lock);
266 +
267 +do_instantiate:
268 +       if (inode)
269 +               list_add(&dentry->d_alias, &inode->i_dentry);
270 +       dentry->d_inode = inode;
271 +       spin_unlock(&dcache_lock);
272 +       security_d_instantiate(dentry, inode);
273 +}
274 +
275 +/*
276 + * These are the special structures for the iopen pseudo directory.
277 + */
278 +
279 +static struct inode_operations iopen_inode_operations = {
280 +       lookup:         iopen_lookup,           /* BKL held */
281 +};
282 +
283 +static struct file_operations iopen_file_operations = {
284 +       read:           generic_read_dir,
285 +};
286 +
287 +static int match_dentry(struct dentry *dentry, const char *name)
288 +{
289 +       int     len;
290 +
291 +       len = strlen(name);
292 +       if (dentry->d_name.len != len)
293 +               return 0;
294 +       if (strncmp(dentry->d_name.name, name, len))
295 +               return 0;
296 +       return 1;
297 +}
298 +
299 +/*
300 + * This function is spliced into ext3_lookup and returns 1 the file
301 + * name is __iopen__ and dentry has been filled in appropriately.
302 + */
303 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
304 +{
305 +       struct inode *inode;
306 +
307 +       if (dir->i_ino != EXT3_ROOT_INO ||
308 +           !test_opt(dir->i_sb, IOPEN) ||
309 +           !match_dentry(dentry, "__iopen__"))
310 +               return 0;
311 +
312 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
313 +
314 +       if (!inode)
315 +               return 0;
316 +       d_add(dentry, inode);
317 +       return 1;
318 +}
319 +
320 +/*
321 + * This function is spliced into read_inode; it returns 1 if inode
322 + * number is the one for /__iopen__, in which case the inode is filled
323 + * in appropriately.  Otherwise, this fuction returns 0.
324 + */
325 +int ext3_iopen_get_inode(struct inode *inode)
326 +{
327 +       if (inode->i_ino != EXT3_BAD_INO)
328 +               return 0;
329 +
330 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
331 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
332 +               inode->i_mode |= 0777;
333 +       inode->i_uid = 0;
334 +       inode->i_gid = 0;
335 +       inode->i_nlink = 1;
336 +       inode->i_size = 4096;
337 +       inode->i_atime = CURRENT_TIME;
338 +       inode->i_ctime = CURRENT_TIME;
339 +       inode->i_mtime = CURRENT_TIME;
340 +       EXT3_I(inode)->i_dtime = 0;
341 +       EXT3_I(inode)->i_file_acl = 0;
342 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
343 +                                        * (for stat), not the fs block
344 +                                        * size */
345 +       inode->i_blocks = 0;
346 +       inode->i_version = 1;
347 +       inode->i_generation = 0;
348 +
349 +       inode->i_op = &iopen_inode_operations;
350 +       inode->i_fop = &iopen_file_operations;
351 +       inode->i_mapping->a_ops = 0;
352 +
353 +       return 1;
354 +}
355 Index: linux-2.6.9-67/fs/ext3/iopen.h
356 ===================================================================
357 --- /dev/null
358 +++ linux-2.6.9-67/fs/ext3/iopen.h
359 @@ -0,0 +1,24 @@
360 +/*
361 + * iopen.h
362 + *
363 + * Special support for opening files by inode number.
364 + *
365 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
366 + *
367 + * This file may be redistributed under the terms of the GNU General
368 + * Public License.
369 + */
370 +
371 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
372 +extern int ext3_iopen_get_inode(struct inode *inode);
373 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
374 +                                          struct inode *inode, int rehash);
375 +extern void iopen_d_instantiate(struct dentry *dentry, struct inode * inode);
376 +
377 +#if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
378 +#define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
379 +#endif
380 +
381 +#if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
382 +#define d_move_locked(dentry, target) __d_move(dentry, target)
383 +#endif
384 Index: linux-2.6.9-67/fs/ext3/namei.c
385 ===================================================================
386 --- linux-2.6.9-67.orig/fs/ext3/namei.c
387 +++ linux-2.6.9-67/fs/ext3/namei.c
388 @@ -37,6 +37,7 @@
389  #include <linux/buffer_head.h>
390  #include <linux/smp_lock.h>
391  #include "xattr.h"
392 +#include "iopen.h"
393  #include "acl.h"
394  
395  /*
396 @@ -1017,6 +1018,9 @@ static struct dentry *ext3_lookup(struct
397         if (dentry->d_name.len > EXT3_NAME_LEN)
398                 return ERR_PTR(-ENAMETOOLONG);
399  
400 +       if (ext3_check_for_iopen(dir, dentry))
401 +               return NULL;
402 +
403         bh = ext3_find_entry(dentry, &de);
404         inode = NULL;
405         if (bh) {
406 @@ -1027,10 +1031,8 @@ static struct dentry *ext3_lookup(struct
407                 if (!inode)
408                         return ERR_PTR(-EACCES);
409         }
410 -       if (inode)
411 -               return d_splice_alias(inode, dentry);
412 -       d_add(dentry, inode);
413 -       return NULL;
414 +
415 +       return iopen_connect_dentry(dentry, inode, 1);
416  }
417  
418  
419 @@ -1669,7 +1671,7 @@ static int ext3_add_nondir(handle_t *han
420         int err = ext3_add_entry(handle, dentry, inode);
421         if (!err) {
422                 ext3_mark_inode_dirty(handle, inode);
423 -               d_instantiate(dentry, inode);
424 +               iopen_d_instantiate(dentry, inode);
425                 return 0;
426         }
427         ext3_dec_count(handle, inode);
428 @@ -1831,7 +1833,7 @@ retry:
429         dir->i_nlink++;
430         ext3_update_dx_flag(dir);
431         ext3_mark_inode_dirty(handle, dir);
432 -       d_instantiate(dentry, inode);
433 +       iopen_d_instantiate(dentry, inode);
434  out_stop:
435         ext3_journal_stop(handle);
436         if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
437 @@ -2099,10 +2101,6 @@ static int ext3_rmdir (struct inode * di
438                               inode->i_nlink);
439         inode->i_version++;
440         inode->i_nlink = 0;
441 -       /* There's no need to set i_disksize: the fact that i_nlink is
442 -        * zero will ensure that the right thing happens during any
443 -        * recovery. */
444 -       inode->i_size = 0;
445         ext3_orphan_add(handle, inode);
446         inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
447         ext3_mark_inode_dirty(handle, inode);
448 @@ -2225,6 +2223,23 @@ out_stop:
449         return err;
450  }
451  
452 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
453 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
454 +                        struct inode *inode)
455 +{
456 +       int err = ext3_add_entry(handle, dentry, inode);
457 +       if (!err) {
458 +               err = ext3_mark_inode_dirty(handle, inode);
459 +               if (err == 0) {
460 +                       dput(iopen_connect_dentry(dentry, inode, 0));
461 +                       return 0;
462 +               }
463 +       }
464 +       ext3_dec_count(handle, inode);
465 +       iput(inode);
466 +       return err;
467 +}
468 +
469  static int ext3_link (struct dentry * old_dentry,
470                 struct inode * dir, struct dentry *dentry)
471  {
472 @@ -2254,7 +2269,8 @@ retry:
473         ext3_inc_count(handle, inode);
474         atomic_inc(&inode->i_count);
475  
476 -       err = ext3_add_nondir(handle, dentry, inode);
477 +       err = ext3_add_link(handle, dentry, inode);
478 +       ext3_orphan_del(handle, inode);
479         ext3_journal_stop(handle);
480         if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
481                 goto retry;
482 Index: linux-2.6.9-67/fs/ext3/super.c
483 ===================================================================
484 --- linux-2.6.9-67.orig/fs/ext3/super.c
485 +++ linux-2.6.9-67/fs/ext3/super.c
486 @@ -632,6 +632,7 @@ enum {
487         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
488         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
489         Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
490 +       Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
491  };
492  
493  static match_table_t tokens = {
494 @@ -678,6 +679,9 @@ static match_table_t tokens = {
495         {Opt_ignore, "noquota"},
496         {Opt_ignore, "quota"},
497         {Opt_ignore, "usrquota"},
498 +       {Opt_iopen, "iopen"},
499 +       {Opt_noiopen, "noiopen"},
500 +       {Opt_iopen_nopriv, "iopen_nopriv"},
501         {Opt_barrier, "barrier=%u"},
502         {Opt_err, NULL},
503         {Opt_resize, "resize"},
504 @@ -959,6 +963,18 @@ clear_qf_name:
505                         else
506                                 clear_opt(sbi->s_mount_opt, BARRIER);
507                         break;
508 +               case Opt_iopen:
509 +                       set_opt (sbi->s_mount_opt, IOPEN);
510 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
511 +                       break;
512 +               case Opt_noiopen:
513 +                       clear_opt (sbi->s_mount_opt, IOPEN);
514 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
515 +                       break;
516 +               case Opt_iopen_nopriv:
517 +                       set_opt (sbi->s_mount_opt, IOPEN);
518 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
519 +                       break;
520                 case Opt_ignore:
521                         break;
522                 case Opt_resize:
523 Index: linux-2.6.9-67/include/linux/ext3_fs.h
524 ===================================================================
525 --- linux-2.6.9-67.orig/include/linux/ext3_fs.h
526 +++ linux-2.6.9-67/include/linux/ext3_fs.h
527 @@ -355,6 +355,8 @@ struct ext3_inode {
528  #define EXT3_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
529  #define EXT3_MOUNT_BARRIER             0x10000 /* Use block barriers */
530  #define EXT3_MOUNT_RESERVATION         0x20000 /* Preallocation */
531 +#define EXT3_MOUNT_IOPEN               0x80000 /* Allow access via iopen */
532 +#define EXT3_MOUNT_IOPEN_NOPRIV                0x100000/* Make iopen world-readable */
533  
534  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
535  #ifndef _LINUX_EXT2_FS_H