Commit 04da11bf authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBIFS: fix zero-length truncations

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: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 6a55617e
...@@ -587,7 +587,6 @@ static int ubifs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -587,7 +587,6 @@ static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
if (err) { if (err) {
if (err != -ENOSPC) if (err != -ENOSPC)
return err; return err;
err = 0;
budgeted = 0; budgeted = 0;
} }
......
...@@ -793,7 +793,7 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode, ...@@ -793,7 +793,7 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
int err; int err;
struct ubifs_budget_req req; struct ubifs_budget_req req;
loff_t old_size = inode->i_size, new_size = attr->ia_size; 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); struct ubifs_inode *ui = ubifs_inode(inode);
dbg_gen("ino %lu, size %lld -> %lld", inode->i_ino, old_size, new_size); 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, ...@@ -811,8 +811,15 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
/* A funny way to budget for truncation node */ /* A funny way to budget for truncation node */
req.dirtied_ino_d = UBIFS_TRUN_NODE_SZ; req.dirtied_ino_d = UBIFS_TRUN_NODE_SZ;
err = ubifs_budget_space(c, &req); err = ubifs_budget_space(c, &req);
if (err) if (err) {
return 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); err = vmtruncate(inode, new_size);
if (err) if (err)
...@@ -869,7 +876,12 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode, ...@@ -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); err = ubifs_jnl_truncate(c, inode, old_size, new_size);
mutex_unlock(&ui->ui_mutex); mutex_unlock(&ui->ui_mutex);
out_budg: 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; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment