blob: 2ada6e10d07b873b126bb894c903ed5fd29b6ca3 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Bob Peterson0d0868b2007-12-11 18:51:25 -06003 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
10/*
11 * Quota change tags are associated with each transaction that allocates or
12 * deallocates space. Those changes are accumulated locally to each node (in a
13 * per-node file) and then are periodically synced to the quota file. This
14 * avoids the bottleneck of constantly touching the quota file, but introduces
15 * fuzziness in the current usage value of IDs that are being used on different
16 * nodes in the cluster simultaneously. So, it is possible for a user on
17 * multiple nodes to overrun their quota, but that overrun is controlable.
18 * Since quota tags are part of transactions, there is no need to a quota check
19 * program to be run on node crashes or anything like that.
20 *
21 * There are couple of knobs that let the administrator manage the quota
22 * fuzziness. "quota_quantum" sets the maximum time a quota change can be
23 * sitting on one node before being synced to the quota file. (The default is
24 * 60 seconds.) Another knob, "quota_scale" controls how quickly the frequency
25 * of quota file syncs increases as the user moves closer to their limit. The
26 * more frequent the syncs, the more accurate the quota enforcement, but that
27 * means that there is more contention between the nodes for the quota file.
28 * The default value is one. This sets the maximum theoretical quota overrun
29 * (with infinite node with infinite bandwidth) to twice the user's limit. (In
30 * practice, the maximum overrun you see should be much less.) A "quota_scale"
31 * number greater than one makes quota syncs more frequent and reduces the
32 * maximum overrun. Numbers less than one (but greater than zero) make quota
33 * syncs less frequent.
34 *
35 * GFS quotas also use per-ID Lock Value Blocks (LVBs) to cache the contents of
36 * the quota file, so it is not being constantly read.
37 */
38
39#include <linux/sched.h>
40#include <linux/slab.h>
41#include <linux/spinlock.h>
42#include <linux/completion.h>
43#include <linux/buffer_head.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000044#include <linux/sort.h>
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000045#include <linux/fs.h>
Steven Whitehouse2e565bb2006-10-02 11:38:25 -040046#include <linux/bio.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050047#include <linux/gfs2_ondisk.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020048#include <linux/lm_interface.h>
Steven Whitehouse37b2c832008-11-17 14:25:37 +000049#include <linux/kthread.h>
50#include <linux/freezer.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000051
52#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050053#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000054#include "bmap.h"
55#include "glock.h"
56#include "glops.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000057#include "log.h"
58#include "meta_io.h"
59#include "quota.h"
60#include "rgrp.h"
61#include "super.h"
62#include "trans.h"
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000063#include "inode.h"
Steven Whitehouse18ec7d52006-02-08 11:50:51 +000064#include "ops_address.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050065#include "util.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000066
67#define QUOTA_USER 1
68#define QUOTA_GROUP 0
69
Steven Whitehousebb8d8a62007-06-01 14:11:58 +010070struct gfs2_quota_host {
71 u64 qu_limit;
72 u64 qu_warn;
73 s64 qu_value;
Abhijith Das2d9a4bb2007-08-15 11:25:05 -050074 u32 qu_ll_next;
Steven Whitehousebb8d8a62007-06-01 14:11:58 +010075};
76
77struct gfs2_quota_change_host {
78 u64 qc_change;
79 u32 qc_flags; /* GFS2_QCF_... */
80 u32 qc_id;
81};
82
Abhijith Das0a7ab792009-01-07 16:03:37 -060083static LIST_HEAD(qd_lru_list);
84static atomic_t qd_lru_count = ATOMIC_INIT(0);
85static spinlock_t qd_lru_lock = SPIN_LOCK_UNLOCKED;
86
87int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask)
88{
89 struct gfs2_quota_data *qd;
90 struct gfs2_sbd *sdp;
91
92 if (nr == 0)
93 goto out;
94
95 if (!(gfp_mask & __GFP_FS))
96 return -1;
97
98 spin_lock(&qd_lru_lock);
99 while (nr && !list_empty(&qd_lru_list)) {
100 qd = list_entry(qd_lru_list.next,
101 struct gfs2_quota_data, qd_reclaim);
102 sdp = qd->qd_gl->gl_sbd;
103
104 /* Free from the filesystem-specific list */
105 list_del(&qd->qd_list);
106
107 spin_lock(&sdp->sd_quota_spin);
108 gfs2_assert_warn(sdp, !qd->qd_change);
109 gfs2_assert_warn(sdp, !qd->qd_slot_count);
110 gfs2_assert_warn(sdp, !qd->qd_bh_count);
111
112 gfs2_lvb_unhold(qd->qd_gl);
113 spin_unlock(&sdp->sd_quota_spin);
114 atomic_dec(&sdp->sd_quota_count);
115
116 /* Delete it from the common reclaim list */
117 list_del_init(&qd->qd_reclaim);
118 atomic_dec(&qd_lru_count);
119 spin_unlock(&qd_lru_lock);
120 kmem_cache_free(gfs2_quotad_cachep, qd);
121 spin_lock(&qd_lru_lock);
122 nr--;
123 }
124 spin_unlock(&qd_lru_lock);
125
126out:
127 return (atomic_read(&qd_lru_count) * sysctl_vfs_cache_pressure) / 100;
128}
129
Steven Whitehousecd915492006-09-04 12:49:07 -0400130static u64 qd2offset(struct gfs2_quota_data *qd)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000131{
Steven Whitehousecd915492006-09-04 12:49:07 -0400132 u64 offset;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000133
Steven Whitehousecd915492006-09-04 12:49:07 -0400134 offset = 2 * (u64)qd->qd_id + !test_bit(QDF_USER, &qd->qd_flags);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000135 offset *= sizeof(struct gfs2_quota);
136
137 return offset;
138}
139
Steven Whitehousecd915492006-09-04 12:49:07 -0400140static int qd_alloc(struct gfs2_sbd *sdp, int user, u32 id,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000141 struct gfs2_quota_data **qdp)
142{
143 struct gfs2_quota_data *qd;
144 int error;
145
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000146 qd = kmem_cache_zalloc(gfs2_quotad_cachep, GFP_NOFS);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000147 if (!qd)
148 return -ENOMEM;
149
Abhijith Das0a7ab792009-01-07 16:03:37 -0600150 atomic_set(&qd->qd_count, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000151 qd->qd_id = id;
152 if (user)
153 set_bit(QDF_USER, &qd->qd_flags);
154 qd->qd_slot = -1;
Abhijith Das0a7ab792009-01-07 16:03:37 -0600155 INIT_LIST_HEAD(&qd->qd_reclaim);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000156
Steven Whitehousecd915492006-09-04 12:49:07 -0400157 error = gfs2_glock_get(sdp, 2 * (u64)id + !user,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000158 &gfs2_quota_glops, CREATE, &qd->qd_gl);
159 if (error)
160 goto fail;
161
162 error = gfs2_lvb_hold(qd->qd_gl);
163 gfs2_glock_put(qd->qd_gl);
164 if (error)
165 goto fail;
166
167 *qdp = qd;
168
169 return 0;
170
Steven Whitehousea91ea692006-09-04 12:04:26 -0400171fail:
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000172 kmem_cache_free(gfs2_quotad_cachep, qd);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000173 return error;
174}
175
Steven Whitehousecd915492006-09-04 12:49:07 -0400176static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000177 struct gfs2_quota_data **qdp)
178{
179 struct gfs2_quota_data *qd = NULL, *new_qd = NULL;
180 int error, found;
181
182 *qdp = NULL;
183
184 for (;;) {
185 found = 0;
Abhijith Das0a7ab792009-01-07 16:03:37 -0600186 spin_lock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000187 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
188 if (qd->qd_id == id &&
189 !test_bit(QDF_USER, &qd->qd_flags) == !user) {
Abhijith Das0a7ab792009-01-07 16:03:37 -0600190 if (!atomic_read(&qd->qd_count) &&
191 !list_empty(&qd->qd_reclaim)) {
192 /* Remove it from reclaim list */
193 list_del_init(&qd->qd_reclaim);
194 atomic_dec(&qd_lru_count);
195 }
196 atomic_inc(&qd->qd_count);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000197 found = 1;
198 break;
199 }
200 }
201
202 if (!found)
203 qd = NULL;
204
205 if (!qd && new_qd) {
206 qd = new_qd;
207 list_add(&qd->qd_list, &sdp->sd_quota_list);
208 atomic_inc(&sdp->sd_quota_count);
209 new_qd = NULL;
210 }
211
Abhijith Das0a7ab792009-01-07 16:03:37 -0600212 spin_unlock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000213
214 if (qd || !create) {
215 if (new_qd) {
216 gfs2_lvb_unhold(new_qd->qd_gl);
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000217 kmem_cache_free(gfs2_quotad_cachep, new_qd);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000218 }
219 *qdp = qd;
220 return 0;
221 }
222
223 error = qd_alloc(sdp, user, id, &new_qd);
224 if (error)
225 return error;
226 }
227}
228
229static void qd_hold(struct gfs2_quota_data *qd)
230{
231 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
Abhijith Das0a7ab792009-01-07 16:03:37 -0600232 gfs2_assert(sdp, atomic_read(&qd->qd_count));
233 atomic_inc(&qd->qd_count);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000234}
235
236static void qd_put(struct gfs2_quota_data *qd)
237{
Abhijith Das0a7ab792009-01-07 16:03:37 -0600238 if (atomic_dec_and_lock(&qd->qd_count, &qd_lru_lock)) {
239 /* Add to the reclaim list */
240 list_add_tail(&qd->qd_reclaim, &qd_lru_list);
241 atomic_inc(&qd_lru_count);
242 spin_unlock(&qd_lru_lock);
243 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000244}
245
246static int slot_get(struct gfs2_quota_data *qd)
247{
248 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
249 unsigned int c, o = 0, b;
250 unsigned char byte = 0;
251
252 spin_lock(&sdp->sd_quota_spin);
253
254 if (qd->qd_slot_count++) {
255 spin_unlock(&sdp->sd_quota_spin);
256 return 0;
257 }
258
259 for (c = 0; c < sdp->sd_quota_chunks; c++)
260 for (o = 0; o < PAGE_SIZE; o++) {
261 byte = sdp->sd_quota_bitmap[c][o];
262 if (byte != 0xFF)
263 goto found;
264 }
265
266 goto fail;
267
Steven Whitehousea91ea692006-09-04 12:04:26 -0400268found:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000269 for (b = 0; b < 8; b++)
270 if (!(byte & (1 << b)))
271 break;
272 qd->qd_slot = c * (8 * PAGE_SIZE) + o * 8 + b;
273
274 if (qd->qd_slot >= sdp->sd_quota_slots)
275 goto fail;
276
277 sdp->sd_quota_bitmap[c][o] |= 1 << b;
278
279 spin_unlock(&sdp->sd_quota_spin);
280
281 return 0;
282
Steven Whitehousea91ea692006-09-04 12:04:26 -0400283fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000284 qd->qd_slot_count--;
285 spin_unlock(&sdp->sd_quota_spin);
286 return -ENOSPC;
287}
288
289static void slot_hold(struct gfs2_quota_data *qd)
290{
291 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
292
293 spin_lock(&sdp->sd_quota_spin);
294 gfs2_assert(sdp, qd->qd_slot_count);
295 qd->qd_slot_count++;
296 spin_unlock(&sdp->sd_quota_spin);
297}
298
299static void slot_put(struct gfs2_quota_data *qd)
300{
301 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
302
303 spin_lock(&sdp->sd_quota_spin);
304 gfs2_assert(sdp, qd->qd_slot_count);
305 if (!--qd->qd_slot_count) {
306 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0);
307 qd->qd_slot = -1;
308 }
309 spin_unlock(&sdp->sd_quota_spin);
310}
311
312static int bh_get(struct gfs2_quota_data *qd)
313{
314 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400315 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000316 unsigned int block, offset;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000317 struct buffer_head *bh;
318 int error;
Steven Whitehouse23591252006-10-13 17:25:45 -0400319 struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 };
David Teiglandb3b94fa2006-01-16 16:50:04 +0000320
Steven Whitehousef55ab262006-02-21 12:51:39 +0000321 mutex_lock(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000322
323 if (qd->qd_bh_count++) {
Steven Whitehousef55ab262006-02-21 12:51:39 +0000324 mutex_unlock(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000325 return 0;
326 }
327
328 block = qd->qd_slot / sdp->sd_qc_per_block;
Bob Peterson0d0868b2007-12-11 18:51:25 -0600329 offset = qd->qd_slot % sdp->sd_qc_per_block;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000330
Steven Whitehouse23591252006-10-13 17:25:45 -0400331 bh_map.b_size = 1 << ip->i_inode.i_blkbits;
Bob Petersone9e1ef22007-12-10 14:13:27 -0600332 error = gfs2_block_map(&ip->i_inode, block, &bh_map, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000333 if (error)
334 goto fail;
Steven Whitehouse7276b3b2006-09-21 17:05:23 -0400335 error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000336 if (error)
337 goto fail;
338 error = -EIO;
339 if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC))
340 goto fail_brelse;
341
342 qd->qd_bh = bh;
343 qd->qd_bh_qc = (struct gfs2_quota_change *)
344 (bh->b_data + sizeof(struct gfs2_meta_header) +
345 offset * sizeof(struct gfs2_quota_change));
346
Josef Whiter2e95b662007-02-20 00:03:29 -0500347 mutex_unlock(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000348
349 return 0;
350
Steven Whitehousea91ea692006-09-04 12:04:26 -0400351fail_brelse:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000352 brelse(bh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400353fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000354 qd->qd_bh_count--;
Steven Whitehousef55ab262006-02-21 12:51:39 +0000355 mutex_unlock(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000356 return error;
357}
358
359static void bh_put(struct gfs2_quota_data *qd)
360{
361 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
362
Steven Whitehousef55ab262006-02-21 12:51:39 +0000363 mutex_lock(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000364 gfs2_assert(sdp, qd->qd_bh_count);
365 if (!--qd->qd_bh_count) {
366 brelse(qd->qd_bh);
367 qd->qd_bh = NULL;
368 qd->qd_bh_qc = NULL;
369 }
Steven Whitehousef55ab262006-02-21 12:51:39 +0000370 mutex_unlock(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000371}
372
373static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
374{
375 struct gfs2_quota_data *qd = NULL;
376 int error;
377 int found = 0;
378
379 *qdp = NULL;
380
381 if (sdp->sd_vfs->s_flags & MS_RDONLY)
382 return 0;
383
Abhijith Das0a7ab792009-01-07 16:03:37 -0600384 spin_lock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000385 spin_lock(&sdp->sd_quota_spin);
386
387 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
388 if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
389 !test_bit(QDF_CHANGE, &qd->qd_flags) ||
390 qd->qd_sync_gen >= sdp->sd_quota_sync_gen)
391 continue;
392
393 list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
394
395 set_bit(QDF_LOCKED, &qd->qd_flags);
Abhijith Das0a7ab792009-01-07 16:03:37 -0600396 gfs2_assert_warn(sdp, atomic_read(&qd->qd_count));
397 atomic_inc(&qd->qd_count);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000398 qd->qd_change_sync = qd->qd_change;
399 gfs2_assert_warn(sdp, qd->qd_slot_count);
400 qd->qd_slot_count++;
401 found = 1;
402
403 break;
404 }
405
406 if (!found)
407 qd = NULL;
408
409 spin_unlock(&sdp->sd_quota_spin);
Abhijith Das0a7ab792009-01-07 16:03:37 -0600410 spin_unlock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000411
412 if (qd) {
413 gfs2_assert_warn(sdp, qd->qd_change_sync);
414 error = bh_get(qd);
415 if (error) {
416 clear_bit(QDF_LOCKED, &qd->qd_flags);
417 slot_put(qd);
418 qd_put(qd);
419 return error;
420 }
421 }
422
423 *qdp = qd;
424
425 return 0;
426}
427
428static int qd_trylock(struct gfs2_quota_data *qd)
429{
430 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
431
432 if (sdp->sd_vfs->s_flags & MS_RDONLY)
433 return 0;
434
Abhijith Das0a7ab792009-01-07 16:03:37 -0600435 spin_lock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000436 spin_lock(&sdp->sd_quota_spin);
437
438 if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
439 !test_bit(QDF_CHANGE, &qd->qd_flags)) {
440 spin_unlock(&sdp->sd_quota_spin);
Abhijith Das0a7ab792009-01-07 16:03:37 -0600441 spin_unlock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000442 return 0;
443 }
444
445 list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
446
447 set_bit(QDF_LOCKED, &qd->qd_flags);
Abhijith Das0a7ab792009-01-07 16:03:37 -0600448 gfs2_assert_warn(sdp, atomic_read(&qd->qd_count));
449 atomic_inc(&qd->qd_count);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000450 qd->qd_change_sync = qd->qd_change;
451 gfs2_assert_warn(sdp, qd->qd_slot_count);
452 qd->qd_slot_count++;
453
454 spin_unlock(&sdp->sd_quota_spin);
Abhijith Das0a7ab792009-01-07 16:03:37 -0600455 spin_unlock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000456
457 gfs2_assert_warn(sdp, qd->qd_change_sync);
458 if (bh_get(qd)) {
459 clear_bit(QDF_LOCKED, &qd->qd_flags);
460 slot_put(qd);
461 qd_put(qd);
462 return 0;
463 }
464
465 return 1;
466}
467
468static void qd_unlock(struct gfs2_quota_data *qd)
469{
Steven Whitehouse568f4c92006-02-27 12:00:42 -0500470 gfs2_assert_warn(qd->qd_gl->gl_sbd,
471 test_bit(QDF_LOCKED, &qd->qd_flags));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000472 clear_bit(QDF_LOCKED, &qd->qd_flags);
473 bh_put(qd);
474 slot_put(qd);
475 qd_put(qd);
476}
477
Steven Whitehousecd915492006-09-04 12:49:07 -0400478static int qdsb_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000479 struct gfs2_quota_data **qdp)
480{
481 int error;
482
483 error = qd_get(sdp, user, id, create, qdp);
484 if (error)
485 return error;
486
487 error = slot_get(*qdp);
488 if (error)
489 goto fail;
490
491 error = bh_get(*qdp);
492 if (error)
493 goto fail_slot;
494
495 return 0;
496
Steven Whitehousea91ea692006-09-04 12:04:26 -0400497fail_slot:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000498 slot_put(*qdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400499fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000500 qd_put(*qdp);
501 return error;
502}
503
504static void qdsb_put(struct gfs2_quota_data *qd)
505{
506 bh_put(qd);
507 slot_put(qd);
508 qd_put(qd);
509}
510
Steven Whitehousecd915492006-09-04 12:49:07 -0400511int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000512{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400513 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +0000514 struct gfs2_alloc *al = ip->i_alloc;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000515 struct gfs2_quota_data **qd = al->al_qd;
516 int error;
517
518 if (gfs2_assert_warn(sdp, !al->al_qd_num) ||
519 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)))
520 return -EIO;
521
522 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF)
523 return 0;
524
Steven Whitehouse2933f922006-11-01 13:23:29 -0500525 error = qdsb_get(sdp, QUOTA_USER, ip->i_inode.i_uid, CREATE, qd);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000526 if (error)
527 goto out;
528 al->al_qd_num++;
529 qd++;
530
Steven Whitehouse2933f922006-11-01 13:23:29 -0500531 error = qdsb_get(sdp, QUOTA_GROUP, ip->i_inode.i_gid, CREATE, qd);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000532 if (error)
533 goto out;
534 al->al_qd_num++;
535 qd++;
536
Steven Whitehouse2933f922006-11-01 13:23:29 -0500537 if (uid != NO_QUOTA_CHANGE && uid != ip->i_inode.i_uid) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000538 error = qdsb_get(sdp, QUOTA_USER, uid, CREATE, qd);
539 if (error)
540 goto out;
541 al->al_qd_num++;
542 qd++;
543 }
544
Steven Whitehouse2933f922006-11-01 13:23:29 -0500545 if (gid != NO_QUOTA_CHANGE && gid != ip->i_inode.i_gid) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000546 error = qdsb_get(sdp, QUOTA_GROUP, gid, CREATE, qd);
547 if (error)
548 goto out;
549 al->al_qd_num++;
550 qd++;
551 }
552
Steven Whitehousea91ea692006-09-04 12:04:26 -0400553out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000554 if (error)
555 gfs2_quota_unhold(ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000556 return error;
557}
558
559void gfs2_quota_unhold(struct gfs2_inode *ip)
560{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400561 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +0000562 struct gfs2_alloc *al = ip->i_alloc;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000563 unsigned int x;
564
565 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags));
566
567 for (x = 0; x < al->al_qd_num; x++) {
568 qdsb_put(al->al_qd[x]);
569 al->al_qd[x] = NULL;
570 }
571 al->al_qd_num = 0;
572}
573
574static int sort_qd(const void *a, const void *b)
575{
Steven Whitehouse48fac172006-09-05 15:17:12 -0400576 const struct gfs2_quota_data *qd_a = *(const struct gfs2_quota_data **)a;
577 const struct gfs2_quota_data *qd_b = *(const struct gfs2_quota_data **)b;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000578
579 if (!test_bit(QDF_USER, &qd_a->qd_flags) !=
580 !test_bit(QDF_USER, &qd_b->qd_flags)) {
581 if (test_bit(QDF_USER, &qd_a->qd_flags))
Steven Whitehouse48fac172006-09-05 15:17:12 -0400582 return -1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000583 else
Steven Whitehouse48fac172006-09-05 15:17:12 -0400584 return 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000585 }
Steven Whitehouse48fac172006-09-05 15:17:12 -0400586 if (qd_a->qd_id < qd_b->qd_id)
587 return -1;
588 if (qd_a->qd_id > qd_b->qd_id)
589 return 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000590
Steven Whitehouse48fac172006-09-05 15:17:12 -0400591 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000592}
593
Steven Whitehousecd915492006-09-04 12:49:07 -0400594static void do_qc(struct gfs2_quota_data *qd, s64 change)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000595{
596 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400597 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000598 struct gfs2_quota_change *qc = qd->qd_bh_qc;
Steven Whitehousecd915492006-09-04 12:49:07 -0400599 s64 x;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000600
Steven Whitehousef55ab262006-02-21 12:51:39 +0000601 mutex_lock(&sdp->sd_quota_mutex);
Steven Whitehoused4e9c4c2006-01-18 11:19:28 +0000602 gfs2_trans_add_bh(ip->i_gl, qd->qd_bh, 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000603
604 if (!test_bit(QDF_CHANGE, &qd->qd_flags)) {
605 qc->qc_change = 0;
606 qc->qc_flags = 0;
607 if (test_bit(QDF_USER, &qd->qd_flags))
608 qc->qc_flags = cpu_to_be32(GFS2_QCF_USER);
609 qc->qc_id = cpu_to_be32(qd->qd_id);
610 }
611
Al Virob44b84d2006-10-14 10:46:30 -0400612 x = be64_to_cpu(qc->qc_change) + change;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000613 qc->qc_change = cpu_to_be64(x);
614
615 spin_lock(&sdp->sd_quota_spin);
616 qd->qd_change = x;
617 spin_unlock(&sdp->sd_quota_spin);
618
619 if (!x) {
620 gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags));
621 clear_bit(QDF_CHANGE, &qd->qd_flags);
622 qc->qc_flags = 0;
623 qc->qc_id = 0;
624 slot_put(qd);
625 qd_put(qd);
626 } else if (!test_and_set_bit(QDF_CHANGE, &qd->qd_flags)) {
627 qd_hold(qd);
628 slot_hold(qd);
629 }
Steven Whitehouse907b9bc2006-09-25 09:26:04 -0400630
Steven Whitehousef55ab262006-02-21 12:51:39 +0000631 mutex_unlock(&sdp->sd_quota_mutex);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000632}
633
Steven Whitehousebb8d8a62007-06-01 14:11:58 +0100634static void gfs2_quota_in(struct gfs2_quota_host *qu, const void *buf)
635{
636 const struct gfs2_quota *str = buf;
637
638 qu->qu_limit = be64_to_cpu(str->qu_limit);
639 qu->qu_warn = be64_to_cpu(str->qu_warn);
640 qu->qu_value = be64_to_cpu(str->qu_value);
Abhijith Das2d9a4bb2007-08-15 11:25:05 -0500641 qu->qu_ll_next = be32_to_cpu(str->qu_ll_next);
Steven Whitehousebb8d8a62007-06-01 14:11:58 +0100642}
643
644static void gfs2_quota_out(const struct gfs2_quota_host *qu, void *buf)
645{
646 struct gfs2_quota *str = buf;
647
648 str->qu_limit = cpu_to_be64(qu->qu_limit);
649 str->qu_warn = cpu_to_be64(qu->qu_warn);
650 str->qu_value = cpu_to_be64(qu->qu_value);
Abhijith Das2d9a4bb2007-08-15 11:25:05 -0500651 str->qu_ll_next = cpu_to_be32(qu->qu_ll_next);
Steven Whitehousebb8d8a62007-06-01 14:11:58 +0100652 memset(&str->qu_reserved, 0, sizeof(str->qu_reserved));
653}
654
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000655/**
656 * gfs2_adjust_quota
657 *
658 * This function was mostly borrowed from gfs2_block_truncate_page which was
659 * in turn mostly borrowed from ext3
660 */
661static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
Steven Whitehousecd915492006-09-04 12:49:07 -0400662 s64 change, struct gfs2_quota_data *qd)
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000663{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400664 struct inode *inode = &ip->i_inode;
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000665 struct address_space *mapping = inode->i_mapping;
666 unsigned long index = loc >> PAGE_CACHE_SHIFT;
Abhijith Das1990e912007-05-31 17:52:02 -0500667 unsigned offset = loc & (PAGE_CACHE_SIZE - 1);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000668 unsigned blocksize, iblock, pos;
669 struct buffer_head *bh;
670 struct page *page;
671 void *kaddr;
Abhijith Das1990e912007-05-31 17:52:02 -0500672 char *ptr;
673 struct gfs2_quota_host qp;
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400674 s64 value;
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000675 int err = -EIO;
676
Abhijith Das20b95bf2008-03-06 17:43:52 -0600677 if (gfs2_is_stuffed(ip))
Abhijith Das0fd53552007-08-14 15:34:58 -0500678 gfs2_unstuff_dinode(ip, NULL);
Abhijith Das20b95bf2008-03-06 17:43:52 -0600679
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000680 page = grab_cache_page(mapping, index);
681 if (!page)
682 return -ENOMEM;
683
684 blocksize = inode->i_sb->s_blocksize;
685 iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
686
687 if (!page_has_buffers(page))
688 create_empty_buffers(page, blocksize, 0);
689
690 bh = page_buffers(page);
691 pos = blocksize;
692 while (offset >= pos) {
693 bh = bh->b_this_page;
694 iblock++;
695 pos += blocksize;
696 }
697
698 if (!buffer_mapped(bh)) {
Bob Petersone9e1ef22007-12-10 14:13:27 -0600699 gfs2_block_map(inode, iblock, bh, 1);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000700 if (!buffer_mapped(bh))
701 goto unlock;
702 }
703
704 if (PageUptodate(page))
705 set_buffer_uptodate(bh);
706
707 if (!buffer_uptodate(bh)) {
Steven Whitehouse2e565bb2006-10-02 11:38:25 -0400708 ll_rw_block(READ_META, 1, &bh);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000709 wait_on_buffer(bh);
710 if (!buffer_uptodate(bh))
711 goto unlock;
712 }
713
714 gfs2_trans_add_bh(ip->i_gl, bh, 0);
715
716 kaddr = kmap_atomic(page, KM_USER0);
Steven Whitehouse48fac172006-09-05 15:17:12 -0400717 ptr = kaddr + offset;
Abhijith Das1990e912007-05-31 17:52:02 -0500718 gfs2_quota_in(&qp, ptr);
719 qp.qu_value += change;
720 value = qp.qu_value;
721 gfs2_quota_out(&qp, ptr);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000722 flush_dcache_page(page);
723 kunmap_atomic(kaddr, KM_USER0);
724 err = 0;
725 qd->qd_qb.qb_magic = cpu_to_be32(GFS2_MAGIC);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000726 qd->qd_qb.qb_value = cpu_to_be64(value);
Abhijith Das2a87ab02007-05-16 17:02:19 -0500727 ((struct gfs2_quota_lvb*)(qd->qd_gl->gl_lvb))->qb_magic = cpu_to_be32(GFS2_MAGIC);
728 ((struct gfs2_quota_lvb*)(qd->qd_gl->gl_lvb))->qb_value = cpu_to_be64(value);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000729unlock:
730 unlock_page(page);
731 page_cache_release(page);
732 return err;
733}
734
David Teiglandb3b94fa2006-01-16 16:50:04 +0000735static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
736{
737 struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400738 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000739 unsigned int data_blocks, ind_blocks;
740 struct gfs2_holder *ghs, i_gh;
741 unsigned int qx, x;
742 struct gfs2_quota_data *qd;
Steven Whitehousef42faf42006-01-30 18:34:10 +0000743 loff_t offset;
Abhijith Das20b95bf2008-03-06 17:43:52 -0600744 unsigned int nalloc = 0, blocks;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000745 struct gfs2_alloc *al = NULL;
746 int error;
747
748 gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota),
749 &data_blocks, &ind_blocks);
750
Josef Bacik16c5f062008-04-09 09:33:41 -0400751 ghs = kcalloc(num_qd, sizeof(struct gfs2_holder), GFP_NOFS);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000752 if (!ghs)
753 return -ENOMEM;
754
755 sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL);
756 for (qx = 0; qx < num_qd; qx++) {
757 error = gfs2_glock_nq_init(qda[qx]->qd_gl,
758 LM_ST_EXCLUSIVE,
759 GL_NOCACHE, &ghs[qx]);
760 if (error)
761 goto out;
762 }
763
764 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
765 if (error)
766 goto out;
767
768 for (x = 0; x < num_qd; x++) {
769 int alloc_required;
770
771 offset = qd2offset(qda[x]);
772 error = gfs2_write_alloc_required(ip, offset,
773 sizeof(struct gfs2_quota),
774 &alloc_required);
775 if (error)
776 goto out_gunlock;
777 if (alloc_required)
778 nalloc++;
779 }
780
Abhijith Das20b95bf2008-03-06 17:43:52 -0600781 al = gfs2_alloc_get(ip);
782 if (!al) {
783 error = -ENOMEM;
784 goto out_gunlock;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000785 }
Abhijith Das20b95bf2008-03-06 17:43:52 -0600786 /*
787 * 1 blk for unstuffing inode if stuffed. We add this extra
788 * block to the reservation unconditionally. If the inode
789 * doesn't need unstuffing, the block will be released to the
790 * rgrp since it won't be allocated during the transaction
791 */
792 al->al_requested = 1;
793 /* +1 in the end for block requested above for unstuffing */
794 blocks = num_qd * data_blocks + RES_DINODE + num_qd + 1;
795
796 if (nalloc)
797 al->al_requested += nalloc * (data_blocks + ind_blocks);
798 error = gfs2_inplace_reserve(ip);
799 if (error)
800 goto out_alloc;
801
802 if (nalloc)
803 blocks += al->al_rgd->rd_length + nalloc * ind_blocks + RES_STATFS;
804
805 error = gfs2_trans_begin(sdp, blocks, 0);
806 if (error)
807 goto out_ipres;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000808
809 for (x = 0; x < num_qd; x++) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000810 qd = qda[x];
811 offset = qd2offset(qd);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000812 error = gfs2_adjust_quota(ip, offset, qd->qd_change_sync,
Steven Whitehouse568f4c92006-02-27 12:00:42 -0500813 (struct gfs2_quota_data *)
Abhijith Das2a87ab02007-05-16 17:02:19 -0500814 qd);
Steven Whitehouse18ec7d52006-02-08 11:50:51 +0000815 if (error)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000816 goto out_end_trans;
817
David Teiglandb3b94fa2006-01-16 16:50:04 +0000818 do_qc(qd, -qd->qd_change_sync);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000819 }
820
821 error = 0;
822
Steven Whitehousea91ea692006-09-04 12:04:26 -0400823out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000824 gfs2_trans_end(sdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400825out_ipres:
Abhijith Das20b95bf2008-03-06 17:43:52 -0600826 gfs2_inplace_release(ip);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400827out_alloc:
Abhijith Das20b95bf2008-03-06 17:43:52 -0600828 gfs2_alloc_put(ip);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400829out_gunlock:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000830 gfs2_glock_dq_uninit(&i_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400831out:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000832 while (qx--)
833 gfs2_glock_dq_uninit(&ghs[qx]);
834 kfree(ghs);
Steven Whitehouseb09e5932006-04-07 11:17:32 -0400835 gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000836 return error;
837}
838
839static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
840 struct gfs2_holder *q_gh)
841{
842 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400843 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000844 struct gfs2_holder i_gh;
Al Virob5bc9e82006-10-13 23:31:55 -0400845 struct gfs2_quota_host q;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000846 char buf[sizeof(struct gfs2_quota)];
847 int error;
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400848 struct gfs2_quota_lvb *qlvb;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000849
Steven Whitehousea91ea692006-09-04 12:04:26 -0400850restart:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000851 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh);
852 if (error)
853 return error;
854
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400855 qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000856
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400857 if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) {
Steven Whitehousef42faf42006-01-30 18:34:10 +0000858 loff_t pos;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000859 gfs2_glock_dq_uninit(q_gh);
860 error = gfs2_glock_nq_init(qd->qd_gl,
Abhijith Das0a7ab792009-01-07 16:03:37 -0600861 LM_ST_EXCLUSIVE, GL_NOCACHE,
862 q_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000863 if (error)
864 return error;
865
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400866 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000867 if (error)
868 goto fail;
869
870 memset(buf, 0, sizeof(struct gfs2_quota));
Steven Whitehousef42faf42006-01-30 18:34:10 +0000871 pos = qd2offset(qd);
Steven Whitehouse51ff87b2007-10-15 14:42:35 +0100872 error = gfs2_internal_read(ip, NULL, buf, &pos,
873 sizeof(struct gfs2_quota));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000874 if (error < 0)
875 goto fail_gunlock;
876
877 gfs2_glock_dq_uninit(&i_gh);
878
879 gfs2_quota_in(&q, buf);
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400880 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
881 qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC);
882 qlvb->__pad = 0;
883 qlvb->qb_limit = cpu_to_be64(q.qu_limit);
884 qlvb->qb_warn = cpu_to_be64(q.qu_warn);
885 qlvb->qb_value = cpu_to_be64(q.qu_value);
886 qd->qd_qb = *qlvb;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000887
888 if (gfs2_glock_is_blocking(qd->qd_gl)) {
889 gfs2_glock_dq_uninit(q_gh);
890 force_refresh = 0;
891 goto restart;
892 }
893 }
894
895 return 0;
896
Steven Whitehousea91ea692006-09-04 12:04:26 -0400897fail_gunlock:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000898 gfs2_glock_dq_uninit(&i_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -0400899fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000900 gfs2_glock_dq_uninit(q_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000901 return error;
902}
903
Steven Whitehousecd915492006-09-04 12:49:07 -0400904int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000905{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400906 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +0000907 struct gfs2_alloc *al = ip->i_alloc;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000908 unsigned int x;
909 int error = 0;
910
911 gfs2_quota_hold(ip, uid, gid);
912
913 if (capable(CAP_SYS_RESOURCE) ||
914 sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
915 return 0;
916
917 sort(al->al_qd, al->al_qd_num, sizeof(struct gfs2_quota_data *),
918 sort_qd, NULL);
919
920 for (x = 0; x < al->al_qd_num; x++) {
921 error = do_glock(al->al_qd[x], NO_FORCE, &al->al_qd_ghs[x]);
922 if (error)
923 break;
924 }
925
926 if (!error)
927 set_bit(GIF_QD_LOCKED, &ip->i_flags);
928 else {
929 while (x--)
930 gfs2_glock_dq_uninit(&al->al_qd_ghs[x]);
931 gfs2_quota_unhold(ip);
932 }
933
934 return error;
935}
936
937static int need_sync(struct gfs2_quota_data *qd)
938{
939 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
940 struct gfs2_tune *gt = &sdp->sd_tune;
Steven Whitehousecd915492006-09-04 12:49:07 -0400941 s64 value;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000942 unsigned int num, den;
943 int do_sync = 1;
944
945 if (!qd->qd_qb.qb_limit)
946 return 0;
947
948 spin_lock(&sdp->sd_quota_spin);
949 value = qd->qd_change;
950 spin_unlock(&sdp->sd_quota_spin);
951
952 spin_lock(&gt->gt_spin);
953 num = gt->gt_quota_scale_num;
954 den = gt->gt_quota_scale_den;
955 spin_unlock(&gt->gt_spin);
956
957 if (value < 0)
958 do_sync = 0;
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400959 else if ((s64)be64_to_cpu(qd->qd_qb.qb_value) >=
960 (s64)be64_to_cpu(qd->qd_qb.qb_limit))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000961 do_sync = 0;
962 else {
963 value *= gfs2_jindex_size(sdp) * num;
David Howells4abaca172008-07-11 14:39:56 +0100964 value = div_s64(value, den);
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -0400965 value += (s64)be64_to_cpu(qd->qd_qb.qb_value);
Steven Whitehousecd915492006-09-04 12:49:07 -0400966 if (value < (s64)be64_to_cpu(qd->qd_qb.qb_limit))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000967 do_sync = 0;
968 }
969
970 return do_sync;
971}
972
973void gfs2_quota_unlock(struct gfs2_inode *ip)
974{
Steven Whitehouse6dbd8222008-01-10 15:18:55 +0000975 struct gfs2_alloc *al = ip->i_alloc;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000976 struct gfs2_quota_data *qda[4];
977 unsigned int count = 0;
978 unsigned int x;
979
980 if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags))
981 goto out;
982
983 for (x = 0; x < al->al_qd_num; x++) {
984 struct gfs2_quota_data *qd;
985 int sync;
986
987 qd = al->al_qd[x];
988 sync = need_sync(qd);
989
990 gfs2_glock_dq_uninit(&al->al_qd_ghs[x]);
991
992 if (sync && qd_trylock(qd))
993 qda[count++] = qd;
994 }
995
996 if (count) {
997 do_sync(count, qda);
998 for (x = 0; x < count; x++)
999 qd_unlock(qda[x]);
1000 }
1001
Steven Whitehousea91ea692006-09-04 12:04:26 -04001002out:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001003 gfs2_quota_unhold(ip);
1004}
1005
1006#define MAX_LINE 256
1007
1008static int print_message(struct gfs2_quota_data *qd, char *type)
1009{
1010 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001011
Steven Whitehouse02630a12006-07-03 11:20:06 -04001012 printk(KERN_INFO "GFS2: fsid=%s: quota %s for %s %u\r\n",
1013 sdp->sd_fsname, type,
1014 (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group",
1015 qd->qd_id);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001016
1017 return 0;
1018}
1019
Steven Whitehousecd915492006-09-04 12:49:07 -04001020int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001021{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001022 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +00001023 struct gfs2_alloc *al = ip->i_alloc;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001024 struct gfs2_quota_data *qd;
Steven Whitehousecd915492006-09-04 12:49:07 -04001025 s64 value;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001026 unsigned int x;
1027 int error = 0;
1028
1029 if (!test_bit(GIF_QD_LOCKED, &ip->i_flags))
1030 return 0;
1031
1032 if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON)
1033 return 0;
1034
1035 for (x = 0; x < al->al_qd_num; x++) {
1036 qd = al->al_qd[x];
1037
1038 if (!((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1039 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))))
1040 continue;
1041
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04001042 value = (s64)be64_to_cpu(qd->qd_qb.qb_value);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001043 spin_lock(&sdp->sd_quota_spin);
1044 value += qd->qd_change;
1045 spin_unlock(&sdp->sd_quota_spin);
1046
Steven Whitehousecd915492006-09-04 12:49:07 -04001047 if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001048 print_message(qd, "exceeded");
1049 error = -EDQUOT;
1050 break;
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04001051 } else if (be64_to_cpu(qd->qd_qb.qb_warn) &&
Steven Whitehousecd915492006-09-04 12:49:07 -04001052 (s64)be64_to_cpu(qd->qd_qb.qb_warn) < value &&
David Teiglandb3b94fa2006-01-16 16:50:04 +00001053 time_after_eq(jiffies, qd->qd_last_warn +
Steven Whitehouse568f4c92006-02-27 12:00:42 -05001054 gfs2_tune_get(sdp,
1055 gt_quota_warn_period) * HZ)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001056 error = print_message(qd, "warning");
1057 qd->qd_last_warn = jiffies;
1058 }
1059 }
1060
1061 return error;
1062}
1063
Steven Whitehousecd915492006-09-04 12:49:07 -04001064void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1065 u32 uid, u32 gid)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001066{
Steven Whitehouse6dbd8222008-01-10 15:18:55 +00001067 struct gfs2_alloc *al = ip->i_alloc;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001068 struct gfs2_quota_data *qd;
1069 unsigned int x;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001070
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001071 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change))
David Teiglandb3b94fa2006-01-16 16:50:04 +00001072 return;
Steven Whitehouse383f01f2008-11-04 10:05:22 +00001073 if (ip->i_diskflags & GFS2_DIF_SYSTEM)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001074 return;
1075
1076 for (x = 0; x < al->al_qd_num; x++) {
1077 qd = al->al_qd[x];
1078
1079 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1080 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) {
1081 do_qc(qd, change);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001082 }
1083 }
1084}
1085
1086int gfs2_quota_sync(struct gfs2_sbd *sdp)
1087{
1088 struct gfs2_quota_data **qda;
1089 unsigned int max_qd = gfs2_tune_get(sdp, gt_quota_simul_sync);
1090 unsigned int num_qd;
1091 unsigned int x;
1092 int error = 0;
1093
1094 sdp->sd_quota_sync_gen++;
1095
1096 qda = kcalloc(max_qd, sizeof(struct gfs2_quota_data *), GFP_KERNEL);
1097 if (!qda)
1098 return -ENOMEM;
1099
1100 do {
1101 num_qd = 0;
1102
1103 for (;;) {
1104 error = qd_fish(sdp, qda + num_qd);
1105 if (error || !qda[num_qd])
1106 break;
1107 if (++num_qd == max_qd)
1108 break;
1109 }
1110
1111 if (num_qd) {
1112 if (!error)
1113 error = do_sync(num_qd, qda);
1114 if (!error)
1115 for (x = 0; x < num_qd; x++)
1116 qda[x]->qd_sync_gen =
1117 sdp->sd_quota_sync_gen;
1118
1119 for (x = 0; x < num_qd; x++)
1120 qd_unlock(qda[x]);
1121 }
1122 } while (!error && num_qd == max_qd);
1123
1124 kfree(qda);
1125
1126 return error;
1127}
1128
Steven Whitehousecd915492006-09-04 12:49:07 -04001129int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001130{
1131 struct gfs2_quota_data *qd;
1132 struct gfs2_holder q_gh;
1133 int error;
1134
1135 error = qd_get(sdp, user, id, CREATE, &qd);
1136 if (error)
1137 return error;
1138
1139 error = do_glock(qd, FORCE, &q_gh);
1140 if (!error)
1141 gfs2_glock_dq_uninit(&q_gh);
1142
1143 qd_put(qd);
1144
1145 return error;
1146}
1147
Steven Whitehousebb8d8a62007-06-01 14:11:58 +01001148static void gfs2_quota_change_in(struct gfs2_quota_change_host *qc, const void *buf)
1149{
1150 const struct gfs2_quota_change *str = buf;
1151
1152 qc->qc_change = be64_to_cpu(str->qc_change);
1153 qc->qc_flags = be32_to_cpu(str->qc_flags);
1154 qc->qc_id = be32_to_cpu(str->qc_id);
1155}
1156
David Teiglandb3b94fa2006-01-16 16:50:04 +00001157int gfs2_quota_init(struct gfs2_sbd *sdp)
1158{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001159 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
Steven Whitehousec9e98882008-11-04 09:47:33 +00001160 unsigned int blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001161 unsigned int x, slot = 0;
1162 unsigned int found = 0;
Steven Whitehousecd915492006-09-04 12:49:07 -04001163 u64 dblock;
1164 u32 extlen = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001165 int error;
1166
Steven Whitehousec9e98882008-11-04 09:47:33 +00001167 if (!ip->i_disksize || ip->i_disksize > (64 << 20) ||
1168 ip->i_disksize & (sdp->sd_sb.sb_bsize - 1)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001169 gfs2_consist_inode(ip);
Steven Whitehouse907b9bc2006-09-25 09:26:04 -04001170 return -EIO;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001171 }
1172 sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block;
Steven Whitehouse5c676f62006-02-27 17:23:27 -05001173 sdp->sd_quota_chunks = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * PAGE_SIZE);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001174
1175 error = -ENOMEM;
1176
1177 sdp->sd_quota_bitmap = kcalloc(sdp->sd_quota_chunks,
Josef Bacik16c5f062008-04-09 09:33:41 -04001178 sizeof(unsigned char *), GFP_NOFS);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001179 if (!sdp->sd_quota_bitmap)
1180 return error;
1181
1182 for (x = 0; x < sdp->sd_quota_chunks; x++) {
Josef Bacik16c5f062008-04-09 09:33:41 -04001183 sdp->sd_quota_bitmap[x] = kzalloc(PAGE_SIZE, GFP_NOFS);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001184 if (!sdp->sd_quota_bitmap[x])
1185 goto fail;
1186 }
1187
1188 for (x = 0; x < blocks; x++) {
1189 struct buffer_head *bh;
1190 unsigned int y;
1191
1192 if (!extlen) {
1193 int new = 0;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001194 error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001195 if (error)
1196 goto fail;
1197 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001198 error = -EIO;
Steven Whitehouse7276b3b2006-09-21 17:05:23 -04001199 bh = gfs2_meta_ra(ip->i_gl, dblock, extlen);
1200 if (!bh)
1201 goto fail;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001202 if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) {
1203 brelse(bh);
1204 goto fail;
1205 }
1206
Steven Whitehouse7276b3b2006-09-21 17:05:23 -04001207 for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001208 y++, slot++) {
Al Virob62f9632006-10-13 23:46:46 -04001209 struct gfs2_quota_change_host qc;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001210 struct gfs2_quota_data *qd;
1211
1212 gfs2_quota_change_in(&qc, bh->b_data +
1213 sizeof(struct gfs2_meta_header) +
1214 y * sizeof(struct gfs2_quota_change));
1215 if (!qc.qc_change)
1216 continue;
1217
1218 error = qd_alloc(sdp, (qc.qc_flags & GFS2_QCF_USER),
1219 qc.qc_id, &qd);
1220 if (error) {
1221 brelse(bh);
1222 goto fail;
1223 }
1224
1225 set_bit(QDF_CHANGE, &qd->qd_flags);
1226 qd->qd_change = qc.qc_change;
1227 qd->qd_slot = slot;
1228 qd->qd_slot_count = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001229
Abhijith Das0a7ab792009-01-07 16:03:37 -06001230 spin_lock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001231 spin_lock(&sdp->sd_quota_spin);
1232 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1);
Abhijith Das0a7ab792009-01-07 16:03:37 -06001233 spin_unlock(&sdp->sd_quota_spin);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001234 list_add(&qd->qd_list, &sdp->sd_quota_list);
1235 atomic_inc(&sdp->sd_quota_count);
Abhijith Das0a7ab792009-01-07 16:03:37 -06001236 spin_unlock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001237
1238 found++;
1239 }
1240
1241 brelse(bh);
1242 dblock++;
1243 extlen--;
1244 }
1245
1246 if (found)
1247 fs_info(sdp, "found %u quota changes\n", found);
1248
1249 return 0;
1250
Steven Whitehousea91ea692006-09-04 12:04:26 -04001251fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001252 gfs2_quota_cleanup(sdp);
1253 return error;
1254}
1255
David Teiglandb3b94fa2006-01-16 16:50:04 +00001256void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
1257{
1258 struct list_head *head = &sdp->sd_quota_list;
1259 struct gfs2_quota_data *qd;
1260 unsigned int x;
1261
Abhijith Das0a7ab792009-01-07 16:03:37 -06001262 spin_lock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001263 while (!list_empty(head)) {
1264 qd = list_entry(head->prev, struct gfs2_quota_data, qd_list);
1265
Abhijith Das0a7ab792009-01-07 16:03:37 -06001266 spin_lock(&sdp->sd_quota_spin);
1267 if (atomic_read(&qd->qd_count) > 1 ||
1268 (atomic_read(&qd->qd_count) &&
1269 !test_bit(QDF_CHANGE, &qd->qd_flags))) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001270 spin_unlock(&sdp->sd_quota_spin);
Abhijith Das0a7ab792009-01-07 16:03:37 -06001271 list_move(&qd->qd_list, head);
1272 spin_unlock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001273 schedule();
Abhijith Das0a7ab792009-01-07 16:03:37 -06001274 spin_lock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001275 continue;
1276 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001277 spin_unlock(&sdp->sd_quota_spin);
1278
Abhijith Das0a7ab792009-01-07 16:03:37 -06001279 list_del(&qd->qd_list);
1280 /* Also remove if this qd exists in the reclaim list */
1281 if (!list_empty(&qd->qd_reclaim)) {
1282 list_del_init(&qd->qd_reclaim);
1283 atomic_dec(&qd_lru_count);
1284 }
1285 atomic_dec(&sdp->sd_quota_count);
1286 spin_unlock(&qd_lru_lock);
1287
1288 if (!atomic_read(&qd->qd_count)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001289 gfs2_assert_warn(sdp, !qd->qd_change);
1290 gfs2_assert_warn(sdp, !qd->qd_slot_count);
1291 } else
1292 gfs2_assert_warn(sdp, qd->qd_slot_count == 1);
1293 gfs2_assert_warn(sdp, !qd->qd_bh_count);
1294
1295 gfs2_lvb_unhold(qd->qd_gl);
Steven Whitehouse37b2c832008-11-17 14:25:37 +00001296 kmem_cache_free(gfs2_quotad_cachep, qd);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001297
Abhijith Das0a7ab792009-01-07 16:03:37 -06001298 spin_lock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001299 }
Abhijith Das0a7ab792009-01-07 16:03:37 -06001300 spin_unlock(&qd_lru_lock);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001301
1302 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count));
1303
1304 if (sdp->sd_quota_bitmap) {
1305 for (x = 0; x < sdp->sd_quota_chunks; x++)
1306 kfree(sdp->sd_quota_bitmap[x]);
1307 kfree(sdp->sd_quota_bitmap);
1308 }
1309}
1310
Steven Whitehouse37b2c832008-11-17 14:25:37 +00001311static void quotad_error(struct gfs2_sbd *sdp, const char *msg, int error)
1312{
1313 if (error == 0 || error == -EROFS)
1314 return;
1315 if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
1316 fs_err(sdp, "gfs2_quotad: %s error %d\n", msg, error);
1317}
1318
1319static void quotad_check_timeo(struct gfs2_sbd *sdp, const char *msg,
1320 int (*fxn)(struct gfs2_sbd *sdp),
1321 unsigned long t, unsigned long *timeo,
1322 unsigned int *new_timeo)
1323{
1324 if (t >= *timeo) {
1325 int error = fxn(sdp);
1326 quotad_error(sdp, msg, error);
1327 *timeo = gfs2_tune_get_i(&sdp->sd_tune, new_timeo) * HZ;
1328 } else {
1329 *timeo -= t;
1330 }
1331}
1332
Steven Whitehouse813e0c42008-11-18 13:38:48 +00001333static void quotad_check_trunc_list(struct gfs2_sbd *sdp)
1334{
1335 struct gfs2_inode *ip;
1336
1337 while(1) {
1338 ip = NULL;
1339 spin_lock(&sdp->sd_trunc_lock);
1340 if (!list_empty(&sdp->sd_trunc_list)) {
1341 ip = list_entry(sdp->sd_trunc_list.next,
1342 struct gfs2_inode, i_trunc_list);
1343 list_del_init(&ip->i_trunc_list);
1344 }
1345 spin_unlock(&sdp->sd_trunc_lock);
1346 if (ip == NULL)
1347 return;
1348 gfs2_glock_finish_truncate(ip);
1349 }
1350}
1351
Steven Whitehouse37b2c832008-11-17 14:25:37 +00001352/**
1353 * gfs2_quotad - Write cached quota changes into the quota file
1354 * @sdp: Pointer to GFS2 superblock
1355 *
1356 */
1357
1358int gfs2_quotad(void *data)
1359{
1360 struct gfs2_sbd *sdp = data;
1361 struct gfs2_tune *tune = &sdp->sd_tune;
1362 unsigned long statfs_timeo = 0;
1363 unsigned long quotad_timeo = 0;
1364 unsigned long t = 0;
1365 DEFINE_WAIT(wait);
Steven Whitehouse813e0c42008-11-18 13:38:48 +00001366 int empty;
Steven Whitehouse37b2c832008-11-17 14:25:37 +00001367
1368 while (!kthread_should_stop()) {
1369
1370 /* Update the master statfs file */
1371 quotad_check_timeo(sdp, "statfs", gfs2_statfs_sync, t,
1372 &statfs_timeo, &tune->gt_statfs_quantum);
1373
1374 /* Update quota file */
1375 quotad_check_timeo(sdp, "sync", gfs2_quota_sync, t,
1376 &quotad_timeo, &tune->gt_quota_quantum);
1377
Steven Whitehouse813e0c42008-11-18 13:38:48 +00001378 /* Check for & recover partially truncated inodes */
1379 quotad_check_trunc_list(sdp);
1380
Steven Whitehouse37b2c832008-11-17 14:25:37 +00001381 if (freezing(current))
1382 refrigerator();
1383 t = min(quotad_timeo, statfs_timeo);
1384
1385 prepare_to_wait(&sdp->sd_quota_wait, &wait, TASK_UNINTERRUPTIBLE);
Steven Whitehouse813e0c42008-11-18 13:38:48 +00001386 spin_lock(&sdp->sd_trunc_lock);
1387 empty = list_empty(&sdp->sd_trunc_list);
1388 spin_unlock(&sdp->sd_trunc_lock);
1389 if (empty)
1390 t -= schedule_timeout(t);
1391 else
1392 t = 0;
Steven Whitehouse37b2c832008-11-17 14:25:37 +00001393 finish_wait(&sdp->sd_quota_wait, &wait);
1394 }
1395
1396 return 0;
1397}
1398