Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'quota_scaling' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs

Pull quota scaling updates from Jan Kara:
"This contains changes to make the quota subsystem more scalable.

Reportedly it improves number of files created per second on ext4
filesystem on fast storage by about a factor of 2x"

* 'quota_scaling' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: (28 commits)
quota: Add lock annotations to struct members
quota: Reduce contention on dq_data_lock
fs: Provide __inode_get_bytes()
quota: Inline dquot_[re]claim_reserved_space() into callsite
quota: Inline inode_{incr,decr}_space() into callsites
quota: Inline functions into their callsites
ext4: Disable dirty list tracking of dquots when journalling quotas
quota: Allow disabling tracking of dirty dquots in a list
quota: Remove dq_wait_unused from dquot
quota: Move locking into clear_dquot_dirty()
quota: Do not dirty bad dquots
quota: Fix possible corruption of dqi_flags
quota: Propagate ->quota_read errors from v2_read_file_info()
quota: Fix error codes in v2_read_file_info()
quota: Push dqio_sem down to ->read_file_info()
quota: Push dqio_sem down to ->write_file_info()
quota: Push dqio_sem down to ->get_next_id()
quota: Push dqio_sem down to ->release_dqblk()
quota: Remove locking for writing to the old quota format
quota: Do not acquire dqio_sem for dquot overwrites in v2 format
...

