|
100 | 100 | * |
101 | 101 | * Any operation working on dquots via inode pointers must hold dqptr_sem. If |
102 | 102 | * operation is just reading pointers from inode (or not using them at all) the |
103 | | - * read lock is enough. If pointers are altered function must hold write lock |
104 | | - * (these locking rules also apply for S_NOQUOTA flag in the inode - note that |
105 | | - * for altering the flag i_mutex is also needed). |
| 103 | + * read lock is enough. If pointers are altered function must hold write lock. |
| 104 | + * Special care needs to be taken about S_NOQUOTA inode flag (marking that |
| 105 | + * inode is a quota file). Functions adding pointers from inode to dquots have |
| 106 | + * to check this flag under dqptr_sem and then (if S_NOQUOTA is not set) they |
| 107 | + * have to do all pointer modifications before dropping dqptr_sem. This makes |
| 108 | + * sure they cannot race with quotaon which first sets S_NOQUOTA flag and |
| 109 | + * then drops all pointers to dquots from an inode. |
106 | 110 | * |
107 | 111 | * Each dquot has its dq_lock mutex. Locked dquots might not be referenced |
108 | 112 | * from inodes (dquot_alloc_space() and such don't check the dq_lock). |
@@ -1275,7 +1279,6 @@ int dquot_initialize(struct inode *inode, int type) |
1275 | 1279 | } |
1276 | 1280 |
|
1277 | 1281 | down_write(&sb_dqopt(sb)->dqptr_sem); |
1278 | | - /* Having dqptr_sem we know NOQUOTA flags can't be altered... */ |
1279 | 1282 | if (IS_NOQUOTA(inode)) |
1280 | 1283 | goto out_err; |
1281 | 1284 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
@@ -1431,11 +1434,6 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, |
1431 | 1434 | } |
1432 | 1435 |
|
1433 | 1436 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1434 | | - if (IS_NOQUOTA(inode)) { |
1435 | | - inode_incr_space(inode, number, reserve); |
1436 | | - goto out_unlock; |
1437 | | - } |
1438 | | - |
1439 | 1437 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
1440 | 1438 | warntype[cnt] = QUOTA_NL_NOWARN; |
1441 | 1439 |
|
@@ -1466,7 +1464,6 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, |
1466 | 1464 | mark_all_dquot_dirty(inode->i_dquot); |
1467 | 1465 | out_flush_warn: |
1468 | 1466 | flush_warnings(inode->i_dquot, warntype); |
1469 | | -out_unlock: |
1470 | 1467 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1471 | 1468 | out: |
1472 | 1469 | return ret; |
@@ -1499,10 +1496,6 @@ int dquot_alloc_inode(const struct inode *inode, qsize_t number) |
1499 | 1496 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
1500 | 1497 | warntype[cnt] = QUOTA_NL_NOWARN; |
1501 | 1498 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1502 | | - if (IS_NOQUOTA(inode)) { |
1503 | | - up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1504 | | - return QUOTA_OK; |
1505 | | - } |
1506 | 1499 | spin_lock(&dq_data_lock); |
1507 | 1500 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
1508 | 1501 | if (!inode->i_dquot[cnt]) |
@@ -1539,12 +1532,6 @@ int dquot_claim_space(struct inode *inode, qsize_t number) |
1539 | 1532 | } |
1540 | 1533 |
|
1541 | 1534 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1542 | | - if (IS_NOQUOTA(inode)) { |
1543 | | - up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1544 | | - inode_claim_rsv_space(inode, number); |
1545 | | - goto out; |
1546 | | - } |
1547 | | - |
1548 | 1535 | spin_lock(&dq_data_lock); |
1549 | 1536 | /* Claim reserved quotas to allocated quotas */ |
1550 | 1537 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
@@ -1573,17 +1560,11 @@ int __dquot_free_space(struct inode *inode, qsize_t number, int reserve) |
1573 | 1560 | /* First test before acquiring mutex - solves deadlocks when we |
1574 | 1561 | * re-enter the quota code and are already holding the mutex */ |
1575 | 1562 | if (IS_NOQUOTA(inode)) { |
1576 | | -out_sub: |
1577 | 1563 | inode_decr_space(inode, number, reserve); |
1578 | 1564 | return QUOTA_OK; |
1579 | 1565 | } |
1580 | 1566 |
|
1581 | 1567 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1582 | | - /* Now recheck reliably when holding dqptr_sem */ |
1583 | | - if (IS_NOQUOTA(inode)) { |
1584 | | - up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1585 | | - goto out_sub; |
1586 | | - } |
1587 | 1568 | spin_lock(&dq_data_lock); |
1588 | 1569 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
1589 | 1570 | if (!inode->i_dquot[cnt]) |
@@ -1636,11 +1617,6 @@ int dquot_free_inode(const struct inode *inode, qsize_t number) |
1636 | 1617 | return QUOTA_OK; |
1637 | 1618 |
|
1638 | 1619 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1639 | | - /* Now recheck reliably when holding dqptr_sem */ |
1640 | | - if (IS_NOQUOTA(inode)) { |
1641 | | - up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1642 | | - return QUOTA_OK; |
1643 | | - } |
1644 | 1620 | spin_lock(&dq_data_lock); |
1645 | 1621 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
1646 | 1622 | if (!inode->i_dquot[cnt]) |
@@ -1692,7 +1668,6 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr) |
1692 | 1668 | GRPQUOTA); |
1693 | 1669 |
|
1694 | 1670 | down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1695 | | - /* Now recheck reliably when holding dqptr_sem */ |
1696 | 1671 | if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ |
1697 | 1672 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1698 | 1673 | goto put_all; |
@@ -2010,13 +1985,15 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, |
2010 | 1985 | /* We don't want quota and atime on quota files (deadlocks |
2011 | 1986 | * possible) Also nobody should write to the file - we use |
2012 | 1987 | * special IO operations which ignore the immutable bit. */ |
2013 | | - down_write(&dqopt->dqptr_sem); |
2014 | 1988 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); |
2015 | 1989 | oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | |
2016 | 1990 | S_NOQUOTA); |
2017 | 1991 | inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE; |
2018 | 1992 | mutex_unlock(&inode->i_mutex); |
2019 | | - up_write(&dqopt->dqptr_sem); |
| 1993 | + /* |
| 1994 | + * When S_NOQUOTA is set, remove dquot references as no more |
| 1995 | + * references can be added |
| 1996 | + */ |
2020 | 1997 | sb->dq_op->drop(inode); |
2021 | 1998 | } |
2022 | 1999 |
|
@@ -2053,14 +2030,12 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, |
2053 | 2030 | iput(inode); |
2054 | 2031 | out_lock: |
2055 | 2032 | if (oldflags != -1) { |
2056 | | - down_write(&dqopt->dqptr_sem); |
2057 | 2033 | mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); |
2058 | 2034 | /* Set the flags back (in the case of accidental quotaon() |
2059 | 2035 | * on a wrong file we don't want to mess up the flags) */ |
2060 | 2036 | inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE); |
2061 | 2037 | inode->i_flags |= oldflags; |
2062 | 2038 | mutex_unlock(&inode->i_mutex); |
2063 | | - up_write(&dqopt->dqptr_sem); |
2064 | 2039 | } |
2065 | 2040 | mutex_unlock(&dqopt->dqonoff_mutex); |
2066 | 2041 | out_fmt: |
|
0 commit comments