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