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. |
Steven Whitehouse | 1e72c0f | 2009-09-15 20:42:56 +0100 | [diff] [blame] | 18 | * Since quota tags are part of transactions, there is no need for a quota check |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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> |
Ying Han | 1495f23 | 2011-05-24 17:12:27 -0700 | [diff] [blame] | 41 | #include <linux/mm.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 42 | #include <linux/spinlock.h> |
| 43 | #include <linux/completion.h> |
| 44 | #include <linux/buffer_head.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 45 | #include <linux/sort.h> |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 46 | #include <linux/fs.h> |
Steven Whitehouse | 2e565bb | 2006-10-02 11:38:25 -0400 | [diff] [blame] | 47 | #include <linux/bio.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 48 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 49 | #include <linux/kthread.h> |
| 50 | #include <linux/freezer.h> |
Steven Whitehouse | 2ec4650 | 2009-09-28 12:49:15 +0100 | [diff] [blame] | 51 | #include <linux/quota.h> |
Steven Whitehouse | 1d371b5 | 2009-09-11 15:57:27 +0100 | [diff] [blame] | 52 | #include <linux/dqblk_xfs.h> |
Steven Whitehouse | 9b9f039 | 2013-11-01 14:52:06 -0400 | [diff] [blame] | 53 | #include <linux/lockref.h> |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 54 | #include <linux/list_lru.h> |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 55 | #include <linux/rcupdate.h> |
| 56 | #include <linux/rculist_bl.h> |
| 57 | #include <linux/bit_spinlock.h> |
| 58 | #include <linux/jhash.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 59 | |
| 60 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 61 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 62 | #include "bmap.h" |
| 63 | #include "glock.h" |
| 64 | #include "glops.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 65 | #include "log.h" |
| 66 | #include "meta_io.h" |
| 67 | #include "quota.h" |
| 68 | #include "rgrp.h" |
| 69 | #include "super.h" |
| 70 | #include "trans.h" |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 71 | #include "inode.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 72 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 73 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 74 | #define GFS2_QD_HASH_SHIFT 12 |
| 75 | #define GFS2_QD_HASH_SIZE (1 << GFS2_QD_HASH_SHIFT) |
| 76 | #define GFS2_QD_HASH_MASK (GFS2_QD_HASH_SIZE - 1) |
| 77 | |
| 78 | /* Lock order: qd_lock -> bucket lock -> qd->lockref.lock -> lru lock */ |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 79 | static DEFINE_SPINLOCK(qd_lock); |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 80 | struct list_lru gfs2_qd_lru; |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 81 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 82 | static struct hlist_bl_head qd_hash_table[GFS2_QD_HASH_SIZE]; |
| 83 | |
| 84 | static unsigned int gfs2_qd_hash(const struct gfs2_sbd *sdp, |
| 85 | const struct kqid qid) |
| 86 | { |
| 87 | unsigned int h; |
| 88 | |
| 89 | h = jhash(&sdp, sizeof(struct gfs2_sbd *), 0); |
| 90 | h = jhash(&qid, sizeof(struct kqid), h); |
| 91 | |
| 92 | return h & GFS2_QD_HASH_MASK; |
| 93 | } |
| 94 | |
| 95 | static inline void spin_lock_bucket(unsigned int hash) |
| 96 | { |
| 97 | hlist_bl_lock(&qd_hash_table[hash]); |
| 98 | } |
| 99 | |
| 100 | static inline void spin_unlock_bucket(unsigned int hash) |
| 101 | { |
| 102 | hlist_bl_unlock(&qd_hash_table[hash]); |
| 103 | } |
| 104 | |
| 105 | static void gfs2_qd_dealloc(struct rcu_head *rcu) |
| 106 | { |
| 107 | struct gfs2_quota_data *qd = container_of(rcu, struct gfs2_quota_data, qd_rcu); |
| 108 | kmem_cache_free(gfs2_quotad_cachep, qd); |
| 109 | } |
| 110 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 111 | static void gfs2_qd_dispose(struct list_head *list) |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 112 | { |
| 113 | struct gfs2_quota_data *qd; |
| 114 | struct gfs2_sbd *sdp; |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 115 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 116 | while (!list_empty(list)) { |
| 117 | qd = list_entry(list->next, struct gfs2_quota_data, qd_lru); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 118 | sdp = qd->qd_gl->gl_sbd; |
| 119 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 120 | list_del(&qd->qd_lru); |
| 121 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 122 | /* Free from the filesystem-specific list */ |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 123 | spin_lock(&qd_lock); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 124 | list_del(&qd->qd_list); |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 125 | spin_unlock(&qd_lock); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 126 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 127 | spin_lock_bucket(qd->qd_hash); |
| 128 | hlist_bl_del_rcu(&qd->qd_hlist); |
| 129 | spin_unlock_bucket(qd->qd_hash); |
| 130 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 131 | gfs2_assert_warn(sdp, !qd->qd_change); |
| 132 | gfs2_assert_warn(sdp, !qd->qd_slot_count); |
| 133 | gfs2_assert_warn(sdp, !qd->qd_bh_count); |
| 134 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 135 | gfs2_glock_put(qd->qd_gl); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 136 | atomic_dec(&sdp->sd_quota_count); |
| 137 | |
| 138 | /* Delete it from the common reclaim list */ |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 139 | call_rcu(&qd->qd_rcu, gfs2_qd_dealloc); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 140 | } |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | static enum lru_status gfs2_qd_isolate(struct list_head *item, spinlock_t *lock, void *arg) |
| 145 | { |
| 146 | struct list_head *dispose = arg; |
| 147 | struct gfs2_quota_data *qd = list_entry(item, struct gfs2_quota_data, qd_lru); |
| 148 | |
| 149 | if (!spin_trylock(&qd->qd_lockref.lock)) |
| 150 | return LRU_SKIP; |
| 151 | |
| 152 | if (qd->qd_lockref.count == 0) { |
| 153 | lockref_mark_dead(&qd->qd_lockref); |
| 154 | list_move(&qd->qd_lru, dispose); |
| 155 | } |
| 156 | |
| 157 | spin_unlock(&qd->qd_lockref.lock); |
| 158 | return LRU_REMOVED; |
| 159 | } |
| 160 | |
| 161 | static unsigned long gfs2_qd_shrink_scan(struct shrinker *shrink, |
| 162 | struct shrink_control *sc) |
| 163 | { |
| 164 | LIST_HEAD(dispose); |
| 165 | unsigned long freed; |
| 166 | |
| 167 | if (!(sc->gfp_mask & __GFP_FS)) |
| 168 | return SHRINK_STOP; |
| 169 | |
| 170 | freed = list_lru_walk_node(&gfs2_qd_lru, sc->nid, gfs2_qd_isolate, |
| 171 | &dispose, &sc->nr_to_scan); |
| 172 | |
| 173 | gfs2_qd_dispose(&dispose); |
| 174 | |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 175 | return freed; |
| 176 | } |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 177 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 178 | static unsigned long gfs2_qd_shrink_count(struct shrinker *shrink, |
| 179 | struct shrink_control *sc) |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 180 | { |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 181 | return vfs_pressure_ratio(list_lru_count_node(&gfs2_qd_lru, sc->nid)); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 182 | } |
| 183 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 184 | struct shrinker gfs2_qd_shrinker = { |
| 185 | .count_objects = gfs2_qd_shrink_count, |
| 186 | .scan_objects = gfs2_qd_shrink_scan, |
| 187 | .seeks = DEFAULT_SEEKS, |
| 188 | .flags = SHRINKER_NUMA_AWARE, |
| 189 | }; |
| 190 | |
| 191 | |
Eric W. Biederman | 2f6c989 | 2013-01-31 18:33:38 -0800 | [diff] [blame] | 192 | static u64 qd2index(struct gfs2_quota_data *qd) |
| 193 | { |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 194 | struct kqid qid = qd->qd_id; |
| 195 | return (2 * (u64)from_kqid(&init_user_ns, qid)) + |
Bob Peterson | 37f7157 | 2013-05-10 11:59:18 -0400 | [diff] [blame] | 196 | ((qid.type == USRQUOTA) ? 0 : 1); |
Eric W. Biederman | 2f6c989 | 2013-01-31 18:33:38 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 199 | static u64 qd2offset(struct gfs2_quota_data *qd) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 200 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 201 | u64 offset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 202 | |
Eric W. Biederman | 2f6c989 | 2013-01-31 18:33:38 -0800 | [diff] [blame] | 203 | offset = qd2index(qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 204 | offset *= sizeof(struct gfs2_quota); |
| 205 | |
| 206 | return offset; |
| 207 | } |
| 208 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 209 | static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, struct kqid qid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 210 | { |
| 211 | struct gfs2_quota_data *qd; |
| 212 | int error; |
| 213 | |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 214 | qd = kmem_cache_zalloc(gfs2_quotad_cachep, GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 215 | if (!qd) |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 216 | return NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 217 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 218 | qd->qd_sbd = sdp; |
Steven Whitehouse | 9b9f039 | 2013-11-01 14:52:06 -0400 | [diff] [blame] | 219 | qd->qd_lockref.count = 1; |
| 220 | spin_lock_init(&qd->qd_lockref.lock); |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 221 | qd->qd_id = qid; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 222 | qd->qd_slot = -1; |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 223 | INIT_LIST_HEAD(&qd->qd_lru); |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 224 | qd->qd_hash = hash; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 225 | |
Eric W. Biederman | 2f6c989 | 2013-01-31 18:33:38 -0800 | [diff] [blame] | 226 | error = gfs2_glock_get(sdp, qd2index(qd), |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 227 | &gfs2_quota_glops, CREATE, &qd->qd_gl); |
| 228 | if (error) |
| 229 | goto fail; |
| 230 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 231 | return qd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 232 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 233 | fail: |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 234 | kmem_cache_free(gfs2_quotad_cachep, qd); |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 235 | return NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 238 | static struct gfs2_quota_data *gfs2_qd_search_bucket(unsigned int hash, |
| 239 | const struct gfs2_sbd *sdp, |
| 240 | struct kqid qid) |
| 241 | { |
| 242 | struct gfs2_quota_data *qd; |
| 243 | struct hlist_bl_node *h; |
| 244 | |
| 245 | hlist_bl_for_each_entry_rcu(qd, h, &qd_hash_table[hash], qd_hlist) { |
| 246 | if (!qid_eq(qd->qd_id, qid)) |
| 247 | continue; |
| 248 | if (qd->qd_sbd != sdp) |
| 249 | continue; |
| 250 | if (lockref_get_not_dead(&qd->qd_lockref)) { |
| 251 | list_lru_del(&gfs2_qd_lru, &qd->qd_lru); |
| 252 | return qd; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | return NULL; |
| 257 | } |
| 258 | |
| 259 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 260 | static int qd_get(struct gfs2_sbd *sdp, struct kqid qid, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 261 | struct gfs2_quota_data **qdp) |
| 262 | { |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 263 | struct gfs2_quota_data *qd, *new_qd; |
| 264 | unsigned int hash = gfs2_qd_hash(sdp, qid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 265 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 266 | rcu_read_lock(); |
| 267 | *qdp = qd = gfs2_qd_search_bucket(hash, sdp, qid); |
| 268 | rcu_read_unlock(); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 269 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 270 | if (qd) |
| 271 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 272 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 273 | new_qd = qd_alloc(hash, sdp, qid); |
| 274 | if (!new_qd) |
| 275 | return -ENOMEM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 276 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 277 | spin_lock(&qd_lock); |
| 278 | spin_lock_bucket(hash); |
| 279 | *qdp = qd = gfs2_qd_search_bucket(hash, sdp, qid); |
| 280 | if (qd == NULL) { |
| 281 | *qdp = new_qd; |
| 282 | list_add(&new_qd->qd_list, &sdp->sd_quota_list); |
| 283 | hlist_bl_add_head_rcu(&new_qd->qd_hlist, &qd_hash_table[hash]); |
| 284 | atomic_inc(&sdp->sd_quota_count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 285 | } |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 286 | spin_unlock_bucket(hash); |
| 287 | spin_unlock(&qd_lock); |
| 288 | |
| 289 | if (qd) { |
| 290 | gfs2_glock_put(new_qd->qd_gl); |
| 291 | kmem_cache_free(gfs2_quotad_cachep, new_qd); |
| 292 | } |
| 293 | |
| 294 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 297 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 298 | static void qd_hold(struct gfs2_quota_data *qd) |
| 299 | { |
| 300 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
Steven Whitehouse | 9b9f039 | 2013-11-01 14:52:06 -0400 | [diff] [blame] | 301 | gfs2_assert(sdp, !__lockref_is_dead(&qd->qd_lockref)); |
| 302 | lockref_get(&qd->qd_lockref); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static void qd_put(struct gfs2_quota_data *qd) |
| 306 | { |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 307 | if (lockref_put_or_lock(&qd->qd_lockref)) |
| 308 | return; |
Steven Whitehouse | 9b9f039 | 2013-11-01 14:52:06 -0400 | [diff] [blame] | 309 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 310 | qd->qd_lockref.count = 0; |
| 311 | list_lru_add(&gfs2_qd_lru, &qd->qd_lru); |
| 312 | spin_unlock(&qd->qd_lockref.lock); |
Steven Whitehouse | 9b9f039 | 2013-11-01 14:52:06 -0400 | [diff] [blame] | 313 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | static int slot_get(struct gfs2_quota_data *qd) |
| 317 | { |
| 318 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
| 319 | unsigned int c, o = 0, b; |
| 320 | unsigned char byte = 0; |
| 321 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 322 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 323 | |
| 324 | if (qd->qd_slot_count++) { |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 325 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | for (c = 0; c < sdp->sd_quota_chunks; c++) |
| 330 | for (o = 0; o < PAGE_SIZE; o++) { |
| 331 | byte = sdp->sd_quota_bitmap[c][o]; |
| 332 | if (byte != 0xFF) |
| 333 | goto found; |
| 334 | } |
| 335 | |
| 336 | goto fail; |
| 337 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 338 | found: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 339 | for (b = 0; b < 8; b++) |
| 340 | if (!(byte & (1 << b))) |
| 341 | break; |
| 342 | qd->qd_slot = c * (8 * PAGE_SIZE) + o * 8 + b; |
| 343 | |
| 344 | if (qd->qd_slot >= sdp->sd_quota_slots) |
| 345 | goto fail; |
| 346 | |
| 347 | sdp->sd_quota_bitmap[c][o] |= 1 << b; |
| 348 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 349 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 350 | |
| 351 | return 0; |
| 352 | |
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_slot_count--; |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 355 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 356 | return -ENOSPC; |
| 357 | } |
| 358 | |
| 359 | static void slot_hold(struct gfs2_quota_data *qd) |
| 360 | { |
| 361 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
| 362 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 363 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 364 | gfs2_assert(sdp, qd->qd_slot_count); |
| 365 | qd->qd_slot_count++; |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 366 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Steven Whitehouse | 26e43a1 | 2013-10-02 14:47:02 +0100 | [diff] [blame] | 369 | static void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap, |
| 370 | unsigned int bit, int new_value) |
| 371 | { |
| 372 | unsigned int c, o, b = bit; |
| 373 | int old_value; |
| 374 | |
| 375 | c = b / (8 * PAGE_SIZE); |
| 376 | b %= 8 * PAGE_SIZE; |
| 377 | o = b / 8; |
| 378 | b %= 8; |
| 379 | |
| 380 | old_value = (bitmap[c][o] & (1 << b)); |
| 381 | gfs2_assert_withdraw(sdp, !old_value != !new_value); |
| 382 | |
| 383 | if (new_value) |
| 384 | bitmap[c][o] |= 1 << b; |
| 385 | else |
| 386 | bitmap[c][o] &= ~(1 << b); |
| 387 | } |
| 388 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 389 | static void slot_put(struct gfs2_quota_data *qd) |
| 390 | { |
| 391 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
| 392 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 393 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 394 | gfs2_assert(sdp, qd->qd_slot_count); |
| 395 | if (!--qd->qd_slot_count) { |
| 396 | gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0); |
| 397 | qd->qd_slot = -1; |
| 398 | } |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 399 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static int bh_get(struct gfs2_quota_data *qd) |
| 403 | { |
| 404 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 405 | struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 406 | unsigned int block, offset; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 407 | struct buffer_head *bh; |
| 408 | int error; |
Steven Whitehouse | 2359125 | 2006-10-13 17:25:45 -0400 | [diff] [blame] | 409 | struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 }; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 410 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 411 | mutex_lock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 412 | |
| 413 | if (qd->qd_bh_count++) { |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 414 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | block = qd->qd_slot / sdp->sd_qc_per_block; |
Bob Peterson | 0d0868b | 2007-12-11 18:51:25 -0600 | [diff] [blame] | 419 | offset = qd->qd_slot % sdp->sd_qc_per_block; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 420 | |
Steven Whitehouse | 2359125 | 2006-10-13 17:25:45 -0400 | [diff] [blame] | 421 | bh_map.b_size = 1 << ip->i_inode.i_blkbits; |
Bob Peterson | e9e1ef2 | 2007-12-10 14:13:27 -0600 | [diff] [blame] | 422 | error = gfs2_block_map(&ip->i_inode, block, &bh_map, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 423 | if (error) |
| 424 | goto fail; |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 425 | 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] | 426 | if (error) |
| 427 | goto fail; |
| 428 | error = -EIO; |
| 429 | if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) |
| 430 | goto fail_brelse; |
| 431 | |
| 432 | qd->qd_bh = bh; |
| 433 | qd->qd_bh_qc = (struct gfs2_quota_change *) |
| 434 | (bh->b_data + sizeof(struct gfs2_meta_header) + |
| 435 | offset * sizeof(struct gfs2_quota_change)); |
| 436 | |
Josef Whiter | 2e95b66 | 2007-02-20 00:03:29 -0500 | [diff] [blame] | 437 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 438 | |
| 439 | return 0; |
| 440 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 441 | fail_brelse: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 442 | brelse(bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 443 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 444 | qd->qd_bh_count--; |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 445 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 446 | return error; |
| 447 | } |
| 448 | |
| 449 | static void bh_put(struct gfs2_quota_data *qd) |
| 450 | { |
| 451 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
| 452 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 453 | mutex_lock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 454 | gfs2_assert(sdp, qd->qd_bh_count); |
| 455 | if (!--qd->qd_bh_count) { |
| 456 | brelse(qd->qd_bh); |
| 457 | qd->qd_bh = NULL; |
| 458 | qd->qd_bh_qc = NULL; |
| 459 | } |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 460 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Steven Whitehouse | 1bf59bf | 2013-10-04 11:14:46 +0100 | [diff] [blame] | 463 | static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd, |
| 464 | u64 *sync_gen) |
| 465 | { |
| 466 | if (test_bit(QDF_LOCKED, &qd->qd_flags) || |
| 467 | !test_bit(QDF_CHANGE, &qd->qd_flags) || |
| 468 | (sync_gen && (qd->qd_sync_gen >= *sync_gen))) |
| 469 | return 0; |
| 470 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 471 | if (!lockref_get_not_dead(&qd->qd_lockref)) |
| 472 | return 0; |
Steven Whitehouse | 1bf59bf | 2013-10-04 11:14:46 +0100 | [diff] [blame] | 473 | |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 474 | list_move_tail(&qd->qd_list, &sdp->sd_quota_list); |
Steven Whitehouse | 1bf59bf | 2013-10-04 11:14:46 +0100 | [diff] [blame] | 475 | set_bit(QDF_LOCKED, &qd->qd_flags); |
Steven Whitehouse | 1bf59bf | 2013-10-04 11:14:46 +0100 | [diff] [blame] | 476 | qd->qd_change_sync = qd->qd_change; |
| 477 | gfs2_assert_warn(sdp, qd->qd_slot_count); |
| 478 | qd->qd_slot_count++; |
| 479 | return 1; |
| 480 | } |
| 481 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 482 | static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp) |
| 483 | { |
| 484 | struct gfs2_quota_data *qd = NULL; |
| 485 | int error; |
| 486 | int found = 0; |
| 487 | |
| 488 | *qdp = NULL; |
| 489 | |
| 490 | if (sdp->sd_vfs->s_flags & MS_RDONLY) |
| 491 | return 0; |
| 492 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 493 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 494 | |
| 495 | list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { |
Steven Whitehouse | 1bf59bf | 2013-10-04 11:14:46 +0100 | [diff] [blame] | 496 | found = qd_check_sync(sdp, qd, &sdp->sd_quota_sync_gen); |
| 497 | if (found) |
| 498 | break; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | if (!found) |
| 502 | qd = NULL; |
| 503 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 504 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 505 | |
| 506 | if (qd) { |
| 507 | gfs2_assert_warn(sdp, qd->qd_change_sync); |
| 508 | error = bh_get(qd); |
| 509 | if (error) { |
| 510 | clear_bit(QDF_LOCKED, &qd->qd_flags); |
| 511 | slot_put(qd); |
| 512 | qd_put(qd); |
| 513 | return error; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | *qdp = qd; |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 522 | static void qd_unlock(struct gfs2_quota_data *qd) |
| 523 | { |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 524 | gfs2_assert_warn(qd->qd_gl->gl_sbd, |
| 525 | test_bit(QDF_LOCKED, &qd->qd_flags)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 526 | clear_bit(QDF_LOCKED, &qd->qd_flags); |
| 527 | bh_put(qd); |
| 528 | slot_put(qd); |
| 529 | qd_put(qd); |
| 530 | } |
| 531 | |
Eric W. Biederman | b59c8b6 | 2013-01-31 19:35:56 -0800 | [diff] [blame] | 532 | static int qdsb_get(struct gfs2_sbd *sdp, struct kqid qid, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 533 | struct gfs2_quota_data **qdp) |
| 534 | { |
| 535 | int error; |
| 536 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 537 | error = qd_get(sdp, qid, qdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 538 | if (error) |
| 539 | return error; |
| 540 | |
| 541 | error = slot_get(*qdp); |
| 542 | if (error) |
| 543 | goto fail; |
| 544 | |
| 545 | error = bh_get(*qdp); |
| 546 | if (error) |
| 547 | goto fail_slot; |
| 548 | |
| 549 | return 0; |
| 550 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 551 | fail_slot: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 552 | slot_put(*qdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 553 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 554 | qd_put(*qdp); |
| 555 | return error; |
| 556 | } |
| 557 | |
| 558 | static void qdsb_put(struct gfs2_quota_data *qd) |
| 559 | { |
| 560 | bh_put(qd); |
| 561 | slot_put(qd); |
| 562 | qd_put(qd); |
| 563 | } |
| 564 | |
Eric W. Biederman | 7c06b5d | 2013-01-31 20:27:54 -0800 | [diff] [blame] | 565 | int gfs2_quota_hold(struct gfs2_inode *ip, kuid_t uid, kgid_t gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 566 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 567 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 568 | struct gfs2_quota_data **qd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 569 | int error; |
| 570 | |
Andrew Price | aaaf68c | 2012-10-12 16:45:08 +0100 | [diff] [blame] | 571 | if (ip->i_res == NULL) { |
| 572 | error = gfs2_rs_alloc(ip); |
| 573 | if (error) |
| 574 | return error; |
| 575 | } |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 576 | |
| 577 | qd = ip->i_res->rs_qa_qd; |
| 578 | |
| 579 | if (gfs2_assert_warn(sdp, !ip->i_res->rs_qa_qd_num) || |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 580 | gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags))) |
| 581 | return -EIO; |
| 582 | |
| 583 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) |
| 584 | return 0; |
| 585 | |
Eric W. Biederman | b59c8b6 | 2013-01-31 19:35:56 -0800 | [diff] [blame] | 586 | error = qdsb_get(sdp, make_kqid_uid(ip->i_inode.i_uid), qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 587 | if (error) |
| 588 | goto out; |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 589 | ip->i_res->rs_qa_qd_num++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 590 | qd++; |
| 591 | |
Eric W. Biederman | b59c8b6 | 2013-01-31 19:35:56 -0800 | [diff] [blame] | 592 | error = qdsb_get(sdp, make_kqid_gid(ip->i_inode.i_gid), qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 593 | if (error) |
| 594 | goto out; |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 595 | ip->i_res->rs_qa_qd_num++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 596 | qd++; |
| 597 | |
Eric W. Biederman | 6b24c0d | 2013-01-31 21:56:13 -0800 | [diff] [blame] | 598 | if (!uid_eq(uid, NO_UID_QUOTA_CHANGE) && |
| 599 | !uid_eq(uid, ip->i_inode.i_uid)) { |
Eric W. Biederman | b59c8b6 | 2013-01-31 19:35:56 -0800 | [diff] [blame] | 600 | error = qdsb_get(sdp, make_kqid_uid(uid), qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 601 | if (error) |
| 602 | goto out; |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 603 | ip->i_res->rs_qa_qd_num++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 604 | qd++; |
| 605 | } |
| 606 | |
Eric W. Biederman | 6b24c0d | 2013-01-31 21:56:13 -0800 | [diff] [blame] | 607 | if (!gid_eq(gid, NO_GID_QUOTA_CHANGE) && |
| 608 | !gid_eq(gid, ip->i_inode.i_gid)) { |
Eric W. Biederman | b59c8b6 | 2013-01-31 19:35:56 -0800 | [diff] [blame] | 609 | error = qdsb_get(sdp, make_kqid_gid(gid), qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 610 | if (error) |
| 611 | goto out; |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 612 | ip->i_res->rs_qa_qd_num++; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 613 | qd++; |
| 614 | } |
| 615 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 616 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 617 | if (error) |
| 618 | gfs2_quota_unhold(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 619 | return error; |
| 620 | } |
| 621 | |
| 622 | void gfs2_quota_unhold(struct gfs2_inode *ip) |
| 623 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 624 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 625 | unsigned int x; |
| 626 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 627 | if (ip->i_res == NULL) |
| 628 | return; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 629 | gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); |
| 630 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 631 | for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) { |
| 632 | qdsb_put(ip->i_res->rs_qa_qd[x]); |
| 633 | ip->i_res->rs_qa_qd[x] = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 634 | } |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 635 | ip->i_res->rs_qa_qd_num = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static int sort_qd(const void *a, const void *b) |
| 639 | { |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 640 | const struct gfs2_quota_data *qd_a = *(const struct gfs2_quota_data **)a; |
| 641 | 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] | 642 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 643 | if (qid_lt(qd_a->qd_id, qd_b->qd_id)) |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 644 | return -1; |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 645 | if (qid_lt(qd_b->qd_id, qd_a->qd_id)) |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 646 | return 1; |
Steven Whitehouse | 48fac17 | 2006-09-05 15:17:12 -0400 | [diff] [blame] | 647 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 650 | static void do_qc(struct gfs2_quota_data *qd, s64 change) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 651 | { |
| 652 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 653 | struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 654 | struct gfs2_quota_change *qc = qd->qd_bh_qc; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 655 | s64 x; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 656 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 657 | mutex_lock(&sdp->sd_quota_mutex); |
Steven Whitehouse | 350a9b0 | 2012-12-14 12:36:02 +0000 | [diff] [blame] | 658 | gfs2_trans_add_meta(ip->i_gl, qd->qd_bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 659 | |
| 660 | if (!test_bit(QDF_CHANGE, &qd->qd_flags)) { |
| 661 | qc->qc_change = 0; |
| 662 | qc->qc_flags = 0; |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 663 | if (qd->qd_id.type == USRQUOTA) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 664 | qc->qc_flags = cpu_to_be32(GFS2_QCF_USER); |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 665 | qc->qc_id = cpu_to_be32(from_kqid(&init_user_ns, qd->qd_id)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 668 | x = be64_to_cpu(qc->qc_change) + change; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 669 | qc->qc_change = cpu_to_be64(x); |
| 670 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 671 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 672 | qd->qd_change = x; |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 673 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 674 | |
| 675 | if (!x) { |
| 676 | gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags)); |
| 677 | clear_bit(QDF_CHANGE, &qd->qd_flags); |
| 678 | qc->qc_flags = 0; |
| 679 | qc->qc_id = 0; |
| 680 | slot_put(qd); |
| 681 | qd_put(qd); |
| 682 | } else if (!test_and_set_bit(QDF_CHANGE, &qd->qd_flags)) { |
| 683 | qd_hold(qd); |
| 684 | slot_hold(qd); |
| 685 | } |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 686 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 687 | mutex_unlock(&sdp->sd_quota_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 690 | /** |
Steven Whitehouse | 1e72c0f | 2009-09-15 20:42:56 +0100 | [diff] [blame] | 691 | * gfs2_adjust_quota - adjust record of current block usage |
| 692 | * @ip: The quota inode |
| 693 | * @loc: Offset of the entry in the quota file |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 694 | * @change: The amount of usage change to record |
Steven Whitehouse | 1e72c0f | 2009-09-15 20:42:56 +0100 | [diff] [blame] | 695 | * @qd: The quota data |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 696 | * @fdq: The updated limits to record |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 697 | * |
| 698 | * This function was mostly borrowed from gfs2_block_truncate_page which was |
| 699 | * in turn mostly borrowed from ext3 |
Steven Whitehouse | 1e72c0f | 2009-09-15 20:42:56 +0100 | [diff] [blame] | 700 | * |
| 701 | * Returns: 0 or -ve on error |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 702 | */ |
Steven Whitehouse | 1e72c0f | 2009-09-15 20:42:56 +0100 | [diff] [blame] | 703 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 704 | static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 705 | s64 change, struct gfs2_quota_data *qd, |
| 706 | struct fs_disk_quota *fdq) |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 707 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 708 | struct inode *inode = &ip->i_inode; |
Abhijith Das | 14870b4 | 2010-11-18 11:24:24 -0500 | [diff] [blame] | 709 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 710 | struct address_space *mapping = inode->i_mapping; |
| 711 | unsigned long index = loc >> PAGE_CACHE_SHIFT; |
Abhijith Das | 1990e91 | 2007-05-31 17:52:02 -0500 | [diff] [blame] | 712 | unsigned offset = loc & (PAGE_CACHE_SIZE - 1); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 713 | unsigned blocksize, iblock, pos; |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 714 | struct buffer_head *bh; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 715 | struct page *page; |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 716 | void *kaddr, *ptr; |
Al Viro | 951b4bd | 2013-06-02 19:53:40 -0400 | [diff] [blame] | 717 | struct gfs2_quota q; |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 718 | int err, nbytes; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 719 | u64 size; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 720 | |
Steven Whitehouse | 891a8e9 | 2011-09-19 10:25:49 +0100 | [diff] [blame] | 721 | if (gfs2_is_stuffed(ip)) { |
| 722 | err = gfs2_unstuff_dinode(ip, NULL); |
| 723 | if (err) |
| 724 | return err; |
| 725 | } |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 726 | |
| 727 | memset(&q, 0, sizeof(struct gfs2_quota)); |
Andrew Price | 4306629 | 2012-04-16 16:40:55 +0100 | [diff] [blame] | 728 | err = gfs2_internal_read(ip, (char *)&q, &loc, sizeof(q)); |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 729 | if (err < 0) |
| 730 | return err; |
| 731 | |
| 732 | err = -EIO; |
Al Viro | 951b4bd | 2013-06-02 19:53:40 -0400 | [diff] [blame] | 733 | be64_add_cpu(&q.qu_value, change); |
| 734 | qd->qd_qb.qb_value = q.qu_value; |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 735 | if (fdq) { |
| 736 | if (fdq->d_fieldmask & FS_DQ_BSOFT) { |
Al Viro | 951b4bd | 2013-06-02 19:53:40 -0400 | [diff] [blame] | 737 | q.qu_warn = cpu_to_be64(fdq->d_blk_softlimit >> sdp->sd_fsb2bb_shift); |
| 738 | qd->qd_qb.qb_warn = q.qu_warn; |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 739 | } |
| 740 | if (fdq->d_fieldmask & FS_DQ_BHARD) { |
Al Viro | 951b4bd | 2013-06-02 19:53:40 -0400 | [diff] [blame] | 741 | q.qu_limit = cpu_to_be64(fdq->d_blk_hardlimit >> sdp->sd_fsb2bb_shift); |
| 742 | qd->qd_qb.qb_limit = q.qu_limit; |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 743 | } |
Abhijith Das | 802ec9b | 2010-11-18 11:26:46 -0500 | [diff] [blame] | 744 | if (fdq->d_fieldmask & FS_DQ_BCOUNT) { |
Al Viro | 951b4bd | 2013-06-02 19:53:40 -0400 | [diff] [blame] | 745 | q.qu_value = cpu_to_be64(fdq->d_bcount >> sdp->sd_fsb2bb_shift); |
| 746 | qd->qd_qb.qb_value = q.qu_value; |
Abhijith Das | 802ec9b | 2010-11-18 11:26:46 -0500 | [diff] [blame] | 747 | } |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* Write the quota into the quota file on disk */ |
Al Viro | 951b4bd | 2013-06-02 19:53:40 -0400 | [diff] [blame] | 751 | ptr = &q; |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 752 | nbytes = sizeof(struct gfs2_quota); |
| 753 | get_a_page: |
Bob Peterson | 220cca2 | 2012-03-19 15:25:50 -0400 | [diff] [blame] | 754 | page = find_or_create_page(mapping, index, GFP_NOFS); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 755 | if (!page) |
| 756 | return -ENOMEM; |
| 757 | |
| 758 | blocksize = inode->i_sb->s_blocksize; |
| 759 | iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); |
| 760 | |
| 761 | if (!page_has_buffers(page)) |
| 762 | create_empty_buffers(page, blocksize, 0); |
| 763 | |
| 764 | bh = page_buffers(page); |
| 765 | pos = blocksize; |
| 766 | while (offset >= pos) { |
| 767 | bh = bh->b_this_page; |
| 768 | iblock++; |
| 769 | pos += blocksize; |
| 770 | } |
| 771 | |
| 772 | if (!buffer_mapped(bh)) { |
Bob Peterson | e9e1ef2 | 2007-12-10 14:13:27 -0600 | [diff] [blame] | 773 | gfs2_block_map(inode, iblock, bh, 1); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 774 | if (!buffer_mapped(bh)) |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 775 | goto unlock_out; |
| 776 | /* If it's a newly allocated disk block for quota, zero it */ |
Abhijith Das | 8b42160 | 2010-07-04 01:33:24 -0400 | [diff] [blame] | 777 | if (buffer_new(bh)) |
| 778 | zero_user(page, pos - blocksize, bh->b_size); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | if (PageUptodate(page)) |
| 782 | set_buffer_uptodate(bh); |
| 783 | |
| 784 | if (!buffer_uptodate(bh)) { |
Steven Whitehouse | 20ed053 | 2011-10-31 09:52:02 +0000 | [diff] [blame] | 785 | ll_rw_block(READ | REQ_META, 1, &bh); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 786 | wait_on_buffer(bh); |
| 787 | if (!buffer_uptodate(bh)) |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 788 | goto unlock_out; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Bob Peterson | 37f7157 | 2013-05-10 11:59:18 -0400 | [diff] [blame] | 791 | gfs2_trans_add_data(ip->i_gl, bh); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 792 | |
Cong Wang | d934928 | 2011-11-25 23:14:30 +0800 | [diff] [blame] | 793 | kaddr = kmap_atomic(page); |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 794 | if (offset + sizeof(struct gfs2_quota) > PAGE_CACHE_SIZE) |
| 795 | nbytes = PAGE_CACHE_SIZE - offset; |
| 796 | memcpy(kaddr + offset, ptr, nbytes); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 797 | flush_dcache_page(page); |
Cong Wang | d934928 | 2011-11-25 23:14:30 +0800 | [diff] [blame] | 798 | kunmap_atomic(kaddr); |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 799 | unlock_page(page); |
| 800 | page_cache_release(page); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 801 | |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 802 | /* If quota straddles page boundary, we need to update the rest of the |
| 803 | * quota at the beginning of the next page */ |
Abhijith Das | 8b42160 | 2010-07-04 01:33:24 -0400 | [diff] [blame] | 804 | if ((offset + sizeof(struct gfs2_quota)) > PAGE_CACHE_SIZE) { |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 805 | ptr = ptr + nbytes; |
| 806 | nbytes = sizeof(struct gfs2_quota) - nbytes; |
| 807 | offset = 0; |
| 808 | index++; |
| 809 | goto get_a_page; |
| 810 | } |
| 811 | |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 812 | size = loc + sizeof(struct gfs2_quota); |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 813 | if (size > inode->i_size) |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 814 | i_size_write(inode, size); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 815 | inode->i_mtime = inode->i_atime = CURRENT_TIME; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 816 | mark_inode_dirty(inode); |
Bob Peterson | 500242a | 2012-05-15 14:51:54 -0400 | [diff] [blame] | 817 | return 0; |
Steven Whitehouse | ab9bbda | 2011-08-15 14:20:36 +0100 | [diff] [blame] | 818 | |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 819 | unlock_out: |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 820 | unlock_page(page); |
| 821 | page_cache_release(page); |
| 822 | return err; |
| 823 | } |
| 824 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 825 | static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) |
| 826 | { |
| 827 | struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 828 | struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); |
Steven Whitehouse | 7b9cff4 | 2013-10-02 11:13:25 +0100 | [diff] [blame] | 829 | struct gfs2_alloc_parms ap = { .aflags = 0, }; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 830 | unsigned int data_blocks, ind_blocks; |
| 831 | struct gfs2_holder *ghs, i_gh; |
| 832 | unsigned int qx, x; |
| 833 | struct gfs2_quota_data *qd; |
Steven Whitehouse | 71f890f | 2012-07-30 14:53:19 +0100 | [diff] [blame] | 834 | unsigned reserved; |
Steven Whitehouse | f42faf4 | 2006-01-30 18:34:10 +0000 | [diff] [blame] | 835 | loff_t offset; |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 836 | unsigned int nalloc = 0, blocks; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 837 | int error; |
| 838 | |
Bob Peterson | 0a305e4 | 2012-06-06 11:17:59 +0100 | [diff] [blame] | 839 | error = gfs2_rs_alloc(ip); |
| 840 | if (error) |
| 841 | return error; |
| 842 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 843 | gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), |
| 844 | &data_blocks, &ind_blocks); |
| 845 | |
Josef Bacik | 16c5f06 | 2008-04-09 09:33:41 -0400 | [diff] [blame] | 846 | ghs = kcalloc(num_qd, sizeof(struct gfs2_holder), GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 847 | if (!ghs) |
| 848 | return -ENOMEM; |
| 849 | |
| 850 | sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); |
Jan Kara | 56aa72d | 2012-09-05 16:55:11 -0400 | [diff] [blame] | 851 | mutex_lock(&ip->i_inode.i_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 852 | for (qx = 0; qx < num_qd; qx++) { |
Steven Whitehouse | 1e72c0f | 2009-09-15 20:42:56 +0100 | [diff] [blame] | 853 | error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 854 | GL_NOCACHE, &ghs[qx]); |
| 855 | if (error) |
| 856 | goto out; |
| 857 | } |
| 858 | |
| 859 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
| 860 | if (error) |
| 861 | goto out; |
| 862 | |
| 863 | for (x = 0; x < num_qd; x++) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 864 | offset = qd2offset(qda[x]); |
Bob Peterson | 461cb41 | 2010-06-24 19:21:20 -0400 | [diff] [blame] | 865 | if (gfs2_write_alloc_required(ip, offset, |
| 866 | sizeof(struct gfs2_quota))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 867 | nalloc++; |
| 868 | } |
| 869 | |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 870 | /* |
| 871 | * 1 blk for unstuffing inode if stuffed. We add this extra |
| 872 | * block to the reservation unconditionally. If the inode |
| 873 | * doesn't need unstuffing, the block will be released to the |
| 874 | * rgrp since it won't be allocated during the transaction |
| 875 | */ |
Abhijith Das | 7e619bc | 2010-05-07 17:50:18 -0400 | [diff] [blame] | 876 | /* +3 in the end for unstuffing block, inode size update block |
| 877 | * and another block in case quota straddles page boundary and |
| 878 | * two blocks need to be updated instead of 1 */ |
| 879 | blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 880 | |
Steven Whitehouse | 71f890f | 2012-07-30 14:53:19 +0100 | [diff] [blame] | 881 | reserved = 1 + (nalloc * (data_blocks + ind_blocks)); |
Steven Whitehouse | 7b9cff4 | 2013-10-02 11:13:25 +0100 | [diff] [blame] | 882 | ap.target = reserved; |
| 883 | error = gfs2_inplace_reserve(ip, &ap); |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 884 | if (error) |
| 885 | goto out_alloc; |
| 886 | |
| 887 | if (nalloc) |
Steven Whitehouse | 71f890f | 2012-07-30 14:53:19 +0100 | [diff] [blame] | 888 | blocks += gfs2_rg_blocks(ip, reserved) + nalloc * ind_blocks + RES_STATFS; |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 889 | |
| 890 | error = gfs2_trans_begin(sdp, blocks, 0); |
| 891 | if (error) |
| 892 | goto out_ipres; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 893 | |
| 894 | for (x = 0; x < num_qd; x++) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 895 | qd = qda[x]; |
| 896 | offset = qd2offset(qd); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 897 | error = gfs2_adjust_quota(ip, offset, qd->qd_change_sync, qd, NULL); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 898 | if (error) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 899 | goto out_end_trans; |
| 900 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 901 | do_qc(qd, -qd->qd_change_sync); |
Abhijith Das | 662e3a5 | 2011-03-08 10:40:42 -0500 | [diff] [blame] | 902 | set_bit(QDF_REFRESH, &qd->qd_flags); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | error = 0; |
| 906 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 907 | out_end_trans: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 908 | gfs2_trans_end(sdp); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 909 | out_ipres: |
Abhijith Das | 20b95bf | 2008-03-06 17:43:52 -0600 | [diff] [blame] | 910 | gfs2_inplace_release(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 911 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 912 | gfs2_glock_dq_uninit(&i_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 913 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 914 | while (qx--) |
| 915 | gfs2_glock_dq_uninit(&ghs[qx]); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 916 | mutex_unlock(&ip->i_inode.i_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 917 | kfree(ghs); |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 918 | gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 919 | return error; |
| 920 | } |
| 921 | |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 922 | static int update_qd(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd) |
| 923 | { |
| 924 | struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); |
| 925 | struct gfs2_quota q; |
| 926 | struct gfs2_quota_lvb *qlvb; |
| 927 | loff_t pos; |
| 928 | int error; |
| 929 | |
| 930 | memset(&q, 0, sizeof(struct gfs2_quota)); |
| 931 | pos = qd2offset(qd); |
Andrew Price | 4306629 | 2012-04-16 16:40:55 +0100 | [diff] [blame] | 932 | error = gfs2_internal_read(ip, (char *)&q, &pos, sizeof(q)); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 933 | if (error < 0) |
| 934 | return error; |
| 935 | |
David Teigland | 4e2f884 | 2012-11-14 13:47:37 -0500 | [diff] [blame] | 936 | qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 937 | qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC); |
| 938 | qlvb->__pad = 0; |
| 939 | qlvb->qb_limit = q.qu_limit; |
| 940 | qlvb->qb_warn = q.qu_warn; |
| 941 | qlvb->qb_value = q.qu_value; |
| 942 | qd->qd_qb = *qlvb; |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 947 | static int do_glock(struct gfs2_quota_data *qd, int force_refresh, |
| 948 | struct gfs2_holder *q_gh) |
| 949 | { |
| 950 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 951 | struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 952 | struct gfs2_holder i_gh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 953 | int error; |
| 954 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 955 | restart: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 956 | error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); |
| 957 | if (error) |
| 958 | return error; |
| 959 | |
David Teigland | 4e2f884 | 2012-11-14 13:47:37 -0500 | [diff] [blame] | 960 | qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 961 | |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 962 | if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 963 | gfs2_glock_dq_uninit(q_gh); |
Steven Whitehouse | 91094d0 | 2009-09-11 15:21:56 +0100 | [diff] [blame] | 964 | error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_EXCLUSIVE, |
| 965 | GL_NOCACHE, q_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 966 | if (error) |
| 967 | return error; |
| 968 | |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 969 | 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] | 970 | if (error) |
| 971 | goto fail; |
| 972 | |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 973 | error = update_qd(sdp, qd); |
| 974 | if (error) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 975 | goto fail_gunlock; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 976 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 977 | gfs2_glock_dq_uninit(&i_gh); |
Steven Whitehouse | 91094d0 | 2009-09-11 15:21:56 +0100 | [diff] [blame] | 978 | gfs2_glock_dq_uninit(q_gh); |
| 979 | force_refresh = 0; |
| 980 | goto restart; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | return 0; |
| 984 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 985 | fail_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 986 | gfs2_glock_dq_uninit(&i_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 987 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 988 | gfs2_glock_dq_uninit(q_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 989 | return error; |
| 990 | } |
| 991 | |
Eric W. Biederman | 7c06b5d | 2013-01-31 20:27:54 -0800 | [diff] [blame] | 992 | int gfs2_quota_lock(struct gfs2_inode *ip, kuid_t uid, kgid_t gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 993 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 994 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
Abhijith Das | 662e3a5 | 2011-03-08 10:40:42 -0500 | [diff] [blame] | 995 | struct gfs2_quota_data *qd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 996 | unsigned int x; |
| 997 | int error = 0; |
| 998 | |
Steven Whitehouse | 891a8e9 | 2011-09-19 10:25:49 +0100 | [diff] [blame] | 999 | error = gfs2_quota_hold(ip, uid, gid); |
| 1000 | if (error) |
| 1001 | return error; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1002 | |
| 1003 | if (capable(CAP_SYS_RESOURCE) || |
| 1004 | sdp->sd_args.ar_quota != GFS2_QUOTA_ON) |
| 1005 | return 0; |
| 1006 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1007 | sort(ip->i_res->rs_qa_qd, ip->i_res->rs_qa_qd_num, |
| 1008 | sizeof(struct gfs2_quota_data *), sort_qd, NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1009 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1010 | for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) { |
Abhijith Das | 662e3a5 | 2011-03-08 10:40:42 -0500 | [diff] [blame] | 1011 | int force = NO_FORCE; |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1012 | qd = ip->i_res->rs_qa_qd[x]; |
Abhijith Das | 662e3a5 | 2011-03-08 10:40:42 -0500 | [diff] [blame] | 1013 | if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags)) |
| 1014 | force = FORCE; |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1015 | error = do_glock(qd, force, &ip->i_res->rs_qa_qd_ghs[x]); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1016 | if (error) |
| 1017 | break; |
| 1018 | } |
| 1019 | |
| 1020 | if (!error) |
| 1021 | set_bit(GIF_QD_LOCKED, &ip->i_flags); |
| 1022 | else { |
| 1023 | while (x--) |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1024 | gfs2_glock_dq_uninit(&ip->i_res->rs_qa_qd_ghs[x]); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1025 | gfs2_quota_unhold(ip); |
| 1026 | } |
| 1027 | |
| 1028 | return error; |
| 1029 | } |
| 1030 | |
| 1031 | static int need_sync(struct gfs2_quota_data *qd) |
| 1032 | { |
| 1033 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
| 1034 | struct gfs2_tune *gt = &sdp->sd_tune; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1035 | s64 value; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1036 | unsigned int num, den; |
| 1037 | int do_sync = 1; |
| 1038 | |
| 1039 | if (!qd->qd_qb.qb_limit) |
| 1040 | return 0; |
| 1041 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1042 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1043 | value = qd->qd_change; |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1044 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1045 | |
| 1046 | spin_lock(>->gt_spin); |
| 1047 | num = gt->gt_quota_scale_num; |
| 1048 | den = gt->gt_quota_scale_den; |
| 1049 | spin_unlock(>->gt_spin); |
| 1050 | |
| 1051 | if (value < 0) |
| 1052 | do_sync = 0; |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 1053 | else if ((s64)be64_to_cpu(qd->qd_qb.qb_value) >= |
| 1054 | (s64)be64_to_cpu(qd->qd_qb.qb_limit)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1055 | do_sync = 0; |
| 1056 | else { |
| 1057 | value *= gfs2_jindex_size(sdp) * num; |
David Howells | 4abaca17 | 2008-07-11 14:39:56 +0100 | [diff] [blame] | 1058 | value = div_s64(value, den); |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 1059 | value += (s64)be64_to_cpu(qd->qd_qb.qb_value); |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1060 | if (value < (s64)be64_to_cpu(qd->qd_qb.qb_limit)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1061 | do_sync = 0; |
| 1062 | } |
| 1063 | |
| 1064 | return do_sync; |
| 1065 | } |
| 1066 | |
| 1067 | void gfs2_quota_unlock(struct gfs2_inode *ip) |
| 1068 | { |
Steven Whitehouse | aabd7c7 | 2013-10-04 11:31:05 +0100 | [diff] [blame] | 1069 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1070 | struct gfs2_quota_data *qda[4]; |
| 1071 | unsigned int count = 0; |
| 1072 | unsigned int x; |
Steven Whitehouse | aabd7c7 | 2013-10-04 11:31:05 +0100 | [diff] [blame] | 1073 | int found; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1074 | |
| 1075 | if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags)) |
| 1076 | goto out; |
| 1077 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1078 | for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1079 | struct gfs2_quota_data *qd; |
| 1080 | int sync; |
| 1081 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1082 | qd = ip->i_res->rs_qa_qd[x]; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1083 | sync = need_sync(qd); |
| 1084 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1085 | gfs2_glock_dq_uninit(&ip->i_res->rs_qa_qd_ghs[x]); |
Steven Whitehouse | aabd7c7 | 2013-10-04 11:31:05 +0100 | [diff] [blame] | 1086 | if (!sync) |
| 1087 | continue; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1088 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1089 | spin_lock(&qd_lock); |
Steven Whitehouse | aabd7c7 | 2013-10-04 11:31:05 +0100 | [diff] [blame] | 1090 | found = qd_check_sync(sdp, qd, NULL); |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1091 | spin_unlock(&qd_lock); |
Steven Whitehouse | aabd7c7 | 2013-10-04 11:31:05 +0100 | [diff] [blame] | 1092 | |
| 1093 | if (!found) |
| 1094 | continue; |
| 1095 | |
| 1096 | gfs2_assert_warn(sdp, qd->qd_change_sync); |
| 1097 | if (bh_get(qd)) { |
| 1098 | clear_bit(QDF_LOCKED, &qd->qd_flags); |
| 1099 | slot_put(qd); |
| 1100 | qd_put(qd); |
| 1101 | continue; |
| 1102 | } |
| 1103 | |
| 1104 | qda[count++] = qd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | if (count) { |
| 1108 | do_sync(count, qda); |
| 1109 | for (x = 0; x < count; x++) |
| 1110 | qd_unlock(qda[x]); |
| 1111 | } |
| 1112 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1113 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1114 | gfs2_quota_unhold(ip); |
| 1115 | } |
| 1116 | |
| 1117 | #define MAX_LINE 256 |
| 1118 | |
| 1119 | static int print_message(struct gfs2_quota_data *qd, char *type) |
| 1120 | { |
| 1121 | struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1122 | |
Steven Whitehouse | 2ec4650 | 2009-09-28 12:49:15 +0100 | [diff] [blame] | 1123 | printk(KERN_INFO "GFS2: fsid=%s: quota %s for %s %u\n", |
Steven Whitehouse | 02630a1 | 2006-07-03 11:20:06 -0400 | [diff] [blame] | 1124 | sdp->sd_fsname, type, |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1125 | (qd->qd_id.type == USRQUOTA) ? "user" : "group", |
| 1126 | from_kqid(&init_user_ns, qd->qd_id)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1127 | |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
Eric W. Biederman | 7c06b5d | 2013-01-31 20:27:54 -0800 | [diff] [blame] | 1131 | int gfs2_quota_check(struct gfs2_inode *ip, kuid_t uid, kgid_t gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1132 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1133 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1134 | struct gfs2_quota_data *qd; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1135 | s64 value; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1136 | unsigned int x; |
| 1137 | int error = 0; |
| 1138 | |
| 1139 | if (!test_bit(GIF_QD_LOCKED, &ip->i_flags)) |
| 1140 | return 0; |
| 1141 | |
| 1142 | if (sdp->sd_args.ar_quota != GFS2_QUOTA_ON) |
| 1143 | return 0; |
| 1144 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1145 | for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) { |
| 1146 | qd = ip->i_res->rs_qa_qd[x]; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1147 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1148 | if (!(qid_eq(qd->qd_id, make_kqid_uid(uid)) || |
| 1149 | qid_eq(qd->qd_id, make_kqid_gid(gid)))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1150 | continue; |
| 1151 | |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 1152 | value = (s64)be64_to_cpu(qd->qd_qb.qb_value); |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1153 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1154 | value += qd->qd_change; |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1155 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1156 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1157 | 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] | 1158 | print_message(qd, "exceeded"); |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1159 | quota_send_warning(qd->qd_id, |
Steven Whitehouse | 2ec4650 | 2009-09-28 12:49:15 +0100 | [diff] [blame] | 1160 | sdp->sd_vfs->s_dev, QUOTA_NL_BHARDWARN); |
| 1161 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1162 | error = -EDQUOT; |
| 1163 | break; |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 1164 | } else if (be64_to_cpu(qd->qd_qb.qb_warn) && |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1165 | (s64)be64_to_cpu(qd->qd_qb.qb_warn) < value && |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1166 | time_after_eq(jiffies, qd->qd_last_warn + |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 1167 | gfs2_tune_get(sdp, |
| 1168 | gt_quota_warn_period) * HZ)) { |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1169 | quota_send_warning(qd->qd_id, |
Steven Whitehouse | 2ec4650 | 2009-09-28 12:49:15 +0100 | [diff] [blame] | 1170 | sdp->sd_vfs->s_dev, QUOTA_NL_BSOFTWARN); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1171 | error = print_message(qd, "warning"); |
| 1172 | qd->qd_last_warn = jiffies; |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | return error; |
| 1177 | } |
| 1178 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1179 | void gfs2_quota_change(struct gfs2_inode *ip, s64 change, |
Eric W. Biederman | 7c06b5d | 2013-01-31 20:27:54 -0800 | [diff] [blame] | 1180 | kuid_t uid, kgid_t gid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1181 | { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1182 | struct gfs2_quota_data *qd; |
| 1183 | unsigned int x; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1184 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1185 | if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1186 | return; |
Steven Whitehouse | 383f01f | 2008-11-04 10:05:22 +0000 | [diff] [blame] | 1187 | if (ip->i_diskflags & GFS2_DIF_SYSTEM) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1188 | return; |
| 1189 | |
Bob Peterson | 5407e24 | 2012-05-18 09:28:23 -0400 | [diff] [blame] | 1190 | for (x = 0; x < ip->i_res->rs_qa_qd_num; x++) { |
| 1191 | qd = ip->i_res->rs_qa_qd[x]; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1192 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1193 | if (qid_eq(qd->qd_id, make_kqid_uid(uid)) || |
| 1194 | qid_eq(qd->qd_id, make_kqid_gid(gid))) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1195 | do_qc(qd, change); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | |
Jan Kara | ceed172 | 2012-07-03 16:45:28 +0200 | [diff] [blame] | 1200 | int gfs2_quota_sync(struct super_block *sb, int type) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1201 | { |
Steven Whitehouse | 8c42d63 | 2009-09-11 14:36:44 +0100 | [diff] [blame] | 1202 | struct gfs2_sbd *sdp = sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1203 | struct gfs2_quota_data **qda; |
Steven Whitehouse | bef292a | 2013-10-03 18:43:20 +0100 | [diff] [blame] | 1204 | unsigned int max_qd = PAGE_SIZE/sizeof(struct gfs2_holder); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1205 | unsigned int num_qd; |
| 1206 | unsigned int x; |
| 1207 | int error = 0; |
| 1208 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1209 | qda = kcalloc(max_qd, sizeof(struct gfs2_quota_data *), GFP_KERNEL); |
| 1210 | if (!qda) |
| 1211 | return -ENOMEM; |
| 1212 | |
Steven Whitehouse | e46c772 | 2013-10-04 12:29:34 +0100 | [diff] [blame] | 1213 | mutex_lock(&sdp->sd_quota_sync_mutex); |
| 1214 | sdp->sd_quota_sync_gen++; |
| 1215 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1216 | do { |
| 1217 | num_qd = 0; |
| 1218 | |
| 1219 | for (;;) { |
| 1220 | error = qd_fish(sdp, qda + num_qd); |
| 1221 | if (error || !qda[num_qd]) |
| 1222 | break; |
| 1223 | if (++num_qd == max_qd) |
| 1224 | break; |
| 1225 | } |
| 1226 | |
| 1227 | if (num_qd) { |
| 1228 | if (!error) |
| 1229 | error = do_sync(num_qd, qda); |
| 1230 | if (!error) |
| 1231 | for (x = 0; x < num_qd; x++) |
| 1232 | qda[x]->qd_sync_gen = |
| 1233 | sdp->sd_quota_sync_gen; |
| 1234 | |
| 1235 | for (x = 0; x < num_qd; x++) |
| 1236 | qd_unlock(qda[x]); |
| 1237 | } |
| 1238 | } while (!error && num_qd == max_qd); |
| 1239 | |
Steven Whitehouse | e46c772 | 2013-10-04 12:29:34 +0100 | [diff] [blame] | 1240 | mutex_unlock(&sdp->sd_quota_sync_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1241 | kfree(qda); |
| 1242 | |
| 1243 | return error; |
| 1244 | } |
| 1245 | |
Eric W. Biederman | ed87dab | 2013-01-31 19:42:40 -0800 | [diff] [blame] | 1246 | int gfs2_quota_refresh(struct gfs2_sbd *sdp, struct kqid qid) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1247 | { |
| 1248 | struct gfs2_quota_data *qd; |
| 1249 | struct gfs2_holder q_gh; |
| 1250 | int error; |
| 1251 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1252 | error = qd_get(sdp, qid, &qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1253 | if (error) |
| 1254 | return error; |
| 1255 | |
| 1256 | error = do_glock(qd, FORCE, &q_gh); |
| 1257 | if (!error) |
| 1258 | gfs2_glock_dq_uninit(&q_gh); |
| 1259 | |
| 1260 | qd_put(qd); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1261 | return error; |
| 1262 | } |
| 1263 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1264 | int gfs2_quota_init(struct gfs2_sbd *sdp) |
| 1265 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1266 | struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 1267 | u64 size = i_size_read(sdp->sd_qc_inode); |
| 1268 | unsigned int blocks = size >> sdp->sd_sb.sb_bsize_shift; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1269 | unsigned int x, slot = 0; |
| 1270 | unsigned int found = 0; |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 1271 | unsigned int hash; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1272 | u64 dblock; |
| 1273 | u32 extlen = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1274 | int error; |
| 1275 | |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 1276 | if (gfs2_check_internal_file_size(sdp->sd_qc_inode, 1, 64 << 20)) |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 1277 | return -EIO; |
Steven Whitehouse | a2e0f79 | 2010-08-11 09:53:11 +0100 | [diff] [blame] | 1278 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1279 | sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 1280 | 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] | 1281 | |
| 1282 | error = -ENOMEM; |
| 1283 | |
| 1284 | sdp->sd_quota_bitmap = kcalloc(sdp->sd_quota_chunks, |
Josef Bacik | 16c5f06 | 2008-04-09 09:33:41 -0400 | [diff] [blame] | 1285 | sizeof(unsigned char *), GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1286 | if (!sdp->sd_quota_bitmap) |
| 1287 | return error; |
| 1288 | |
| 1289 | for (x = 0; x < sdp->sd_quota_chunks; x++) { |
Josef Bacik | 16c5f06 | 2008-04-09 09:33:41 -0400 | [diff] [blame] | 1290 | sdp->sd_quota_bitmap[x] = kzalloc(PAGE_SIZE, GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1291 | if (!sdp->sd_quota_bitmap[x]) |
| 1292 | goto fail; |
| 1293 | } |
| 1294 | |
| 1295 | for (x = 0; x < blocks; x++) { |
| 1296 | struct buffer_head *bh; |
Steven Whitehouse | 7aed98f | 2013-11-26 15:17:09 +0000 | [diff] [blame] | 1297 | const struct gfs2_quota_change *qc; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1298 | unsigned int y; |
| 1299 | |
| 1300 | if (!extlen) { |
| 1301 | int new = 0; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1302 | error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1303 | if (error) |
| 1304 | goto fail; |
| 1305 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1306 | error = -EIO; |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 1307 | bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); |
| 1308 | if (!bh) |
| 1309 | goto fail; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1310 | if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) { |
| 1311 | brelse(bh); |
| 1312 | goto fail; |
| 1313 | } |
| 1314 | |
Steven Whitehouse | 7aed98f | 2013-11-26 15:17:09 +0000 | [diff] [blame] | 1315 | qc = (const struct gfs2_quota_change *)(bh->b_data + sizeof(struct gfs2_meta_header)); |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 1316 | 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] | 1317 | y++, slot++) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1318 | struct gfs2_quota_data *qd; |
Steven Whitehouse | 7aed98f | 2013-11-26 15:17:09 +0000 | [diff] [blame] | 1319 | s64 qc_change = be64_to_cpu(qc->qc_change); |
| 1320 | u32 qc_flags = be32_to_cpu(qc->qc_flags); |
| 1321 | enum quota_type qtype = (qc_flags & GFS2_QCF_USER) ? |
| 1322 | USRQUOTA : GRPQUOTA; |
| 1323 | struct kqid qc_id = make_kqid(&init_user_ns, qtype, |
| 1324 | be32_to_cpu(qc->qc_id)); |
| 1325 | qc++; |
| 1326 | if (!qc_change) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1327 | continue; |
| 1328 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 1329 | hash = gfs2_qd_hash(sdp, qc_id); |
| 1330 | qd = qd_alloc(hash, sdp, qc_id); |
| 1331 | if (qd == NULL) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1332 | brelse(bh); |
| 1333 | goto fail; |
| 1334 | } |
| 1335 | |
| 1336 | set_bit(QDF_CHANGE, &qd->qd_flags); |
Steven Whitehouse | 7aed98f | 2013-11-26 15:17:09 +0000 | [diff] [blame] | 1337 | qd->qd_change = qc_change; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1338 | qd->qd_slot = slot; |
| 1339 | qd->qd_slot_count = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1340 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1341 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1342 | gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1); |
| 1343 | list_add(&qd->qd_list, &sdp->sd_quota_list); |
| 1344 | atomic_inc(&sdp->sd_quota_count); |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1345 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1346 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 1347 | spin_lock_bucket(hash); |
| 1348 | hlist_bl_add_head_rcu(&qd->qd_hlist, &qd_hash_table[hash]); |
| 1349 | spin_unlock_bucket(hash); |
| 1350 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1351 | found++; |
| 1352 | } |
| 1353 | |
| 1354 | brelse(bh); |
| 1355 | dblock++; |
| 1356 | extlen--; |
| 1357 | } |
| 1358 | |
| 1359 | if (found) |
| 1360 | fs_info(sdp, "found %u quota changes\n", found); |
| 1361 | |
| 1362 | return 0; |
| 1363 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1364 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1365 | gfs2_quota_cleanup(sdp); |
| 1366 | return error; |
| 1367 | } |
| 1368 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1369 | void gfs2_quota_cleanup(struct gfs2_sbd *sdp) |
| 1370 | { |
| 1371 | struct list_head *head = &sdp->sd_quota_list; |
| 1372 | struct gfs2_quota_data *qd; |
| 1373 | unsigned int x; |
| 1374 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1375 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1376 | while (!list_empty(head)) { |
| 1377 | qd = list_entry(head->prev, struct gfs2_quota_data, qd_list); |
| 1378 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 1379 | list_del(&qd->qd_list); |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 1380 | |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 1381 | /* Also remove if this qd exists in the reclaim list */ |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 1382 | list_lru_del(&gfs2_qd_lru, &qd->qd_lru); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 1383 | atomic_dec(&sdp->sd_quota_count); |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1384 | spin_unlock(&qd_lock); |
Abhijith Das | 0a7ab79 | 2009-01-07 16:03:37 -0600 | [diff] [blame] | 1385 | |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 1386 | spin_lock_bucket(qd->qd_hash); |
| 1387 | hlist_bl_del_rcu(&qd->qd_hlist); |
| 1388 | spin_unlock_bucket(qd->qd_hash); |
| 1389 | |
Steven Whitehouse | 8ad151c | 2013-12-12 11:34:09 +0000 | [diff] [blame^] | 1390 | gfs2_assert_warn(sdp, !qd->qd_change); |
| 1391 | gfs2_assert_warn(sdp, !qd->qd_slot_count); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1392 | gfs2_assert_warn(sdp, !qd->qd_bh_count); |
| 1393 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1394 | gfs2_glock_put(qd->qd_gl); |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 1395 | call_rcu(&qd->qd_rcu, gfs2_qd_dealloc); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1396 | |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1397 | spin_lock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1398 | } |
Steven Whitehouse | 7d80823 | 2013-11-01 14:52:08 -0400 | [diff] [blame] | 1399 | spin_unlock(&qd_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1400 | |
| 1401 | gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count)); |
| 1402 | |
| 1403 | if (sdp->sd_quota_bitmap) { |
| 1404 | for (x = 0; x < sdp->sd_quota_chunks; x++) |
| 1405 | kfree(sdp->sd_quota_bitmap[x]); |
| 1406 | kfree(sdp->sd_quota_bitmap); |
| 1407 | } |
| 1408 | } |
| 1409 | |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1410 | static void quotad_error(struct gfs2_sbd *sdp, const char *msg, int error) |
| 1411 | { |
| 1412 | if (error == 0 || error == -EROFS) |
| 1413 | return; |
| 1414 | if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
| 1415 | fs_err(sdp, "gfs2_quotad: %s error %d\n", msg, error); |
| 1416 | } |
| 1417 | |
| 1418 | static void quotad_check_timeo(struct gfs2_sbd *sdp, const char *msg, |
Steven Whitehouse | 8c42d63 | 2009-09-11 14:36:44 +0100 | [diff] [blame] | 1419 | int (*fxn)(struct super_block *sb, int type), |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1420 | unsigned long t, unsigned long *timeo, |
| 1421 | unsigned int *new_timeo) |
| 1422 | { |
| 1423 | if (t >= *timeo) { |
Steven Whitehouse | 8c42d63 | 2009-09-11 14:36:44 +0100 | [diff] [blame] | 1424 | int error = fxn(sdp->sd_vfs, 0); |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1425 | quotad_error(sdp, msg, error); |
| 1426 | *timeo = gfs2_tune_get_i(&sdp->sd_tune, new_timeo) * HZ; |
| 1427 | } else { |
| 1428 | *timeo -= t; |
| 1429 | } |
| 1430 | } |
| 1431 | |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1432 | static void quotad_check_trunc_list(struct gfs2_sbd *sdp) |
| 1433 | { |
| 1434 | struct gfs2_inode *ip; |
| 1435 | |
| 1436 | while(1) { |
| 1437 | ip = NULL; |
| 1438 | spin_lock(&sdp->sd_trunc_lock); |
| 1439 | if (!list_empty(&sdp->sd_trunc_list)) { |
| 1440 | ip = list_entry(sdp->sd_trunc_list.next, |
| 1441 | struct gfs2_inode, i_trunc_list); |
| 1442 | list_del_init(&ip->i_trunc_list); |
| 1443 | } |
| 1444 | spin_unlock(&sdp->sd_trunc_lock); |
| 1445 | if (ip == NULL) |
| 1446 | return; |
| 1447 | gfs2_glock_finish_truncate(ip); |
| 1448 | } |
| 1449 | } |
| 1450 | |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1451 | void gfs2_wake_up_statfs(struct gfs2_sbd *sdp) { |
| 1452 | if (!sdp->sd_statfs_force_sync) { |
| 1453 | sdp->sd_statfs_force_sync = 1; |
| 1454 | wake_up(&sdp->sd_quota_wait); |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1459 | /** |
| 1460 | * gfs2_quotad - Write cached quota changes into the quota file |
| 1461 | * @sdp: Pointer to GFS2 superblock |
| 1462 | * |
| 1463 | */ |
| 1464 | |
| 1465 | int gfs2_quotad(void *data) |
| 1466 | { |
| 1467 | struct gfs2_sbd *sdp = data; |
| 1468 | struct gfs2_tune *tune = &sdp->sd_tune; |
| 1469 | unsigned long statfs_timeo = 0; |
| 1470 | unsigned long quotad_timeo = 0; |
| 1471 | unsigned long t = 0; |
| 1472 | DEFINE_WAIT(wait); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1473 | int empty; |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1474 | |
| 1475 | while (!kthread_should_stop()) { |
| 1476 | |
| 1477 | /* Update the master statfs file */ |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1478 | if (sdp->sd_statfs_force_sync) { |
| 1479 | int error = gfs2_statfs_sync(sdp->sd_vfs, 0); |
| 1480 | quotad_error(sdp, "statfs", error); |
| 1481 | statfs_timeo = gfs2_tune_get(sdp, gt_statfs_quantum) * HZ; |
| 1482 | } |
| 1483 | else |
| 1484 | quotad_check_timeo(sdp, "statfs", gfs2_statfs_sync, t, |
| 1485 | &statfs_timeo, |
| 1486 | &tune->gt_statfs_quantum); |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1487 | |
| 1488 | /* Update quota file */ |
Steven Whitehouse | edd2e9a | 2013-06-03 11:12:59 +0100 | [diff] [blame] | 1489 | quotad_check_timeo(sdp, "sync", gfs2_quota_sync, t, |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1490 | "ad_timeo, &tune->gt_quota_quantum); |
| 1491 | |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1492 | /* Check for & recover partially truncated inodes */ |
| 1493 | quotad_check_trunc_list(sdp); |
| 1494 | |
Tejun Heo | a0acae0 | 2011-11-21 12:32:22 -0800 | [diff] [blame] | 1495 | try_to_freeze(); |
| 1496 | |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1497 | t = min(quotad_timeo, statfs_timeo); |
| 1498 | |
Steven Whitehouse | 7fa5d20 | 2009-03-31 15:49:08 +0100 | [diff] [blame] | 1499 | prepare_to_wait(&sdp->sd_quota_wait, &wait, TASK_INTERRUPTIBLE); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1500 | spin_lock(&sdp->sd_trunc_lock); |
| 1501 | empty = list_empty(&sdp->sd_trunc_list); |
| 1502 | spin_unlock(&sdp->sd_trunc_lock); |
Benjamin Marzinski | 3d3c10f | 2009-10-20 02:39:44 -0500 | [diff] [blame] | 1503 | if (empty && !sdp->sd_statfs_force_sync) |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1504 | t -= schedule_timeout(t); |
| 1505 | else |
| 1506 | t = 0; |
Steven Whitehouse | 37b2c83 | 2008-11-17 14:25:37 +0000 | [diff] [blame] | 1507 | finish_wait(&sdp->sd_quota_wait, &wait); |
| 1508 | } |
| 1509 | |
| 1510 | return 0; |
| 1511 | } |
| 1512 | |
Steven Whitehouse | 1d371b5 | 2009-09-11 15:57:27 +0100 | [diff] [blame] | 1513 | static int gfs2_quota_get_xstate(struct super_block *sb, |
| 1514 | struct fs_quota_stat *fqs) |
| 1515 | { |
| 1516 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1517 | |
| 1518 | memset(fqs, 0, sizeof(struct fs_quota_stat)); |
| 1519 | fqs->qs_version = FS_QSTAT_VERSION; |
Christoph Hellwig | ad6bb90 | 2010-05-05 00:10:56 +0200 | [diff] [blame] | 1520 | |
| 1521 | switch (sdp->sd_args.ar_quota) { |
| 1522 | case GFS2_QUOTA_ON: |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 1523 | fqs->qs_flags |= (FS_QUOTA_UDQ_ENFD | FS_QUOTA_GDQ_ENFD); |
Christoph Hellwig | ad6bb90 | 2010-05-05 00:10:56 +0200 | [diff] [blame] | 1524 | /*FALLTHRU*/ |
| 1525 | case GFS2_QUOTA_ACCOUNT: |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 1526 | fqs->qs_flags |= (FS_QUOTA_UDQ_ACCT | FS_QUOTA_GDQ_ACCT); |
Christoph Hellwig | ad6bb90 | 2010-05-05 00:10:56 +0200 | [diff] [blame] | 1527 | break; |
| 1528 | case GFS2_QUOTA_OFF: |
| 1529 | break; |
| 1530 | } |
| 1531 | |
Steven Whitehouse | 1d371b5 | 2009-09-11 15:57:27 +0100 | [diff] [blame] | 1532 | if (sdp->sd_quota_inode) { |
| 1533 | fqs->qs_uquota.qfs_ino = GFS2_I(sdp->sd_quota_inode)->i_no_addr; |
| 1534 | fqs->qs_uquota.qfs_nblks = sdp->sd_quota_inode->i_blocks; |
| 1535 | } |
| 1536 | fqs->qs_uquota.qfs_nextents = 1; /* unsupported */ |
| 1537 | fqs->qs_gquota = fqs->qs_uquota; /* its the same inode in both cases */ |
Steven Whitehouse | 2147dbf | 2013-11-04 10:15:08 +0000 | [diff] [blame] | 1538 | fqs->qs_incoredqs = list_lru_count(&gfs2_qd_lru); |
Steven Whitehouse | 1d371b5 | 2009-09-11 15:57:27 +0100 | [diff] [blame] | 1539 | return 0; |
| 1540 | } |
| 1541 | |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 1542 | static int gfs2_get_dqblk(struct super_block *sb, struct kqid qid, |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 1543 | struct fs_disk_quota *fdq) |
Steven Whitehouse | 113d6b3 | 2009-09-28 11:52:16 +0100 | [diff] [blame] | 1544 | { |
| 1545 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1546 | struct gfs2_quota_lvb *qlvb; |
| 1547 | struct gfs2_quota_data *qd; |
| 1548 | struct gfs2_holder q_gh; |
| 1549 | int error; |
| 1550 | |
| 1551 | memset(fdq, 0, sizeof(struct fs_disk_quota)); |
| 1552 | |
| 1553 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) |
| 1554 | return -ESRCH; /* Crazy XFS error code */ |
| 1555 | |
Eric W. Biederman | 236c64e | 2013-01-31 20:09:30 -0800 | [diff] [blame] | 1556 | if ((qid.type != USRQUOTA) && |
| 1557 | (qid.type != GRPQUOTA)) |
Steven Whitehouse | 113d6b3 | 2009-09-28 11:52:16 +0100 | [diff] [blame] | 1558 | return -EINVAL; |
| 1559 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1560 | error = qd_get(sdp, qid, &qd); |
Steven Whitehouse | 113d6b3 | 2009-09-28 11:52:16 +0100 | [diff] [blame] | 1561 | if (error) |
| 1562 | return error; |
| 1563 | error = do_glock(qd, FORCE, &q_gh); |
| 1564 | if (error) |
| 1565 | goto out; |
| 1566 | |
David Teigland | 4e2f884 | 2012-11-14 13:47:37 -0500 | [diff] [blame] | 1567 | qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; |
Steven Whitehouse | 113d6b3 | 2009-09-28 11:52:16 +0100 | [diff] [blame] | 1568 | fdq->d_version = FS_DQUOT_VERSION; |
Eric W. Biederman | 236c64e | 2013-01-31 20:09:30 -0800 | [diff] [blame] | 1569 | fdq->d_flags = (qid.type == USRQUOTA) ? FS_USER_QUOTA : FS_GROUP_QUOTA; |
Eric W. Biederman | 558e852 | 2013-01-31 18:15:33 -0800 | [diff] [blame] | 1570 | fdq->d_id = from_kqid_munged(current_user_ns(), qid); |
Abhijith Das | 14870b4 | 2010-11-18 11:24:24 -0500 | [diff] [blame] | 1571 | fdq->d_blk_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_fsb2bb_shift; |
| 1572 | fdq->d_blk_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_fsb2bb_shift; |
| 1573 | fdq->d_bcount = be64_to_cpu(qlvb->qb_value) << sdp->sd_fsb2bb_shift; |
Steven Whitehouse | 113d6b3 | 2009-09-28 11:52:16 +0100 | [diff] [blame] | 1574 | |
| 1575 | gfs2_glock_dq_uninit(&q_gh); |
| 1576 | out: |
| 1577 | qd_put(qd); |
| 1578 | return error; |
| 1579 | } |
| 1580 | |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1581 | /* GFS2 only supports a subset of the XFS fields */ |
Abhijith Das | 802ec9b | 2010-11-18 11:26:46 -0500 | [diff] [blame] | 1582 | #define GFS2_FIELDMASK (FS_DQ_BSOFT|FS_DQ_BHARD|FS_DQ_BCOUNT) |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1583 | |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 1584 | static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid, |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 1585 | struct fs_disk_quota *fdq) |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1586 | { |
| 1587 | struct gfs2_sbd *sdp = sb->s_fs_info; |
| 1588 | struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); |
| 1589 | struct gfs2_quota_data *qd; |
| 1590 | struct gfs2_holder q_gh, i_gh; |
| 1591 | unsigned int data_blocks, ind_blocks; |
| 1592 | unsigned int blocks = 0; |
| 1593 | int alloc_required; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1594 | loff_t offset; |
| 1595 | int error; |
| 1596 | |
| 1597 | if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) |
| 1598 | return -ESRCH; /* Crazy XFS error code */ |
| 1599 | |
Eric W. Biederman | 236c64e | 2013-01-31 20:09:30 -0800 | [diff] [blame] | 1600 | if ((qid.type != USRQUOTA) && |
| 1601 | (qid.type != GRPQUOTA)) |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1602 | return -EINVAL; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1603 | |
| 1604 | if (fdq->d_fieldmask & ~GFS2_FIELDMASK) |
| 1605 | return -EINVAL; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1606 | |
Eric W. Biederman | 05e0a60 | 2013-01-31 19:52:08 -0800 | [diff] [blame] | 1607 | error = qd_get(sdp, qid, &qd); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1608 | if (error) |
| 1609 | return error; |
| 1610 | |
Bob Peterson | 0a305e4 | 2012-06-06 11:17:59 +0100 | [diff] [blame] | 1611 | error = gfs2_rs_alloc(ip); |
| 1612 | if (error) |
| 1613 | goto out_put; |
| 1614 | |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1615 | mutex_lock(&ip->i_inode.i_mutex); |
| 1616 | error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_EXCLUSIVE, 0, &q_gh); |
| 1617 | if (error) |
Bob Peterson | 0a305e4 | 2012-06-06 11:17:59 +0100 | [diff] [blame] | 1618 | goto out_unlockput; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1619 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
| 1620 | if (error) |
| 1621 | goto out_q; |
| 1622 | |
| 1623 | /* Check for existing entry, if none then alloc new blocks */ |
| 1624 | error = update_qd(sdp, qd); |
| 1625 | if (error) |
| 1626 | goto out_i; |
| 1627 | |
| 1628 | /* If nothing has changed, this is a no-op */ |
| 1629 | if ((fdq->d_fieldmask & FS_DQ_BSOFT) && |
Abhijith Das | 14870b4 | 2010-11-18 11:24:24 -0500 | [diff] [blame] | 1630 | ((fdq->d_blk_softlimit >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_warn))) |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1631 | fdq->d_fieldmask ^= FS_DQ_BSOFT; |
Abhijith Das | 802ec9b | 2010-11-18 11:26:46 -0500 | [diff] [blame] | 1632 | |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1633 | if ((fdq->d_fieldmask & FS_DQ_BHARD) && |
Abhijith Das | 14870b4 | 2010-11-18 11:24:24 -0500 | [diff] [blame] | 1634 | ((fdq->d_blk_hardlimit >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_limit))) |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1635 | fdq->d_fieldmask ^= FS_DQ_BHARD; |
Abhijith Das | 802ec9b | 2010-11-18 11:26:46 -0500 | [diff] [blame] | 1636 | |
| 1637 | if ((fdq->d_fieldmask & FS_DQ_BCOUNT) && |
| 1638 | ((fdq->d_bcount >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_value))) |
| 1639 | fdq->d_fieldmask ^= FS_DQ_BCOUNT; |
| 1640 | |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1641 | if (fdq->d_fieldmask == 0) |
| 1642 | goto out_i; |
| 1643 | |
| 1644 | offset = qd2offset(qd); |
Bob Peterson | 461cb41 | 2010-06-24 19:21:20 -0400 | [diff] [blame] | 1645 | alloc_required = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota)); |
Abhijith Das | e79a46a | 2011-02-07 11:22:41 -0500 | [diff] [blame] | 1646 | if (gfs2_is_stuffed(ip)) |
| 1647 | alloc_required = 1; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1648 | if (alloc_required) { |
Steven Whitehouse | 7b9cff4 | 2013-10-02 11:13:25 +0100 | [diff] [blame] | 1649 | struct gfs2_alloc_parms ap = { .aflags = 0, }; |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1650 | gfs2_write_calc_reserv(ip, sizeof(struct gfs2_quota), |
| 1651 | &data_blocks, &ind_blocks); |
Bob Peterson | 564e12b | 2011-11-21 13:36:17 -0500 | [diff] [blame] | 1652 | blocks = 1 + data_blocks + ind_blocks; |
Steven Whitehouse | 7b9cff4 | 2013-10-02 11:13:25 +0100 | [diff] [blame] | 1653 | ap.target = blocks; |
| 1654 | error = gfs2_inplace_reserve(ip, &ap); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1655 | if (error) |
Bob Peterson | 564e12b | 2011-11-21 13:36:17 -0500 | [diff] [blame] | 1656 | goto out_i; |
Steven Whitehouse | 71f890f | 2012-07-30 14:53:19 +0100 | [diff] [blame] | 1657 | blocks += gfs2_rg_blocks(ip, blocks); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1658 | } |
| 1659 | |
Abhijith Das | e79a46a | 2011-02-07 11:22:41 -0500 | [diff] [blame] | 1660 | /* Some quotas span block boundaries and can update two blocks, |
| 1661 | adding an extra block to the transaction to handle such quotas */ |
| 1662 | error = gfs2_trans_begin(sdp, blocks + RES_DINODE + 2, 0); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1663 | if (error) |
| 1664 | goto out_release; |
| 1665 | |
| 1666 | /* Apply changes */ |
| 1667 | error = gfs2_adjust_quota(ip, offset, 0, qd, fdq); |
| 1668 | |
| 1669 | gfs2_trans_end(sdp); |
| 1670 | out_release: |
Bob Peterson | 564e12b | 2011-11-21 13:36:17 -0500 | [diff] [blame] | 1671 | if (alloc_required) |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1672 | gfs2_inplace_release(ip); |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1673 | out_i: |
| 1674 | gfs2_glock_dq_uninit(&i_gh); |
| 1675 | out_q: |
| 1676 | gfs2_glock_dq_uninit(&q_gh); |
Bob Peterson | 0a305e4 | 2012-06-06 11:17:59 +0100 | [diff] [blame] | 1677 | out_unlockput: |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1678 | mutex_unlock(&ip->i_inode.i_mutex); |
Bob Peterson | 0a305e4 | 2012-06-06 11:17:59 +0100 | [diff] [blame] | 1679 | out_put: |
Steven Whitehouse | e285c10 | 2009-09-23 13:50:49 +0100 | [diff] [blame] | 1680 | qd_put(qd); |
| 1681 | return error; |
| 1682 | } |
| 1683 | |
Steven Whitehouse | cc632e7 | 2009-09-15 09:59:02 +0100 | [diff] [blame] | 1684 | const struct quotactl_ops gfs2_quotactl_ops = { |
| 1685 | .quota_sync = gfs2_quota_sync, |
Steven Whitehouse | 1d371b5 | 2009-09-11 15:57:27 +0100 | [diff] [blame] | 1686 | .get_xstate = gfs2_quota_get_xstate, |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 1687 | .get_dqblk = gfs2_get_dqblk, |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 1688 | .set_dqblk = gfs2_set_dqblk, |
Steven Whitehouse | cc632e7 | 2009-09-15 09:59:02 +0100 | [diff] [blame] | 1689 | }; |
Steven Whitehouse | c754fbb | 2013-12-12 10:47:59 +0000 | [diff] [blame] | 1690 | |
| 1691 | void __init gfs2_quota_hash_init(void) |
| 1692 | { |
| 1693 | unsigned i; |
| 1694 | |
| 1695 | for(i = 0; i < GFS2_QD_HASH_SIZE; i++) |
| 1696 | INIT_HLIST_BL_HEAD(&qd_hash_table[i]); |
| 1697 | } |