Skip to contentSkip to conversation

RFC quota: Redesign IO error handling interface

PATCH In review Dmitry Monakhov 2 participants 16 messages Apr 8, 2010 – May 17, 2010

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover RFC quota: Redesign IO error handling interface

This patchset is tended to provide interface for handling IO errors from internal quota code.
Any error must being returned to fs-caller to signal about possible quota inconsistency. I've done it in following way:

1) Handle low-level io errors from dqget() and it's callers
2) Handle errors from dquot_initialize
This path catch most of IO error, but no all.
3) Check what i_dquot was initialized in each low-level function. There are two types of such functions
3A) Charging functions (alloc_{space,inode}): Caller of such
function may easy handle an error and abort an operation.
3B) nofail functions (claim_space,free_{space,inode})
In most cases caller can not abort an operation even if inode's quotas was semi-initialized, so I just skip this functions for now.
I would like to know you ideas suggestions about this.
Note: Only ext4's part was basically tested for now, others was just compile tested.

#1 lore raw

PATCH 1/6 quota: unify quota init condition in setattr

Quota must being initialized if size or uid/git changes requested. But initialization performed in two different places:
in case of i_size file system is responsible for dquot init , but in case of uid/gid init will be called internally in dquot_transfer().
This ambiguity makes code harder to understand.
Let's move this logic to one common helper function.

---
 fs/ext2/inode.c          |    2 +-
 fs/ext3/inode.c          |    2 +-
 fs/ext4/inode.c          |    2 +-
 fs/jfs/file.c            |    2 +-
 fs/ocfs2/file.c          |    4 ++--
 fs/quota/dquot.c         |    5 ++---
 fs/reiserfs/inode.c      |    3 ++-
 fs/udf/file.c            |    2 +-
 fs/ufs/truncate.c        |    8 ++++----
 include/linux/quotaops.h |    8 ++++++++
 10 files changed, 23 insertions(+), 15 deletions(-)
fs/ext2/inode.c +1 -1
index 45ff49f..445f08a 100644
@@ -1460,7 +1460,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (error)
 		return error;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
fs/ext3/inode.c +1 -1
index ffbbc65..0981a27 100644
@@ -3151,7 +3151,7 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
fs/ext4/inode.c +1 -1
index 4a91225..b812655 100644
@@ -5255,7 +5255,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
fs/jfs/file.c +1 -1
index 14ba982..85d9ec6 100644
@@ -98,7 +98,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (rc)
 		return rc;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
fs/ocfs2/file.c +2 -2
index 3641052..b26df86 100644
@@ -978,10 +978,10 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 	if (status)
 		return status;
 
+	if (is_quota_modification(inode, attr))
+		dquot_initialize(inode);
 	size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
 	if (size_change) {
-		dquot_initialize(inode);
-
 		status = ocfs2_rw_lock(inode, 1);
 		if (status < 0) {
 			mlog_errno(status);
fs/quota/dquot.c +2 -3
index 8a2f0cb..a168189 100644
@@ -1801,10 +1801,9 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
 		mask |= 1 << GRPQUOTA;
 		chid[GRPQUOTA] = iattr->ia_gid;
 	}
-	if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) {
-		dquot_initialize(inode);
+	if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
 		return __dquot_transfer(inode, chid, mask);
-	}
+
 	return 0;
 }
 EXPORT_SYMBOL(dquot_transfer);
fs/reiserfs/inode.c +2 -1
index b8671a5..0bf5324 100644
@@ -3075,9 +3075,10 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
 	ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID);
 
 	depth = reiserfs_write_lock_once(inode->i_sb);
-	if (attr->ia_valid & ATTR_SIZE) {
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 
+	if (attr->ia_valid & ATTR_SIZE) {
 		/* version 2 items will be caught by the s_maxbytes check
 		 ** done for us in vmtruncate
 		 */
fs/udf/file.c +1 -1
index 4b6a46c..6ebc043 100644
@@ -227,7 +227,7 @@ int udf_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (error)
 		return error;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
fs/ufs/truncate.c +4 -4
index ee8db3e..f294c44 100644
@@ -518,18 +518,18 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
+	if (is_quota_modification(inode, attr))
+		dquot_initialize(inode);
+
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 	    (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
 		error = dquot_transfer(inode, attr);
 		if (error)
 			return error;
 	}
-	if (ia_valid & ATTR_SIZE &&
-	    attr->ia_size != i_size_read(inode)) {
+	if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
 		loff_t old_i_size = inode->i_size;
 
-		dquot_initialize(inode);
-
 		error = vmtruncate(inode, attr->ia_size);
 		if (error)
 			return error;
include/linux/quotaops.h +8 -0
index e6fa7ac..fd8f70b 100644
@@ -14,6 +14,14 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 	return &sb->s_dquot;
 }
 
+/* i_mutex must being held */
+static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
+{
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+		(ia->ia_valid & ATTR_UID && ia->ia_uid != inode->i_uid) ||
+		(ia->ia_valid & ATTR_GID && ia->ia_gid != inode->i_gid);
+}
+
 #if defined(CONFIG_QUOTA)
 
 /*
Signature · 1 line
1.6.6.1
#2 lore raw

PATCH 2/6 quota: Add proper error handling on quota initialization.

Currently dqget_initialize() is a black-box so IO errors are simply ignored. In order to pass to the caller real error codes quota interface must being redesigned in following way.

- return real error code from dqget()
- return real error code from dquot_initialize()

Now filesystem it is filesystem's responsibility to dquot_initialize() return value.

---
 fs/ocfs2/file.c          |   18 ++++++--
 fs/ocfs2/quota_local.c   |   10 ++--
 fs/quota/dquot.c         |  101 +++++++++++++++++++++++++++++++---------------
 include/linux/quotaops.h |    5 +-
 4 files changed, 90 insertions(+), 44 deletions(-)
fs/ocfs2/file.c +14 -4
index b26df86..3c32f40 100644
@@ -1032,10 +1032,15 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 		    OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
 			transfer_to[USRQUOTA] = dqget(sb, attr->ia_uid,
 						      USRQUOTA);
+			if (IS_ERR(transfer_to[USRQUOTA])) {
+				status = PTR_ERR(transfer_to[USRQUOTA]);
+				goto bail_unlock;
+			}
+
 			transfer_from[USRQUOTA] = dqget(sb, inode->i_uid,
 							USRQUOTA);
-			if (!transfer_to[USRQUOTA] || !transfer_from[USRQUOTA]) {
-				status = -ESRCH;
+			if (IS_ERR(transfer_from[USRQUOTA])) {
+				status = PTR_ERR(transfer_from[USRQUOTA]);
 				goto bail_unlock;
 			}
 		}
@@ -1044,10 +1049,15 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 		    OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
 			transfer_to[GRPQUOTA] = dqget(sb, attr->ia_gid,
 						      GRPQUOTA);
+			if (IS_ERR(transfer_to[GRPQUOTA])) {
+				status = PTR_ERR(transfer_to[GRPQUOTA]);
+				goto bail_unlock;
+			}
+
 			transfer_from[GRPQUOTA] = dqget(sb, inode->i_gid,
 							GRPQUOTA);
-			if (!transfer_to[GRPQUOTA] || !transfer_from[GRPQUOTA]) {
-				status = -ESRCH;
+			if (IS_ERR(transfer_from[GRPQUOTA])) {
+				status = PTR_ERR(transfer_from[GRPQUOTA]);
 				goto bail_unlock;
 			}
 		}
fs/ocfs2/quota_local.c +5 -5
index 21f9e71..6827ff6 100644
@@ -469,13 +469,13 @@ static int ocfs2_recover_local_quota_file(struct inode *lqinode,
 			dqblk = (struct ocfs2_local_disk_dqblk *)(qbh->b_data +
 				ol_dqblk_block_off(sb, chunk, bit));
 			dquot = dqget(sb, le64_to_cpu(dqblk->dqb_id), type);
-			if (!dquot) {
-				status = -EIO;
+			if (IS_ERR(dquot)) {
+				status = PTR_ERR(dquot);
 				mlog(ML_ERROR, "Failed to get quota structure "
-				     "for id %u, type %d. Cannot finish quota "
-				     "file recovery.\n",
+				     "for id %u, type %d err %d. Cannot finish"
+				     " quota file recovery.\n",
 				     (unsigned)le64_to_cpu(dqblk->dqb_id),
-				     type);
+				     type, status);
 				goto out_put_bh;
 			}
 			status = ocfs2_lock_global_qf(oinfo, 1);
fs/quota/dquot.c +68 -33

204 lines not on this page · raw message

include/linux/quotaops.h +3 -2
index fd8f70b..6b50f98 100644
@@ -31,7 +31,7 @@ void inode_add_rsv_space(struct inode *inode, qsize_t number);
 void inode_claim_rsv_space(struct inode *inode, qsize_t number);
 void inode_sub_rsv_space(struct inode *inode, qsize_t number);
 
-void dquot_initialize(struct inode *inode);
+int dquot_initialize(struct inode *inode);
 void dquot_drop(struct inode *inode);
 struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
 void dqput(struct dquot *dquot);
@@ -206,8 +206,9 @@ static inline int sb_any_quota_active(struct super_block *sb)
 #define sb_dquot_ops				(NULL)
 #define sb_quotactl_ops				(NULL)
 
-static inline void dquot_initialize(struct inode *inode)
+static inline int dquot_initialize(struct inode *inode)
 {
+	return 0;
 }
 
 static inline void dquot_drop(struct inode *inode)
Signature · 1 line
1.6.6.1
#3 lore raw

PATCH 3/6 quota: Check what quota is properly initialized for inode before charge

Due to previous IO error or other bugs an inode may not has quota pointer. This definite sign of quota inconsistency/corruption. In fact this condition must being checked in all charge/uncharge functions. And if error was detected it is reasonable to fail whole operation. But uncharge(free_space/claim_space/free_inode) functions has no fail nature. This is because caller can't handle errors from such functions. How can you handle error from following call-trace? write_page()->quota_claim_space()

So alloc_space() and alloc_inode() are the only functions which we may reliably abort in case of any errors.

This patch add corresponding checks only for charge functions.

---
 fs/quota/dquot.c |   39 +++++++++++++++++++++++++++++++++------
 1 files changed, 33 insertions(+), 6 deletions(-)
fs/quota/dquot.c +33 -6
index 3f4541e..7480e03 100644
@@ -1516,7 +1516,7 @@ static void inode_decr_space(struct inode *inode, qsize_t number, int reserve)
 int __dquot_alloc_space(struct inode *inode, qsize_t number,
 		int warn, int reserve)
 {
-	int cnt, ret = 0;
+	int cnt, active, ret = 0;
 	char warntype[MAXQUOTAS];
 
 	/*
@@ -1529,13 +1529,27 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
 	}
 
 	down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+	/* Now recheck reliably when holding dqptr_sem */
+	if (!(active = sb_any_quota_active(inode->i_sb)) || IS_NOQUOTA(inode)) {
+		inode_incr_space(inode, number, reserve);
+		goto out;
+	}
+
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++)
 		warntype[cnt] = QUOTA_NL_NOWARN;
 
 	spin_lock(&dq_data_lock);
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!inode->i_dquot[cnt])
+		if (!(active & (1 << cnt)))
 			continue;
