Whamcloud - gitweb
LU-3427 build: fix 'error handling' issues
[fs/lustre-release.git] / lustre / kernel_patches / patches / replace_dqptr_sem-sles11.patch
1 diff -urp linux-2.6.32.46-0.orig/fs/quota/dquot.c linux-2.6.32.46-0/fs/quota/dquot.c
2 --- linux-2.6.32.46-0.orig/fs/quota/dquot.c     2013-04-26 11:56:35.000000000 -0400
3 +++ linux-2.6.32.46-0/fs/quota/dquot.c  2013-04-26 12:00:44.000000000 -0400
4 @@ -89,22 +89,17 @@
5  /*
6   * There are three quota SMP locks. dq_list_lock protects all lists with quotas
7   * and quota formats, dqstats structure containing statistics about the lists
8 - * dq_data_lock protects data from dq_dqb and also mem_dqinfo structures and
9 - * also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
10 - * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly
11 - * in inode_add_bytes() and inode_sub_bytes(). dq_state_lock protects
12 - * modifications of quota state (on quotaon and quotaoff) and readers who care
13 - * about latest values take it as well.
14 + * dq_data_lock protects data from dq_dqb and also mem_dqinfo structures.
15 + * dq_state_lock protects modifications of quota state (on quotaon and quotaoff)
16 + * and readers who care about latest values take it as well.
17   *
18 - * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock,
19 + * The spinlock ordering is hence: i_lock > dq_data_lock > dq_list_lock,
20   *   dq_list_lock > dq_state_lock
21   *
22   * Note that some things (eg. sb pointer, type, id) doesn't change during
23   * the life of the dquot structure and so needn't to be protected by a lock
24   *
25 - * Any operation working on dquots via inode pointers must hold dqptr_sem.  If
26 - * operation is just reading pointers from inode (or not using them at all) the
27 - * read lock is enough. If pointers are altered function must hold write lock
28 + * Any operation working on dquots via inode pointers must hold i_lock.
29   * (these locking rules also apply for S_NOQUOTA flag in the inode - note that
30   * for altering the flag i_mutex is also needed).
31   *
32 @@ -118,15 +113,8 @@
33   * spinlock to internal buffers before writing.
34   *
35   * Lock ordering (including related VFS locks) is the following:
36 - *   i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock >
37 - *   dqio_mutex
38 - * The lock ordering of dqptr_sem imposed by quota code is only dqonoff_sem >
39 - * dqptr_sem. But filesystem has to count with the fact that functions such as
40 - * dquot_alloc_space() acquire dqptr_sem and they usually have to be called
41 - * from inside a transaction to keep filesystem consistency after a crash. Also
42 - * filesystems usually want to do some IO on dquot from ->mark_dirty which is
43 - * called with dqptr_sem held.
44 - * i_mutex on quota files is special (it's below dqio_mutex)
45 + *  i_mutex > dqonoff_sem > journal_lock > dquot->dq_lock > dqio_mutex
46 + *  i_mutex on quota files is special (it's below dqio_mutex)
47   */
48  
49  static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_list_lock);
50 @@ -867,7 +855,6 @@ static inline int dqput_blocks(struct dq
51  /*
52   * Remove references to dquots from inode and add dquot to list for freeing
53   * if we have the last referece to dquot
54 - * We can't race with anybody because we hold dqptr_sem for writing...
55   */
56  static int remove_inode_dquot_ref(struct inode *inode, int type,
57                                   struct list_head *tofree_head)
58 @@ -925,10 +912,12 @@ static void remove_dquot_ref(struct supe
59                  *  We have to scan also I_NEW inodes because they can already
60                  *  have quota pointer initialized. Luckily, we need to touch
61                  *  only quota pointers and these have separate locking
62 -                *  (dqptr_sem).
63 +                *  (i_lock).
64                  */
65 +               spin_lock(&inode->i_lock);
66                 if (!IS_NOQUOTA(inode))
67                         remove_inode_dquot_ref(inode, type, tofree_head);
68 +               spin_unlock(&inode->i_lock);
69         }
70         spin_unlock(&inode_lock);
71  }
72 @@ -939,9 +928,7 @@ static void drop_dquot_ref(struct super_
73         LIST_HEAD(tofree_head);
74  
75         if (sb->dq_op) {
76 -               down_write(&sb_dqopt(sb)->dqptr_sem);
77                 remove_dquot_ref(sb, type, &tofree_head);
78 -               up_write(&sb_dqopt(sb)->dqptr_sem);
79                 put_dquot_list(&tofree_head);
80         }
81  }
82 @@ -1303,8 +1290,6 @@ static int info_bdq_free(struct dquot *d
83  
84  /*
85   *     Initialize quota pointers in inode
86 - *     We do things in a bit complicated way but by that we avoid calling
87 - *     dqget() and thus filesystem callbacks under dqptr_sem.
88   */
89  int dquot_initialize(struct inode *inode, int type)
90  {
91 @@ -1334,8 +1319,7 @@ int dquot_initialize(struct inode *inode
92                 got[cnt] = dqget(sb, id, cnt);
93         }
94  
95 -       down_write(&sb_dqopt(sb)->dqptr_sem);
96 -       /* Having dqptr_sem we know NOQUOTA flags can't be altered... */
97 +       spin_lock(&inode->i_lock);
98         if (IS_NOQUOTA(inode))
99                 goto out_err;
100         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
101 @@ -1352,12 +1336,16 @@ int dquot_initialize(struct inode *inode
102                          * did a write before quota was turned on
103                          */
104                         rsv = inode_get_rsv_space(inode);
105 -                       if (unlikely(rsv))
106 +                       if (unlikely(rsv)) {
107 +                               spin_lock(&dq_data_lock);
108                                 dquot_resv_space(inode->i_dquot[cnt], rsv);
109 +                               spin_unlock(&dq_data_lock);
110 +                       }
111                 }
112         }
113  out_err:
114 -       up_write(&sb_dqopt(sb)->dqptr_sem);
115 +       spin_unlock(&inode->i_lock);
116 +
117         /* Drop unused references */
118         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
119                 dqput(got[cnt]);
120 @@ -1373,12 +1361,12 @@ int dquot_drop(struct inode *inode)
121         int cnt;
122         struct dquot *put[MAXQUOTAS];
123  
124 -       down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
125 +       spin_lock(&inode->i_lock);
126         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
127                 put[cnt] = inode->i_dquot[cnt];
128                 inode->i_dquot[cnt] = NULL;
129         }
130 -       up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
131 +       spin_unlock(&inode->i_lock);
132  
133         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
134                 dqput(put[cnt]);
135 @@ -1421,27 +1409,42 @@ static qsize_t *inode_reserved_space(str
136         return inode->i_sb->dq_op->get_reserved_space(inode);
137  }
138  
139 +static inline void __inode_add_rsv_space(struct inode *inode, qsize_t number)
140 +{
141 +       *inode_reserved_space(inode) += number;
142 +}
143 +
144  void inode_add_rsv_space(struct inode *inode, qsize_t number)
145  {
146         spin_lock(&inode->i_lock);
147 -       *inode_reserved_space(inode) += number;
148 +       __inode_add_rsv_space(inode, number);
149         spin_unlock(&inode->i_lock);
150  }
151  EXPORT_SYMBOL(inode_add_rsv_space);
152  
153 -void inode_claim_rsv_space(struct inode *inode, qsize_t number)
154 +static inline void __inode_claim_rsv_space(struct inode *inode, qsize_t number)
155  {
156 -       spin_lock(&inode->i_lock);
157         *inode_reserved_space(inode) -= number;
158         __inode_add_bytes(inode, number);
159 +}
160 +
161 +void inode_claim_rsv_space(struct inode *inode, qsize_t number)
162 +{
163 +       spin_lock(&inode->i_lock);
164 +       __inode_claim_rsv_space(inode, number);
165         spin_unlock(&inode->i_lock);
166  }
167  EXPORT_SYMBOL(inode_claim_rsv_space);
168  
169 +static inline void __inode_sub_rsv_space(struct inode *inode, qsize_t number)
170 +{
171 +       *inode_reserved_space(inode) -= number;
172 +}
173 +
174  void inode_sub_rsv_space(struct inode *inode, qsize_t number)
175  {
176         spin_lock(&inode->i_lock);
177 -       *inode_reserved_space(inode) -= number;
178 +       __inode_sub_rsv_space(inode, number);
179         spin_unlock(&inode->i_lock);
180  }
181  EXPORT_SYMBOL(inode_sub_rsv_space);
182 @@ -1452,9 +1455,8 @@ static qsize_t inode_get_rsv_space(struc
183  
184         if (!inode->i_sb->dq_op->get_reserved_space)
185                 return 0;
186 -       spin_lock(&inode->i_lock);
187 +
188         ret = *inode_reserved_space(inode);
189 -       spin_unlock(&inode->i_lock);
190         return ret;
191  }
192  
193 @@ -1462,17 +1464,17 @@ static void inode_incr_space(struct inod
194                                 int reserve)
195  {
196         if (reserve)
197 -               inode_add_rsv_space(inode, number);
198 +               __inode_add_rsv_space(inode, number);
199         else
200 -               inode_add_bytes(inode, number);
201 +               __inode_add_bytes(inode, number);
202  }
203  
204  static void inode_decr_space(struct inode *inode, qsize_t number, int reserve)
205  {
206         if (reserve)
207 -               inode_sub_rsv_space(inode, number);
208 +               __inode_sub_rsv_space(inode, number);
209         else
210 -               inode_sub_bytes(inode, number);
211 +               __inode_sub_bytes(inode, number);
212  }
213  
214  /*
215 @@ -1492,6 +1494,7 @@ int __dquot_alloc_space(struct inode *in
216  {
217         int cnt, ret = QUOTA_OK;
218         char warntype[MAXQUOTAS];
219 +       struct dquot *dquot[MAXQUOTAS] = { NULL };
220  
221         /*
222          * First test before acquiring mutex - solves deadlocks when we
223 @@ -1502,10 +1505,11 @@ int __dquot_alloc_space(struct inode *in
224                 goto out;
225         }
226  
227 -       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
228 +       spin_lock(&inode->i_lock);
229         if (IS_NOQUOTA(inode)) {
230                 inode_incr_space(inode, number, reserve);
231 -               goto out_unlock;
232 +               spin_unlock(&inode->i_lock);
233 +               goto out;
234         }
235  
236         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
237 @@ -1513,9 +1517,11 @@ int __dquot_alloc_space(struct inode *in
238  
239         spin_lock(&dq_data_lock);
240         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
241 -               if (!inode->i_dquot[cnt])
242 +               dquot[cnt] = inode->i_dquot[cnt];
243 +               if (!dquot[cnt])
244                         continue;
245 -               if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt)
246 +               atomic_inc(&dquot[cnt]->dq_count);
247 +               if (check_bdq(dquot[cnt], number, warn, warntype+cnt)
248                     == NO_QUOTA) {
249                         ret = NO_QUOTA;
250                         spin_unlock(&dq_data_lock);
251 @@ -1523,26 +1529,27 @@ int __dquot_alloc_space(struct inode *in
252                 }
253         }
254         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
255 -               if (!inode->i_dquot[cnt])
256 +               if (!dquot[cnt])
257                         continue;
258                 if (reserve)
259 -                       dquot_resv_space(inode->i_dquot[cnt], number);
260 +                       dquot_resv_space(dquot[cnt], number);
261                 else
262 -                       dquot_incr_space(inode->i_dquot[cnt], number);
263 +                       dquot_incr_space(dquot[cnt], number);
264         }
265         inode_incr_space(inode, number, reserve);
266         spin_unlock(&dq_data_lock);
267 +       spin_unlock(&inode->i_lock);
268  
269         if (reserve)
270                 goto out_flush_warn;
271         /* Dirtify all the dquots - this can block when journalling */
272         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
273 -               if (inode->i_dquot[cnt])
274 -                       mark_dquot_dirty(inode->i_dquot[cnt]);
275 +               if (dquot[cnt])
276 +                       mark_dquot_dirty(dquot[cnt]);
277  out_flush_warn:
278 -       flush_warnings(inode->i_dquot, warntype);
279 -out_unlock:
280 -       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
281 +       flush_warnings(dquot, warntype);
282 +       for (cnt = 0; cnt < MAXQUOTAS; cnt++)
283 +               dqput(dquot[cnt]);
284  out:
285         return ret;
286  }
287 @@ -1566,6 +1573,7 @@ int dquot_alloc_inode(const struct inode
288  {
289         int cnt, ret = NO_QUOTA;
290         char warntype[MAXQUOTAS];
291 +       struct dquot *dquot[MAXQUOTAS] = { NULL };
292  
293         /* First test before acquiring mutex - solves deadlocks when we
294           * re-enter the quota code and are already holding the mutex */
295 @@ -1573,35 +1581,41 @@ int dquot_alloc_inode(const struct inode
296                 return QUOTA_OK;
297         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
298                 warntype[cnt] = QUOTA_NL_NOWARN;
299 -       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
300 +
301 +       spin_lock(&((struct inode *)inode)->i_lock);
302         if (IS_NOQUOTA(inode)) {
303 -               up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
304 +               spin_unlock(&((struct inode *)inode)->i_lock);
305                 return QUOTA_OK;
306         }
307         spin_lock(&dq_data_lock);
308         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
309 -               if (!inode->i_dquot[cnt])
310 +               dquot[cnt] = inode->i_dquot[cnt];
311 +               if (!dquot[cnt])
312                         continue;
313 -               if (check_idq(inode->i_dquot[cnt], number, warntype+cnt)
314 +               atomic_inc(&dquot[cnt]->dq_count);
315 +               if (check_idq(dquot[cnt], number, warntype+cnt)
316                     == NO_QUOTA)
317                         goto warn_put_all;
318         }
319  
320         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
321 -               if (!inode->i_dquot[cnt])
322 +               if (!dquot[cnt])
323                         continue;
324 -               dquot_incr_inodes(inode->i_dquot[cnt], number);
325 +               dquot_incr_inodes(dquot[cnt], number);
326         }
327         ret = QUOTA_OK;
328  warn_put_all:
329         spin_unlock(&dq_data_lock);
330 +       spin_unlock(&((struct inode *)inode)->i_lock);
331 +
332         if (ret == QUOTA_OK)
333                 /* Dirtify all the dquots - this can block when journalling */
334                 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
335 -                       if (inode->i_dquot[cnt])
336 -                               mark_dquot_dirty(inode->i_dquot[cnt]);
337 -       flush_warnings(inode->i_dquot, warntype);
338 -       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
339 +                       if (dquot[cnt])
340 +                               mark_dquot_dirty(dquot[cnt]);
341 +       flush_warnings(dquot, warntype);
342 +       for (cnt = 0; cnt < MAXQUOTAS; cnt++)
343 +               dqput(dquot[cnt]);
344         return ret;
345  }
346  EXPORT_SYMBOL(dquot_alloc_inode);
347 @@ -1610,34 +1624,40 @@ int dquot_claim_space(struct inode *inod
348  {
349         int cnt;
350         int ret = QUOTA_OK;
351 +       struct dquot *dquot[MAXQUOTAS] = { NULL };
352  
353         if (IS_NOQUOTA(inode)) {
354                 inode_claim_rsv_space(inode, number);
355                 goto out;
356         }
357  
358 -       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
359 +       spin_lock(&inode->i_lock);
360         if (IS_NOQUOTA(inode))  {
361 -               up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
362 -               inode_claim_rsv_space(inode, number);
363 +               __inode_claim_rsv_space(inode, number);
364 +               spin_unlock(&inode->i_lock);
365                 goto out;
366         }
367  
368         spin_lock(&dq_data_lock);
369         /* Claim reserved quotas to allocated quotas */
370         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
371 -               if (inode->i_dquot[cnt])
372 -                       dquot_claim_reserved_space(inode->i_dquot[cnt],
373 -                                                       number);
374 +               dquot[cnt] = inode->i_dquot[cnt];
375 +               if (dquot[cnt]) {
376 +                       atomic_inc(&dquot[cnt]->dq_count);
377 +                       dquot_claim_reserved_space(dquot[cnt], number);
378 +               }
379         }
380         /* Update inode bytes */
381 -       inode_claim_rsv_space(inode, number);
382 +       __inode_claim_rsv_space(inode, number);
383         spin_unlock(&dq_data_lock);
384 +       spin_unlock(&inode->i_lock);
385 +
386         /* Dirtify all the dquots - this can block when journalling */
387         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
388 -               if (inode->i_dquot[cnt])
389 -                       mark_dquot_dirty(inode->i_dquot[cnt]);
390 -       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
391 +               if (dquot[cnt])
392 +                       mark_dquot_dirty(dquot[cnt]);
393 +       for (cnt = 0; cnt < MAXQUOTAS; cnt++)
394 +               dqput(dquot[cnt]);
395  out:
396         return ret;
397  }
398 @@ -1650,6 +1670,7 @@ int __dquot_free_space(struct inode *ino
399  {
400         unsigned int cnt;
401         char warntype[MAXQUOTAS];
402 +       struct dquot *dquot[MAXQUOTAS] = { NULL };
403  
404         /* First test before acquiring mutex - solves deadlocks when we
405           * re-enter the quota code and are already holding the mutex */
406 @@ -1659,34 +1680,37 @@ out_sub:
407                 return QUOTA_OK;
408         }
409  
410 -       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
411 -       /* Now recheck reliably when holding dqptr_sem */
412 +       spin_lock(&inode->i_lock);
413         if (IS_NOQUOTA(inode)) {
414 -               up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
415 +               spin_unlock(&inode->i_lock);
416                 goto out_sub;
417         }
418         spin_lock(&dq_data_lock);
419         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
420 -               if (!inode->i_dquot[cnt])
421 +               dquot[cnt] = inode->i_dquot[cnt];
422 +               if (!dquot[cnt])
423                         continue;
424 -               warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number);
425 +               atomic_inc(&dquot[cnt]->dq_count);
426 +               warntype[cnt] = info_bdq_free(dquot[cnt], number);
427                 if (reserve)
428 -                       dquot_free_reserved_space(inode->i_dquot[cnt], number);
429 +                       dquot_free_reserved_space(dquot[cnt], number);
430                 else
431 -                       dquot_decr_space(inode->i_dquot[cnt], number);
432 +                       dquot_decr_space(dquot[cnt], number);
433         }
434         inode_decr_space(inode, number, reserve);
435         spin_unlock(&dq_data_lock);
436 +       spin_unlock(&inode->i_lock);
437  
438         if (reserve)
439 -               goto out_unlock;
440 +               goto out;
441         /* Dirtify all the dquots - this can block when journalling */
442         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
443 -               if (inode->i_dquot[cnt])
444 -                       mark_dquot_dirty(inode->i_dquot[cnt]);
445 -out_unlock:
446 -       flush_warnings(inode->i_dquot, warntype);
447 -       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
448 +               if (dquot[cnt])
449 +                       mark_dquot_dirty(dquot[cnt]);
450 +out:
451 +       flush_warnings(dquot, warntype);
452 +       for (cnt = 0; cnt < MAXQUOTAS; cnt++)
453 +               dqput(dquot[cnt]);
454         return QUOTA_OK;
455  }
456  
457 @@ -1713,32 +1737,37 @@ int dquot_free_inode(const struct inode
458  {
459         unsigned int cnt;
460         char warntype[MAXQUOTAS];
461 +       struct dquot *dquot[MAXQUOTAS] = { NULL };
462  
463         /* First test before acquiring mutex - solves deadlocks when we
464           * re-enter the quota code and are already holding the mutex */
465         if (IS_NOQUOTA(inode))
466                 return QUOTA_OK;
467  
468 -       down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
469 -       /* Now recheck reliably when holding dqptr_sem */
470 +       spin_lock(&((struct inode *)inode)->i_lock);
471         if (IS_NOQUOTA(inode)) {
472 -               up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
473 +               spin_unlock(&((struct inode *)inode)->i_lock);
474                 return QUOTA_OK;
475         }
476         spin_lock(&dq_data_lock);
477         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
478 -               if (!inode->i_dquot[cnt])
479 +               dquot[cnt] = inode->i_dquot[cnt];
480 +               if (!dquot[cnt])
481                         continue;
482 -               warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number);
483 -               dquot_decr_inodes(inode->i_dquot[cnt], number);
484 +               atomic_inc(&dquot[cnt]->dq_count);
485 +               warntype[cnt] = info_idq_free(dquot[cnt], number);
486 +               dquot_decr_inodes(dquot[cnt], number);
487         }
488         spin_unlock(&dq_data_lock);
489 +       spin_unlock(&((struct inode *)inode)->i_lock);
490 +
491         /* Dirtify all the dquots - this can block when journalling */
492         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
493 -               if (inode->i_dquot[cnt])
494 -                       mark_dquot_dirty(inode->i_dquot[cnt]);
495 -       flush_warnings(inode->i_dquot, warntype);
496 -       up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
497 +               if (dquot[cnt])
498 +                       mark_dquot_dirty(dquot[cnt]);
499 +       flush_warnings(dquot, warntype);
500 +       for (cnt = 0; cnt < MAXQUOTAS; cnt++)
501 +               dqput(dquot[cnt]);
502         return QUOTA_OK;
503  }
504  EXPORT_SYMBOL(dquot_free_inode);
505 @@ -1778,14 +1807,13 @@ int dquot_transfer(struct inode *inode,
506                 transfer_to[GRPQUOTA] = dqget(inode->i_sb, iattr->ia_gid,
507                                               GRPQUOTA);
508  
509 -       down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
510 -       /* Now recheck reliably when holding dqptr_sem */
511 +       spin_lock(&inode->i_lock);
512         if (IS_NOQUOTA(inode)) {        /* File without quota accounting? */
513 -               up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
514 +               spin_unlock(&inode->i_lock);
515                 goto put_all;
516         }
517         spin_lock(&dq_data_lock);
518 -       cur_space = inode_get_bytes(inode);
519 +       cur_space = __inode_get_bytes(inode);
520         rsv_space = inode_get_rsv_space(inode);
521         space = cur_space + rsv_space;
522         /* Build the transfer_from list and check the limits */
523 @@ -1828,7 +1856,7 @@ int dquot_transfer(struct inode *inode,
524                 inode->i_dquot[cnt] = transfer_to[cnt];
525         }
526         spin_unlock(&dq_data_lock);
527 -       up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
528 +       spin_unlock(&inode->i_lock);
529  
530         /* Dirtify all the dquots - this can block when journalling */
531         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
532 @@ -1852,7 +1880,7 @@ put_all:
533         return ret;
534  over_quota:
535         spin_unlock(&dq_data_lock);
536 -       up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
537 +       spin_unlock(&inode->i_lock);
538         /* Clear dquot pointers we don't want to dqput() */
539         for (cnt = 0; cnt < MAXQUOTAS; cnt++)
540                 transfer_from[cnt] = NULL;
541 @@ -2104,13 +2132,13 @@ static int vfs_load_quota_inode(struct i
542                 /* We don't want quota and atime on quota files (deadlocks
543                  * possible) Also nobody should write to the file - we use
544                  * special IO operations which ignore the immutable bit. */
545 -               down_write(&dqopt->dqptr_sem);
546                 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
547 +               spin_lock(&inode->i_lock);
548                 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE |
549                                              S_NOQUOTA);
550                 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
551 +               spin_unlock(&inode->i_lock);
552                 mutex_unlock(&inode->i_mutex);
553 -               up_write(&dqopt->dqptr_sem);
554                 sb->dq_op->drop(inode);
555         }
556  
557 @@ -2147,14 +2175,14 @@ out_file_init:
558         iput(inode);
559  out_lock:
560         if (oldflags != -1) {
561 -               down_write(&dqopt->dqptr_sem);
562                 mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
563 +               spin_lock(&inode->i_lock);
564                 /* Set the flags back (in the case of accidental quotaon()
565                  * on a wrong file we don't want to mess up the flags) */
566                 inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE);
567                 inode->i_flags |= oldflags;
568 +               spin_unlock(&inode->i_lock);
569                 mutex_unlock(&inode->i_mutex);
570 -               up_write(&dqopt->dqptr_sem);
571         }
572         mutex_unlock(&dqopt->dqonoff_mutex);
573  out_fmt:
574 diff -urp linux-2.6.32.46-0.orig/fs/quota/quota.c linux-2.6.32.46-0/fs/quota/quota.c
575 --- linux-2.6.32.46-0.orig/fs/quota/quota.c     2009-12-02 22:51:21.000000000 -0500
576 +++ linux-2.6.32.46-0/fs/quota/quota.c  2013-04-26 11:59:22.000000000 -0400
577 @@ -255,13 +255,13 @@ static int do_quotactl(struct super_bloc
578                 case Q_GETFMT: {
579                         __u32 fmt;
580  
581 -                       down_read(&sb_dqopt(sb)->dqptr_sem);
582 +                       mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
583                         if (!sb_has_quota_active(sb, type)) {
584 -                               up_read(&sb_dqopt(sb)->dqptr_sem);
585 +                               mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
586                                 return -ESRCH;
587                         }
588                         fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
589 -                       up_read(&sb_dqopt(sb)->dqptr_sem);
590 +                       mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
591                         if (copy_to_user(addr, &fmt, sizeof(fmt)))
592                                 return -EFAULT;
593                         return 0;
594 diff -urp linux-2.6.32.46-0.orig/fs/stat.c linux-2.6.32.46-0/fs/stat.c
595 --- linux-2.6.32.46-0.orig/fs/stat.c    2013-04-26 11:56:28.000000000 -0400
596 +++ linux-2.6.32.46-0/fs/stat.c 2013-04-26 11:59:22.000000000 -0400
597 @@ -422,9 +422,8 @@ void inode_add_bytes(struct inode *inode
598  
599  EXPORT_SYMBOL(inode_add_bytes);
600  
601 -void inode_sub_bytes(struct inode *inode, loff_t bytes)
602 +void __inode_sub_bytes(struct inode *inode, loff_t bytes)
603  {
604 -       spin_lock(&inode->i_lock);
605         inode->i_blocks -= bytes >> 9;
606         bytes &= 511;
607         if (inode->i_bytes < bytes) {
608 @@ -432,17 +431,28 @@ void inode_sub_bytes(struct inode *inode
609                 inode->i_bytes += 512;
610         }
611         inode->i_bytes -= bytes;
612 +}
613 +
614 +void inode_sub_bytes(struct inode *inode, loff_t bytes)
615 +{
616 +       spin_lock(&inode->i_lock);
617 +       __inode_sub_bytes(inode, bytes);
618         spin_unlock(&inode->i_lock);
619  }
620  
621  EXPORT_SYMBOL(inode_sub_bytes);
622  
623 +loff_t __inode_get_bytes(struct inode *inode)
624 +{
625 +       return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
626 +}
627 +
628  loff_t inode_get_bytes(struct inode *inode)
629  {
630         loff_t ret;
631  
632         spin_lock(&inode->i_lock);
633 -       ret = (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
634 +       ret = __inode_get_bytes(inode);
635         spin_unlock(&inode->i_lock);
636         return ret;
637  }
638 diff -urp linux-2.6.32.46-0.orig/fs/super.c linux-2.6.32.46-0/fs/super.c
639 --- linux-2.6.32.46-0.orig/fs/super.c   2013-04-26 11:56:52.000000000 -0400
640 +++ linux-2.6.32.46-0/fs/super.c        2013-04-26 11:59:22.000000000 -0400
641 @@ -98,7 +98,6 @@ static struct super_block *alloc_super(s
642                 mutex_init(&s->s_vfs_rename_mutex);
643                 mutex_init(&s->s_dquot.dqio_mutex);
644                 mutex_init(&s->s_dquot.dqonoff_mutex);
645 -               init_rwsem(&s->s_dquot.dqptr_sem);
646                 init_waitqueue_head(&s->s_wait_unfrozen);
647                 s->s_maxbytes = MAX_NON_LFS;
648                 s->dq_op = sb_dquot_ops;
649 diff -urp linux-2.6.32.46-0.orig/include/linux/fs.h linux-2.6.32.46-0/include/linux/fs.h
650 --- linux-2.6.32.46-0.orig/include/linux/fs.h   2013-04-26 11:56:52.000000000 -0400
651 +++ linux-2.6.32.46-0/include/linux/fs.h        2013-04-26 11:59:22.000000000 -0400
652 @@ -2356,7 +2356,9 @@ extern void generic_fillattr(struct inod
653  extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
654  void __inode_add_bytes(struct inode *inode, loff_t bytes);
655  void inode_add_bytes(struct inode *inode, loff_t bytes);
656 +void __inode_sub_bytes(struct inode *inode, loff_t bytes);
657  void inode_sub_bytes(struct inode *inode, loff_t bytes);
658 +loff_t __inode_get_bytes(struct inode *inode);
659  loff_t inode_get_bytes(struct inode *inode);
660  void inode_set_bytes(struct inode *inode, loff_t bytes);
661