aboutsummaryrefslogtreecommitdiffstats
path: root/fs/quota
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-28 13:00:14 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-28 13:00:14 -0400
commit9a7259d5c8978bbeb5fdcf64b168f8470d8208a6 (patch)
tree5c255d4b18622de06c2637c0c4069a384e99466d /fs/quota
parente9c0f1529c9022afbab16a442382aa9a84a79c41 (diff)
parente703c206135acb458adb705ec44bcc5d2615b37d (diff)
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull ext3, UDF, and quota fixes from Jan Kara: "A couple of ext3 & UDF fixes and also one improvement in quota locking." * 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: ext3: fix start and len arguments handling in ext3_trim_fs() udf: Fix deadlock in udf_release_file() udf: Fix file entry logicalBlocksRecorded udf: Fix handling of i_blocks quota: Make quota code not call tty layer with dqptr_sem held udf: Init/maintain file entry checkpoint field ext3: Update ctime in ext3_splice_branch() only when needed ext3: Don't call dquot_free_block() if we don't update anything udf: Remove unnecessary OOM messages
Diffstat (limited to 'fs/quota')
-rw-r--r--fs/quota/dquot.c189
1 files changed, 113 insertions, 76 deletions
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 8b4f12b33f5..d69a1d1d7e1 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -1110,6 +1110,13 @@ static void dquot_decr_space(struct dquot *dquot, qsize_t number)
1110 clear_bit(DQ_BLKS_B, &dquot->dq_flags); 1110 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
1111} 1111}
1112 1112
1113struct dquot_warn {
1114 struct super_block *w_sb;
1115 qid_t w_dq_id;
1116 short w_dq_type;
1117 short w_type;
1118};
1119
1113static int warning_issued(struct dquot *dquot, const int warntype) 1120static int warning_issued(struct dquot *dquot, const int warntype)
1114{ 1121{
1115 int flag = (warntype == QUOTA_NL_BHARDWARN || 1122 int flag = (warntype == QUOTA_NL_BHARDWARN ||
@@ -1125,41 +1132,42 @@ static int warning_issued(struct dquot *dquot, const int warntype)
1125#ifdef CONFIG_PRINT_QUOTA_WARNING 1132#ifdef CONFIG_PRINT_QUOTA_WARNING
1126static int flag_print_warnings = 1; 1133static int flag_print_warnings = 1;
1127 1134
1128static int need_print_warning(struct dquot *dquot) 1135static int need_print_warning(struct dquot_warn *warn)
1129{ 1136{
1130 if (!flag_print_warnings) 1137 if (!flag_print_warnings)
1131 return 0; 1138 return 0;
1132 1139
1133 switch (dquot->dq_type) { 1140 switch (warn->w_dq_type) {
1134 case USRQUOTA: 1141 case USRQUOTA:
1135 return current_fsuid() == dquot->dq_id; 1142 return current_fsuid() == warn->w_dq_id;
1136 case GRPQUOTA: 1143 case GRPQUOTA:
1137 return in_group_p(dquot->dq_id); 1144 return in_group_p(warn->w_dq_id);
1138 } 1145 }
1139 return 0; 1146 return 0;
1140} 1147}
1141 1148
1142/* Print warning to user which exceeded quota */ 1149/* Print warning to user which exceeded quota */
1143static void print_warning(struct dquot *dquot, const int warntype) 1150static void print_warning(struct dquot_warn *warn)
1144{ 1151{
1145 char *msg = NULL; 1152 char *msg = NULL;
1146 struct tty_struct *tty; 1153 struct tty_struct *tty;
1154 int warntype = warn->w_type;
1147 1155
1148 if (warntype == QUOTA_NL_IHARDBELOW || 1156 if (warntype == QUOTA_NL_IHARDBELOW ||
1149 warntype == QUOTA_NL_ISOFTBELOW || 1157 warntype == QUOTA_NL_ISOFTBELOW ||
1150 warntype == QUOTA_NL_BHARDBELOW || 1158 warntype == QUOTA_NL_BHARDBELOW ||
1151 warntype == QUOTA_NL_BSOFTBELOW || !need_print_warning(dquot)) 1159 warntype == QUOTA_NL_BSOFTBELOW || !need_print_warning(warn))
1152 return; 1160 return;
1153 1161
1154 tty = get_current_tty(); 1162 tty = get_current_tty();
1155 if (!tty) 1163 if (!tty)
1156 return; 1164 return;
1157 tty_write_message(tty, dquot->dq_sb->s_id); 1165 tty_write_message(tty, warn->w_sb->s_id);
1158 if (warntype == QUOTA_NL_ISOFTWARN || warntype == QUOTA_NL_BSOFTWARN) 1166 if (warntype == QUOTA_NL_ISOFTWARN || warntype == QUOTA_NL_BSOFTWARN)
1159 tty_write_message(tty, ": warning, "); 1167 tty_write_message(tty, ": warning, ");
1160 else 1168 else
1161 tty_write_message(tty, ": write failed, "); 1169 tty_write_message(tty, ": write failed, ");
1162 tty_write_message(tty, quotatypes[dquot->dq_type]); 1170 tty_write_message(tty, quotatypes[warn->w_dq_type]);
1163 switch (warntype) { 1171 switch (warntype) {
1164 case QUOTA_NL_IHARDWARN: 1172 case QUOTA_NL_IHARDWARN:
1165 msg = " file limit reached.\r\n"; 1173 msg = " file limit reached.\r\n";
@@ -1185,26 +1193,34 @@ static void print_warning(struct dquot *dquot, const int warntype)
1185} 1193}
1186#endif 1194#endif
1187 1195
1196static void prepare_warning(struct dquot_warn *warn, struct dquot *dquot,
1197 int warntype)
1198{
1199 if (warning_issued(dquot, warntype))
1200 return;
1201 warn->w_type = warntype;
1202 warn->w_sb = dquot->dq_sb;
1203 warn->w_dq_id = dquot->dq_id;
1204 warn->w_dq_type = dquot->dq_type;
1205}
1206
1188/* 1207/*
1189 * Write warnings to the console and send warning messages over netlink. 1208 * Write warnings to the console and send warning messages over netlink.
1190 * 1209 *
1191 * Note that this function can sleep. 1210 * Note that this function can call into tty and networking code.
1192 */ 1211 */
1193static void flush_warnings(struct dquot *const *dquots, char *warntype) 1212static void flush_warnings(struct dquot_warn *warn)
1194{ 1213{
1195 struct dquot *dq;
1196 int i; 1214 int i;
1197 1215
1198 for (i = 0; i < MAXQUOTAS; i++) { 1216 for (i = 0; i < MAXQUOTAS; i++) {
1199 dq = dquots[i]; 1217 if (warn[i].w_type == QUOTA_NL_NOWARN)
1200 if (dq && warntype[i] != QUOTA_NL_NOWARN && 1218 continue;
1201 !warning_issued(dq, warntype[i])) {
1202#ifdef CONFIG_PRINT_QUOTA_WARNING 1219#ifdef CONFIG_PRINT_QUOTA_WARNING
1203 print_warning(dq, warntype[i]); 1220 print_warning(&warn[i]);
1204#endif 1221#endif
1205 quota_send_warning(dq->dq_type, dq->dq_id, 1222 quota_send_warning(warn[i].w_dq_type, warn[i].w_dq_id,
1206 dq->dq_sb->s_dev, warntype[i]); 1223 warn[i].w_sb->s_dev, warn[i].w_type);
1207 }
1208 } 1224 }
1209} 1225}
1210 1226
@@ -1218,11 +1234,11 @@ static int ignore_hardlimit(struct dquot *dquot)
1218} 1234}
1219 1235
1220/* needs dq_data_lock */ 1236/* needs dq_data_lock */
1221static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype) 1237static int check_idq(struct dquot *dquot, qsize_t inodes,
1238 struct dquot_warn *warn)
1222{ 1239{
1223 qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes; 1240 qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes;
1224 1241
1225 *warntype = QUOTA_NL_NOWARN;
1226 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) || 1242 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
1227 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1243 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1228 return 0; 1244 return 0;
@@ -1230,7 +1246,7 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1230 if (dquot->dq_dqb.dqb_ihardlimit && 1246 if (dquot->dq_dqb.dqb_ihardlimit &&
1231 newinodes > dquot->dq_dqb.dqb_ihardlimit && 1247 newinodes > dquot->dq_dqb.dqb_ihardlimit &&
1232 !ignore_hardlimit(dquot)) { 1248 !ignore_hardlimit(dquot)) {
1233 *warntype = QUOTA_NL_IHARDWARN; 1249 prepare_warning(warn, dquot, QUOTA_NL_IHARDWARN);
1234 return -EDQUOT; 1250 return -EDQUOT;
1235 } 1251 }
1236 1252
@@ -1239,14 +1255,14 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1239 dquot->dq_dqb.dqb_itime && 1255 dquot->dq_dqb.dqb_itime &&
1240 get_seconds() >= dquot->dq_dqb.dqb_itime && 1256 get_seconds() >= dquot->dq_dqb.dqb_itime &&
1241 !ignore_hardlimit(dquot)) { 1257 !ignore_hardlimit(dquot)) {
1242 *warntype = QUOTA_NL_ISOFTLONGWARN; 1258 prepare_warning(warn, dquot, QUOTA_NL_ISOFTLONGWARN);
1243 return -EDQUOT; 1259 return -EDQUOT;
1244 } 1260 }
1245 1261
1246 if (dquot->dq_dqb.dqb_isoftlimit && 1262 if (dquot->dq_dqb.dqb_isoftlimit &&
1247 newinodes > dquot->dq_dqb.dqb_isoftlimit && 1263 newinodes > dquot->dq_dqb.dqb_isoftlimit &&
1248 dquot->dq_dqb.dqb_itime == 0) { 1264 dquot->dq_dqb.dqb_itime == 0) {
1249 *warntype = QUOTA_NL_ISOFTWARN; 1265 prepare_warning(warn, dquot, QUOTA_NL_ISOFTWARN);
1250 dquot->dq_dqb.dqb_itime = get_seconds() + 1266 dquot->dq_dqb.dqb_itime = get_seconds() +
1251 sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace; 1267 sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1252 } 1268 }
@@ -1255,12 +1271,12 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1255} 1271}
1256 1272
1257/* needs dq_data_lock */ 1273/* needs dq_data_lock */
1258static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype) 1274static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc,
1275 struct dquot_warn *warn)
1259{ 1276{
1260 qsize_t tspace; 1277 qsize_t tspace;
1261 struct super_block *sb = dquot->dq_sb; 1278 struct super_block *sb = dquot->dq_sb;
1262 1279
1263 *warntype = QUOTA_NL_NOWARN;
1264 if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) || 1280 if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) ||
1265 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1281 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1266 return 0; 1282 return 0;
@@ -1272,7 +1288,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1272 tspace > dquot->dq_dqb.dqb_bhardlimit && 1288 tspace > dquot->dq_dqb.dqb_bhardlimit &&
1273 !ignore_hardlimit(dquot)) { 1289 !ignore_hardlimit(dquot)) {
1274 if (!prealloc) 1290 if (!prealloc)
1275 *warntype = QUOTA_NL_BHARDWARN; 1291 prepare_warning(warn, dquot, QUOTA_NL_BHARDWARN);
1276 return -EDQUOT; 1292 return -EDQUOT;
1277 } 1293 }
1278 1294
@@ -1282,7 +1298,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1282 get_seconds() >= dquot->dq_dqb.dqb_btime && 1298 get_seconds() >= dquot->dq_dqb.dqb_btime &&
1283 !ignore_hardlimit(dquot)) { 1299 !ignore_hardlimit(dquot)) {
1284 if (!prealloc) 1300 if (!prealloc)
1285 *warntype = QUOTA_NL_BSOFTLONGWARN; 1301 prepare_warning(warn, dquot, QUOTA_NL_BSOFTLONGWARN);
1286 return -EDQUOT; 1302 return -EDQUOT;
1287 } 1303 }
1288 1304
@@ -1290,7 +1306,7 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1290 tspace > dquot->dq_dqb.dqb_bsoftlimit && 1306 tspace > dquot->dq_dqb.dqb_bsoftlimit &&
1291 dquot->dq_dqb.dqb_btime == 0) { 1307 dquot->dq_dqb.dqb_btime == 0) {
1292 if (!prealloc) { 1308 if (!prealloc) {
1293 *warntype = QUOTA_NL_BSOFTWARN; 1309 prepare_warning(warn, dquot, QUOTA_NL_BSOFTWARN);
1294 dquot->dq_dqb.dqb_btime = get_seconds() + 1310 dquot->dq_dqb.dqb_btime = get_seconds() +
1295 sb_dqopt(sb)->info[dquot->dq_type].dqi_bgrace; 1311 sb_dqopt(sb)->info[dquot->dq_type].dqi_bgrace;
1296 } 1312 }
@@ -1543,10 +1559,9 @@ static void inode_decr_space(struct inode *inode, qsize_t number, int reserve)
1543int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags) 1559int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags)
1544{ 1560{
1545 int cnt, ret = 0; 1561 int cnt, ret = 0;
1546 char warntype[MAXQUOTAS]; 1562 struct dquot_warn warn[MAXQUOTAS];
1547 int warn = flags & DQUOT_SPACE_WARN; 1563 struct dquot **dquots = inode->i_dquot;
1548 int reserve = flags & DQUOT_SPACE_RESERVE; 1564 int reserve = flags & DQUOT_SPACE_RESERVE;
1549 int nofail = flags & DQUOT_SPACE_NOFAIL;
1550 1565
1551 /* 1566 /*
1552 * First test before acquiring mutex - solves deadlocks when we 1567 * First test before acquiring mutex - solves deadlocks when we
@@ -1559,36 +1574,36 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags)
1559 1574
1560 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1575 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1561 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1576 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1562 warntype[cnt] = QUOTA_NL_NOWARN; 1577 warn[cnt].w_type = QUOTA_NL_NOWARN;
1563 1578
1564 spin_lock(&dq_data_lock); 1579 spin_lock(&dq_data_lock);
1565 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1580 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1566 if (!inode->i_dquot[cnt]) 1581 if (!dquots[cnt])
1567 continue; 1582 continue;
1568 ret = check_bdq(inode->i_dquot[cnt], number, !warn, 1583 ret = check_bdq(dquots[cnt], number,
1569 warntype+cnt); 1584 !(flags & DQUOT_SPACE_WARN), &warn[cnt]);
1570 if (ret && !nofail) { 1585 if (ret && !(flags & DQUOT_SPACE_NOFAIL)) {
1571 spin_unlock(&dq_data_lock); 1586 spin_unlock(&dq_data_lock);
1572 goto out_flush_warn; 1587 goto out_flush_warn;
1573 } 1588 }
1574 } 1589 }
1575 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1590 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1576 if (!inode->i_dquot[cnt]) 1591 if (!dquots[cnt])
1577 continue; 1592 continue;
1578 if (reserve) 1593 if (reserve)
1579 dquot_resv_space(inode->i_dquot[cnt], number); 1594 dquot_resv_space(dquots[cnt], number);
1580 else 1595 else
1581 dquot_incr_space(inode->i_dquot[cnt], number); 1596 dquot_incr_space(dquots[cnt], number);
1582 } 1597 }
1583 inode_incr_space(inode, number, reserve); 1598 inode_incr_space(inode, number, reserve);
1584 spin_unlock(&dq_data_lock); 1599 spin_unlock(&dq_data_lock);
1585 1600
1586 if (reserve) 1601 if (reserve)
1587 goto out_flush_warn; 1602 goto out_flush_warn;
1588 mark_all_dquot_dirty(inode->i_dquot); 1603 mark_all_dquot_dirty(dquots);
1589out_flush_warn: 1604out_flush_warn:
1590 flush_warnings(inode->i_dquot, warntype);
1591 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1605 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1606 flush_warnings(warn);
1592out: 1607out:
1593 return ret; 1608 return ret;
1594} 1609}
@@ -1600,36 +1615,37 @@ EXPORT_SYMBOL(__dquot_alloc_space);
1600int dquot_alloc_inode(const struct inode *inode) 1615int dquot_alloc_inode(const struct inode *inode)
1601{ 1616{
1602 int cnt, ret = 0; 1617 int cnt, ret = 0;
1603 char warntype[MAXQUOTAS]; 1618 struct dquot_warn warn[MAXQUOTAS];
1619 struct dquot * const *dquots = inode->i_dquot;
1604 1620
1605 /* First test before acquiring mutex - solves deadlocks when we 1621 /* First test before acquiring mutex - solves deadlocks when we
1606 * re-enter the quota code and are already holding the mutex */ 1622 * re-enter the quota code and are already holding the mutex */
1607 if (!dquot_active(inode)) 1623 if (!dquot_active(inode))
1608 return 0; 1624 return 0;
1609 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1625 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1610 warntype[cnt] = QUOTA_NL_NOWARN; 1626 warn[cnt].w_type = QUOTA_NL_NOWARN;
1611 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1627 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1612 spin_lock(&dq_data_lock); 1628 spin_lock(&dq_data_lock);
1613 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1629 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1614 if (!inode->i_dquot[cnt]) 1630 if (!dquots[cnt])
1615 continue; 1631 continue;
1616 ret = check_idq(inode->i_dquot[cnt], 1, warntype + cnt); 1632 ret = check_idq(dquots[cnt], 1, &warn[cnt]);
1617 if (ret) 1633 if (ret)
1618 goto warn_put_all; 1634 goto warn_put_all;
1619 } 1635 }
1620 1636
1621 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1637 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1622 if (!inode->i_dquot[cnt]) 1638 if (!dquots[cnt])
1623 continue; 1639 continue;
1624 dquot_incr_inodes(inode->i_dquot[cnt], 1); 1640 dquot_incr_inodes(dquots[cnt], 1);
1625 } 1641 }
1626 1642
1627warn_put_all: 1643warn_put_all:
1628 spin_unlock(&dq_data_lock); 1644 spin_unlock(&dq_data_lock);
1629 if (ret == 0) 1645 if (ret == 0)
1630 mark_all_dquot_dirty(inode->i_dquot); 1646 mark_all_dquot_dirty(dquots);
1631 flush_warnings(inode->i_dquot, warntype);
1632 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1647 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1648 flush_warnings(warn);
1633 return ret; 1649 return ret;
1634} 1650}
1635EXPORT_SYMBOL(dquot_alloc_inode); 1651EXPORT_SYMBOL(dquot_alloc_inode);
@@ -1669,7 +1685,8 @@ EXPORT_SYMBOL(dquot_claim_space_nodirty);
1669void __dquot_free_space(struct inode *inode, qsize_t number, int flags) 1685void __dquot_free_space(struct inode *inode, qsize_t number, int flags)
1670{ 1686{
1671 unsigned int cnt; 1687 unsigned int cnt;
1672 char warntype[MAXQUOTAS]; 1688 struct dquot_warn warn[MAXQUOTAS];
1689 struct dquot **dquots = inode->i_dquot;
1673 int reserve = flags & DQUOT_SPACE_RESERVE; 1690 int reserve = flags & DQUOT_SPACE_RESERVE;
1674 1691
1675 /* First test before acquiring mutex - solves deadlocks when we 1692 /* First test before acquiring mutex - solves deadlocks when we
@@ -1682,23 +1699,28 @@ void __dquot_free_space(struct inode *inode, qsize_t number, int flags)
1682 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1699 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1683 spin_lock(&dq_data_lock); 1700 spin_lock(&dq_data_lock);
1684 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1701 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1685 if (!inode->i_dquot[cnt]) 1702 int wtype;
1703
1704 warn[cnt].w_type = QUOTA_NL_NOWARN;
1705 if (!dquots[cnt])
1686 continue; 1706 continue;
1687 warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number); 1707 wtype = info_bdq_free(dquots[cnt], number);
1708 if (wtype != QUOTA_NL_NOWARN)
1709 prepare_warning(&warn[cnt], dquots[cnt], wtype);
1688 if (reserve) 1710 if (reserve)
1689 dquot_free_reserved_space(inode->i_dquot[cnt], number); 1711 dquot_free_reserved_space(dquots[cnt], number);
1690 else 1712 else
1691 dquot_decr_space(inode->i_dquot[cnt], number); 1713 dquot_decr_space(dquots[cnt], number);
1692 } 1714 }
1693 inode_decr_space(inode, number, reserve); 1715 inode_decr_space(inode, number, reserve);
1694 spin_unlock(&dq_data_lock); 1716 spin_unlock(&dq_data_lock);
1695 1717
1696 if (reserve) 1718 if (reserve)
1697 goto out_unlock; 1719 goto out_unlock;
1698 mark_all_dquot_dirty(inode->i_dquot); 1720 mark_all_dquot_dirty(dquots);
1699out_unlock: 1721out_unlock:
1700 flush_warnings(inode->i_dquot, warntype);
1701 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1722 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1723 flush_warnings(warn);
1702} 1724}
1703EXPORT_SYMBOL(__dquot_free_space); 1725EXPORT_SYMBOL(__dquot_free_space);
1704 1726
@@ -1708,7 +1730,8 @@ EXPORT_SYMBOL(__dquot_free_space);
1708void dquot_free_inode(const struct inode *inode) 1730void dquot_free_inode(const struct inode *inode)
1709{ 1731{
1710 unsigned int cnt; 1732 unsigned int cnt;
1711 char warntype[MAXQUOTAS]; 1733 struct dquot_warn warn[MAXQUOTAS];
1734 struct dquot * const *dquots = inode->i_dquot;
1712 1735
1713 /* First test before acquiring mutex - solves deadlocks when we 1736 /* First test before acquiring mutex - solves deadlocks when we
1714 * re-enter the quota code and are already holding the mutex */ 1737 * re-enter the quota code and are already holding the mutex */
@@ -1718,15 +1741,20 @@ void dquot_free_inode(const struct inode *inode)
1718 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1741 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1719 spin_lock(&dq_data_lock); 1742 spin_lock(&dq_data_lock);
1720 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1743 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1721 if (!inode->i_dquot[cnt]) 1744 int wtype;
1745
1746 warn[cnt].w_type = QUOTA_NL_NOWARN;
1747 if (!dquots[cnt])
1722 continue; 1748 continue;
1723 warntype[cnt] = info_idq_free(inode->i_dquot[cnt], 1); 1749 wtype = info_idq_free(dquots[cnt], 1);
1724 dquot_decr_inodes(inode->i_dquot[cnt], 1); 1750 if (wtype != QUOTA_NL_NOWARN)
1751 prepare_warning(&warn[cnt], dquots[cnt], wtype);
1752 dquot_decr_inodes(dquots[cnt], 1);
1725 } 1753 }
1726 spin_unlock(&dq_data_lock); 1754 spin_unlock(&dq_data_lock);
1727 mark_all_dquot_dirty(inode->i_dquot); 1755 mark_all_dquot_dirty(dquots);
1728 flush_warnings(inode->i_dquot, warntype);
1729 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1756 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1757 flush_warnings(warn);
1730} 1758}
1731EXPORT_SYMBOL(dquot_free_inode); 1759EXPORT_SYMBOL(dquot_free_inode);
1732 1760
@@ -1747,16 +1775,20 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1747 struct dquot *transfer_from[MAXQUOTAS] = {}; 1775 struct dquot *transfer_from[MAXQUOTAS] = {};
1748 int cnt, ret = 0; 1776 int cnt, ret = 0;
1749 char is_valid[MAXQUOTAS] = {}; 1777 char is_valid[MAXQUOTAS] = {};
1750 char warntype_to[MAXQUOTAS]; 1778 struct dquot_warn warn_to[MAXQUOTAS];
1751 char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS]; 1779 struct dquot_warn warn_from_inodes[MAXQUOTAS];
1780 struct dquot_warn warn_from_space[MAXQUOTAS];
1752 1781
1753 /* First test before acquiring mutex - solves deadlocks when we 1782 /* First test before acquiring mutex - solves deadlocks when we
1754 * re-enter the quota code and are already holding the mutex */ 1783 * re-enter the quota code and are already holding the mutex */
1755 if (IS_NOQUOTA(inode)) 1784 if (IS_NOQUOTA(inode))
1756 return 0; 1785 return 0;
1757 /* Initialize the arrays */ 1786 /* Initialize the arrays */
1758 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1787 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1759 warntype_to[cnt] = QUOTA_NL_NOWARN; 1788 warn_to[cnt].w_type = QUOTA_NL_NOWARN;
1789 warn_from_inodes[cnt].w_type = QUOTA_NL_NOWARN;
1790 warn_from_space[cnt].w_type = QUOTA_NL_NOWARN;
1791 }
1760 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1792 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1761 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */ 1793 if (IS_NOQUOTA(inode)) { /* File without quota accounting? */
1762 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1794 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
@@ -1778,10 +1810,10 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1778 continue; 1810 continue;
1779 is_valid[cnt] = 1; 1811 is_valid[cnt] = 1;
1780 transfer_from[cnt] = inode->i_dquot[cnt]; 1812 transfer_from[cnt] = inode->i_dquot[cnt];
1781 ret = check_idq(transfer_to[cnt], 1, warntype_to + cnt); 1813 ret = check_idq(transfer_to[cnt], 1, &warn_to[cnt]);
1782 if (ret) 1814 if (ret)
1783 goto over_quota; 1815 goto over_quota;
1784 ret = check_bdq(transfer_to[cnt], space, 0, warntype_to + cnt); 1816 ret = check_bdq(transfer_to[cnt], space, 0, &warn_to[cnt]);
1785 if (ret) 1817 if (ret)
1786 goto over_quota; 1818 goto over_quota;
1787 } 1819 }
@@ -1794,10 +1826,15 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1794 continue; 1826 continue;
1795 /* Due to IO error we might not have transfer_from[] structure */ 1827 /* Due to IO error we might not have transfer_from[] structure */
1796 if (transfer_from[cnt]) { 1828 if (transfer_from[cnt]) {
1797 warntype_from_inodes[cnt] = 1829 int wtype;
1798 info_idq_free(transfer_from[cnt], 1); 1830 wtype = info_idq_free(transfer_from[cnt], 1);
1799 warntype_from_space[cnt] = 1831 if (wtype != QUOTA_NL_NOWARN)
1800 info_bdq_free(transfer_from[cnt], space); 1832 prepare_warning(&warn_from_inodes[cnt],
1833 transfer_from[cnt], wtype);
1834 wtype = info_bdq_free(transfer_from[cnt], space);
1835 if (wtype != QUOTA_NL_NOWARN)
1836 prepare_warning(&warn_from_space[cnt],
1837 transfer_from[cnt], wtype);
1801 dquot_decr_inodes(transfer_from[cnt], 1); 1838 dquot_decr_inodes(transfer_from[cnt], 1);
1802 dquot_decr_space(transfer_from[cnt], cur_space); 1839 dquot_decr_space(transfer_from[cnt], cur_space);
1803 dquot_free_reserved_space(transfer_from[cnt], 1840 dquot_free_reserved_space(transfer_from[cnt],
@@ -1815,9 +1852,9 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1815 1852
1816 mark_all_dquot_dirty(transfer_from); 1853 mark_all_dquot_dirty(transfer_from);
1817 mark_all_dquot_dirty(transfer_to); 1854 mark_all_dquot_dirty(transfer_to);
1818 flush_warnings(transfer_to, warntype_to); 1855 flush_warnings(warn_to);
1819 flush_warnings(transfer_from, warntype_from_inodes); 1856 flush_warnings(warn_from_inodes);
1820 flush_warnings(transfer_from, warntype_from_space); 1857 flush_warnings(warn_from_space);
1821 /* Pass back references to put */ 1858 /* Pass back references to put */
1822 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1859 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1823 if (is_valid[cnt]) 1860 if (is_valid[cnt])
@@ -1826,7 +1863,7 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1826over_quota: 1863over_quota:
1827 spin_unlock(&dq_data_lock); 1864 spin_unlock(&dq_data_lock);
1828 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1865 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1829 flush_warnings(transfer_to, warntype_to); 1866 flush_warnings(warn_to);
1830 return ret; 1867 return ret;
1831} 1868}
1832EXPORT_SYMBOL(__dquot_transfer); 1869EXPORT_SYMBOL(__dquot_transfer);