.. | .. |
---|
9 | 9 | * on the Melbourne quota system as used on BSD derived systems. The internal |
---|
10 | 10 | * implementation is based on one of the several variants of the LINUX |
---|
11 | 11 | * inode-subsystem with added complexity of the diskquota system. |
---|
12 | | - * |
---|
| 12 | + * |
---|
13 | 13 | * Author: Marco van Wieringen <mvw@planets.elm.net> |
---|
14 | 14 | * |
---|
15 | 15 | * Fixes: Dmitry Gorodchanin <pgmdsg@ibi.com>, 11 Feb 96 |
---|
.. | .. |
---|
51 | 51 | * Added journalled quota support, fix lock inversion problems |
---|
52 | 52 | * Jan Kara, <jack@suse.cz>, 2003,2004 |
---|
53 | 53 | * |
---|
54 | | - * (C) Copyright 1994 - 1997 Marco van Wieringen |
---|
| 54 | + * (C) Copyright 1994 - 1997 Marco van Wieringen |
---|
55 | 55 | */ |
---|
56 | 56 | |
---|
57 | 57 | #include <linux/errno.h> |
---|
.. | .. |
---|
78 | 78 | #include <linux/namei.h> |
---|
79 | 79 | #include <linux/capability.h> |
---|
80 | 80 | #include <linux/quotaops.h> |
---|
| 81 | +#include <linux/blkdev.h> |
---|
| 82 | +#include <linux/sched/mm.h> |
---|
81 | 83 | #include "../internal.h" /* ugh */ |
---|
82 | 84 | |
---|
83 | 85 | #include <linux/uaccess.h> |
---|
.. | .. |
---|
197 | 199 | int qm; |
---|
198 | 200 | |
---|
199 | 201 | spin_unlock(&dq_list_lock); |
---|
200 | | - |
---|
| 202 | + |
---|
201 | 203 | for (qm = 0; module_names[qm].qm_fmt_id && |
---|
202 | 204 | module_names[qm].qm_fmt_id != id; qm++) |
---|
203 | 205 | ; |
---|
.. | .. |
---|
223 | 225 | |
---|
224 | 226 | /* |
---|
225 | 227 | * Dquot List Management: |
---|
226 | | - * The quota code uses three lists for dquot management: the inuse_list, |
---|
227 | | - * free_dquots, and dquot_hash[] array. A single dquot structure may be |
---|
228 | | - * on all three lists, depending on its current state. |
---|
| 228 | + * The quota code uses five lists for dquot management: the inuse_list, |
---|
| 229 | + * releasing_dquots, free_dquots, dqi_dirty_list, and dquot_hash[] array. |
---|
| 230 | + * A single dquot structure may be on some of those lists, depending on |
---|
| 231 | + * its current state. |
---|
229 | 232 | * |
---|
230 | 233 | * All dquots are placed to the end of inuse_list when first created, and this |
---|
231 | 234 | * list is used for invalidate operation, which must look at every dquot. |
---|
| 235 | + * |
---|
| 236 | + * When the last reference of a dquot will be dropped, the dquot will be |
---|
| 237 | + * added to releasing_dquots. We'd then queue work item which would call |
---|
| 238 | + * synchronize_srcu() and after that perform the final cleanup of all the |
---|
| 239 | + * dquots on the list. Both releasing_dquots and free_dquots use the |
---|
| 240 | + * dq_free list_head in the dquot struct. When a dquot is removed from |
---|
| 241 | + * releasing_dquots, a reference count is always subtracted, and if |
---|
| 242 | + * dq_count == 0 at that point, the dquot will be added to the free_dquots. |
---|
232 | 243 | * |
---|
233 | 244 | * Unused dquots (dq_count == 0) are added to the free_dquots list when freed, |
---|
234 | 245 | * and this list is searched whenever we need an available dquot. Dquots are |
---|
235 | 246 | * removed from the list as soon as they are used again, and |
---|
236 | 247 | * dqstats.free_dquots gives the number of dquots on the list. When |
---|
237 | 248 | * dquot is invalidated it's completely released from memory. |
---|
| 249 | + * |
---|
| 250 | + * Dirty dquots are added to the dqi_dirty_list of quota_info when mark |
---|
| 251 | + * dirtied, and this list is searched when writing dirty dquots back to |
---|
| 252 | + * quota file. Note that some filesystems do dirty dquot tracking on their |
---|
| 253 | + * own (e.g. in a journal) and thus don't use dqi_dirty_list. |
---|
238 | 254 | * |
---|
239 | 255 | * Dquots with a specific identity (device, type and id) are placed on |
---|
240 | 256 | * one of the dquot_hash[] hash chains. The provides an efficient search |
---|
.. | .. |
---|
243 | 259 | |
---|
244 | 260 | static LIST_HEAD(inuse_list); |
---|
245 | 261 | static LIST_HEAD(free_dquots); |
---|
| 262 | +static LIST_HEAD(releasing_dquots); |
---|
246 | 263 | static unsigned int dq_hash_bits, dq_hash_mask; |
---|
247 | 264 | static struct hlist_head *dquot_hash; |
---|
248 | 265 | |
---|
.. | .. |
---|
252 | 269 | static qsize_t inode_get_rsv_space(struct inode *inode); |
---|
253 | 270 | static qsize_t __inode_get_rsv_space(struct inode *inode); |
---|
254 | 271 | static int __dquot_initialize(struct inode *inode, int type); |
---|
| 272 | + |
---|
| 273 | +static void quota_release_workfn(struct work_struct *work); |
---|
| 274 | +static DECLARE_DELAYED_WORK(quota_release_work, quota_release_workfn); |
---|
255 | 275 | |
---|
256 | 276 | static inline unsigned int |
---|
257 | 277 | hashfn(const struct super_block *sb, struct kqid qid) |
---|
.. | .. |
---|
300 | 320 | dqstats_inc(DQST_FREE_DQUOTS); |
---|
301 | 321 | } |
---|
302 | 322 | |
---|
| 323 | +static inline void put_releasing_dquots(struct dquot *dquot) |
---|
| 324 | +{ |
---|
| 325 | + list_add_tail(&dquot->dq_free, &releasing_dquots); |
---|
| 326 | +} |
---|
| 327 | + |
---|
303 | 328 | static inline void remove_free_dquot(struct dquot *dquot) |
---|
304 | 329 | { |
---|
305 | 330 | if (list_empty(&dquot->dq_free)) |
---|
306 | 331 | return; |
---|
307 | 332 | list_del_init(&dquot->dq_free); |
---|
308 | | - dqstats_dec(DQST_FREE_DQUOTS); |
---|
| 333 | + if (!atomic_read(&dquot->dq_count)) |
---|
| 334 | + dqstats_dec(DQST_FREE_DQUOTS); |
---|
309 | 335 | } |
---|
310 | 336 | |
---|
311 | 337 | static inline void put_inuse(struct dquot *dquot) |
---|
.. | .. |
---|
331 | 357 | mutex_unlock(&dquot->dq_lock); |
---|
332 | 358 | } |
---|
333 | 359 | |
---|
| 360 | +static inline int dquot_active(struct dquot *dquot) |
---|
| 361 | +{ |
---|
| 362 | + return test_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
---|
| 363 | +} |
---|
| 364 | + |
---|
334 | 365 | static inline int dquot_dirty(struct dquot *dquot) |
---|
335 | 366 | { |
---|
336 | 367 | return test_bit(DQ_MOD_B, &dquot->dq_flags); |
---|
.. | .. |
---|
346 | 377 | { |
---|
347 | 378 | int ret = 1; |
---|
348 | 379 | |
---|
349 | | - if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) |
---|
| 380 | + if (!dquot_active(dquot)) |
---|
350 | 381 | return 0; |
---|
351 | 382 | |
---|
352 | 383 | if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NOLIST_DIRTY) |
---|
353 | 384 | return test_and_set_bit(DQ_MOD_B, &dquot->dq_flags); |
---|
354 | 385 | |
---|
355 | 386 | /* If quota is dirty already, we don't have to acquire dq_list_lock */ |
---|
356 | | - if (test_bit(DQ_MOD_B, &dquot->dq_flags)) |
---|
| 387 | + if (dquot_dirty(dquot)) |
---|
357 | 388 | return 1; |
---|
358 | 389 | |
---|
359 | 390 | spin_lock(&dq_list_lock); |
---|
.. | .. |
---|
421 | 452 | int dquot_acquire(struct dquot *dquot) |
---|
422 | 453 | { |
---|
423 | 454 | int ret = 0, ret2 = 0; |
---|
| 455 | + unsigned int memalloc; |
---|
424 | 456 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
---|
425 | 457 | |
---|
426 | 458 | mutex_lock(&dquot->dq_lock); |
---|
427 | | - if (!test_bit(DQ_READ_B, &dquot->dq_flags)) |
---|
| 459 | + memalloc = memalloc_nofs_save(); |
---|
| 460 | + if (!test_bit(DQ_READ_B, &dquot->dq_flags)) { |
---|
428 | 461 | ret = dqopt->ops[dquot->dq_id.type]->read_dqblk(dquot); |
---|
429 | | - if (ret < 0) |
---|
430 | | - goto out_iolock; |
---|
| 462 | + if (ret < 0) |
---|
| 463 | + goto out_iolock; |
---|
| 464 | + } |
---|
431 | 465 | /* Make sure flags update is visible after dquot has been filled */ |
---|
432 | 466 | smp_mb__before_atomic(); |
---|
433 | 467 | set_bit(DQ_READ_B, &dquot->dq_flags); |
---|
434 | 468 | /* Instantiate dquot if needed */ |
---|
435 | | - if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) { |
---|
| 469 | + if (!dquot_active(dquot) && !dquot->dq_off) { |
---|
436 | 470 | ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot); |
---|
437 | 471 | /* Write the info if needed */ |
---|
438 | 472 | if (info_dirty(&dqopt->info[dquot->dq_id.type])) { |
---|
.. | .. |
---|
453 | 487 | smp_mb__before_atomic(); |
---|
454 | 488 | set_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
---|
455 | 489 | out_iolock: |
---|
| 490 | + memalloc_nofs_restore(memalloc); |
---|
456 | 491 | mutex_unlock(&dquot->dq_lock); |
---|
457 | 492 | return ret; |
---|
458 | 493 | } |
---|
.. | .. |
---|
464 | 499 | int dquot_commit(struct dquot *dquot) |
---|
465 | 500 | { |
---|
466 | 501 | int ret = 0; |
---|
| 502 | + unsigned int memalloc; |
---|
467 | 503 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
---|
468 | 504 | |
---|
469 | 505 | mutex_lock(&dquot->dq_lock); |
---|
| 506 | + memalloc = memalloc_nofs_save(); |
---|
470 | 507 | if (!clear_dquot_dirty(dquot)) |
---|
471 | 508 | goto out_lock; |
---|
472 | 509 | /* Inactive dquot can be only if there was error during read/init |
---|
473 | 510 | * => we have better not writing it */ |
---|
474 | | - if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) |
---|
| 511 | + if (dquot_active(dquot)) |
---|
475 | 512 | ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot); |
---|
476 | 513 | else |
---|
477 | 514 | ret = -EIO; |
---|
478 | 515 | out_lock: |
---|
| 516 | + memalloc_nofs_restore(memalloc); |
---|
479 | 517 | mutex_unlock(&dquot->dq_lock); |
---|
480 | 518 | return ret; |
---|
481 | 519 | } |
---|
.. | .. |
---|
487 | 525 | int dquot_release(struct dquot *dquot) |
---|
488 | 526 | { |
---|
489 | 527 | int ret = 0, ret2 = 0; |
---|
| 528 | + unsigned int memalloc; |
---|
490 | 529 | struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); |
---|
491 | 530 | |
---|
492 | 531 | mutex_lock(&dquot->dq_lock); |
---|
| 532 | + memalloc = memalloc_nofs_save(); |
---|
493 | 533 | /* Check whether we are not racing with some other dqget() */ |
---|
494 | 534 | if (dquot_is_busy(dquot)) |
---|
495 | 535 | goto out_dqlock; |
---|
.. | .. |
---|
505 | 545 | } |
---|
506 | 546 | clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); |
---|
507 | 547 | out_dqlock: |
---|
| 548 | + memalloc_nofs_restore(memalloc); |
---|
508 | 549 | mutex_unlock(&dquot->dq_lock); |
---|
509 | 550 | return ret; |
---|
510 | 551 | } |
---|
.. | .. |
---|
532 | 573 | struct dquot *dquot, *tmp; |
---|
533 | 574 | |
---|
534 | 575 | restart: |
---|
| 576 | + flush_delayed_work("a_release_work); |
---|
| 577 | + |
---|
535 | 578 | spin_lock(&dq_list_lock); |
---|
536 | 579 | list_for_each_entry_safe(dquot, tmp, &inuse_list, dq_inuse) { |
---|
537 | 580 | if (dquot->dq_sb != sb) |
---|
.. | .. |
---|
540 | 583 | continue; |
---|
541 | 584 | /* Wait for dquot users */ |
---|
542 | 585 | if (atomic_read(&dquot->dq_count)) { |
---|
543 | | - dqgrab(dquot); |
---|
| 586 | + /* dquot in releasing_dquots, flush and retry */ |
---|
| 587 | + if (!list_empty(&dquot->dq_free)) { |
---|
| 588 | + spin_unlock(&dq_list_lock); |
---|
| 589 | + goto restart; |
---|
| 590 | + } |
---|
| 591 | + |
---|
| 592 | + atomic_inc(&dquot->dq_count); |
---|
544 | 593 | spin_unlock(&dq_list_lock); |
---|
545 | 594 | /* |
---|
546 | 595 | * Once dqput() wakes us up, we know it's time to free |
---|
.. | .. |
---|
582 | 631 | |
---|
583 | 632 | spin_lock(&dq_list_lock); |
---|
584 | 633 | list_for_each_entry(dquot, &inuse_list, dq_inuse) { |
---|
585 | | - if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) |
---|
| 634 | + if (!dquot_active(dquot)) |
---|
586 | 635 | continue; |
---|
587 | 636 | if (dquot->dq_sb != sb) |
---|
588 | 637 | continue; |
---|
589 | 638 | /* Now we have active dquot so we can just increase use count */ |
---|
590 | 639 | atomic_inc(&dquot->dq_count); |
---|
591 | 640 | spin_unlock(&dq_list_lock); |
---|
592 | | - dqstats_inc(DQST_LOOKUPS); |
---|
593 | 641 | dqput(old_dquot); |
---|
594 | 642 | old_dquot = dquot; |
---|
595 | 643 | /* |
---|
.. | .. |
---|
598 | 646 | * outstanding call and recheck the DQ_ACTIVE_B after that. |
---|
599 | 647 | */ |
---|
600 | 648 | wait_on_dquot(dquot); |
---|
601 | | - if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
---|
| 649 | + if (dquot_active(dquot)) { |
---|
602 | 650 | ret = fn(dquot, priv); |
---|
603 | 651 | if (ret < 0) |
---|
604 | 652 | goto out; |
---|
.. | .. |
---|
613 | 661 | return ret; |
---|
614 | 662 | } |
---|
615 | 663 | EXPORT_SYMBOL(dquot_scan_active); |
---|
| 664 | + |
---|
| 665 | +static inline int dquot_write_dquot(struct dquot *dquot) |
---|
| 666 | +{ |
---|
| 667 | + int ret = dquot->dq_sb->dq_op->write_dquot(dquot); |
---|
| 668 | + if (ret < 0) { |
---|
| 669 | + quota_error(dquot->dq_sb, "Can't write quota structure " |
---|
| 670 | + "(error %d). Quota may get out of sync!", ret); |
---|
| 671 | + /* Clear dirty bit anyway to avoid infinite loop. */ |
---|
| 672 | + clear_dquot_dirty(dquot); |
---|
| 673 | + } |
---|
| 674 | + return ret; |
---|
| 675 | +} |
---|
616 | 676 | |
---|
617 | 677 | /* Write all dquot structures to quota files */ |
---|
618 | 678 | int dquot_writeback_dquots(struct super_block *sb, int type) |
---|
.. | .. |
---|
637 | 697 | dquot = list_first_entry(&dirty, struct dquot, |
---|
638 | 698 | dq_dirty); |
---|
639 | 699 | |
---|
640 | | - WARN_ON(!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)); |
---|
| 700 | + WARN_ON(!dquot_active(dquot)); |
---|
641 | 701 | |
---|
642 | 702 | /* Now we have active dquot from which someone is |
---|
643 | 703 | * holding reference so we can safely just increase |
---|
644 | 704 | * use count */ |
---|
645 | 705 | dqgrab(dquot); |
---|
646 | 706 | spin_unlock(&dq_list_lock); |
---|
647 | | - dqstats_inc(DQST_LOOKUPS); |
---|
648 | | - err = sb->dq_op->write_dquot(dquot); |
---|
649 | | - if (err) { |
---|
650 | | - /* |
---|
651 | | - * Clear dirty bit anyway to avoid infinite |
---|
652 | | - * loop here. |
---|
653 | | - */ |
---|
654 | | - clear_dquot_dirty(dquot); |
---|
655 | | - if (!ret) |
---|
656 | | - ret = err; |
---|
657 | | - } |
---|
| 707 | + err = dquot_write_dquot(dquot); |
---|
| 708 | + if (err && !ret) |
---|
| 709 | + ret = err; |
---|
658 | 710 | dqput(dquot); |
---|
659 | 711 | spin_lock(&dq_list_lock); |
---|
660 | 712 | } |
---|
.. | .. |
---|
748 | 800 | }; |
---|
749 | 801 | |
---|
750 | 802 | /* |
---|
| 803 | + * Safely release dquot and put reference to dquot. |
---|
| 804 | + */ |
---|
| 805 | +static void quota_release_workfn(struct work_struct *work) |
---|
| 806 | +{ |
---|
| 807 | + struct dquot *dquot; |
---|
| 808 | + struct list_head rls_head; |
---|
| 809 | + |
---|
| 810 | + spin_lock(&dq_list_lock); |
---|
| 811 | + /* Exchange the list head to avoid livelock. */ |
---|
| 812 | + list_replace_init(&releasing_dquots, &rls_head); |
---|
| 813 | + spin_unlock(&dq_list_lock); |
---|
| 814 | + |
---|
| 815 | +restart: |
---|
| 816 | + synchronize_srcu(&dquot_srcu); |
---|
| 817 | + spin_lock(&dq_list_lock); |
---|
| 818 | + while (!list_empty(&rls_head)) { |
---|
| 819 | + dquot = list_first_entry(&rls_head, struct dquot, dq_free); |
---|
| 820 | + /* Dquot got used again? */ |
---|
| 821 | + if (atomic_read(&dquot->dq_count) > 1) { |
---|
| 822 | + remove_free_dquot(dquot); |
---|
| 823 | + atomic_dec(&dquot->dq_count); |
---|
| 824 | + continue; |
---|
| 825 | + } |
---|
| 826 | + if (dquot_dirty(dquot)) { |
---|
| 827 | + spin_unlock(&dq_list_lock); |
---|
| 828 | + /* Commit dquot before releasing */ |
---|
| 829 | + dquot_write_dquot(dquot); |
---|
| 830 | + goto restart; |
---|
| 831 | + } |
---|
| 832 | + if (dquot_active(dquot)) { |
---|
| 833 | + spin_unlock(&dq_list_lock); |
---|
| 834 | + dquot->dq_sb->dq_op->release_dquot(dquot); |
---|
| 835 | + goto restart; |
---|
| 836 | + } |
---|
| 837 | + /* Dquot is inactive and clean, now move it to free list */ |
---|
| 838 | + remove_free_dquot(dquot); |
---|
| 839 | + atomic_dec(&dquot->dq_count); |
---|
| 840 | + put_dquot_last(dquot); |
---|
| 841 | + } |
---|
| 842 | + spin_unlock(&dq_list_lock); |
---|
| 843 | +} |
---|
| 844 | + |
---|
| 845 | +/* |
---|
751 | 846 | * Put reference to dquot |
---|
752 | 847 | */ |
---|
753 | 848 | void dqput(struct dquot *dquot) |
---|
754 | 849 | { |
---|
755 | | - int ret; |
---|
756 | | - |
---|
757 | 850 | if (!dquot) |
---|
758 | 851 | return; |
---|
759 | 852 | #ifdef CONFIG_QUOTA_DEBUG |
---|
.. | .. |
---|
765 | 858 | } |
---|
766 | 859 | #endif |
---|
767 | 860 | dqstats_inc(DQST_DROPS); |
---|
768 | | -we_slept: |
---|
| 861 | + |
---|
769 | 862 | spin_lock(&dq_list_lock); |
---|
770 | 863 | if (atomic_read(&dquot->dq_count) > 1) { |
---|
771 | 864 | /* We have more than one user... nothing to do */ |
---|
.. | .. |
---|
777 | 870 | spin_unlock(&dq_list_lock); |
---|
778 | 871 | return; |
---|
779 | 872 | } |
---|
| 873 | + |
---|
780 | 874 | /* Need to release dquot? */ |
---|
781 | | - if (dquot_dirty(dquot)) { |
---|
782 | | - spin_unlock(&dq_list_lock); |
---|
783 | | - /* Commit dquot before releasing */ |
---|
784 | | - ret = dquot->dq_sb->dq_op->write_dquot(dquot); |
---|
785 | | - if (ret < 0) { |
---|
786 | | - quota_error(dquot->dq_sb, "Can't write quota structure" |
---|
787 | | - " (error %d). Quota may get out of sync!", |
---|
788 | | - ret); |
---|
789 | | - /* |
---|
790 | | - * We clear dirty bit anyway, so that we avoid |
---|
791 | | - * infinite loop here |
---|
792 | | - */ |
---|
793 | | - clear_dquot_dirty(dquot); |
---|
794 | | - } |
---|
795 | | - goto we_slept; |
---|
796 | | - } |
---|
797 | | - if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
---|
798 | | - spin_unlock(&dq_list_lock); |
---|
799 | | - dquot->dq_sb->dq_op->release_dquot(dquot); |
---|
800 | | - goto we_slept; |
---|
801 | | - } |
---|
802 | | - atomic_dec(&dquot->dq_count); |
---|
803 | 875 | #ifdef CONFIG_QUOTA_DEBUG |
---|
804 | 876 | /* sanity check */ |
---|
805 | 877 | BUG_ON(!list_empty(&dquot->dq_free)); |
---|
806 | 878 | #endif |
---|
807 | | - put_dquot_last(dquot); |
---|
| 879 | + put_releasing_dquots(dquot); |
---|
808 | 880 | spin_unlock(&dq_list_lock); |
---|
| 881 | + queue_delayed_work(system_unbound_wq, "a_release_work, 1); |
---|
809 | 882 | } |
---|
810 | 883 | EXPORT_SYMBOL(dqput); |
---|
811 | 884 | |
---|
.. | .. |
---|
895 | 968 | * already finished or it will be canceled due to dq_count > 1 test */ |
---|
896 | 969 | wait_on_dquot(dquot); |
---|
897 | 970 | /* Read the dquot / allocate space in quota file */ |
---|
898 | | - if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { |
---|
| 971 | + if (!dquot_active(dquot)) { |
---|
899 | 972 | int err; |
---|
900 | 973 | |
---|
901 | 974 | err = sb->dq_op->acquire_dquot(dquot); |
---|
.. | .. |
---|
1056 | 1129 | struct list_head *tofree_head) |
---|
1057 | 1130 | { |
---|
1058 | 1131 | struct inode *inode; |
---|
| 1132 | +#ifdef CONFIG_QUOTA_DEBUG |
---|
1059 | 1133 | int reserved = 0; |
---|
| 1134 | +#endif |
---|
1060 | 1135 | |
---|
1061 | 1136 | spin_lock(&sb->s_inode_list_lock); |
---|
1062 | 1137 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { |
---|
.. | .. |
---|
1068 | 1143 | */ |
---|
1069 | 1144 | spin_lock(&dq_data_lock); |
---|
1070 | 1145 | if (!IS_NOQUOTA(inode)) { |
---|
| 1146 | +#ifdef CONFIG_QUOTA_DEBUG |
---|
1071 | 1147 | if (unlikely(inode_get_rsv_space(inode) > 0)) |
---|
1072 | 1148 | reserved = 1; |
---|
| 1149 | +#endif |
---|
1073 | 1150 | remove_inode_dquot_ref(inode, type, tofree_head); |
---|
1074 | 1151 | } |
---|
1075 | 1152 | spin_unlock(&dq_data_lock); |
---|
.. | .. |
---|
1408 | 1485 | return QUOTA_NL_NOWARN; |
---|
1409 | 1486 | } |
---|
1410 | 1487 | |
---|
1411 | | -static int dquot_active(const struct inode *inode) |
---|
| 1488 | +static int inode_quota_active(const struct inode *inode) |
---|
1412 | 1489 | { |
---|
1413 | 1490 | struct super_block *sb = inode->i_sb; |
---|
1414 | 1491 | |
---|
.. | .. |
---|
1431 | 1508 | qsize_t rsv; |
---|
1432 | 1509 | int ret = 0; |
---|
1433 | 1510 | |
---|
1434 | | - if (!dquot_active(inode)) |
---|
| 1511 | + if (!inode_quota_active(inode)) |
---|
1435 | 1512 | return 0; |
---|
1436 | 1513 | |
---|
1437 | 1514 | dquots = i_dquot(inode); |
---|
.. | .. |
---|
1539 | 1616 | struct dquot **dquots; |
---|
1540 | 1617 | int i; |
---|
1541 | 1618 | |
---|
1542 | | - if (!dquot_active(inode)) |
---|
| 1619 | + if (!inode_quota_active(inode)) |
---|
1543 | 1620 | return false; |
---|
1544 | 1621 | |
---|
1545 | 1622 | dquots = i_dquot(inode); |
---|
.. | .. |
---|
1650 | 1727 | int reserve = flags & DQUOT_SPACE_RESERVE; |
---|
1651 | 1728 | struct dquot **dquots; |
---|
1652 | 1729 | |
---|
1653 | | - if (!dquot_active(inode)) { |
---|
| 1730 | + if (!inode_quota_active(inode)) { |
---|
1654 | 1731 | if (reserve) { |
---|
1655 | 1732 | spin_lock(&inode->i_lock); |
---|
1656 | 1733 | *inode_reserved_space(inode) += number; |
---|
.. | .. |
---|
1670 | 1747 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
---|
1671 | 1748 | if (!dquots[cnt]) |
---|
1672 | 1749 | continue; |
---|
1673 | | - if (flags & DQUOT_SPACE_RESERVE) { |
---|
| 1750 | + if (reserve) { |
---|
1674 | 1751 | ret = dquot_add_space(dquots[cnt], 0, number, flags, |
---|
1675 | 1752 | &warn[cnt]); |
---|
1676 | 1753 | } else { |
---|
.. | .. |
---|
1683 | 1760 | if (!dquots[cnt]) |
---|
1684 | 1761 | continue; |
---|
1685 | 1762 | spin_lock(&dquots[cnt]->dq_dqb_lock); |
---|
1686 | | - if (flags & DQUOT_SPACE_RESERVE) { |
---|
1687 | | - dquots[cnt]->dq_dqb.dqb_rsvspace -= |
---|
1688 | | - number; |
---|
1689 | | - } else { |
---|
1690 | | - dquots[cnt]->dq_dqb.dqb_curspace -= |
---|
1691 | | - number; |
---|
1692 | | - } |
---|
| 1763 | + if (reserve) |
---|
| 1764 | + dquot_free_reserved_space(dquots[cnt], |
---|
| 1765 | + number); |
---|
| 1766 | + else |
---|
| 1767 | + dquot_decr_space(dquots[cnt], number); |
---|
1693 | 1768 | spin_unlock(&dquots[cnt]->dq_dqb_lock); |
---|
1694 | 1769 | } |
---|
1695 | 1770 | spin_unlock(&inode->i_lock); |
---|
.. | .. |
---|
1722 | 1797 | struct dquot_warn warn[MAXQUOTAS]; |
---|
1723 | 1798 | struct dquot * const *dquots; |
---|
1724 | 1799 | |
---|
1725 | | - if (!dquot_active(inode)) |
---|
| 1800 | + if (!inode_quota_active(inode)) |
---|
1726 | 1801 | return 0; |
---|
1727 | 1802 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
---|
1728 | 1803 | warn[cnt].w_type = QUOTA_NL_NOWARN; |
---|
.. | .. |
---|
1740 | 1815 | continue; |
---|
1741 | 1816 | /* Back out changes we already did */ |
---|
1742 | 1817 | spin_lock(&dquots[cnt]->dq_dqb_lock); |
---|
1743 | | - dquots[cnt]->dq_dqb.dqb_curinodes--; |
---|
| 1818 | + dquot_decr_inodes(dquots[cnt], 1); |
---|
1744 | 1819 | spin_unlock(&dquots[cnt]->dq_dqb_lock); |
---|
1745 | 1820 | } |
---|
1746 | 1821 | goto warn_put_all; |
---|
.. | .. |
---|
1765 | 1840 | struct dquot **dquots; |
---|
1766 | 1841 | int cnt, index; |
---|
1767 | 1842 | |
---|
1768 | | - if (!dquot_active(inode)) { |
---|
| 1843 | + if (!inode_quota_active(inode)) { |
---|
1769 | 1844 | spin_lock(&inode->i_lock); |
---|
1770 | 1845 | *inode_reserved_space(inode) -= number; |
---|
1771 | 1846 | __inode_add_bytes(inode, number); |
---|
.. | .. |
---|
1807 | 1882 | struct dquot **dquots; |
---|
1808 | 1883 | int cnt, index; |
---|
1809 | 1884 | |
---|
1810 | | - if (!dquot_active(inode)) { |
---|
| 1885 | + if (!inode_quota_active(inode)) { |
---|
1811 | 1886 | spin_lock(&inode->i_lock); |
---|
1812 | 1887 | *inode_reserved_space(inode) += number; |
---|
1813 | 1888 | __inode_sub_bytes(inode, number); |
---|
.. | .. |
---|
1851 | 1926 | struct dquot **dquots; |
---|
1852 | 1927 | int reserve = flags & DQUOT_SPACE_RESERVE, index; |
---|
1853 | 1928 | |
---|
1854 | | - if (!dquot_active(inode)) { |
---|
| 1929 | + if (!inode_quota_active(inode)) { |
---|
1855 | 1930 | if (reserve) { |
---|
1856 | 1931 | spin_lock(&inode->i_lock); |
---|
1857 | 1932 | *inode_reserved_space(inode) -= number; |
---|
.. | .. |
---|
1906 | 1981 | struct dquot * const *dquots; |
---|
1907 | 1982 | int index; |
---|
1908 | 1983 | |
---|
1909 | | - if (!dquot_active(inode)) |
---|
| 1984 | + if (!inode_quota_active(inode)) |
---|
1910 | 1985 | return; |
---|
1911 | 1986 | |
---|
1912 | 1987 | dquots = i_dquot(inode); |
---|
.. | .. |
---|
2077 | 2152 | struct super_block *sb = inode->i_sb; |
---|
2078 | 2153 | int ret; |
---|
2079 | 2154 | |
---|
2080 | | - if (!dquot_active(inode)) |
---|
| 2155 | + if (!inode_quota_active(inode)) |
---|
2081 | 2156 | return 0; |
---|
2082 | 2157 | |
---|
2083 | 2158 | if (iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)){ |
---|
.. | .. |
---|
2161 | 2236 | } |
---|
2162 | 2237 | EXPORT_SYMBOL(dquot_file_open); |
---|
2163 | 2238 | |
---|
| 2239 | +static void vfs_cleanup_quota_inode(struct super_block *sb, int type) |
---|
| 2240 | +{ |
---|
| 2241 | + struct quota_info *dqopt = sb_dqopt(sb); |
---|
| 2242 | + struct inode *inode = dqopt->files[type]; |
---|
| 2243 | + |
---|
| 2244 | + if (!inode) |
---|
| 2245 | + return; |
---|
| 2246 | + if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
---|
| 2247 | + inode_lock(inode); |
---|
| 2248 | + inode->i_flags &= ~S_NOQUOTA; |
---|
| 2249 | + inode_unlock(inode); |
---|
| 2250 | + } |
---|
| 2251 | + dqopt->files[type] = NULL; |
---|
| 2252 | + iput(inode); |
---|
| 2253 | +} |
---|
| 2254 | + |
---|
2164 | 2255 | /* |
---|
2165 | 2256 | * Turn quota off on a device. type == -1 ==> quotaoff for all types (umount) |
---|
2166 | 2257 | */ |
---|
2167 | 2258 | int dquot_disable(struct super_block *sb, int type, unsigned int flags) |
---|
2168 | 2259 | { |
---|
2169 | | - int cnt, ret = 0; |
---|
| 2260 | + int cnt; |
---|
2170 | 2261 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2171 | | - struct inode *toputinode[MAXQUOTAS]; |
---|
2172 | 2262 | |
---|
2173 | 2263 | /* s_umount should be held in exclusive mode */ |
---|
2174 | 2264 | if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount))) |
---|
.. | .. |
---|
2190 | 2280 | return 0; |
---|
2191 | 2281 | |
---|
2192 | 2282 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
---|
2193 | | - toputinode[cnt] = NULL; |
---|
2194 | 2283 | if (type != -1 && cnt != type) |
---|
2195 | 2284 | continue; |
---|
2196 | 2285 | if (!sb_has_quota_loaded(sb, cnt)) |
---|
.. | .. |
---|
2210 | 2299 | dqopt->flags &= ~dquot_state_flag( |
---|
2211 | 2300 | DQUOT_SUSPENDED, cnt); |
---|
2212 | 2301 | spin_unlock(&dq_state_lock); |
---|
2213 | | - iput(dqopt->files[cnt]); |
---|
2214 | | - dqopt->files[cnt] = NULL; |
---|
| 2302 | + vfs_cleanup_quota_inode(sb, cnt); |
---|
2215 | 2303 | continue; |
---|
2216 | 2304 | } |
---|
2217 | 2305 | spin_unlock(&dq_state_lock); |
---|
.. | .. |
---|
2233 | 2321 | if (dqopt->ops[cnt]->free_file_info) |
---|
2234 | 2322 | dqopt->ops[cnt]->free_file_info(sb, cnt); |
---|
2235 | 2323 | put_quota_format(dqopt->info[cnt].dqi_format); |
---|
2236 | | - |
---|
2237 | | - toputinode[cnt] = dqopt->files[cnt]; |
---|
2238 | | - if (!sb_has_quota_loaded(sb, cnt)) |
---|
2239 | | - dqopt->files[cnt] = NULL; |
---|
2240 | 2324 | dqopt->info[cnt].dqi_flags = 0; |
---|
2241 | 2325 | dqopt->info[cnt].dqi_igrace = 0; |
---|
2242 | 2326 | dqopt->info[cnt].dqi_bgrace = 0; |
---|
.. | .. |
---|
2258 | 2342 | * must also discard the blockdev buffers so that we see the |
---|
2259 | 2343 | * changes done by userspace on the next quotaon() */ |
---|
2260 | 2344 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
---|
2261 | | - /* This can happen when suspending quotas on remount-ro... */ |
---|
2262 | | - if (toputinode[cnt] && !sb_has_quota_loaded(sb, cnt)) { |
---|
2263 | | - inode_lock(toputinode[cnt]); |
---|
2264 | | - toputinode[cnt]->i_flags &= ~S_NOQUOTA; |
---|
2265 | | - truncate_inode_pages(&toputinode[cnt]->i_data, 0); |
---|
2266 | | - inode_unlock(toputinode[cnt]); |
---|
2267 | | - mark_inode_dirty_sync(toputinode[cnt]); |
---|
| 2345 | + if (!sb_has_quota_loaded(sb, cnt) && dqopt->files[cnt]) { |
---|
| 2346 | + inode_lock(dqopt->files[cnt]); |
---|
| 2347 | + truncate_inode_pages(&dqopt->files[cnt]->i_data, 0); |
---|
| 2348 | + inode_unlock(dqopt->files[cnt]); |
---|
2268 | 2349 | } |
---|
2269 | 2350 | if (sb->s_bdev) |
---|
2270 | 2351 | invalidate_bdev(sb->s_bdev); |
---|
2271 | 2352 | put_inodes: |
---|
| 2353 | + /* We are done when suspending quotas */ |
---|
| 2354 | + if (flags & DQUOT_SUSPENDED) |
---|
| 2355 | + return 0; |
---|
| 2356 | + |
---|
2272 | 2357 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
---|
2273 | | - if (toputinode[cnt]) { |
---|
2274 | | - /* On remount RO, we keep the inode pointer so that we |
---|
2275 | | - * can reenable quota on the subsequent remount RW. We |
---|
2276 | | - * have to check 'flags' variable and not use sb_has_ |
---|
2277 | | - * function because another quotaon / quotaoff could |
---|
2278 | | - * change global state before we got here. We refuse |
---|
2279 | | - * to suspend quotas when there is pending delete on |
---|
2280 | | - * the quota file... */ |
---|
2281 | | - if (!(flags & DQUOT_SUSPENDED)) |
---|
2282 | | - iput(toputinode[cnt]); |
---|
2283 | | - else if (!toputinode[cnt]->i_nlink) |
---|
2284 | | - ret = -EBUSY; |
---|
2285 | | - } |
---|
2286 | | - return ret; |
---|
| 2358 | + if (!sb_has_quota_loaded(sb, cnt)) |
---|
| 2359 | + vfs_cleanup_quota_inode(sb, cnt); |
---|
| 2360 | + return 0; |
---|
2287 | 2361 | } |
---|
2288 | 2362 | EXPORT_SYMBOL(dquot_disable); |
---|
2289 | 2363 | |
---|
.. | .. |
---|
2298 | 2372 | * Turn quotas on on a device |
---|
2299 | 2373 | */ |
---|
2300 | 2374 | |
---|
2301 | | -/* |
---|
2302 | | - * Helper function to turn quotas on when we already have the inode of |
---|
2303 | | - * quota file and no quota information is loaded. |
---|
2304 | | - */ |
---|
2305 | | -static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, |
---|
| 2375 | +static int vfs_setup_quota_inode(struct inode *inode, int type) |
---|
| 2376 | +{ |
---|
| 2377 | + struct super_block *sb = inode->i_sb; |
---|
| 2378 | + struct quota_info *dqopt = sb_dqopt(sb); |
---|
| 2379 | + |
---|
| 2380 | + if (is_bad_inode(inode)) |
---|
| 2381 | + return -EUCLEAN; |
---|
| 2382 | + if (!S_ISREG(inode->i_mode)) |
---|
| 2383 | + return -EACCES; |
---|
| 2384 | + if (IS_RDONLY(inode)) |
---|
| 2385 | + return -EROFS; |
---|
| 2386 | + if (sb_has_quota_loaded(sb, type)) |
---|
| 2387 | + return -EBUSY; |
---|
| 2388 | + |
---|
| 2389 | + dqopt->files[type] = igrab(inode); |
---|
| 2390 | + if (!dqopt->files[type]) |
---|
| 2391 | + return -EIO; |
---|
| 2392 | + if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
---|
| 2393 | + /* We don't want quota and atime on quota files (deadlocks |
---|
| 2394 | + * possible) Also nobody should write to the file - we use |
---|
| 2395 | + * special IO operations which ignore the immutable bit. */ |
---|
| 2396 | + inode_lock(inode); |
---|
| 2397 | + inode->i_flags |= S_NOQUOTA; |
---|
| 2398 | + inode_unlock(inode); |
---|
| 2399 | + /* |
---|
| 2400 | + * When S_NOQUOTA is set, remove dquot references as no more |
---|
| 2401 | + * references can be added |
---|
| 2402 | + */ |
---|
| 2403 | + __dquot_drop(inode); |
---|
| 2404 | + } |
---|
| 2405 | + return 0; |
---|
| 2406 | +} |
---|
| 2407 | + |
---|
| 2408 | +int dquot_load_quota_sb(struct super_block *sb, int type, int format_id, |
---|
2306 | 2409 | unsigned int flags) |
---|
2307 | 2410 | { |
---|
2308 | 2411 | struct quota_format_type *fmt = find_quota_format(format_id); |
---|
2309 | | - struct super_block *sb = inode->i_sb; |
---|
2310 | 2412 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2311 | 2413 | int error; |
---|
2312 | 2414 | |
---|
| 2415 | + /* Just unsuspend quotas? */ |
---|
| 2416 | + BUG_ON(flags & DQUOT_SUSPENDED); |
---|
| 2417 | + /* s_umount should be held in exclusive mode */ |
---|
| 2418 | + if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount))) |
---|
| 2419 | + up_read(&sb->s_umount); |
---|
| 2420 | + |
---|
2313 | 2421 | if (!fmt) |
---|
2314 | 2422 | return -ESRCH; |
---|
2315 | | - if (!S_ISREG(inode->i_mode)) { |
---|
2316 | | - error = -EACCES; |
---|
2317 | | - goto out_fmt; |
---|
2318 | | - } |
---|
2319 | | - if (IS_RDONLY(inode)) { |
---|
2320 | | - error = -EROFS; |
---|
2321 | | - goto out_fmt; |
---|
2322 | | - } |
---|
2323 | 2423 | if (!sb->s_op->quota_write || !sb->s_op->quota_read || |
---|
2324 | 2424 | (type == PRJQUOTA && sb->dq_op->get_projid == NULL)) { |
---|
2325 | 2425 | error = -EINVAL; |
---|
.. | .. |
---|
2351 | 2451 | invalidate_bdev(sb->s_bdev); |
---|
2352 | 2452 | } |
---|
2353 | 2453 | |
---|
2354 | | - if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) { |
---|
2355 | | - /* We don't want quota and atime on quota files (deadlocks |
---|
2356 | | - * possible) Also nobody should write to the file - we use |
---|
2357 | | - * special IO operations which ignore the immutable bit. */ |
---|
2358 | | - inode_lock(inode); |
---|
2359 | | - inode->i_flags |= S_NOQUOTA; |
---|
2360 | | - inode_unlock(inode); |
---|
2361 | | - /* |
---|
2362 | | - * When S_NOQUOTA is set, remove dquot references as no more |
---|
2363 | | - * references can be added |
---|
2364 | | - */ |
---|
2365 | | - __dquot_drop(inode); |
---|
2366 | | - } |
---|
2367 | | - |
---|
2368 | | - error = -EIO; |
---|
2369 | | - dqopt->files[type] = igrab(inode); |
---|
2370 | | - if (!dqopt->files[type]) |
---|
2371 | | - goto out_file_flags; |
---|
2372 | 2454 | error = -EINVAL; |
---|
2373 | 2455 | if (!fmt->qf_ops->check_quota_file(sb, type)) |
---|
2374 | | - goto out_file_init; |
---|
| 2456 | + goto out_fmt; |
---|
2375 | 2457 | |
---|
2376 | 2458 | dqopt->ops[type] = fmt->qf_ops; |
---|
2377 | 2459 | dqopt->info[type].dqi_format = fmt; |
---|
.. | .. |
---|
2379 | 2461 | INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list); |
---|
2380 | 2462 | error = dqopt->ops[type]->read_file_info(sb, type); |
---|
2381 | 2463 | if (error < 0) |
---|
2382 | | - goto out_file_init; |
---|
| 2464 | + goto out_fmt; |
---|
2383 | 2465 | if (dqopt->flags & DQUOT_QUOTA_SYS_FILE) { |
---|
2384 | 2466 | spin_lock(&dq_data_lock); |
---|
2385 | 2467 | dqopt->info[type].dqi_flags |= DQF_SYS_FILE; |
---|
.. | .. |
---|
2391 | 2473 | |
---|
2392 | 2474 | error = add_dquot_ref(sb, type); |
---|
2393 | 2475 | if (error) |
---|
2394 | | - dquot_disable(sb, type, flags); |
---|
| 2476 | + dquot_disable(sb, type, |
---|
| 2477 | + DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
---|
2395 | 2478 | |
---|
2396 | 2479 | return error; |
---|
2397 | | -out_file_init: |
---|
2398 | | - dqopt->files[type] = NULL; |
---|
2399 | | - iput(inode); |
---|
2400 | | -out_file_flags: |
---|
2401 | | - inode_lock(inode); |
---|
2402 | | - inode->i_flags &= ~S_NOQUOTA; |
---|
2403 | | - inode_unlock(inode); |
---|
2404 | 2480 | out_fmt: |
---|
2405 | 2481 | put_quota_format(fmt); |
---|
2406 | 2482 | |
---|
2407 | | - return error; |
---|
| 2483 | + return error; |
---|
2408 | 2484 | } |
---|
| 2485 | +EXPORT_SYMBOL(dquot_load_quota_sb); |
---|
| 2486 | + |
---|
| 2487 | +/* |
---|
| 2488 | + * More powerful function for turning on quotas on given quota inode allowing |
---|
| 2489 | + * setting of individual quota flags |
---|
| 2490 | + */ |
---|
| 2491 | +int dquot_load_quota_inode(struct inode *inode, int type, int format_id, |
---|
| 2492 | + unsigned int flags) |
---|
| 2493 | +{ |
---|
| 2494 | + int err; |
---|
| 2495 | + |
---|
| 2496 | + err = vfs_setup_quota_inode(inode, type); |
---|
| 2497 | + if (err < 0) |
---|
| 2498 | + return err; |
---|
| 2499 | + err = dquot_load_quota_sb(inode->i_sb, type, format_id, flags); |
---|
| 2500 | + if (err < 0) |
---|
| 2501 | + vfs_cleanup_quota_inode(inode->i_sb, type); |
---|
| 2502 | + return err; |
---|
| 2503 | +} |
---|
| 2504 | +EXPORT_SYMBOL(dquot_load_quota_inode); |
---|
2409 | 2505 | |
---|
2410 | 2506 | /* Reenable quotas on remount RW */ |
---|
2411 | 2507 | int dquot_resume(struct super_block *sb, int type) |
---|
2412 | 2508 | { |
---|
2413 | 2509 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2414 | | - struct inode *inode; |
---|
2415 | 2510 | int ret = 0, cnt; |
---|
2416 | 2511 | unsigned int flags; |
---|
2417 | 2512 | |
---|
.. | .. |
---|
2425 | 2520 | if (!sb_has_quota_suspended(sb, cnt)) |
---|
2426 | 2521 | continue; |
---|
2427 | 2522 | |
---|
2428 | | - inode = dqopt->files[cnt]; |
---|
2429 | | - dqopt->files[cnt] = NULL; |
---|
2430 | 2523 | spin_lock(&dq_state_lock); |
---|
2431 | 2524 | flags = dqopt->flags & dquot_state_flag(DQUOT_USAGE_ENABLED | |
---|
2432 | 2525 | DQUOT_LIMITS_ENABLED, |
---|
.. | .. |
---|
2435 | 2528 | spin_unlock(&dq_state_lock); |
---|
2436 | 2529 | |
---|
2437 | 2530 | flags = dquot_generic_flag(flags, cnt); |
---|
2438 | | - ret = vfs_load_quota_inode(inode, cnt, |
---|
2439 | | - dqopt->info[cnt].dqi_fmt_id, flags); |
---|
2440 | | - iput(inode); |
---|
| 2531 | + ret = dquot_load_quota_sb(sb, cnt, dqopt->info[cnt].dqi_fmt_id, |
---|
| 2532 | + flags); |
---|
| 2533 | + if (ret < 0) |
---|
| 2534 | + vfs_cleanup_quota_inode(sb, cnt); |
---|
2441 | 2535 | } |
---|
2442 | 2536 | |
---|
2443 | 2537 | return ret; |
---|
.. | .. |
---|
2454 | 2548 | if (path->dentry->d_sb != sb) |
---|
2455 | 2549 | error = -EXDEV; |
---|
2456 | 2550 | else |
---|
2457 | | - error = vfs_load_quota_inode(d_inode(path->dentry), type, |
---|
| 2551 | + error = dquot_load_quota_inode(d_inode(path->dentry), type, |
---|
2458 | 2552 | format_id, DQUOT_USAGE_ENABLED | |
---|
2459 | 2553 | DQUOT_LIMITS_ENABLED); |
---|
2460 | 2554 | return error; |
---|
2461 | 2555 | } |
---|
2462 | 2556 | EXPORT_SYMBOL(dquot_quota_on); |
---|
2463 | | - |
---|
2464 | | -/* |
---|
2465 | | - * More powerful function for turning on quotas allowing setting |
---|
2466 | | - * of individual quota flags |
---|
2467 | | - */ |
---|
2468 | | -int dquot_enable(struct inode *inode, int type, int format_id, |
---|
2469 | | - unsigned int flags) |
---|
2470 | | -{ |
---|
2471 | | - struct super_block *sb = inode->i_sb; |
---|
2472 | | - |
---|
2473 | | - /* Just unsuspend quotas? */ |
---|
2474 | | - BUG_ON(flags & DQUOT_SUSPENDED); |
---|
2475 | | - /* s_umount should be held in exclusive mode */ |
---|
2476 | | - if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount))) |
---|
2477 | | - up_read(&sb->s_umount); |
---|
2478 | | - |
---|
2479 | | - if (!flags) |
---|
2480 | | - return 0; |
---|
2481 | | - /* Just updating flags needed? */ |
---|
2482 | | - if (sb_has_quota_loaded(sb, type)) { |
---|
2483 | | - if (flags & DQUOT_USAGE_ENABLED && |
---|
2484 | | - sb_has_quota_usage_enabled(sb, type)) |
---|
2485 | | - return -EBUSY; |
---|
2486 | | - if (flags & DQUOT_LIMITS_ENABLED && |
---|
2487 | | - sb_has_quota_limits_enabled(sb, type)) |
---|
2488 | | - return -EBUSY; |
---|
2489 | | - spin_lock(&dq_state_lock); |
---|
2490 | | - sb_dqopt(sb)->flags |= dquot_state_flag(flags, type); |
---|
2491 | | - spin_unlock(&dq_state_lock); |
---|
2492 | | - return 0; |
---|
2493 | | - } |
---|
2494 | | - |
---|
2495 | | - return vfs_load_quota_inode(inode, type, format_id, flags); |
---|
2496 | | -} |
---|
2497 | | -EXPORT_SYMBOL(dquot_enable); |
---|
2498 | 2557 | |
---|
2499 | 2558 | /* |
---|
2500 | 2559 | * This function is used when filesystem needs to initialize quotas |
---|
.. | .. |
---|
2506 | 2565 | struct dentry *dentry; |
---|
2507 | 2566 | int error; |
---|
2508 | 2567 | |
---|
2509 | | - dentry = lookup_one_len_unlocked(qf_name, sb->s_root, strlen(qf_name)); |
---|
| 2568 | + dentry = lookup_positive_unlocked(qf_name, sb->s_root, strlen(qf_name)); |
---|
2510 | 2569 | if (IS_ERR(dentry)) |
---|
2511 | 2570 | return PTR_ERR(dentry); |
---|
2512 | 2571 | |
---|
2513 | | - if (d_really_is_negative(dentry)) { |
---|
2514 | | - error = -ENOENT; |
---|
2515 | | - goto out; |
---|
2516 | | - } |
---|
2517 | | - |
---|
2518 | 2572 | error = security_quota_on(dentry); |
---|
2519 | 2573 | if (!error) |
---|
2520 | | - error = vfs_load_quota_inode(d_inode(dentry), type, format_id, |
---|
| 2574 | + error = dquot_load_quota_inode(d_inode(dentry), type, format_id, |
---|
2521 | 2575 | DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
---|
2522 | 2576 | |
---|
2523 | | -out: |
---|
2524 | 2577 | dput(dentry); |
---|
2525 | 2578 | return error; |
---|
2526 | 2579 | } |
---|
.. | .. |
---|
2542 | 2595 | if (!(flags & qtype_enforce_flag(type))) |
---|
2543 | 2596 | continue; |
---|
2544 | 2597 | /* Can't enforce without accounting */ |
---|
2545 | | - if (!sb_has_quota_usage_enabled(sb, type)) |
---|
2546 | | - return -EINVAL; |
---|
2547 | | - ret = dquot_enable(dqopt->files[type], type, |
---|
2548 | | - dqopt->info[type].dqi_fmt_id, |
---|
2549 | | - DQUOT_LIMITS_ENABLED); |
---|
2550 | | - if (ret < 0) |
---|
| 2598 | + if (!sb_has_quota_usage_enabled(sb, type)) { |
---|
| 2599 | + ret = -EINVAL; |
---|
2551 | 2600 | goto out_err; |
---|
| 2601 | + } |
---|
| 2602 | + if (sb_has_quota_limits_enabled(sb, type)) { |
---|
| 2603 | + ret = -EBUSY; |
---|
| 2604 | + goto out_err; |
---|
| 2605 | + } |
---|
| 2606 | + spin_lock(&dq_state_lock); |
---|
| 2607 | + dqopt->flags |= dquot_state_flag(DQUOT_LIMITS_ENABLED, type); |
---|
| 2608 | + spin_unlock(&dq_state_lock); |
---|
2552 | 2609 | } |
---|
2553 | 2610 | return 0; |
---|
2554 | 2611 | out_err: |
---|
.. | .. |
---|
2598 | 2655 | out_err: |
---|
2599 | 2656 | /* Backout enforcement disabling we already did */ |
---|
2600 | 2657 | for (type--; type >= 0; type--) { |
---|
2601 | | - if (flags & qtype_enforce_flag(type)) |
---|
2602 | | - dquot_enable(dqopt->files[type], type, |
---|
2603 | | - dqopt->info[type].dqi_fmt_id, |
---|
2604 | | - DQUOT_LIMITS_ENABLED); |
---|
| 2658 | + if (flags & qtype_enforce_flag(type)) { |
---|
| 2659 | + spin_lock(&dq_state_lock); |
---|
| 2660 | + dqopt->flags |= |
---|
| 2661 | + dquot_state_flag(DQUOT_LIMITS_ENABLED, type); |
---|
| 2662 | + spin_unlock(&dq_state_lock); |
---|
| 2663 | + } |
---|
2605 | 2664 | } |
---|
2606 | 2665 | return ret; |
---|
2607 | 2666 | } |
---|
.. | .. |
---|
2730 | 2789 | |
---|
2731 | 2790 | if (check_blim) { |
---|
2732 | 2791 | if (!dm->dqb_bsoftlimit || |
---|
2733 | | - dm->dqb_curspace + dm->dqb_rsvspace < dm->dqb_bsoftlimit) { |
---|
| 2792 | + dm->dqb_curspace + dm->dqb_rsvspace <= dm->dqb_bsoftlimit) { |
---|
2734 | 2793 | dm->dqb_btime = 0; |
---|
2735 | 2794 | clear_bit(DQ_BLKS_B, &dquot->dq_flags); |
---|
2736 | 2795 | } else if (!(di->d_fieldmask & QC_SPC_TIMER)) |
---|
.. | .. |
---|
2739 | 2798 | } |
---|
2740 | 2799 | if (check_ilim) { |
---|
2741 | 2800 | if (!dm->dqb_isoftlimit || |
---|
2742 | | - dm->dqb_curinodes < dm->dqb_isoftlimit) { |
---|
| 2801 | + dm->dqb_curinodes <= dm->dqb_isoftlimit) { |
---|
2743 | 2802 | dm->dqb_itime = 0; |
---|
2744 | 2803 | clear_bit(DQ_INODES_B, &dquot->dq_flags); |
---|
2745 | 2804 | } else if (!(di->d_fieldmask & QC_INO_TIMER)) |
---|
.. | .. |
---|
2782 | 2841 | struct qc_type_state *tstate; |
---|
2783 | 2842 | struct quota_info *dqopt = sb_dqopt(sb); |
---|
2784 | 2843 | int type; |
---|
2785 | | - |
---|
| 2844 | + |
---|
2786 | 2845 | memset(state, 0, sizeof(*state)); |
---|
2787 | 2846 | for (type = 0; type < MAXQUOTAS; type++) { |
---|
2788 | 2847 | if (!sb_has_quota_active(sb, type)) |
---|
.. | .. |
---|
2799 | 2858 | tstate->flags |= QCI_LIMITS_ENFORCED; |
---|
2800 | 2859 | tstate->spc_timelimit = mi->dqi_bgrace; |
---|
2801 | 2860 | tstate->ino_timelimit = mi->dqi_igrace; |
---|
2802 | | - tstate->ino = dqopt->files[type]->i_ino; |
---|
2803 | | - tstate->blocks = dqopt->files[type]->i_blocks; |
---|
| 2861 | + if (dqopt->files[type]) { |
---|
| 2862 | + tstate->ino = dqopt->files[type]->i_ino; |
---|
| 2863 | + tstate->blocks = dqopt->files[type]->i_blocks; |
---|
| 2864 | + } |
---|
2804 | 2865 | tstate->nextents = 1; /* We don't know... */ |
---|
2805 | 2866 | spin_unlock(&dq_data_lock); |
---|
2806 | 2867 | } |
---|
.. | .. |
---|
2857 | 2918 | EXPORT_SYMBOL(dquot_quotactl_sysfile_ops); |
---|
2858 | 2919 | |
---|
2859 | 2920 | static int do_proc_dqstats(struct ctl_table *table, int write, |
---|
2860 | | - void __user *buffer, size_t *lenp, loff_t *ppos) |
---|
| 2921 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
2861 | 2922 | { |
---|
2862 | 2923 | unsigned int type = (unsigned long *)table->data - dqstats.stat; |
---|
2863 | 2924 | s64 value = percpu_counter_sum(&dqstats.counter[type]); |
---|
.. | .. |
---|
2987 | 3048 | |
---|
2988 | 3049 | /* Find power-of-two hlist_heads which can fit into allocation */ |
---|
2989 | 3050 | nr_hash = (1UL << order) * PAGE_SIZE / sizeof(struct hlist_head); |
---|
2990 | | - dq_hash_bits = 0; |
---|
2991 | | - do { |
---|
2992 | | - dq_hash_bits++; |
---|
2993 | | - } while (nr_hash >> dq_hash_bits); |
---|
2994 | | - dq_hash_bits--; |
---|
| 3051 | + dq_hash_bits = ilog2(nr_hash); |
---|
2995 | 3052 | |
---|
2996 | 3053 | nr_hash = 1UL << dq_hash_bits; |
---|
2997 | 3054 | dq_hash_mask = nr_hash - 1; |
---|