Whamcloud - gitweb
39ebb392dcabec4b9d447a22fe25f937e9beb9bb
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / iopen-2.6-rhel4.patch
1 Index: linux-stage/fs/ext3/Makefile
2 ===================================================================
3 --- linux-stage.orig/fs/ext3/Makefile   2005-02-25 14:31:53.151076368 +0200
4 +++ linux-stage/fs/ext3/Makefile        2005-02-25 14:41:51.259150120 +0200
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-stage/fs/ext3/inode.c
15 ===================================================================
16 --- linux-stage.orig/fs/ext3/inode.c    2005-02-25 14:37:30.983718000 +0200
17 +++ linux-stage/fs/ext3/inode.c 2005-02-25 14:47:42.069818792 +0200
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 @@ -2408,6 +2409,8 @@
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-stage/fs/ext3/iopen.c
36 ===================================================================
37 --- linux-stage.orig/fs/ext3/iopen.c    2005-02-25 14:41:01.017787968 +0200
38 +++ linux-stage/fs/ext3/iopen.c 2005-02-25 14:41:01.045783712 +0200
39 @@ -0,0 +1,278 @@
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 + * These are the special structures for the iopen pseudo directory.
241 + */
242 +
243 +static struct inode_operations iopen_inode_operations = {
244 +       lookup:         iopen_lookup,           /* BKL held */
245 +};
246 +
247 +static struct file_operations iopen_file_operations = {
248 +       read:           generic_read_dir,
249 +};
250 +
251 +static int match_dentry(struct dentry *dentry, const char *name)
252 +{
253 +       int     len;
254 +
255 +       len = strlen(name);
256 +       if (dentry->d_name.len != len)
257 +               return 0;
258 +       if (strncmp(dentry->d_name.name, name, len))
259 +               return 0;
260 +       return 1;
261 +}
262 +
263 +/*
264 + * This function is spliced into ext3_lookup and returns 1 the file
265 + * name is __iopen__ and dentry has been filled in appropriately.
266 + */
267 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
268 +{
269 +       struct inode *inode;
270 +
271 +       if (dir->i_ino != EXT3_ROOT_INO ||
272 +           !test_opt(dir->i_sb, IOPEN) ||
273 +           !match_dentry(dentry, "__iopen__"))
274 +               return 0;
275 +
276 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
277 +
278 +       if (!inode)
279 +               return 0;
280 +       d_add(dentry, inode);
281 +       return 1;
282 +}
283 +
284 +/*
285 + * This function is spliced into read_inode; it returns 1 if inode
286 + * number is the one for /__iopen__, in which case the inode is filled
287 + * in appropriately.  Otherwise, this fuction returns 0.
288 + */
289 +int ext3_iopen_get_inode(struct inode *inode)
290 +{
291 +       if (inode->i_ino != EXT3_BAD_INO)
292 +               return 0;
293 +
294 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
295 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
296 +               inode->i_mode |= 0777;
297 +       inode->i_uid = 0;
298 +       inode->i_gid = 0;
299 +       inode->i_nlink = 1;
300 +       inode->i_size = 4096;
301 +       inode->i_atime = CURRENT_TIME;
302 +       inode->i_ctime = CURRENT_TIME;
303 +       inode->i_mtime = CURRENT_TIME;
304 +       EXT3_I(inode)->i_dtime = 0;
305 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
306 +                                        * (for stat), not the fs block
307 +                                        * size */
308 +       inode->i_blocks = 0;
309 +       inode->i_version = 1;
310 +       inode->i_generation = 0;
311 +
312 +       inode->i_op = &iopen_inode_operations;
313 +       inode->i_fop = &iopen_file_operations;
314 +       inode->i_mapping->a_ops = 0;
315 +
316 +       return 1;
317 +}
318 Index: linux-stage/fs/ext3/iopen.h
319 ===================================================================
320 --- linux-stage.orig/fs/ext3/iopen.h    2005-02-25 14:41:01.017787968 +0200
321 +++ linux-stage/fs/ext3/iopen.h 2005-02-25 14:41:01.045783712 +0200
322 @@ -0,0 +1,15 @@
323 +/*
324 + * iopen.h
325 + *
326 + * Special support for opening files by inode number.
327 + *
328 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
329 + *
330 + * This file may be redistributed under the terms of the GNU General
331 + * Public License.
332 + */
333 +
334 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
335 +extern int ext3_iopen_get_inode(struct inode *inode);
336 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
337 +                                          struct inode *inode, int rehash);
338 Index: linux-stage/fs/ext3/namei.c
339 ===================================================================
340 --- linux-stage.orig/fs/ext3/namei.c    2005-02-25 14:37:28.975023368 +0200
341 +++ linux-stage/fs/ext3/namei.c 2005-02-25 14:46:43.090784968 +0200
342 @@ -37,6 +37,7 @@
343  #include <linux/buffer_head.h>
344  #include <linux/smp_lock.h>
345  #include "xattr.h"
346 +#include "iopen.h"
347  #include "acl.h"
348  
349  /*
350 @@ -980,6 +981,9 @@
351         if (dentry->d_name.len > EXT3_NAME_LEN)
352                 return ERR_PTR(-ENAMETOOLONG);
353  
354 +       if (ext3_check_for_iopen(dir, dentry))
355 +               return NULL;
356 +
357         bh = ext3_find_entry(dentry, &de);
358         inode = NULL;
359         if (bh) {
360 @@ -990,10 +994,8 @@
361                 if (!inode)
362                         return ERR_PTR(-EACCES);
363         }
364 -       if (inode)
365 -               return d_splice_alias(inode, dentry);
366 -       d_add(dentry, inode);
367 -       return NULL;
368 +
369 +       return iopen_connect_dentry(dentry, inode, 1);
370  }
371  
372  
373 @@ -2037,10 +2039,6 @@
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;
383         ext3_mark_inode_dirty(handle, inode);
384 @@ -2163,6 +2161,23 @@
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 @@ -2186,7 +2201,8 @@
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-stage/fs/ext3/super.c
419 ===================================================================
420 --- linux-stage.orig/fs/ext3/super.c    2005-02-25 14:37:30.987717392 +0200
421 +++ linux-stage/fs/ext3/super.c 2005-02-25 14:44:50.495901992 +0200
422 @@ -586,6 +586,7 @@
423         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
424         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
425         Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
426 +       Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
427  };
428  
429  static match_table_t tokens = {
430 @@ -633,6 +634,9 @@
431         {Opt_ignore, "noquota"},
432         {Opt_ignore, "quota"},
433         {Opt_ignore, "usrquota"},
434 +       {Opt_iopen, "iopen"},
435 +       {Opt_noiopen, "noiopen"},
436 +       {Opt_iopen_nopriv, "iopen_nopriv"},
437         {Opt_barrier, "barrier=%u"},
438         {Opt_err, NULL},
439         {Opt_resize, "resize"},
440 @@ -914,6 +918,18 @@
441                         else
442                                 clear_opt(sbi->s_mount_opt, BARRIER);
443                         break;
444 +               case Opt_iopen:
445 +                       set_opt (sbi->s_mount_opt, IOPEN);
446 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
447 +                       break;
448 +               case Opt_noiopen:
449 +                       clear_opt (sbi->s_mount_opt, IOPEN);
450 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
451 +                       break;
452 +               case Opt_iopen_nopriv:
453 +                       set_opt (sbi->s_mount_opt, IOPEN);
454 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
455 +                       break;
456                 case Opt_ignore:
457                         break;
458                 case Opt_resize:
459 Index: linux-stage/include/linux/ext3_fs.h
460 ===================================================================
461 --- linux-stage.orig/include/linux/ext3_fs.h    2005-02-25 14:37:28.977023064 +0200
462 +++ linux-stage/include/linux/ext3_fs.h 2005-02-25 14:49:00.569884968 +0200
463 @@ -355,6 +355,8 @@
464  #define EXT3_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
465  #define EXT3_MOUNT_BARRIER             0x10000 /* Use block barriers */
466  #define EXT3_MOUNT_RESERVATION         0x20000 /* Preallocation */
467 +#define EXT3_MOUNT_IOPEN               0x80000 /* Allow access via iopen */
468 +#define EXT3_MOUNT_IOPEN_NOPRIV                0x100000/* Make iopen world-readable */
469  
470  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
471  #ifndef _LINUX_EXT2_FS_H