Skip to contentSkip to conversation

quota: don't let mark_dquot_dirty() fail silently

PATCH In review Chao Yu 3 participants 4 messages Apr 7, 2024 – Apr 11, 2024

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 quota: don't let mark_dquot_dirty() fail silently

mark_dquot_dirty() will callback to specified filesystem function, it may fail due to any reasons, however, no caller will check return value of mark_dquot_dirty(), so, it may fail silently, let's print one line message for such case.

---
 fs/quota/dquot.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
fs/quota/dquot.c +13 -10
index dacbee455c03..c5df7863942a 100644
@@ -399,21 +399,20 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
 EXPORT_SYMBOL(dquot_mark_dquot_dirty);
 
 /* Dirtify all the dquots - this can block when journalling */
-static inline int mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
+static inline void mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
 {
-	int ret, err, cnt;
+	int ret, cnt;
 	struct dquot *dquot;
 
-	ret = err = 0;
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
 		dquot = srcu_dereference(dquots[cnt], &dquot_srcu);
-		if (dquot)
-			/* Even in case of error we have to continue */
-			ret = mark_dquot_dirty(dquot);
-		if (!err)
-			err = ret;
+		if (!dquot)
+			continue;
+		ret = mark_dquot_dirty(dquot);
+		if (ret < 0)
+			quota_error(dquot->dq_sb,
+				"mark_all_dquot_dirty fails, ret: %d", ret);
 	}
-	return err;
 }
 
 static inline void dqput_all(struct dquot **dquot)
@@ -2725,6 +2724,7 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
 {
 	struct mem_dqblk *dm = &dquot->dq_dqb;
 	int check_blim = 0, check_ilim = 0;
+	int ret;
 	struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type];
 
 	if (di->d_fieldmask & ~VFS_QC_MASK)
@@ -2807,7 +2807,10 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
 	else
 		set_bit(DQ_FAKE_B, &dquot->dq_flags);
 	spin_unlock(&dquot->dq_dqb_lock);
-	mark_dquot_dirty(dquot);
+	ret = mark_dquot_dirty(dquot);
+	if (ret < 0)
+		quota_error(dquot->dq_sb,
+			"mark_dquot_dirty fails, ret: %d", ret);
 
 	return 0;
 }
Signature · 1 line
2.40.1
reviewer
#1 lore raw
Quoted 29 lines · Chao Yu

mark_dquot_dirty() will callback to specified filesystem function, it may fail due to any reasons, however, no caller will check return value of mark_dquot_dirty(), so, it may fail silently, let's print one line message for such case.

---
 fs/quota/dquot.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
fs/quota/dquot.c +2 -4
index dacbee455c03..c5df7863942a 100644
@@ -399,21 +399,20 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
 EXPORT_SYMBOL(dquot_mark_dquot_dirty);
 
 /* Dirtify all the dquots - this can block when journalling */
-static inline int mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
+static inline void mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
 {
-	int ret, err, cnt;
+	int ret, cnt;
 	struct dquot *dquot;
 
-	ret = err = 0;
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
 		dquot = srcu_dereference(dquots[cnt], &dquot_srcu);
-		if (dquot)

fs/quota/dquot.c int dquot_mark_dquot_dirty(struct dquot *dquot) · line 414

Quoted 10 lines
fs/quota/dquot.c +6 -4
-			/* Even in case of error we have to continue */
-			ret = mark_dquot_dirty(dquot);
-		if (!err)
-			err = ret;
+		if (!dquot)
+			continue;
+		ret = mark_dquot_dirty(dquot);
+		if (ret < 0)
+			quota_error(dquot->dq_sb,
+				"mark_all_dquot_dirty fails, ret: %d", ret);

Do you have any practical case you care about? Because in practice the filesystem will usually report if there's some catastrophic error (and the errors from ->mark_dirty() all mean the filesystem is in unhealthy state). So this message just adds to the noise in the error log - and e.g. if the disk goes bad so we cannot write, we could spew a lot of messages like this.

Quoted 14 lines
fs/quota/dquot.c +1 -1
 	}
-	return err;
 }
 
 static inline void dqput_all(struct dquot **dquot)
@@ -2725,6 +2724,7 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
 {
 	struct mem_dqblk *dm = &dquot->dq_dqb;
 	int check_blim = 0, check_ilim = 0;
+	int ret;
 	struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type];
 
 	if (di->d_fieldmask & ~VFS_QC_MASK)

fs/quota/dquot.c static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di) · line 2813

Quoted 8 lines
fs/quota/dquot.c +4 -1
@@ -2807,7 +2807,10 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
 	else
 		set_bit(DQ_FAKE_B, &dquot->dq_flags);
 	spin_unlock(&dquot->dq_dqb_lock);
-	mark_dquot_dirty(dquot);
+	ret = mark_dquot_dirty(dquot);
+	if (ret < 0)
+		quota_error(dquot->dq_sb,
+			"mark_dquot_dirty fails, ret: %d", ret);

Here, we can propagate the error back to userspace, which is probably better than spamming the logs.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw
In reply to Chao Yu
Quoted 53 lines · Chao Yu

mark_dquot_dirty() will callback to specified filesystem function, it may fail due to any reasons, however, no caller will check return value of mark_dquot_dirty(), so, it may fail silently, let's print one line message for such case.

---
  fs/quota/dquot.c | 23 +++++++++++++----------
  1 file changed, 13 insertions(+), 10 deletions(-)
