Whamcloud - gitweb
b=16680
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / iopen-2.6-suse.patch
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
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
12  
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
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 @@ -2419,6 +2420,9 @@ void ext3_read_inode(struct inode * inod
27  #endif
28         ei->i_rsv_window.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED;
29  
30 +       if (ext3_iopen_get_inode(inode))
31 +               return;
32 +
33         if (ext3_get_inode_loc(inode, &iloc, 0))
34                 goto bad_inode;
35         bh = iloc.bh;
36 Index: linux-2.6.5-7.311/fs/ext3/iopen.c
37 ===================================================================
38 --- /dev/null
39 +++ linux-2.6.5-7.311/fs/ext3/iopen.c
40 @@ -0,0 +1,315 @@
41 +/*
42 + * linux/fs/ext3/iopen.c
43 + *
44 + * Special support for open by inode number
45 + *
46 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
47 + *
48 + * This file may be redistributed under the terms of the GNU General
49 + * Public License.
50 + *
51 + *
52 + * Invariants:
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.
57 + *
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
62 + * until it is gone.
63 + *
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.
69 + */
70 +
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>
79 +#include "iopen.h"
80 +
81 +#ifndef assert
82 +#define assert(test) J_ASSERT(test)
83 +#endif
84 +
85 +#define IOPEN_NAME_LEN 32
86 +
87 +/*
88 + * This implements looking up an inode by number.
89 + */
90 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
91 +                                  struct nameidata *nd)
92 +{
93 +       struct inode *inode;
94 +       unsigned long ino;
95 +       struct list_head *lp;
96 +       struct dentry *alternate;
97 +       char buf[IOPEN_NAME_LEN];
98 +
99 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
100 +               return ERR_PTR(-ENAMETOOLONG);
101 +
102 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
103 +       buf[dentry->d_name.len] = 0;
104 +
105 +       if (strcmp(buf, ".") == 0)
106 +               ino = dir->i_ino;
107 +       else if (strcmp(buf, "..") == 0)
108 +               ino = EXT3_ROOT_INO;
109 +       else
110 +               ino = simple_strtoul(buf, 0, 0);
111 +
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);
118 +
119 +       inode = iget(dir->i_sb, ino);
120 +       if (!inode)
121 +               return ERR_PTR(-EACCES);
122 +       if (is_bad_inode(inode)) {
123 +               iput(inode);
124 +               return ERR_PTR(-ENOENT);
125 +       }
126 +
127 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
128 +       assert(d_unhashed(dentry));                     /* d_rehash */
129 +
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));
135 +       }
136 +
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);
144 +               iput(inode);
145 +               spin_unlock(&dcache_lock);
146 +               return alternate;
147 +       }
148 +       dentry->d_flags |= DCACHE_DISCONNECTED;
149 +
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;
153 +
154 +       d_rehash_cond(dentry, 0);
155 +       spin_unlock(&dcache_lock);
156 +
157 +       return NULL;
158 +}
159 +
160 +#define do_switch(x,y) do { \
161 +       __typeof__ (x) __tmp = x; \
162 +       x = y; y = __tmp; } while (0)
163 +
164 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
165 +{
166 +       const unsigned char *old_name, *new_name;
167 +
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;
177 +}
178 +
179 +/* This function is spliced into ext3_lookup and does the move of a
180 + * disconnected dentry (if it exists) to a connected dentry.
181 + */
182 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
183 +                                   int rehash)
184 +{
185 +       struct dentry *tmp, *goal = NULL;
186 +       struct list_head *lp;
187 +
188 +       /* verify this dentry is really new */
189 +       assert(dentry->d_inode == NULL);
190 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
191 +       if (rehash)
192 +               assert(d_unhashed(dentry));     /* d_rehash */
193 +       assert(list_empty(&dentry->d_subdirs));
194 +
195 +       spin_lock(&dcache_lock);
196 +       if (!inode)
197 +               goto do_rehash;
198 +
199 +       if (!test_opt(inode->i_sb, IOPEN))
200 +               goto do_instantiate;
201 +
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);
208 +                       goal = tmp;
209 +                       dget_locked(goal);
210 +                       break;
211 +               }
212 +       }
213 +
214 +       if (!goal)
215 +               goto do_instantiate;
216 +
217 +       /* Move the goal to the de hash queue */
218 +       goal->d_flags &= ~DCACHE_DISCONNECTED;
219 +       security_d_instantiate(goal, inode);
220 +       __d_drop(dentry);
221 +       d_rehash_cond(dentry, 0);
222 +       d_move_locked(goal, dentry);
223 +       spin_unlock(&dcache_lock);
224 +       iput(inode);
225 +
226 +       return goal;
227 +
228 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
229 +do_instantiate:
230 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
231 +       dentry->d_inode = inode;
232 +do_rehash:
233 +       if (rehash)
234 +               d_rehash_cond(dentry, 0);
235 +       spin_unlock(&dcache_lock);
236 +
237 +       return NULL;
238 +}
239 +
240 +/*
241 + * Similar as d_instantiate() except that it drops the disconnected
242 + * dentry if any.
243 + */
244 +void iopen_d_instantiate(struct dentry *dentry, struct inode * inode)
245 +{
246 +       struct dentry *dis_dentry;
247 +
248 +       /* verify this dentry is really new */
249 +       assert(dentry->d_inode == NULL);
250 +       assert(list_empty(&dentry->d_alias));
251 +
252 +       spin_lock(&dcache_lock);
253 +       if (!inode || !test_opt(inode->i_sb, IOPEN) ||
254 +           list_empty(&inode->i_dentry))
255 +               goto do_instantiate;
256 +
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);
267 +
268 +do_instantiate:
269 +       if (inode)
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);
274 +}
275 +
276 +/*
277 + * These are the special structures for the iopen pseudo directory.
278 + */
279 +
280 +static struct inode_operations iopen_inode_operations = {
281 +       lookup:         iopen_lookup,           /* BKL held */
282 +};
283 +
284 +static struct file_operations iopen_file_operations = {
285 +       read:           generic_read_dir,
286 +};
287 +
288 +static int match_dentry(struct dentry *dentry, const char *name)
289 +{
290 +       int     len;
291 +
292 +       len = strlen(name);
293 +       if (dentry->d_name.len != len)
294 +               return 0;
295 +       if (strncmp(dentry->d_name.name, name, len))
296 +               return 0;
297 +       return 1;
298 +}
299 +
300 +/*
301 + * This function is spliced into ext3_lookup and returns 1 the file
302 + * name is __iopen__ and dentry has been filled in appropriately.
303 + */
304 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
305 +{
306 +       struct inode *inode;
307 +
308 +       if (dir->i_ino != EXT3_ROOT_INO ||
309 +           !test_opt(dir->i_sb, IOPEN) ||
310 +           !match_dentry(dentry, "__iopen__"))
311 +               return 0;
312 +
313 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
314 +
315 +       if (!inode)
316 +               return 0;
317 +       d_add(dentry, inode);
318 +       return 1;
319 +}
320 +
321 +/*
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.
325 + */
326 +int ext3_iopen_get_inode(struct inode *inode)
327 +{
328 +       if (inode->i_ino != EXT3_BAD_INO)
329 +               return 0;
330 +
331 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
332 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
333 +               inode->i_mode |= 0777;
334 +       inode->i_uid = 0;
335 +       inode->i_gid = 0;
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
345 +                                        * size */
346 +       inode->i_blocks = 0;
347 +       inode->i_version = 1;
348 +       inode->i_generation = 0;
349 +
350 +       inode->i_op = &iopen_inode_operations;
351 +       inode->i_fop = &iopen_file_operations;
352 +       inode->i_mapping->a_ops = 0;
353 +
354 +       return 1;
355 +}
356 Index: linux-2.6.5-7.311/fs/ext3/iopen.h
357 ===================================================================
358 --- /dev/null
359 +++ linux-2.6.5-7.311/fs/ext3/iopen.h
360 @@ -0,0 +1,24 @@
361 +/*
362 + * iopen.h
363 + *
364 + * Special support for opening files by inode number.
365 + *
366 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
367 + *
368 + * This file may be redistributed under the terms of the GNU General
369 + * Public License.
370 + */
371 +
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);
377 +
378 +#if !defined(HAVE_D_REHASH_COND) && defined(HAVE___D_REHASH)
379 +#define d_rehash_cond(dentry, lock) __d_rehash(dentry, lock)
380 +#endif
381 +
382 +#if !defined(HAVE_D_MOVE_LOCKED) && defined(HAVE___D_MOVE)
383 +#define d_move_locked(dentry, target) __d_move(dentry, target)
384 +#endif
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
389 @@ -37,6 +37,7 @@
390  #include <linux/buffer_head.h>
391  #include <linux/smp_lock.h>
392  #include "xattr.h"
393 +#include "iopen.h"
394  #include "acl.h"
395  
396  /*
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);
400  
401 +       if (ext3_check_for_iopen(dir, dentry))
402 +               return NULL;
403 +
404         bh = ext3_find_entry(dentry, &de);
405         inode = NULL;
406         if (bh) {
407 @@ -1034,10 +1038,8 @@ static struct dentry *ext3_lookup(struct
408                 if (!inode)
409                         return ERR_PTR(-EACCES);
410         }
411 -       if (inode)
412 -               return d_splice_alias(inode, dentry);
413 -       d_add(dentry, inode);
414 -       return NULL;
415 +
416 +       return iopen_connect_dentry(dentry, inode, 1);
417  }
418  
419  
420 @@ -1653,7 +1655,7 @@ static int ext3_add_nondir(handle_t *han
421         if (!err) {
422                 err = ext3_mark_inode_dirty(handle, inode);
423                 if (!err) {
424 -                       d_instantiate(dentry, inode);
425 +                       iopen_d_instantiate(dentry, inode);
426                         return 0;
427                 }
428         }
429 @@ -1814,7 +1816,7 @@ retry:
430         dir->i_nlink++;
431         ext3_update_dx_flag(dir);
432         ext3_mark_inode_dirty(handle, dir);
433 -       d_instantiate(dentry, inode);
434 +       iopen_d_instantiate(dentry, inode);
435  out_stop:
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
439                               inode->i_nlink);
440         inode->i_version++;
441         inode->i_nlink = 0;
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
444 -        * recovery. */
445 -       inode->i_size = 0;
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:
450         return err;
451  }
452  
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)
456 +{
457 +       int err = ext3_add_entry(handle, dentry, inode);
458 +       if (!err) {
459 +               err = ext3_mark_inode_dirty(handle, inode);
460 +               if (err == 0) {
461 +                       dput(iopen_connect_dentry(dentry, inode, 0));
462 +                       return 0;
463 +               }
464 +       }
465 +       ext3_dec_count(handle, inode);
466 +       iput(inode);
467 +       return err;
468 +}
469 +
470  static int ext3_link (struct dentry * old_dentry,
471                 struct inode * dir, struct dentry *dentry)
472  {
473 @@ -2222,7 +2237,8 @@ retry:
474         ext3_inc_count(handle, inode);
475         atomic_inc(&inode->i_count);
476  
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))
482                 goto retry;
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,
490         Opt_err,
491 +       Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
492  };
493  
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"},
503         {Opt_err, NULL}
504  };
505 @@ -823,6 +827,18 @@ static int parse_options (char * options
506                         else
507                                 clear_opt(sbi->s_mount_opt, BARRIER);
508                         break;
509 +               case Opt_iopen:
510 +                       set_opt (sbi->s_mount_opt, IOPEN);
511 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
512 +                       break;
513 +               case Opt_noiopen:
514 +                       clear_opt (sbi->s_mount_opt, IOPEN);
515 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
516 +                       break;
517 +               case Opt_iopen_nopriv:
518 +                       set_opt (sbi->s_mount_opt, IOPEN);
519 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
520 +                       break;
521                 case Opt_ignore:
522                         break;
523                 default:
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 */
534  
535  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
536  #ifndef _LINUX_EXT2_FS_H