Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / iopen-2.6-suse.patch
1 Index: linux-stage/fs/ext3/Makefile
2 ===================================================================
3 --- linux-stage.orig/fs/ext3/Makefile   2005-02-25 14:31:53.151076368 +0200
4 +++ linux-stage/fs/ext3/Makefile        2005-02-25 14:41:51.259150120 +0200
5 @@ -4,7 +4,7 @@
6  
7  obj-$(CONFIG_EXT3_FS) += ext3.o
8  
9 -ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
10 +ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
11            ioctl.o namei.o super.o symlink.o hash.o
12  
13  ext3-$(CONFIG_EXT3_FS_XATTR)    += xattr.o xattr_user.o xattr_trusted.o
14 Index: linux-stage/fs/ext3/inode.c
15 ===================================================================
16 --- linux-stage.orig/fs/ext3/inode.c    2005-02-25 14:37:30.983718000 +0200
17 +++ linux-stage/fs/ext3/inode.c 2005-02-25 14:47:42.069818792 +0200
18 @@ -37,6 +37,7 @@
19  #include <linux/mpage.h>
20  #include <linux/uio.h>
21  #include "xattr.h"
22 +#include "iopen.h"
23  #include "acl.h"
24  
25  /*
26 @@ -2408,6 +2409,9 @@
27  #endif
28         ei->i_rsv_window.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED;
29  
30 +       if (ext3_iopen_get_inode(inode))
31 +               return;
32 +
33         if (ext3_get_inode_loc(inode, &iloc, 0))
34                 goto bad_inode;
35         bh = iloc.bh;
36 Index: linux-stage/fs/ext3/iopen.c
37 ===================================================================
38 --- linux-2.6.5-sles9.orig/fs/ext3/iopen.c      2003-01-30 13:24:37.000000000 +0300
39 +++ linux-2.6.5-sles9/fs/ext3/iopen.c   2004-11-09 02:18:27.611913312 +0300
40 @@ -0,0 +1,278 @@
41 +/*
42 + * linux/fs/ext3/iopen.c
43 + *
44 + * Special support for open by inode number
45 + *
46 + * Copyright (C) 2001 by Theodore Ts'o (tytso@alum.mit.edu).
47 + *
48 + * This file may be redistributed under the terms of the GNU General
49 + * Public License.
50 + *
51 + *
52 + * Invariants:
53 + *   - there is only ever a single DCACHE_NFSD_DISCONNECTED dentry alias
54 + *     for an inode at one time.
55 + *   - there are never both connected and DCACHE_NFSD_DISCONNECTED dentry
56 + *     aliases on an inode at the same time.
57 + *
58 + * If we have any connected dentry aliases for an inode, use one of those
59 + * in iopen_lookup().  Otherwise, we instantiate a single NFSD_DISCONNECTED
60 + * dentry for this inode, which thereafter will be found by the dcache
61 + * when looking up this inode number in __iopen__, so we don't return here
62 + * until it is gone.
63 + *
64 + * If we get an inode via a regular name lookup, then we "rename" the
65 + * NFSD_DISCONNECTED dentry to the proper name and parent.  This ensures
66 + * existing users of the disconnected dentry will continue to use the same
67 + * dentry as the connected users, and there will never be both kinds of
68 + * dentry aliases at one time.
69 + */
70 +
71 +#include <linux/sched.h>
72 +#include <linux/fs.h>
73 +#include <linux/ext3_jbd.h>
74 +#include <linux/jbd.h>
75 +#include <linux/ext3_fs.h>
76 +#include <linux/smp_lock.h>
77 +#include <linux/dcache.h>
78 +#include <linux/security.h>
79 +#include "iopen.h"
80 +
81 +#ifndef assert
82 +#define assert(test) J_ASSERT(test)
83 +#endif
84 +
85 +#define IOPEN_NAME_LEN 32
86 +
87 +/*
88 + * This implements looking up an inode by number.
89 + */
90 +static struct dentry *iopen_lookup(struct inode * dir, struct dentry *dentry,
91 +                                  struct nameidata *nd)
92 +{
93 +       struct inode *inode;
94 +       unsigned long ino;
95 +       struct list_head *lp;
96 +       struct dentry *alternate;
97 +       char buf[IOPEN_NAME_LEN];
98 +
99 +       if (dentry->d_name.len >= IOPEN_NAME_LEN)
100 +               return ERR_PTR(-ENAMETOOLONG);
101 +
102 +       memcpy(buf, dentry->d_name.name, dentry->d_name.len);
103 +       buf[dentry->d_name.len] = 0;
104 +
105 +       if (strcmp(buf, ".") == 0)
106 +               ino = dir->i_ino;
107 +       else if (strcmp(buf, "..") == 0)
108 +               ino = EXT3_ROOT_INO;
109 +       else
110 +               ino = simple_strtoul(buf, 0, 0);
111 +
112 +       if ((ino != EXT3_ROOT_INO &&
113 +            //ino != EXT3_ACL_IDX_INO &&
114 +            //ino != EXT3_ACL_DATA_INO &&
115 +            ino < EXT3_FIRST_INO(dir->i_sb)) ||
116 +           ino > le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
117 +               return ERR_PTR(-ENOENT);
118 +
119 +       inode = iget(dir->i_sb, ino);
120 +       if (!inode)
121 +               return ERR_PTR(-EACCES);
122 +       if (is_bad_inode(inode)) {
123 +               iput(inode);
124 +               return ERR_PTR(-ENOENT);
125 +       }
126 +
127 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
128 +       assert(d_unhashed(dentry));                     /* d_rehash */
129 +
130 +       /* preferrably return a connected dentry */
131 +       spin_lock(&dcache_lock);
132 +       list_for_each(lp, &inode->i_dentry) {
133 +               alternate = list_entry(lp, struct dentry, d_alias);
134 +               assert(!(alternate->d_flags & DCACHE_DISCONNECTED));
135 +       }
136 +
137 +       if (!list_empty(&inode->i_dentry)) {
138 +               alternate = list_entry(inode->i_dentry.next,
139 +                                      struct dentry, d_alias);
140 +               dget_locked(alternate);
141 +               spin_lock(&alternate->d_lock);
142 +               alternate->d_vfs_flags |= DCACHE_REFERENCED;
143 +               spin_unlock(&alternate->d_lock);
144 +               iput(inode);
145 +               spin_unlock(&dcache_lock);
146 +               return alternate;
147 +       }
148 +       dentry->d_flags |= DCACHE_DISCONNECTED;
149 +
150 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
151 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
152 +       dentry->d_inode = inode;
153 +
154 +       __d_rehash(dentry, 0);                          /* d_rehash */
155 +       spin_unlock(&dcache_lock);
156 +
157 +       return NULL;
158 +}
159 +
160 +#define do_switch(x,y) do { \
161 +       __typeof__ (x) __tmp = x; \
162 +       x = y; y = __tmp; } while (0)
163 +
164 +static inline void switch_names(struct dentry *dentry, struct dentry *target)
165 +{
166 +       const unsigned char *old_name, *new_name;
167 +
168 +       memcpy(dentry->d_iname, target->d_iname, DNAME_INLINE_LEN);
169 +       old_name = target->d_name.name;
170 +       new_name = dentry->d_name.name;
171 +       if (old_name == target->d_iname)
172 +               old_name = dentry->d_iname;
173 +       if (new_name == dentry->d_iname)
174 +               new_name = target->d_iname;
175 +       target->d_name.name = new_name;
176 +       dentry->d_name.name = old_name;
177 +}
178 +
179 +/* This function is spliced into ext3_lookup and does the move of a
180 + * disconnected dentry (if it exists) to a connected dentry.
181 + */
182 +struct dentry *iopen_connect_dentry(struct dentry *dentry, struct inode *inode,
183 +                                   int rehash)
184 +{
185 +       struct dentry *tmp, *goal = NULL;
186 +       struct list_head *lp;
187 +
188 +       /* verify this dentry is really new */
189 +       assert(dentry->d_inode == NULL);
190 +       assert(list_empty(&dentry->d_alias));           /* d_instantiate */
191 +       if (rehash)
192 +               assert(d_unhashed(dentry));     /* d_rehash */
193 +       assert(list_empty(&dentry->d_subdirs));
194 +
195 +       spin_lock(&dcache_lock);
196 +       if (!inode)
197 +               goto do_rehash;
198 +
199 +       if (!test_opt(inode->i_sb, IOPEN))
200 +               goto do_instantiate;
201 +
202 +       /* preferrably return a connected dentry */
203 +       list_for_each(lp, &inode->i_dentry) {
204 +               tmp = list_entry(lp, struct dentry, d_alias);
205 +               if (tmp->d_flags & DCACHE_DISCONNECTED) {
206 +                       assert(tmp->d_alias.next == &inode->i_dentry);
207 +                       assert(tmp->d_alias.prev == &inode->i_dentry);
208 +                       goal = tmp;
209 +                       dget_locked(goal);
210 +                       break;
211 +               }
212 +       }
213 +
214 +       if (!goal)
215 +               goto do_instantiate;
216 +
217 +       /* Move the goal to the de hash queue */
218 +       goal->d_flags &= ~DCACHE_DISCONNECTED;
219 +       security_d_instantiate(goal, inode);
220 +       __d_drop(dentry);
221 +       __d_rehash(dentry, 0);
222 +       __d_move(goal, dentry);
223 +       spin_unlock(&dcache_lock);
224 +       iput(inode);
225 +
226 +       return goal;
227 +
228 +       /* d_add(), but don't drop dcache_lock before adding dentry to inode */
229 +do_instantiate:
230 +       list_add(&dentry->d_alias, &inode->i_dentry);   /* d_instantiate */
231 +       dentry->d_inode = inode;
232 +do_rehash:
233 +       if (rehash)
234 +               __d_rehash(dentry, 0);                  /* d_rehash */
235 +       spin_unlock(&dcache_lock);
236 +
237 +       return NULL;
238 +}
239 +
240 +/*
241 + * These are the special structures for the iopen pseudo directory.
242 + */
243 +
244 +static struct inode_operations iopen_inode_operations = {
245 +       lookup:         iopen_lookup,           /* BKL held */
246 +};
247 +
248 +static struct file_operations iopen_file_operations = {
249 +       read:           generic_read_dir,
250 +};
251 +
252 +static int match_dentry(struct dentry *dentry, const char *name)
253 +{
254 +       int     len;
255 +
256 +       len = strlen(name);
257 +       if (dentry->d_name.len != len)
258 +               return 0;
259 +       if (strncmp(dentry->d_name.name, name, len))
260 +               return 0;
261 +       return 1;
262 +}
263 +
264 +/*
265 + * This function is spliced into ext3_lookup and returns 1 the file
266 + * name is __iopen__ and dentry has been filled in appropriately.
267 + */
268 +int ext3_check_for_iopen(struct inode *dir, struct dentry *dentry)
269 +{
270 +       struct inode *inode;
271 +
272 +       if (dir->i_ino != EXT3_ROOT_INO ||
273 +           !test_opt(dir->i_sb, IOPEN) ||
274 +           !match_dentry(dentry, "__iopen__"))
275 +               return 0;
276 +
277 +       inode = iget(dir->i_sb, EXT3_BAD_INO);
278 +
279 +       if (!inode)
280 +               return 0;
281 +       d_add(dentry, inode);
282 +       return 1;
283 +}
284 +
285 +/*
286 + * This function is spliced into read_inode; it returns 1 if inode
287 + * number is the one for /__iopen__, in which case the inode is filled
288 + * in appropriately.  Otherwise, this fuction returns 0.
289 + */
290 +int ext3_iopen_get_inode(struct inode *inode)
291 +{
292 +       if (inode->i_ino != EXT3_BAD_INO)
293 +               return 0;
294 +
295 +       inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
296 +       if (test_opt(inode->i_sb, IOPEN_NOPRIV))
297 +               inode->i_mode |= 0777;
298 +       inode->i_uid = 0;
299 +       inode->i_gid = 0;
300 +       inode->i_nlink = 1;
301 +       inode->i_size = 4096;
302 +       inode->i_atime = CURRENT_TIME;
303 +       inode->i_ctime = CURRENT_TIME;
304 +       inode->i_mtime = CURRENT_TIME;
305 +       EXT3_I(inode)->i_dtime = 0;
306 +       inode->i_blksize = PAGE_SIZE;   /* This is the optimal IO size
307 +                                        * (for stat), not the fs block
308 +                                        * size */
309 +       inode->i_blocks = 0;
310 +       inode->i_version = 1;
311 +       inode->i_generation = 0;
312 +
313 +       inode->i_op = &iopen_inode_operations;
314 +       inode->i_fop = &iopen_file_operations;
315 +       inode->i_mapping->a_ops = 0;
316 +
317 +       return 1;
318 +}
319 Index: linux-stage/fs/ext3/iopen.h
320 ===================================================================
321 --- linux-stage.orig/fs/ext3/iopen.h    2005-02-25 14:41:01.017787968 +0200
322 +++ linux-stage/fs/ext3/iopen.h 2005-02-25 14:41:01.045783712 +0200
323 @@ -0,0 +1,15 @@
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 +extern struct dentry *iopen_connect_dentry(struct dentry *dentry,
338 +                                          struct inode *inode, int rehash);
339 Index: linux-stage/fs/ext3/namei.c
340 ===================================================================
341 --- linux-stage.orig/fs/ext3/namei.c    2005-02-25 14:37:28.975023368 +0200
342 +++ linux-stage/fs/ext3/namei.c 2005-02-25 14:46:43.090784968 +0200
343 @@ -37,6 +37,7 @@
344  #include <linux/buffer_head.h>
345  #include <linux/smp_lock.h>
346  #include "xattr.h"
347 +#include "iopen.h"
348  #include "acl.h"
349  
350  /*
351 @@ -980,6 +981,9 @@
352         if (dentry->d_name.len > EXT3_NAME_LEN)
353                 return ERR_PTR(-ENAMETOOLONG);
354  
355 +       if (ext3_check_for_iopen(dir, dentry))
356 +               return NULL;
357 +
358         bh = ext3_find_entry(dentry, &de);
359         inode = NULL;
360         if (bh) {
361 @@ -990,10 +994,8 @@
362                 if (!inode)
363                         return ERR_PTR(-EACCES);
364         }
365 -       if (inode)
366 -               return d_splice_alias(inode, dentry);
367 -       d_add(dentry, inode);
368 -       return NULL;
369 +
370 +       return iopen_connect_dentry(dentry, inode, 1);
371  }
372  
373  
374 @@ -2037,10 +2039,6 @@
375                               inode->i_nlink);
376         inode->i_version++;
377         inode->i_nlink = 0;
378 -       /* There's no need to set i_disksize: the fact that i_nlink is
379 -        * zero will ensure that the right thing happens during any
380 -        * recovery. */
381 -       inode->i_size = 0;
382         ext3_orphan_add(handle, inode);
383         inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
384         ext3_mark_inode_dirty(handle, inode);
385 @@ -2163,6 +2161,23 @@
386         return err;
387  }
388  
389 +/* Like ext3_add_nondir() except for call to iopen_connect_dentry */
390 +static int ext3_add_link(handle_t *handle, struct dentry *dentry,
391 +                        struct inode *inode)
392 +{
393 +       int err = ext3_add_entry(handle, dentry, inode);
394 +       if (!err) {
395 +               err = ext3_mark_inode_dirty(handle, inode);
396 +               if (err == 0) {
397 +                       dput(iopen_connect_dentry(dentry, inode, 0));
398 +                       return 0;
399 +               }
400 +       }
401 +       ext3_dec_count(handle, inode);
402 +       iput(inode);
403 +       return err;
404 +}
405 +
406  static int ext3_link (struct dentry * old_dentry,
407                 struct inode * dir, struct dentry *dentry)
408  {
409 @@ -2186,7 +2201,8 @@
410         ext3_inc_count(handle, inode);
411         atomic_inc(&inode->i_count);
412  
413 -       err = ext3_add_nondir(handle, dentry, inode);
414 +       err = ext3_add_link(handle, dentry, inode);
415 +       ext3_orphan_del(handle, inode);
416         ext3_journal_stop(handle);
417         if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
418                 goto retry;
419 Index: linux-stage/fs/ext3/super.c
420 ===================================================================
421 --- linux-stage.orig/fs/ext3/super.c    2005-02-25 14:37:30.987717392 +0200
422 +++ linux-stage/fs/ext3/super.c 2005-02-25 14:44:50.495901992 +0200
423 @@ -586,6 +586,7 @@
424         Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
425         Opt_ignore, Opt_barrier,
426         Opt_err,
427 +       Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
428  };
429  
430  static match_table_t tokens = {
431 @@ -633,6 +634,9 @@
432         {Opt_ignore, "noquota"},
433         {Opt_ignore, "quota"},
434         {Opt_ignore, "usrquota"},
435 +       {Opt_iopen, "iopen"},
436 +       {Opt_noiopen, "noiopen"},
437 +       {Opt_iopen_nopriv, "iopen_nopriv"},
438         {Opt_barrier, "barrier=%u"},
439         {Opt_err, NULL}
440  };
441 @@ -914,6 +918,18 @@
442                         else
443                                 clear_opt(sbi->s_mount_opt, BARRIER);
444                         break;
445 +               case Opt_iopen:
446 +                       set_opt (sbi->s_mount_opt, IOPEN);
447 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
448 +                       break;
449 +               case Opt_noiopen:
450 +                       clear_opt (sbi->s_mount_opt, IOPEN);
451 +                       clear_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
452 +                       break;
453 +               case Opt_iopen_nopriv:
454 +                       set_opt (sbi->s_mount_opt, IOPEN);
455 +                       set_opt (sbi->s_mount_opt, IOPEN_NOPRIV);
456 +                       break;
457                 case Opt_ignore:
458                         break;
459                 default:
460 Index: linux-stage/include/linux/ext3_fs.h
461 ===================================================================
462 --- linux-stage.orig/include/linux/ext3_fs.h    2005-02-25 14:37:28.977023064 +0200
463 +++ linux-stage/include/linux/ext3_fs.h 2005-02-25 14:49:00.569884968 +0200
464 @@ -355,6 +355,8 @@
465  #define EXT3_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
466  #define EXT3_MOUNT_RESERVATION         0x10000 /* Preallocation */
467  #define EXT3_MOUNT_BARRIER             0x20000 /* Use block barriers */
468 +#define EXT3_MOUNT_IOPEN               0x80000 /* Allow access via iopen */
469 +#define EXT3_MOUNT_IOPEN_NOPRIV                0x100000/* Make iopen world-readable */
470  
471  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
472  #ifndef _LINUX_EXT2_FS_H