mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind@infradead.org>
To: linux-fsdevel-owner@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Adrian Hunter <ext-adrian.hunter@nokia.com>
Subject: [PATCH] UBIFS: fix zero-length truncations
Date: Sun, 31 Aug 2008 17:52:35 +0300	[thread overview]
Message-ID: <1220194366-12731-2-git-send-email-dedekind@infradead.org> (raw)
In-Reply-To: <1220194366-12731-1-git-send-email-dedekind@infradead.org>

From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

Always allow truncations to zero, even if budgeting thinks there
is no space. UBIFS reserves some space for deletions anyway.

Otherwise, the following happans:
1. create a file, and write as much as possible there, until ENOSPC
2. truncate the file, which fails with ENOSPC, which is not good.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 fs/ubifs/dir.c  |    1 -
 fs/ubifs/file.c |   20 ++++++++++++++++----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 5c96f1f..2b267c9 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -587,7 +587,6 @@ static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
 	if (err) {
 		if (err != -ENOSPC)
 			return err;
-		err = 0;
 		budgeted = 0;
 	}
 
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 4071d1c..3d698e2 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -793,7 +793,7 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
 	int err;
 	struct ubifs_budget_req req;
 	loff_t old_size = inode->i_size, new_size = attr->ia_size;
-	int offset = new_size & (UBIFS_BLOCK_SIZE - 1);
+	int offset = new_size & (UBIFS_BLOCK_SIZE - 1), budgeted = 1;
 	struct ubifs_inode *ui = ubifs_inode(inode);
 
 	dbg_gen("ino %lu, size %lld -> %lld", inode->i_ino, old_size, new_size);
@@ -811,8 +811,15 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
 	/* A funny way to budget for truncation node */
 	req.dirtied_ino_d = UBIFS_TRUN_NODE_SZ;
 	err = ubifs_budget_space(c, &req);
-	if (err)
-		return err;
+	if (err) {
+		/*
+		 * Treat truncations to zero as deletion and always allow them,
+		 * just like we do for '->unlink()'.
+		 */
+		if (new_size || err != -ENOSPC)
+			return err;
+		budgeted = 0;
+	}
 
 	err = vmtruncate(inode, new_size);
 	if (err)
@@ -869,7 +876,12 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
 	err = ubifs_jnl_truncate(c, inode, old_size, new_size);
 	mutex_unlock(&ui->ui_mutex);
 out_budg:
-	ubifs_release_budget(c, &req);
+	if (budgeted)
+		ubifs_release_budget(c, &req);
+	else {
+		c->nospace = c->nospace_rp = 0;
+		smp_wmb();
+	}
 	return err;
 }
 
-- 
1.5.4.1


  parent reply	other threads:[~2008-08-31 13:15 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-31 14:52 UBIFS updates for 2.6.27 Artem Bityutskiy
2008-08-31 14:32 ` Artem Bityutskiy
2008-08-31 14:52 ` Artem Bityutskiy [this message]
2008-08-31 14:52 ` [PATCH] UBIFS: always read hashed-key nodes under TNC mutex Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: allow for racing between GC and TNC Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: do not update min_idx_lebs in stafs Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: push empty flash hack down Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: remove incorrect index space check Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: improve statfs reporting Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: fix assertion Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: add forgotten gc_idx_lebs component Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: introduce LEB overhead Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: improve statfs reporting even more Artem Bityutskiy
2008-08-31 14:52 ` [PATCH] UBIFS: fill f_fsid Artem Bityutskiy
2008-09-01  9:43   ` David Woodhouse
2008-09-01 11:16     ` Artem Bityutskiy
2008-09-01 11:28       ` David Woodhouse
2008-09-01 11:43         ` Artem Bityutskiy
2008-09-01 11:50           ` David Woodhouse
2008-09-01 11:56             ` Artem Bityutskiy
2008-09-01 15:01     ` Christoph Hellwig
2008-09-02  7:03       ` Artem Bityutskiy
2008-09-02 17:09         ` Andreas Dilger
2008-09-02 17:29           ` David Woodhouse
2008-09-02 19:13             ` Andreas Dilger
2008-09-02 19:32               ` David Woodhouse
2008-09-02 21:02           ` Christoph Hellwig
2008-09-02 21:26             ` David Woodhouse
2008-09-02 21:48               ` Christoph Hellwig
2008-09-02 22:12                 ` David Woodhouse
2008-09-03  6:20               ` Artem Bityutskiy
2008-09-02 22:32             ` David Woodhouse
2008-09-03  9:44     ` Artem Bityutskiy
2008-09-03 10:14       ` David Woodhouse

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=1220194366-12731-2-git-send-email-dedekind@infradead.org \
    --to=dedekind@infradead.org \
    --cc=ext-adrian.hunter@nokia.com \
    --cc=linux-fsdevel-owner@vger.kernel.org \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®