Whamcloud - gitweb
land b_v26 (20040316_1603)
[fs/lustre-release.git] / lustre / kernel_patches / patches / iopen-2.6.3-mm4.patch
1  Documentation/filesystems/ext2.txt |   16 ++
2  fs/ext3/inode.c                    |    3 
3  fs/ext3/iopen.c                    |  239 +++++++++++++++++++++++++++++++++++++
4  fs/ext3/iopen.h                    |   15 ++
5  fs/ext3/namei.c                    |   13 ++
6  fs/ext3/super.c                    |   17 ++
7  include/linux/ext3_fs.h            |    2 
8  7 files changed, 304 insertions(+), 1 deletion(-)
9
10 Index: linux-2.6.3-mm4/Documentation/filesystems/ext2.txt
11 ===================================================================
12 --- linux-2.6.3-mm4.orig/Documentation/filesystems/ext2.txt     2004-01-09 14:59:18.000000000 +0800
13 +++ linux-2.6.3-mm4/Documentation/filesystems/ext2.txt  2004-03-08 14:58:44.431196112 +0800
14 @@ -35,6 +35,22 @@
15  
16  sb=n                           Use alternate superblock at this location.
17  
18 +iopen                          Makes an invisible pseudo-directory called 
19 +                               __iopen__ available in the root directory
20 +                               of the filesystem.  Allows open-by-inode-
21 +                               number.  i.e., inode 3145 can be accessed
22 +                               via /mntpt/__iopen__/3145
23 +
24 +iopen_nopriv                   This option makes the iopen directory be
25 +                               world-readable.  This may be safer since it
26 +                               allows daemons to run as an unprivileged user,
27 +                               however it significantly changes the security
28 +                               model of a Unix filesystem, since previously
29 +                               all files under a mode 700 directory were not
30 +                               generally avilable even if the
31 +                               permissions on the file itself is
32 +                               world-readable.
33 +
34  grpquota,noquota,quota,usrquota        Quota options are silently ignored by ext2.
35  
36  
37 Index: linux-2.6.3-mm4/fs/ext3/inode.c
38 ===================================================================
39 --- linux-2.6.3-mm4.orig/fs/ext3/inode.c        2004-03-08 14:57:54.969715400 +0800
40 +++ linux-2.6.3-mm4/fs/ext3/inode.c     2004-03-08 14:58:44.504185016 +0800
41 @@ -37,6 +37,7 @@
42  #include <linux/mpage.h>
43  #include <linux/uio.h>
44  #include "xattr.h"
45 +#include "iopen.h"
46  #include "acl.h"
47  
48  /*
49 @@ -2472,6 +2473,8 @@
50         ei->i_acl = EXT3_ACL_NOT_CACHED;
51         ei->i_default_acl = EXT3_ACL_NOT_CACHED;
52  #endif
53 +       if (ext3_iopen_get_inode(inode))
54 +               return;
55         if (ext3_get_inode_loc(inode, &iloc, 0))
56                 goto bad_inode;
57         bh = iloc.bh;
58 Index: linux-2.6.3-mm4/fs/ext3/iopen.c
59 ===================================================================
60 --- linux-2.6.3-mm4.orig/fs/ext3/iopen.c        2004-03-08 14:58:44.413198848 +0800
61 +++ linux-2.6.3-mm4/fs/ext3/iopen.c     2004-03-08 14:58:44.576174072 +0800
62 @@ -0,0 +1,223 @@
63 +
64 +
65 +/*
66 + * linux/fs/ext3/iopen.c
67 + *
68 + * Special support for open by inode number
69 + *
70 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
71 + * 
72 + * This file may be redistributed under the terms of the GNU General
73 + * Public License.
74 + */
75 +
76 +#include <linux/sched.h>
77 +#include <linux/fs.h>
78 +#include <linux/ext3_jbd.h>
79 +#include <linux/jbd.h>
80 +#include <linux/ext3_fs.h>
81 +#include <linux/smp_lock.h>
82 +#include "iopen.h"
83 +
84 +#ifndef assert
85 +#define assert(test) J_ASSERT(test)
86 +#endif
87 +
88 +#define IOPEN_NAME_LEN 32
89 +
90 +/*
91 + * This implements looking up an inode by number.
92 + */
93 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
94 +{
95 +       struct inode * inode;
96 +       unsigned long ino;
97 +        struct list_head *lp;
98 +        struct dentry *alternate;
99 +       char buf[IOPEN_NAME_LEN];
100 +       
101 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
102 +               return ERR_PTR(-ENAMETOOLONG);
103 +
104 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
105 +       buf[dentry->d_name.len] = 0;
106 +
107 +       if (strcmp(buf, ".") == 0)
108 +               ino = dir->i_ino;
109 +       else if (strcmp(buf, "..") == 0)
110 +               ino = EXT3_ROOT_INO;
111 +       else
112 +               ino = simple_strtoul(buf, 0, 0);
113 +
114 +       if ((ino != EXT3_ROOT_INO &&
115 +            //ino != EXT3_ACL_IDX_INO &&
116 +            //ino != EXT3_ACL_DATA_INO &&
117 +            ino < EXT3_FIRST_INO(dir->i_sb)) ||
118 +           ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
119 +               return ERR_PTR(-ENOENT);
120 +
121 +       inode = iget(dir->i_sb, ino);
122 +       if (!inode)
123 +               return ERR_PTR(-EACCES);
124 +       if (is_bad_inode(inode)) {
125 +               iput(inode);
126 +               return ERR_PTR(-ENOENT);
127 +       }
128 +
129 +        /* preferrably return a connected dentry */
130 +        spin_lock(&dcache_lock);
131 +        list_for_each(lp, &inode->i_dentry) {
132 +                alternate = list_entry(lp, struct dentry, d_alias);
133 +                assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
134 +        }
135 +
136 +        if (!list_empty(&inode->i_dentry)) {
137 +                alternate = list_entry(inode->i_dentry.next, 
138 +                                       struct dentry, d_alias);
139 +                dget_locked(alternate);
140 +                alternate->d_vfs_flags |= DCACHE_REFERENCED;
141 +                iput(inode);
142 +                spin_unlock(&dcache_lock);
143 +                return alternate;
144 +        }
145 +        dentry->d_flags |= DCACHE_DISCONNECTED;
146 +        spin_unlock(&dcache_lock);
147 +
148 +       d_add(dentry, inode);
149 +       return NULL;
150 +}
151 +
152 +#define do_switch(x,y) do { \
153 +       __typeof__ (x) __tmp = x; \
154 +       x = y; y = __tmp; } while (0)
155 +
156 +static inline void switch_names(struct dentry * dentry, struct dentry * target)
157 +{
158 +       const unsigned char *old_name, *new_name;
159 +
160 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN); 
161 +       old_name = target->d_name.name;
162 +       new_name = dentry->d_name.name;
163 +       if (old_name == target->d_iname)
164 +               old_name = dentry->d_iname;
165 +       if (new_name == dentry->d_iname)
166 +               new_name = target->d_iname;
167 +       target->d_name.name = new_name;
168 +       dentry->d_name.name = old_name;
169 +}
170 +
171 +
172 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
173 +{
174 +        struct dentry *tmp, *goal = NULL;
175 +        struct list_head *lp;
176 +
177 +        /* preferrably return a connected dentry */
178 +        spin_lock(&dcache_lock);
179 +        /* verify this dentry is really new */
180 +        assert(!de->d_inode);
181 +        assert(list_empty(&de->d_subdirs));
182 +        assert(list_empty(&de->d_alias));
183 +
184 +
185 +        list_for_each(lp, &inode->i_dentry) {
186 +                tmp = list_entry(lp, struct dentry, d_alias);
187 +                if (tmp->d_flags & DCACHE_DISCONNECTED) {
188 +                        assert(tmp->d_alias.next == &inode->i_dentry);
189 +                        assert(tmp->d_alias.prev == &inode->i_dentry);
190 +                        goal = tmp;
191 +                        dget_locked(goal);
192 +                        break;
193 +                }
194 +        }
195 +        spin_unlock(&dcache_lock);
196 +
197 +        if (!goal)
198 +                return NULL; 
199 +
200 +        goal->d_flags &= ~DCACHE_DISCONNECTED;
201 +       d_rehash(de);
202 +       d_move(goal, de);
203 +
204 +        return goal;
205 +}
206 +
207 +/*
208 + * These are the special structures for the iopen pseudo directory.
209 + */
210 +
211 +static struct inode_operations iopen_inode_operations = {
212 +       lookup:         iopen_lookup,           /* BKL held */
213 +};
214 +
215 +static struct file_operations iopen_file_operations = {
216 +       read:           generic_read_dir,
217 +};
218 +
219 +static int match_dentry(struct dentry *dentry, const char *name)
220 +{
221 +       int     len;
222 +
223 +       len = strlen(name);
224 +       if (dentry->d_name.len != len)
225 +               return 0;
226 +       if (strncmp(dentry->d_name.name, name, len))
227 +               return 0;
228 +       return 1;
229 +}
230 +
231 +/*
232 + * This function is spliced into ext3_lookup and returns 1 the file
233 + * name is __iopen__ and dentry has been filled in appropriately.
234 + */
235 +int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry)
236 +{
237 +       struct inode * inode;
238 +
239 +       if (dir->i_ino != EXT3_ROOT_INO ||
240 +           !test_opt(dir->i_sb, IOPEN) ||
241 +           !match_dentry(dentry, "__iopen__"))
242 +               return 0;
243 +
244 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
245 +
246 +       if (!inode) 
247 +               return 0;
248 +       d_add(dentry, inode);
249 +       return 1;
250 +}
251 +
252 +/*
253 + * This function is spliced into read_inode; it returns 1 if inode
254 + * number is the one for /__iopen__, in which case the inode is filled
255 + * in appropriately.  Otherwise, this fuction returns 0.
256 + */
257 +int ext3_iopen_get_inode(struct inode * inode)
258 +{
259 +       if (inode->i_ino != EXT3_BAD_INO)
260 +               return 0;
261 +
262 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
263 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
264 +               inode->i_mode |= 0777;
265 +       inode->i_uid = 0;
266 +       inode->i_gid = 0;
267 +       inode->i_nlink = 1;
268 +       inode->i_size = 4096;
269 +       inode->i_atime = CURRENT_TIME;
270 +       inode->i_ctime = CURRENT_TIME;
271 +       inode->i_mtime = CURRENT_TIME;
272 +       EXT3_I(inode)->i_dtime = 0;
273 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
274 +                                        * (for stat), not the fs block
275 +                                        * size */  
276 +       inode->i_blocks = 0;
277 +       inode->i_version = 1;
278 +       inode->i_generation = 0;
279 +
280 +       inode->i_op = &iopen_inode_operations;
281 +       inode->i_fop = &iopen_file_operations;
282 +       inode->i_mapping->a_ops = 0;
283 +
284 +       return 1;
285 +}
286 Index: linux-2.6.3-mm4/fs/ext3/iopen.h
287 ===================================================================
288 --- linux-2.6.3-mm4.orig/fs/ext3/iopen.h        2004-03-08 14:58:44.413198848 +0800
289 +++ linux-2.6.3-mm4/fs/ext3/iopen.h     2004-03-08 14:58:44.577173920 +0800
290 @@ -0,0 +1,15 @@
291 +/*
292 + * iopen.h
293 + *
294 + * Special support for opening files by inode number.
295 + * 
296 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
297 + * 
298 + * This file may be redistributed under the terms of the GNU General
299 + * Public License.
300 + */
301 +
302 +extern int ext3_check_for_iopen(struct inode * dir, struct dentry *dentry);
303 +extern int ext3_iopen_get_inode(struct inode * inode);
304 +
305 +
306 Index: linux-2.6.3-mm4/fs/ext3/namei.c
307 ===================================================================
308 --- linux-2.6.3-mm4.orig/fs/ext3/namei.c        2004-03-08 14:57:52.978018184 +0800
309 +++ linux-2.6.3-mm4/fs/ext3/namei.c     2004-03-08 14:58:44.648163128 +0800
310 @@ -37,6 +37,7 @@
311  #include <linux/buffer_head.h>
312  #include <linux/smp_lock.h>
313  #include "xattr.h"
314 +#include "iopen.h"
315  #include "acl.h"
316  
317  /*
318 @@ -970,15 +971,21 @@
319  }
320  #endif
321  
322 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
323
324  static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
325  {
326         struct inode * inode;
327         struct ext3_dir_entry_2 * de;
328         struct buffer_head * bh;
329 +       struct dentry *alternate = NULL;
330  
331         if (dentry->d_name.len > EXT3_NAME_LEN)
332                 return ERR_PTR(-ENAMETOOLONG);
333  
334 +       if (ext3_check_for_iopen(dir, dentry))
335 +               return NULL;
336 +
337         bh = ext3_find_entry(dentry, &de);
338         inode = NULL;
339         if (bh) {
340 @@ -989,8 +996,14 @@
341                 if (!inode)
342                         return ERR_PTR(-EACCES);
343         }
344 +       if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
345 +               iput(inode);
346 +               return alternate;
347 +       }
348 +
349         if (inode)
350                 return d_splice_alias(inode, dentry);
351 +
352         d_add(dentry, inode);
353         return NULL;
354  }
355 Index: linux-2.6.3-mm4/fs/ext3/super.c
356 ===================================================================
357 --- linux-2.6.3-mm4.orig/fs/ext3/super.c        2004-03-08 14:57:55.049703240 +0800
358 +++ linux-2.6.3-mm4/fs/ext3/super.c     2004-03-08 15:03:18.310560120 +0800
359 @@ -575,7 +575,7 @@
360         Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
361         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
362         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
363 -       Opt_ignore, Opt_err,
364 +       Opt_ignore, Opt_err, Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
365  };
366  
367  static match_table_t tokens = {
368 @@ -620,6 +620,9 @@
369         {Opt_ignore, "noquota"},
370         {Opt_ignore, "quota"},
371         {Opt_ignore, "usrquota"},
372 +       {Opt_iopen,  "iopen"},
373 +       {Opt_noiopen,  "noiopen"},
374 +       {Opt_iopen_nopriv,  "iopen_nopriv"},
375         {Opt_err, NULL}
376  };
377  
378 @@ -869,6 +872,18 @@
379                 case Opt_abort:
380                         set_opt(sbi->s_mount_opt, ABORT);
381                         break;
382 +               case Opt_iopen:
383 +                       set_opt (sbi->s_mount_opt, IOPEN);
384 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
385 +                       break;
386 +               case Opt_noiopen:
387 +                       clear_opt (sbi->s_mount_opt, IOPEN);
388 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
389 +                       break;
390 +               case Opt_iopen_nopriv:
391 +                       set_opt (sbi->s_mount_opt, IOPEN);
392 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
393 +                       break;
394                 case Opt_ignore:
395                         break;
396                 default:
397 Index: linux-2.6.3-mm4/fs/ext3/Makefile
398 ===================================================================
399 --- linux-2.6.3-mm4.orig/fs/ext3/Makefile       2004-01-09 14:59:08.000000000 +0800
400 +++ linux-2.6.3-mm4/fs/ext3/Makefile    2004-03-08 14:58:44.794140936 +0800
401 @@ -5,7 +5,7 @@
402  obj-$(CONFIG_EXT3_FS) += ext3.o
403  
404  ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
405 -          ioctl.o namei.o super.o symlink.o hash.o
406 +          ioctl.o namei.o super.o symlink.o hash.o iopen.o
407  
408  ext3-$(CONFIG_EXT3_FS_XATTR)    += xattr.o xattr_user.o xattr_trusted.o
409  ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
410 Index: linux-2.6.3-mm4/include/linux/ext3_fs.h
411 ===================================================================
412 --- linux-2.6.3-mm4.orig/include/linux/ext3_fs.h        2004-03-08 14:57:53.057006176 +0800
413 +++ linux-2.6.3-mm4/include/linux/ext3_fs.h     2004-03-08 14:58:44.795140784 +0800
414 @@ -325,6 +325,8 @@
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_POSIX_ACL           0x8000  /* POSIX Access Control Lists */
418 +#define EXT3_MOUNT_IOPEN              0x10000  /* Allow access via iopen */
419 +#define EXT3_MOUNT_IOPEN_NOPRIV               0x20000  /* Make iopen world-readable */
420  
421  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
422  #ifndef _LINUX_EXT2_FS_H