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