Whamcloud - gitweb
6eabe858bd059306b5968859ad190f6037214baf
[fs/lustre-release.git] / lustre / kernel_patches / patches / iopen-2.4.18.patch
1  0 files changed
2
3 --- linux-2.4.18-chaos52/Documentation/filesystems/ext2.txt~iopen-2.4.18        2003-04-13 15:21:33.000000000 +0800
4 +++ linux-2.4.18-chaos52-root/Documentation/filesystems/ext2.txt        2003-06-03 17:10:55.000000000 +0800
5 @@ -35,6 +35,22 @@ resgid=n                     The group ID which may use th
6  
7  sb=n                           Use alternate superblock at this location.
8  
9 +iopen                          Makes an invisible pseudo-directory called 
10 +                               __iopen__ available in the root directory
11 +                               of the filesystem.  Allows open-by-inode-
12 +                               number.  i.e., inode 3145 can be accessed
13 +                               via /mntpt/__iopen__/3145
14 +
15 +iopen_nopriv                   This option makes the iopen directory be
16 +                               world-readable.  This may be safer since it
17 +                               allows daemons to run as an unprivileged user,
18 +                               however it significantly changes the security
19 +                               model of a Unix filesystem, since previously
20 +                               all files under a mode 700 directory were not
21 +                               generally avilable even if the
22 +                               permissions on the file itself is
23 +                               world-readable.
24 +
25  grpquota,noquota,quota,usrquota        Quota options are silently ignored by ext2.
26  
27  
28 --- linux-2.4.18-chaos52/fs/ext3/Makefile~iopen-2.4.18  2003-06-01 03:24:07.000000000 +0800
29 +++ linux-2.4.18-chaos52-root/fs/ext3/Makefile  2003-06-03 17:10:55.000000000 +0800
30 @@ -11,7 +11,7 @@ O_TARGET := ext3.o
31  
32  export-objs := super.o inode.o xattr.o
33  
34 -obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
35 +obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
36                 ioctl.o namei.o super.o symlink.o xattr.o
37  obj-m    := $(O_TARGET)
38  
39 --- linux-2.4.18-chaos52/fs/ext3/inode.c~iopen-2.4.18   2003-06-03 17:10:21.000000000 +0800
40 +++ linux-2.4.18-chaos52-root/fs/ext3/inode.c   2003-06-03 17:10:55.000000000 +0800
41 @@ -31,6 +31,7 @@
42  #include <linux/highuid.h>
43  #include <linux/quotaops.h>
44  #include <linux/module.h>
45 +#include "iopen.h"
46  
47  /*
48   * SEARCH_FROM_ZERO forces each block allocation to search from the start
49 @@ -2135,6 +2136,9 @@ void ext3_read_inode(struct inode * inod
50         struct buffer_head *bh;
51         int block;
52         
53 +       if (ext3_iopen_get_inode(inode))
54 +               return;
55 +       
56         if(ext3_get_inode_loc(inode, &iloc))
57                 goto bad_inode;
58         bh = iloc.bh;
59 --- /dev/null   2002-08-31 07:31:37.000000000 +0800
60 +++ linux-2.4.18-chaos52-root/fs/ext3/iopen.c   2003-06-03 17:10:55.000000000 +0800
61 @@ -0,0 +1,259 @@
62 +/*
63 + * linux/fs/ext3/iopen.c
64 + *
65 + * Special support for open by inode number
66 + *
67 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
68 + * 
69 + * This file may be redistributed under the terms of the GNU General
70 + * Public License.
71 + *
72 + *
73 + * Invariants:
74 + *   - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
75 + *     for an inode at one time.
76 + *   - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
77 + *     aliases on an inode at the same time.
78 + *
79 + * If we have any connected dentry aliases for an inode, use one of those
80 + * in iopen_lookup().  Otherwise, we instantiate a single NFSD_DISCONNECTED
81 + * dentry for this inode, which thereafter will be found by the dcache
82 + * when looking up this inode number in __iopen__, so we don't return here
83 + * until it is gone.
84 + *
85 + * If we get an inode via a regular name lookup, then we "rename" the
86 + * NFSD_DISCONNECTED dentry to the proper name and parent.  This ensures
87 + * existing users of the disconnected dentry will continue to use the same
88 + * dentry as the connected users, and there will never be both kinds of
89 + * dentry aliases at one time.
90 + */
91 +
92 +#include <linux/sched.h>
93 +#include <linux/fs.h>
94 +#include <linux/locks.h>
95 +#include <linux/ext3_jbd.h>
96 +#include <linux/jbd.h>
97 +#include <linux/ext3_fs.h>
98 +#include <linux/smp_lock.h>
99 +#include "iopen.h"
100 +
101 +#ifndef assert
102 +#define assert(test) J_ASSERT(test)
103 +#endif
104 +
105 +#define IOPEN_NAME_LEN 32
106 +
107 +/*
108 + * This implements looking up an inode by number.
109 + */
110 +static struct dentry *iopen_lookup(struct inode *dir, struct dentry *dentry)
111 +{
112 +       struct inode *inode;
113 +       unsigned long ino;
114 +       struct list_head *lp;
115 +       struct dentry *alternate;
116 +       char buf[IOPEN_NAME_LEN];
117 +       
118 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
119 +               return ERR_PTR(-ENAMETOOLONG);
120 +
121 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
122 +       buf[dentry->d_name.len] = 0;
123 +
124 +       if (strcmp(buf, ".") == 0)
125 +               ino = dir->i_ino;
126 +       else if (strcmp(buf, "..") == 0)
127 +               ino = EXT3_ROOT_INO;
128 +       else
129 +               ino = simple_strtoul(buf, 0, 0);
130 +
131 +       if ((ino != EXT3_ROOT_INO &&
132 +            //ino != EXT3_ACL_IDX_INO &&
133 +            //ino != EXT3_ACL_DATA_INO &&
134 +            ino < EXT3_FIRST_INO(dir->i_sb)) ||
135 +           ino > le32_to_cpu(dir->i_sb->u.ext3_sb.s_es->s_inodes_count))
136 +               return ERR_PTR(-ENOENT);
137 +
138 +       inode = iget(dir->i_sb, ino);
139 +       if (!inode)
140 +               return ERR_PTR(-EACCES);
141 +       if (is_bad_inode(inode)) {
142 +               iput(inode);
143 +               return ERR_PTR(-ENOENT);
144 +       }
145 +
146 +       /* preferrably return a connected dentry */
147 +       spin_lock(&dcache_lock);
148 +       list_for_each(lp, &inode->i_dentry) {
149 +               alternate = list_entry(lp, struct dentry, d_alias);
150 +               assert(!(alternate->d_flags & DCACHE_NFSD_DISCONNECTED));
151 +       }
152 +
153 +       if (!list_empty(&inode->i_dentry)) {
154 +               alternate = list_entry(inode->i_dentry.next, 
155 +                                      struct dentry, d_alias);
156 +               dget_locked(alternate);
157 +               alternate->d_vfs_flags |= DCACHE_REFERENCED;
158 +               iput(inode);
159 +               spin_unlock(&dcache_lock);
160 +               return alternate;
161 +       }
162 +       dentry->d_flags |= DCACHE_NFSD_DISCONNECTED;
163 +       spin_unlock(&dcache_lock);
164 +
165 +       d_add(dentry, inode);
166 +       return NULL;
167 +}
168 +
169 +#define do_switch(x,y) do { \
170 +       __typeof__ (x) __tmp = x; \
171 +       x = y; y = __tmp; } while (0)
172 +
173 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
174 +{
175 +       const unsigned char *old_name, *new_name;
176 +
177 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN); 
178 +       old_name = target->d_name.name;
179 +       new_name = dentry->d_name.name;
180 +       if (old_name == target->d_iname)
181 +               old_name = dentry->d_iname;
182 +       if (new_name == dentry->d_iname)
183 +               new_name = target->d_iname;
184 +       target->d_name.name = new_name;
185 +       dentry->d_name.name = old_name;
186 +}
187 +
188 +/* This function is spliced into ext3_lookup and does the move of a
189 + * disconnected dentry (if it exists) to a connected dentry.
190 + */
191 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode)
192 +{
193 +       struct dentry *tmp, *goal = NULL;
194 +       struct list_head *lp;
195 +
196 +       /* preferrably return a connected dentry */
197 +       spin_lock(&dcache_lock);
198 +       /* verify this dentry is really new */
199 +       assert(!de->d_inode);
200 +       assert(list_empty(&de->d_subdirs));
201 +       assert(list_empty(&de->d_alias));
202 +
203 +
204 +       list_for_each(lp, &inode->i_dentry) {
205 +               tmp = list_entry(lp, struct dentry, d_alias);
206 +               if (tmp->d_flags & DCACHE_NFSD_DISCONNECTED) {
207 +                       assert(tmp->d_alias.next == &inode->i_dentry);
208 +                       assert(tmp->d_alias.prev == &inode->i_dentry);
209 +                       goal = tmp;
210 +                       dget_locked(goal);
211 +                       break;
212 +               }
213 +       }
214 +
215 +       if (!goal) { 
216 +               spin_unlock(&dcache_lock);
217 +               return NULL; 
218 +       }
219 +
220 +       /* Move the goal to the de hash queue - like d_move() */
221 +       goal->d_flags &= ~DCACHE_NFSD_DISCONNECTED;
222 +       list_del(&goal->d_hash);
223 +       list_add(&goal->d_hash, &de->d_hash);
224 +
225 +       list_del(&goal->d_child);
226 +       list_del(&de->d_child);
227 +
228 +       /* Switch the parents and the names.. */
229 +       switch_names(goal, de);
230 +       do_switch(goal->d_parent, de->d_parent);
231 +       do_switch(goal->d_name.len, de->d_name.len);
232 +       do_switch(goal->d_name.hash, de->d_name.hash);
233 +
234 +       /* And add them back to the (new) parent lists */
235 +       list_add(&goal->d_child, &goal->d_parent->d_subdirs);
236 +       list_add(&de->d_child, &de->d_parent->d_subdirs);
237 +       spin_unlock(&dcache_lock);
238 +
239 +       return goal;
240 +}
241 +
242 +/*
243 + * These are the special structures for the iopen pseudo directory.
244 + */
245 +
246 +static struct inode_operations iopen_inode_operations = {
247 +       lookup:         iopen_lookup,           /* BKL held */
248 +};
249 +
250 +static struct file_operations iopen_file_operations = {
251 +       read:           generic_read_dir,
252 +};
253 +
254 +static int match_dentry(struct dentry *dentry, const char *name)
255 +{
256 +       int     len;
257 +
258 +       len = strlen(name);
259 +       if (dentry->d_name.len != len)
260 +               return 0;
261 +       if (strncmp(dentry->d_name.name, name, len))
262 +               return 0;
263 +       return 1;
264 +}
265 +
266 +/*
267 + * This function is spliced into ext3_lookup and returns 1 the file
268 + * name is __iopen__ and dentry has been filled in appropriately.
269 + */
270 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
271 +{
272 +       struct inode *inode;
273 +
274 +       if (dir->i_ino != EXT3_ROOT_INO ||
275 +           !test_opt(dir->i_sb, IOPEN) ||
276 +           !match_dentry(dentry, "__iopen__"))
277 +               return 0;
278 +
279 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
280 +
281 +       if (!inode) 
282 +               return 0;
283 +       d_add(dentry, inode);
284 +       return 1;
285 +}
286 +
287 +/*
288 + * This function is spliced into read_inode; it returns 1 if inode
289 + * number is the one for /__iopen__, in which case the inode is filled
290 + * in appropriately.  Otherwise, this fuction returns 0.
291 + */
292 +int ext3_iopen_get_inode(struct inode *inode)
293 +{
294 +       if (inode->i_ino != EXT3_BAD_INO)
295 +               return 0;
296 +
297 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
298 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
299 +               inode->i_mode |= 0777;
300 +       inode->i_uid = 0;
301 +       inode->i_gid = 0;
302 +       inode->i_nlink = 1;
303 +       inode->i_size = 4096;
304 +       inode->i_atime = CURRENT_TIME;
305 +       inode->i_ctime = CURRENT_TIME;
306 +       inode->i_mtime = CURRENT_TIME;
307 +       inode->u.ext3_i.i_dtime = 0;
308 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
309 +                                        * (for stat), not the fs block
310 +                                        * size */  
311 +       inode->i_blocks = 0;
312 +       inode->i_version = 1;
313 +       inode->i_generation = 0;
314 +
315 +       inode->i_op = &iopen_inode_operations;
316 +       inode->i_fop = &iopen_file_operations;
317 +       inode->i_mapping->a_ops = 0;
318 +
319 +       return 1;
320 +}
321 --- /dev/null   2002-08-31 07:31:37.000000000 +0800
322 +++ linux-2.4.18-chaos52-root/fs/ext3/iopen.h   2003-06-03 17:10:55.000000000 +0800
323 @@ -0,0 +1,13 @@
324 +/*
325 + * iopen.h
326 + *
327 + * Special support for opening files by inode number.
328 + * 
329 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
330 + * 
331 + * This file may be redistributed under the terms of the GNU General
332 + * Public License.
333 + */
334 +
335 +extern int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry);
336 +extern int ext3_iopen_get_inode(struct inode *inode);
337 --- linux-2.4.18-chaos52/fs/ext3/namei.c~iopen-2.4.18   2003-06-03 17:10:20.000000000 +0800
338 +++ linux-2.4.18-chaos52-root/fs/ext3/namei.c   2003-06-03 17:10:55.000000000 +0800
339 @@ -34,6 +34,7 @@
340  #include <linux/locks.h>
341  #include <linux/quotaops.h>
342  #include <linux/slab.h>
343 +#include "iopen.h"
344  
345  /*
346   * define how far ahead to read directories while searching them.
347 @@ -703,16 +704,21 @@ cleanup_and_exit:
348                 brelse (bh_use[ra_ptr]);
349         return ret;
350  }
351 +struct dentry *iopen_connect_dentry(struct dentry *de, struct inode *inode);
352  
353  static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry)
354  {
355         struct inode * inode;
356         struct ext3_dir_entry_2 * de;
357         struct buffer_head * bh;
358 +       struct dentry *alternate = NULL;
359  
360         if (dentry->d_name.len > EXT3_NAME_LEN)
361                 return ERR_PTR(-ENAMETOOLONG);
362  
363 +       if (ext3_check_for_iopen(dir, dentry))
364 +               return NULL;
365 +
366         bh = ext3_find_entry(dentry, &de);
367         inode = NULL;
368         if (bh) {
369 @@ -723,6 +729,12 @@ static struct dentry *ext3_lookup(struct
370                 if (!inode)
371                         return ERR_PTR(-EACCES);
372         }
373 +
374 +       if (inode && (alternate = iopen_connect_dentry(dentry, inode))) {
375 +               iput(inode);
376 +               return alternate;
377 +       }
378 +
379         d_add(dentry, inode);
380         return NULL;
381  }
382 --- linux-2.4.18-chaos52/fs/ext3/super.c~iopen-2.4.18   2003-06-03 17:10:21.000000000 +0800
383 +++ linux-2.4.18-chaos52-root/fs/ext3/super.c   2003-06-03 17:10:55.000000000 +0800
384 @@ -820,6 +820,17 @@ static int parse_options (char * options
385                          || !strcmp (this_char, "quota")
386                          || !strcmp (this_char, "usrquota"))
387                         /* Don't do anything ;-) */ ;
388 +               else if (!strcmp (this_char, "iopen")) {
389 +                       set_opt (sbi->s_mount_opt, IOPEN);
390 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
391 +               } else if (!strcmp (this_char, "noiopen")) {
392 +                       clear_opt (sbi->s_mount_opt, IOPEN);
393 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
394 +               }
395 +               else if (!strcmp (this_char, "iopen_nopriv")) {
396 +                       set_opt (sbi->s_mount_opt, IOPEN);
397 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
398 +               }
399                 else if (!strcmp (this_char, "journal")) {
400                         /* @@@ FIXME */
401                         /* Eventually we will want to be able to create
402 --- linux-2.4.18-chaos52/include/linux/ext3_fs.h~iopen-2.4.18   2003-06-03 17:10:22.000000000 +0800
403 +++ linux-2.4.18-chaos52-root/include/linux/ext3_fs.h   2003-06-03 17:12:08.000000000 +0800
404 @@ -321,6 +321,8 @@ struct ext3_inode {
405  #define EXT3_MOUNT_UPDATE_JOURNAL      0x1000  /* Update the journal format */
406  #define EXT3_MOUNT_NO_UID32            0x2000  /* Disable 32-bit UIDs */
407  #define EXT3_MOUNT_INDEX               0x4000  /* Enable directory index */
408 +#define EXT3_MOUNT_IOPEN               0x8000  /* Allow access via iopen */
409 +#define EXT3_MOUNT_IOPEN_NOPRIV                0x10000 /* Make iopen world-readable */
410  #define EXT3_MOUNT_ASYNCDEL            0x20000 /* Delayed deletion */
411  
412  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
413
414 _