+		/*
+		 * Given quota type is active, so quota must being
+		 * initialized for this inode
+		 */
+		if (!inode->i_dquot[cnt]) {
+			ret = -EIO;
+			goto out_flush_warn;
+		}
 		ret = check_bdq(inode->i_dquot[cnt], number, !warn,
 				warntype+cnt);
 		if (ret) {
@@ -1544,7 +1558,7 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
 		}
 	}
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!inode->i_dquot[cnt])
+		if (!(active & (1 << cnt)))
 			continue;
 		if (reserve)
 			dquot_resv_space(inode->i_dquot[cnt], number);
@@ -1570,7 +1584,7 @@ EXPORT_SYMBOL(__dquot_alloc_space);
  */
 int dquot_alloc_inode(const struct inode *inode)
 {
-	int cnt, ret = 0;
+	int cnt, active, ret = 0;
 	char warntype[MAXQUOTAS];
 
 	/* First test before acquiring mutex - solves deadlocks when we
@@ -1580,17 +1594,30 @@ int dquot_alloc_inode(const struct inode *inode)
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++)
 		warntype[cnt] = QUOTA_NL_NOWARN;
 	down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+	/* Now recheck reliably when holding dqptr_sem */
+	if (!(active = sb_any_quota_active(inode->i_sb)) || IS_NOQUOTA(inode)) {
+		return 0;
+	}
+
 	spin_lock(&dq_data_lock);
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!inode->i_dquot[cnt])
+		if (!(active & (1 < cnt)))
 			continue;
+		/*
+		 * Given quota type is active, so quota must being
+		 * initialized for this inode
+		 */
+		if (!inode->i_dquot[cnt]) {
+			ret = -EIO;
+			goto warn_put_all;
+		}
 		ret = check_idq(inode->i_dquot[cnt], 1, warntype + cnt);
 		if (ret)
 			goto warn_put_all;
 	}
 
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!inode->i_dquot[cnt])
+		if ((!active & (1 < cnt)))
 			continue;
 		dquot_incr_inodes(inode->i_dquot[cnt], 1);
 	}
Signature · 1 line
1.6.6.1
#4 lore raw

PATCH 4/6 ext3: handle errors in orphan_cleanup

Orphan cleanup procedure is complex task and may fail due to number of reasons. Handle errors from orphan_cleanp according to predefined per-sb errors behavior flags.

---
 fs/ext3/super.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
fs/ext3/super.c +20 -9
index e844acc..72d979a 100644
@@ -1422,23 +1422,24 @@ static int ext3_check_descriptors(struct super_block *sb)
  * e2fsck was run on this filesystem, and it must have already done the orphan
  * inode cleanup for us, so we can safely abort without any further action.
  */
-static void ext3_orphan_cleanup (struct super_block * sb,
+static int ext3_orphan_cleanup (struct super_block * sb,
 				 struct ext3_super_block * es)
 {
 	unsigned int s_flags = sb->s_flags;
 	int nr_orphans = 0, nr_truncates = 0;
+	int ret = 0;
 #ifdef CONFIG_QUOTA
 	int i;
 #endif
 	if (!es->s_last_orphan) {
 		jbd_debug(4, "no orphan inodes to clean up\n");
-		return;
+		return ret;
 	}
 
 	if (bdev_read_only(sb->s_bdev)) {
 		ext3_msg(sb, KERN_ERR, "error: write access "
 			"unavailable, skipping orphan cleanup.");
-		return;
+		return ret;
 	}
 
 	if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) {
@@ -1447,7 +1448,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
 				  "clearing orphan list.\n");
 		es->s_last_orphan = 0;
 		jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
-		return;
+		return ret;
 	}
 
 	if (s_flags & MS_RDONLY) {
@@ -1460,11 +1461,14 @@ static void ext3_orphan_cleanup (struct super_block * sb,
 	/* Turn on quotas so that they are updated correctly */
 	for (i = 0; i < MAXQUOTAS; i++) {
 		if (EXT3_SB(sb)->s_qf_names[i]) {
-			int ret = ext3_quota_on_mount(sb, i);
-			if (ret < 0)
+			ret = ext3_quota_on_mount(sb, i);
+			if (ret < 0) {
 				ext3_msg(sb, KERN_ERR,
 					"error: cannot turn on journaled "
 					"quota: %d", ret);
+				if (!test_opt (sb, ERRORS_CONT))
+					goto out;
+			}
 		}
 	}
 #endif
@@ -1498,7 +1502,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
 		}
 		iput(inode);  /* The delete magic happens here! */
 	}
