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