David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Bob Peterson | 0d0868b | 2007-12-11 18:51:25 -0600 | [diff] [blame] | 3 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 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 Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 44 | #include <linux/sort.h> |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 45 | #include <linux/fs.h> |
Steven Whitehouse | 2e565bb | 2006-10-02 11:38:25 -0400 | [diff] [blame] | 46 | #include <linux/bio.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 47 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 48 | #include <linux/lm_interface.h> |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 49 | #include <linux/kthread.h> |
| 50 | #include <linux/freezer.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 51 | |
| 52 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 53 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 54 | #include "bmap.h" |
| 55 | #include "glock.h" |
| 56 | #include "glops.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 57 | #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 Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 63 | #include "inode.h" |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 64 | #include "ops_address.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 65 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 66 | |
| 67 | #define QUOTA_USER 1 |
| 68 | #define QUOTA_GROUP 0 |
| 69 | |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 70 | struct gfs2_quota_host { |
| 71 | u64 qu_limit; |
| 72 | u64 qu_warn; |
| 73 | s64 qu_value; |
Abhijith Das | 2d9a4bb | 2007-08-15 11:25:05 -0500 | [diff] [blame] | 74 | u32 qu_ll_next; |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | struct gfs2_quota_change_host { |
| 78 | u64 qc_change; |
| 79 | u32 qc_flags; /* GFS2_QCF_... */ |
| 80 | u32 qc_id; |
| 81 | }; |
| 82 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 83 | static LIST_HEAD(qd_lru_list); |
| 84 | static atomic_t qd_lru_count = ATOMIC_INIT(0); |
| 85 | static spinlock_t qd_lru_lock = SPIN_LOCK_UNLOCKED; |
| 86 | |
| 87 | int 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 | |
| 126 | out: |
| 127 | return (atomic_read(&qd_lru_count) * sysctl_vfs_cache_pressure) / 100; |
| 128 | } |
| 129 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 130 | static u64 qd2offset(struct gfs2_quota_data *qd) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 131 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 132 | u64 offset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 133 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 134 | offset = 2 * (u64)qd->qd_id + !test_bit(QDF_USER, &qd->qd_flags); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 135 | offset *= sizeof(struct gfs2_quota); |
| 136 | |
| 137 | return offset; |
| 138 | } |
| 139 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 140 | static int qd_alloc(struct gfs2_sbd *sdp, int user, u32 id, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 141 | struct gfs2_quota_data **qdp) |
| 142 | { |
| 143 | struct gfs2_quota_data *qd; |
| 144 | int error; |
| 145 | |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 146 | qd = kmem_cache_zalloc(gfs2_quotad_cachep, GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 147 | if (!qd) |
| 148 | return -ENOMEM; |
| 149 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 150 | atomic_set(&qd->qd_count, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 151 | qd->qd_id = id; |
| 152 | if (user) |
| 153 | set_bit(QDF_USER, &qd->qd_flags); |
| 154 | qd->qd_slot = -1; |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 155 | INIT_LIST_HEAD(&qd->qd_reclaim); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 156 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 157 | error = gfs2_glock_get(sdp, 2 * (u64)id + !user, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 158 | &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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 171 | fail: |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 172 | kmem_cache_free(gfs2_quotad_cachep, qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 173 | return error; |
| 174 | } |
| 175 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 176 | static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 177 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 186 | spin_lock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 187 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 190 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 197 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 212 | spin_unlock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 213 | |
| 214 | if (qd || !create) { |
| 215 | if (new_qd) { |
| 216 | gfs2_lvb_unhold(new_qd->qd_gl); |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 217 | kmem_cache_free(gfs2_quotad_cachep, new_qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 218 | } |
| 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 | |
| 229 | static void qd_hold(struct gfs2_quota_data *qd) |
| 230 | { |
| 231 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 232 | gfs2_assert(sdp, atomic_read(&qd->qd_count)); |
| 233 | atomic_inc(&qd->qd_count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static void qd_put(struct gfs2_quota_data *qd) |
| 237 | { |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 238 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static 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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 268 | found: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 269 | 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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 283 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 284 | qd->qd_slot_count--; |
| 285 | spin_unlock(&sdp->sd_quota_spin); |
| 286 | return -ENOSPC; |
| 287 | } |
| 288 | |
| 289 | static 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 | |
| 299 | static 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 | |
| 312 | static int bh_get(struct gfs2_quota_data *qd) |
| 313 | { |
| 314 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 315 | struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 316 | unsigned int block, offset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 317 | struct buffer_head *bh; |
| 318 | int error; |
Steven Whitehouse | 2359125 | 2006-10-13 17:25:45 -0400 | [diff] [blame] | 319 | struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 }; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 320 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 321 | mutex_lock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 322 | |
| 323 | if (qd->qd_bh_count++) { |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 324 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | block = qd->qd_slot / sdp->sd_qc_per_block; |
Bob Peterson | 0d0868b | 2007-12-11 18:51:25 -0600 | [diff] [blame] | 329 | offset = qd->qd_slot % sdp->sd_qc_per_block; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 330 | |
Steven Whitehouse | 2359125 | 2006-10-13 17:25:45 -0400 | [diff] [blame] | 331 | bh_map.b_size = 1 << ip->i_inode.i_blkbits; |
Bob Peterson | e9e1ef2 | 2007-12-10 14:13:27 -0600 | [diff] [blame] | 332 | error = gfs2_block_map(&ip->i_inode, block, &bh_map, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 333 | if (error) |
| 334 | goto fail; |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 335 | error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 336 | 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 Whiter | 2e95b66 | 2007-02-20 00:03:29 -0500 | [diff] [blame] | 347 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 348 | |
| 349 | return 0; |
| 350 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 351 | fail_brelse: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 352 | brelse(bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 353 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 354 | qd->qd_bh_count--; |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 355 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 356 | return error; |
| 357 | } |
| 358 | |
| 359 | static void bh_put(struct gfs2_quota_data *qd) |
| 360 | { |
| 361 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
| 362 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 363 | mutex_lock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 364 | 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 Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 370 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 384 | spin_lock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 385 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 396 | gfs2_assert_warn(sdp, atomic_read(&qd->qd_count)); |
| 397 | atomic_inc(&qd->qd_count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 398 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 410 | spin_unlock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 411 | |
| 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 | |
| 428 | static 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 435 | spin_lock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 436 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 441 | spin_unlock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 442 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 448 | gfs2_assert_warn(sdp, atomic_read(&qd->qd_count)); |
| 449 | atomic_inc(&qd->qd_count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 450 | 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 455 | spin_unlock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 456 | |
| 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 | |
| 468 | static void qd_unlock(struct gfs2_quota_data *qd) |
| 469 | { |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 470 | gfs2_assert_warn(qd->qd_gl->gl_sbd, |
| 471 | test_bit(QDF_LOCKED, &qd->qd_flags)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 472 | clear_bit(QDF_LOCKED, &qd->qd_flags); |
| 473 | bh_put(qd); |
| 474 | slot_put(qd); |
| 475 | qd_put(qd); |
| 476 | } |
| 477 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 478 | static int qdsb_get(struct gfs2_sbd *sdp, int user, u32 id, int create, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 479 | 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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 497 | fail_slot: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 498 | slot_put(*qdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 499 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 500 | qd_put(*qdp); |
| 501 | return error; |
| 502 | } |
| 503 | |
| 504 | static void qdsb_put(struct gfs2_quota_data *qd) |
| 505 | { |
| 506 | bh_put(qd); |
| 507 | slot_put(qd); |
| 508 | qd_put(qd); |
| 509 | } |
| 510 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 511 | int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 512 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 513 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 514 | struct gfs2_alloc *al = ip->i_alloc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 515 | 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 Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 525 | error = qdsb_get(sdp, QUOTA_USER, ip->i_inode.i_uid, CREATE, qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 526 | if (error) |
| 527 | goto out; |
| 528 | al->al_qd_num++; |
| 529 | qd++; |
| 530 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 531 | error = qdsb_get(sdp, QUOTA_GROUP, ip->i_inode.i_gid, CREATE, qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 532 | if (error) |
| 533 | goto out; |
| 534 | al->al_qd_num++; |
| 535 | qd++; |
| 536 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 537 | if (uid != NO_QUOTA_CHANGE && uid != ip->i_inode.i_uid) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 538 | 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 Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 545 | if (gid != NO_QUOTA_CHANGE && gid != ip->i_inode.i_gid) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 546 | 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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 553 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 554 | if (error) |
| 555 | gfs2_quota_unhold(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 556 | return error; |
| 557 | } |
| 558 | |
| 559 | void gfs2_quota_unhold(struct gfs2_inode *ip) |
| 560 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 561 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 562 | struct gfs2_alloc *al = ip->i_alloc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 563 | 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 | |
| 574 | static int sort_qd(const void *a, const void *b) |
| 575 | { |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 576 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 578 | |
| 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 Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 582 | return -1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 583 | else |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 584 | return 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 585 | } |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 586 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 590 | |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 591 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 594 | static void do_qc(struct gfs2_quota_data *qd, s64 change) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 595 | { |
| 596 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 597 | struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 598 | struct gfs2_quota_change *qc = qd->qd_bh_qc; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 599 | s64 x; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 600 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 601 | mutex_lock(&sdp->sd_quota_mutex); |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 602 | gfs2_trans_add_bh(ip->i_gl, qd->qd_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 603 | |
| 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 Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 612 | x = be64_to_cpu(qc->qc_change) + change; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 613 | 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 Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 630 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 631 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 634 | static 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 Das | 2d9a4bb | 2007-08-15 11:25:05 -0500 | [diff] [blame] | 641 | qu->qu_ll_next = be32_to_cpu(str->qu_ll_next); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | static 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 Das | 2d9a4bb | 2007-08-15 11:25:05 -0500 | [diff] [blame] | 651 | str->qu_ll_next = cpu_to_be32(qu->qu_ll_next); |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 652 | memset(&str->qu_reserved, 0, sizeof(str->qu_reserved)); |
| 653 | } |
| 654 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 655 | /** |
| 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 | */ |
| 661 | static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 662 | s64 change, struct gfs2_quota_data *qd) |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 663 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 664 | struct inode *inode = &ip->i_inode; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 665 | struct address_space *mapping = inode->i_mapping; |
| 666 | unsigned long index = loc >> PAGE_CACHE_SHIFT; |
Abhijith Das | 1990e91 | 2007-05-31 17:52:02 -0500 | [diff] [blame] | 667 | unsigned offset = loc & (PAGE_CACHE_SIZE - 1); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 668 | unsigned blocksize, iblock, pos; |
| 669 | struct buffer_head *bh; |
| 670 | struct page *page; |
| 671 | void *kaddr; |
Abhijith Das | 1990e91 | 2007-05-31 17:52:02 -0500 | [diff] [blame] | 672 | char *ptr; |
| 673 | struct gfs2_quota_host qp; |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 674 | s64 value; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 675 | int err = -EIO; |
| 676 | |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 677 | if (gfs2_is_stuffed(ip)) |
Abhijith Das | 0fd5355 | 2007-08-14 15:34:58 -0500 | [diff] [blame] | 678 | gfs2_unstuff_dinode(ip, NULL); |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 679 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 680 | 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 Peterson | e9e1ef2 | 2007-12-10 14:13:27 -0600 | [diff] [blame] | 699 | gfs2_block_map(inode, iblock, bh, 1); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 700 | 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 Whitehouse | 2e565bb | 2006-10-02 11:38:25 -0400 | [diff] [blame] | 708 | ll_rw_block(READ_META, 1, &bh); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 709 | 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 Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 717 | ptr = kaddr + offset; |
Abhijith Das | 1990e91 | 2007-05-31 17:52:02 -0500 | [diff] [blame] | 718 | gfs2_quota_in(&qp, ptr); |
| 719 | qp.qu_value += change; |
| 720 | value = qp.qu_value; |
| 721 | gfs2_quota_out(&qp, ptr); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 722 | 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 Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 726 | qd->qd_qb.qb_value = cpu_to_be64(value); |
Abhijith Das | 2a87ab0 | 2007-05-16 17:02:19 -0500 | [diff] [blame] | 727 | ((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 Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 729 | unlock: |
| 730 | unlock_page(page); |
| 731 | page_cache_release(page); |
| 732 | return err; |
| 733 | } |
| 734 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 735 | static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) |
| 736 | { |
| 737 | struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 738 | struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 739 | 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 Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 743 | loff_t offset; |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 744 | unsigned int nalloc = 0, blocks; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 745 | 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 Bacik | 16c5f06 | 2008-04-09 09:33:41 -0400 | [diff] [blame] | 751 | ghs = kcalloc(num_qd, sizeof(struct gfs2_holder), GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 752 | 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 Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 781 | al = gfs2_alloc_get(ip); |
| 782 | if (!al) { |
| 783 | error = -ENOMEM; |
| 784 | goto out_gunlock; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 785 | } |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 786 | /* |
| 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 808 | |
| 809 | for (x = 0; x < num_qd; x++) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 810 | qd = qda[x]; |
| 811 | offset = qd2offset(qd); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 812 | error = gfs2_adjust_quota(ip, offset, qd->qd_change_sync, |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 813 | (struct gfs2_quota_data *) |
Abhijith Das | 2a87ab0 | 2007-05-16 17:02:19 -0500 | [diff] [blame] | 814 | qd); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 815 | if (error) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 816 | goto out_end_trans; |
| 817 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 818 | do_qc(qd, -qd->qd_change_sync); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | error = 0; |
| 822 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 823 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 824 | gfs2_trans_end(sdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 825 | out_ipres: |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 826 | gfs2_inplace_release(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 827 | out_alloc: |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 828 | gfs2_alloc_put(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 829 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 830 | gfs2_glock_dq_uninit(&i_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 831 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 832 | while (qx--) |
| 833 | gfs2_glock_dq_uninit(&ghs[qx]); |
| 834 | kfree(ghs); |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 835 | gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 836 | return error; |
| 837 | } |
| 838 | |
| 839 | static 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 Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 843 | struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 844 | struct gfs2_holder i_gh; |
Al Viro | b5bc9e8 | 2006-10-13 23:31:55 -0400 | [diff] [blame] | 845 | struct gfs2_quota_host q; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 846 | char buf[sizeof(struct gfs2_quota)]; |
| 847 | int error; |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 848 | struct gfs2_quota_lvb *qlvb; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 849 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 850 | restart: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 851 | error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); |
| 852 | if (error) |
| 853 | return error; |
| 854 | |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 855 | qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 856 | |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 857 | if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) { |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 858 | loff_t pos; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 859 | gfs2_glock_dq_uninit(q_gh); |
| 860 | error = gfs2_glock_nq_init(qd->qd_gl, |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 861 | LM_ST_EXCLUSIVE, GL_NOCACHE, |
| 862 | q_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 863 | if (error) |
| 864 | return error; |
| 865 | |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 866 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 867 | if (error) |
| 868 | goto fail; |
| 869 | |
| 870 | memset(buf, 0, sizeof(struct gfs2_quota)); |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 871 | pos = qd2offset(qd); |
Steven Whitehouse | 51ff87b | 2007-10-15 14:42:35 +0100 | [diff] [blame] | 872 | error = gfs2_internal_read(ip, NULL, buf, &pos, |
| 873 | sizeof(struct gfs2_quota)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 874 | if (error < 0) |
| 875 | goto fail_gunlock; |
| 876 | |
| 877 | gfs2_glock_dq_uninit(&i_gh); |
| 878 | |
| 879 | gfs2_quota_in(&q, buf); |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 880 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 887 | |
| 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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 897 | fail_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 898 | gfs2_glock_dq_uninit(&i_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 899 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 900 | gfs2_glock_dq_uninit(q_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 901 | return error; |
| 902 | } |
| 903 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 904 | int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 905 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 906 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 907 | struct gfs2_alloc *al = ip->i_alloc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 908 | 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 | |
| 937 | static 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 Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 941 | s64 value; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 942 | 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_spin); |
| 953 | num = gt->gt_quota_scale_num; |
| 954 | den = gt->gt_quota_scale_den; |
| 955 | spin_unlock(>->gt_spin); |
| 956 | |
| 957 | if (value < 0) |
| 958 | do_sync = 0; |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 959 | else if ((s64)be64_to_cpu(qd->qd_qb.qb_value) >= |
| 960 | (s64)be64_to_cpu(qd->qd_qb.qb_limit)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 961 | do_sync = 0; |
| 962 | else { |
| 963 | value *= gfs2_jindex_size(sdp) * num; |
David Howells | 4abaca17 | 2008-07-11 14:39:56 +0100 | [diff] [blame] | 964 | value = div_s64(value, den); |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 965 | value += (s64)be64_to_cpu(qd->qd_qb.qb_value); |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 966 | if (value < (s64)be64_to_cpu(qd->qd_qb.qb_limit)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 967 | do_sync = 0; |
| 968 | } |
| 969 | |
| 970 | return do_sync; |
| 971 | } |
| 972 | |
| 973 | void gfs2_quota_unlock(struct gfs2_inode *ip) |
| 974 | { |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 975 | struct gfs2_alloc *al = ip->i_alloc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 976 | 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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1002 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1003 | gfs2_quota_unhold(ip); |
| 1004 | } |
| 1005 | |
| 1006 | #define MAX_LINE 256 |
| 1007 | |
| 1008 | static int print_message(struct gfs2_quota_data *qd, char *type) |
| 1009 | { |
| 1010 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1011 | |
Steven Whitehouse | 02630a1 | 2006-07-03 11:20:06 -0400 | [diff] [blame] | 1012 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1016 | |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1020 | int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1021 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1022 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 1023 | struct gfs2_alloc *al = ip->i_alloc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1024 | struct gfs2_quota_data *qd; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1025 | s64 value; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1026 | 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 Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 1042 | value = (s64)be64_to_cpu(qd->qd_qb.qb_value); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1043 | spin_lock(&sdp->sd_quota_spin); |
| 1044 | value += qd->qd_change; |
| 1045 | spin_unlock(&sdp->sd_quota_spin); |
| 1046 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1047 | if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1048 | print_message(qd, "exceeded"); |
| 1049 | error = -EDQUOT; |
| 1050 | break; |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 1051 | } else if (be64_to_cpu(qd->qd_qb.qb_warn) && |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1052 | (s64)be64_to_cpu(qd->qd_qb.qb_warn) < value && |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1053 | time_after_eq(jiffies, qd->qd_last_warn + |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 1054 | gfs2_tune_get(sdp, |
| 1055 | gt_quota_warn_period) * HZ)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1056 | error = print_message(qd, "warning"); |
| 1057 | qd->qd_last_warn = jiffies; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | return error; |
| 1062 | } |
| 1063 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1064 | void gfs2_quota_change(struct gfs2_inode *ip, s64 change, |
| 1065 | u32 uid, u32 gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1066 | { |
Steven Whitehouse | 6dbd822 | 2008-01-10 15:18:55 +0000 | [diff] [blame] | 1067 | struct gfs2_alloc *al = ip->i_alloc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1068 | struct gfs2_quota_data *qd; |
| 1069 | unsigned int x; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1070 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1071 | if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1072 | return; |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 1073 | if (ip->i_diskflags & GFS2_DIF_SYSTEM) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1074 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | int 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 Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1129 | int gfs2_quota_refresh(struct gfs2_sbd *sdp, int user, u32 id) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1130 | { |
| 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 Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 1148 | static 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1157 | int gfs2_quota_init(struct gfs2_sbd *sdp) |
| 1158 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1159 | struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 1160 | unsigned int blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1161 | unsigned int x, slot = 0; |
| 1162 | unsigned int found = 0; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1163 | u64 dblock; |
| 1164 | u32 extlen = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1165 | int error; |
| 1166 | |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 1167 | if (!ip->i_disksize || ip->i_disksize > (64 << 20) || |
| 1168 | ip->i_disksize & (sdp->sd_sb.sb_bsize - 1)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1169 | gfs2_consist_inode(ip); |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 1170 | return -EIO; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1171 | } |
| 1172 | sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 1173 | sdp->sd_quota_chunks = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * PAGE_SIZE); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1174 | |
| 1175 | error = -ENOMEM; |
| 1176 | |
| 1177 | sdp->sd_quota_bitmap = kcalloc(sdp->sd_quota_chunks, |
Josef Bacik | 16c5f06 | 2008-04-09 09:33:41 -0400 | [diff] [blame] | 1178 | sizeof(unsigned char *), GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1179 | if (!sdp->sd_quota_bitmap) |
| 1180 | return error; |
| 1181 | |
| 1182 | for (x = 0; x < sdp->sd_quota_chunks; x++) { |
Josef Bacik | 16c5f06 | 2008-04-09 09:33:41 -0400 | [diff] [blame] | 1183 | sdp->sd_quota_bitmap[x] = kzalloc(PAGE_SIZE, GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1184 | 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 Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1194 | error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1195 | if (error) |
| 1196 | goto fail; |
| 1197 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1198 | error = -EIO; |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 1199 | bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); |
| 1200 | if (!bh) |
| 1201 | goto fail; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1202 | if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) { |
| 1203 | brelse(bh); |
| 1204 | goto fail; |
| 1205 | } |
| 1206 | |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 1207 | for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1208 | y++, slot++) { |
Al Viro | b62f963 | 2006-10-13 23:46:46 -0400 | [diff] [blame] | 1209 | struct gfs2_quota_change_host qc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1210 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1229 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1230 | spin_lock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1231 | spin_lock(&sdp->sd_quota_spin); |
| 1232 | gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1233 | spin_unlock(&sdp->sd_quota_spin); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1234 | list_add(&qd->qd_list, &sdp->sd_quota_list); |
| 1235 | atomic_inc(&sdp->sd_quota_count); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1236 | spin_unlock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1237 | |
| 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 Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1251 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1252 | gfs2_quota_cleanup(sdp); |
| 1253 | return error; |
| 1254 | } |
| 1255 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1256 | void 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 Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1262 | spin_lock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1263 | while (!list_empty(head)) { |
| 1264 | qd = list_entry(head->prev, struct gfs2_quota_data, qd_list); |
| 1265 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1266 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1270 | spin_unlock(&sdp->sd_quota_spin); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1271 | list_move(&qd->qd_list, head); |
| 1272 | spin_unlock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1273 | schedule(); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1274 | spin_lock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1275 | continue; |
| 1276 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1277 | spin_unlock(&sdp->sd_quota_spin); |
| 1278 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1279 | 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 Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1289 | 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 Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1296 | kmem_cache_free(gfs2_quotad_cachep, qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1297 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1298 | spin_lock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1299 | } |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame^] | 1300 | spin_unlock(&qd_lru_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1301 | |
| 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 Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1311 | static 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 | |
| 1319 | static 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 Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1333 | static 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 Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1352 | /** |
| 1353 | * gfs2_quotad - Write cached quota changes into the quota file |
| 1354 | * @sdp: Pointer to GFS2 superblock |
| 1355 | * |
| 1356 | */ |
| 1357 | |
| 1358 | int 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 Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1366 | int empty; |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1367 | |
| 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 | "ad_timeo, &tune->gt_quota_quantum); |
| 1377 | |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1378 | /* Check for & recover partially truncated inodes */ |
| 1379 | quotad_check_trunc_list(sdp); |
| 1380 | |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1381 | 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 Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1386 | 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 Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1393 | finish_wait(&sdp->sd_quota_wait, &wait); |
| 1394 | } |
| 1395 | |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |