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