+413 -330
+14 -12
fs/ext4/super.c
··· 5215 5215 dquot = dqget(sb, qid); 5216 5216 if (IS_ERR(dquot)) 5217 5217 return PTR_ERR(dquot); 5218 - spin_lock(&dq_data_lock); 5218 + spin_lock(&dquot->dq_dqb_lock); 5219 5219 5220 5220 limit = (dquot->dq_dqb.dqb_bsoftlimit ? 5221 5221 dquot->dq_dqb.dqb_bsoftlimit : ··· 5238 5238 (buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0; 5239 5239 } 5240 5240 5241 - spin_unlock(&dq_data_lock); 5241 + spin_unlock(&dquot->dq_dqb_lock); 5242 5242 dqput(dquot); 5243 5243 return 0; 5244 5244 } ··· 5284 5284 return 0; 5285 5285 } 5286 5286 5287 - /* Helper function for writing quotas on sync - we need to start transaction 5288 - * before quota file is locked for write. Otherwise the are possible deadlocks: 5289 - * Process 1 Process 2 5290 - * ext4_create() quota_sync() 5291 - * jbd2_journal_start() write_dquot() 5292 - * dquot_initialize() down(dqio_mutex) 5293 - * down(dqio_mutex) jbd2_journal_start() 5294 - * 5295 - */ 5296 5287 5297 5288 #ifdef CONFIG_QUOTA 5298 5289 5290 + /* 5291 + * Helper functions so that transaction is started before we acquire dqio_sem 5292 + * to keep correct lock ordering of transaction > dqio_sem 5293 + */ 5299 5294 static inline struct inode *dquot_to_inode(struct dquot *dquot) 5300 5295 { 5301 5296 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type]; ··· 5425 5430 ext4_msg(sb, KERN_WARNING, 5426 5431 "Quota file not on filesystem root. " 5427 5432 "Journaled quota will not work"); 5433 + sb_dqopt(sb)->flags |= DQUOT_NOLIST_DIRTY; 5434 + } else { 5435 + /* 5436 + * Clear the flag just in case mount options changed since 5437 + * last time. 5438 + */ 5439 + sb_dqopt(sb)->flags &= ~DQUOT_NOLIST_DIRTY; 5428 5440 } 5429 5441 5430 5442 /* ··· 5528 5526 test_opt(sb, PRJQUOTA), 5529 5527 }; 5530 5528 5531 - sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE; 5529 + sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NOLIST_DIRTY; 5532 5530 for (type = 0; type < EXT4_MAXQUOTAS; type++) { 5533 5531 if (qf_inums[type]) { 5534 5532 err = ext4_quota_enable(sb, type, QFMT_VFS_V1,
+20 -16
fs/ocfs2/quota_global.c
··· 33 33 * Locking of quotas with OCFS2 is rather complex. Here are rules that 34 34 * should be obeyed by all the functions: 35 35 * - any write of quota structure (either to local or global file) is protected 36 - * by dqio_mutex or dquot->dq_lock. 36 + * by dqio_sem or dquot->dq_lock. 37 37 * - any modification of global quota file holds inode cluster lock, i_mutex, 38 38 * and ip_alloc_sem of the global quota file (achieved by 39 39 * ocfs2_lock_global_qf). It also has to hold qinfo_lock. ··· 42 42 * 43 43 * A rough sketch of locking dependencies (lf = local file, gf = global file): 44 44 * Normal filesystem operation: 45 - * start_trans -> dqio_mutex -> write to lf 45 + * start_trans -> dqio_sem -> write to lf 46 46 * Syncing of local and global file: 47 - * ocfs2_lock_global_qf -> start_trans -> dqio_mutex -> qinfo_lock -> 47 + * ocfs2_lock_global_qf -> start_trans -> dqio_sem -> qinfo_lock -> 48 48 * write to gf 49 49 * -> write to lf 50 50 * Acquire dquot for the first time: ··· 60 60 * Recovery: 61 61 * inode cluster lock of recovered lf 62 62 * -> read bitmaps -> ip_alloc_sem of lf 63 - * -> ocfs2_lock_global_qf -> start_trans -> dqio_mutex -> qinfo_lock -> 63 + * -> ocfs2_lock_global_qf -> start_trans -> dqio_sem -> qinfo_lock -> 64 64 * write to gf 65 65 */ 66 66 ··· 443 443 int ocfs2_global_write_info(struct super_block *sb, int type) 444 444 { 445 445 int err; 446 - struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv; 446 + struct quota_info *dqopt = sb_dqopt(sb); 447 + struct ocfs2_mem_dqinfo *info = dqopt->info[type].dqi_priv; 447 448 449 + down_write(&dqopt->dqio_sem); 448 450 err = ocfs2_qinfo_lock(info, 1); 449 451 if (err < 0) 450 - return err; 452 + goto out_sem; 451 453 err = __ocfs2_global_write_info(sb, type); 452 454 ocfs2_qinfo_unlock(info, 1); 455 + out_sem: 456 + up_write(&dqopt->dqio_sem); 453 457 return err; 454 458 } 455 459 ··· 504 500 /* Update space and inode usage. Get also other information from 505 501 * global quota file so that we don't overwrite any changes there. 506 502 * We are */ 507 - spin_lock(&dq_data_lock); 503 + spin_lock(&dquot->dq_dqb_lock); 508 504 spacechange = dquot->dq_dqb.dqb_curspace - 509 505 OCFS2_DQUOT(dquot)->dq_origspace; 510 506 inodechange = dquot->dq_dqb.dqb_curinodes - ··· 560 556 __clear_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags); 561 557 OCFS2_DQUOT(dquot)->dq_origspace = dquot->dq_dqb.dqb_curspace; 562 558 OCFS2_DQUOT(dquot)->dq_originodes = dquot->dq_dqb.dqb_curinodes; 563 - spin_unlock(&dq_data_lock); 559 + spin_unlock(&dquot->dq_dqb_lock); 564 560 err = ocfs2_qinfo_lock(info, freeing); 565 561 if (err < 0) { 566 562 mlog(ML_ERROR, "Failed to lock quota info, losing quota write" ··· 615 611 mlog_errno(status); 616 612 goto out_ilock; 617 613 } 618 - mutex_lock(&sb_dqopt(sb)->dqio_mutex); 614 + down_write(&sb_dqopt(sb)->dqio_sem); 619 615 status = ocfs2_sync_dquot(dquot); 620 616 if (status < 0) 621 617 mlog_errno(status); ··· 623 619 status = ocfs2_local_write_dquot(dquot); 624 620 if (status < 0) 625 621 mlog_errno(status); 626 - mutex_unlock(&sb_dqopt(sb)->dqio_mutex); 622 + up_write(&sb_dqopt(sb)->dqio_sem); 627 623 ocfs2_commit_trans(osb, handle); 628 624 out_ilock: 629 625 ocfs2_unlock_global_qf(oinfo, 1); ··· 670 666 mlog_errno(status); 671 667 goto out; 672 668 } 673 - mutex_lock(&sb_dqopt(dquot->dq_sb)->dqio_mutex); 669 + down_write(&sb_dqopt(dquot->dq_sb)->dqio_sem); 674 670 status = ocfs2_local_write_dquot(dquot); 675 - mutex_unlock(&sb_dqopt(dquot->dq_sb)->dqio_mutex); 671 + up_write(&sb_dqopt(dquot->dq_sb)->dqio_sem); 676 672 ocfs2_commit_trans(osb, handle); 677 673 out: 678 674 return status; ··· 924 920 925 921 /* In case user set some limits, sync dquot immediately to global 926 922 * quota file so that information propagates quicker */ 927 - spin_lock(&dq_data_lock); 923 + spin_lock(&dquot->dq_dqb_lock); 928 924 if (dquot->dq_flags & mask) 929 925 sync = 1; 930 - spin_unlock(&dq_data_lock); 926 + spin_unlock(&dquot->dq_dqb_lock); 931 927 /* This is a slight hack but we can't afford getting global quota 932 928 * lock if we already have a transaction started. */ 933 929 if (!sync || journal_current_handle()) { ··· 943 939 mlog_errno(status); 944 940 goto out_ilock; 945 941 } 946 - mutex_lock(&sb_dqopt(sb)->dqio_mutex); 942 + down_write(&sb_dqopt(sb)->dqio_sem); 947 943 status = ocfs2_sync_dquot(dquot); 948 944 if (status < 0) { 949 945 mlog_errno(status); ··· 952 948 /* Now write updated local dquot structure */ 953 949 status = ocfs2_local_write_dquot(dquot); 954 950 out_dlock: 955 - mutex_unlock(&sb_dqopt(sb)->dqio_mutex); 951 + up_write(&sb_dqopt(sb)->dqio_sem); 956 952 ocfs2_commit_trans(osb, handle); 957 953 out_ilock: 958 954 ocfs2_unlock_global_qf(oinfo, 1);
+6 -11
fs/ocfs2/quota_local.c
··· 520 520 mlog_errno(status); 521 521 goto out_drop_lock; 522 522 } 523 - mutex_lock(&sb_dqopt(sb)->dqio_mutex); 524 - spin_lock(&dq_data_lock); 523 + down_write(&sb_dqopt(sb)->dqio_sem); 524 + spin_lock(&dquot->dq_dqb_lock); 525 525 /* Add usage from quota entry into quota changes 526 526 * of our node. Auxiliary variables are important 527 527 * due to signedness */ ··· 529 529 inodechange = le64_to_cpu(dqblk->dqb_inodemod); 530 530 dquot->dq_dqb.dqb_curspace += spacechange; 531 531 dquot->dq_dqb.dqb_curinodes += inodechange; 532 - spin_unlock(&dq_data_lock); 532 + spin_unlock(&dquot->dq_dqb_lock); 533 533 /* We want to drop reference held by the crashed 534 534 * node. Since we have our own reference we know 535 535 * global structure actually won't be freed. */ ··· 553 553 unlock_buffer(qbh); 554 554 ocfs2_journal_dirty(handle, qbh); 555 555 out_commit: 556 - mutex_unlock(&sb_dqopt(sb)->dqio_mutex); 556 + up_write(&sb_dqopt(sb)->dqio_sem); 557 557 ocfs2_commit_trans(OCFS2_SB(sb), handle); 558 558 out_drop_lock: 559 559 ocfs2_unlock_global_qf(oinfo, 1); ··· 691 691 struct ocfs2_quota_recovery *rec; 692 692 int locked = 0; 693 693 694 - /* We don't need the lock and we have to acquire quota file locks 695 - * which will later depend on this lock */ 696 - mutex_unlock(&sb_dqopt(sb)->dqio_mutex); 697 694 info->dqi_max_spc_limit = 0x7fffffffffffffffLL; 698 695 info->dqi_max_ino_limit = 0x7fffffffffffffffLL; 699 696 oinfo = kmalloc(sizeof(struct ocfs2_mem_dqinfo), GFP_NOFS); ··· 769 772 goto out_err; 770 773 } 771 774 772 - mutex_lock(&sb_dqopt(sb)->dqio_mutex); 773 775 return 0; 774 776 out_err: 775 777 if (oinfo) { ··· 782 786 kfree(oinfo); 783 787 } 784 788 brelse(bh); 785 - mutex_lock(&sb_dqopt(sb)->dqio_mutex); 786 789 return -1; 787 790 } 788 791 ··· 877 882 878 883 dqblk->dqb_id = cpu_to_le64(from_kqid(&init_user_ns, 879 884 od->dq_dquot.dq_id)); 880 - spin_lock(&dq_data_lock); 885 + spin_lock(&od->dq_dquot.dq_dqb_lock); 881 886 dqblk->dqb_spacemod = cpu_to_le64(od->dq_dquot.dq_dqb.dqb_curspace - 882 887 od->dq_origspace); 883 888 dqblk->dqb_inodemod = cpu_to_le64(od->dq_dquot.dq_dqb.dqb_curinodes - 884 889 od->dq_originodes); 885 - spin_unlock(&dq_data_lock); 890 + spin_unlock(&od->dq_dquot.dq_dqb_lock); 886 891 trace_olq_set_dquot( 887 892 (unsigned long long)le64_to_cpu(dqblk->dqb_spacemod), 888 893 (unsigned long long)le64_to_cpu(dqblk->dqb_inodemod),
+259 -245
fs/quota/dquot.c
··· 82 82 #include <linux/uaccess.h> 83 83 84 84 /* 85 - * There are three quota SMP locks. dq_list_lock protects all lists with quotas 86 - * and quota formats. 87 - * dq_data_lock protects data from dq_dqb and also mem_dqinfo structures and 88 - * also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes. 89 - * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly 90 - * in inode_add_bytes() and inode_sub_bytes(). dq_state_lock protects 91 - * modifications of quota state (on quotaon and quotaoff) and readers who care 92 - * about latest values take it as well. 85 + * There are five quota SMP locks: 86 + * * dq_list_lock protects all lists with quotas and quota formats. 87 + * * dquot->dq_dqb_lock protects data from dq_dqb 88 + * * inode->i_lock protects inode->i_blocks, i_bytes and also guards 89 + * consistency of dquot->dq_dqb with inode->i_blocks, i_bytes so that 90 + * dquot_transfer() can stabilize amount it transfers 91 + * * dq_data_lock protects mem_dqinfo structures and modifications of dquot 92 + * pointers in the inode 93 + * * dq_state_lock protects modifications of quota state (on quotaon and 94 + * quotaoff) and readers who care about latest values take it as well. 93 95 * 94 - * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock, 96 + * The spinlock ordering is hence: 97 + * dq_data_lock > dq_list_lock > i_lock > dquot->dq_dqb_lock, 95 98 * dq_list_lock > dq_state_lock 96 99 * 97 100 * Note that some things (eg. sb pointer, type, id) doesn't change during ··· 113 110 * sure they cannot race with quotaon which first sets S_NOQUOTA flag and 114 111 * then drops all pointers to dquots from an inode. 115 112 * 116 - * Each dquot has its dq_lock mutex. Locked dquots might not be referenced 117 - * from inodes (dquot_alloc_space() and such don't check the dq_lock). 118 - * Currently dquot is locked only when it is being read to memory (or space for 119 - * it is being allocated) on the first dqget() and when it is being released on 120 - * the last dqput(). The allocation and release oparations are serialized by 121 - * the dq_lock and by checking the use count in dquot_release(). Write 122 - * operations on dquots don't hold dq_lock as they copy data under dq_data_lock 123 - * spinlock to internal buffers before writing. 113 + * Each dquot has its dq_lock mutex. Dquot is locked when it is being read to 114 + * memory (or space for it is being allocated) on the first dqget(), when it is 115 + * being written out, and when it is being released on the last dqput(). The 116 + * allocation and release operations are serialized by the dq_lock and by 117 + * checking the use count in dquot_release(). 124 118 * 125 119 * Lock ordering (including related VFS locks) is the following: 126 - * s_umount > i_mutex > journal_lock > dquot->dq_lock > dqio_mutex 120 + * s_umount > i_mutex > journal_lock > dquot->dq_lock > dqio_sem 127 121 */ 128 122 129 123 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_list_lock); ··· 128 128 __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_data_lock); 129 129 EXPORT_SYMBOL(dq_data_lock); 130 130 DEFINE_STATIC_SRCU(dquot_srcu); 131 + 132 + static DECLARE_WAIT_QUEUE_HEAD(dquot_ref_wq); 131 133 132 134 void __quota_error(struct super_block *sb, const char *func, 133 135 const char *fmt, ...) ··· 249 247 EXPORT_SYMBOL(dqstats); 250 248 251 249 static qsize_t inode_get_rsv_space(struct inode *inode); 250 + static qsize_t __inode_get_rsv_space(struct inode *inode); 252 251 static int __dquot_initialize(struct inode *inode, int type); 253 252 254 253 static inline unsigned int ··· 345 342 { 346 343 int ret = 1; 347 344 345 + if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) 346 + return 0; 347 + 348 + if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NOLIST_DIRTY) 349 + return test_and_set_bit(DQ_MOD_B, &dquot->dq_flags); 350 + 348 351 /* If quota is dirty already, we don't have to acquire dq_list_lock */ 349 352 if (test_bit(DQ_MOD_B, &dquot->dq_flags)) 350 353 return 1; ··· 390 381 dqput(dquot[cnt]); 391 382 } 392 383 393 - /* This function needs dq_list_lock */ 394 384 static inline int clear_dquot_dirty(struct dquot *dquot) 395 385 { 396 - if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags)) 386 + if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NOLIST_DIRTY) 387 + return test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags); 388 + 389 + spin_lock(&dq_list_lock); 390 + if (!test_and_clear_bit(DQ_MOD_B, &dquot->dq_flags)) { 391 + spin_unlock(&dq_list_lock); 397 392 return 0; 393 + } 398 394 list_del_init(&dquot->dq_dirty); 395 + spin_unlock(&dq_list_lock); 399 396 return 1; 400 397 } 401 398 402 399 void mark_info_dirty(struct super_block *sb, int type) 403 400 { 404 - set_bit(DQF_INFO_DIRTY_B, &sb_dqopt(sb)->info[type].dqi_flags); 401 + spin_lock(&dq_data_lock); 402 + sb_dqopt(sb)->info[type].dqi_flags |= DQF_INFO_DIRTY; 403 + spin_unlock(&dq_data_lock); 405 404 } 406 405 EXPORT_SYMBOL(mark_info_dirty); 407 406 ··· 423 406 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); 424 407 425 408 mutex_lock(&dquot->dq_lock); 426 - mutex_lock(&dqopt->dqio_mutex); 427 409 if (!test_bit(DQ_READ_B, &dquot->dq_flags)) 428 410 ret = dqopt->ops[dquot->dq_id.type]->read_dqblk(dquot); 429 411 if (ret < 0) ··· 452 436 smp_mb__before_atomic(); 453 437 set_bit(DQ_ACTIVE_B, &dquot->dq_flags); 454 438 out_iolock: 455 - mutex_unlock(&dqopt->dqio_mutex); 456 439 mutex_unlock(&dquot->dq_lock); 457 440 return ret; 458 441 } ··· 465 450 int ret = 0; 466 451 struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); 467 452 468 - mutex_lock(&dqopt->dqio_mutex); 469 - spin_lock(&dq_list_lock); 470 - if (!clear_dquot_dirty(dquot)) { 471 - spin_unlock(&dq_list_lock); 472 - goto out_sem; 473 - } 474 - spin_unlock(&dq_list_lock); 453 + mutex_lock(&dquot->dq_lock); 454 + if (!clear_dquot_dirty(dquot)) 455 + goto out_lock; 475 456 /* Inactive dquot can be only if there was error during read/init 476 457 * => we have better not writing it */ 477 458 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) 478 459 ret = dqopt->ops[dquot->dq_id.type]->commit_dqblk(dquot); 479 460 else 480 461 ret = -EIO; 481 - out_sem: 482 - mutex_unlock(&dqopt->dqio_mutex); 462 + out_lock: 463 + mutex_unlock(&dquot->dq_lock); 483 464 return ret; 484 465 } 485 466 EXPORT_SYMBOL(dquot_commit); ··· 492 481 /* Check whether we are not racing with some other dqget() */ 493 482 if (atomic_read(&dquot->dq_count) > 1) 494 483 goto out_dqlock; 495 - mutex_lock(&dqopt->dqio_mutex); 496 484 if (dqopt->ops[dquot->dq_id.type]->release_dqblk) { 497 485 ret = dqopt->ops[dquot->dq_id.type]->release_dqblk(dquot); 498 486 /* Write the info */ ··· 503 493 ret = ret2; 504 494 } 505 495 clear_bit(DQ_ACTIVE_B, &dquot->dq_flags); 506 - mutex_unlock(&dqopt->dqio_mutex); 507 496 out_dqlock: 508 497 mutex_unlock(&dquot->dq_lock); 509 498 return ret; ··· 539 530 continue; 540 531 /* Wait for dquot users */ 541 532 if (atomic_read(&dquot->dq_count)) { 542 - DEFINE_WAIT(wait); 543 - 544 533 dqgrab(dquot); 545 - prepare_to_wait(&dquot->dq_wait_unused, &wait, 546 - TASK_UNINTERRUPTIBLE); 547 534 spin_unlock(&dq_list_lock); 548 - /* Once dqput() wakes us up, we know it's time to free 535 + /* 536 + * Once dqput() wakes us up, we know it's time to free 549 537 * the dquot. 550 538 * IMPORTANT: we rely on the fact that there is always 551 539 * at most one process waiting for dquot to free. 552 540 * Otherwise dq_count would be > 1 and we would never 553 541 * wake up. 554 542 */ 555 - if (atomic_read(&dquot->dq_count) > 1) 556 - schedule(); 557 - finish_wait(&dquot->dq_wait_unused, &wait); 543 + wait_event(dquot_ref_wq, 544 + atomic_read(&dquot->dq_count) == 1); 558 545 dqput(dquot); 559 546 /* At this moment dquot() need not exist (it could be 560 547 * reclaimed by prune_dqcache(). Hence we must ··· 634 629 while (!list_empty(dirty)) { 635 630 dquot = list_first_entry(dirty, struct dquot, 636 631 dq_dirty); 637 - /* Dirty and inactive can be only bad dquot... */ 638 - if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { 639 - clear_dquot_dirty(dquot); 640 - continue; 641 - } 632 + 633 + WARN_ON(!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)); 634 + 642 635 /* Now we have active dquot from which someone is 643 636 * holding reference so we can safely just increase 644 637 * use count */ ··· 762 759 /* Releasing dquot during quotaoff phase? */ 763 760 if (!sb_has_quota_active(dquot->dq_sb, dquot->dq_id.type) && 764 761 atomic_read(&dquot->dq_count) == 1) 765 - wake_up(&dquot->dq_wait_unused); 762 + wake_up(&dquot_ref_wq); 766 763 spin_unlock(&dq_list_lock); 767 764 return; 768 765 } 769 766 /* Need to release dquot? */ 770 - if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && dquot_dirty(dquot)) { 767 + if (dquot_dirty(dquot)) { 771 768 spin_unlock(&dq_list_lock); 772 769 /* Commit dquot before releasing */ 773 770 ret = dquot->dq_sb->dq_op->write_dquot(dquot); ··· 779 776 * We clear dirty bit anyway, so that we avoid 780 777 * infinite loop here 781 778 */ 782 - spin_lock(&dq_list_lock); 783 779 clear_dquot_dirty(dquot); 784 - spin_unlock(&dq_list_lock); 785 780 } 786 781 goto we_slept; 787 782 } 788 - /* Clear flag in case dquot was inactive (something bad happened) */ 789 - clear_dquot_dirty(dquot); 790 783 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { 791 784 spin_unlock(&dq_list_lock); 792 785 dquot->dq_sb->dq_op->release_dquot(dquot); ··· 817 818 INIT_LIST_HEAD(&dquot->dq_inuse); 818 819 INIT_HLIST_NODE(&dquot->dq_hash); 819 820 INIT_LIST_HEAD(&dquot->dq_dirty); 820 - init_waitqueue_head(&dquot->dq_wait_unused); 821 821 dquot->dq_sb = sb; 822 822 dquot->dq_id = make_kqid_invalid(type); 823 823 atomic_set(&dquot->dq_count, 1); 824 + spin_lock_init(&dquot->dq_dqb_lock); 824 825 825 826 return dquot; 826 827 } ··· 1078 1079 } 1079 1080 } 1080 1081 1081 - static inline void dquot_incr_inodes(struct dquot *dquot, qsize_t number) 1082 - { 1083 - dquot->dq_dqb.dqb_curinodes += number; 1084 - } 1085 - 1086 - static inline void dquot_incr_space(struct dquot *dquot, qsize_t number) 1087 - { 1088 - dquot->dq_dqb.dqb_curspace += number; 1089 - } 1090 - 1091 - static inline void dquot_resv_space(struct dquot *dquot, qsize_t number) 1092 - { 1093 - dquot->dq_dqb.dqb_rsvspace += number; 1094 - } 1095 - 1096 - /* 1097 - * Claim reserved quota space 1098 - */ 1099 - static void dquot_claim_reserved_space(struct dquot *dquot, qsize_t number) 1100 - { 1101 - if (dquot->dq_dqb.dqb_rsvspace < number) { 1102 - WARN_ON_ONCE(1); 1103 - number = dquot->dq_dqb.dqb_rsvspace; 1104 - } 1105 - dquot->dq_dqb.dqb_curspace += number; 1106 - dquot->dq_dqb.dqb_rsvspace -= number; 1107 - } 1108 - 1109 - static void dquot_reclaim_reserved_space(struct dquot *dquot, qsize_t number) 1110 - { 1111 - if (WARN_ON_ONCE(dquot->dq_dqb.dqb_curspace < number)) 1112 - number = dquot->dq_dqb.dqb_curspace; 1113 - dquot->dq_dqb.dqb_rsvspace += number; 1114 - dquot->dq_dqb.dqb_curspace -= number; 1115 - } 1116 - 1117 1082 static inline 1118 1083 void dquot_free_reserved_space(struct dquot *dquot, qsize_t number) 1119 1084 { ··· 1241 1278 !(info->dqi_flags & DQF_ROOT_SQUASH)); 1242 1279 } 1243 1280 1244 - /* needs dq_data_lock */ 1245 - static int check_idq(struct dquot *dquot, qsize_t inodes, 1246 - struct dquot_warn *warn) 1281 + static int dquot_add_inodes(struct dquot *dquot, qsize_t inodes, 1282 + struct dquot_warn *warn) 1247 1283 { 1248 - qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes; 1284 + qsize_t newinodes; 1285 + int ret = 0; 1249 1286 1287 + spin_lock(&dquot->dq_dqb_lock); 1288 + newinodes = dquot->dq_dqb.dqb_curinodes + inodes; 1250 1289 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_id.type) || 1251 1290 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1252 - return 0; 1291 + goto add; 1253 1292 1254 1293 if (dquot->dq_dqb.dqb_ihardlimit && 1255 1294 newinodes > dquot->dq_dqb.dqb_ihardlimit && 1256 1295 !ignore_hardlimit(dquot)) { 1257 1296 prepare_warning(warn, dquot, QUOTA_NL_IHARDWARN); 1258 - return -EDQUOT; 1297 + ret = -EDQUOT; 1298 + goto out; 1259 1299 } 1260 1300 1261 1301 if (dquot->dq_dqb.dqb_isoftlimit && ··· 1267 1301 ktime_get_real_seconds() >= dquot->dq_dqb.dqb_itime && 1268 1302 !ignore_hardlimit(dquot)) { 1269 1303 prepare_warning(warn, dquot, QUOTA_NL_ISOFTLONGWARN); 1270 - return -EDQUOT; 1304 + ret = -EDQUOT; 1305 + goto out; 1271 1306 } 1272 1307 1273 1308 if (dquot->dq_dqb.dqb_isoftlimit && ··· 1278 1311 dquot->dq_dqb.dqb_itime = ktime_get_real_seconds() + 1279 1312 sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type].dqi_igrace; 1280 1313 } 1314 + add: 1315 + dquot->dq_dqb.dqb_curinodes = newinodes; 1281 1316 1282 - return 0; 1317 + out: 1318 + spin_unlock(&dquot->dq_dqb_lock); 1319 + return ret; 1283 1320 } 1284 1321 1285 - /* needs dq_data_lock */ 1286 - static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, 1287 - struct dquot_warn *warn) 1322 + static int dquot_add_space(struct dquot *dquot, qsize_t space, 1323 + qsize_t rsv_space, unsigned int flags, 1324 + struct dquot_warn *warn) 1288 1325 { 1289 1326 qsize_t tspace; 1290 1327 struct super_block *sb = dquot->dq_sb; 1328 + int ret = 0; 1291 1329 1330 + spin_lock(&dquot->dq_dqb_lock); 1292 1331 if (!sb_has_quota_limits_enabled(sb, dquot->dq_id.type) || 1293 1332 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1294 - return 0; 1333 + goto add; 1295 1334 1296 1335 tspace = dquot->dq_dqb.dqb_curspace + dquot->dq_dqb.dqb_rsvspace 1297 - + space; 1336 + + space + rsv_space; 1337 + 1338 + if (flags & DQUOT_SPACE_NOFAIL) 1339 + goto add; 1298 1340 1299 1341 if (dquot->dq_dqb.dqb_bhardlimit && 1300 1342 tspace > dquot->dq_dqb.dqb_bhardlimit && 1301 1343 !ignore_hardlimit(dquot)) { 1302 - if (!prealloc) 1344 + if (flags & DQUOT_SPACE_WARN) 1303 1345 prepare_warning(warn, dquot, QUOTA_NL_BHARDWARN); 1304 - return -EDQUOT; 1346 + ret = -EDQUOT; 1347 + goto out; 1305 1348 } 1306 1349 1307 1350 if (dquot->dq_dqb.dqb_bsoftlimit && ··· 1319 1342 dquot->dq_dqb.dqb_btime && 1320 1343 ktime_get_real_seconds() >= dquot->dq_dqb.dqb_btime && 1321 1344 !ignore_hardlimit(dquot)) { 1322 - if (!prealloc) 1345 + if (flags & DQUOT_SPACE_WARN) 1323 1346 prepare_warning(warn, dquot, QUOTA_NL_BSOFTLONGWARN); 1324 - return -EDQUOT; 1347 + ret = -EDQUOT; 1348 + goto out; 1325 1349 } 1326 1350 1327 1351 if (dquot->dq_dqb.dqb_bsoftlimit && 1328 1352 tspace > dquot->dq_dqb.dqb_bsoftlimit && 1329 1353 dquot->dq_dqb.dqb_btime == 0) { 1330 - if (!prealloc) { 1354 + if (flags & DQUOT_SPACE_WARN) { 1331 1355 prepare_warning(warn, dquot, QUOTA_NL_BSOFTWARN); 1332 1356 dquot->dq_dqb.dqb_btime = ktime_get_real_seconds() + 1333 1357 sb_dqopt(sb)->info[dquot->dq_id.type].dqi_bgrace; 1334 - } 1335 - else 1358 + } else { 1336 1359 /* 1337 1360 * We don't allow preallocation to exceed softlimit so exceeding will 1338 1361 * be always printed 1339 1362 */ 1340 - return -EDQUOT; 1363 + ret = -EDQUOT; 1364 + goto out; 1365 + } 1341 1366 } 1342 - 1343 - return 0; 1367 + add: 1368 + dquot->dq_dqb.dqb_rsvspace += rsv_space; 1369 + dquot->dq_dqb.dqb_curspace += space; 1370 + out: 1371 + spin_unlock(&dquot->dq_dqb_lock); 1372 + return ret; 1344 1373 } 1345 1374 1346 1375 static int info_idq_free(struct dquot *dquot, qsize_t inodes) ··· 1485 1502 * did a write before quota was turned on 1486 1503 */ 1487 1504 rsv = inode_get_rsv_space(inode); 1488 - if (unlikely(rsv)) 1489 - dquot_resv_space(dquots[cnt], rsv); 1505 + if (unlikely(rsv)) { 1506 + spin_lock(&inode->i_lock); 1507 + /* Get reservation again under proper lock */ 1508 + rsv = __inode_get_rsv_space(inode); 1509 + spin_lock(&dquots[cnt]->dq_dqb_lock); 1510 + dquots[cnt]->dq_dqb.dqb_rsvspace += rsv; 1511 + spin_unlock(&dquots[cnt]->dq_dqb_lock); 1512 + spin_unlock(&inode->i_lock); 1513 + } 1490 1514 } 1491 1515 } 1492 1516 out_lock: ··· 1588 1598 return inode->i_sb->dq_op->get_reserved_space(inode); 1589 1599 } 1590 1600 1591 - void inode_add_rsv_space(struct inode *inode, qsize_t number) 1601 + static qsize_t __inode_get_rsv_space(struct inode *inode) 1592 1602 { 1593 - spin_lock(&inode->i_lock); 1594 - *inode_reserved_space(inode) += number; 1595 - spin_unlock(&inode->i_lock); 1603 + if (!inode->i_sb->dq_op->get_reserved_space) 1604 + return 0; 1605 + return *inode_reserved_space(inode); 1596 1606 } 1597 - EXPORT_SYMBOL(inode_add_rsv_space); 1598 - 1599 - void inode_claim_rsv_space(struct inode *inode, qsize_t number) 1600 - { 1601 - spin_lock(&inode->i_lock); 1602 - *inode_reserved_space(inode) -= number; 1603 - __inode_add_bytes(inode, number); 1604 - spin_unlock(&inode->i_lock); 1605 - } 1606 - EXPORT_SYMBOL(inode_claim_rsv_space); 1607 - 1608 - void inode_reclaim_rsv_space(struct inode *inode, qsize_t number) 1609 - { 1610 - spin_lock(&inode->i_lock); 1611 - *inode_reserved_space(inode) += number; 1612 - __inode_sub_bytes(inode, number); 1613 - spin_unlock(&inode->i_lock); 1614 - } 1615 - EXPORT_SYMBOL(inode_reclaim_rsv_space); 1616 - 1617 - void inode_sub_rsv_space(struct inode *inode, qsize_t number) 1618 - { 1619 - spin_lock(&inode->i_lock); 1620 - *inode_reserved_space(inode) -= number; 1621 - spin_unlock(&inode->i_lock); 1622 - } 1623 - EXPORT_SYMBOL(inode_sub_rsv_space); 1624 1607 1625 1608 static qsize_t inode_get_rsv_space(struct inode *inode) 1626 1609 { ··· 1602 1639 if (!inode->i_sb->dq_op->get_reserved_space) 1603 1640 return 0; 1604 1641 spin_lock(&inode->i_lock); 1605 - ret = *inode_reserved_space(inode); 1642 + ret = __inode_get_rsv_space(inode); 1606 1643 spin_unlock(&inode->i_lock); 1607 1644 return ret; 1608 - } 1609 - 1610 - static void inode_incr_space(struct inode *inode, qsize_t number, 1611 - int reserve) 1612 - { 1613 - if (reserve) 1614 - inode_add_rsv_space(inode, number); 1615 - else 1616 - inode_add_bytes(inode, number); 1617 - } 1618 - 1619 - static void inode_decr_space(struct inode *inode, qsize_t number, int reserve) 1620 - { 1621 - if (reserve) 1622 - inode_sub_rsv_space(inode, number); 1623 - else 1624 - inode_sub_bytes(inode, number); 1625 1645 } 1626 1646 1627 1647 /* ··· 1628 1682 struct dquot **dquots; 1629 1683 1630 1684 if (!dquot_active(inode)) { 1631 - inode_incr_space(inode, number, reserve); 1685 + if (reserve) { 1686 + spin_lock(&inode->i_lock); 1687 + *inode_reserved_space(inode) += number; 1688 + spin_unlock(&inode->i_lock); 1689 + } else { 1690 + inode_add_bytes(inode, number); 1691 + } 1632 1692 goto out; 1633 1693 } 1634 1694 ··· 1643 1691 1644 1692 dquots = i_dquot(inode); 1645 1693 index = srcu_read_lock(&dquot_srcu); 1646 - spin_lock(&dq_data_lock); 1694 + spin_lock(&inode->i_lock); 1647 1695 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1648 1696 if (!dquots[cnt]) 1649 1697 continue; 1650 - ret = check_bdq(dquots[cnt], number, 1651 - !(flags & DQUOT_SPACE_WARN), &warn[cnt]); 1652 - if (ret && !(flags & DQUOT_SPACE_NOFAIL)) { 1653 - spin_unlock(&dq_data_lock); 1698 + if (flags & DQUOT_SPACE_RESERVE) { 1699 + ret = dquot_add_space(dquots[cnt], 0, number, flags, 1700 + &warn[cnt]); 1701 + } else { 1702 + ret = dquot_add_space(dquots[cnt], number, 0, flags, 1703 + &warn[cnt]); 1704 + } 1705 + if (ret) { 1706 + /* Back out changes we already did */ 1707 + for (cnt--; cnt >= 0; cnt--) { 1708 + if (!dquots[cnt]) 1709 + continue; 1710 + spin_lock(&dquots[cnt]->dq_dqb_lock); 1711 + if (flags & DQUOT_SPACE_RESERVE) { 1712 + dquots[cnt]->dq_dqb.dqb_rsvspace -= 1713 + number; 1714 + } else { 1715 + dquots[cnt]->dq_dqb.dqb_curspace -= 1716 + number; 1717 + } 1718 + spin_unlock(&dquots[cnt]->dq_dqb_lock); 1719 + } 1720 + spin_unlock(&inode->i_lock); 1654 1721 goto out_flush_warn; 1655 1722 } 1656 1723 } 1657 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1658 - if (!dquots[cnt]) 1659 - continue; 1660 - if (reserve) 1661 - dquot_resv_space(dquots[cnt], number); 1662 - else 1663 - dquot_incr_space(dquots[cnt], number); 1664 - } 1665 - inode_incr_space(inode, number, reserve); 1666 - spin_unlock(&dq_data_lock); 1724 + if (reserve) 1725 + *inode_reserved_space(inode) += number; 1726 + else 1727 + __inode_add_bytes(inode, number); 1728 + spin_unlock(&inode->i_lock); 1667 1729 1668 1730 if (reserve) 1669 1731 goto out_flush_warn; ··· 1706 1740 1707 1741 dquots = i_dquot(inode); 1708 1742 index = srcu_read_lock(&dquot_srcu); 1709 - spin_lock(&dq_data_lock); 1743 + spin_lock(&inode->i_lock); 1710 1744 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1711 1745 if (!dquots[cnt]) 1712 1746 continue; 1713 - ret = check_idq(dquots[cnt], 1, &warn[cnt]); 1714 - if (ret) 1747 + ret = dquot_add_inodes(dquots[cnt], 1, &warn[cnt]); 1748 + if (ret) { 1749 + for (cnt--; cnt >= 0; cnt--) { 1750 + if (!dquots[cnt]) 1751 + continue; 1752 + /* Back out changes we already did */ 1753 + spin_lock(&dquots[cnt]->dq_dqb_lock); 1754 + dquots[cnt]->dq_dqb.dqb_curinodes--; 1755 + spin_unlock(&dquots[cnt]->dq_dqb_lock); 1756 + } 1715 1757 goto warn_put_all; 1716 - } 1717 - 1718 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1719 - if (!dquots[cnt]) 1720 - continue; 1721 - dquot_incr_inodes(dquots[cnt], 1); 1758 + } 1722 1759 } 1723 1760 1724 1761 warn_put_all: 1725 - spin_unlock(&dq_data_lock); 1762 + spin_unlock(&inode->i_lock); 1726 1763 if (ret == 0) 1727 1764 mark_all_dquot_dirty(dquots); 1728 1765 srcu_read_unlock(&dquot_srcu, index); ··· 1743 1774 int cnt, index; 1744 1775 1745 1776 if (!dquot_active(inode)) { 1746 - inode_claim_rsv_space(inode, number); 1777 + spin_lock(&inode->i_lock); 1778 + *inode_reserved_space(inode) -= number; 1779 + __inode_add_bytes(inode, number); 1780 + spin_unlock(&inode->i_lock); 1747 1781 return 0; 1748 1782 } 1749 1783 1750 1784 dquots = i_dquot(inode); 1751 1785 index = srcu_read_lock(&dquot_srcu); 1752 - spin_lock(&dq_data_lock); 1786 + spin_lock(&inode->i_lock); 1753 1787 /* Claim reserved quotas to allocated quotas */ 1754 1788 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1755 - if (dquots[cnt]) 1756 - dquot_claim_reserved_space(dquots[cnt], number); 1789 + if (dquots[cnt]) { 1790 + struct dquot *dquot = dquots[cnt]; 1791 + 1792 + spin_lock(&dquot->dq_dqb_lock); 1793 + if (WARN_ON_ONCE(dquot->dq_dqb.dqb_rsvspace < number)) 1794 + number = dquot->dq_dqb.dqb_rsvspace; 1795 + dquot->dq_dqb.dqb_curspace += number; 1796 + dquot->dq_dqb.dqb_rsvspace -= number; 1797 + spin_unlock(&dquot->dq_dqb_lock); 1798 + } 1757 1799 } 1758 1800 /* Update inode bytes */ 1759 - inode_claim_rsv_space(inode, number); 1760 - spin_unlock(&dq_data_lock); 1801 + *inode_reserved_space(inode) -= number; 1802 + __inode_add_bytes(inode, number); 1803 + spin_unlock(&inode->i_lock); 1761 1804 mark_all_dquot_dirty(dquots); 1762 1805 srcu_read_unlock(&dquot_srcu, index); 1763 1806 return 0; ··· 1785 1804 int cnt, index; 1786 1805 1787 1806 if (!dquot_active(inode)) { 1788 - inode_reclaim_rsv_space(inode, number); 1807 + spin_lock(&inode->i_lock); 1808 + *inode_reserved_space(inode) += number; 1809 + __inode_sub_bytes(inode, number); 1810 + spin_unlock(&inode->i_lock); 1789 1811 return; 1790 1812 } 1791 1813 1792 1814 dquots = i_dquot(inode); 1793 1815 index = srcu_read_lock(&dquot_srcu); 1794 - spin_lock(&dq_data_lock); 1816 + spin_lock(&inode->i_lock); 1795 1817 /* Claim reserved quotas to allocated quotas */ 1796 1818 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1797 - if (dquots[cnt]) 1798 - dquot_reclaim_reserved_space(dquots[cnt], number); 1819 + if (dquots[cnt]) { 1820 + struct dquot *dquot = dquots[cnt]; 1821 + 1822 + spin_lock(&dquot->dq_dqb_lock); 1823 + if (WARN_ON_ONCE(dquot->dq_dqb.dqb_curspace < number)) 1824 + number = dquot->dq_dqb.dqb_curspace; 1825 + dquot->dq_dqb.dqb_rsvspace += number; 1826 + dquot->dq_dqb.dqb_curspace -= number; 1827 + spin_unlock(&dquot->dq_dqb_lock); 1828 + } 1799 1829 } 1800 1830 /* Update inode bytes */ 1801 - inode_reclaim_rsv_space(inode, number); 1802 - spin_unlock(&dq_data_lock); 1831 + *inode_reserved_space(inode) += number; 1832 + __inode_sub_bytes(inode, number); 1833 + spin_unlock(&inode->i_lock); 1803 1834 mark_all_dquot_dirty(dquots); 1804 1835 srcu_read_unlock(&dquot_srcu, index); 1805 1836 return; ··· 1829 1836 int reserve = flags & DQUOT_SPACE_RESERVE, index; 1830 1837 1831 1838 if (!dquot_active(inode)) { 1832 - inode_decr_space(inode, number, reserve); 1839 + if (reserve) { 1840 + spin_lock(&inode->i_lock); 1841 + *inode_reserved_space(inode) -= number; 1842 + spin_unlock(&inode->i_lock); 1843 + } else { 1844 + inode_sub_bytes(inode, number); 1845 + } 1833 1846 return; 1834 1847 } 1835 1848 1836 1849 dquots = i_dquot(inode); 1837 1850 index = srcu_read_lock(&dquot_srcu); 1838 - spin_lock(&dq_data_lock); 1851 + spin_lock(&inode->i_lock); 1839 1852 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1840 1853 int wtype; 1841 1854 1842 1855 warn[cnt].w_type = QUOTA_NL_NOWARN; 1843 1856 if (!dquots[cnt]) 1844 1857 continue; 1858 + spin_lock(&dquots[cnt]->dq_dqb_lock); 1845 1859 wtype = info_bdq_free(dquots[cnt], number); 1846 1860 if (wtype != QUOTA_NL_NOWARN) 1847 1861 prepare_warning(&warn[cnt], dquots[cnt], wtype); ··· 1856 1856 dquot_free_reserved_space(dquots[cnt], number); 1857 1857 else 1858 1858 dquot_decr_space(dquots[cnt], number); 1859 + spin_unlock(&dquots[cnt]->dq_dqb_lock); 1859 1860 } 1860 - inode_decr_space(inode, number, reserve); 1861 - spin_unlock(&dq_data_lock); 1861 + if (reserve) 1862 + *inode_reserved_space(inode) -= number; 1863 + else 1864 + __inode_sub_bytes(inode, number); 1865 + spin_unlock(&inode->i_lock); 1862 1866 1863 1867 if (reserve) 1864 1868 goto out_unlock; ··· 1888 1884 1889 1885 dquots = i_dquot(inode); 1890 1886 index = srcu_read_lock(&dquot_srcu); 1891 - spin_lock(&dq_data_lock); 1887 + spin_lock(&inode->i_lock); 1892 1888 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1893 1889 int wtype; 1894 1890 1895 1891 warn[cnt].w_type = QUOTA_NL_NOWARN; 1896 1892 if (!dquots[cnt]) 1897 1893 continue; 1894 + spin_lock(&dquots[cnt]->dq_dqb_lock); 1898 1895 wtype = info_idq_free(dquots[cnt], 1); 1899 1896 if (wtype != QUOTA_NL_NOWARN) 1900 1897 prepare_warning(&warn[cnt], dquots[cnt], wtype); 1901 1898 dquot_decr_inodes(dquots[cnt], 1); 1899 + spin_unlock(&dquots[cnt]->dq_dqb_lock); 1902 1900 } 1903 - spin_unlock(&dq_data_lock); 1901 + spin_unlock(&inode->i_lock); 1904 1902 mark_all_dquot_dirty(dquots); 1905 1903 srcu_read_unlock(&dquot_srcu, index); 1906 1904 flush_warnings(warn); ··· 1923 1917 */ 1924 1918 int __dquot_transfer(struct inode *inode, struct dquot **transfer_to) 1925 1919 { 1926 - qsize_t space, cur_space; 1920 + qsize_t cur_space; 1927 1921 qsize_t rsv_space = 0; 1928 1922 qsize_t inode_usage = 1; 1929 1923 struct dquot *transfer_from[MAXQUOTAS] = {}; ··· 1950 1944 } 1951 1945 1952 1946 spin_lock(&dq_data_lock); 1947 + spin_lock(&inode->i_lock); 1953 1948 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ 1949 + spin_unlock(&inode->i_lock); 1954 1950 spin_unlock(&dq_data_lock); 1955 1951 return 0; 1956 1952 } 1957 - cur_space = inode_get_bytes(inode); 1958 - rsv_space = inode_get_rsv_space(inode); 1959 - space = cur_space + rsv_space; 1960 - /* Build the transfer_from list and check the limits */ 1953 + cur_space = __inode_get_bytes(inode); 1954 + rsv_space = __inode_get_rsv_space(inode); 1955 + /* 1956 + * Build the transfer_from list, check limits, and update usage in 1957 + * the target structures. 1958 + */ 1961 1959 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1962 1960 /* 1963 1961 * Skip changes for same uid or gid or for turned off quota-type. ··· 1973 1963 continue; 1974 1964 is_valid[cnt] = 1; 1975 1965 transfer_from[cnt] = i_dquot(inode)[cnt]; 1976 - ret = check_idq(transfer_to[cnt], inode_usage, &warn_to[cnt]); 1966 + ret = dquot_add_inodes(transfer_to[cnt], inode_usage, 1967 + &warn_to[cnt]); 1977 1968 if (ret) 1978 1969 goto over_quota; 1979 - ret = check_bdq(transfer_to[cnt], space, 0, &warn_to[cnt]); 1980 - if (ret) 1970 + ret = dquot_add_space(transfer_to[cnt], cur_space, rsv_space, 0, 1971 + &warn_to[cnt]); 1972 + if (ret) { 1973 + dquot_decr_inodes(transfer_to[cnt], inode_usage); 1981 1974 goto over_quota; 1975 + } 1982 1976 } 1983 1977 1984 - /* 1985 - * Finally perform the needed transfer from transfer_from to transfer_to 1986 - */ 1978 + /* Decrease usage for source structures and update quota pointers */ 1987 1979 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1988 1980 if (!is_valid[cnt]) 1989 1981 continue; 1990 1982 /* Due to IO error we might not have transfer_from[] structure */ 1991 1983 if (transfer_from[cnt]) { 1992 1984 int wtype; 1985 + 1986 + spin_lock(&transfer_from[cnt]->dq_dqb_lock); 1993 1987 wtype = info_idq_free(transfer_from[cnt], inode_usage); 1994 1988 if (wtype != QUOTA_NL_NOWARN) 1995 1989 prepare_warning(&warn_from_inodes[cnt], 1996 1990 transfer_from[cnt], wtype); 1997 - wtype = info_bdq_free(transfer_from[cnt], space); 1991 + wtype = info_bdq_free(transfer_from[cnt], 1992 + cur_space + rsv_space); 1998 1993 if (wtype != QUOTA_NL_NOWARN) 1999 1994 prepare_warning(&warn_from_space[cnt], 2000 1995 transfer_from[cnt], wtype); ··· 2007 1992 dquot_decr_space(transfer_from[cnt], cur_space); 2008 1993 dquot_free_reserved_space(transfer_from[cnt], 2009 1994 rsv_space); 1995 + spin_unlock(&transfer_from[cnt]->dq_dqb_lock); 2010 1996 } 2011 - 2012 - dquot_incr_inodes(transfer_to[cnt], inode_usage); 2013 - dquot_incr_space(transfer_to[cnt], cur_space); 2014 - dquot_resv_space(transfer_to[cnt], rsv_space); 2015 - 2016 1997 i_dquot(inode)[cnt] = transfer_to[cnt]; 2017 1998 } 1999 + spin_unlock(&inode->i_lock); 2018 2000 spin_unlock(&dq_data_lock); 2019 2001 2020 2002 mark_all_dquot_dirty(transfer_from); ··· 2025 2013 transfer_to[cnt] = transfer_from[cnt]; 2026 2014 return 0; 2027 2015 over_quota: 2016 + /* Back out changes we already did */ 2017 + for (cnt--; cnt >= 0; cnt--) { 2018 + if (!is_valid[cnt]) 2019 + continue; 2020 + spin_lock(&transfer_to[cnt]->dq_dqb_lock); 2021 + dquot_decr_inodes(transfer_to[cnt], inode_usage); 2022 + dquot_decr_space(transfer_to[cnt], cur_space); 2023 + dquot_free_reserved_space(transfer_to[cnt], rsv_space); 2024 + spin_unlock(&transfer_to[cnt]->dq_dqb_lock); 2025 + } 2026 + spin_unlock(&inode->i_lock); 2028 2027 spin_unlock(&dq_data_lock); 2029 2028 flush_warnings(warn_to); 2030 2029 return ret; ··· 2089 2066 */ 2090 2067 int dquot_commit_info(struct super_block *sb, int type) 2091 2068 { 2092 - int ret; 2093 2069 struct quota_info *dqopt = sb_dqopt(sb); 2094 2070 2095 - mutex_lock(&dqopt->dqio_mutex); 2096 - ret = dqopt->ops[type]->write_file_info(sb, type); 2097 - mutex_unlock(&dqopt->dqio_mutex); 2098 - return ret; 2071 + return dqopt->ops[type]->write_file_info(sb, type); 2099 2072 } 2100 2073 EXPORT_SYMBOL(dquot_commit_info); 2101 2074 2102 2075 int dquot_get_next_id(struct super_block *sb, struct kqid *qid) 2103 2076 { 2104 2077 struct quota_info *dqopt = sb_dqopt(sb); 2105 - int err; 2106 2078 2107 2079 if (!sb_has_quota_active(sb, qid->type)) 2108 2080 return -ESRCH; 2109 2081 if (!dqopt->ops[qid->type]->get_next_id) 2110 2082 return -ENOSYS; 2111 - mutex_lock(&dqopt->dqio_mutex); 2112 - err = dqopt->ops[qid->type]->get_next_id(sb, qid); 2113 - mutex_unlock(&dqopt->dqio_mutex); 2114 - return err; 2083 + return dqopt->ops[qid->type]->get_next_id(sb, qid); 2115 2084 } 2116 2085 EXPORT_SYMBOL(dquot_get_next_id); 2117 2086 ··· 2352 2337 dqopt->info[type].dqi_format = fmt; 2353 2338 dqopt->info[type].dqi_fmt_id = format_id; 2354 2339 INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list); 2355 - mutex_lock(&dqopt->dqio_mutex); 2356 2340 error = dqopt->ops[type]->read_file_info(sb, type); 2357 - if (error < 0) { 2358 - mutex_unlock(&dqopt->dqio_mutex); 2341 + if (error < 0) 2359 2342 goto out_file_init; 2360 - } 2361 - if (dqopt->flags & DQUOT_QUOTA_SYS_FILE) 2343 + if (dqopt->flags & DQUOT_QUOTA_SYS_FILE) { 2344 + spin_lock(&dq_data_lock); 2362 2345 dqopt->info[type].dqi_flags |= DQF_SYS_FILE; 2363 - mutex_unlock(&dqopt->dqio_mutex); 2346 + spin_unlock(&dq_data_lock); 2347 + } 2364 2348 spin_lock(&dq_state_lock); 2365 2349 dqopt->flags |= dquot_state_flag(flags, type); 2366 2350 spin_unlock(&dq_state_lock); ··· 2586 2572 struct mem_dqblk *dm = &dquot->dq_dqb; 2587 2573 2588 2574 memset(di, 0, sizeof(*di)); 2589 - spin_lock(&dq_data_lock); 2575 + spin_lock(&dquot->dq_dqb_lock); 2590 2576 di->d_spc_hardlimit = dm->dqb_bhardlimit; 2591 2577 di->d_spc_softlimit = dm->dqb_bsoftlimit; 2592 2578 di->d_ino_hardlimit = dm->dqb_ihardlimit; ··· 2595 2581 di->d_ino_count = dm->dqb_curinodes; 2596 2582 di->d_spc_timer = dm->dqb_btime; 2597 2583 di->d_ino_timer = dm->dqb_itime; 2598 - spin_unlock(&dq_data_lock); 2584 + spin_unlock(&dquot->dq_dqb_lock); 2599 2585 } 2600 2586 2601 2587 int dquot_get_dqblk(struct super_block *sb, struct kqid qid, ··· 2659 2645 (di->d_ino_hardlimit > dqi->dqi_max_ino_limit))) 2660 2646 return -ERANGE; 2661 2647 2662 - spin_lock(&dq_data_lock); 2648 + spin_lock(&dquot->dq_dqb_lock); 2663 2649 if (di->d_fieldmask & QC_SPACE) { 2664 2650 dm->dqb_curspace = di->d_space - dm->dqb_rsvspace; 2665 2651 check_blim = 1; ··· 2725 2711 clear_bit(DQ_FAKE_B, &dquot->dq_flags); 2726 2712 else 2727 2713 set_bit(DQ_FAKE_B, &dquot->dq_flags); 2728 - spin_unlock(&dq_data_lock); 2714 + spin_unlock(&dquot->dq_dqb_lock); 2729 2715 mark_dquot_dirty(dquot); 2730 2716 2731 2717 return 0;
+5 -5
fs/quota/quota_tree.c
··· 379 379 if (!ddquot) 380 380 return -ENOMEM; 381 381 382 - /* dq_off is guarded by dqio_mutex */ 382 + /* dq_off is guarded by dqio_sem */ 383 383 if (!dquot->dq_off) { 384 384 ret = dq_insert_tree(info, dquot); 385 385 if (ret < 0) { ··· 389 389 return ret; 390 390 } 391 391 } 392 - spin_lock(&dq_data_lock); 392 + spin_lock(&dquot->dq_dqb_lock); 393 393 info->dqi_ops->mem2disk_dqblk(ddquot, dquot); 394 - spin_unlock(&dq_data_lock); 394 + spin_unlock(&dquot->dq_dqb_lock); 395 395 ret = sb->s_op->quota_write(sb, type, ddquot, info->dqi_entry_size, 396 396 dquot->dq_off); 397 397 if (ret != info->dqi_entry_size) { ··· 649 649 kfree(ddquot); 650 650 goto out; 651 651 } 652 - spin_lock(&dq_data_lock); 652 + spin_lock(&dquot->dq_dqb_lock); 653 653 info->dqi_ops->disk2mem_dqblk(dquot, ddquot); 654 654 if (!dquot->dq_dqb.dqb_bhardlimit && 655 655 !dquot->dq_dqb.dqb_bsoftlimit && 656 656 !dquot->dq_dqb.dqb_ihardlimit && 657 657 !dquot->dq_dqb.dqb_isoftlimit) 658 658 set_bit(DQ_FAKE_B, &dquot->dq_flags); 659 - spin_unlock(&dq_data_lock); 659 + spin_unlock(&dquot->dq_dqb_lock); 660 660 kfree(ddquot); 661 661 out: 662 662 dqstats_inc(DQST_READS);
+9 -2
fs/quota/quota_v1.c
··· 56 56 { 57 57 int type = dquot->dq_id.type; 58 58 struct v1_disk_dqblk dqblk; 59 + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); 59 60 60 - if (!sb_dqopt(dquot->dq_sb)->files[type]) 61 + if (!dqopt->files[type]) 61 62 return -EINVAL; 62 63 63 64 /* Set structure to 0s in case read fails/is after end of file */ ··· 161 160 struct v1_disk_dqblk dqblk; 162 161 int ret; 163 162 163 + down_read(&dqopt->dqio_sem); 164 164 ret = sb->s_op->quota_read(sb, type, (char *)&dqblk, 165 165 sizeof(struct v1_disk_dqblk), v1_dqoff(0)); 166 166 if (ret != sizeof(struct v1_disk_dqblk)) { ··· 178 176 dqopt->info[type].dqi_bgrace = 179 177 dqblk.dqb_btime ? dqblk.dqb_btime : MAX_DQ_TIME; 180 178 out: 179 + up_read(&dqopt->dqio_sem); 181 180 return ret; 182 181 } 183 182 ··· 188 185 struct v1_disk_dqblk dqblk; 189 186 int ret; 190 187 191 - dqopt->info[type].dqi_flags &= ~DQF_INFO_DIRTY; 188 + down_write(&dqopt->dqio_sem); 192 189 ret = sb->s_op->quota_read(sb, type, (char *)&dqblk, 193 190 sizeof(struct v1_disk_dqblk), v1_dqoff(0)); 194 191 if (ret != sizeof(struct v1_disk_dqblk)) { ··· 196 193 ret = -EIO; 197 194 goto out; 198 195 } 196 + spin_lock(&dq_data_lock); 197 + dqopt->info[type].dqi_flags &= ~DQF_INFO_DIRTY; 199 198 dqblk.dqb_itime = dqopt->info[type].dqi_igrace; 200 199 dqblk.dqb_btime = dqopt->info[type].dqi_bgrace; 200 + spin_unlock(&dq_data_lock); 201 201 ret = sb->s_op->quota_write(sb, type, (char *)&dqblk, 202 202 sizeof(struct v1_disk_dqblk), v1_dqoff(0)); 203 203 if (ret == sizeof(struct v1_disk_dqblk)) ··· 208 202 else if (ret > 0) 209 203 ret = -EIO; 210 204 out: 205 + up_write(&dqopt->dqio_sem); 211 206 return ret; 212 207 } 213 208
+77 -18
fs/quota/quota_v2.c
··· 65 65 if (size != sizeof(struct v2_disk_dqheader)) { 66 66 quota_error(sb, "Failed header read: expected=%zd got=%zd", 67 67 sizeof(struct v2_disk_dqheader), size); 68 - return 0; 68 + if (size < 0) 69 + return size; 70 + return -EIO; 69 71 } 70 - return 1; 72 + return 0; 71 73 } 72 74 73 75 /* Check whether given file is really vfsv0 quotafile */ ··· 79 77 static const uint quota_magics[] = V2_INITQMAGICS; 80 78 static const uint quota_versions[] = V2_INITQVERSIONS; 81 79 82 - if (!v2_read_header(sb, type, &dqhead)) 80 + if (v2_read_header(sb, type, &dqhead)) 83 81 return 0; 84 82 if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] || 85 83 le32_to_cpu(dqhead.dqh_version) > quota_versions[type]) ··· 92 90 { 93 91 struct v2_disk_dqinfo dinfo; 94 92 struct v2_disk_dqheader dqhead; 95 - struct mem_dqinfo *info = sb_dqinfo(sb, type); 93 + struct quota_info *dqopt = sb_dqopt(sb); 94 + struct mem_dqinfo *info = &dqopt->info[type]; 96 95 struct qtree_mem_dqinfo *qinfo; 97 96 ssize_t size; 98 97 unsigned int version; 98 + int ret; 99 99 100 - if (!v2_read_header(sb, type, &dqhead)) 101 - return -1; 100 + down_read(&dqopt->dqio_sem); 101 + ret = v2_read_header(sb, type, &dqhead); 102 + if (ret < 0) 103 + goto out; 102 104 version = le32_to_cpu(dqhead.dqh_version); 103 105 if ((info->dqi_fmt_id == QFMT_VFS_V0 && version != 0) || 104 - (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) 105 - return -1; 106 + (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) { 107 + ret = -EINVAL; 108 + goto out; 109 + } 106 110 107 111 size = sb->s_op->quota_read(sb, type, (char *)&dinfo, 108 112 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); 109 113 if (size != sizeof(struct v2_disk_dqinfo)) { 110 114 quota_error(sb, "Can't read info structure"); 111 - return -1; 115 + if (size < 0) 116 + ret = size; 117 + else 118 + ret = -EIO; 119 + goto out; 112 120 } 113 121 info->dqi_priv = kmalloc(sizeof(struct qtree_mem_dqinfo), GFP_NOFS); 114 - if (!info->dqi_priv) 115 - return -ENOMEM; 116 - 122 + if (!info->dqi_priv) { 123 + ret = -ENOMEM; 124 + goto out; 125 + } 117 126 qinfo = info->dqi_priv; 118 127 if (version == 0) { 119 128 /* limits are stored as unsigned 32-bit data */ ··· 158 145 qinfo->dqi_entry_size = sizeof(struct v2r1_disk_dqblk); 159 146 qinfo->dqi_ops = &v2r1_qtree_ops; 160 147 } 161 - return 0; 148 + ret = 0; 149 + out: 150 + up_read(&dqopt->dqio_sem); 151 + return ret; 162 152 } 163 153 164 154 /* Write information header to quota file */ 165 155 static int v2_write_file_info(struct super_block *sb, int type) 166 156 { 167 157 struct v2_disk_dqinfo dinfo; 168 - struct mem_dqinfo *info = sb_dqinfo(sb, type); 158 + struct quota_info *dqopt = sb_dqopt(sb); 159 + struct mem_dqinfo *info = &dqopt->info[type]; 169 160 struct qtree_mem_dqinfo *qinfo = info->dqi_priv; 170 161 ssize_t size; 171 162 163 + down_write(&dqopt->dqio_sem); 172 164 spin_lock(&dq_data_lock); 173 165 info->dqi_flags &= ~DQF_INFO_DIRTY; 174 166 dinfo.dqi_bgrace = cpu_to_le32(info->dqi_bgrace); ··· 186 168 dinfo.dqi_free_entry = cpu_to_le32(qinfo->dqi_free_entry); 187 169 size = sb->s_op->quota_write(sb, type, (char *)&dinfo, 188 170 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); 171 + up_write(&dqopt->dqio_sem); 189 172 if (size != sizeof(struct v2_disk_dqinfo)) { 190 173 quota_error(sb, "Can't write info structure"); 191 174 return -1; ··· 302 283 303 284 static int v2_read_dquot(struct dquot *dquot) 304 285 { 305 - return qtree_read_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); 286 + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); 287 + int ret; 288 + 289 + down_read(&dqopt->dqio_sem); 290 + ret = qtree_read_dquot( 291 + sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, 292 + dquot); 293 + up_read(&dqopt->dqio_sem); 294 + return ret; 306 295 } 307 296 308 297 static int v2_write_dquot(struct dquot *dquot) 309 298 { 310 - return qtree_write_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); 299 + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); 300 + int ret; 301 + bool alloc = false; 302 + 303 + /* 304 + * If space for dquot is already allocated, we don't need any 305 + * protection as we'll only overwrite the place of dquot. We are 306 + * still protected by concurrent writes of the same dquot by 307 + * dquot->dq_lock. 308 + */ 309 + if (!dquot->dq_off) { 310 + alloc = true; 311 + down_write(&dqopt->dqio_sem); 312 + } 313 + ret = qtree_write_dquot( 314 + sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, 315 + dquot); 316 + if (alloc) 317 + up_write(&dqopt->dqio_sem); 318 + return ret; 311 319 } 312 320 313 321 static int v2_release_dquot(struct dquot *dquot) 314 322 { 315 - return qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); 323 + struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); 324 + int ret; 325 + 326 + down_write(&dqopt->dqio_sem); 327 + ret = qtree_release_dquot(sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv, dquot); 328 + up_write(&dqopt->dqio_sem); 329 + 330 + return ret; 316 331 } 317 332 318 333 static int v2_free_file_info(struct super_block *sb, int type) ··· 357 304 358 305 static int v2_get_next_id(struct super_block *sb, struct kqid *qid) 359 306 { 360 - return qtree_get_next_id(sb_dqinfo(sb, qid->type)->dqi_priv, qid); 307 + struct quota_info *dqopt = sb_dqopt(sb); 308 + int ret; 309 + 310 + down_read(&dqopt->dqio_sem); 311 + ret = qtree_get_next_id(sb_dqinfo(sb, qid->type)->dqi_priv, qid); 312 + up_read(&dqopt->dqio_sem); 313 + return ret; 361 314 } 362 315 363 316 static const struct quota_format_ops v2_format_ops = {
+1 -1
fs/stat.c
··· 710 710 loff_t ret; 711 711 712 712 spin_lock(&inode->i_lock); 713 - ret = (((loff_t)inode->i_blocks) << 9) + inode->i_bytes; 713 + ret = __inode_get_bytes(inode); 714 714 spin_unlock(&inode->i_lock); 715 715 return ret; 716 716 }
+1 -1
fs/super.c
··· 242 242 atomic_set(&s->s_active, 1); 243 243 mutex_init(&s->s_vfs_rename_mutex); 244 244 lockdep_set_class(&s->s_vfs_rename_mutex, &type->s_vfs_rename_key); 245 - mutex_init(&s->s_dquot.dqio_mutex); 245 + init_rwsem(&s->s_dquot.dqio_sem); 246 246 s->s_maxbytes = MAX_NON_LFS; 247 247 s->s_op = &default_op; 248 248 s->s_time_gran = 1000000000;
+4
include/linux/fs.h
··· 3015 3015 void inode_add_bytes(struct inode *inode, loff_t bytes); 3016 3016 void __inode_sub_bytes(struct inode *inode, loff_t bytes); 3017 3017 void inode_sub_bytes(struct inode *inode, loff_t bytes); 3018 + static inline loff_t __inode_get_bytes(struct inode *inode) 3019 + { 3020 + return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes; 3021 + } 3018 3022 loff_t inode_get_bytes(struct inode *inode); 3019 3023 void inode_set_bytes(struct inode *inode, loff_t bytes); 3020 3024 const char *simple_get_link(struct dentry *, struct inode *,
+17 -14
include/linux/quota.h
··· 223 223 struct quota_format_type *dqi_format; 224 224 int dqi_fmt_id; /* Id of the dqi_format - used when turning 225 225 * quotas on after remount RW */ 226 - struct list_head dqi_dirty_list; /* List of dirty dquots */ 227 - unsigned long dqi_flags; 228 - unsigned int dqi_bgrace; 229 - unsigned int dqi_igrace; 230 - qsize_t dqi_max_spc_limit; 231 - qsize_t dqi_max_ino_limit; 226 + struct list_head dqi_dirty_list; /* List of dirty dquots [dq_list_lock] */ 227 + unsigned long dqi_flags; /* DFQ_ flags [dq_data_lock] */ 228 + unsigned int dqi_bgrace; /* Space grace time [dq_data_lock] */ 229 + unsigned int dqi_igrace; /* Inode grace time [dq_data_lock] */ 230 + qsize_t dqi_max_spc_limit; /* Maximum space limit [static] */ 231 + qsize_t dqi_max_ino_limit; /* Maximum inode limit [static] */ 232 232 void *dqi_priv; 233 233 }; 234 234 ··· 293 293 * clear them when it sees fit. */ 294 294 295 295 struct dquot { 296 - struct hlist_node dq_hash; /* Hash list in memory */ 297 - struct list_head dq_inuse; /* List of all quotas */ 298 - struct list_head dq_free; /* Free list element */ 299 - struct list_head dq_dirty; /* List of dirty dquots */ 296 + struct hlist_node dq_hash; /* Hash list in memory [dq_list_lock] */ 297 + struct list_head dq_inuse; /* List of all quotas [dq_list_lock] */ 298 + struct list_head dq_free; /* Free list element [dq_list_lock] */ 299 + struct list_head dq_dirty; /* List of dirty dquots [dq_list_lock] */ 300 300 struct mutex dq_lock; /* dquot IO lock */ 301 + spinlock_t dq_dqb_lock; /* Lock protecting dq_dqb changes */ 301 302 atomic_t dq_count; /* Use count */ 302 - wait_queue_head_t dq_wait_unused; /* Wait queue for dquot to become unused */ 303 303 struct super_block *dq_sb; /* superblock this applies to */ 304 304 struct kqid dq_id; /* ID this applies to (uid, gid, projid) */ 305 - loff_t dq_off; /* Offset of dquot on disk */ 305 + loff_t dq_off; /* Offset of dquot on disk [dq_lock, stable once set] */ 306 306 unsigned long dq_flags; /* See DQ_* */ 307 - struct mem_dqblk dq_dqb; /* Diskquota usage */ 307 + struct mem_dqblk dq_dqb; /* Diskquota usage [dq_dqb_lock] */ 308 308 }; 309 309 310 310 /* Operations which must be implemented by each quota format */ ··· 491 491 */ 492 492 #define DQUOT_NEGATIVE_USAGE (1 << (DQUOT_STATE_LAST + 1)) 493 493 /* Allow negative quota usage */ 494 + /* Do not track dirty dquots in a list */ 495 + #define DQUOT_NOLIST_DIRTY (1 << (DQUOT_STATE_LAST + 2)) 496 + 494 497 static inline unsigned int dquot_state_flag(unsigned int flags, int type) 495 498 { 496 499 return flags << type; ··· 524 521 525 522 struct quota_info { 526 523 unsigned int flags; /* Flags for diskquotas on this device */ 527 - struct mutex dqio_mutex; /* lock device while I/O in progress */ 524 + struct rw_semaphore dqio_sem; /* Lock quota file while I/O in progress */ 528 525 struct inode *files[MAXQUOTAS]; /* inodes of quotafiles */ 529 526 struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */ 530 527 const struct quota_format_ops *ops[MAXQUOTAS]; /* Operations for each type */
-5
include/linux/quotaops.h
··· 38 38 /* 39 39 * declaration of quota_function calls in kernel. 40 40 */ 41 - void inode_add_rsv_space(struct inode *inode, qsize_t number); 42 - void inode_claim_rsv_space(struct inode *inode, qsize_t number); 43 - void inode_sub_rsv_space(struct inode *inode, qsize_t number); 44 - void inode_reclaim_rsv_space(struct inode *inode, qsize_t number); 45 - 46 41 int dquot_initialize(struct inode *inode); 47 42 bool dquot_initialize_needed(struct inode *inode); 48 43 void dquot_drop(struct inode *inode);