fs/quota/dquot.c +9 -9
index dacbee455c03..c5df7863942a 100644
@@ -399,21 +399,20 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
  EXPORT_SYMBOL(dquot_mark_dquot_dirty);
 
  /* Dirtify all the dquots - this can block when journalling */
-static inline int mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
+static inline void mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
  {
-	int ret, err, cnt;
+	int ret, cnt;
  	struct dquot *dquot;
 
-	ret = err = 0;
  	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
  		dquot = srcu_dereference(dquots[cnt], &dquot_srcu);
-		if (dquot)
-			/* Even in case of error we have to continue */
-			ret = mark_dquot_dirty(dquot);
-		if (!err)
-			err = ret;
+		if (!dquot)
+			continue;
+		ret = mark_dquot_dirty(dquot);
+		if (ret < 0)
+			quota_error(dquot->dq_sb,
+				"mark_all_dquot_dirty fails, ret: %d", ret);
  	}
-	return err;
  }
 
  static inline void dqput_all(struct dquot **dquot)
@@ -2725,6 +2724,7 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
  {
  	struct mem_dqblk *dm = &dquot->dq_dqb;
  	int check_blim = 0, check_ilim = 0;
+	int ret;
  	struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type];
 
  	if (di->d_fieldmask & ~VFS_QC_MASK)

fs/quota/dquot.c static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di) · line 2810

Quoted 5 lines
fs/quota/dquot.c +1 -1
@@ -2807,7 +2807,10 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
  	else
  		set_bit(DQ_FAKE_B, &dquot->dq_flags);
  	spin_unlock(&dquot->dq_dqb_lock);
-	mark_dquot_dirty(dquot);
+	ret = mark_dquot_dirty(dquot);

Here it overwrite previous error.

Quoted 6 lines
fs/quota/dquot.c +3 -0
+	if (ret < 0)
+		quota_error(dquot->dq_sb,
+			"mark_dquot_dirty fails, ret: %d", ret);
 
  	return 0;
  }
Signature · 1 line
Regards
author
#2 lore raw
In reply to Jan Kara
Quoted 26 lines · Jan Kara
Quoted 25 lines · Chao Yu

mark_dquot_dirty() will callback to specified filesystem function, it may fail due to any reasons, however, no caller will check return value of mark_dquot_dirty(), so, it may fail silently, let's print one line message for such case.

---
  fs/quota/dquot.c | 23 +++++++++++++----------
  1 file changed, 13 insertions(+), 10 deletions(-)
fs/quota/dquot.c +2 -2
index dacbee455c03..c5df7863942a 100644
@@ -399,21 +399,20 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
  EXPORT_SYMBOL(dquot_mark_dquot_dirty);
 
  /* Dirtify all the dquots - this can block when journalling */
-static inline int mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
+static inline void mark_all_dquot_dirty(struct dquot __rcu * const *dquots)
  {
-	int ret, err, cnt;
+	int ret, cnt;
  	struct dquot *dquot;
 
Quoted 16 lines
Quoted 4 lines
fs/quota/dquot.c +0 -2
-	ret = err = 0;
  	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
  		dquot = srcu_dereference(dquots[cnt], &dquot_srcu);
-		if (dquot)

fs/quota/dquot.c int dquot_mark_dquot_dirty(struct dquot *dquot) · line 414

Quoted 10 lines
fs/quota/dquot.c +6 -4
-			/* Even in case of error we have to continue */
-			ret = mark_dquot_dirty(dquot);
-		if (!err)
-			err = ret;
+		if (!dquot)
+			continue;
+		ret = mark_dquot_dirty(dquot);
+		if (ret < 0)
+			quota_error(dquot->dq_sb,
+				"mark_all_dquot_dirty fails, ret: %d", ret);

Do you have any practical case you care about? Because in practice the

Actually, no.

Quoted 5 lines

filesystem will usually report if there's some catastrophic error (and the errors from ->mark_dirty() all mean the filesystem is in unhealthy state). So this message just adds to the noise in the error log - and e.g. if the disk goes bad so we cannot write, we could spew a lot of messages like this.

Agreed,

I guess we can propagate the error to caller rather than printing redundant message in log.

Quoted 13 lines
Quoted 13 lines
fs/quota/dquot.c +1 -1
  	}
-	return err;
  }
 
  static inline void dqput_all(struct dquot **dquot)
@@ -2725,6 +2724,7 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
  {
  	struct mem_dqblk *dm = &dquot->dq_dqb;
  	int check_blim = 0, check_ilim = 0;
+	int ret;
  	struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type];
 
Quoted 13 lines

fs/quota/dquot.c static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di) · line 2813

Quoted 10 lines
fs/quota/dquot.c +4 -1
  	if (di->d_fieldmask & ~VFS_QC_MASK)
@@ -2807,7 +2807,10 @@ static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
  	else
  		set_bit(DQ_FAKE_B, &dquot->dq_flags);
  	spin_unlock(&dquot->dq_dqb_lock);
-	mark_dquot_dirty(dquot);
+	ret = mark_dquot_dirty(dquot);
+	if (ret < 0)
+		quota_error(dquot->dq_sb,
+			"mark_dquot_dirty fails, ret: %d", ret);

Here, we can propagate the error back to userspace, which is probably better than spamming the logs.

Yes, let me submit a new patch for this.

Thanks,

Quoted 2 lines

Honza