-
+out:
 #define PLURAL(x) (x), ((x)==1) ? "" : "s"
 
 	if (nr_orphans)
@@ -1507,6 +1511,9 @@ static void ext3_orphan_cleanup (struct super_block * sb,
 	if (nr_truncates)
 		ext3_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
 		       PLURAL(nr_truncates));
+	if (ret)
+		ext3_msg(sb, KERN_ERR, "Error %d wile orphan cleanup", ret);
+
 #ifdef CONFIG_QUOTA
 	/* Turn quotas off */
 	for (i = 0; i < MAXQUOTAS; i++) {
@@ -1515,6 +1522,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
 	}
 #endif
 	sb->s_flags = s_flags; /* Restore MS_RDONLY status */
+	return ret;
 }
 
 /*
@@ -2019,7 +2027,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
 	ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY);
 
 	EXT3_SB(sb)->s_mount_state |= EXT3_ORPHAN_FS;
-	ext3_orphan_cleanup(sb, es);
+	ret = ext3_orphan_cleanup(sb, es);
+
+	if (ret)
+		goto failed_mount4;
+
 	EXT3_SB(sb)->s_mount_state &= ~EXT3_ORPHAN_FS;
 	if (needs_recovery)
 		ext3_msg(sb, KERN_INFO, "recovery complete");
@@ -2038,7 +2050,6 @@ cantfind_ext3:
 			"error: can't find ext3 filesystem on dev %s.",
 		       sb->s_id);
 	goto failed_mount;
-
 failed_mount4:
 	journal_destroy(sbi->s_journal);
 failed_mount3:
Signature · 1 line
1.6.6.1
#5 lore raw

PATCH 5/6 ext4: handle errors in orphan_cleanup

Orphan cleanup procedure is complex task and may fail due to number of reasons. Handle errors from orphan_cleanp according to predefined per-sb errors behavior flags.

---
 fs/ext4/super.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)
fs/ext4/super.c +22 -8
index edcf3b0..230b71c 100644
@@ -1873,23 +1873,24 @@ static int ext4_check_descriptors(struct super_block *sb)
  * e2fsck was run on this filesystem, and it must have already done the orphan
  * inode cleanup for us, so we can safely abort without any further action.
  */
