Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-quota-2.6

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-quota-2.6:
ocfs2: Remove ocfs2_dquot_initialize() and ocfs2_dquot_drop()
quota: Improve locking

+126 -267
+124 -98
fs/dquot.c
··· 87 87 #define __DQUOT_PARANOIA 88 88 89 89 /* 90 - * There are two quota SMP locks. dq_list_lock protects all lists with quotas 91 - * and quota formats and also dqstats structure containing statistics about the 92 - * lists. dq_data_lock protects data from dq_dqb and also mem_dqinfo structures 93 - * and also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes. 90 + * There are three quota SMP locks. dq_list_lock protects all lists with quotas 91 + * and quota formats, dqstats structure containing statistics about the lists 92 + * dq_data_lock protects data from dq_dqb and also mem_dqinfo structures and 93 + * also guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes. 94 94 * i_blocks and i_bytes updates itself are guarded by i_lock acquired directly 95 - * in inode_add_bytes() and inode_sub_bytes(). 95 + * in inode_add_bytes() and inode_sub_bytes(). dq_state_lock protects 96 + * modifications of quota state (on quotaon and quotaoff) and readers who care 97 + * about latest values take it as well. 96 98 * 97 - * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock 99 + * The spinlock ordering is hence: dq_data_lock > dq_list_lock > i_lock, 100 + * dq_list_lock > dq_state_lock 98 101 * 99 102 * Note that some things (eg. sb pointer, type, id) doesn't change during 100 103 * the life of the dquot structure and so needn't to be protected by a lock ··· 106 103 * operation is just reading pointers from inode (or not using them at all) the 107 104 * read lock is enough. If pointers are altered function must hold write lock 108 105 * (these locking rules also apply for S_NOQUOTA flag in the inode - note that 109 - * for altering the flag i_mutex is also needed). If operation is holding 110 - * reference to dquot in other way (e.g. quotactl ops) it must be guarded by 111 - * dqonoff_mutex. 112 - * This locking assures that: 113 - * a) update/access to dquot pointers in inode is serialized 114 - * b) everyone is guarded against invalidate_dquots() 106 + * for altering the flag i_mutex is also needed). 115 107 * 116 108 * Each dquot has its dq_lock mutex. Locked dquots might not be referenced 117 109 * from inodes (dquot_alloc_space() and such don't check the dq_lock). ··· 120 122 * Lock ordering (including related VFS locks) is the following: 121 123 * i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock > 122 124 * dqio_mutex 125 + * The lock ordering of dqptr_sem imposed by quota code is only dqonoff_sem > 126 + * dqptr_sem. But filesystem has to count with the fact that functions such as 127 + * dquot_alloc_space() acquire dqptr_sem and they usually have to be called 128 + * from inside a transaction to keep filesystem consistency after a crash. Also 129 + * filesystems usually want to do some IO on dquot from ->mark_dirty which is 130 + * called with dqptr_sem held. 123 131 * i_mutex on quota files is special (it's below dqio_mutex) 124 132 */ 125 133 126 134 static DEFINE_SPINLOCK(dq_list_lock); 135 + static DEFINE_SPINLOCK(dq_state_lock); 127 136 DEFINE_SPINLOCK(dq_data_lock); 128 137 129 138 static char *quotatypes[] = INITQFNAMES; ··· 433 428 * quota is disabled and pointers from inodes removed so there cannot be new 434 429 * quota users. There can still be some users of quotas due to inodes being 435 430 * just deleted or pruned by prune_icache() (those are not attached to any 436 - * list). We have to wait for such users. 431 + * list) or parallel quotactl call. We have to wait for such users. 437 432 */ 438 433 static void invalidate_dquots(struct super_block *sb, int type) 439 434 { ··· 605 600 /* 606 601 * Put reference to dquot 607 602 * NOTE: If you change this function please check whether dqput_blocks() works right... 608 - * MUST be called with either dqptr_sem or dqonoff_mutex held 609 603 */ 610 604 void dqput(struct dquot *dquot) 611 605 { ··· 701 697 } 702 698 703 699 /* 704 - * Check whether dquot is in memory. 705 - * MUST be called with either dqptr_sem or dqonoff_mutex held 706 - */ 707 - int dquot_is_cached(struct super_block *sb, unsigned int id, int type) 708 - { 709 - unsigned int hashent = hashfn(sb, id, type); 710 - int ret = 0; 711 - 712 - if (!sb_has_quota_active(sb, type)) 713 - return 0; 714 - spin_lock(&dq_list_lock); 715 - if (find_dquot(hashent, sb, id, type) != NODQUOT) 716 - ret = 1; 717 - spin_unlock(&dq_list_lock); 718 - return ret; 719 - } 720 - 721 - /* 722 700 * Get reference to dquot 723 - * MUST be called with either dqptr_sem or dqonoff_mutex held 701 + * 702 + * Locking is slightly tricky here. We are guarded from parallel quotaoff() 703 + * destroying our dquot by: 704 + * a) checking for quota flags under dq_list_lock and 705 + * b) getting a reference to dquot before we release dq_list_lock 724 706 */ 725 707 struct dquot *dqget(struct super_block *sb, unsigned int id, int type) 726 708 { 727 709 unsigned int hashent = hashfn(sb, id, type); 728 - struct dquot *dquot, *empty = NODQUOT; 710 + struct dquot *dquot = NODQUOT, *empty = NODQUOT; 729 711 730 712 if (!sb_has_quota_active(sb, type)) 731 713 return NODQUOT; 732 714 we_slept: 733 715 spin_lock(&dq_list_lock); 716 + spin_lock(&dq_state_lock); 717 + if (!sb_has_quota_active(sb, type)) { 718 + spin_unlock(&dq_state_lock); 719 + spin_unlock(&dq_list_lock); 720 + goto out; 721 + } 722 + spin_unlock(&dq_state_lock); 723 + 734 724 if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) { 735 725 if (empty == NODQUOT) { 736 726 spin_unlock(&dq_list_lock); ··· 733 735 goto we_slept; 734 736 } 735 737 dquot = empty; 738 + empty = NODQUOT; 736 739 dquot->dq_id = id; 737 740 /* all dquots go on the inuse_list */ 738 741 put_inuse(dquot); ··· 748 749 dqstats.cache_hits++; 749 750 dqstats.lookups++; 750 751 spin_unlock(&dq_list_lock); 751 - if (empty) 752 - do_destroy_dquot(empty); 753 752 } 754 753 /* Wait for dq_lock - after this we know that either dquot_release() is already 755 754 * finished or it will be canceled due to dq_count > 1 test */ ··· 755 758 /* Read the dquot and instantiate it (everything done only if needed) */ 756 759 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) { 757 760 dqput(dquot); 758 - return NODQUOT; 761 + dquot = NODQUOT; 762 + goto out; 759 763 } 760 764 #ifdef __DQUOT_PARANOIA 761 765 BUG_ON(!dquot->dq_sb); /* Has somebody invalidated entry under us? */ 762 766 #endif 767 + out: 768 + if (empty) 769 + do_destroy_dquot(empty); 763 770 764 771 return dquot; 765 772 } ··· 1199 1198 } 1200 1199 /* 1201 1200 * Initialize quota pointers in inode 1202 - * Transaction must be started at entry 1201 + * We do things in a bit complicated way but by that we avoid calling 1202 + * dqget() and thus filesystem callbacks under dqptr_sem. 1203 1203 */ 1204 1204 int dquot_initialize(struct inode *inode, int type) 1205 1205 { 1206 1206 unsigned int id = 0; 1207 1207 int cnt, ret = 0; 1208 + struct dquot *got[MAXQUOTAS] = { NODQUOT, NODQUOT }; 1209 + struct super_block *sb = inode->i_sb; 1208 1210 1209 1211 /* First test before acquiring mutex - solves deadlocks when we 1210 1212 * re-enter the quota code and are already holding the mutex */ 1211 1213 if (IS_NOQUOTA(inode)) 1212 1214 return 0; 1213 - down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1215 + 1216 + /* First get references to structures we might need. */ 1217 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1218 + if (type != -1 && cnt != type) 1219 + continue; 1220 + switch (cnt) { 1221 + case USRQUOTA: 1222 + id = inode->i_uid; 1223 + break; 1224 + case GRPQUOTA: 1225 + id = inode->i_gid; 1226 + break; 1227 + } 1228 + got[cnt] = dqget(sb, id, cnt); 1229 + } 1230 + 1231 + down_write(&sb_dqopt(sb)->dqptr_sem); 1214 1232 /* Having dqptr_sem we know NOQUOTA flags can't be altered... */ 1215 1233 if (IS_NOQUOTA(inode)) 1216 1234 goto out_err; 1217 1235 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1218 1236 if (type != -1 && cnt != type) 1219 1237 continue; 1238 + /* Avoid races with quotaoff() */ 1239 + if (!sb_has_quota_active(sb, cnt)) 1240 + continue; 1220 1241 if (inode->i_dquot[cnt] == NODQUOT) { 1221 - switch (cnt) { 1222 - case USRQUOTA: 1223 - id = inode->i_uid; 1224 - break; 1225 - case GRPQUOTA: 1226 - id = inode->i_gid; 1227 - break; 1228 - } 1229 - inode->i_dquot[cnt] = dqget(inode->i_sb, id, cnt); 1242 + inode->i_dquot[cnt] = got[cnt]; 1243 + got[cnt] = NODQUOT; 1230 1244 } 1231 1245 } 1232 1246 out_err: 1233 - up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1247 + up_write(&sb_dqopt(sb)->dqptr_sem); 1248 + /* Drop unused references */ 1249 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1250 + dqput(got[cnt]); 1234 1251 return ret; 1235 1252 } 1236 1253 1237 1254 /* 1238 1255 * Release all quotas referenced by inode 1239 - * Transaction must be started at an entry 1240 1256 */ 1241 - int dquot_drop_locked(struct inode *inode) 1242 - { 1243 - int cnt; 1244 - 1245 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1246 - if (inode->i_dquot[cnt] != NODQUOT) { 1247 - dqput(inode->i_dquot[cnt]); 1248 - inode->i_dquot[cnt] = NODQUOT; 1249 - } 1250 - } 1251 - return 0; 1252 - } 1253 - 1254 1257 int dquot_drop(struct inode *inode) 1255 1258 { 1259 + int cnt; 1260 + struct dquot *put[MAXQUOTAS]; 1261 + 1256 1262 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1257 - dquot_drop_locked(inode); 1263 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1264 + put[cnt] = inode->i_dquot[cnt]; 1265 + inode->i_dquot[cnt] = NODQUOT; 1266 + } 1258 1267 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1268 + 1269 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1270 + dqput(put[cnt]); 1259 1271 return 0; 1260 1272 } 1261 1273 ··· 1484 1470 qsize_t space; 1485 1471 struct dquot *transfer_from[MAXQUOTAS]; 1486 1472 struct dquot *transfer_to[MAXQUOTAS]; 1487 - int cnt, ret = NO_QUOTA, chuid = (iattr->ia_valid & ATTR_UID) && inode->i_uid != iattr->ia_uid, 1488 - chgid = (iattr->ia_valid & ATTR_GID) && inode->i_gid != iattr->ia_gid; 1473 + int cnt, ret = QUOTA_OK; 1474 + int chuid = iattr->ia_valid & ATTR_UID && inode->i_uid != iattr->ia_uid, 1475 + chgid = iattr->ia_valid & ATTR_GID && inode->i_gid != iattr->ia_gid; 1489 1476 char warntype_to[MAXQUOTAS]; 1490 1477 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS]; 1491 1478 ··· 1494 1479 * re-enter the quota code and are already holding the mutex */ 1495 1480 if (IS_NOQUOTA(inode)) 1496 1481 return QUOTA_OK; 1497 - /* Clear the arrays */ 1482 + /* Initialize the arrays */ 1498 1483 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1499 - transfer_to[cnt] = transfer_from[cnt] = NODQUOT; 1484 + transfer_from[cnt] = NODQUOT; 1485 + transfer_to[cnt] = NODQUOT; 1500 1486 warntype_to[cnt] = QUOTA_NL_NOWARN; 1501 - } 1502 - down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1503 - /* Now recheck reliably when holding dqptr_sem */ 1504 - if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ 1505 - up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1506 - return QUOTA_OK; 1507 - } 1508 - /* First build the transfer_to list - here we can block on 1509 - * reading/instantiating of dquots. We know that the transaction for 1510 - * us was already started so we don't violate lock ranking here */ 1511 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1512 1487 switch (cnt) { 1513 1488 case USRQUOTA: 1514 1489 if (!chuid) ··· 1512 1507 break; 1513 1508 } 1514 1509 } 1510 + 1511 + down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1512 + /* Now recheck reliably when holding dqptr_sem */ 1513 + if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ 1514 + up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1515 + goto put_all; 1516 + } 1515 1517 spin_lock(&dq_data_lock); 1516 1518 space = inode_get_bytes(inode); 1517 1519 /* Build the transfer_from list and check the limits */ ··· 1529 1517 if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) == 1530 1518 NO_QUOTA || check_bdq(transfer_to[cnt], space, 0, 1531 1519 warntype_to + cnt) == NO_QUOTA) 1532 - goto warn_put_all; 1520 + goto over_quota; 1533 1521 } 1534 1522 1535 1523 /* ··· 1557 1545 1558 1546 inode->i_dquot[cnt] = transfer_to[cnt]; 1559 1547 } 1560 - ret = QUOTA_OK; 1561 - warn_put_all: 1562 1548 spin_unlock(&dq_data_lock); 1549 + up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1550 + 1563 1551 /* Dirtify all the dquots - this can block when journalling */ 1564 1552 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1565 1553 if (transfer_from[cnt]) 1566 1554 mark_dquot_dirty(transfer_from[cnt]); 1567 - if (transfer_to[cnt]) 1555 + if (transfer_to[cnt]) { 1568 1556 mark_dquot_dirty(transfer_to[cnt]); 1557 + /* The reference we got is transferred to the inode */ 1558 + transfer_to[cnt] = NODQUOT; 1559 + } 1569 1560 } 1561 + warn_put_all: 1570 1562 flush_warnings(transfer_to, warntype_to); 1571 1563 flush_warnings(transfer_from, warntype_from_inodes); 1572 1564 flush_warnings(transfer_from, warntype_from_space); 1573 - 1565 + put_all: 1574 1566 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1575 - if (ret == QUOTA_OK && transfer_from[cnt] != NODQUOT) 1576 - dqput(transfer_from[cnt]); 1577 - if (ret == NO_QUOTA && transfer_to[cnt] != NODQUOT) 1578 - dqput(transfer_to[cnt]); 1567 + dqput(transfer_from[cnt]); 1568 + dqput(transfer_to[cnt]); 1579 1569 } 1580 - up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1581 1570 return ret; 1571 + over_quota: 1572 + spin_unlock(&dq_data_lock); 1573 + up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1574 + /* Clear dquot pointers we don't want to dqput() */ 1575 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1576 + transfer_from[cnt] = NODQUOT; 1577 + ret = NO_QUOTA; 1578 + goto warn_put_all; 1582 1579 } 1583 1580 1584 1581 /* Wrapper for transferring ownership of an inode */ ··· 1672 1651 continue; 1673 1652 1674 1653 if (flags & DQUOT_SUSPENDED) { 1654 + spin_lock(&dq_state_lock); 1675 1655 dqopt->flags |= 1676 1656 dquot_state_flag(DQUOT_SUSPENDED, cnt); 1657 + spin_unlock(&dq_state_lock); 1677 1658 } else { 1659 + spin_lock(&dq_state_lock); 1678 1660 dqopt->flags &= ~dquot_state_flag(flags, cnt); 1679 1661 /* Turning off suspended quotas? */ 1680 1662 if (!sb_has_quota_loaded(sb, cnt) && 1681 1663 sb_has_quota_suspended(sb, cnt)) { 1682 1664 dqopt->flags &= ~dquot_state_flag( 1683 1665 DQUOT_SUSPENDED, cnt); 1666 + spin_unlock(&dq_state_lock); 1684 1667 iput(dqopt->files[cnt]); 1685 1668 dqopt->files[cnt] = NULL; 1686 1669 continue; 1687 1670 } 1671 + spin_unlock(&dq_state_lock); 1688 1672 } 1689 1673 1690 1674 /* We still have to keep quota loaded? */ ··· 1856 1830 } 1857 1831 mutex_unlock(&dqopt->dqio_mutex); 1858 1832 mutex_unlock(&inode->i_mutex); 1833 + spin_lock(&dq_state_lock); 1859 1834 dqopt->flags |= dquot_state_flag(flags, type); 1835 + spin_unlock(&dq_state_lock); 1860 1836 1861 1837 add_dquot_ref(sb, type); 1862 1838 mutex_unlock(&dqopt->dqonoff_mutex); ··· 1900 1872 } 1901 1873 inode = dqopt->files[type]; 1902 1874 dqopt->files[type] = NULL; 1875 + spin_lock(&dq_state_lock); 1903 1876 flags = dqopt->flags & dquot_state_flag(DQUOT_USAGE_ENABLED | 1904 1877 DQUOT_LIMITS_ENABLED, type); 1905 1878 dqopt->flags &= ~dquot_state_flag(DQUOT_STATE_FLAGS, type); 1879 + spin_unlock(&dq_state_lock); 1906 1880 mutex_unlock(&dqopt->dqonoff_mutex); 1907 1881 1908 1882 flags = dquot_generic_flag(flags, type); ··· 1982 1952 ret = -EBUSY; 1983 1953 goto out_lock; 1984 1954 } 1955 + spin_lock(&dq_state_lock); 1985 1956 sb_dqopt(sb)->flags |= dquot_state_flag(flags, type); 1957 + spin_unlock(&dq_state_lock); 1986 1958 out_lock: 1987 1959 mutex_unlock(&dqopt->dqonoff_mutex); 1988 1960 return ret; ··· 2071 2039 { 2072 2040 struct dquot *dquot; 2073 2041 2074 - mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); 2075 - if (!(dquot = dqget(sb, id, type))) { 2076 - mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); 2042 + dquot = dqget(sb, id, type); 2043 + if (dquot == NODQUOT) 2077 2044 return -ESRCH; 2078 - } 2079 2045 do_get_dqblk(dquot, di); 2080 2046 dqput(dquot); 2081 - mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); 2047 + 2082 2048 return 0; 2083 2049 } 2084 2050 ··· 2160 2130 struct dquot *dquot; 2161 2131 int rc; 2162 2132 2163 - mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); 2164 2133 dquot = dqget(sb, id, type); 2165 2134 if (!dquot) { 2166 2135 rc = -ESRCH; ··· 2168 2139 rc = do_set_dqblk(dquot, di); 2169 2140 dqput(dquot); 2170 2141 out: 2171 - mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); 2172 2142 return rc; 2173 2143 } 2174 2144 ··· 2398 2370 EXPORT_SYMBOL(dquot_mark_dquot_dirty); 2399 2371 EXPORT_SYMBOL(dquot_initialize); 2400 2372 EXPORT_SYMBOL(dquot_drop); 2401 - EXPORT_SYMBOL(dquot_drop_locked); 2402 2373 EXPORT_SYMBOL(vfs_dq_drop); 2403 2374 EXPORT_SYMBOL(dqget); 2404 2375 EXPORT_SYMBOL(dqput); 2405 - EXPORT_SYMBOL(dquot_is_cached); 2406 2376 EXPORT_SYMBOL(dquot_alloc_space); 2407 2377 EXPORT_SYMBOL(dquot_alloc_inode); 2408 2378 EXPORT_SYMBOL(dquot_free_space);
+2 -167
fs/ocfs2/quota_global.c
··· 810 810 return status; 811 811 } 812 812 813 - /* This is difficult. We have to lock quota inode and start transaction 814 - * in this function but we don't want to take the penalty of exlusive 815 - * quota file lock when we are just going to use cached structures. So 816 - * we just take read lock check whether we have dquot cached and if so, 817 - * we don't have to take the write lock... */ 818 - static int ocfs2_dquot_initialize(struct inode *inode, int type) 819 - { 820 - handle_t *handle = NULL; 821 - int status = 0; 822 - struct super_block *sb = inode->i_sb; 823 - struct ocfs2_mem_dqinfo *oinfo; 824 - int exclusive = 0; 825 - int cnt; 826 - qid_t id; 827 - 828 - mlog_entry_void(); 829 - 830 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 831 - if (type != -1 && cnt != type) 832 - continue; 833 - if (!sb_has_quota_active(sb, cnt)) 834 - continue; 835 - oinfo = sb_dqinfo(sb, cnt)->dqi_priv; 836 - status = ocfs2_lock_global_qf(oinfo, 0); 837 - if (status < 0) 838 - goto out; 839 - /* This is just a performance optimization not a reliable test. 840 - * Since we hold an inode lock, noone can actually release 841 - * the structure until we are finished with initialization. */ 842 - if (inode->i_dquot[cnt] != NODQUOT) { 843 - ocfs2_unlock_global_qf(oinfo, 0); 844 - continue; 845 - } 846 - /* When we have inode lock, we know that no dquot_release() can 847 - * run and thus we can safely check whether we need to 848 - * read+modify global file to get quota information or whether 849 - * our node already has it. */ 850 - if (cnt == USRQUOTA) 851 - id = inode->i_uid; 852 - else if (cnt == GRPQUOTA) 853 - id = inode->i_gid; 854 - else 855 - BUG(); 856 - /* Obtain exclusion from quota off... */ 857 - down_write(&sb_dqopt(sb)->dqptr_sem); 858 - exclusive = !dquot_is_cached(sb, id, cnt); 859 - up_write(&sb_dqopt(sb)->dqptr_sem); 860 - if (exclusive) { 861 - status = ocfs2_lock_global_qf(oinfo, 1); 862 - if (status < 0) { 863 - exclusive = 0; 864 - mlog_errno(status); 865 - goto out_ilock; 866 - } 867 - handle = ocfs2_start_trans(OCFS2_SB(sb), 868 - ocfs2_calc_qinit_credits(sb, cnt)); 869 - if (IS_ERR(handle)) { 870 - status = PTR_ERR(handle); 871 - mlog_errno(status); 872 - goto out_ilock; 873 - } 874 - } 875 - dquot_initialize(inode, cnt); 876 - if (exclusive) { 877 - ocfs2_commit_trans(OCFS2_SB(sb), handle); 878 - ocfs2_unlock_global_qf(oinfo, 1); 879 - } 880 - ocfs2_unlock_global_qf(oinfo, 0); 881 - } 882 - mlog_exit(0); 883 - return 0; 884 - out_ilock: 885 - if (exclusive) 886 - ocfs2_unlock_global_qf(oinfo, 1); 887 - ocfs2_unlock_global_qf(oinfo, 0); 888 - out: 889 - mlog_exit(status); 890 - return status; 891 - } 892 - 893 - static int ocfs2_dquot_drop_slow(struct inode *inode) 894 - { 895 - int status = 0; 896 - int cnt; 897 - int got_lock[MAXQUOTAS] = {0, 0}; 898 - handle_t *handle; 899 - struct super_block *sb = inode->i_sb; 900 - struct ocfs2_mem_dqinfo *oinfo; 901 - 902 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 903 - if (!sb_has_quota_active(sb, cnt)) 904 - continue; 905 - oinfo = sb_dqinfo(sb, cnt)->dqi_priv; 906 - status = ocfs2_lock_global_qf(oinfo, 1); 907 - if (status < 0) 908 - goto out; 909 - got_lock[cnt] = 1; 910 - } 911 - handle = ocfs2_start_trans(OCFS2_SB(sb), 912 - ocfs2_calc_qinit_credits(sb, USRQUOTA) + 913 - ocfs2_calc_qinit_credits(sb, GRPQUOTA)); 914 - if (IS_ERR(handle)) { 915 - status = PTR_ERR(handle); 916 - mlog_errno(status); 917 - goto out; 918 - } 919 - dquot_drop(inode); 920 - ocfs2_commit_trans(OCFS2_SB(sb), handle); 921 - out: 922 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 923 - if (got_lock[cnt]) { 924 - oinfo = sb_dqinfo(sb, cnt)->dqi_priv; 925 - ocfs2_unlock_global_qf(oinfo, 1); 926 - } 927 - return status; 928 - } 929 - 930 - /* See the comment before ocfs2_dquot_initialize. */ 931 - static int ocfs2_dquot_drop(struct inode *inode) 932 - { 933 - int status = 0; 934 - struct super_block *sb = inode->i_sb; 935 - struct ocfs2_mem_dqinfo *oinfo; 936 - int exclusive = 0; 937 - int cnt; 938 - int got_lock[MAXQUOTAS] = {0, 0}; 939 - 940 - mlog_entry_void(); 941 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 942 - if (!sb_has_quota_active(sb, cnt)) 943 - continue; 944 - oinfo = sb_dqinfo(sb, cnt)->dqi_priv; 945 - status = ocfs2_lock_global_qf(oinfo, 0); 946 - if (status < 0) 947 - goto out; 948 - got_lock[cnt] = 1; 949 - } 950 - /* Lock against anyone releasing references so that when when we check 951 - * we know we are not going to be last ones to release dquot */ 952 - down_write(&sb_dqopt(sb)->dqptr_sem); 953 - /* Urgh, this is a terrible hack :( */ 954 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 955 - if (inode->i_dquot[cnt] != NODQUOT && 956 - atomic_read(&inode->i_dquot[cnt]->dq_count) > 1) { 957 - exclusive = 1; 958 - break; 959 - } 960 - } 961 - if (!exclusive) 962 - dquot_drop_locked(inode); 963 - up_write(&sb_dqopt(sb)->dqptr_sem); 964 - out: 965 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 966 - if (got_lock[cnt]) { 967 - oinfo = sb_dqinfo(sb, cnt)->dqi_priv; 968 - ocfs2_unlock_global_qf(oinfo, 0); 969 - } 970 - /* In case we bailed out because we had to do expensive locking 971 - * do it now... */ 972 - if (exclusive) 973 - status = ocfs2_dquot_drop_slow(inode); 974 - mlog_exit(status); 975 - return status; 976 - } 977 - 978 813 static struct dquot *ocfs2_alloc_dquot(struct super_block *sb, int type) 979 814 { 980 815 struct ocfs2_dquot *dquot = ··· 826 991 } 827 992 828 993 struct dquot_operations ocfs2_quota_operations = { 829 - .initialize = ocfs2_dquot_initialize, 830 - .drop = ocfs2_dquot_drop, 994 + .initialize = dquot_initialize, 995 + .drop = dquot_drop, 831 996 .alloc_space = dquot_alloc_space, 832 997 .alloc_inode = dquot_alloc_inode, 833 998 .free_space = dquot_free_space,
-2
include/linux/quotaops.h
··· 24 24 25 25 int dquot_initialize(struct inode *inode, int type); 26 26 int dquot_drop(struct inode *inode); 27 - int dquot_drop_locked(struct inode *inode); 28 27 struct dquot *dqget(struct super_block *sb, unsigned int id, int type); 29 28 void dqput(struct dquot *dquot); 30 - int dquot_is_cached(struct super_block *sb, unsigned int id, int type); 31 29 int dquot_scan_active(struct super_block *sb, 32 30 int (*fn)(struct dquot *dquot, unsigned long priv), 33 31 unsigned long priv);