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