-static void ext4_orphan_cleanup(struct super_block *sb,
+static int ext4_orphan_cleanup(struct super_block *sb,
 				struct ext4_super_block *es)
 {
 	unsigned int s_flags = sb->s_flags;
 	int nr_orphans = 0, nr_truncates = 0;
+	int ret = 0;
 #ifdef CONFIG_QUOTA
 	int i;
 #endif
 	if (!es->s_last_orphan) {
 		jbd_debug(4, "no orphan inodes to clean up\n");
-		return;
+		return 0;
 	}
 
 	if (bdev_read_only(sb->s_bdev)) {
 		ext4_msg(sb, KERN_ERR, "write access "
 			"unavailable, skipping orphan cleanup");
-		return;
+		return 0;
 	}
 
 	if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
@@ -1898,7 +1899,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
 				  "clearing orphan list.\n");
 		es->s_last_orphan = 0;
 		jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
-		return;
+		return 0;
 	}
 
 	if (s_flags & MS_RDONLY) {
@@ -1911,11 +1912,14 @@ static void ext4_orphan_cleanup(struct super_block *sb,
 	/* Turn on quotas so that they are updated correctly */
 	for (i = 0; i < MAXQUOTAS; i++) {
 		if (EXT4_SB(sb)->s_qf_names[i]) {
-			int ret = ext4_quota_on_mount(sb, i);
-			if (ret < 0)
+			ret = ext4_quota_on_mount(sb, i);
+			if (ret < 0) {
 				ext4_msg(sb, KERN_ERR,
 					"Cannot turn on journaled "
 					"quota: error %d", ret);
+				if (!test_opt (sb, ERRORS_CONT))
+					goto out;
+			}
 		}
 	}
 #endif
@@ -1951,13 +1955,16 @@ static void ext4_orphan_cleanup(struct super_block *sb,
 	}
 
 #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
-
+out:
 	if (nr_orphans)
 		ext4_msg(sb, KERN_INFO, "%d orphan inode%s deleted",
 		       PLURAL(nr_orphans));
 	if (nr_truncates)
 		ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
 		       PLURAL(nr_truncates));
+	if (ret)
+		ext4_msg(sb, KERN_ERR, "Error %d wile orphan cleanup", ret);
+
 #ifdef CONFIG_QUOTA
 	/* Turn quotas off */
 	for (i = 0; i < MAXQUOTAS; i++) {
@@ -1966,6 +1973,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
 	}
 #endif
 	sb->s_flags = s_flags; /* Restore MS_RDONLY status */
+	return ret;
 }
 
 /*
@@ -2915,7 +2923,13 @@ no_journal:
 	};
 
 	EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
-	ext4_orphan_cleanup(sb, es);
+	ret = ext4_orphan_cleanup(sb, es);
+	if (err) {
+		ext4_mb_release(sb);
+		ext4_ext_release(sb);
+		goto failed_mount4;
+	}
+
 	EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
 	if (needs_recovery) {
 		ext4_msg(sb, KERN_INFO, "recovery complete");
Signature · 1 line
1.6.6.1
#6 lore raw

PATCH 6/6 quota: check error code from dquot_initialize

In most places quota initialization error may be handled trivially. But xxx_delete_inode is another story. It can not fail. So we may just print error and continue.

NOTE: Filesystem which has ondisk orphan list may add such quotaless inodes to the list to let fsck to handle it later.
But still, if inode hasn't quota initialized at the moment of ->delete_inode() is definite sign of quota corruption so full fsck, quotacheck is probably required.

---
 fs/ext2/ialloc.c        |    5 +++-
 fs/ext2/inode.c         |   11 ++++++-
 fs/ext2/namei.c         |   40 ++++++++++++++++++++++-------
 fs/ext3/ialloc.c        |    6 +++-
 fs/ext3/inode.c         |   19 ++++++++++---
 fs/ext3/namei.c         |   54 +++++++++++++++++++++++++++++----------
 fs/ext3/super.c         |    9 ++++++-
 fs/ext4/ialloc.c        |    5 +++-
 fs/ext4/inode.c         |   18 ++++++++++---
 fs/ext4/namei.c         |   55 ++++++++++++++++++++++++++++++----------
 fs/ext4/super.c         |    9 ++++++-
 fs/jfs/file.c           |    7 +++-
 fs/jfs/jfs_inode.c      |    5 +++-
 fs/jfs/namei.c          |   59 +++++++++++++++++++++++++++++++-----------
 fs/ocfs2/file.c         |   16 ++++++++---
 fs/ocfs2/inode.c        |    5 +++-
 fs/ocfs2/namei.c        |   64 ++++++++++++++++++++++++++++++++++++----------
 fs/ocfs2/refcounttree.c |    5 ++-
 fs/reiserfs/inode.c     |   10 +++++--
 fs/reiserfs/namei.c     |   64 ++++++++++++++++++++++++++++++++++++-----------
 fs/reiserfs/super.c     |    3 +-
 fs/udf/file.c           |    6 +++-
 fs/udf/ialloc.c         |   18 ++++++++-----
 fs/udf/namei.c          |   39 +++++++++++++++++++++-------
 fs/ufs/ialloc.c         |    5 +++-
 fs/ufs/namei.c          |   46 ++++++++++++++++++++++++---------
 fs/ufs/truncate.c       |    6 +++-
 27 files changed, 440 insertions(+), 149 deletions(-)
fs/ext2/ialloc.c +4 -1
index ad7d572..e0d1581 100644
@@ -586,7 +586,10 @@ got:
 		goto fail_drop;
 	}
 
-	dquot_initialize(inode);
+	err = dquot_initialize(inode);
+	if (err)
+		goto fail_drop;
+
 	err = dquot_alloc_inode(inode);
 	if (err)
 		goto fail_drop;
fs/ext2/inode.c +9 -2
index 445f08a..bf67cbc 100644
@@ -58,8 +58,15 @@ static inline int ext2_inode_is_fast_symlink(struct inode *inode)
  */
 void ext2_delete_inode (struct inode * inode)
 {
-	if (!is_bad_inode(inode))
-		dquot_initialize(inode);
+	if (!is_bad_inode(inode)) {
+		int ret = dquot_initialize(inode);
+		if (ret)
+			ext2_error(inode->i_sb, __func__, "Fail to init_quota "
+				"for inode %lu, uid %d, gid:%d, error%d, thus "
+				"quota information is probably inconsistent,  "
+				"Please run quotacheck(8)", inode->i_ino,
+				inode->i_uid, inode->i_gid, ret);
+	}
 	truncate_inode_pages(&inode->i_data, 0);
 
 	if (is_bad_inode(inode))
fs/ext2/namei.c +30 -10
index 71efb0e..d47e549 100644
@@ -101,8 +101,11 @@ struct dentry *ext2_get_parent(struct dentry *child)
 static int ext2_create (struct inode * dir, struct dentry * dentry, int mode, struct nameidata *nd)
 {
 	struct inode *inode;
+	int err;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	inode = ext2_new_inode(dir, mode);
 	if (IS_ERR(inode))
@@ -131,7 +134,9 @@ static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_
 	if (!new_valid_dev(rdev))
 		return -EINVAL;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	inode = ext2_new_inode (dir, mode);
 	err = PTR_ERR(inode);
@@ -157,7 +162,9 @@ static int ext2_symlink (struct inode * dir, struct dentry * dentry,
 	if (l > sb->s_blocksize)
 		goto out;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO);
 	err = PTR_ERR(inode);
@@ -202,7 +209,9 @@ static int ext2_link (struct dentry * old_dentry, struct inode * dir,
 	if (inode->i_nlink >= EXT2_LINK_MAX)
 		return -EMLINK;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	inode->i_ctime = CURRENT_TIME_SEC;
 	inode_inc_link_count(inode);
@@ -226,7 +235,9 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
 	if (dir->i_nlink >= EXT2_LINK_MAX)
 		goto out;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	inode_inc_link_count(dir);
 
@@ -274,7 +285,9 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
 	struct page * page;
 	int err = -ENOENT;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	de = ext2_find_entry (dir, &dentry->d_name, &page);
 	if (!de)
@@ -316,14 +329,21 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
 	struct ext2_dir_entry_2 * dir_de = NULL;
 	struct page * old_page;
 	struct ext2_dir_entry_2 * old_de;
-	int err = -ENOENT;
+	int err;
 
-	dquot_initialize(old_dir);
-	dquot_initialize(new_dir);
+	err = dquot_initialize(old_dir);
+	if (err)
+		return err;
+
+	err = dquot_initialize(new_dir);
+	if (err)
+		return err;
 
 	old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page);
-	if (!old_de)
+	if (!old_de) {
+		err = -ENOENT;
 		goto out;
+	}
 
 	if (S_ISDIR(old_inode->i_mode)) {
 		err = -EIO;
fs/ext3/ialloc.c +5 -1
index ef9008b..15f6ec7 100644
@@ -588,7 +588,11 @@ got:
 		sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0;
 
 	ret = inode;
-	dquot_initialize(inode);
+
+	err = dquot_initialize(inode);
+	if (err)
+		goto fail_drop;
+
 	err = dquot_alloc_inode(inode);
 	if (err)
 		goto fail_drop;
fs/ext3/inode.c +14 -5
index 0981a27..ed267ed 100644
@@ -196,9 +196,15 @@ void ext3_delete_inode (struct inode * inode)
 {
 	handle_t *handle;
 
-	if (!is_bad_inode(inode))
-		dquot_initialize(inode);
-
+	if (!is_bad_inode(inode)) {
+		int ret = dquot_initialize(inode);
+		if (ret)
+			ext3_error(inode->i_sb, __func__, "Fail to init_quota "
+				"for inode %lu, uid %d, gid:%d, error%d, thus "
+				"quota information is probably inconsistent,  "
+				"Please run quotacheck(8)", inode->i_ino,
+				inode->i_uid, inode->i_gid, ret);
+	}
 	truncate_inode_pages(&inode->i_data, 0);
 
 	if (is_bad_inode(inode))
@@ -3151,8 +3157,11 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (is_quota_modification(inode, attr))
-		dquot_initialize(inode);
+	if (is_quota_modification(inode, attr)) {
+		error = dquot_initialize(inode);
+		if (error)
+			return error;
+	}
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
 		handle_t *handle;
fs/ext3/namei.c +40 -14

107 lines not on this page · raw message

fs/ext3/super.c +8 -1
index 72d979a..f25bf61 100644
@@ -1483,7 +1483,14 @@ static int ext3_orphan_cleanup (struct super_block * sb,
 		}
 
 		list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan);
-		dquot_initialize(inode);
+		ret = dquot_initialize(inode);
+		if (ret) {
+			ext3_msg(sb, KERN_ERR, "Can not initialize quota for "
+				"inode:%lu error %d",
+				inode->i_ino, ret);
+			if (!test_opt (sb, ERRORS_CONT))
+				goto out;
+		}
 		if (inode->i_nlink) {
 			printk(KERN_DEBUG
 				"%s: truncating inode %lu to %Ld bytes\n",
fs/ext4/ialloc.c +4 -1
index 9bb2bb9..139845f 100644
@@ -1034,7 +1034,10 @@ got:
 	ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize;
 
 	ret = inode;
-	dquot_initialize(inode);
+	err = dquot_initialize(inode);
+	if(err)
+		goto fail_drop;
+
 	err = dquot_alloc_inode(inode);
 	if (err)
 		goto fail_drop;
fs/ext4/inode.c +14 -4
index b812655..2d04631 100644
@@ -170,8 +170,15 @@ void ext4_delete_inode(struct inode *inode)
 	handle_t *handle;
 	int err;
 
-	if (!is_bad_inode(inode))
-		dquot_initialize(inode);
+	if (!is_bad_inode(inode)) {
+		int ret = dquot_initialize(inode);
+		if (ret)
+			ext4_error(inode->i_sb, __func__, "Fail to init_quota "
+				"for inode %lu, uid %d, gid:%d, error%d, thus "
+				"quota information is probably inconsistent,  "
+				"Please run quotacheck(8)", inode->i_ino,
+				inode->i_uid, inode->i_gid, ret);
+	}
 
 	if (ext4_should_order_data(inode))
 		ext4_begin_ordered_truncate(inode, 0);
@@ -5255,8 +5262,11 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (is_quota_modification(inode, attr))
-		dquot_initialize(inode);
+	if (is_quota_modification(inode, attr)) {
+		error = dquot_initialize(inode);
+		if (error)
+			return error;
+	}
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
 		handle_t *handle;
fs/ext4/namei.c +41 -14

108 lines not on this page · raw message

fs/ext4/super.c +8 -1
index 230b71c..c215d26 100644
@@ -1934,7 +1934,14 @@ static int ext4_orphan_cleanup(struct super_block *sb,
 		}
 
 		list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
-		dquot_initialize(inode);
+		ret = dquot_initialize(inode);
+		if (ret) {
+			ext4_msg(sb, KERN_ERR, "Can not initialize quota for "
+				"inode:%lu error %d",
+				inode->i_ino, ret);
+			if (!test_opt (sb, ERRORS_CONT))
+				goto out;
+		}
 		if (inode->i_nlink) {
 			ext4_msg(sb, KERN_DEBUG,
 				"%s: truncating inode %lu to %lld bytes",
fs/jfs/file.c +5 -2
index 85d9ec6..cb0da27 100644
@@ -98,8 +98,11 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (rc)
 		return rc;
 
-	if (is_quota_modification(inode, iattr))
-		dquot_initialize(inode);
+	if (is_quota_modification(inode, iattr)) {
+		rc = dquot_initialize(inode);
+		if (rc)
+			return rc;
+	}
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
 		rc = dquot_transfer(inode, iattr);
fs/jfs/jfs_inode.c +4 -1
index 829921b..8d18c95 100644
@@ -116,7 +116,10 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
 	/*
 	 * Allocate inode to quota.
 	 */
-	dquot_initialize(inode);
+	rc = dquot_initialize(inode);
+	if (rc)
+		goto fail_unlock;
+
 	rc = dquot_alloc_inode(inode);
 	if (rc)
 		goto fail_drop;
fs/jfs/namei.c +43 -16

117 lines not on this page · raw message

fs/ocfs2/file.c +11 -5
index 3c32f40..cafcc59 100644
@@ -107,9 +107,11 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)
 	mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
 		   file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name);
 
-	if (file->f_mode & FMODE_WRITE)
-		dquot_initialize(inode);
-
+	if (file->f_mode & FMODE_WRITE) {
+		status = dquot_initialize(inode);
+		if (status)
+			goto leave;
+	}
 	spin_lock(&oi->ip_lock);
 
 	/* Check that the inode hasn't been wiped from disk by another
@@ -978,8 +980,12 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 	if (status)
 		return status;
 
-	if (is_quota_modification(inode, attr))
-		dquot_initialize(inode);
+	if (is_quota_modification(inode, attr)) {
+		status = dquot_initialize(inode);
+		if (status)
+			return status;
+	}
+
 	size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
 	if (size_change) {
 		status = ocfs2_rw_lock(inode, 1);
fs/ocfs2/inode.c +4 -1
index 278a223..b8c3a14 100644
@@ -971,7 +971,10 @@ void ocfs2_delete_inode(struct inode *inode)
 		goto bail;
 	}
 
-	dquot_initialize(inode);
+	status = dquot_initialize(inode);
+	/* Even when quota wasn't initialized we can't faile the operation */
+	if (status)
+		mlog_errno(status);
 
 	if (!ocfs2_inode_is_valid_to_delete(inode)) {
 		/* It's probably not necessary to truncate_inode_pages
fs/ocfs2/namei.c +50 -14

131 lines not on this page · raw message

fs/ocfs2/refcounttree.c +3 -2
index f3ae10c..7d38db5 100644
@@ -4390,8 +4390,9 @@ static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir,
 	}
 
 	mutex_lock(&inode->i_mutex);
-	dquot_initialize(dir);
-	error = ocfs2_reflink(old_dentry, dir, new_dentry, preserve);
+	error = dquot_initialize(dir);
+	if (!error)
+		error = ocfs2_reflink(old_dentry, dir, new_dentry, preserve);
 	mutex_unlock(&inode->i_mutex);
 	if (!error)
 		fsnotify_create(dir, new_dentry);
fs/reiserfs/inode.c +7 -3
index 0bf5324..43070d8 100644
@@ -1768,7 +1768,9 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
 
 	BUG_ON(!th->t_trans_id);
 
-	dquot_initialize(inode);
+	err = dquot_initialize(inode);
+	if (err)
+		goto out_end_trans;
 	err = dquot_alloc_inode(inode);
 	if (err)
 		goto out_end_trans;
@@ -3075,8 +3077,10 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
 	ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID);
 
 	depth = reiserfs_write_lock_once(inode->i_sb);
-	if (is_quota_modification(inode, attr))
-		dquot_initialize(inode);
+	if (is_quota_modification(inode, attr)) {
+		error = dquot_initialize(inode);
+		goto out;
+	}
 
 	if (attr->ia_valid & ATTR_SIZE) {
 		/* version 2 items will be caught by the s_maxbytes check
fs/reiserfs/namei.c +49 -15

136 lines not on this page · raw message

fs/reiserfs/super.c +2 -1
index 04bf5d7..afbe4d2 100644
@@ -246,7 +246,8 @@ static int finish_unfinished(struct super_block *s)
 			retval = remove_save_link_only(s, &save_link_key, 0);
 			continue;
 		}
-		dquot_initialize(inode);
+		retval = dquot_initialize(inode);
+		/* XXX don't know what to do with error here */
 
 		if (truncate && S_ISDIR(inode->i_mode)) {
 			/* We got a truncate request for a dir which is impossible.
fs/udf/file.c +4 -2
index 6ebc043..1ef70d6 100644
@@ -227,8 +227,10 @@ int udf_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (error)
 		return error;
 
-	if (is_quota_modification(inode, iattr))
-		dquot_initialize(inode);
+	if (is_quota_modification(inode, iattr)) {
+		error = dquot_initialize(inode);
+		return error;
+	}
 
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
             (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
fs/udf/ialloc.c +11 -7
index fb68c9c..dc78998 100644
@@ -153,17 +153,21 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
 	insert_inode_hash(inode);
 	mark_inode_dirty(inode);
 
-	dquot_initialize(inode);
+	ret = dquot_initialize(inode);
+	if (ret)
+		goto out_put;
 	ret = dquot_alloc_inode(inode);
 	if (ret) {
 		dquot_drop(inode);
-		inode->i_flags |= S_NOQUOTA;
-		inode->i_nlink = 0;
-		iput(inode);
-		*err = ret;
-		return NULL;
+		goto out_put;
 	}
-
 	*err = 0;
 	return inode;
+out_put:
+	inode->i_flags |= S_NOQUOTA;
+	clear_nlink(inode);
+	iput(inode);
+	*err = ret;
+	return NULL;
+
 }
fs/udf/namei.c +29 -10
index 1fdbee2..21a59a1 100644
@@ -563,7 +563,9 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
 	int err;
 	struct udf_inode_info *iinfo;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	lock_kernel();
 	inode = udf_new_inode(dir, mode, &err);
@@ -618,7 +620,9 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
 	if (!old_valid_dev(rdev))
 		return -EINVAL;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	lock_kernel();
 	err = -EIO;
@@ -666,7 +670,9 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 	struct udf_inode_info *dinfo = UDF_I(dir);
 	struct udf_inode_info *iinfo;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	lock_kernel();
 	err = -EMLINK;
@@ -805,7 +811,9 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
 	struct fileIdentDesc *fi, cfi;
 	struct kernel_lb_addr tloc;
 
-	dquot_initialize(dir);
+	retval = dquot_initialize(dir);
+	if (retval)
+		return retval;
 
 	retval = -ENOENT;
 	lock_kernel();
@@ -853,7 +861,9 @@ static int udf_unlink(struct inode *dir, struct dentry *dentry)
 	struct fileIdentDesc cfi;
 	struct kernel_lb_addr tloc;
 
-	dquot_initialize(dir);
+	retval = dquot_initialize(dir);
+	if (retval)
+		return retval;
 
 	retval = -ENOENT;
 	lock_kernel();
@@ -909,7 +919,9 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
 	struct buffer_head *bh;
 	struct udf_inode_info *iinfo;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	lock_kernel();
 	inode = udf_new_inode(dir, S_IFLNK, &err);
@@ -1081,7 +1093,9 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
 	int err;
 	struct buffer_head *bh;
 
-	dquot_initialize(dir);
+	err = dquot_initialize(dir);
+	if (err)
+		return err;
 
 	lock_kernel();
 	if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
@@ -1141,13 +1155,18 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
 	struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL;
 	struct fileIdentDesc ocfi, ncfi;
 	struct buffer_head *dir_bh = NULL;
-	int retval = -ENOENT;
+	int retval;
 	struct kernel_lb_addr tloc;
 	struct udf_inode_info *old_iinfo = UDF_I(old_inode);
 
-	dquot_initialize(old_dir);
-	dquot_initialize(new_dir);
+	retval = dquot_initialize(old_dir);
+	if (retval)
+		return retval;
+	retval = dquot_initialize(new_dir);
+	if (retval)
+		return retval;
 
+	retval = -ENOENT;
 	lock_kernel();
 	ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
 	if (ofi) {
fs/ufs/ialloc.c +4 -1
index 230ecf6..33e6fab 100644
@@ -355,7 +355,10 @@ cg_found:
 
 	unlock_super (sb);
 
-	dquot_initialize(inode);
+	err = dquot_initialize(inode);
+	if (err)
+		goto fail_without_unlock;
+
 	err = dquot_alloc_inode(inode);
 	if (err) {
 		dquot_drop(inode);
fs/ufs/namei.c +33 -13

102 lines not on this page · raw message

fs/ufs/truncate.c +4 -2
index f294c44..2de89ee 100644
@@ -518,8 +518,10 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (is_quota_modification(inode, attr))
-		dquot_initialize(inode);
+	if (is_quota_modification(inode, attr)) {
+		error = dquot_initialize(inode);
+		return error;
+	}
 
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 	    (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
Signature · 1 line
1.6.6.1
reviewer
#7 lore raw

Re: [PATCH 6/6] quota: check error code from dquot_initialize

Quoted 10 lines · Dmitry Monakhov

In most places quota initialization error may be handled trivially. But xxx_delete_inode is another story. It can not fail. So we may just print error and continue.

NOTE: Filesystem which has ondisk orphan list may add such quotaless inodes to the list to let fsck to handle it later.
But still, if inode hasn't quota initialized at the moment of ->delete_inode() is definite sign of quota corruption so full fsck, quotacheck is probably required.

Please split this to per-fs patches. They can be merged through
fs-specific trees and can get review from respective filesystem maintainers.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#8 lore raw

Re: [PATCH 4/6] ext3: handle errors in orphan_cleanup

In reply to Dmitry Monakhov
Quoted 17 lines · Dmitry Monakhov

Orphan cleanup procedure is complex task and may fail due to number of reasons. Handle errors from orphan_cleanp according to predefined per-sb errors behavior flags.

---
 fs/ext3/super.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
fs/ext3/super.c +0 -0
index e844acc..72d979a 100644
@@ -1460,11 +1461,14 @@ static void ext3_orphan_cleanup (struct super_block * sb,
 	/* Turn on quotas so that they are updated correctly */
 	for (i = 0; i < MAXQUOTAS; i++) {
 		if (EXT3_SB(sb)->s_qf_names[i]) {

fs/ext3/super.c static void ext3_orphan_cleanup (struct super_block * sb, · line 1471

Quoted 10 lines
fs/ext3/super.c +5 -2
-			int ret = ext3_quota_on_mount(sb, i);
-			if (ret < 0)
+			ret = ext3_quota_on_mount(sb, i);
+			if (ret < 0) {
 				ext3_msg(sb, KERN_ERR,
 					"error: cannot turn on journaled "
 					"quota: %d", ret);
+				if (!test_opt (sb, ERRORS_CONT))
+					goto out;
+			}

I see two consistent approaches:
a) consider the filesystem is mounted and use ext3_handle_error()
b) consider this a part of mounting procedure and return error and fail the mount.

I would prefer b) but if you have some good arguments for a)...

Quoted 3 lines
fs/ext3/super.c +0 -0
 		}
 	}
 #endif

...

fs/ext3/super.c static void ext3_orphan_cleanup (struct super_block * sb, · line 1515

Quoted 6 lines
fs/ext3/super.c +2 -0
@@ -1507,6 +1511,9 @@ static void ext3_orphan_cleanup (struct super_block * sb,
 	if (nr_truncates)
 		ext3_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
 		       PLURAL(nr_truncates));
+	if (ret)
+		ext3_msg(sb, KERN_ERR, "Error %d wile orphan cleanup", ret);
                                                 ^^^ while

									Honza
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#9 lore raw

Re: [PATCH 3/6] quota: Check what quota is properly initialized for inode before charge

In reply to Dmitry Monakhov
Quoted 24 lines · Dmitry Monakhov

Due to previous IO error or other bugs an inode may not has quota pointer. This definite sign of quota inconsistency/corruption. In fact this condition must being checked in all charge/uncharge functions. And if error was detected it is reasonable to fail whole operation. But uncharge(free_space/claim_space/free_inode) functions has no fail nature. This is because caller can't handle errors from such functions. How can you handle error from following call-trace? write_page()->quota_claim_space()

So alloc_space() and alloc_inode() are the only functions which we may reliably abort in case of any errors.

This patch add corresponding checks only for charge functions.

---
 fs/quota/dquot.c |   39 +++++++++++++++++++++++++++++++++------
 1 files changed, 33 insertions(+), 6 deletions(-)
fs/quota/dquot.c +0 -0
index 3f4541e..7480e03 100644

fs/quota/dquot.c int __dquot_alloc_space(struct inode *inode, qsize_t number, · line 1533

Quoted 5 lines
fs/quota/dquot.c +2 -0
@@ -1529,13 +1529,27 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
 	}
 
 	down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+	/* Now recheck reliably when holding dqptr_sem */
+	if (!(active = sb_any_quota_active(inode->i_sb)) || IS_NOQUOTA(inode)) {

Please don't use assignment in conditions... It's against kernel's coding
style.

Quoted 8 lines
fs/quota/dquot.c +4 -0
+		inode_incr_space(inode, number, reserve);
+		goto out;
+	}
+
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++)
 		warntype[cnt] = QUOTA_NL_NOWARN;
 
 	spin_lock(&dq_data_lock);

fs/quota/dquot.c int __dquot_alloc_space(struct inode *inode, qsize_t number, · line 1550

Quoted 10 lines
fs/quota/dquot.c +7 -1
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!inode->i_dquot[cnt])
+		if (!(active & (1 << cnt)))
 			continue;
+		/*
+		 * Given quota type is active, so quota must being
+		 * initialized for this inode
+		 */
+		if (!inode->i_dquot[cnt]) {
+			ret = -EIO;

Umm, I don't like this. I think we should just silently skip the quota
modification. The error has already been passed to the filesystem during dquot_initialize and this would effectively disallow any allocation on the filesystem if quota structure isn't available which might be a bit impractical.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#10 lore raw

Re: [PATCH 3/6] quota: Check what quota is properly initialized for inode before charge

Quoted 40 lines · Jan Kara
Quoted 24 lines · Dmitry Monakhov

Due to previous IO error or other bugs an inode may not has quota pointer. This definite sign of quota inconsistency/corruption. In fact this condition must being checked in all charge/uncharge functions. And if error was detected it is reasonable to fail whole operation. But uncharge(free_space/claim_space/free_inode) functions has no fail nature. This is because caller can't handle errors from such functions. How can you handle error from following call-trace? write_page()->quota_claim_space()

So alloc_space() and alloc_inode() are the only functions which we may reliably abort in case of any errors.

This patch add corresponding checks only for charge functions.

---
 fs/quota/dquot.c |   39 +++++++++++++++++++++++++++++++++------
 1 files changed, 33 insertions(+), 6 deletions(-)
fs/quota/dquot.c +0 -0
index 3f4541e..7480e03 100644

fs/quota/dquot.c int __dquot_alloc_space(struct inode *inode, qsize_t number, · line 1533

Quoted 5 lines
fs/quota/dquot.c +2 -0
@@ -1529,13 +1529,27 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number,
 	}
 
 	down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
+	/* Now recheck reliably when holding dqptr_sem */
+	if (!(active = sb_any_quota_active(inode->i_sb)) || IS_NOQUOTA(inode)) {

Please don't use assignment in conditions... It's against kernel's coding
style.

Quoted 7 lines
fs/quota/dquot.c +4 -0
+		inode_incr_space(inode, number, reserve);
+		goto out;
+	}
+
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++)
 		warntype[cnt] = QUOTA_NL_NOWARN;
 
Quoted 16 lines

fs/quota/dquot.c int __dquot_alloc_space(struct inode *inode, qsize_t number, · line 1550

Quoted 11 lines
fs/quota/dquot.c +7 -1
 	spin_lock(&dq_data_lock);
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!inode->i_dquot[cnt])
+		if (!(active & (1 << cnt)))
 			continue;
+		/*
+		 * Given quota type is active, so quota must being
+		 * initialized for this inode
+		 */
+		if (!inode->i_dquot[cnt]) {
+			ret = -EIO;

Umm, I don't like this. I think we should just silently skip the quota
modification. The error has already been passed to the filesystem during dquot_initialize and this would effectively disallow any allocation on the filesystem if quota structure isn't available which might be a bit impractical.

In fact in many places ret code from dquot_initialize() is simply ignored, because before this patch-set init was void, so it takes significant amount of time to fix all callers. And charge callers are usually do care about error code, so IMHO we have to signal what quota is broken if it is actually broken.
Another example: If filesystem becomes RO (due to journal abort, and etc) we do care about this, and check that condition in almost all places and return appropriate error, instead of simply skip write() syscall. User is able to disable quota if it becomes broken, and continue with hope that this is just an quota issue, but not disk failure :)

reviewer
#11 lore raw

Re: [PATCH 2/6] quota: Add proper error handling on quota initialization.

In reply to Dmitry Monakhov
Quoted 18 lines · Dmitry Monakhov

Currently dqget_initialize() is a black-box so IO errors are simply ignored. In order to pass to the caller real error codes quota interface must being redesigned in following way.

- return real error code from dqget()
- return real error code from dquot_initialize()

Now filesystem it is filesystem's responsibility to dquot_initialize() return value.

---
 fs/ocfs2/file.c          |   18 ++++++--
 fs/ocfs2/quota_local.c   |   10 ++--
 fs/quota/dquot.c         |  101 +++++++++++++++++++++++++++++++---------------
 include/linux/quotaops.h |    5 +-
 4 files changed, 90 insertions(+), 44 deletions(-)

...

Quoted 10 lines
fs/quota/dquot.c +0 -4
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
 		if (type != -1 && cnt != type)
 			continue;
 		/* Avoid races with quotaoff() */
 		if (!sb_has_quota_active(sb, cnt))
 			continue;
-		if (!inode->i_dquot[cnt]) {
-			inode->i_dquot[cnt] = got[cnt];
-			got[cnt] = NULL;
-			/*

fs/quota/dquot.c static void __dquot_initialize(struct inode *inode, int type) · line 1362

Quoted 10 lines
fs/quota/dquot.c +4 -6
-			 * Make quota reservation system happy if someone
-			 * did a write before quota was turned on
-			 */
-			rsv = inode_get_rsv_space(inode);
-			if (unlikely(rsv))
-				dquot_resv_space(inode->i_dquot[cnt], rsv);
+		if (inode->i_dquot[cnt])
+			continue;
+		if (unlikely(IS_ERR(got[cnt]))) {
+			err = (int)PTR_ERR(got[cnt]);
                              ^^^^ Why is (int) needed?

fs/quota/dquot.c static int __dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask · line 1748

Quoted 9 lines
fs/quota/dquot.c +3 -1
@@ -1721,15 +1742,29 @@ static int __dquot_transfer(struct inode *inode, qid_t *chid, unsigned long mask
 	space = cur_space + rsv_space;
 	/* Build the transfer_from list and check the limits */
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		if (!transfer_to[cnt])
+		if (!(mask & (1 << cnt)))
 			continue;
+		if (unlikely(IS_ERR(transfer_to[cnt]))) {
+			ret = (int)PTR_ERR(transfer_to[cnt]);
                              ^^^^^ And here as well.

								Honza
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#12 lore raw

Re: [PATCH 1/6] quota: unify quota init condition in setattr

In reply to Dmitry Monakhov
Quoted 7 lines · Dmitry Monakhov

Quota must being initialized if size or uid/git changes requested. But initialization performed in two different places:
in case of i_size file system is responsible for dquot init , but in case of uid/gid init will be called internally in dquot_transfer().
This ambiguity makes code harder to understand.
Let's move this logic to one common helper function.

This looks OK.

Honza

Quoted 179 lines
---
 fs/ext2/inode.c          |    2 +-
 fs/ext3/inode.c          |    2 +-
 fs/ext4/inode.c          |    2 +-
 fs/jfs/file.c            |    2 +-
 fs/ocfs2/file.c          |    4 ++--
 fs/quota/dquot.c         |    5 ++---
 fs/reiserfs/inode.c      |    3 ++-
 fs/udf/file.c            |    2 +-
 fs/ufs/truncate.c        |    8 ++++----
 include/linux/quotaops.h |    8 ++++++++
 10 files changed, 23 insertions(+), 15 deletions(-)
fs/ext2/inode.c +1 -1
index 45ff49f..445f08a 100644
@@ -1460,7 +1460,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (error)
 		return error;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
fs/ext3/inode.c +1 -1
index ffbbc65..0981a27 100644
@@ -3151,7 +3151,7 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
fs/ext4/inode.c +1 -1
index 4a91225..b812655 100644
@@ -5255,7 +5255,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
fs/jfs/file.c +1 -1
index 14ba982..85d9ec6 100644
@@ -98,7 +98,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (rc)
 		return rc;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
fs/ocfs2/file.c +2 -2
index 3641052..b26df86 100644
@@ -978,10 +978,10 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 	if (status)
 		return status;
 
+	if (is_quota_modification(inode, attr))
+		dquot_initialize(inode);
 	size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
 	if (size_change) {
-		dquot_initialize(inode);
-
 		status = ocfs2_rw_lock(inode, 1);
 		if (status < 0) {
 			mlog_errno(status);
fs/quota/dquot.c +2 -3
index 8a2f0cb..a168189 100644
@@ -1801,10 +1801,9 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
 		mask |= 1 << GRPQUOTA;
 		chid[GRPQUOTA] = iattr->ia_gid;
 	}
-	if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) {
-		dquot_initialize(inode);
+	if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
 		return __dquot_transfer(inode, chid, mask);
-	}
+
 	return 0;
 }
 EXPORT_SYMBOL(dquot_transfer);
fs/reiserfs/inode.c +2 -1
index b8671a5..0bf5324 100644
@@ -3075,9 +3075,10 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
 	ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID);
 
 	depth = reiserfs_write_lock_once(inode->i_sb);
-	if (attr->ia_valid & ATTR_SIZE) {
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 
+	if (attr->ia_valid & ATTR_SIZE) {
 		/* version 2 items will be caught by the s_maxbytes check
 		 ** done for us in vmtruncate
 		 */
fs/udf/file.c +1 -1
index 4b6a46c..6ebc043 100644
@@ -227,7 +227,7 @@ int udf_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (error)
 		return error;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
fs/ufs/truncate.c +4 -4
index ee8db3e..f294c44 100644
@@ -518,18 +518,18 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
+	if (is_quota_modification(inode, attr))
+		dquot_initialize(inode);
+
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 	    (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
 		error = dquot_transfer(inode, attr);
 		if (error)
 			return error;
 	}
-	if (ia_valid & ATTR_SIZE &&
-	    attr->ia_size != i_size_read(inode)) {
+	if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
 		loff_t old_i_size = inode->i_size;
 
-		dquot_initialize(inode);
-
 		error = vmtruncate(inode, attr->ia_size);
 		if (error)
 			return error;
include/linux/quotaops.h +8 -0
index e6fa7ac..fd8f70b 100644
@@ -14,6 +14,14 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 	return &sb->s_dquot;
 }
 
+/* i_mutex must being held */
+static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
+{
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+		(ia->ia_valid & ATTR_UID && ia->ia_uid != inode->i_uid) ||
+		(ia->ia_valid & ATTR_GID && ia->ia_gid != inode->i_gid);
+}
+
 #if defined(CONFIG_QUOTA)
 
 /*
Signature · 1 line
1.6.6.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer
#13 lore raw

Re: [PATCH 1/6] quota: unify quota init condition in setattr

In reply to Dmitry Monakhov
Quoted 7 lines · Dmitry Monakhov

Quota must being initialized if size or uid/git changes requested. But initialization performed in two different places:
in case of i_size file system is responsible for dquot init , but in case of uid/gid init will be called internally in dquot_transfer().
This ambiguity makes code harder to understand.
Let's move this logic to one common helper function.

Dmitry, I'm fixing some OCFS2 quota bugs and this patch helps it as well
so I took it into my tree.

Honza

Quoted 179 lines
---
 fs/ext2/inode.c          |    2 +-
 fs/ext3/inode.c          |    2 +-
 fs/ext4/inode.c          |    2 +-
 fs/jfs/file.c            |    2 +-
 fs/ocfs2/file.c          |    4 ++--
 fs/quota/dquot.c         |    5 ++---
 fs/reiserfs/inode.c      |    3 ++-
 fs/udf/file.c            |    2 +-
 fs/ufs/truncate.c        |    8 ++++----
 include/linux/quotaops.h |    8 ++++++++
 10 files changed, 23 insertions(+), 15 deletions(-)
fs/ext2/inode.c +1 -1
index 45ff49f..445f08a 100644
@@ -1460,7 +1460,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (error)
 		return error;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
fs/ext3/inode.c +1 -1
index ffbbc65..0981a27 100644
@@ -3151,7 +3151,7 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
fs/ext4/inode.c +1 -1
index 4a91225..b812655 100644
@@ -5255,7 +5255,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
-	if (ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 		(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
fs/jfs/file.c +1 -1
index 14ba982..85d9ec6 100644
@@ -98,7 +98,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (rc)
 		return rc;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
 	    (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
fs/ocfs2/file.c +2 -2
index 3641052..b26df86 100644
@@ -978,10 +978,10 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
 	if (status)
 		return status;
 
+	if (is_quota_modification(inode, attr))
+		dquot_initialize(inode);
 	size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
 	if (size_change) {
-		dquot_initialize(inode);
-
 		status = ocfs2_rw_lock(inode, 1);
 		if (status < 0) {
 			mlog_errno(status);
fs/quota/dquot.c +2 -3
index 8a2f0cb..a168189 100644
@@ -1801,10 +1801,9 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
 		mask |= 1 << GRPQUOTA;
 		chid[GRPQUOTA] = iattr->ia_gid;
 	}
-	if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode)) {
-		dquot_initialize(inode);
+	if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
 		return __dquot_transfer(inode, chid, mask);
-	}
+
 	return 0;
 }
 EXPORT_SYMBOL(dquot_transfer);
fs/reiserfs/inode.c +2 -1
index b8671a5..0bf5324 100644
@@ -3075,9 +3075,10 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
 	ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID);
 
 	depth = reiserfs_write_lock_once(inode->i_sb);
-	if (attr->ia_valid & ATTR_SIZE) {
+	if (is_quota_modification(inode, attr))
 		dquot_initialize(inode);
 
+	if (attr->ia_valid & ATTR_SIZE) {
 		/* version 2 items will be caught by the s_maxbytes check
 		 ** done for us in vmtruncate
 		 */
fs/udf/file.c +1 -1
index 4b6a46c..6ebc043 100644
@@ -227,7 +227,7 @@ int udf_setattr(struct dentry *dentry, struct iattr *iattr)
 	if (error)
 		return error;
 
-	if (iattr->ia_valid & ATTR_SIZE)
+	if (is_quota_modification(inode, iattr))
 		dquot_initialize(inode);
 
 	if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
fs/ufs/truncate.c +4 -4
index ee8db3e..f294c44 100644
@@ -518,18 +518,18 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)
 	if (error)
 		return error;
 
+	if (is_quota_modification(inode, attr))
+		dquot_initialize(inode);
+
 	if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
 	    (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
 		error = dquot_transfer(inode, attr);
 		if (error)
 			return error;
 	}
-	if (ia_valid & ATTR_SIZE &&
-	    attr->ia_size != i_size_read(inode)) {
+	if (ia_valid & ATTR_SIZE && attr->ia_size != inode->i_size) {
 		loff_t old_i_size = inode->i_size;
 
-		dquot_initialize(inode);
-
 		error = vmtruncate(inode, attr->ia_size);
 		if (error)
 			return error;
include/linux/quotaops.h +8 -0
index e6fa7ac..fd8f70b 100644
@@ -14,6 +14,14 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
 	return &sb->s_dquot;
 }
 
+/* i_mutex must being held */
+static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
+{
+	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
+		(ia->ia_valid & ATTR_UID && ia->ia_uid != inode->i_uid) ||
+		(ia->ia_valid & ATTR_GID && ia->ia_gid != inode->i_gid);
+}
+
 #if defined(CONFIG_QUOTA)
 
 /*
Signature · 1 line
1.6.6.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#14 lore raw
In reply to Dmitry Monakhov

Jan, can you please take a look at following patch set
it starts here: http://marc.info/?l=linux-fsdevel&m=127074989804295&w=2
Do you agree with approach?
Would you accept updated version for recent merge window?

Quoted 19 lines · Dmitry Monakhov

This patchset is tended to provide interface for handling IO errors from internal quota code.
Any error must being returned to fs-caller to signal about possible quota inconsistency. I've done it in following way:

1) Handle low-level io errors from dqget() and it's callers
2) Handle errors from dquot_initialize
This path catch most of IO error, but no all.
3) Check what i_dquot was initialized in each low-level function. There are two types of such functions
3A) Charging functions (alloc_{space,inode}): Caller of such
function may easy handle an error and abort an operation.
3B) nofail functions (claim_space,free_{space,inode})
In most cases caller can not abort an operation even if inode's quotas was semi-initialized, so I just skip this functions for now.
I would like to know you ideas suggestions about this.
Note: Only ext4's part was basically tested for now, others was just compile tested.

reviewer
#15 lore raw
In reply to Dmitry Monakhov
Quoted 5 lines · Dmitry Monakhov

This patchset is tended to provide interface for handling IO errors from internal quota code.
Any error must being returned to fs-caller to signal about possible quota inconsistency. I've done it in following way:

Quoted 14 lines

1) Handle low-level io errors from dqget() and it's callers
2) Handle errors from dquot_initialize
This path catch most of IO error, but no all.
3) Check what i_dquot was initialized in each low-level function. There are two types of such functions
3A) Charging functions (alloc_{space,inode}): Caller of such
function may easy handle an error and abort an operation.
3B) nofail functions (claim_space,free_{space,inode})
In most cases caller can not abort an operation even if inode's quotas was semi-initialized, so I just skip this functions for now.
I would like to know you ideas suggestions about this.
Note: Only ext4's part was basically tested for now, others was just compile tested.

Sorry for not replying earlier. I've glanced over the patch set and I
have no major objections. I'll send you now the problems I've found and next week I will have a more detailed look.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR