Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / extN-wantedi.patch
1 diff -urp linux-2.4.24.orig/fs/ext3/ialloc.c linux-2.4.24/fs/ext3/ialloc.c
2 --- linux-2.4.24.orig/fs/ext3/ialloc.c  2007-02-16 10:54:31.000000000 +0200
3 +++ linux-2.4.24/fs/ext3/ialloc.c       2007-02-16 10:55:30.000000000 +0200
4 @@ -330,7 +330,8 @@ int ext3_itable_block_used(struct super_
5   * group to find a free inode.
6   */
7  struct inode * ext3_new_inode (handle_t *handle,
8 -                               const struct inode * dir, int mode)
9 +                               const struct inode * dir, int mode,
10 +                               unsigned long goal)
11  {
12         struct super_block * sb;
13         struct buffer_head * bh;
14 @@ -355,7 +356,41 @@ struct inode * ext3_new_inode (handle_t 
15         init_rwsem(&inode->u.ext3_i.truncate_sem);
16  
17         lock_super (sb);
18 -       es = sb->u.ext3_sb.s_es;
19 +       es = EXT3_SB(sb)->s_es;
20 +
21 +       if (goal) {
22 +               i = (goal - 1) / EXT3_INODES_PER_GROUP(sb);
23 +               j = (goal - 1) % EXT3_INODES_PER_GROUP(sb);
24 +               gdp = ext3_get_group_desc(sb, i, &bh2);
25 +
26 +               bitmap_nr = load_inode_bitmap (sb, i);
27 +               if (bitmap_nr < 0) {
28 +                       err = bitmap_nr;
29 +                       goto fail;
30 +               }
31 +
32 +               bh = EXT3_SB(sb)->s_inode_bitmap[bitmap_nr];
33 +
34 +               BUFFER_TRACE(bh, "get_write_access");
35 +               err = ext3_journal_get_write_access(handle, bh);
36 +               if (err) goto fail;
37 +
38 +               if (ext3_set_bit(j, bh->b_data)) {
39 +                       printk(KERN_ERR "goal inode %lu unavailable\n", goal);
40 +                       /* Oh well, we tried. */
41 +                       goto repeat;
42 +               }
43 +
44 +               BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
45 +               err = ext3_journal_dirty_metadata(handle, bh);
46 +               if (err) goto fail;
47 +
48 +               /* We've shortcircuited the allocation system successfully,
49 +                * now finish filling in the inode.
50 +                */
51 +               goto have_bit_and_group;
52 +       }
53 +
54  repeat:
55         gdp = NULL;
56         i = 0;
57 @@ -470,6 +505,7 @@ repeat:
58                 }
59                 goto repeat;
60         }
61 + have_bit_and_group:
62         j += i * EXT3_INODES_PER_GROUP(sb) + 1;
63         if (j < EXT3_FIRST_INO(sb) || j > le32_to_cpu(es->s_inodes_count)) {
64                 ext3_error (sb, "ext3_new_inode",
65 diff -urp linux-2.4.24.orig/fs/ext3/inode.c linux-2.4.24/fs/ext3/inode.c
66 --- linux-2.4.24.orig/fs/ext3/inode.c   2007-02-16 10:54:31.000000000 +0200
67 +++ linux-2.4.24/fs/ext3/inode.c        2007-02-16 10:55:30.000000000 +0200
68 @@ -2605,7 +2605,7 @@ void ext3_truncate_thread(struct inode *
69         if (IS_ERR(handle))
70                 goto out_truncate;
71  
72 -       new_inode = ext3_new_inode(handle, old_inode, old_inode->i_mode);
73 +       new_inode = ext3_new_inode(handle, old_inode, old_inode->i_mode, 0);
74         if (IS_ERR(new_inode)) {
75                 ext3_debug("truncate inode %lu directly (no new inodes)\n",
76                            old_inode->i_ino);
77 diff -urp linux-2.4.24.orig/fs/ext3/ioctl.c linux-2.4.24/fs/ext3/ioctl.c
78 --- linux-2.4.24.orig/fs/ext3/ioctl.c   2003-06-13 17:51:37.000000000 +0300
79 +++ linux-2.4.24/fs/ext3/ioctl.c        2007-02-16 10:55:30.000000000 +0200
80 @@ -23,6 +23,31 @@ int ext3_ioctl (struct inode * inode, st
81         ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg);
82  
83         switch (cmd) {
84 +       case EXT3_IOC_CREATE_INUM: {
85 +               char name[32];
86 +               struct dentry *dchild, *dparent;
87 +               int rc = 0;
88 +
89 +               dparent = list_entry(inode->i_dentry.next, struct dentry,
90 +                                    d_alias);
91 +               snprintf(name, sizeof name, "%lu", arg);
92 +               dchild = lookup_one_len(name, dparent, strlen(name));
93 +               if (dchild->d_inode) {
94 +                       printk(KERN_ERR "%*s/%lu already exists (ino %lu)\n",
95 +                              dparent->d_name.len, dparent->d_name.name, arg,
96 +                              dchild->d_inode->i_ino);
97 +                       rc = -EEXIST;
98 +               } else {
99 +                       dchild->d_fsdata = (void *)arg;
100 +                       rc = vfs_create(inode, dchild, 0644);
101 +                       if (rc)
102 +                               printk(KERN_ERR "vfs_create: %d\n", rc);
103 +                       else if (dchild->d_inode->i_ino != arg)
104 +                               rc = -EEXIST;
105 +               }
106 +               dput(dchild);
107 +               return rc;
108 +       }
109         case EXT3_IOC_GETFLAGS:
110                 flags = inode->u.ext3_i.i_flags & EXT3_FL_USER_VISIBLE;
111                 return put_user(flags, (int *) arg);
112 diff -urp linux-2.4.24.orig/fs/ext3/namei.c linux-2.4.24/fs/ext3/namei.c
113 --- linux-2.4.24.orig/fs/ext3/namei.c   2007-02-16 10:54:31.000000000 +0200
114 +++ linux-2.4.24/fs/ext3/namei.c        2007-02-16 10:56:22.000000000 +0200
115 @@ -142,6 +142,14 @@ struct dx_map_entry
116         u32 offs;
117  };
118  
119 +#define LVFS_DENTRY_PARAM_MAGIC                20070216UL
120 +struct lvfs_dentry_params
121 +{
122 +       unsigned long   p_inum;
123 +       void            *p_ptr; 
124 +       u32             magic;
125 +};
126 +
127  #ifdef CONFIG_EXT3_INDEX
128  static inline unsigned dx_get_block (struct dx_entry *entry);
129  static void dx_set_block (struct dx_entry *entry, unsigned value);
130 @@ -1541,6 +1549,20 @@ static int ext3_add_nondir(handle_t *han
131         return err;
132  }
133  
134 +static struct inode * ext3_new_inode_wantedi(handle_t *handle, struct inode *dir,
135 +                                               int mode, struct dentry *dentry)
136 +{
137 +       unsigned long inum = 0;
138 +
139 +       if (dentry->d_fsdata != NULL) {
140 +               struct lvfs_dentry_params *param = dentry->d_fsdata;
141 +
142 +               if (param->magic == LVFS_DENTRY_PARAM_MAGIC)
143 +                       inum = param->p_inum;
144 +       }
145 +       return ext3_new_inode(handle, dir, mode, inum);
146 +}
147 +
148  /*
149   * By the time this is called, we already have created
150   * the directory cache entry for the new file, but it
151 @@ -1564,7 +1586,7 @@ static int ext3_create (struct inode * d
152         if (IS_SYNC(dir))
153                 handle->h_sync = 1;
154  
155 -       inode = ext3_new_inode (handle, dir, mode);
156 +       inode = ext3_new_inode_wantedi (handle, dir, mode, dentry);
157         err = PTR_ERR(inode);
158         if (!IS_ERR(inode)) {
159                 inode->i_op = &ext3_file_inode_operations;
160 @@ -1592,7 +1614,7 @@ static int ext3_mknod (struct inode * di
161         if (IS_SYNC(dir))
162                 handle->h_sync = 1;
163  
164 -       inode = ext3_new_inode (handle, dir, mode);
165 +       inode = ext3_new_inode_wantedi (handle, dir, mode, dentry);
166         err = PTR_ERR(inode);
167         if (!IS_ERR(inode)) {
168                 init_special_inode(inode, mode, rdev);
169 @@ -1622,7 +1644,7 @@ static int ext3_mkdir(struct inode * dir
170         if (IS_SYNC(dir))
171                 handle->h_sync = 1;
172  
173 -       inode = ext3_new_inode (handle, dir, S_IFDIR | mode);
174 +       inode = ext3_new_inode_wantedi (handle, dir, S_IFDIR | mode, dentry);
175         err = PTR_ERR(inode);
176         if (IS_ERR(inode))
177                 goto out_stop;
178 @@ -2053,7 +2075,7 @@ static int ext3_symlink (struct inode * 
179         if (IS_SYNC(dir))
180                 handle->h_sync = 1;
181  
182 -       inode = ext3_new_inode (handle, dir, S_IFLNK|S_IRWXUGO);
183 +       inode = ext3_new_inode_wantedi (handle, dir, S_IFLNK|S_IRWXUGO, dentry);
184         err = PTR_ERR(inode);
185         if (IS_ERR(inode))
186                 goto out_stop;
187 diff -urp linux-2.4.24.orig/include/linux/ext3_fs.h linux-2.4.24/include/linux/ext3_fs.h
188 --- linux-2.4.24.orig/include/linux/ext3_fs.h   2007-02-16 10:54:31.000000000 +0200
189 +++ linux-2.4.24/include/linux/ext3_fs.h        2007-02-16 10:55:30.000000000 +0200
190 @@ -202,6 +202,7 @@ struct ext3_group_desc
191  #define        EXT3_IOC_SETFLAGS               _IOW('f', 2, long)
192  #define        EXT3_IOC_GETVERSION             _IOR('f', 3, long)
193  #define        EXT3_IOC_SETVERSION             _IOW('f', 4, long)
194 +/* EXT3_IOC_CREATE_INUM at bottom of file (visible to kernel and user). */
195  #define        EXT3_IOC_GETVERSION_OLD         _IOR('v', 1, long)
196  #define        EXT3_IOC_SETVERSION_OLD         _IOW('v', 2, long)
197  #ifdef CONFIG_JBD_DEBUG
198 @@ -674,7 +675,8 @@ extern int ext3fs_dirhash(const char *na
199                           dx_hash_info *hinfo);
200  
201  /* ialloc.c */
202 -extern struct inode * ext3_new_inode (handle_t *, const struct inode *, int);
203 +extern struct inode * ext3_new_inode (handle_t *, const struct inode *, int,
204 +                                     unsigned long);
205  extern void ext3_free_inode (handle_t *, struct inode *);
206  extern struct inode * ext3_orphan_get (struct super_block *, unsigned long);
207  extern unsigned long ext3_count_free_inodes (struct super_block *);
208 @@ -766,4 +768,5 @@ extern struct inode_operations ext3_fast
209  
210  #endif /* __KERNEL__ */
211  
212 +#define EXT3_IOC_CREATE_INUM                   _IOW('f', 5, long)
213  #endif /* _LINUX_EXT3_FS_H */