Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / kernel_patches / patches / iopen-2.5.73.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.5.73   2003-07-13 21:31:56.000000000 -0600
12 +++ linux-2.6.0-test1-braam/Documentation/filesystems/ext2.txt  2003-07-22 01:15:46.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.6.0-test1/fs/ext3/Makefile~iopen-2.5.73     2003-07-13 21:30:37.000000000 -0600
37 +++ linux-2.6.0-test1-braam/fs/ext3/Makefile    2003-07-22 01:15:46.000000000 -0600
38 @@ -5,7 +5,7 @@
39  obj-$(CONFIG_EXT3_FS) += ext3.o
40  
41  ext3-objs    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
42 -               ioctl.o namei.o super.o symlink.o hash.o
43 +               iopen.o ioctl.o namei.o super.o symlink.o hash.o
44  
45  ifeq ($(CONFIG_EXT3_FS_XATTR),y)
46  ext3-objs += xattr.o xattr_user.o xattr_trusted.o
47 --- linux-2.6.0-test1/fs/ext3/inode.c~iopen-2.5.73      2003-07-22 01:15:25.000000000 -0600
48 +++ linux-2.6.0-test1-braam/fs/ext3/inode.c     2003-07-22 01:16:19.000000000 -0600
49 @@ -37,6 +37,7 @@
50  #include <linux/mpage.h>
51  #include <linux/uio.h>
52  #include "xattr.h"
53 +#include "iopen.h"
54  #include "acl.h"
55  
56  /*
57 @@ -2478,6 +2479,8 @@ void ext3_read_inode(struct inode * inod
58         ei->i_acl = EXT3_ACL_NOT_CACHED;
59         ei->i_default_acl = EXT3_ACL_NOT_CACHED;
60  #endif
61 +       if (ext3_iopen_get_inode(inode))
62 +               return;
63         if (ext3_get_inode_loc(inode, &iloc, 0))
64                 goto bad_inode;
65         bh = iloc.bh;
66 --- /dev/null   2003-01-30 03:24:37.000000000 -0700
67 +++ linux-2.6.0-test1-braam/fs/ext3/iopen.c     2003-07-22 01:15:46.000000000 -0600
68 @@ -0,0 +1,239 @@
69 +
70 +
71 +/*
72 + * linux/fs/ext3/iopen.c
73 + *
74 + * Special support for open by inode number
75 + *
76 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
77 + * 
78 + * This file may be redistributed under the terms of the GNU General
79 + * Public License.
80 + */
81 +
82 +#include <linux/sched.h>
83 +#include <linux/fs.h>
84 +#include <linux/ext3_jbd.h>
85 +#include <linux/jbd.h>
86 +#include <linux/ext3_fs.h>
87 +#include <linux/smp_lock.h>
88 +#include "iopen.h"
89 +
90 +#ifndef assert
91 +#define assert(test) J_ASSERT(test)
92 +#endif
93 +
94 +#define IOPEN_NAME_LEN 32
95 +
96 +/*
97 + * This implements looking up an inode by number.
98 + */
99 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry)
100 +{
101 +       struct inode * inode;
102 +       unsigned long ino;
103 +        struct list_head *lp;
104 +        struct dentry *alternate;
105 +       char buf[IOPEN_NAME_LEN];
106 +       
107 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
108 +               return ERR_PTR(-ENAMETOOLONG);
109 +
110 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
111 +       buf[dentry->d_name.len] = 0;
112 +
113 +       if (strcmp(buf, ".") == 0)
114 +               ino = dir->i_ino;
115 +       else if (strcmp(buf, "..") == 0)
116 +               ino = EXT3_ROOT_INO;
117 +       else
118 +               ino = simple_strtoul(buf, 0, 0);
119 +
120 +       if ((ino != EXT3_ROOT_INO &&
121 +            //ino != EXT3_ACL_IDX_INO &&
122 +            //ino != EXT3_ACL_DATA_INO &&
123 +            ino < EXT3_FIRST_INO(dir->i_sb)) ||
124 +           ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
125 +               return ERR_PTR(-ENOENT);
126 +
127 +       inode = iget(dir->i_sb, ino);
128 +       if (!inode)
129 +               return ERR_PTR(-EACCES);
130 +       if (is_bad_inode(inode)) {
131 +               iput(inode);
132 +               return ERR_PTR(-ENOENT);
133 +       }
134 +
135 +        /* preferrably return a connected dentry */
136 +        spin_lock(&dcache_lock);
137 +        list_for_each(lp, &inode->i_dentry) {
138 +                alternate = list_entry(lp, struct dentry, d_alias);
139 +                assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
140 +        }
141 +
142 +        if (!list_empty(&inode->i_dentry)) {
143 +                alternate = list_entry(inode->i_dentry.next, 
144 +                                       struct dentry, d_alias);
145 +                dget_locked(alternate);
146 +                alternate->d_vfs_flags |= DCACHE_REFERENCED;
147 +                iput(inode);
148 +                spin_unlock(&dcache_lock);
149 +                return alternate;
150 +        }
151 +        dentry->d_flags |= DCACHE_DISCONNECTED;
152 +        spin_unlock(&dcache_lock);
153 +
154 +       d_add(dentry, inode);
155 +       return NULL;
156 +}
157 +
158 +#define do_switch(x,y) do { \
159 +       __typeof__ (x) __tmp = x; \
160 +       x = y; y = __tmp; } while (0)
161 +
162 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
163 +{
164 +       const unsigned char *old_name, *new_name;
165 +
166 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN); 
167 +       old_name = target->d_name.name;
168 +       new_name = dentry->d_name.name;
169 +       if (old_name == target->d_iname)
170 +               old_name = dentry->d_iname;
171 +       if (new_name == dentry->d_iname)
172 +               new_name = target->d_iname;
173 +       target->d_name.name = new_name;
174 +       dentry->d_name.name = old_name;
175 +}
176 +
177 +
178 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
179 +{
180 +        struct dentry *tmp, *goal = NULL;
181 +        struct list_head *lp;
182 +
183 +        /* preferrably return a connected dentry */
184 +        spin_lock(&dcache_lock);
185 +        /* verify this dentry is really new */
186 +        assert(!de->d_inode);
187 +        assert(list_empty(&de->d_subdirs));
188 +        assert(list_empty(&de->d_alias));
189 +
190 +
191 +        list_for_each(lp, &inode->i_dentry) {
192 +                tmp = list_entry(lp, struct dentry, d_alias);
193 +                if (tmp->d_flags & DCACHE_DISCONNECTED) {
194 +                        assert(tmp->d_alias.next == &inode->i_dentry);
195 +                        assert(tmp->d_alias.prev == &inode->i_dentry);
196 +                        goal = tmp;
197 +                        dget_locked(goal);
198 +                        break;
199 +                }
200 +        }
201 +
202 +        if (!goal) { 
203 +                spin_unlock(&dcache_lock);
204 +                return NULL; 
205 +        }
206 +
207 +        /* Move the goal to the de hash queue */
208 +        goal->d_flags &= ~DCACHE_DISCONNECTED;
209 +       hlist_add_before(&goal->d_hash, &de->d_hash);
210 +       hlist_del(&goal->d_hash);
211 +
212 +       list_del(&goal->d_child);
213 +       list_del(&de->d_child);
214 +
215 +       /* Switch the parents and the names.. */
216 +       switch_names(goal, de);
217 +       do_switch(goal->d_parent, de->d_parent);
218 +       do_switch(goal->d_name.len, de->d_name.len);
219 +       do_switch(goal->d_name.hash, de->d_name.hash);
220 +
221 +       /* And add them back to the (new) parent lists */
222 +       list_add(&goal->d_child, &goal->d_parent->d_subdirs);
223 +       list_add(&de->d_child, &de->d_parent->d_subdirs);
224 +
225 +        spin_unlock(&dcache_lock);
226 +        return goal;
227 +}
228 +
229 +/*
230 + * These are the special structures for the iopen pseudo directory.
231 + */
232 +
233 +static struct inode_operations iopen_inode_operations = {
234 +       lookup:         iopen_lookup,           /* BKL held */
235 +};
236 +
237 +static struct file_operations iopen_file_operations = {
238 +       read:           generic_read_dir,
239 +};
240 +
241 +static int match_dentry(struct dentry *dentry, const char *name)
242 +{
243 +       int     len;
244 +
245 +       len = strlen(name);
246 +       if (dentry->d_name.len != len)
247 +               return 0;
248 +       if (strncmp(dentry->d_name.name, name, len))
249 +               return 0;
250 +       return 1;
251 +}
252 +
253 +/*
254 + * This function is spliced into ext3_lookup and returns 1 the file
255 + * name is __iopen__ and dentry has been filled in appropriately.
256 + */
257 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
258 +{
259 +       struct inode * inode;
260 +
261 +       if (dir->i_ino != EXT3_ROOT_INO ||
262 +           !test_opt(dir->i_sb, IOPEN) ||
263 +           !match_dentry(dentry, "__iopen__"))
264 +               return 0;
265 +
266 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
267 +
268 +       if (!inode) 
269 +               return 0;
270 +       d_add(dentry, inode);
271 +       return 1;
272 +}
273 +
274 +/*
275 + * This function is spliced into read_inode; it returns 1 if inode
276 + * number is the one for /__iopen__, in which case the inode is filled
277 + * in appropriately.  Otherwise, this fuction returns 0.
278 + */
279 +int ext3_iopen_get_inode(struct inode * inode)
280 +{
281 +       if (inode->i_ino != EXT3_BAD_INO)
282 +               return 0;
283 +
284 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
285 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
286 +               inode->i_mode |= 0777;
287 +       inode->i_uid = 0;
288 +       inode->i_gid = 0;
289 +       inode->i_nlink = 1;
290 +       inode->i_size = 4096;
291 +       inode->i_atime = CURRENT_TIME;
292 +       inode->i_ctime = CURRENT_TIME;
293 +       inode->i_mtime = CURRENT_TIME;
294 +       EXT3_I(inode)->i_dtime = 0;
295 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
296 +                                        * (for stat), not the fs block
297 +                                        * size */  
298 +       inode->i_blocks = 0;
299 +       inode->i_version = 1;
300 +       inode->i_generation = 0;
301 +
302 +       inode->i_op = &iopen_inode_operations;
303 +       inode->i_fop = &iopen_file_operations;
304 +       inode->i_mapping->a_ops = 0;
305 +
306 +       return 1;
307 +}
308 --- /dev/null   2003-01-30 03:24:37.000000000 -0700
309 +++ linux-2.6.0-test1-braam/fs/ext3/iopen.h     2003-07-22 01:15:46.000000000 -0600
310 @@ -0,0 +1,15 @@
311 +/*
312 + * iopen.h
313 + *
314 + * Special support for opening files by inode number.
315 + * 
316 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
317 + * 
318 + * This file may be redistributed under the terms of the GNU General
319 + * Public License.
320 + */
321 +
322 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
323 +extern int ext3_iopen_get_inode(struct inode * inode);
324 +
325 +
326 --- linux-2.6.0-test1/fs/ext3/namei.c~iopen-2.5.73      2003-07-13 21:34:43.000000000 -0600
327 +++ linux-2.6.0-test1-braam/fs/ext3/namei.c     2003-07-22 01:17:20.000000000 -0600
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.5.73      2003-07-22 01:15:25.000000000 -0600
372 +++ linux-2.6.0-test1-braam/fs/ext3/super.c     2003-07-22 01:15:46.000000000 -0600
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.5.73      2003-07-22 01:14:05.000000000 -0600
392 +++ linux-2.6.0-test1-braam/include/linux/ext3_fs.h     2003-07-22 01:15:46.000000000 -0600
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 _