Whamcloud - gitweb
landing b_cmobd_merge on HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / iopen-2.4.18-2.patch
1  Documentation/filesystems/ext2.txt |   16 ++
2  fs/ext3/Makefile                   |    2 
3  fs/ext3/inode.c                    |    4 
4  fs/ext3/iopen.c                    |  259 +++++++++++++++++++++++++++++++++++++
5  fs/ext3/iopen.h                    |   13 +
6  fs/ext3/namei.c                    |   12 +
7  fs/ext3/super.c                    |   11 +
8  include/linux/ext3_fs.h            |    2 
9  8 files changed, 318 insertions(+), 1 deletion(-)
10
11 Index: linux-aed/Documentation/filesystems/ext2.txt
12 ===================================================================
13 --- linux-aed.orig/Documentation/filesystems/ext2.txt   Tue May  4 13:14:35 2004
14 +++ linux-aed/Documentation/filesystems/ext2.txt        Tue May  4 19:17:12 2004
15 @@ -35,6 +35,22 @@
16  
17  sb=n                           Use alternate superblock at this location.
18  
19 +iopen                          Makes an invisible pseudo-directory called
20 +                               __iopen__ available in the root directory
21 +                               of the filesystem.  Allows open-by-inode-
22 +                               number.  i.e., inode 3145 can be accessed
23 +                               via /mntpt/__iopen__/3145
24 +
25 +iopen_nopriv                   This option makes the iopen directory be
26 +                               world-readable.  This may be safer since it
27 +                               allows daemons to run as an unprivileged user,
28 +                               however it significantly changes the security
29 +                               model of a Unix filesystem, since previously
30 +                               all files under a mode 700 directory were not
31 +                               generally avilable even if the
32 +                               permissions on the file itself is
33 +                               world-readable.
34 +
35  grpquota,noquota,quota,usrquota        Quota options are silently ignored by ext2.
36  
37  
38 Index: linux-aed/fs/ext3/Makefile
39 ===================================================================
40 --- linux-aed.orig/fs/ext3/Makefile     Tue May  4 19:16:51 2004
41 +++ linux-aed/fs/ext3/Makefile  Tue May  4 19:17:12 2004
42 @@ -11,7 +11,7 @@
43  
44  export-objs := ext3-exports.o
45  
46 -obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
47 +obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
48                 ioctl.o namei.o super.o symlink.o xattr.o hash.o ext3-exports.o
49  obj-m    := $(O_TARGET)
50  
51 Index: linux-aed/fs/ext3/inode.c
52 ===================================================================
53 --- linux-aed.orig/fs/ext3/inode.c      Tue May  4 19:17:09 2004
54 +++ linux-aed/fs/ext3/inode.c   Tue May  4 19:17:12 2004
55 @@ -31,6 +31,7 @@
56  #include <linux/highuid.h>
57  #include <linux/quotaops.h>
58  #include <linux/module.h>
59 +#include "iopen.h"
60  
61  /*
62   * SEARCH_FROM_ZERO forces each block allocation to search from the start
63 @@ -2277,6 +2278,9 @@
64         struct buffer_head *bh;
65         int block;
66         
67 +       if (ext3_iopen_get_inode(inode))
68 +               return;
69 +
70         if(ext3_get_inode_loc(inode, &iloc))
71                 goto bad_inode;
72         bh = iloc.bh;
73 Index: linux-aed/fs/ext3/iopen.c
74 ===================================================================
75 --- linux-aed.orig/fs/ext3/iopen.c      Tue May  4 13:14:35 2004
76 +++ linux-aed/fs/ext3/iopen.c   Tue May  4 19:17:12 2004
77 @@ -0,0 +1,282 @@
78 +/*
79 + * linux/fs/ext3/iopen.c
80 + *
81 + * Special support for open by inode number
82 + *
83 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
84 + *
85 + * This file may be redistributed under the terms of the GNU General
86 + * Public License.
87 + *
88 + *
89 + * Invariants:
90 + *   - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
91 + *     for an inode at one time.
92 + *   - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
93 + *     aliases on an inode at the same time.
94 + *
95 + * If we have any connected dentry aliases for an inode, use one of those
96 + * in iopen_lookup().  Otherwise, we instantiate a single NFSD_DISCONNECTED
97 + * dentry for this inode, which thereafter will be found by the dcache
98 + * when looking up this inode number in __iopen__, so we don't return here
99 + * until it is gone.
100 + *
101 + * If we get an inode via a regular name lookup, then we "rename" the
102 + * NFSD_DISCONNECTED dentry to the proper name and parent.  This ensures
103 + * existing users of the disconnected dentry will continue to use the same
104 + * dentry as the connected users, and there will never be both kinds of
105 + * dentry aliases at one time.
106 + */
107 +
108 +#include <linux/sched.h>
109 +#include <linux/fs.h>
110 +#include <linux/locks.h>
111 +#include <linux/ext3_jbd.h>
112 +#include <linux/jbd.h>
113 +#include <linux/ext3_fs.h>
114 +#include <linux/smp_lock.h>
115 +#include "iopen.h"
116 +
117 +#ifndef assert
118 +#define assert(test) J_ASSERT(test)
119 +#endif
120 +
121 +#define IOPEN_NAME_LEN 32
122 +
123 +/*
124 + * This implements looking up an inode by number.
125 + */
126 +static struct dentry *iopen_lookup(struct inode *dir, struct dentry *dentry)
127 +{
128 +       struct inode *inode;
129 +       unsigned long ino;
130 +       struct list_head *lp;
131 +       struct dentry *alternate;
132 +       char buf[IOPEN_NAME_LEN];
133 +
134 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
135 +               return ERR_PTR(-ENAMETOOLONG);
136 +
137 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
138 +       buf[dentry->d_name.len] = 0;
139 +
140 +       if (strcmp(buf, ".") == 0)
141 +               ino = dir->i_ino;
142 +       else if (strcmp(buf, "..") == 0)
143 +               ino = EXT3_ROOT_INO;
144 +       else
145 +               ino = simple_strtoul(buf, 0, 0);
146 +
147 +       if ((ino != EXT3_ROOT_INO &&
148 +            //ino != EXT3_ACL_IDX_INO &&
149 +            //ino != EXT3_ACL_DATA_INO &&
150 +            ino < EXT3_FIRST_INO(dir->i_sb)) ||
151 +           ino > le32_to_cpu(dir->i_sb->u.ext3_sb.s_es->s_inodes_count))
152 +               return ERR_PTR(-ENOENT);
153 +
154 +       inode = iget(dir->i_sb, ino);
155 +       if (!inode)
156 +               return ERR_PTR(-EACCES);
157 +       if (is_bad_inode(inode)) {
158 +               iput(inode);
159 +               return ERR_PTR(-ENOENT);
160 +       }
161 +
162 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
163 +       assert(list_empty(&dentry->d_hash));            /* d_rehash */
164 +
165 +       /* preferrably return a connected dentry */
166 +       spin_lock(&dcache_lock);
167 +       list_for_each(lp, &inode->i_dentry) {
168 +               alternate = list_entry(lp, struct dentry, d_alias);
169 +               assert(!(alternate->d_flags & DCACHE_NFSD_DISCONNECTED));
170 +       }
171 +
172 +       if (!list_empty(&inode->i_dentry)) {
173 +               alternate = list_entry(inode->i_dentry.next,
174 +                                      struct dentry, d_alias);
175 +               dget_locked(alternate);
176 +               alternate->d_vfs_flags |= DCACHE_REFERENCED;
177 +               iput(inode);
178 +               spin_unlock(&dcache_lock);
179 +               return alternate;
180 +       }
181 +       dentry->d_flags |= DCACHE_NFSD_DISCONNECTED;
182 +
183 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
184 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
185 +       dentry->d_inode = inode;
186 +
187 +       __d_rehash(dentry, 0);                          /* d_rehash */
188 +       spin_unlock(&dcache_lock);
189 +
190 +       return NULL;
191 +}
192 +
193 +#define do_switch(x,y) do { \
194 +       __typeof__ (x) __tmp = x; \
195 +       x = y; y = __tmp; } while (0)
196 +
197 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
198 +{
199 +       const unsigned char *old_name, *new_name;
200 +
201 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
202 +       old_name = target->d_name.name;
203 +       new_name = dentry->d_name.name;
204 +       if (old_name == target->d_iname)
205 +               old_name = dentry->d_iname;
206 +       if (new_name == dentry->d_iname)
207 +               new_name = target->d_iname;
208 +       target->d_name.name = new_name;
209 +       dentry->d_name.name = old_name;
210 +}
211 +
212 +/* This function is spliced into ext3_lookup and does the move of a
213 + * disconnected dentry (if it exists) to a connected dentry.
214 + */
215 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
216 +                                   int rehash)
217 +{
218 +       struct dentry *tmp, *goal = NULL;
219 +       struct list_head *lp;
220 +
221 +       /* verify this dentry is really new */
222 +       assert(dentry->d_inode == NULL);
223 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
224 +       if (rehash)
225 +               assert(list_empty(&dentry->d_hash));    /* d_rehash */
226 +       assert(list_empty(&dentry->d_subdirs));
227 +
228 +       spin_lock(&dcache_lock);
229 +       if (!inode)
230 +               goto do_rehash;
231 +
232 +       /* preferrably return a connected dentry */
233 +       list_for_each(lp, &inode->i_dentry) {
234 +               tmp = list_entry(lp, struct dentry, d_alias);
235 +               if (tmp->d_flags & DCACHE_NFSD_DISCONNECTED) {
236 +                       assert(tmp->d_alias.next == &inode->i_dentry);
237 +                       assert(tmp->d_alias.prev == &inode->i_dentry);
238 +                       goal = tmp;
239 +                       dget_locked(goal);
240 +                       break;
241 +               }
242 +       }
243 +
244 +       if (!goal)
245 +               goto do_instantiate;
246 +
247 +       /* Move the goal to the de hash queue - like d_move() */
248 +       goal->d_flags &= ~DCACHE_NFSD_DISCONNECTED;
249 +       list_del_init(&goal->d_hash);
250 +
251 +       list_del(&goal->d_child);
252 +       list_del(&dentry->d_child);
253 +
254 +       /* Switch the parents and the names.. */
255 +       switch_names(goal, dentry);
256 +       do_switch(goal->d_parent, dentry->d_parent);
257 +       do_switch(goal->d_name.len, dentry->d_name.len);
258 +       do_switch(goal->d_name.hash, dentry->d_name.hash);
259 +
260 +       /* And add them back to the (new) parent lists */
261 +       list_add(&goal->d_child, &goal->d_parent->d_subdirs);
262 +       list_add(&dentry->d_child, &dentry->d_parent->d_subdirs);
263 +       __d_rehash(goal, 0);
264 +       spin_unlock(&dcache_lock);
265 +       iput(inode);
266 +
267 +       return goal;
268 +
269 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
270 +do_instantiate:
271 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
272 +       dentry->d_inode = inode;
273 +do_rehash:
274 +       if (rehash)
275 +               __d_rehash(dentry, 0);                  /* d_rehash */
276 +       spin_unlock(&dcache_lock);
277 +
278 +       return NULL;
279 +}
280 +
281 +/*
282 + * These are the special structures for the iopen pseudo directory.
283 + */
284 +
285 +static struct inode_operations iopen_inode_operations = {
286 +       lookup:         iopen_lookup,           /* BKL held */
287 +};
288 +
289 +static struct file_operations iopen_file_operations = {
290 +       read:           generic_read_dir,
291 +};
292 +
293 +static int match_dentry(struct dentry *dentry, const char *name)
294 +{
295 +       int     len;
296 +
297 +       len = strlen(name);
298 +       if (dentry->d_name.len != len)
299 +               return 0;
300 +       if (strncmp(dentry->d_name.name, name, len))
301 +               return 0;
302 +       return 1;
303 +}
304 +
305 +/*
306 + * This function is spliced into ext3_lookup and returns 1 the file
307 + * name is __iopen__ and dentry has been filled in appropriately.
308 + */
309 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
310 +{
311 +       struct inode *inode;
312 +
313 +       if (dir->i_ino != EXT3_ROOT_INO ||
314 +           !test_opt(dir->i_sb, IOPEN) ||
315 +           !match_dentry(dentry, "__iopen__"))
316 +               return 0;
317 +
318 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
319 +
320 +       if (!inode)
321 +               return 0;
322 +       d_add(dentry, inode);
323 +       return 1;
324 +}
325 +
326 +/*
327 + * This function is spliced into read_inode; it returns 1 if inode
328 + * number is the one for /__iopen__, in which case the inode is filled
329 + * in appropriately.  Otherwise, this fuction returns 0.
330 + */
331 +int ext3_iopen_get_inode(struct inode *inode)
332 +{
333 +       if (inode->i_ino != EXT3_BAD_INO)
334 +               return 0;
335 +
336 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
337 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
338 +               inode->i_mode |= 0777;
339 +       inode->i_uid = 0;
340 +       inode->i_gid = 0;
341 +       inode->i_nlink = 1;
342 +       inode->i_size = 4096;
343 +       inode->i_atime = CURRENT_TIME;
344 +       inode->i_ctime = CURRENT_TIME;
345 +       inode->i_mtime = CURRENT_TIME;
346 +       inode->u.ext3_i.i_dtime = 0;
347 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
348 +                                        * (for stat), not the fs block
349 +                                        * size */
350 +       inode->i_blocks = 0;
351 +       inode->i_version = 1;
352 +       inode->i_generation = 0;
353 +
354 +       inode->i_op = &iopen_inode_operations;
355 +       inode->i_fop = &iopen_file_operations;
356 +       inode->i_mapping->a_ops = 0;
357 +
358 +       return 1;
359 +}
360 Index: linux-aed/fs/ext3/iopen.h
361 ===================================================================
362 --- linux-aed.orig/fs/ext3/iopen.h      Tue May  4 13:14:35 2004
363 +++ linux-aed/fs/ext3/iopen.h   Tue May  4 19:17:12 2004
364 @@ -0,0 +1,15 @@
365 +/*
366 + * iopen.h
367 + *
368 + * Special support for opening files by inode number.
369 + *
370 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
371 + *
372 + * This file may be redistributed under the terms of the GNU General
373 + * Public License.
374 + */
375 +
376 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
377 +extern int ext3_iopen_get_inode(struct inode *inode);
378 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
379 +                                          struct inode *inode, int rehash);
380 Index: linux-aed/fs/ext3/namei.c
381 ===================================================================
382 --- linux-aed.orig/fs/ext3/namei.c      Tue May  4 19:17:05 2004
383 +++ linux-aed/fs/ext3/namei.c   Tue May  4 19:17:12 2004
384 @@ -34,6 +34,7 @@
385  #include <linux/locks.h>
386  #include <linux/quotaops.h>
387  #include <linux/slab.h>
388 +#include "iopen.h"
389  
390  /*
391   * define how far ahead to read directories while searching them.
392 @@ -713,6 +714,9 @@
393         if (dentry->d_name.len > EXT3_NAME_LEN)
394                 return ERR_PTR(-ENAMETOOLONG);
395  
396 +       if (ext3_check_for_iopen(dir, dentry))
397 +               return NULL;
398 +
399         bh = ext3_find_entry(dentry, &de);
400         inode = NULL;
401         if (bh) {
402 @@ -723,8 +727,8 @@
403                 if (!inode)
404                         return ERR_PTR(-EACCES);
405         }
406 -       d_add(dentry, inode);
407 -       return NULL;
408 +
409 +       return iopen_connect_dentry(dentry, inode, 1);
410  }
411  
412  #define S_SHIFT 12
413 @@ -1588,10 +1592,6 @@
414                               inode->i_nlink);
415         inode->i_version = ++event;
416         inode->i_nlink = 0;
417 -       /* There's no need to set i_disksize: the fact that i_nlink is
418 -        * zero will ensure that the right thing happens during any
419 -        * recovery. */
420 -       inode->i_size = 0;
421         ext3_orphan_add(handle, inode);
422         ext3_mark_inode_dirty(handle, inode);
423         dir->i_nlink--;
424 @@ -1711,6 +1711,23 @@
425         goto out_stop;
426  }
427  
428 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
429 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
430 +                        struct inode *inode)
431 +{
432 +       int err = ext3_add_entry(handle, dentry, inode);
433 +       if (!err) {
434 +               err = ext3_mark_inode_dirty(handle, inode);
435 +               if (err == 0) {
436 +                       (void)iopen_connect_dentry(dentry, inode, 0);
437 +                       return 0;
438 +               }
439 +       }
440 +       ext3_dec_count(handle, inode);
441 +       iput(inode);
442 +       return err;
443 +}
444 +
445  static int ext3_link (struct dentry * old_dentry,
446                 struct inode * dir, struct dentry *dentry)
447  {
448 @@ -1736,7 +1753,8 @@
449         ext3_inc_count(handle, inode);
450         atomic_inc(&inode->i_count);
451  
452 -       err = ext3_add_nondir(handle, dentry, inode);
453 +       err = ext3_add_link(handle, dentry, inode);
454 +       ext3_orphan_del(handle, inode);
455         ext3_mark_inode_dirty(handle, inode);
456         ext3_journal_stop(handle, dir);
457         return err;
458 Index: linux-aed/fs/ext3/super.c
459 ===================================================================
460 --- linux-aed.orig/fs/ext3/super.c      Tue May  4 19:17:01 2004
461 +++ linux-aed/fs/ext3/super.c   Tue May  4 19:17:12 2004
462 @@ -834,6 +834,18 @@
463                          || !strcmp (this_char, "quota")
464                          || !strcmp (this_char, "usrquota"))
465                         /* Don't do anything ;-) */ ;
466 +               else if (!strcmp (this_char, "iopen")) {
467 +                       set_opt (sbi->s_mount_opt, IOPEN);
468 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
469 +               }
470 +               else if (!strcmp (this_char, "noiopen")) {
471 +                       clear_opt (sbi->s_mount_opt, IOPEN);
472 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
473 +               }
474 +               else if (!strcmp (this_char, "iopen_nopriv")) {
475 +                       set_opt (sbi->s_mount_opt, IOPEN);
476 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
477 +               }
478                 else if (!strcmp (this_char, "journal")) {
479                         /* @@@ FIXME */
480                         /* Eventually we will want to be able to create
481 Index: linux-aed/include/linux/ext3_fs.h
482 ===================================================================
483 --- linux-aed.orig/include/linux/ext3_fs.h      Tue May  4 19:17:08 2004
484 +++ linux-aed/include/linux/ext3_fs.h   Tue May  4 19:17:12 2004
485 @@ -321,6 +321,8 @@
486    #define EXT3_MOUNT_WRITEBACK_DATA    0x0C00  /* No data ordering */
487  #define EXT3_MOUNT_UPDATE_JOURNAL      0x1000  /* Update the journal format */
488  #define EXT3_MOUNT_NO_UID32            0x2000  /* Disable 32-bit UIDs */
489 +#define EXT3_MOUNT_IOPEN               0x8000  /* Allow access via iopen */
490 +#define EXT3_MOUNT_IOPEN_NOPRIV                0x10000 /* Make iopen world-readable */
491  #define EXT3_MOUNT_ASYNCDEL            0x20000 /* Delayed deletion */
492  
493  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */