| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
#include <linux/errno.h> |
|---|
| 59 |
#include <linux/kernel.h> |
|---|
| 60 |
#include <linux/fs.h> |
|---|
| 61 |
#include <linux/mount.h> |
|---|
| 62 |
#include <linux/mm.h> |
|---|
| 63 |
#include <linux/time.h> |
|---|
| 64 |
#include <linux/types.h> |
|---|
| 65 |
#include <linux/string.h> |
|---|
| 66 |
#include <linux/fcntl.h> |
|---|
| 67 |
#include <linux/stat.h> |
|---|
| 68 |
#include <linux/tty.h> |
|---|
| 69 |
#include <linux/file.h> |
|---|
| 70 |
#include <linux/slab.h> |
|---|
| 71 |
#include <linux/sysctl.h> |
|---|
| 72 |
#include <linux/smp_lock.h> |
|---|
| 73 |
#include <linux/init.h> |
|---|
| 74 |
#include <linux/module.h> |
|---|
| 75 |
#include <linux/proc_fs.h> |
|---|
| 76 |
#include <linux/security.h> |
|---|
| 77 |
#include <linux/kmod.h> |
|---|
| 78 |
#include <linux/pagemap.h> |
|---|
| 79 |
|
|---|
| 80 |
#include <asm/uaccess.h> |
|---|
| 81 |
|
|---|
| 82 |
#define __DQUOT_PARANOIA |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
spinlock_t dq_list_lock = SPIN_LOCK_UNLOCKED; |
|---|
| 120 |
spinlock_t dq_data_lock = SPIN_LOCK_UNLOCKED; |
|---|
| 121 |
|
|---|
| 122 |
static char *quotatypes[] = INITQFNAMES; |
|---|
| 123 |
static struct quota_format_type *quota_formats; |
|---|
| 124 |
static struct quota_module_name module_names[] = INIT_QUOTA_MODULE_NAMES; |
|---|
| 125 |
|
|---|
| 126 |
int register_quota_format(struct quota_format_type *fmt) |
|---|
| 127 |
{ |
|---|
| 128 |
spin_lock(&dq_list_lock); |
|---|
| 129 |
fmt->qf_next = quota_formats; |
|---|
| 130 |
quota_formats = fmt; |
|---|
| 131 |
spin_unlock(&dq_list_lock); |
|---|
| 132 |
return 0; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
void unregister_quota_format(struct quota_format_type *fmt) |
|---|
| 136 |
{ |
|---|
| 137 |
struct quota_format_type **actqf; |
|---|
| 138 |
|
|---|
| 139 |
spin_lock(&dq_list_lock); |
|---|
| 140 |
for (actqf = "a_formats; *actqf && *actqf != fmt; actqf = &(*actqf)->qf_next); |
|---|
| 141 |
if (*actqf) |
|---|
| 142 |
*actqf = (*actqf)->qf_next; |
|---|
| 143 |
spin_unlock(&dq_list_lock); |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
static struct quota_format_type *find_quota_format(int id) |
|---|
| 147 |
{ |
|---|
| 148 |
struct quota_format_type *actqf; |
|---|
| 149 |
|
|---|
| 150 |
spin_lock(&dq_list_lock); |
|---|
| 151 |
for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next); |
|---|
| 152 |
if (!actqf || !try_module_get(actqf->qf_owner)) { |
|---|
| 153 |
int qm; |
|---|
| 154 |
|
|---|
| 155 |
spin_unlock(&dq_list_lock); |
|---|
| 156 |
|
|---|
| 157 |
for (qm = 0; module_names[qm].qm_fmt_id && module_names[qm].qm_fmt_id != id; qm++); |
|---|
| 158 |
if (!module_names[qm].qm_fmt_id || request_module(module_names[qm].qm_mod_name)) |
|---|
| 159 |
return NULL; |
|---|
| 160 |
|
|---|
| 161 |
spin_lock(&dq_list_lock); |
|---|
| 162 |
for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next); |
|---|
| 163 |
if (actqf && !try_module_get(actqf->qf_owner)) |
|---|
| 164 |
actqf = NULL; |
|---|
| 165 |
} |
|---|
| 166 |
spin_unlock(&dq_list_lock); |
|---|
| 167 |
return actqf; |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
static void put_quota_format(struct quota_format_type *fmt) |
|---|
| 171 |
{ |
|---|
| 172 |
module_put(fmt->qf_owner); |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
static LIST_HEAD(inuse_list); |
|---|
| 197 |
static LIST_HEAD(free_dquots); |
|---|
| 198 |
unsigned int dq_hash_bits, dq_hash_mask; |
|---|
| 199 |
static struct hlist_head *dquot_hash; |
|---|
| 200 |
|
|---|
| 201 |
struct dqstats dqstats; |
|---|
| 202 |
|
|---|
| 203 |
static void dqput(struct dquot *dquot); |
|---|
| 204 |
|
|---|
| 205 |
static inline int const hashfn(struct super_block *sb, unsigned int id, int type) |
|---|
| 206 |
{ |
|---|
| 207 |
unsigned long tmp = (((unsigned long)sb>>L1_CACHE_SHIFT) ^ id) * (MAXQUOTAS - type); |
|---|
| 208 |
return (tmp + (tmp >> dq_hash_bits)) & dq_hash_mask; |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
static inline void insert_dquot_hash(struct dquot *dquot) |
|---|
| 215 |
{ |
|---|
| 216 |
struct hlist_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type); |
|---|
| 217 |
hlist_add_head(&dquot->dq_hash, head); |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
static inline void remove_dquot_hash(struct dquot *dquot) |
|---|
| 221 |
{ |
|---|
| 222 |
hlist_del_init(&dquot->dq_hash); |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type) |
|---|
| 226 |
{ |
|---|
| 227 |
struct hlist_node *node; |
|---|
| 228 |
struct dquot *dquot; |
|---|
| 229 |
|
|---|
| 230 |
hlist_for_each (node, dquot_hash+hashent) { |
|---|
| 231 |
dquot = hlist_entry(node, struct dquot, dq_hash); |
|---|
| 232 |
if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type) |
|---|
| 233 |
return dquot; |
|---|
| 234 |
} |
|---|
| 235 |
return NODQUOT; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
static inline void put_dquot_last(struct dquot *dquot) |
|---|
| 240 |
{ |
|---|
| 241 |
list_add(&dquot->dq_free, free_dquots.prev); |
|---|
| 242 |
dqstats.free_dquots++; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
static inline void remove_free_dquot(struct dquot *dquot) |
|---|
| 246 |
{ |
|---|
| 247 |
if (list_empty(&dquot->dq_free)) |
|---|
| 248 |
return; |
|---|
| 249 |
list_del_init(&dquot->dq_free); |
|---|
| 250 |
dqstats.free_dquots--; |
|---|
| 251 |
} |
|---|
| 252 |
|
|---|
| 253 |
static inline void put_inuse(struct dquot *dquot) |
|---|
| 254 |
{ |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
list_add(&dquot->dq_inuse, inuse_list.prev); |
|---|
| 258 |
dqstats.allocated_dquots++; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
static inline void remove_inuse(struct dquot *dquot) |
|---|
| 262 |
{ |
|---|
| 263 |
dqstats.allocated_dquots--; |
|---|
| 264 |
list_del(&dquot->dq_inuse); |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
static void wait_on_dquot(struct dquot *dquot) |
|---|
| 271 |
{ |
|---|
| 272 |
down(&dquot->dq_lock); |
|---|
| 273 |
up(&dquot->dq_lock); |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
#define mark_dquot_dirty(dquot) ((dquot)->dq_sb->dq_op->mark_dirty(dquot)) |
|---|
| 277 |
|
|---|
| 278 |
int dquot_mark_dquot_dirty(struct dquot *dquot) |
|---|
| 279 |
{ |
|---|
| 280 |
spin_lock(&dq_list_lock); |
|---|
| 281 |
if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) |
|---|
| 282 |
list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)-> |
|---|
| 283 |
info[dquot->dq_type].dqi_dirty_list); |
|---|
| 284 |
spin_unlock(&dq_list_lock); |
|---|
| 285 |
return 0; |
|---|
| 286 |
} |
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
static inline int clear_dquot_dirty(struct dquot *dquot) |
|---|
| 290 |
{ |
|---|
| 291 |
if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags)) |
|---|
| 292 |
return 0; |
|---|
| 293 |
list_del_init(&dquot->dq_dirty); |
|---|
| 294 |
return 1; |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|
| 297 |
void mark_info_dirty(struct super_block *sb, int type) |
|---|
| 298 |
{ |
|---|
| 299 |
set_bit(DQF_INFO_DIRTY_B, &sb_dqopt(sb)->info[type].dqi_flags); |
|---|
| 300 |
} |
|---|
| 301 |
EXPORT_SYMBOL(mark_info_dirty); |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
int dquot_acquire(struct dquot *dquot) |
|---|
| 308 |
{ |
|---|
| 309 |
int ret = 0, ret2 = 0; |
|---|
| 310 |
struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
|---|
| 311 |
|
|---|
| 312 |
down(&dquot->dq_lock); |
|---|
| 313 |
down(&dqopt->dqio_sem); |
|---|
| 314 |
if (!test_bit(DQ_READ_B, &dquot->dq_flags)) |
|---|
| 315 |
ret = dqopt->ops[dquot->dq_type]->read_dqblk(dquot); |
|---|
| 316 |
if (ret < 0) |
|---|
| 317 |
goto out_iolock; |
|---|
| 318 |
set_bit(DQ_READ_B, &dquot->dq_flags); |
|---|
| 319 |
|
|---|
| 320 |
if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) { |
|---|
| 321 |
ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); |
|---|
| 322 |
|
|---|
| 323 |
if (info_dirty(&dqopt->info[dquot->dq_type])) |
|---|
| 324 |
ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); |
|---|
| 325 |
if (ret < 0) |
|---|
| 326 |
goto out_iolock; |
|---|
| 327 |
if (ret2 < 0) { |
|---|
| 328 |
ret = ret2; |
|---|
| 329 |
goto out_iolock; |
|---|
| 330 |
} |
|---|
| 331 |
} |
|---|
| 332 |
set_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
|---|
| 333 |
out_iolock: |
|---|
| 334 |
up(&dqopt->dqio_sem); |
|---|
| 335 |
up(&dquot->dq_lock); |
|---|
| 336 |
return ret; |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
int dquot_commit(struct dquot *dquot) |
|---|
| 343 |
{ |
|---|
| 344 |
int ret = 0, ret2 = 0; |
|---|
| 345 |
struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
|---|
| 346 |
|
|---|
| 347 |
down(&dqopt->dqio_sem); |
|---|
| 348 |
spin_lock(&dq_list_lock); |
|---|
| 349 |
if (!clear_dquot_dirty(dquot)) { |
|---|
| 350 |
spin_unlock(&dq_list_lock); |
|---|
| 351 |
goto out_sem; |
|---|
| 352 |
} |
|---|
| 353 |
spin_unlock(&dq_list_lock); |
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
|---|
| 357 |
ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); |
|---|
| 358 |
if (info_dirty(&dqopt->info[dquot->dq_type])) |
|---|
| 359 |
ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); |
|---|
| 360 |
if (ret >= 0) |
|---|
| 361 |
ret = ret2; |
|---|
| 362 |
} |
|---|
| 363 |
out_sem: |
|---|
| 364 |
up(&dqopt->dqio_sem); |
|---|
| 365 |
return ret; |
|---|
| 366 |
} |
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
int dquot_release(struct dquot *dquot) |
|---|
| 372 |
{ |
|---|
| 373 |
int ret = 0, ret2 = 0; |
|---|
| 374 |
struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
|---|
| 375 |
|
|---|
| 376 |
down(&dquot->dq_lock); |
|---|
| 377 |
|
|---|
| 378 |
if (atomic_read(&dquot->dq_count) > 1) |
|---|
| 379 |
goto out_dqlock; |
|---|
| 380 |
down(&dqopt->dqio_sem); |
|---|
| 381 |
if (dqopt->ops[dquot->dq_type]->release_dqblk) { |
|---|
| 382 |
ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot); |
|---|
| 383 |
|
|---|
| 384 |
if (info_dirty(&dqopt->info[dquot->dq_type])) |
|---|
| 385 |
ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); |
|---|
| 386 |
if (ret >= 0) |
|---|
| 387 |
ret = ret2; |
|---|
| 388 |
} |
|---|
| 389 |
clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
|---|
| 390 |
up(&dqopt->dqio_sem); |
|---|
| 391 |
out_dqlock: |
|---|
| 392 |
up(&dquot->dq_lock); |
|---|
| 393 |
return ret; |
|---|
| 394 |
} |
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
static void invalidate_dquots(struct super_block *sb, int type) |
|---|
| 401 |
{ |
|---|
| 402 |
struct dquot *dquot; |
|---|
| 403 |
struct list_head *head; |
|---|
| 404 |
|
|---|
| 405 |
spin_lock(&dq_list_lock); |
|---|
| 406 |
for (head = inuse_list.next; head != &inuse_list;) { |
|---|
| 407 |
dquot = list_entry(head, struct dquot, dq_inuse); |
|---|
| 408 |
head = head->next; |
|---|
| 409 |
if (dquot->dq_sb != sb) |
|---|
| 410 |
continue; |
|---|
| 411 |
if (dquot->dq_type != type) |
|---|
| 412 |
continue; |
|---|
| 413 |
#ifdef __DQUOT_PARANOIA |
|---|
| 414 |
if (atomic_read(&dquot->dq_count)) |
|---|
| 415 |
BUG(); |
|---|
| 416 |
#endif |
|---|
| 417 |
|
|---|
| 418 |
remove_dquot_hash(dquot); |
|---|
| 419 |
remove_free_dquot(dquot); |
|---|
| 420 |
remove_inuse(dquot); |
|---|
| 421 |
kmem_cache_free(dquot_cachep, dquot); |
|---|
| 422 |
} |
|---|
| 423 |
spin_unlock(&dq_list_lock); |
|---|
| 424 |
} |
|---|
| 425 |
|
|---|
| 426 |
int vfs_quota_sync(struct super_block *sb, int type) |
|---|
| 427 |
{ |
|---|
| 428 |
struct list_head *dirty; |
|---|
| 429 |
struct dquot *dquot; |
|---|
| 430 |
struct quota_info *dqopt = sb_dqopt(sb); |
|---|
| 431 |
int cnt; |
|---|
| 432 |
|
|---|
| 433 |
down(&dqopt->dqonoff_sem); |
|---|
| 434 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 435 |
if (type != -1 && cnt != type) |
|---|
| 436 |
continue; |
|---|
| 437 |
if (!sb_has_quota_enabled(sb, cnt)) |
|---|
| 438 |
continue; |
|---|
| 439 |
spin_lock(&dq_list_lock); |
|---|
| 440 |
dirty = &dqopt->info[cnt].dqi_dirty_list; |
|---|
| 441 |
while (!list_empty(dirty)) { |
|---|
| 442 |
dquot = list_entry(dirty->next, struct dquot, dq_dirty); |
|---|
| 443 |
|
|---|
| 444 |
if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
|---|
| 445 |
clear_dquot_dirty(dquot); |
|---|
| 446 |
continue; |
|---|
| 447 |
} |
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
atomic_inc(&dquot->dq_count); |
|---|
| 452 |
dqstats.lookups++; |
|---|
| 453 |
spin_unlock(&dq_list_lock); |
|---|
| 454 |
sb->dq_op->write_dquot(dquot); |
|---|
| 455 |
dqput(dquot); |
|---|
| 456 |
spin_lock(&dq_list_lock); |
|---|
| 457 |
} |
|---|
| 458 |
spin_unlock(&dq_list_lock); |
|---|
| 459 |
} |
|---|
| 460 |
|
|---|
| 461 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 462 |
if ((cnt == type || type == -1) && sb_has_quota_enabled(sb, cnt) |
|---|
| 463 |
&& info_dirty(&dqopt->info[cnt])) |
|---|
| 464 |
sb->dq_op->write_info(sb, cnt); |
|---|
| 465 |
spin_lock(&dq_list_lock); |
|---|
| 466 |
dqstats.syncs++; |
|---|
| 467 |
spin_unlock(&dq_list_lock); |
|---|
| 468 |
up(&dqopt->dqonoff_sem); |
|---|
| 469 |
|
|---|
| 470 |
return 0; |
|---|
| 471 |
} |
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
static void prune_dqcache(int count) |
|---|
| 475 |
{ |
|---|
| 476 |
struct list_head *head; |
|---|
| 477 |
struct dquot *dquot; |
|---|
| 478 |
|
|---|
| 479 |
head = free_dquots.prev; |
|---|
| 480 |
while (head != &free_dquots && count) { |
|---|
| 481 |
dquot = list_entry(head, struct dquot, dq_free); |
|---|
| 482 |
remove_dquot_hash(dquot); |
|---|
| 483 |
remove_free_dquot(dquot); |
|---|
| 484 |
remove_inuse(dquot); |
|---|
| 485 |
kmem_cache_free(dquot_cachep, dquot); |
|---|
| 486 |
count--; |
|---|
| 487 |
head = free_dquots.prev; |
|---|
| 488 |
} |
|---|
| 489 |
} |
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
static int shrink_dqcache_memory(int nr, unsigned int gfp_mask) |
|---|
| 497 |
{ |
|---|
| 498 |
int ret; |
|---|
| 499 |
|
|---|
| 500 |
spin_lock(&dq_list_lock); |
|---|
| 501 |
if (nr) |
|---|
| 502 |
prune_dqcache(nr); |
|---|
| 503 |
ret = dqstats.allocated_dquots; |
|---|
| 504 |
spin_unlock(&dq_list_lock); |
|---|
| 505 |
return ret; |
|---|
| 506 |
} |
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
static void dqput(struct dquot *dquot) |
|---|
| 514 |
{ |
|---|
| 515 |
if (!dquot) |
|---|
| 516 |
return; |
|---|
| 517 |
#ifdef __DQUOT_PARANOIA |
|---|
| 518 |
if (!atomic_read(&dquot->dq_count)) { |
|---|
| 519 |
printk("VFS: dqput: trying to free free dquot\n"); |
|---|
| 520 |
printk("VFS: device %s, dquot of %s %d\n", |
|---|
| 521 |
dquot->dq_sb->s_id, |
|---|
| 522 |
quotatypes[dquot->dq_type], |
|---|
| 523 |
dquot->dq_id); |
|---|
| 524 |
BUG(); |
|---|
| 525 |
} |
|---|
| 526 |
#endif |
|---|
| 527 |
|
|---|
| 528 |
spin_lock(&dq_list_lock); |
|---|
| 529 |
dqstats.drops++; |
|---|
| 530 |
spin_unlock(&dq_list_lock); |
|---|
| 531 |
we_slept: |
|---|
| 532 |
spin_lock(&dq_list_lock); |
|---|
| 533 |
if (atomic_read(&dquot->dq_count) > 1) { |
|---|
| 534 |
|
|---|
| 535 |
atomic_dec(&dquot->dq_count); |
|---|
| 536 |
spin_unlock(&dq_list_lock); |
|---|
| 537 |
return; |
|---|
| 538 |
} |
|---|
| 539 |
|
|---|
| 540 |
if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && dquot_dirty(dquot)) { |
|---|
| 541 |
spin_unlock(&dq_list_lock); |
|---|
| 542 |
|
|---|
| 543 |
dquot->dq_sb->dq_op->write_dquot(dquot); |
|---|
| 544 |
goto we_slept; |
|---|
| 545 |
} |
|---|
| 546 |
|
|---|
| 547 |
clear_dquot_dirty(dquot); |
|---|
| 548 |
if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
|---|
| 549 |
spin_unlock(&dq_list_lock); |
|---|
| 550 |
dquot->dq_sb->dq_op->release_dquot(dquot); |
|---|
| 551 |
goto we_slept; |
|---|
| 552 |
} |
|---|
| 553 |
atomic_dec(&dquot->dq_count); |
|---|
| 554 |
#ifdef __DQUOT_PARANOIA |
|---|
| 555 |
|
|---|
| 556 |
if (!list_empty(&dquot->dq_free)) |
|---|
| 557 |
BUG(); |
|---|
| 558 |
#endif |
|---|
| 559 |
put_dquot_last(dquot); |
|---|
| 560 |
spin_unlock(&dq_list_lock); |
|---|
| 561 |
} |
|---|
| 562 |
|
|---|
| 563 |
static struct dquot *get_empty_dquot(struct super_block *sb, int type) |
|---|
| 564 |
{ |
|---|
| 565 |
struct dquot *dquot; |
|---|
| 566 |
|
|---|
| 567 |
dquot = kmem_cache_alloc(dquot_cachep, SLAB_NOFS); |
|---|
| 568 |
if(!dquot) |
|---|
| 569 |
return NODQUOT; |
|---|
| 570 |
|
|---|
| 571 |
memset((caddr_t)dquot, 0, sizeof(struct dquot)); |
|---|
| 572 |
sema_init(&dquot->dq_lock, 1); |
|---|
| 573 |
INIT_LIST_HEAD(&dquot->dq_free); |
|---|
| 574 |
INIT_LIST_HEAD(&dquot->dq_inuse); |
|---|
| 575 |
INIT_HLIST_NODE(&dquot->dq_hash); |
|---|
| 576 |
INIT_LIST_HEAD(&dquot->dq_dirty); |
|---|
| 577 |
dquot->dq_sb = sb; |
|---|
| 578 |
dquot->dq_type = type; |
|---|
| 579 |
atomic_set(&dquot->dq_count, 1); |
|---|
| 580 |
|
|---|
| 581 |
return dquot; |
|---|
| 582 |
} |
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
static struct dquot *dqget(struct super_block *sb, unsigned int id, int type) |
|---|
| 589 |
{ |
|---|
| 590 |
unsigned int hashent = hashfn(sb, id, type); |
|---|
| 591 |
struct dquot *dquot, *empty = NODQUOT; |
|---|
| 592 |
|
|---|
| 593 |
if (!sb_has_quota_enabled(sb, type)) |
|---|
| 594 |
return NODQUOT; |
|---|
| 595 |
we_slept: |
|---|
| 596 |
spin_lock(&dq_list_lock); |
|---|
| 597 |
if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) { |
|---|
| 598 |
if (empty == NODQUOT) { |
|---|
| 599 |
spin_unlock(&dq_list_lock); |
|---|
| 600 |
if ((empty = get_empty_dquot(sb, type)) == NODQUOT) |
|---|
| 601 |
schedule(); |
|---|
| 602 |
goto we_slept; |
|---|
| 603 |
} |
|---|
| 604 |
dquot = empty; |
|---|
| 605 |
dquot->dq_id = id; |
|---|
| 606 |
|
|---|
| 607 |
put_inuse(dquot); |
|---|
| 608 |
|
|---|
| 609 |
insert_dquot_hash(dquot); |
|---|
| 610 |
dqstats.lookups++; |
|---|
| 611 |
spin_unlock(&dq_list_lock); |
|---|
| 612 |
} else { |
|---|
| 613 |
if (!atomic_read(&dquot->dq_count)) |
|---|
| 614 |
remove_free_dquot(dquot); |
|---|
| 615 |
atomic_inc(&dquot->dq_count); |
|---|
| 616 |
dqstats.cache_hits++; |
|---|
| 617 |
dqstats.lookups++; |
|---|
| 618 |
spin_unlock(&dq_list_lock); |
|---|
| 619 |
if (empty) |
|---|
| 620 |
kmem_cache_free(dquot_cachep, empty); |
|---|
| 621 |
} |
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
wait_on_dquot(dquot); |
|---|
| 625 |
|
|---|
| 626 |
if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) { |
|---|
| 627 |
dqput(dquot); |
|---|
| 628 |
return NODQUOT; |
|---|
| 629 |
} |
|---|
| 630 |
#ifdef __DQUOT_PARANOIA |
|---|
| 631 |
if (!dquot->dq_sb) |
|---|
| 632 |
BUG(); |
|---|
| 633 |
#endif |
|---|
| 634 |
|
|---|
| 635 |
return dquot; |
|---|
| 636 |
} |
|---|
| 637 |
|
|---|
| 638 |
static int dqinit_needed(struct inode *inode, int type) |
|---|
| 639 |
{ |
|---|
| 640 |
int cnt; |
|---|
| 641 |
|
|---|
| 642 |
if (IS_NOQUOTA(inode)) |
|---|
| 643 |
return 0; |
|---|
| 644 |
if (type != -1) |
|---|
| 645 |
return inode->i_dquot[type] == NODQUOT; |
|---|
| 646 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 647 |
if (inode->i_dquot[cnt] == NODQUOT) |
|---|
| 648 |
return 1; |
|---|
| 649 |
return 0; |
|---|
| 650 |
} |
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
static void add_dquot_ref(struct super_block *sb, int type) |
|---|
| 654 |
{ |
|---|
| 655 |
struct list_head *p; |
|---|
| 656 |
|
|---|
| 657 |
restart: |
|---|
| 658 |
file_list_lock(); |
|---|
| 659 |
list_for_each(p, &sb->s_files) { |
|---|
| 660 |
struct file *filp = list_entry(p, struct file, f_list); |
|---|
| 661 |
struct inode *inode = filp->f_dentry->d_inode; |
|---|
| 662 |
if (filp->f_mode & FMODE_WRITE && dqinit_needed(inode, type)) { |
|---|
| 663 |
struct dentry *dentry = dget(filp->f_dentry); |
|---|
| 664 |
file_list_unlock(); |
|---|
| 665 |
sb->dq_op->initialize(inode, type); |
|---|
| 666 |
dput(dentry); |
|---|
| 667 |
|
|---|
| 668 |
goto restart; |
|---|
| 669 |
} |
|---|
| 670 |
} |
|---|
| 671 |
file_list_unlock(); |
|---|
| 672 |
} |
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
static inline int dqput_blocks(struct dquot *dquot) |
|---|
| 676 |
{ |
|---|
| 677 |
if (atomic_read(&dquot->dq_count) <= 1) |
|---|
| 678 |
return 1; |
|---|
| 679 |
return 0; |
|---|
| 680 |
} |
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 |
int remove_inode_dquot_ref(struct inode *inode, int type, struct list_head *tofree_head) |
|---|
| 685 |
{ |
|---|
| 686 |
struct dquot *dquot = inode->i_dquot[type]; |
|---|
| 687 |
int cnt; |
|---|
| 688 |
|
|---|
| 689 |
inode->i_dquot[type] = NODQUOT; |
|---|
| 690 |
|
|---|
| 691 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 692 |
if (inode->i_dquot[cnt] != NODQUOT) |
|---|
| 693 |
goto put_it; |
|---|
| 694 |
} |
|---|
| 695 |
inode->i_flags &= ~S_QUOTA; |
|---|
| 696 |
put_it: |
|---|
| 697 |
if (dquot != NODQUOT) { |
|---|
| 698 |
if (dqput_blocks(dquot)) { |
|---|
| 699 |
#ifdef __DQUOT_PARANOIA |
|---|
| 700 |
if (atomic_read(&dquot->dq_count) != 1) |
|---|
| 701 |
printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count)); |
|---|
| 702 |
#endif |
|---|
| 703 |
spin_lock(&dq_list_lock); |
|---|
| 704 |
list_add(&dquot->dq_free, tofree_head); |
|---|
| 705 |
spin_unlock(&dq_list_lock); |
|---|
| 706 |
return 1; |
|---|
| 707 |
} |
|---|
| 708 |
else |
|---|
| 709 |
dqput(dquot); |
|---|
| 710 |
} |
|---|
| 711 |
return 0; |
|---|
| 712 |
} |
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
static void put_dquot_list(struct list_head *tofree_head) |
|---|
| 717 |
{ |
|---|
| 718 |
struct list_head *act_head; |
|---|
| 719 |
struct dquot *dquot; |
|---|
| 720 |
|
|---|
| 721 |
act_head = tofree_head->next; |
|---|
| 722 |
|
|---|
| 723 |
while (act_head != tofree_head) { |
|---|
| 724 |
dquot = list_entry(act_head, struct dquot, dq_free); |
|---|
| 725 |
act_head = act_head->next; |
|---|
| 726 |
list_del_init(&dquot->dq_free); |
|---|
| 727 |
dqput(dquot); |
|---|
| 728 |
} |
|---|
| 729 |
} |
|---|
| 730 |
|
|---|
| 731 |
|
|---|
| 732 |
extern void remove_dquot_ref(struct super_block *, int, struct list_head *); |
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
static void drop_dquot_ref(struct super_block *sb, int type) |
|---|
| 736 |
{ |
|---|
| 737 |
LIST_HEAD(tofree_head); |
|---|
| 738 |
|
|---|
| 739 |
down_write(&sb_dqopt(sb)->dqptr_sem); |
|---|
| 740 |
remove_dquot_ref(sb, type, &tofree_head); |
|---|
| 741 |
up_write(&sb_dqopt(sb)->dqptr_sem); |
|---|
| 742 |
put_dquot_list(&tofree_head); |
|---|
| 743 |
} |
|---|
| 744 |
|
|---|
| 745 |
static inline void dquot_incr_inodes(struct dquot *dquot, unsigned long number) |
|---|
| 746 |
{ |
|---|
| 747 |
dquot->dq_dqb.dqb_curinodes += number; |
|---|
| 748 |
} |
|---|
| 749 |
|
|---|
| 750 |
static inline void dquot_incr_space(struct dquot *dquot, qsize_t number) |
|---|
| 751 |
{ |
|---|
| 752 |
dquot->dq_dqb.dqb_curspace += number; |
|---|
| 753 |
} |
|---|
| 754 |
|
|---|
| 755 |
static inline void dquot_decr_inodes(struct dquot *dquot, unsigned long number) |
|---|
| 756 |
{ |
|---|
| 757 |
if (dquot->dq_dqb.dqb_curinodes > number) |
|---|
| 758 |
dquot->dq_dqb.dqb_curinodes -= number; |
|---|
| 759 |
else |
|---|
| 760 |
dquot->dq_dqb.dqb_curinodes = 0; |
|---|
| 761 |
if (dquot->dq_dqb.dqb_curinodes < dquot->dq_dqb.dqb_isoftlimit) |
|---|
| 762 |
dquot->dq_dqb.dqb_itime = (time_t) 0; |
|---|
| 763 |
clear_bit(DQ_INODES_B, &dquot->dq_flags); |
|---|
| 764 |
} |
|---|
| 765 |
|
|---|
| 766 |
static inline void dquot_decr_space(struct dquot *dquot, qsize_t number) |
|---|
| 767 |
{ |
|---|
| 768 |
if (dquot->dq_dqb.dqb_curspace > number) |
|---|
| 769 |
dquot->dq_dqb.dqb_curspace -= number; |
|---|
| 770 |
else |
|---|
| 771 |
dquot->dq_dqb.dqb_curspace = 0; |
|---|
| 772 |
if (toqb(dquot->dq_dqb.dqb_curspace) < dquot->dq_dqb.dqb_bsoftlimit) |
|---|
| 773 |
dquot->dq_dqb.dqb_btime = (time_t) 0; |
|---|
| 774 |
clear_bit(DQ_BLKS_B, &dquot->dq_flags); |
|---|
| 775 |
} |
|---|
| 776 |
|
|---|
| 777 |
static inline int need_print_warning(struct dquot *dquot) |
|---|
| 778 |
{ |
|---|
| 779 |
switch (dquot->dq_type) { |
|---|
| 780 |
case USRQUOTA: |
|---|
| 781 |
return current->fsuid == dquot->dq_id; |
|---|
| 782 |
case GRPQUOTA: |
|---|
| 783 |
return in_group_p(dquot->dq_id); |
|---|
| 784 |
} |
|---|
| 785 |
return 0; |
|---|
| 786 |
} |
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
#define NOWARN 0 |
|---|
| 790 |
#define IHARDWARN 1 |
|---|
| 791 |
#define ISOFTLONGWARN 2 |
|---|
| 792 |
#define ISOFTWARN 3 |
|---|
| 793 |
#define BHARDWARN 4 |
|---|
| 794 |
#define BSOFTLONGWARN 5 |
|---|
| 795 |
#define BSOFTWARN 6 |
|---|
| 796 |
|
|---|
| 797 |
|
|---|
| 798 |
static void print_warning(struct dquot *dquot, const char warntype) |
|---|
| 799 |
{ |
|---|
| 800 |
char *msg = NULL; |
|---|
| 801 |
int flag = (warntype == BHARDWARN || warntype == BSOFTLONGWARN) ? DQ_BLKS_B : |
|---|
| 802 |
((warntype == IHARDWARN || warntype == ISOFTLONGWARN) ? DQ_INODES_B : 0); |
|---|
| 803 |
|
|---|
| 804 |
if (!need_print_warning(dquot) || (flag && test_and_set_bit(flag, &dquot->dq_flags))) |
|---|
| 805 |
return; |
|---|
| 806 |
tty_write_message(current->signal->tty, dquot->dq_sb->s_id); |
|---|
| 807 |
if (warntype == ISOFTWARN || warntype == BSOFTWARN) |
|---|
| 808 |
tty_write_message(current->signal->tty, ": warning, "); |
|---|
| 809 |
else |
|---|
| 810 |
tty_write_message(current->signal->tty, ": write failed, "); |
|---|
| 811 |
tty_write_message(current->signal->tty, quotatypes[dquot->dq_type]); |
|---|
| 812 |
switch (warntype) { |
|---|
| 813 |
case IHARDWARN: |
|---|
| 814 |
msg = " file limit reached.\n"; |
|---|
| 815 |
break; |
|---|
| 816 |
case ISOFTLONGWARN: |
|---|
| 817 |
msg = " file quota exceeded too long.\n"; |
|---|
| 818 |
break; |
|---|
| 819 |
case ISOFTWARN: |
|---|
| 820 |
msg = " file quota exceeded.\n"; |
|---|
| 821 |
break; |
|---|
| 822 |
case BHARDWARN: |
|---|
| 823 |
msg = " block limit reached.\n"; |
|---|
| 824 |
break; |
|---|
| 825 |
case BSOFTLONGWARN: |
|---|
| 826 |
msg = " block quota exceeded too long.\n"; |
|---|
| 827 |
break; |
|---|
| 828 |
case BSOFTWARN: |
|---|
| 829 |
msg = " block quota exceeded.\n"; |
|---|
| 830 |
break; |
|---|
| 831 |
} |
|---|
| 832 |
tty_write_message(current->signal->tty, msg); |
|---|
| 833 |
} |
|---|
| 834 |
|
|---|
| 835 |
static inline void flush_warnings(struct dquot **dquots, char *warntype) |
|---|
| 836 |
{ |
|---|
| 837 |
int i; |
|---|
| 838 |
|
|---|
| 839 |
for (i = 0; i < MAXQUOTAS; i++) |
|---|
| 840 |
if (dquots[i] != NODQUOT && warntype[i] != NOWARN) |
|---|
| 841 |
print_warning(dquots[i], warntype[i]); |
|---|
| 842 |
} |
|---|
| 843 |
|
|---|
| 844 |
static inline char ignore_hardlimit(struct dquot *dquot) |
|---|
| 845 |
{ |
|---|
| 846 |
struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type]; |
|---|
| 847 |
|
|---|
| 848 |
return capable(CAP_SYS_RESOURCE) && |
|---|
| 849 |
(info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & V1_DQF_RSQUASH)); |
|---|
| 850 |
} |
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
static int check_idq(struct dquot *dquot, ulong inodes, char *warntype) |
|---|
| 854 |
{ |
|---|
| 855 |
*warntype = NOWARN; |
|---|
| 856 |
if (inodes <= 0 || test_bit(DQ_FAKE_B, &dquot->dq_flags)) |
|---|
| 857 |
return QUOTA_OK; |
|---|
| 858 |
|
|---|
| 859 |
if (dquot->dq_dqb.dqb_ihardlimit && |
|---|
| 860 |
(dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit && |
|---|
| 861 |
!ignore_hardlimit(dquot)) { |
|---|
| 862 |
*warntype = IHARDWARN; |
|---|
| 863 |
return NO_QUOTA; |
|---|
| 864 |
} |
|---|
| 865 |
|
|---|
| 866 |
if (dquot->dq_dqb.dqb_isoftlimit && |
|---|
| 867 |
(dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit && |
|---|
| 868 |
dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime && |
|---|
| 869 |
!ignore_hardlimit(dquot)) { |
|---|
| 870 |
*warntype = ISOFTLONGWARN; |
|---|
| 871 |
return NO_QUOTA; |
|---|
| 872 |
} |
|---|
| 873 |
|
|---|
| 874 |
if (dquot->dq_dqb.dqb_isoftlimit && |
|---|
| 875 |
(dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit && |
|---|
| 876 |
dquot->dq_dqb.dqb_itime == 0) { |
|---|
| 877 |
*warntype = ISOFTWARN; |
|---|
| 878 |
dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace; |
|---|
| 879 |
} |
|---|
| 880 |
|
|---|
| 881 |
return QUOTA_OK; |
|---|
| 882 |
} |
|---|
| 883 |
|
|---|
| 884 |
|
|---|
| 885 |
static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype) |
|---|
| 886 |
{ |
|---|
| 887 |
*warntype = 0; |
|---|
| 888 |
if (space <= 0 || test_bit(DQ_FAKE_B, &dquot->dq_flags)) |
|---|
| 889 |
return QUOTA_OK; |
|---|
| 890 |
|
|---|
| 891 |
if (dquot->dq_dqb.dqb_bhardlimit && |
|---|
| 892 |
toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bhardlimit && |
|---|
| 893 |
!ignore_hardlimit(dquot)) { |
|---|
| 894 |
if (!prealloc) |
|---|
| 895 |
*warntype = BHARDWARN; |
|---|
| 896 |
return NO_QUOTA; |
|---|
| 897 |
} |
|---|
| 898 |
|
|---|
| 899 |
if (dquot->dq_dqb.dqb_bsoftlimit && |
|---|
| 900 |
toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bsoftlimit && |
|---|
| 901 |
dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime && |
|---|
| 902 |
!ignore_hardlimit(dquot)) { |
|---|
| 903 |
if (!prealloc) |
|---|
| 904 |
*warntype = BSOFTLONGWARN; |
|---|
| 905 |
return NO_QUOTA; |
|---|
| 906 |
} |
|---|
| 907 |
|
|---|
| 908 |
if (dquot->dq_dqb.dqb_bsoftlimit && |
|---|
| 909 |
toqb(dquot->dq_dqb.dqb_curspace + space) > dquot->dq_dqb.dqb_bsoftlimit && |
|---|
| 910 |
dquot->dq_dqb.dqb_btime == 0) { |
|---|
| 911 |
if (!prealloc) { |
|---|
| 912 |
*warntype = BSOFTWARN; |
|---|
| 913 |
dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace; |
|---|
| 914 |
} |
|---|
| 915 |
else |
|---|
| 916 |
|
|---|
| 917 |
|
|---|
| 918 |
|
|---|
| 919 |
|
|---|
| 920 |
return NO_QUOTA; |
|---|
| 921 |
} |
|---|
| 922 |
|
|---|
| 923 |
return QUOTA_OK; |
|---|
| 924 |
} |
|---|
| 925 |
|
|---|
| 926 |
|
|---|
| 927 |
|
|---|
| 928 |
|
|---|
| 929 |
|
|---|
| 930 |
int dquot_initialize(struct inode *inode, int type) |
|---|
| 931 |
{ |
|---|
| 932 |
unsigned int id = 0; |
|---|
| 933 |
int cnt, ret = 0; |
|---|
| 934 |
|
|---|
| 935 |
|
|---|
| 936 |
|
|---|
| 937 |
if (IS_NOQUOTA(inode)) |
|---|
| 938 |
return 0; |
|---|
| 939 |
down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 940 |
|
|---|
| 941 |
if (IS_NOQUOTA(inode)) |
|---|
| 942 |
goto out_err; |
|---|
| 943 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 944 |
if (type != -1 && cnt != type) |
|---|
| 945 |
continue; |
|---|
| 946 |
if (inode->i_dquot[cnt] == NODQUOT) { |
|---|
| 947 |
switch (cnt) { |
|---|
| 948 |
case USRQUOTA: |
|---|
| 949 |
id = inode->i_uid; |
|---|
| 950 |
break; |
|---|
| 951 |
case GRPQUOTA: |
|---|
| 952 |
id = inode->i_gid; |
|---|
| 953 |
break; |
|---|
| 954 |
} |
|---|
| 955 |
inode->i_dquot[cnt] = dqget(inode->i_sb, id, cnt); |
|---|
| 956 |
if (inode->i_dquot[cnt]) |
|---|
| 957 |
inode->i_flags |= S_QUOTA; |
|---|
| 958 |
} |
|---|
| 959 |
} |
|---|
| 960 |
out_err: |
|---|
| 961 |
up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 962 |
return ret; |
|---|
| 963 |
} |
|---|
| 964 |
|
|---|
| 965 |
|
|---|
| 966 |
|
|---|
| 967 |
|
|---|
| 968 |
|
|---|
| 969 |
int dquot_drop(struct inode *inode) |
|---|
| 970 |
{ |
|---|
| 971 |
int cnt; |
|---|
| 972 |
|
|---|
| 973 |
down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 974 |
inode->i_flags &= ~S_QUOTA; |
|---|
| 975 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 976 |
if (inode->i_dquot[cnt] != NODQUOT) { |
|---|
| 977 |
dqput(inode->i_dquot[cnt]); |
|---|
| 978 |
inode->i_dquot[cnt] = NODQUOT; |
|---|
| 979 |
} |
|---|
| 980 |
} |
|---|
| 981 |
up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 982 |
return 0; |
|---|
| 983 |
} |
|---|
| 984 |
|
|---|
| 985 |
|
|---|
| 986 |
|
|---|
| 987 |
|
|---|
| 988 |
|
|---|
| 989 |
|
|---|
| 990 |
|
|---|
| 991 |
|
|---|
| 992 |
|
|---|
| 993 |
|
|---|
| 994 |
|
|---|
| 995 |
|
|---|
| 996 |
|
|---|
| 997 |
int dquot_alloc_space(struct inode *inode, qsize_t number, int warn) |
|---|
| 998 |
{ |
|---|
| 999 |
int cnt, ret = NO_QUOTA; |
|---|
| 1000 |
char warntype[MAXQUOTAS]; |
|---|
| 1001 |
|
|---|
| 1002 |
|
|---|
| 1003 |
|
|---|
| 1004 |
if (IS_NOQUOTA(inode)) { |
|---|
| 1005 |
out_add: |
|---|
| 1006 |
inode_add_bytes(inode, number); |
|---|
| 1007 |
return QUOTA_OK; |
|---|
| 1008 |
} |
|---|
| 1009 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 1010 |
warntype[cnt] = NOWARN; |
|---|
| 1011 |
|
|---|
| 1012 |
down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1013 |
if (IS_NOQUOTA(inode)) { |
|---|
| 1014 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1015 |
goto out_add; |
|---|
| 1016 |
} |
|---|
| 1017 |
spin_lock(&dq_data_lock); |
|---|
| 1018 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1019 |
if (inode->i_dquot[cnt] == NODQUOT) |
|---|
| 1020 |
continue; |
|---|
| 1021 |
if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) == NO_QUOTA) |
|---|
| 1022 |
goto warn_put_all; |
|---|
| 1023 |
} |
|---|
| 1024 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1025 |
if (inode->i_dquot[cnt] == NODQUOT) |
|---|
| 1026 |
continue; |
|---|
| 1027 |
dquot_incr_space(inode->i_dquot[cnt], number); |
|---|
| 1028 |
} |
|---|
| 1029 |
inode_add_bytes(inode, number); |
|---|
| 1030 |
ret = QUOTA_OK; |
|---|
| 1031 |
warn_put_all: |
|---|
| 1032 |
spin_unlock(&dq_data_lock); |
|---|
| 1033 |
if (ret == QUOTA_OK) |
|---|
| 1034 |
|
|---|
| 1035 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 1036 |
if (inode->i_dquot[cnt]) |
|---|
| 1037 |
mark_dquot_dirty(inode->i_dquot[cnt]); |
|---|
| 1038 |
flush_warnings(inode->i_dquot, warntype); |
|---|
| 1039 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1040 |
return ret; |
|---|
| 1041 |
} |
|---|
| 1042 |
|
|---|
| 1043 |
|
|---|
| 1044 |
|
|---|
| 1045 |
|
|---|
| 1046 |
int dquot_alloc_inode(const struct inode *inode, unsigned long number) |
|---|
| 1047 |
{ |
|---|
| 1048 |
int cnt, ret = NO_QUOTA; |
|---|
| 1049 |
char warntype[MAXQUOTAS]; |
|---|
| 1050 |
|
|---|
| 1051 |
|
|---|
| 1052 |
|
|---|
| 1053 |
if (IS_NOQUOTA(inode)) |
|---|
| 1054 |
return QUOTA_OK; |
|---|
| 1055 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 1056 |
warntype[cnt] = NOWARN; |
|---|
| 1057 |
down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1058 |
if (IS_NOQUOTA(inode)) { |
|---|
| 1059 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1060 |
return QUOTA_OK; |
|---|
| 1061 |
} |
|---|
| 1062 |
spin_lock(&dq_data_lock); |
|---|
| 1063 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1064 |
if (inode->i_dquot[cnt] == NODQUOT) |
|---|
| 1065 |
continue; |
|---|
| 1066 |
if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) == NO_QUOTA) |
|---|
| 1067 |
goto warn_put_all; |
|---|
| 1068 |
} |
|---|
| 1069 |
|
|---|
| 1070 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1071 |
if (inode->i_dquot[cnt] == NODQUOT) |
|---|
| 1072 |
continue; |
|---|
| 1073 |
dquot_incr_inodes(inode->i_dquot[cnt], number); |
|---|
| 1074 |
} |
|---|
| 1075 |
ret = QUOTA_OK; |
|---|
| 1076 |
warn_put_all: |
|---|
| 1077 |
spin_unlock(&dq_data_lock); |
|---|
| 1078 |
if (ret == QUOTA_OK) |
|---|
| 1079 |
|
|---|
| 1080 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 1081 |
if (inode->i_dquot[cnt]) |
|---|
| 1082 |
mark_dquot_dirty(inode->i_dquot[cnt]); |
|---|
| 1083 |
flush_warnings((struct dquot **)inode->i_dquot, warntype); |
|---|
| 1084 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1085 |
return ret; |
|---|
| 1086 |
} |
|---|
| 1087 |
|
|---|
| 1088 |
|
|---|
| 1089 |
|
|---|
| 1090 |
|
|---|
| 1091 |
int dquot_free_space(struct inode *inode, qsize_t number) |
|---|
| 1092 |
{ |
|---|
| 1093 |
unsigned int cnt; |
|---|
| 1094 |
|
|---|
| 1095 |
|
|---|
| 1096 |
|
|---|
| 1097 |
if (IS_NOQUOTA(inode)) { |
|---|
| 1098 |
out_sub: |
|---|
| 1099 |
inode_sub_bytes(inode, number); |
|---|
| 1100 |
return QUOTA_OK; |
|---|
| 1101 |
} |
|---|
| 1102 |
down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1103 |
|
|---|
| 1104 |
if (IS_NOQUOTA(inode)) { |
|---|
| 1105 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1106 |
goto out_sub; |
|---|
| 1107 |
} |
|---|
| 1108 |
spin_lock(&dq_data_lock); |
|---|
| 1109 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1110 |
if (inode->i_dquot[cnt] == NODQUOT) |
|---|
| 1111 |
continue; |
|---|
| 1112 |
dquot_decr_space(inode->i_dquot[cnt], number); |
|---|
| 1113 |
} |
|---|
| 1114 |
inode_sub_bytes(inode, number); |
|---|
| 1115 |
spin_unlock(&dq_data_lock); |
|---|
| 1116 |
|
|---|
| 1117 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 1118 |
if (inode->i_dquot[cnt]) |
|---|
| 1119 |
mark_dquot_dirty(inode->i_dquot[cnt]); |
|---|
| 1120 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1121 |
return QUOTA_OK; |
|---|
| 1122 |
} |
|---|
| 1123 |
|
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 |
|
|---|
| 1127 |
int dquot_free_inode(const struct inode *inode, unsigned long number) |
|---|
| 1128 |
{ |
|---|
| 1129 |
unsigned int cnt; |
|---|
| 1130 |
|
|---|
| 1131 |
|
|---|
| 1132 |
|
|---|
| 1133 |
if (IS_NOQUOTA(inode)) |
|---|
| 1134 |
return QUOTA_OK; |
|---|
| 1135 |
down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1136 |
|
|---|
| 1137 |
if (IS_NOQUOTA(inode)) { |
|---|
| 1138 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1139 |
return QUOTA_OK; |
|---|
| 1140 |
} |
|---|
| 1141 |
spin_lock(&dq_data_lock); |
|---|
| 1142 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1143 |
if (inode->i_dquot[cnt] == NODQUOT) |
|---|
| 1144 |
continue; |
|---|
| 1145 |
dquot_decr_inodes(inode->i_dquot[cnt], number); |
|---|
| 1146 |
} |
|---|
| 1147 |
spin_unlock(&dq_data_lock); |
|---|
| 1148 |
|
|---|
| 1149 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
|---|
| 1150 |
if (inode->i_dquot[cnt]) |
|---|
| 1151 |
mark_dquot_dirty(inode->i_dquot[cnt]); |
|---|
| 1152 |
up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1153 |
return QUOTA_OK; |
|---|
| 1154 |
} |
|---|
| 1155 |
|
|---|
| 1156 |
|
|---|
| 1157 |
|
|---|
| 1158 |
|
|---|
| 1159 |
|
|---|
| 1160 |
|
|---|
| 1161 |
int dquot_transfer(struct inode *inode, struct iattr *iattr) |
|---|
| 1162 |
{ |
|---|
| 1163 |
qsize_t space; |
|---|
| 1164 |
struct dquot *transfer_from[MAXQUOTAS]; |
|---|
| 1165 |
struct dquot *transfer_to[MAXQUOTAS]; |
|---|
| 1166 |
int cnt, ret = NO_QUOTA, chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid, |
|---|
| 1167 |
chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid; |
|---|
| 1168 |
char warntype[MAXQUOTAS]; |
|---|
| 1169 |
|
|---|
| 1170 |
|
|---|
| 1171 |
|
|---|
| 1172 |
if (IS_NOQUOTA(inode)) |
|---|
| 1173 |
return QUOTA_OK; |
|---|
| 1174 |
|
|---|
| 1175 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1176 |
transfer_to[cnt] = transfer_from[cnt] = NODQUOT; |
|---|
| 1177 |
warntype[cnt] = NOWARN; |
|---|
| 1178 |
} |
|---|
| 1179 |
down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1180 |
|
|---|
| 1181 |
if (IS_NOQUOTA(inode)) { |
|---|
| 1182 |
up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1183 |
return QUOTA_OK; |
|---|
| 1184 |
} |
|---|
| 1185 |
|
|---|
| 1186 |
|
|---|
| 1187 |
|
|---|
| 1188 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1189 |
switch (cnt) { |
|---|
| 1190 |
case USRQUOTA: |
|---|
| 1191 |
if (!chuid) |
|---|
| 1192 |
continue; |
|---|
| 1193 |
transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt); |
|---|
| 1194 |
break; |
|---|
| 1195 |
case GRPQUOTA: |
|---|
| 1196 |
if (!chgid) |
|---|
| 1197 |
continue; |
|---|
| 1198 |
transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt); |
|---|
| 1199 |
break; |
|---|
| 1200 |
} |
|---|
| 1201 |
} |
|---|
| 1202 |
spin_lock(&dq_data_lock); |
|---|
| 1203 |
space = inode_get_bytes(inode); |
|---|
| 1204 |
|
|---|
| 1205 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1206 |
if (transfer_to[cnt] == NODQUOT) |
|---|
| 1207 |
continue; |
|---|
| 1208 |
transfer_from[cnt] = inode->i_dquot[cnt]; |
|---|
| 1209 |
if (check_idq(transfer_to[cnt], 1, warntype+cnt) == NO_QUOTA || |
|---|
| 1210 |
check_bdq(transfer_to[cnt], space, 0, warntype+cnt) == NO_QUOTA) |
|---|
| 1211 |
goto warn_put_all; |
|---|
| 1212 |
} |
|---|
| 1213 |
|
|---|
| 1214 |
|
|---|
| 1215 |
|
|---|
| 1216 |
|
|---|
| 1217 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1218 |
|
|---|
| 1219 |
|
|---|
| 1220 |
|
|---|
| 1221 |
if (transfer_to[cnt] == NODQUOT) |
|---|
| 1222 |
continue; |
|---|
| 1223 |
|
|---|
| 1224 |
|
|---|
| 1225 |
if (transfer_from[cnt]) { |
|---|
| 1226 |
dquot_decr_inodes(transfer_from[cnt], 1); |
|---|
| 1227 |
dquot_decr_space(transfer_from[cnt], space); |
|---|
| 1228 |
} |
|---|
| 1229 |
|
|---|
| 1230 |
dquot_incr_inodes(transfer_to[cnt], 1); |
|---|
| 1231 |
dquot_incr_space(transfer_to[cnt], space); |
|---|
| 1232 |
|
|---|
| 1233 |
inode->i_dquot[cnt] = transfer_to[cnt]; |
|---|
| 1234 |
} |
|---|
| 1235 |
ret = QUOTA_OK; |
|---|
| 1236 |
warn_put_all: |
|---|
| 1237 |
spin_unlock(&dq_data_lock); |
|---|
| 1238 |
|
|---|
| 1239 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1240 |
if (transfer_from[cnt]) |
|---|
| 1241 |
mark_dquot_dirty(transfer_from[cnt]); |
|---|
| 1242 |
if (transfer_to[cnt]) |
|---|
| 1243 |
mark_dquot_dirty(transfer_to[cnt]); |
|---|
| 1244 |
} |
|---|
| 1245 |
flush_warnings(transfer_to, warntype); |
|---|
| 1246 |
|
|---|
| 1247 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1248 |
if (ret == QUOTA_OK && transfer_from[cnt] != NODQUOT) |
|---|
| 1249 |
dqput(transfer_from[cnt]); |
|---|
| 1250 |
if (ret == NO_QUOTA && transfer_to[cnt] != NODQUOT) |
|---|
| 1251 |
dqput(transfer_to[cnt]); |
|---|
| 1252 |
} |
|---|
| 1253 |
up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
|---|
| 1254 |
return ret; |
|---|
| 1255 |
} |
|---|
| 1256 |
|
|---|
| 1257 |
|
|---|
| 1258 |
|
|---|
| 1259 |
|
|---|
| 1260 |
int dquot_commit_info(struct super_block *sb, int type) |
|---|
| 1261 |
{ |
|---|
| 1262 |
int ret; |
|---|
| 1263 |
struct quota_info *dqopt = sb_dqopt(sb); |
|---|
| 1264 |
|
|---|
| 1265 |
down(&dqopt->dqio_sem); |
|---|
| 1266 |
ret = dqopt->ops[type]->write_file_info(sb, type); |
|---|
| 1267 |
up(&dqopt->dqio_sem); |
|---|
| 1268 |
return ret; |
|---|
| 1269 |
} |
|---|
| 1270 |
|
|---|
| 1271 |
|
|---|
| 1272 |
|
|---|
| 1273 |
|
|---|
| 1274 |
struct dquot_operations dquot_operations = { |
|---|
| 1275 |
.initialize = dquot_initialize, |
|---|
| 1276 |
.drop = dquot_drop, |
|---|
| 1277 |
.alloc_space = dquot_alloc_space, |
|---|
| 1278 |
.alloc_inode = dquot_alloc_inode, |
|---|
| 1279 |
.free_space = dquot_free_space, |
|---|
| 1280 |
.free_inode = dquot_free_inode, |
|---|
| 1281 |
.transfer = dquot_transfer, |
|---|
| 1282 |
.write_dquot = dquot_commit, |
|---|
| 1283 |
.acquire_dquot = dquot_acquire, |
|---|
| 1284 |
.release_dquot = dquot_release, |
|---|
| 1285 |
.mark_dirty = dquot_mark_dquot_dirty, |
|---|
| 1286 |
.write_info = dquot_commit_info |
|---|
| 1287 |
}; |
|---|
| 1288 |
|
|---|
| 1289 |
static inline void set_enable_flags(struct quota_info *dqopt, int type) |
|---|
| 1290 |
{ |
|---|
| 1291 |
switch (type) { |
|---|
| 1292 |
case USRQUOTA: |
|---|
| 1293 |
dqopt->flags |= DQUOT_USR_ENABLED; |
|---|
| 1294 |
break; |
|---|
| 1295 |
case GRPQUOTA: |
|---|
| 1296 |
dqopt->flags |= DQUOT_GRP_ENABLED; |
|---|
| 1297 |
break; |
|---|
| 1298 |
} |
|---|
| 1299 |
} |
|---|
| 1300 |
|
|---|
| 1301 |
static inline void reset_enable_flags(struct quota_info *dqopt, int type) |
|---|
| 1302 |
{ |
|---|
| 1303 |
switch (type) { |
|---|
| 1304 |
case USRQUOTA: |
|---|
| 1305 |
dqopt->flags &= ~DQUOT_USR_ENABLED; |
|---|
| 1306 |
break; |
|---|
| 1307 |
case GRPQUOTA: |
|---|
| 1308 |
dqopt->flags &= ~DQUOT_GRP_ENABLED; |
|---|
| 1309 |
break; |
|---|
| 1310 |
} |
|---|
| 1311 |
} |
|---|
| 1312 |
|
|---|
| 1313 |
|
|---|
| 1314 |
|
|---|
| 1315 |
|
|---|
| 1316 |
int vfs_quota_off(struct super_block *sb, int type) |
|---|
| 1317 |
{ |
|---|
| 1318 |
int cnt; |
|---|
| 1319 |
struct quota_info *dqopt = sb_dqopt(sb); |
|---|
| 1320 |
|
|---|
| 1321 |
|
|---|
| 1322 |
down(&dqopt->dqonoff_sem); |
|---|
| 1323 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1324 |
if (type != -1 && cnt != type) |
|---|
| 1325 |
continue; |
|---|
| 1326 |
if (!sb_has_quota_enabled(sb, cnt)) |
|---|
| 1327 |
continue; |
|---|
| 1328 |
reset_enable_flags(dqopt, cnt); |
|---|
| 1329 |
|
|---|
| 1330 |
|
|---|
| 1331 |
drop_dquot_ref(sb, cnt); |
|---|
| 1332 |
invalidate_dquots(sb, cnt); |
|---|
| 1333 |
|
|---|
| 1334 |
|
|---|
| 1335 |
|
|---|
| 1336 |
|
|---|
| 1337 |
if (info_dirty(&dqopt->info[cnt])) |
|---|
| 1338 |
sb->dq_op->write_info(sb, cnt); |
|---|
| 1339 |
if (dqopt->ops[cnt]->free_file_info) |
|---|
| 1340 |
dqopt->ops[cnt]->free_file_info(sb, cnt); |
|---|
| 1341 |
put_quota_format(dqopt->info[cnt].dqi_format); |
|---|
| 1342 |
|
|---|
| 1343 |
fput(dqopt->files[cnt]); |
|---|
| 1344 |
dqopt->files[cnt] = NULL; |
|---|
| 1345 |
dqopt->info[cnt].dqi_flags = 0; |
|---|
| 1346 |
dqopt->info[cnt].dqi_igrace = 0; |
|---|
| 1347 |
dqopt->info[cnt].dqi_bgrace = 0; |
|---|
| 1348 |
dqopt->ops[cnt] = NULL; |
|---|
| 1349 |
} |
|---|
| 1350 |
up(&dqopt->dqonoff_sem); |
|---|
| 1351 |
return 0; |
|---|
| 1352 |
} |
|---|
| 1353 |
|
|---|
| 1354 |
|
|---|
| 1355 |
|
|---|
| 1356 |
|
|---|
| 1357 |
|
|---|
| 1358 |
|
|---|
| 1359 |
static int vfs_quota_on_file(struct file *f, int type, int format_id) |
|---|
| 1360 |
{ |
|---|
| 1361 |
struct quota_format_type *fmt = find_quota_format(format_id); |
|---|
| 1362 |
struct inode *inode; |
|---|
| 1363 |
struct super_block *sb = f->f_dentry->d_sb; |
|---|
| 1364 |
struct quota_info *dqopt = sb_dqopt(sb); |
|---|
| 1365 |
struct dquot *to_drop[MAXQUOTAS]; |
|---|
| 1366 |
int error, cnt; |
|---|
| 1367 |
unsigned int oldflags; |
|---|
| 1368 |
|
|---|
| 1369 |
if (!fmt) |
|---|
| 1370 |
return -ESRCH; |
|---|
| 1371 |
error = -EIO; |
|---|
| 1372 |
if (!f->f_op || !f->f_op->read || !f->f_op->write) |
|---|
| 1373 |
goto out_fmt; |
|---|
| 1374 |
inode = f->f_dentry->d_inode; |
|---|
| 1375 |
error = -EACCES; |
|---|
| 1376 |
if (!S_ISREG(inode->i_mode)) |
|---|
| 1377 |
goto out_fmt; |
|---|
| 1378 |
|
|---|
| 1379 |
down(&dqopt->dqonoff_sem); |
|---|
| 1380 |
if (sb_has_quota_enabled(sb, type)) { |
|---|
| 1381 |
error = -EBUSY; |
|---|
| 1382 |
goto out_lock; |
|---|
| 1383 |
} |
|---|
| 1384 |
oldflags = inode->i_flags; |
|---|
| 1385 |
dqopt->files[type] = f; |
|---|
| 1386 |
error = -EINVAL; |
|---|
| 1387 |
if (!fmt->qf_ops->check_quota_file(sb, type)) |
|---|
| 1388 |
goto out_file_init; |
|---|
| 1389 |
|
|---|
| 1390 |
|
|---|
| 1391 |
|
|---|
| 1392 |
down_write(&dqopt->dqptr_sem); |
|---|
| 1393 |
inode->i_flags |= S_NOQUOTA | S_NOATIME; |
|---|
| 1394 |
|
|---|
| 1395 |
|
|---|
| 1396 |
|
|---|
| 1397 |
|
|---|
| 1398 |
|
|---|
| 1399 |
|
|---|
| 1400 |
|
|---|
| 1401 |
mapping_set_gfp_mask(inode->i_mapping, |
|---|
| 1402 |
mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); |
|---|
| 1403 |
|
|---|
| 1404 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1405 |
to_drop[cnt] = inode->i_dquot[cnt]; |
|---|
| 1406 |
inode->i_dquot[cnt] = NODQUOT; |
|---|
| 1407 |
} |
|---|
| 1408 |
inode->i_flags &= ~S_QUOTA; |
|---|
| 1409 |
up_write(&dqopt->dqptr_sem); |
|---|
| 1410 |
|
|---|
| 1411 |
|
|---|
| 1412 |
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
|---|
| 1413 |
if (to_drop[cnt]) |
|---|
| 1414 |
dqput(to_drop[cnt]); |
|---|
| 1415 |
} |
|---|
| 1416 |
|
|---|
| 1417 |
dqopt->ops[type] = fmt->qf_ops; |
|---|
| 1418 |
dqopt->info[type].dqi_format = fmt; |
|---|
| 1419 |
INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list); |
|---|
| 1420 |
down(&dqopt->dqio_sem); |
|---|
| 1421 |
if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0) { |
|---|
| 1422 |
up(&dqopt->dqio_sem); |
|---|
| 1423 |
goto out_file_init; |
|---|
| 1424 |
} |
|---|
| 1425 |
up(&dqopt->dqio_sem); |
|---|
| 1426 |
set_enable_flags(dqopt, type); |
|---|
| 1427 |
|
|---|
| 1428 |
add_dquot_ref(sb, type); |
|---|
| 1429 |
up(&dqopt->dqonoff_sem); |
|---|
| 1430 |
|
|---|
| 1431 |
return 0; |
|---|
| 1432 |
|
|---|
| 1433 |
out_file_init: |
|---|
| 1434 |
inode->i_flags = oldflags; |
|---|
| 1435 |
dqopt->files[type] = NULL; |
|---|
| 1436 |
out_lock: |
|---|
| 1437 |
up_write(&dqopt->dqptr_sem); |
|---|
| 1438 |
up(&dqopt->dqonoff_sem); |
|---|
| 1439 |
out_fmt: |
|---|
| 1440 |
put_quota_format(fmt); |
|---|
| 1441 |
|
|---|
| 1442 |
return error; |
|---|
| 1443 |
} |
|---|
| 1444 |
|
|---|
| 1445 |
|
|---|
| 1446 |
int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path) |
|---|
| 1447 |
{ |
|---|
| 1448 |
struct file *f; |
|---|
| 1449 |
int error; |
|---|
| 1450 |
|
|---|
| 1451 |
f = filp_open(path, O_RDWR, 0600); |
|---|
| 1452 |
if (IS_ERR(f)) |
|---|
| 1453 |
return PTR_ERR(f); |
|---|
| 1454 |
error = security_quota_on(f); |
|---|
| 1455 |
if (error) |
|---|
| 1456 |
goto out_f; |
|---|
| 1457 |
error = vfs_quota_on_file(f, type, format_id); |
|---|
| 1458 |
if (!error) |
|---|
| 1459 |
return 0; |
|---|
| 1460 |
out_f: |
|---|
| 1461 |
filp_close(f, NULL); |
|---|
| 1462 |
return error; |
|---|
| 1463 |
} |
|---|
| 1464 |
|
|---|
| 1465 |
|
|---|
| 1466 |
|
|---|
| 1467 |
|
|---|
| 1468 |
|
|---|
| 1469 |
|
|---|
| 1470 |
|
|---|
| 1471 |
int vfs_quota_on_mount(int type, int format_id, struct dentry *dentry) |
|---|
| 1472 |
{ |
|---|
| 1473 |
struct file *f; |
|---|
| 1474 |
int error; |
|---|
| 1475 |
|
|---|
| 1476 |
dget(dentry); |
|---|
| 1477 |
f = dentry_open(dentry, NULL, O_RDWR); |
|---|
| 1478 |
if (IS_ERR(f)) { |
|---|
| 1479 |
error = PTR_ERR(f); |
|---|
| 1480 |
goto out_dentry; |
|---|
| 1481 |
} |
|---|
| 1482 |
error = vfs_quota_on_file(f, type, format_id); |
|---|
| 1483 |
if (!error) |
|---|
| 1484 |
return 0; |
|---|
| 1485 |
fput(f); |
|---|
| 1486 |
out_dentry: |
|---|
| 1487 |
dput(dentry); |
|---|
| 1488 |
return error; |
|---|
| 1489 |
} |
|---|
| 1490 |
|
|---|
| 1491 |
|
|---|
| 1492 |
static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di) |
|---|
| 1493 |
{ |
|---|
| 1494 |
struct mem_dqblk *dm = &dquot->dq_dqb; |
|---|
| 1495 |
|
|---|
| 1496 |
spin_lock(&dq_data_lock); |
|---|
| 1497 |
di->dqb_bhardlimit = dm->dqb_bhardlimit; |
|---|
| 1498 |
di->dqb_bsoftlimit = dm->dqb_bsoftlimit; |
|---|
| 1499 |
di->dqb_curspace = dm->dqb_curspace; |
|---|
| 1500 |
di->dqb_ihardlimit = dm->dqb_ihardlimit; |
|---|
| 1501 |
di->dqb_isoftlimit = dm->dqb_isoftlimit; |
|---|
| 1502 |
di->dqb_curinodes = dm->dqb_curinodes; |
|---|
| 1503 |
di->dqb_btime = dm->dqb_btime; |
|---|
| 1504 |
di->dqb_itime = dm->dqb_itime; |
|---|
| 1505 |
di->dqb_valid = QIF_ALL; |
|---|
| 1506 |
spin_unlock(&dq_data_lock); |
|---|
| 1507 |
} |
|---|
| 1508 |
|
|---|
| 1509 |
int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di) |
|---|
| 1510 |
{ |
|---|
| 1511 |
struct dquot *dquot; |
|---|
| 1512 |
|
|---|
| 1513 |
down(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1514 |
if (!(dquot = dqget(sb, id, type))) { |
|---|
| 1515 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1516 |
return -ESRCH; |
|---|
| 1517 |
} |
|---|
| 1518 |
do_get_dqblk(dquot, di); |
|---|
| 1519 |
dqput(dquot); |
|---|
| 1520 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1521 |
return 0; |
|---|
| 1522 |
} |
|---|
| 1523 |
|
|---|
| 1524 |
|
|---|
| 1525 |
static void do_set_dqblk(struct dquot *dquot, struct if_dqblk *di) |
|---|
| 1526 |
{ |
|---|
| 1527 |
struct mem_dqblk *dm = &dquot->dq_dqb; |
|---|
| 1528 |
int check_blim = 0, check_ilim = 0; |
|---|
| 1529 |
|
|---|
| 1530 |
spin_lock(&dq_data_lock); |
|---|
| 1531 |
if (di->dqb_valid & QIF_SPACE) { |
|---|
| 1532 |
dm->dqb_curspace = di->dqb_curspace; |
|---|
| 1533 |
check_blim = 1; |
|---|
| 1534 |
} |
|---|
| 1535 |
if (di->dqb_valid & QIF_BLIMITS) { |
|---|
| 1536 |
dm->dqb_bsoftlimit = di->dqb_bsoftlimit; |
|---|
| 1537 |
dm->dqb_bhardlimit = di->dqb_bhardlimit; |
|---|
| 1538 |
check_blim = 1; |
|---|
| 1539 |
} |
|---|
| 1540 |
if (di->dqb_valid & QIF_INODES) { |
|---|
| 1541 |
dm->dqb_curinodes = di->dqb_curinodes; |
|---|
| 1542 |
check_ilim = 1; |
|---|
| 1543 |
} |
|---|
| 1544 |
if (di->dqb_valid & QIF_ILIMITS) { |
|---|
| 1545 |
dm->dqb_isoftlimit = di->dqb_isoftlimit; |
|---|
| 1546 |
dm->dqb_ihardlimit = di->dqb_ihardlimit; |
|---|
| 1547 |
check_ilim = 1; |
|---|
| 1548 |
} |
|---|
| 1549 |
if (di->dqb_valid & QIF_BTIME) |
|---|
| 1550 |
dm->dqb_btime = di->dqb_btime; |
|---|
| 1551 |
if (di->dqb_valid & QIF_ITIME) |
|---|
| 1552 |
dm->dqb_itime = di->dqb_itime; |
|---|
| 1553 |
|
|---|
| 1554 |
if (check_blim) { |
|---|
| 1555 |
if (!dm->dqb_bsoftlimit || toqb(dm->dqb_curspace) < dm->dqb_bsoftlimit) { |
|---|
| 1556 |
dm->dqb_btime = 0; |
|---|
| 1557 |
clear_bit(DQ_BLKS_B, &dquot->dq_flags); |
|---|
| 1558 |
} |
|---|
| 1559 |
else if (!(di->dqb_valid & QIF_BTIME)) |
|---|
| 1560 |
dm->dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace; |
|---|
| 1561 |
} |
|---|
| 1562 |
if (check_ilim) { |
|---|
| 1563 |
if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) { |
|---|
| 1564 |
dm->dqb_itime = 0; |
|---|
| 1565 |
clear_bit(DQ_INODES_B, &dquot->dq_flags); |
|---|
| 1566 |
} |
|---|
| 1567 |
else if (!(di->dqb_valid & QIF_ITIME)) |
|---|
| 1568 |
dm->dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace; |
|---|
| 1569 |
} |
|---|
| 1570 |
if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit) |
|---|
| 1571 |
clear_bit(DQ_FAKE_B, &dquot->dq_flags); |
|---|
| 1572 |
else |
|---|
| 1573 |
set_bit(DQ_FAKE_B, &dquot->dq_flags); |
|---|
| 1574 |
spin_unlock(&dq_data_lock); |
|---|
| 1575 |
mark_dquot_dirty(dquot); |
|---|
| 1576 |
} |
|---|
| 1577 |
|
|---|
| 1578 |
int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di) |
|---|
| 1579 |
{ |
|---|
| 1580 |
struct dquot *dquot; |
|---|
| 1581 |
|
|---|
| 1582 |
down(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1583 |
if (!(dquot = dqget(sb, id, type))) { |
|---|
| 1584 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1585 |
return -ESRCH; |
|---|
| 1586 |
} |
|---|
| 1587 |
do_set_dqblk(dquot, di); |
|---|
| 1588 |
dqput(dquot); |
|---|
| 1589 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1590 |
return 0; |
|---|
| 1591 |
} |
|---|
| 1592 |
|
|---|
| 1593 |
|
|---|
| 1594 |
int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii) |
|---|
| 1595 |
{ |
|---|
| 1596 |
struct mem_dqinfo *mi; |
|---|
| 1597 |
|
|---|
| 1598 |
down(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1599 |
if (!sb_has_quota_enabled(sb, type)) { |
|---|
| 1600 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1601 |
return -ESRCH; |
|---|
| 1602 |
} |
|---|
| 1603 |
mi = sb_dqopt(sb)->info + type; |
|---|
| 1604 |
spin_lock(&dq_data_lock); |
|---|
| 1605 |
ii->dqi_bgrace = mi->dqi_bgrace; |
|---|
| 1606 |
ii->dqi_igrace = mi->dqi_igrace; |
|---|
| 1607 |
ii->dqi_flags = mi->dqi_flags & DQF_MASK; |
|---|
| 1608 |
ii->dqi_valid = IIF_ALL; |
|---|
| 1609 |
spin_unlock(&dq_data_lock); |
|---|
| 1610 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1611 |
return 0; |
|---|
| 1612 |
} |
|---|
| 1613 |
|
|---|
| 1614 |
|
|---|
| 1615 |
int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii) |
|---|
| 1616 |
{ |
|---|
| 1617 |
struct mem_dqinfo *mi; |
|---|
| 1618 |
|
|---|
| 1619 |
down(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1620 |
if (!sb_has_quota_enabled(sb, type)) { |
|---|
| 1621 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1622 |
return -ESRCH; |
|---|
| 1623 |
} |
|---|
| 1624 |
mi = sb_dqopt(sb)->info + type; |
|---|
| 1625 |
spin_lock(&dq_data_lock); |
|---|
| 1626 |
if (ii->dqi_valid & IIF_BGRACE) |
|---|
| 1627 |
mi->dqi_bgrace = ii->dqi_bgrace; |
|---|
| 1628 |
if (ii->dqi_valid & IIF_IGRACE) |
|---|
| 1629 |
mi->dqi_igrace = ii->dqi_igrace; |
|---|
| 1630 |
if (ii->dqi_valid & IIF_FLAGS) |
|---|
| 1631 |
mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) | (ii->dqi_flags & DQF_MASK); |
|---|
| 1632 |
spin_unlock(&dq_data_lock); |
|---|
| 1633 |
mark_info_dirty(sb, type); |
|---|
| 1634 |
|
|---|
| 1635 |
sb->dq_op->write_info(sb, type); |
|---|
| 1636 |
up(&sb_dqopt(sb)->dqonoff_sem); |
|---|
| 1637 |
return 0; |
|---|
| 1638 |
} |
|---|
| 1639 |
|
|---|
| 1640 |
struct quotactl_ops vfs_quotactl_ops = { |
|---|
| 1641 |
.quota_on = vfs_quota_on, |
|---|
| 1642 |
.quota_off = vfs_quota_off, |
|---|
| 1643 |
.quota_sync = vfs_quota_sync, |
|---|
| 1644 |
.get_info = vfs_get_dqinfo, |
|---|
| 1645 |
.set_info = vfs_set_dqinfo, |
|---|
| 1646 |
.get_dqblk = vfs_get_dqblk, |
|---|
| 1647 |
.set_dqblk = vfs_set_dqblk |
|---|
| 1648 |
}; |
|---|
| 1649 |
|
|---|
| 1650 |
static ctl_table fs_dqstats_table[] = { |
|---|
| 1651 |
{ |
|---|
| 1652 |
.ctl_name = FS_DQ_LOOKUPS, |
|---|
| 1653 |
.procname = "lookups", |
|---|
| 1654 |
.data = &dqstats.lookups, |
|---|
| 1655 |
.maxlen = sizeof(int), |
|---|
| 1656 |
.mode = 0444, |
|---|
| 1657 |
.proc_handler = &proc_dointvec, |
|---|
| 1658 |
}, |
|---|
| 1659 |
{ |
|---|
| 1660 |
.ctl_name = FS_DQ_DROPS, |
|---|
| 1661 |
.procname = "drops", |
|---|
| 1662 |
.data = &dqstats.drops, |
|---|
| 1663 |
.maxlen = sizeof(int), |
|---|
| 1664 |
.mode = 0444, |
|---|
| 1665 |
.proc_handler = &proc_dointvec, |
|---|
| 1666 |
}, |
|---|
| 1667 |
{ |
|---|
| 1668 |
.ctl_name = FS_DQ_READS, |
|---|
| 1669 |
.procname = "reads", |
|---|
| 1670 |
.data = &dqstats.reads, |
|---|
| 1671 |
.maxlen = sizeof(int), |
|---|
| 1672 |
.mode = 0444, |
|---|
| 1673 |
.proc_handler = &proc_dointvec, |
|---|
| 1674 |
}, |
|---|
| 1675 |
{ |
|---|
| 1676 |
.ctl_name = FS_DQ_WRITES, |
|---|
| 1677 |
.procname = "writes", |
|---|
| 1678 |
.data = &dqstats.writes, |
|---|
| 1679 |
.maxlen = sizeof(int), |
|---|
| 1680 |
.mode = 0444, |
|---|
| 1681 |
.proc_handler = &proc_dointvec, |
|---|
| 1682 |
}, |
|---|
| 1683 |
{ |
|---|
| 1684 |
.ctl_name = FS_DQ_CACHE_HITS, |
|---|
| 1685 |
.procname = "cache_hits", |
|---|
| 1686 |
.data = &dqstats.cache_hits, |
|---|
| 1687 |
.maxlen = sizeof(int), |
|---|
| 1688 |
.mode = 0444, |
|---|
| 1689 |
.proc_handler = &proc_dointvec, |
|---|
| 1690 |
}, |
|---|
| 1691 |
{ |
|---|
| 1692 |
.ctl_name = FS_DQ_ALLOCATED, |
|---|
| 1693 |
.procname = "allocated_dquots", |
|---|
| 1694 |
.data = &dqstats.allocated_dquots, |
|---|
| 1695 |
.maxlen = sizeof(int), |
|---|
| 1696 |
.mode = 0444, |
|---|
| 1697 |
.proc_handler = &proc_dointvec, |
|---|
| 1698 |
}, |
|---|
| 1699 |
{ |
|---|
| 1700 |
.ctl_name = FS_DQ_FREE, |
|---|
| 1701 |
.procname = "free_dquots", |
|---|
| 1702 |
.data = &dqstats.free_dquots, |
|---|
| 1703 |
.maxlen = sizeof(int), |
|---|
| 1704 |
.mode = 0444, |
|---|
| 1705 |
.proc_handler = &proc_dointvec, |
|---|
| 1706 |
}, |
|---|
| 1707 |
{ |
|---|
| 1708 |
.ctl_name = FS_DQ_SYNCS, |
|---|
| 1709 |
.procname = "syncs", |
|---|
| 1710 |
.data = &dqstats.syncs, |
|---|
| 1711 |
.maxlen = sizeof(int), |
|---|
| 1712 |
.mode = 0444, |
|---|
| 1713 |
.proc_handler = &proc_dointvec, |
|---|
| 1714 |
}, |
|---|
| 1715 |
{ .ctl_name = 0 }, |
|---|
| 1716 |
}; |
|---|
| 1717 |
|
|---|
| 1718 |
static ctl_table fs_table[] = { |
|---|
| 1719 |
{ |
|---|
| 1720 |
.ctl_name = FS_DQSTATS, |
|---|
| 1721 |
.procname = "quota", |
|---|
| 1722 |
.mode = 0555, |
|---|
| 1723 |
.child = fs_dqstats_table, |
|---|
| 1724 |
}, |
|---|
| 1725 |
{ .ctl_name = 0 }, |
|---|
| 1726 |
}; |
|---|
| 1727 |
|
|---|
| 1728 |
static ctl_table sys_table[] = { |
|---|
| 1729 |
{ |
|---|
| 1730 |
.ctl_name = CTL_FS, |
|---|
| 1731 |
.procname = "fs", |
|---|
| 1732 |
.mode = 0555, |
|---|
| 1733 |
.child = fs_table, |
|---|
| 1734 |
}, |
|---|
| 1735 |
{ .ctl_name = 0 }, |
|---|
| 1736 |
}; |
|---|
| 1737 |
|
|---|
| 1738 |
|
|---|
| 1739 |
kmem_cache_t *dquot_cachep; |
|---|
| 1740 |
|
|---|
| 1741 |
static int __init dquot_init(void) |
|---|
| 1742 |
{ |
|---|
| 1743 |
int i; |
|---|
| 1744 |
unsigned long nr_hash, order; |
|---|
| 1745 |
|
|---|
| 1746 |
printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__); |
|---|
| 1747 |
|
|---|
| 1748 |
register_sysctl_table(sys_table, 0); |
|---|
| 1749 |
|
|---|
| 1750 |
dquot_cachep = kmem_cache_create("dquot", |
|---|
| 1751 |
sizeof(struct dquot), sizeof(unsigned long) * 4, |
|---|
| 1752 |
SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_PANIC, |
|---|
| 1753 |
NULL, NULL); |
|---|
| 1754 |
|
|---|
| 1755 |
order = 0; |
|---|
| 1756 |
dquot_hash = (struct hlist_head *)__get_free_pages(GFP_ATOMIC, order); |
|---|
| 1757 |
if (!dquot_hash) |
|---|
| 1758 |
panic("Cannot create dquot hash table"); |
|---|
| 1759 |
|
|---|
| 1760 |
|
|---|
| 1761 |
nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head); |
|---|
| 1762 |
dq_hash_bits = 0; |
|---|
| 1763 |
do { |
|---|
| 1764 |
dq_hash_bits++; |
|---|
| 1765 |
} while (nr_hash >> dq_hash_bits); |
|---|
| 1766 |
dq_hash_bits--; |
|---|
| 1767 |
|
|---|
| 1768 |
nr_hash = 1UL << dq_hash_bits; |
|---|
| 1769 |
dq_hash_mask = nr_hash - 1; |
|---|
| 1770 |
for (i = 0; i < nr_hash; i++) |
|---|
| 1771 |
INIT_HLIST_HEAD(dquot_hash + i); |
|---|
| 1772 |
|
|---|
| 1773 |
printk("Dquot-cache hash table entries: %ld (order %ld, %ld bytes)\n", |
|---|
| 1774 |
nr_hash, order, (PAGE_SIZE << order)); |
|---|
| 1775 |
|
|---|
| 1776 |
set_shrinker(DEFAULT_SEEKS, shrink_dqcache_memory); |
|---|
| 1777 |
|
|---|
| 1778 |
return 0; |
|---|
| 1779 |
} |
|---|
| 1780 |
module_init(dquot_init); |
|---|
| 1781 |
|
|---|
| 1782 |
EXPORT_SYMBOL(register_quota_format); |
|---|
| 1783 |
EXPORT_SYMBOL(unregister_quota_format); |
|---|
| 1784 |
EXPORT_SYMBOL(dqstats); |
|---|
| 1785 |
EXPORT_SYMBOL(dq_list_lock); |
|---|
| 1786 |
EXPORT_SYMBOL(dq_data_lock); |
|---|
| 1787 |
EXPORT_SYMBOL(vfs_quota_on); |
|---|
| 1788 |
EXPORT_SYMBOL(vfs_quota_on_mount); |
|---|
| 1789 |
EXPORT_SYMBOL(vfs_quota_off); |
|---|
| 1790 |
EXPORT_SYMBOL(vfs_quota_sync); |
|---|
| 1791 |
EXPORT_SYMBOL(vfs_get_dqinfo); |
|---|
| 1792 |
EXPORT_SYMBOL(vfs_set_dqinfo); |
|---|
| 1793 |
EXPORT_SYMBOL(vfs_get_dqblk); |
|---|
| 1794 |
EXPORT_SYMBOL(vfs_set_dqblk); |
|---|
| 1795 |
EXPORT_SYMBOL(dquot_commit); |
|---|
| 1796 |
EXPORT_SYMBOL(dquot_commit_info); |
|---|
| 1797 |
EXPORT_SYMBOL(dquot_acquire); |
|---|
| 1798 |
EXPORT_SYMBOL(dquot_release); |
|---|
| 1799 |
EXPORT_SYMBOL(dquot_mark_dquot_dirty); |
|---|
| 1800 |
EXPORT_SYMBOL(dquot_initialize); |
|---|
| 1801 |
EXPORT_SYMBOL(dquot_drop); |
|---|
| 1802 |
EXPORT_SYMBOL(dquot_alloc_space); |
|---|
| 1803 |
EXPORT_SYMBOL(dquot_alloc_inode); |
|---|
| 1804 |
EXPORT_SYMBOL(dquot_free_space); |
|---|
| 1805 |
EXPORT_SYMBOL(dquot_free_inode); |
|---|
| 1806 |
EXPORT_SYMBOL(dquot_transfer); |
|---|