Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / kernel_patches / patches / iopen-2.4.20.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                    |   13 +
7  fs/ext3/super.c                    |   11 +
8  include/linux/ext3_fs.h            |    2 
9  8 files changed, 318 insertions(+), 2 deletions(-)
10
11 --- linux/Documentation/filesystems/ext2.txt~iopen-2.4.20       Wed Jul 11 15:44:45 2001
12 +++ linux-mmonroe/Documentation/filesystems/ext2.txt    Thu Jul 10 12:28:54 2003
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/fs/ext3/Makefile~iopen-2.4.20 Thu Jul 10 12:28:44 2003
37 +++ linux-mmonroe/fs/ext3/Makefile      Thu Jul 10 12:28:54 2003
38 @@ -11,7 +11,7 @@ O_TARGET := ext3.o
39  
40  export-objs := 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 bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
44                 ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
45  obj-m    := $(O_TARGET)
46  
47 --- linux/fs/ext3/inode.c~iopen-2.4.20  Thu Jul 10 12:28:46 2003
48 +++ linux-mmonroe/fs/ext3/inode.c       Thu Jul 10 12:28:54 2003
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 @@ -2253,6 +2254,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   Tue Jan 28 04:00:01 2003
68 +++ linux-mmonroe/fs/ext3/iopen.c       Thu Jul 10 12:28:54 2003
69 @@ -0,0 +1,259 @@
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 +       /* preferrably return a connected dentry */
155 +       spin_lock(&dcache_lock);
156 +       list_for_each(lp, &inode->i_dentry) {
157 +               alternate = list_entry(lp, struct dentry, d_alias);
158 +               assert(!(alternate->d_flags & DCACHE_NFSD_DISCONNECTED));
159 +       }
160 +
161 +       if (!list_empty(&inode->i_dentry)) {
162 +               alternate = list_entry(inode->i_dentry.next, 
163 +                                      struct dentry, d_alias);
164 +               dget_locked(alternate);
165 +               alternate->d_vfs_flags |= DCACHE_REFERENCED;
166 +               iput(inode);
167 +               spin_unlock(&dcache_lock);
168 +               return alternate;
169 +       }
170 +       dentry->d_flags |= DCACHE_NFSD_DISCONNECTED;
171 +       spin_unlock(&dcache_lock);
172 +
173 +       d_add(dentry, inode);
174 +       return NULL;
175 +}
176 +
177 +#define do_switch(x,y) do { \
178 +       __typeof__ (x) __tmp = x; \
179 +       x = y; y = __tmp; } while (0)
180 +
181 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
182 +{
183 +       const unsigned char *old_name, *new_name;
184 +
185 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN); 
186 +       old_name = target->d_name.name;
187 +       new_name = dentry->d_name.name;
188 +       if (old_name == target->d_iname)
189 +               old_name = dentry->d_iname;
190 +       if (new_name == dentry->d_iname)
191 +               new_name = target->d_iname;
192 +       target->d_name.name = new_name;
193 +       dentry->d_name.name = old_name;
194 +}
195 +
196 +/* This function is spliced into ext3_lookup and does the move of a
197 + * disconnected dentry (if it exists) to a connected dentry.
198 + */
199 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
200 +{
201 +       struct dentry *tmp, *goal = NULL;
202 +       struct list_head *lp;
203 +
204 +       /* preferrably return a connected dentry */
205 +       spin_lock(&dcache_lock);
206 +       /* verify this dentry is really new */
207 +       assert(!de->d_inode);
208 +       assert(list_empty(&de->d_subdirs));
209 +       assert(list_empty(&de->d_alias));
210 +
211 +
212 +       list_for_each(lp, &inode->i_dentry) {
213 +               tmp = list_entry(lp, struct dentry, d_alias);
214 +               if (tmp->d_flags & DCACHE_NFSD_DISCONNECTED) {
215 +                       assert(tmp->d_alias.next == &inode->i_dentry);
216 +                       assert(tmp->d_alias.prev == &inode->i_dentry);
217 +                       goal = tmp;
218 +                       dget_locked(goal);
219 +                       break;
220 +               }
221 +       }
222 +
223 +       if (!goal) { 
224 +               spin_unlock(&dcache_lock);
225 +               return NULL; 
226 +       }
227 +
228 +       /* Move the goal to the de hash queue - like d_move() */
229 +       goal->d_flags &= ~DCACHE_NFSD_DISCONNECTED;
230 +       list_del(&goal->d_hash);
231 +       list_add(&goal->d_hash, &de->d_hash);
232 +
233 +       list_del(&goal->d_child);
234 +       list_del(&de->d_child);
235 +
236 +       /* Switch the parents and the names.. */
237 +       switch_names(goal, de);
238 +       do_switch(goal->d_parent, de->d_parent);
239 +       do_switch(goal->d_name.len, de->d_name.len);
240 +       do_switch(goal->d_name.hash, de->d_name.hash);
241 +
242 +       /* And add them back to the (new) parent lists */
243 +       list_add(&goal->d_child, &goal->d_parent->d_subdirs);
244 +       list_add(&de->d_child, &de->d_parent->d_subdirs);
245 +       spin_unlock(&dcache_lock);
246 +
247 +       return goal;
248 +}
249 +
250 +/*
251 + * These are the special structures for the iopen pseudo directory.
252 + */
253 +
254 +static struct inode_operations iopen_inode_operations = {
255 +       lookup:         iopen_lookup,           /* BKL held */
256 +};
257 +
258 +static struct file_operations iopen_file_operations = {
259 +       read:           generic_read_dir,
260 +};
261 +
262 +static int match_dentry(struct dentry *dentry, const char *name)
263 +{
264 +       int     len;
265 +
266 +       len = strlen(name);
267 +       if (dentry->d_name.len != len)
268 +               return 0;
269 +       if (strncmp(dentry->d_name.name, name, len))
270 +               return 0;
271 +       return 1;
272 +}
273 +
274 +/*
275 + * This function is spliced into ext3_lookup and returns 1 the file
276 + * name is __iopen__ and dentry has been filled in appropriately.
277 + */
278 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
279 +{
280 +       struct inode *inode;
281 +
282 +       if (dir->i_ino != EXT3_ROOT_INO ||
283 +           !test_opt(dir->i_sb, IOPEN) ||
284 +           !match_dentry(dentry, "__iopen__"))
285 +               return 0;
286 +
287 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
288 +
289 +       if (!inode) 
290 +               return 0;
291 +       d_add(dentry, inode);
292 +       return 1;
293 +}
294 +
295 +/*
296 + * This function is spliced into read_inode; it returns 1 if inode
297 + * number is the one for /__iopen__, in which case the inode is filled
298 + * in appropriately.  Otherwise, this fuction returns 0.
299 + */
300 +int ext3_iopen_get_inode(struct inode *inode)
301 +{
302 +       if (inode->i_ino != EXT3_BAD_INO)
303 +               return 0;
304 +
305 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
306 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
307 +               inode->i_mode |= 0777;
308 +       inode->i_uid = 0;
309 +       inode->i_gid = 0;
310 +       inode->i_nlink = 1;
311 +       inode->i_size = 4096;
312 +       inode->i_atime = CURRENT_TIME;
313 +       inode->i_ctime = CURRENT_TIME;
314 +       inode->i_mtime = CURRENT_TIME;
315 +       inode->u.ext3_i.i_dtime = 0;
316 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
317 +                                        * (for stat), not the fs block
318 +                                        * size */  
319 +       inode->i_blocks = 0;
320 +       inode->i_version = 1;
321 +       inode->i_generation = 0;
322 +
323 +       inode->i_op = &iopen_inode_operations;
324 +       inode->i_fop = &iopen_file_operations;
325 +       inode->i_mapping->a_ops = 0;
326 +
327 +       return 1;
328 +}
329 --- /dev/null   Tue Jan 28 04:00:01 2003
330 +++ linux-mmonroe/fs/ext3/iopen.h       Thu Jul 10 12:28:54 2003
331 @@ -0,0 +1,13 @@
332 +/*
333 + * iopen.h
334 + *
335 + * Special support for opening files by inode number.
336 + * 
337 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
338 + * 
339 + * This file may be redistributed under the terms of the GNU General
340 + * Public License.
341 + */
342 +
343 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
344 +extern int ext3_iopen_get_inode(struct inode *inode);
345 --- linux/fs/ext3/namei.c~iopen-2.4.20  Thu Jul 10 12:28:46 2003
346 +++ linux-mmonroe/fs/ext3/namei.c       Thu Jul 10 12:28:54 2003
347 @@ -35,7 +35,7 @@
348  #include <linux/string.h>
349  #include <linux/locks.h>
350  #include <linux/quotaops.h>
351 -
352 +#include "iopen.h"
353  
354  /*
355   * define how far ahead to read directories while searching them.
356 @@ -921,16 +921,21 @@ errout:
357         return NULL;
358  }
359  #endif
360 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
361  
362  static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry)
363  {
364         struct inode * inode;
365         struct ext3_dir_entry_2 * de;
366         struct buffer_head * bh;
367 +       struct dentry *alternate = NULL;
368  
369         if (dentry->d_name.len > EXT3_NAME_LEN)
370                 return ERR_PTR(-ENAMETOOLONG);
371  
372 +       if (ext3_check_for_iopen(dir, dentry))
373 +               return NULL;
374 +
375         bh = ext3_find_entry(dentry, &de);
376         inode = NULL;
377         if (bh) {
378 @@ -942,6 +947,12 @@ static struct dentry *ext3_lookup(struct
379                         return ERR_PTR(-EACCES);
380                 }
381         }
382 +
383 +       if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
384 +               iput(inode);
385 +               return alternate;
386 +       }
387 +
388         d_add(dentry, inode);
389         return NULL;
390  }
391 --- linux/fs/ext3/super.c~iopen-2.4.20  Thu Jul 10 12:28:45 2003
392 +++ linux-mmonroe/fs/ext3/super.c       Thu Jul 10 12:28:54 2003
393 @@ -835,6 +835,17 @@ static int parse_options (char * options
394                          || !strcmp (this_char, "quota")
395                          || !strcmp (this_char, "usrquota"))
396                         /* Don't do anything ;-) */ ;
397 +               else if (!strcmp (this_char, "iopen")) {
398 +                       set_opt (sbi->s_mount_opt, IOPEN);
399 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
400 +               } else if (!strcmp (this_char, "noiopen")) {
401 +                       clear_opt (sbi->s_mount_opt, IOPEN);
402 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
403 +               }
404 +               else if (!strcmp (this_char, "iopen_nopriv")) {
405 +                       set_opt (sbi->s_mount_opt, IOPEN);
406 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
407 +               }
408                 else if (!strcmp (this_char, "journal")) {
409                         /* @@@ FIXME */
410                         /* Eventually we will want to be able to create
411 --- linux/include/linux/ext3_fs.h~iopen-2.4.20  Thu Jul 10 12:28:46 2003
412 +++ linux-mmonroe/include/linux/ext3_fs.h       Thu Jul 10 12:30:12 2003
413 @@ -322,6 +322,8 @@ struct ext3_inode {
414  #define EXT3_MOUNT_UPDATE_JOURNAL      0x1000  /* Update the journal format */
415  #define EXT3_MOUNT_NO_UID32            0x2000  /* Disable 32-bit UIDs */
416  #define EXT3_MOUNT_XATTR_USER          0x4000  /* Extended user attributes */
417 +#define EXT3_MOUNT_IOPEN               0x8000  /* Allow access via iopen */
418 +#define EXT3_MOUNT_IOPEN_NOPRIV                0x10000 /* Make iopen world-readable */
419  #define EXT3_MOUNT_ASYNCDEL            0x20000 /* Delayed deletion */
420  
421  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
422
423 _