linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: linux-ext4@vger.kernel.org
Subject: [RFC PATCH 2/2] ext4: undo ei->i_da_metadata_calc_len increment if we fail to claim space
Date: Mon, 02 Apr 2012 11:14:20 -0400	[thread overview]
Message-ID: <4F79C24C.7070907@redhat.com> (raw)

From: Brian Foster <bfoster@redhat.com>

If we call ext4_calc_metadata_amount() and then fail to claim
the space, a subsequent successful request to a block covered
by the same ext2 indirect block will set md_needed to 0, fail
to update the associated counters and result in a delayed md
block allocation without a reservation. Decrement
i_da_metadata_calc_len on failure to ensure the next
reservation sets md_needed correctly.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 fs/ext4/inode.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index b58845c..7d2a3c0 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1138,13 +1138,14 @@ repeat:
 	 * We do still charge estimated metadata to the sb though;
 	 * we cannot afford to run out of free blocks.
 	 */
-	if (ext4_claim_free_clusters(sbi, md_needed + 1, 0)) {
+	ret = ext4_claim_free_clusters(sbi, md_needed + 1, 0);
+	if (ret) {
 		dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1));
 		if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
 			yield();
 			goto repeat;
 		}
-		return -ENOSPC;
+		goto error;
 	}
 	spin_lock(&ei->i_block_reservation_lock);
 	ei->i_reserved_data_blocks++;
@@ -1152,6 +1153,19 @@ repeat:
 	spin_unlock(&ei->i_block_reservation_lock);
 
 	return 0;       /* success */
+
+error:
+	/*
+	 * We've failed to reserve the space. Undo the effect
+	 * of ext4_calc_metadata_amount() to ensure the next
+	 * attempt correctly accounts for metadata.
+	 */
+	spin_lock(&ei->i_block_reservation_lock);
+	if (ei->i_da_metadata_calc_len)
+		ei->i_da_metadata_calc_len--;
+	spin_unlock(&ei->i_block_reservation_lock);
+
+	return ret;
 }
 
 static void ext4_da_release_space(struct inode *inode, int to_free)
-- 
1.7.7.6


             reply	other threads:[~2012-04-02 15:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-02 15:14 Brian Foster [this message]
2012-07-23  4:18 ` [RFC PATCH 2/2] ext4: undo ei->i_da_metadata_calc_len increment if we fail to claim space Theodore Ts'o
2012-07-23 15:46   ` Brian Foster

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=4F79C24C.7070907@redhat.com \
    --to=bfoster@redhat.com \
    --cc=linux-ext4@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).