Whamcloud - gitweb
- put the exit(1)s back in after MPI_Abort() in the hopes that MPI
[fs/lustre-release.git] / lustre / kernel_patches / patches / iopen-2.6.0.patch
1  Documentation/filesystems/ext2.txt |   16 ++
2  fs/ext3/Makefile                   |    2 
3  fs/ext3/inode.c                    |    3 
4  fs/ext3/iopen.c                    |  239 +++++++++++++++++++++++++++++++++++++
5  fs/ext3/iopen.h                    |   15 ++
6  fs/ext3/namei.c                    |   13 ++
7  fs/ext3/super.c                    |   11 +
8  include/linux/ext3_fs.h            |    2 
9  8 files changed, 300 insertions(+), 1 deletion(-)
10
11 --- linux-2.6.0-test1/Documentation/filesystems/ext2.txt~iopen-2.6.0    2002-11-11 06:28:06.000000000 +0300
12 +++ linux-2.6.0-test1-alexey/Documentation/filesystems/ext2.txt 2003-08-24 13:02:02.000000000 +0400
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.6.0-test1/fs/ext3/inode.c~iopen-2.6.0       2003-08-24 13:00:36.000000000 +0400
37 +++ linux-2.6.0-test1-alexey/fs/ext3/inode.c    2003-08-24 13:02:02.000000000 +0400
38 @@ -37,6 +37,7 @@
39  #include <linux/mpage.h>
40  #include <linux/uio.h>
41  #include "xattr.h"
42 +#include "iopen.h"
43  #include "acl.h"
44  
45  /*
46 @@ -2477,6 +2478,8 @@ void ext3_read_inode(struct inode * inod
47         ei->i_acl = EXT3_ACL_NOT_CACHED;
48         ei->i_default_acl = EXT3_ACL_NOT_CACHED;
49  #endif
50 +       if (ext3_iopen_get_inode(inode))
51 +               return;
52         if (ext3_get_inode_loc(inode, &iloc, 0))
53                 goto bad_inode;
54         bh = iloc.bh;
55 --- /dev/null   2003-01-30 13:24:37.000000000 +0300
56 +++ linux-2.6.0-test1-alexey/fs/ext3/iopen.c    2003-08-24 13:02:02.000000000 +0400
57 @@ -0,0 +1,239 @@
58 +
59 +
60 +/*
61 + * linux/fs/ext3/iopen.c
62 + *
63 + * Special support for open by inode number
64 + *
65 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
66 + * 
67 + * This file may be redistributed under the terms of the GNU General
68 + * Public License.
69 + */
70 +
71 +#include <linux/sched.h>
72 +#include <linux/fs.h>
73 +#include <linux/ext3_jbd.h>
74 +#include <linux/jbd.h>
75 +#include <linux/ext3_fs.h>
76 +#include <linux/smp_lock.h>
77 +#include "iopen.h"
78 +
79 +#ifndef assert
80 +#define assert(test) J_ASSERT(test)
81 +#endif
82 +
83 +#define IOPEN_NAME_LEN 32
84 +
85 +/*
86 + * This implements looking up an inode by number.
87 + */
88 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
89 +{
90 +       struct inode * inode;
91 +       unsigned long ino;
92 +        struct list_head *lp;
93 +        struct dentry *alternate;
94 +       char buf[IOPEN_NAME_LEN];
95 +       
96 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
97 +               return ERR_PTR(-ENAMETOOLONG);
98 +
99 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
100 +       buf[dentry->d_name.len] = 0;
101 +
102 +       if (strcmp(buf, ".") == 0)
103 +               ino = dir->i_ino;
104 +       else if (strcmp(buf, "..") == 0)
105 +               ino = EXT3_ROOT_INO;
106 +       else
107 +               ino = simple_strtoul(buf, 0, 0);
108 +
109 +       if ((ino != EXT3_ROOT_INO &&
110 +            //ino != EXT3_ACL_IDX_INO &&
111 +            //ino != EXT3_ACL_DATA_INO &&
112 +            ino < EXT3_FIRST_INO(dir->i_sb)) ||
113 +           ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
114 +               return ERR_PTR(-ENOENT);
115 +
116 +       inode = iget(dir->i_sb, ino);
117 +       if (!inode)
118 +               return ERR_PTR(-EACCES);
119 +       if (is_bad_inode(inode)) {
120 +               iput(inode);
121 +               return ERR_PTR(-ENOENT);
122 +       }
123 +
124 +        /* preferrably return a connected dentry */
125 +        spin_lock(&dcache_lock);
126 +        list_for_each(lp, &inode->i_dentry) {
127 +                alternate = list_entry(lp, struct dentry, d_alias);
128 +                assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
129 +        }
130 +
131 +        if (!list_empty(&inode->i_dentry)) {
132 +                alternate = list_entry(inode->i_dentry.next, 
133 +                                       struct dentry, d_alias);
134 +                dget_locked(alternate);
135 +                alternate->d_vfs_flags |= DCACHE_REFERENCED;
136 +                iput(inode);
137 +                spin_unlock(&dcache_lock);
138 +                return alternate;
139 +        }
140 +        dentry->d_flags |= DCACHE_DISCONNECTED;
141 +        spin_unlock(&dcache_lock);
142 +
143 +       d_add(dentry, inode);
144 +       return NULL;
145 +}
146 +
147 +#define do_switch(x,y) do { \
148 +       __typeof__ (x) __tmp = x; \
149 +       x = y; y = __tmp; } while (0)
150 +
151 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
152 +{
153 +       const unsigned char *old_name, *new_name;
154 +
155 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN); 
156 +       old_name = target->d_name.name;
157 +       new_name = dentry->d_name.name;
158 +       if (old_name == target->d_iname)
159 +               old_name = dentry->d_iname;
160 +       if (new_name == dentry->d_iname)
161 +               new_name = target->d_iname;
162 +       target->d_name.name = new_name;
163 +       dentry->d_name.name = old_name;
164 +}
165 +
166 +
167 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
168 +{
169 +        struct dentry *tmp, *goal = NULL;
170 +        struct list_head *lp;
171 +
172 +        /* preferrably return a connected dentry */
173 +        spin_lock(&dcache_lock);
174 +        /* verify this dentry is really new */
175 +        assert(!de->d_inode);
176 +        assert(list_empty(&de->d_subdirs));
177 +        assert(list_empty(&de->d_alias));
178 +
179 +
180 +        list_for_each(lp, &inode->i_dentry) {
181 +                tmp = list_entry(lp, struct dentry, d_alias);
182 +                if (tmp->d_flags & DCACHE_DISCONNECTED) {
183 +                        assert(tmp->d_alias.next == &inode->i_dentry);
184 +                        assert(tmp->d_alias.prev == &inode->i_dentry);
185 +                        goal = tmp;
186 +                        dget_locked(goal);
187 +                        break;
188 +                }
189 +        }
190 +
191 +        if (!goal) { 
192 +                spin_unlock(&dcache_lock);
193 +                return NULL; 
194 +        }
195 +
196 +        /* Move the goal to the de hash queue */
197 +        goal->d_flags &= ~DCACHE_DISCONNECTED;
198 +       hlist_add_before(&goal->d_hash, &de->d_hash);
199 +       hlist_del(&goal->d_hash);
200 +
201 +       list_del(&goal->d_child);
202 +       list_del(&de->d_child);
203 +
204 +       /* Switch the parents and the names.. */
205 +       switch_names(goal, de);
206 +       do_switch(goal->d_parent, de->d_parent);
207 +       do_switch(goal->d_name.len, de->d_name.len);
208 +       do_switch(goal->d_name.hash, de->d_name.hash);
209 +
210 +       /* And add them back to the (new) parent lists */
211 +       list_add(&goal->d_child, &goal->d_parent->d_subdirs);
212 +       list_add(&de->d_child, &de->d_parent->d_subdirs);
213 +
214 +        spin_unlock(&dcache_lock);
215 +        return goal;
216 +}
217 +
218 +/*
219 + * These are the special structures for the iopen pseudo directory.
220 + */
221 +
222 +static struct inode_operations iopen_inode_operations = {
223 +       lookup:         iopen_lookup,           /* BKL held */
224 +};
225 +
226 +static struct file_operations iopen_file_operations = {
227 +       read:           generic_read_dir,
228 +};
229 +
230 +static int match_dentry(struct dentry *dentry, const char *name)
231 +{
232 +       int     len;
233 +
234 +       len = strlen(name);
235 +       if (dentry->d_name.len != len)
236 +               return 0;
237 +       if (strncmp(dentry->d_name.name, name, len))
238 +               return 0;
239 +       return 1;
240 +}
241 +
242 +/*
243 + * This function is spliced into ext3_lookup and returns 1 the file
244 + * name is __iopen__ and dentry has been filled in appropriately.
245 + */
246 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
247 +{
248 +       struct inode * inode;
249 +
250 +       if (dir->i_ino != EXT3_ROOT_INO ||
251 +           !test_opt(dir->i_sb, IOPEN) ||
252 +           !match_dentry(dentry, "__iopen__"))
253 +               return 0;
254 +
255 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
256 +
257 +       if (!inode) 
258 +               return 0;
259 +       d_add(dentry, inode);
260 +       return 1;
261 +}
262 +
263 +/*
264 + * This function is spliced into read_inode; it returns 1 if inode
265 + * number is the one for /__iopen__, in which case the inode is filled
266 + * in appropriately.  Otherwise, this fuction returns 0.
267 + */
268 +int ext3_iopen_get_inode(struct inode * inode)
269 +{
270 +       if (inode->i_ino != EXT3_BAD_INO)
271 +               return 0;
272 +
273 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
274 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
275 +               inode->i_mode |= 0777;
276 +       inode->i_uid = 0;
277 +       inode->i_gid = 0;
278 +       inode->i_nlink = 1;
279 +       inode->i_size = 4096;
280 +       inode->i_atime = CURRENT_TIME;
281 +       inode->i_ctime = CURRENT_TIME;
282 +       inode->i_mtime = CURRENT_TIME;
283 +       EXT3_I(inode)->i_dtime = 0;
284 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
285 +                                        * (for stat), not the fs block
286 +                                        * size */  
287 +       inode->i_blocks = 0;
288 +       inode->i_version = 1;
289 +       inode->i_generation = 0;
290 +
291 +       inode->i_op = &iopen_inode_operations;
292 +       inode->i_fop = &iopen_file_operations;
293 +       inode->i_mapping->a_ops = 0;
294 +
295 +       return 1;
296 +}
297 --- /dev/null   2003-01-30 13:24:37.000000000 +0300
298 +++ linux-2.6.0-test1-alexey/fs/ext3/iopen.h    2003-08-24 13:02:02.000000000 +0400
299 @@ -0,0 +1,15 @@
300 +/*
301 + * iopen.h
302 + *
303 + * Special support for opening files by inode number.
304 + * 
305 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
306 + * 
307 + * This file may be redistributed under the terms of the GNU General
308 + * Public License.
309 + */
310 +
311 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
312 +extern int ext3_iopen_get_inode(struct inode * inode);
313 +
314 +
315 --- linux-2.6.0-test1/fs/ext3/Makefile~iopen-2.6.0      2003-08-24 12:58:32.000000000 +0400
316 +++ linux-2.6.0-test1-alexey/fs/ext3/Makefile   2003-08-24 13:02:40.000000000 +0400
317 @@ -5,7 +5,7 @@
318  obj-$(CONFIG_EXT3_FS) += ext3.o
319  
320  ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
321 -          ioctl.o namei.o super.o symlink.o hash.o
322 +          iopen.o ioctl.o namei.o super.o symlink.o hash.o
323  
324  ext3-$(CONFIG_EXT3_FS_XATTR)    += xattr.o xattr_user.o xattr_trusted.o
325  ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
326 --- linux-2.6.0-test1/fs/ext3/namei.c~iopen-2.6.0       2003-07-24 15:52:30.000000000 +0400
327 +++ linux-2.6.0-test1-alexey/fs/ext3/namei.c    2003-08-24 13:02:02.000000000 +0400
328 @@ -37,6 +37,7 @@
329  #include <linux/buffer_head.h>
330  #include <linux/smp_lock.h>
331  #include "xattr.h"
332 +#include "iopen.h"
333  #include "acl.h"
334  
335  /*
336 @@ -970,15 +971,21 @@ errout:
337  }
338  #endif
339  
340 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
341
342  static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
343  {
344         struct inode * inode;
345         struct ext3_dir_entry_2 * de;
346         struct buffer_head * bh;
347 +       struct dentry *alternate = NULL;
348  
349         if (dentry->d_name.len > EXT3_NAME_LEN)
350                 return ERR_PTR(-ENAMETOOLONG);
351  
352 +       if (ext3_check_for_iopen(dir, dentry))
353 +               return NULL;
354 +
355         bh = ext3_find_entry(dentry, &de);
356         inode = NULL;
357         if (bh) {
358 @@ -991,6 +998,12 @@ static struct dentry *ext3_lookup(struct
359         }
360         if (inode)
361                 return d_splice_alias(inode, dentry);
362 +
363 +       if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
364 +               iput(inode);
365 +               return alternate;
366 +       }
367 +
368         d_add(dentry, inode);
369         return NULL;
370  }
371 --- linux-2.6.0-test1/fs/ext3/super.c~iopen-2.6.0       2003-08-24 13:00:36.000000000 +0400
372 +++ linux-2.6.0-test1-alexey/fs/ext3/super.c    2003-08-24 13:02:02.000000000 +0400
373 @@ -755,6 +755,17 @@ static int parse_options (char * options
374                          || !strcmp (this_char, "quota")
375                          || !strcmp (this_char, "usrquota"))
376                         /* Don't do anything ;-) */ ;
377 +               else if (!strcmp (this_char, "iopen")) {
378 +                       set_opt (sbi->s_mount_opt, IOPEN);
379 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
380 +               } else if (!strcmp (this_char, "noiopen")) {
381 +                       clear_opt (sbi->s_mount_opt, IOPEN);
382 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
383 +               }
384 +               else if (!strcmp (this_char, "iopen_nopriv")) {
385 +                       set_opt (sbi->s_mount_opt, IOPEN);
386 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
387 +               }
388                 else if (!strcmp (this_char, "journal")) {
389                         /* @@@ FIXME */
390                         /* Eventually we will want to be able to create
391 --- linux-2.6.0-test1/include/linux/ext3_fs.h~iopen-2.6.0       2003-08-24 12:58:57.000000000 +0400
392 +++ linux-2.6.0-test1-alexey/include/linux/ext3_fs.h    2003-08-24 13:02:02.000000000 +0400
393 @@ -324,6 +324,8 @@ struct ext3_inode {
394  #define EXT3_MOUNT_NO_UID32            0x2000  /* Disable 32-bit UIDs */
395  #define EXT3_MOUNT_XATTR_USER          0x4000  /* Extended user attributes */
396  #define EXT3_MOUNT_POSIX_ACL           0x8000  /* POSIX Access Control Lists */
397 +#define EXT3_MOUNT_IOPEN              0x10000  /* Allow access via iopen */
398 +#define EXT3_MOUNT_IOPEN_NOPRIV               0x20000  /* Make iopen world-readable */
399  
400  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
401  #ifndef _LINUX_EXT2_FS_H
402
403 _