Whamcloud - gitweb
Revert Tom's commit. It breaks recovery.
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-extents-in-ea-ioctl-2.6.10-fc3.patch
1 Index: linux-2.6.10/fs/ext3/extents-in-ea.c
2 ===================================================================
3 --- linux-2.6.10.orig/fs/ext3/extents-in-ea.c   2005-03-31 19:41:09.471494208 +0800
4 +++ linux-2.6.10/fs/ext3/extents-in-ea.c        2005-03-31 19:41:09.580477640 +0800
5 @@ -27,7 +27,7 @@
6  #include <linux/quotaops.h>
7  #include <linux/string.h>
8  #include <linux/ext3_extents.h>
9 -#include <linux/ext3_xattr.h>
10 +#include "xattr.h" 
11  #include <linux/slab.h>
12  #include <asm/uaccess.h>
13  
14 @@ -111,7 +111,7 @@
15         err = ext3_extent_tree_init(handle, &tree);
16         ext3_release_tree_in_ea_desc(&tree);
17  out:
18 -       ext3_journal_stop(handle, inode);
19 +       ext3_journal_stop(handle);
20         kfree(root);
21         return err;
22  }
23 @@ -134,24 +134,24 @@
24         up(&EXT3_I(inode)->truncate_sem);
25         handle = ext3_journal_start(tree->inode, needed + 10);
26         if (IS_ERR(handle)) {
27 -               down_write(&EXT3_I(inode)->truncate_sem);
28 +               down(&EXT3_I(inode)->truncate_sem);
29                 return PTR_ERR(handle);
30         }
31  
32         if (tgen != EXT_GENERATION(tree)) {
33                 /* the tree has changed. so path can be invalid at moment */
34 -               ext3_journal_stop(handle, inode);
35 -               down_write(&EXT3_I(inode)->truncate_sem);
36 +               ext3_journal_stop(handle);
37 +               down(&EXT3_I(inode)->truncate_sem);
38                 return EXT_REPEAT;
39         }
40  
41 -       down_write(&EXT3_I(inode)->truncate_sem);
42 +       down(&EXT3_I(inode)->truncate_sem);
43  
44         /* insert new extent */
45         newex->ee_start = 0;
46         err = ext3_ext_insert_extent(handle, tree, path, newex);
47         if (!err)
48 -               ext3_journal_stop(handle, tree->inode);
49 +               ext3_journal_stop(handle);
50  
51         return err;
52  }
53 @@ -165,11 +165,11 @@
54  
55         err = ext3_init_tree_in_ea_desc(&tree, inode, name_index, eaname);
56         if (err == 0) {
57 -               down_write(&EXT3_I(inode)->truncate_sem);       
58 +               down(&EXT3_I(inode)->truncate_sem);     
59                 err = ext3_ext_walk_space(&tree, from, num,
60                                                 ext3_ext_in_ea_new_extent);
61                 ext3_release_tree_in_ea_desc(&tree);
62 -               up_write(&EXT3_I(inode)->truncate_sem);
63 +               up(&EXT3_I(inode)->truncate_sem);
64         }
65         return err;
66  }
67 @@ -222,3 +222,112 @@
68         return err;
69  }
70  
71 +static int
72 +ext3_ext_store_extent_cb(struct ext3_extents_tree *tree,
73 +                       struct ext3_ext_path *path,
74 +                       struct ext3_extent *newex, int exist)
75 +{
76 +       struct ext3_extent_buf *buf = (struct ext3_extent_buf *) tree->private;
77 +
78 +       if (!exist)
79 +               return EXT_CONTINUE;
80 +       if (buf->err < 0)
81 +               return EXT_BREAK;
82 +       if (buf->cur - buf->buffer + sizeof(*newex) > buf->buflen)
83 +               return EXT_BREAK;
84 +
85 +       if (!copy_to_user(buf->cur, newex, sizeof(*newex))) {
86 +               buf->err++;
87 +               buf->cur += sizeof(*newex);
88 +       } else {
89 +               buf->err = -EFAULT;
90 +               return EXT_BREAK;
91 +       }
92 +       return EXT_CONTINUE;
93 +}
94 +
95 +static int
96 +ext3_ext_collect_stats_cb(struct ext3_extents_tree *tree,
97 +                       struct ext3_ext_path *path,
98 +                       struct ext3_extent *ex, int exist)
99 +{
100 +       struct ext3_extent_tree_stats *buf =
101 +               (struct ext3_extent_tree_stats *) tree->private;
102 +       int depth;
103 +
104 +       if (!exist)
105 +               return EXT_CONTINUE;
106 +
107 +       depth = EXT_DEPTH(tree);
108 +       buf->extents_num++;
109 +       if (path[depth].p_ext == EXT_FIRST_EXTENT(path[depth].p_hdr))
110 +               buf->leaf_num++;
111 +       return EXT_CONTINUE;
112 +}
113 +
114 +struct ea_tree_desc {
115 +       int name_index;
116 +       char eaname[256];
117 +};
118 +
119 +int ext3_ext_in_ea_ioctl(struct inode *inode, struct file *filp,
120 +                               unsigned int cmd, unsigned long arg)
121 +{
122 +       int err = 0;
123 +
124 +       if (cmd == EXT3_IOC_EA_TREE_INIT) {
125 +               struct ea_tree_desc desc;
126 +
127 +               if (copy_from_user(&desc, (void *) arg, sizeof(desc)))
128 +                       return -EFAULT;
129 +               err = ext3_init_tree_in_ea(inode, desc.name_index,
130 +                                               desc.eaname, 64);
131 +       } else if (cmd == EXT3_IOC_GET_EA_EXTENTS) {
132 +               struct ext3_extents_tree tree;
133 +               struct ext3_extent_buf buf;
134 +               struct ea_tree_desc desc;
135 +
136 +               if (copy_from_user(&buf, (void *) arg, sizeof(buf)))
137 +                       return -EFAULT;
138 +               if (copy_from_user(&desc, buf.cur, sizeof(desc)))
139 +                       return -EFAULT;
140 +               err = ext3_init_tree_in_ea_desc(&tree, inode,
141 +                                               desc.name_index, desc.eaname);
142 +               if (err)
143 +                       goto out;
144 +               buf.cur = buf.buffer;
145 +               buf.err = 0;
146 +               tree.private = &buf;
147 +               err = ext3_ext_walk_space(&tree, buf.start, EXT_MAX_BLOCK,
148 +                                               ext3_ext_store_extent_cb);
149 +               if (err == 0)
150 +                       err = buf.err;
151 +               ext3_release_tree_in_ea_desc(&tree);
152 +       } else if (cmd == EXT3_IOC_EA_TREE_ALLOCATE) {
153 +               struct ext3_extent_buf buf;
154 +               struct ea_tree_desc desc;
155 +
156 +               if (copy_from_user(&buf, (void *) arg, sizeof(buf)))
157 +                       return -EFAULT;
158 +               if (copy_from_user(&desc, buf.cur, sizeof(desc)))
159 +                       return -EFAULT;
160 +               err = ext3_ext_in_ea_alloc_space(inode, desc.name_index,
161 +                                               desc.eaname, buf.start,
162 +                                               buf.err);
163 +       } else if (cmd == EXT3_IOC_EA_TREE_REMOVE) {
164 +               struct ext3_extent_buf buf;
165 +               struct ea_tree_desc desc;
166 +
167 +               if (copy_from_user(&buf, (void *) arg, sizeof(buf)))
168 +                       return -EFAULT;
169 +               if (copy_from_user(&desc, buf.cur, sizeof(desc)))
170 +                       return -EFAULT;
171 +               err = ext3_ext_in_ea_remove_space(inode, desc.name_index,
172 +                                               desc.eaname, buf.start,
173 +                                               buf.err);
174 +       }
175 +
176 +out:
177 +       return err;
178 +}
179 +
180 Index: linux-2.6.10/fs/ext3/ioctl.c
181 ===================================================================
182 --- linux-2.6.10.orig/fs/ext3/ioctl.c   2005-03-31 19:41:09.365510320 +0800
183 +++ linux-2.6.10/fs/ext3/ioctl.c        2005-03-31 19:41:09.580477640 +0800
184 @@ -249,7 +249,13 @@
185         case EXT3_IOC_GET_TREE_STATS:
186         case EXT3_IOC_GET_TREE_DEPTH:
187                 return ext3_ext_ioctl(inode, filp, cmd, arg);
188 -
189 +       case EXT3_IOC_GET_EA_EXTENTS:
190 +       case EXT3_IOC_GET_EA_TREE_DEPTH:
191 +       case EXT3_IOC_GET_EA_TREE_STATS:
192 +       case EXT3_IOC_EA_TREE_INIT:
193 +       case EXT3_IOC_EA_TREE_ALLOCATE:
194 +       case EXT3_IOC_EA_TREE_REMOVE:
195 +               return ext3_ext_in_ea_ioctl(inode, filp, cmd, arg);
196         default:
197                 return -ENOTTY;
198         }
199 Index: linux-2.6.10/include/linux/ext3_fs.h
200 ===================================================================
201 --- linux-2.6.10.orig/include/linux/ext3_fs.h   2005-03-31 19:41:09.366510168 +0800
202 +++ linux-2.6.10/include/linux/ext3_fs.h        2005-03-31 19:43:30.539048680 +0800
203 @@ -242,6 +242,15 @@
204  #define        EXT3_IOC_GET_EXTENTS            _IOR('f', 10, long)
205  #define        EXT3_IOC_GET_TREE_DEPTH         _IOR('f', 11, long)
206  #define        EXT3_IOC_GET_TREE_STATS         _IOR('f', 12, long)
207 +
208 +#define        EXT3_IOC_GET_EA_EXTENTS         _IOR('f', 13, long)
209 +#define        EXT3_IOC_GET_EA_TREE_DEPTH      _IOR('f', 14, long)
210 +#define        EXT3_IOC_GET_EA_TREE_STATS      _IOR('f', 15, long)
211 +#define        EXT3_IOC_EA_TREE_INIT           _IOW('f', 16, long)
212 +#define        EXT3_IOC_EA_TREE_ALLOCATE       _IOW('f', 17, long)
213 +#define        EXT3_IOC_EA_TREE_REMOVE         _IOW('f', 18, long)
214 +
215 +
216  /*
217   * Structure of an inode on the disk
218   */
219 @@ -788,7 +797,10 @@
220  /* ioctl.c */
221  extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
222                        unsigned long);
223 -
224 +extern int ext3_ext_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
225 +                         unsigned long arg);
226 +extern int ext3_ext_in_ea_ioctl(struct inode *inode, struct file *filp,
227 +                               unsigned int cmd, unsigned long arg);
228  /* namei.c */
229  extern int ext3_orphan_add(handle_t *, struct inode *);
230  extern int ext3_orphan_del(handle_t *, struct inode *);