aboutsummaryrefslogtreecommitdiffstats
path: root/fs/quota
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2010-03-03 09:05:00 -0500
committerJan Kara <jack@suse.cz>2010-03-04 18:20:28 -0500
commit5dd4056db84387975140ff2568eaa0406f07985e (patch)
tree03c26d7f6e3367b167bfeeb1a01654c6619573f4 /fs/quota
parent49792c806d0bfd53afc789dcdf50dc9bed2c5b83 (diff)
dquot: cleanup space allocation / freeing routines
Get rid of the alloc_space, free_space, reserve_space, claim_space and release_rsv dquot operations - they are always called from the filesystem and if a filesystem really needs their own (which none currently does) it can just call into it's own routine directly. Move shared logic into the common __dquot_alloc_space, dquot_claim_space_nodirty and __dquot_free_space low-level methods, and rationalize the wrappers around it to move as much as possible code into the common block for CONFIG_QUOTA vs not. Also rename all these helpers to be named dquot_* instead of vfs_dq_*. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/quota')
-rw-r--r--fs/quota/dquot.c79
1 files changed, 26 insertions, 53 deletions
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 10d021dd37c1..baf202c012cc 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -1464,28 +1464,29 @@ static void inode_decr_space(struct inode *inode, qsize_t number, int reserve)
1464} 1464}
1465 1465
1466/* 1466/*
1467 * Following four functions update i_blocks+i_bytes fields and 1467 * This functions updates i_blocks+i_bytes fields and quota information
1468 * quota information (together with appropriate checks) 1468 * (together with appropriate checks).
1469 * NOTE: We absolutely rely on the fact that caller dirties 1469 *
1470 * the inode (usually macros in quotaops.h care about this) and 1470 * NOTE: We absolutely rely on the fact that caller dirties the inode
1471 * holds a handle for the current transaction so that dquot write and 1471 * (usually helpers in quotaops.h care about this) and holds a handle for
1472 * inode write go into the same transaction. 1472 * the current transaction so that dquot write and inode write go into the
1473 * same transaction.
1473 */ 1474 */
1474 1475
1475/* 1476/*
1476 * This operation can block, but only after everything is updated 1477 * This operation can block, but only after everything is updated
1477 */ 1478 */
1478int __dquot_alloc_space(struct inode *inode, qsize_t number, 1479int __dquot_alloc_space(struct inode *inode, qsize_t number,
1479 int warn, int reserve) 1480 int warn, int reserve)
1480{ 1481{
1481 int cnt, ret = QUOTA_OK; 1482 int cnt, ret = 0;
1482 char warntype[MAXQUOTAS]; 1483 char warntype[MAXQUOTAS];
1483 1484
1484 /* 1485 /*
1485 * First test before acquiring mutex - solves deadlocks when we 1486 * First test before acquiring mutex - solves deadlocks when we
1486 * re-enter the quota code and are already holding the mutex 1487 * re-enter the quota code and are already holding the mutex
1487 */ 1488 */
1488 if (IS_NOQUOTA(inode)) { 1489 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode)) {
1489 inode_incr_space(inode, number, reserve); 1490 inode_incr_space(inode, number, reserve);
1490 goto out; 1491 goto out;
1491 } 1492 }
@@ -1498,9 +1499,9 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
1498 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1499 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1499 if (!inode->i_dquot[cnt]) 1500 if (!inode->i_dquot[cnt])
1500 continue; 1501 continue;
1501 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) 1502 if (check_bdq(inode->i_dquot[cnt], number, !warn, warntype+cnt)
1502 == NO_QUOTA) { 1503 == NO_QUOTA) {
1503 ret = NO_QUOTA; 1504 ret = -EDQUOT;
1504 spin_unlock(&dq_data_lock); 1505 spin_unlock(&dq_data_lock);
1505 goto out_flush_warn; 1506 goto out_flush_warn;
1506 } 1507 }
@@ -1525,18 +1526,7 @@ out_flush_warn:
1525out: 1526out:
1526 return ret; 1527 return ret;
1527} 1528}
1528 1529EXPORT_SYMBOL(__dquot_alloc_space);
1529int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
1530{
1531 return __dquot_alloc_space(inode, number, warn, 0);
1532}
1533EXPORT_SYMBOL(dquot_alloc_space);
1534
1535int dquot_reserve_space(struct inode *inode, qsize_t number, int warn)
1536{
1537 return __dquot_alloc_space(inode, number, warn, 1);
1538}
1539EXPORT_SYMBOL(dquot_reserve_space);
1540 1530
1541/* 1531/*
1542 * This operation can block, but only after everything is updated 1532 * This operation can block, but only after everything is updated
@@ -1578,14 +1568,16 @@ warn_put_all:
1578} 1568}
1579EXPORT_SYMBOL(dquot_alloc_inode); 1569EXPORT_SYMBOL(dquot_alloc_inode);
1580 1570
1581int dquot_claim_space(struct inode *inode, qsize_t number) 1571/*
1572 * Convert in-memory reserved quotas to real consumed quotas
1573 */
1574int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
1582{ 1575{
1583 int cnt; 1576 int cnt;
1584 int ret = QUOTA_OK;
1585 1577
1586 if (IS_NOQUOTA(inode)) { 1578 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode)) {
1587 inode_claim_rsv_space(inode, number); 1579 inode_claim_rsv_space(inode, number);
1588 goto out; 1580 return 0;
1589 } 1581 }
1590 1582
1591 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1583 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
@@ -1601,24 +1593,23 @@ int dquot_claim_space(struct inode *inode, qsize_t number)
1601 spin_unlock(&dq_data_lock); 1593 spin_unlock(&dq_data_lock);
1602 mark_all_dquot_dirty(inode->i_dquot); 1594 mark_all_dquot_dirty(inode->i_dquot);
1603 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1595 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1604out: 1596 return 0;
1605 return ret;
1606} 1597}
1607EXPORT_SYMBOL(dquot_claim_space); 1598EXPORT_SYMBOL(dquot_claim_space_nodirty);
1608 1599
1609/* 1600/*
1610 * This operation can block, but only after everything is updated 1601 * This operation can block, but only after everything is updated
1611 */ 1602 */
1612int __dquot_free_space(struct inode *inode, qsize_t number, int reserve) 1603void __dquot_free_space(struct inode *inode, qsize_t number, int reserve)
1613{ 1604{
1614 unsigned int cnt; 1605 unsigned int cnt;
1615 char warntype[MAXQUOTAS]; 1606 char warntype[MAXQUOTAS];
1616 1607
1617 /* First test before acquiring mutex - solves deadlocks when we 1608 /* First test before acquiring mutex - solves deadlocks when we
1618 * re-enter the quota code and are already holding the mutex */ 1609 * re-enter the quota code and are already holding the mutex */
1619 if (IS_NOQUOTA(inode)) { 1610 if (!sb_any_quota_active(inode->i_sb) || IS_NOQUOTA(inode)) {
1620 inode_decr_space(inode, number, reserve); 1611 inode_decr_space(inode, number, reserve);
1621 return QUOTA_OK; 1612 return;
1622 } 1613 }
1623 1614
1624 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1615 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
@@ -1641,24 +1632,8 @@ int __dquot_free_space(struct inode *inode, qsize_t number, int reserve)
1641out_unlock: 1632out_unlock:
1642 flush_warnings(inode->i_dquot, warntype); 1633 flush_warnings(inode->i_dquot, warntype);
1643 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1634 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1644 return QUOTA_OK;
1645}
1646
1647int dquot_free_space(struct inode *inode, qsize_t number)
1648{
1649 return __dquot_free_space(inode, number, 0);
1650}
1651EXPORT_SYMBOL(dquot_free_space);
1652
1653/*
1654 * Release reserved quota space
1655 */
1656void dquot_release_reserved_space(struct inode *inode, qsize_t number)
1657{
1658 __dquot_free_space(inode, number, 1);
1659
1660} 1635}
1661EXPORT_SYMBOL(dquot_release_reserved_space); 1636EXPORT_SYMBOL(__dquot_free_space);
1662 1637
1663/* 1638/*
1664 * This operation can block, but only after everything is updated 1639 * This operation can block, but only after everything is updated
@@ -1840,9 +1815,7 @@ EXPORT_SYMBOL(dquot_commit_info);
1840const struct dquot_operations dquot_operations = { 1815const struct dquot_operations dquot_operations = {
1841 .initialize = dquot_initialize, 1816 .initialize = dquot_initialize,
1842 .drop = dquot_drop, 1817 .drop = dquot_drop,
1843 .alloc_space = dquot_alloc_space,
1844 .alloc_inode = dquot_alloc_inode, 1818 .alloc_inode = dquot_alloc_inode,
1845 .free_space = dquot_free_space,
1846 .free_inode = dquot_free_inode, 1819 .free_inode = dquot_free_inode,
1847 .transfer = dquot_transfer, 1820 .transfer = dquot_transfer,
1848 .write_dquot = dquot_commit, 1821 .write_dquot = dquot_commit,