linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org, Dmitry Monakhov <dmonakhov@openvz.org>
Subject: [PATCH 5/5] quota: handle IO errors in dquot_transfer()
Date: Mon, 14 Dec 2009 15:21:16 +0300	[thread overview]
Message-ID: <1260793276-8511-5-git-send-email-dmonakhov@openvz.org> (raw)
In-Reply-To: <1260793276-8511-4-git-send-email-dmonakhov@openvz.org>

transfer_to[cnt] = dqget() may returns NULL due to IO error.
But NULL value in transfer_to[cnt] means a dquot transfer
optimization. So after operation succeed inode will have new
i_uid or i_gid but accounted to old dquot. This behaviour
is differ from dquot_initialize(). Let's handle IO error from
dqget() equally in all functions.

In appliance to dquot_transfer() this means that we have to finish
operation regardless to IO errors from dqget().

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 fs/quota/dquot.c |   46 +++++++++++++++++++++++++++-------------------
 1 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index d6d535c..fbbaa4e 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -1733,27 +1733,29 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
 	struct dquot *transfer_from[MAXQUOTAS];
 	struct dquot *transfer_to[MAXQUOTAS];
 	int cnt, ret = QUOTA_OK;
-	int chuid = iattr->ia_valid & ATTR_UID && inode->i_uid != iattr->ia_uid,
-	    chgid = iattr->ia_valid & ATTR_GID && inode->i_gid != iattr->ia_gid;
 	char warntype_to[MAXQUOTAS];
 	char warntype_from_inodes[MAXQUOTAS], warntype_from_space[MAXQUOTAS];
+	char valid[MAXQUOTAS];
 
 	/* First test before acquiring mutex - solves deadlocks when we
          * re-enter the quota code and are already holding the mutex */
 	if (IS_NOQUOTA(inode))
 		return QUOTA_OK;
 	/* Initialize the arrays */
+	memset(transfer_to, 0, sizeof(transfer_to));
+	memset(transfer_from, 0, sizeof(transfer_from));
+	memset(valid, 0, sizeof(valid));
+	valid[USRQUOTA] = iattr->ia_valid & ATTR_UID &&
+		inode->i_uid != iattr->ia_uid,
+	valid[GRPQUOTA] = iattr->ia_valid & ATTR_GID &&
+		inode->i_gid != iattr->ia_gid;
+
 	for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
-		transfer_from[cnt] = NULL;
-		transfer_to[cnt] = NULL;
 		warntype_to[cnt] = QUOTA_NL_NOWARN;
+		if (!valid[cnt])
+			continue;
+		transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt);
 	}
-	if (chuid)
-		transfer_to[USRQUOTA] = dqget(inode->i_sb, iattr->ia_uid,
-					      USRQUOTA);
-	if (chgid)
-		transfer_to[GRPQUOTA] = dqget(inode->i_sb, iattr->ia_gid,
-					      GRPQUOTA);
 
 	down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
 	/* Now recheck reliably when holding dqptr_sem */
@@ -1767,9 +1769,11 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
 	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 (!valid[cnt])
 			continue;
 		transfer_from[cnt] = inode->i_dquot[cnt];
+		if (!transfer_to[cnt])
+			continue;
 		if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) ==
 		    NO_QUOTA || check_bdq(transfer_to[cnt], space, 0,
 		    warntype_to + cnt) == NO_QUOTA)
@@ -1783,10 +1787,15 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
 		/*
 		 * Skip changes for same uid or gid or for turned off quota-type.
 		 */
-		if (!transfer_to[cnt])
+		if (!valid[cnt])
 			continue;
+		/*
+		 * Due to IO error we might not have transfer_to[] or
+		 * transfer_from[] structure. Nor than less the operation must
+		 * being done regardless quota io errors.
+		 */
+		inode->i_dquot[cnt] = transfer_to[cnt];
 
-		/* Due to IO error we might not have transfer_from[] structure */
 		if (transfer_from[cnt]) {
 			warntype_from_inodes[cnt] =
 				info_idq_free(transfer_from[cnt], 1);
@@ -1797,12 +1806,11 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
 			dquot_free_reserved_space(transfer_from[cnt],
 						  rsv_space);
 		}
-
-		dquot_incr_inodes(transfer_to[cnt], 1);
-		dquot_incr_space(transfer_to[cnt], cur_space);
-		dquot_resv_space(transfer_to[cnt], rsv_space);
-
-		inode->i_dquot[cnt] = transfer_to[cnt];
+		if (transfer_to[cnt]) {
+			dquot_incr_inodes(transfer_to[cnt], 1);
+			dquot_incr_space(transfer_to[cnt], cur_space);
+			dquot_resv_space(transfer_to[cnt], rsv_space);
+		}
 	}
 	spin_unlock(&dq_data_lock);
 	up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
-- 
1.6.0.4


  reply	other threads:[~2009-12-14 12:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-14 12:21 [PATCH 1/5] Add unlocked version of inode_add_bytes() function Dmitry Monakhov
2009-12-14 12:21 ` [PATCH 2/5] quota: decouple fs reserved space from quota reservation. [V5] Dmitry Monakhov
2009-12-14 12:21   ` [PATCH 3/5] ext4: Convert to generic reserved quota's space management. [V5] Dmitry Monakhov
2009-12-14 12:21     ` [PATCH 4/5] quota: Move duplicated code to separate functions Dmitry Monakhov
2009-12-14 12:21       ` Dmitry Monakhov [this message]
2009-12-14 18:41         ` [PATCH 5/5] quota: handle IO errors in dquot_transfer() Jan Kara
2009-12-14 22:43           ` Dmitry Monakhov
2009-12-15 11:49             ` Jan Kara
2009-12-14 18:00       ` [PATCH 4/5] quota: Move duplicated code to separate functions Jan Kara
2009-12-14 14:35     ` [PATCH 3/5] ext4: Convert to generic reserved quota's space management. [V5] tytso
2009-12-14 17:26       ` Jan Kara
2009-12-14 17:25     ` Jan Kara
2009-12-14 17:24   ` [PATCH 2/5] quota: decouple fs reserved space from quota reservation. [V5] Jan Kara
2009-12-14 17:21 ` [PATCH 1/5] Add unlocked version of inode_add_bytes() function Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1260793276-8511-5-git-send-email-dmonakhov@openvz.org \
    --to=dmonakhov@openvz.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).