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