Skip to content

Commit 9eaaa2d

Browse files
committed
ext3: Fix truncation of symlinks after failed write
Contents of long symlinks is written via standard write methods. So when the write fails, we add inode to orphan list. But symlinks don't have .truncate method defined so nobody properly removes them from the orphan list (both on disk and in memory). Fix this by calling ext3_truncate() directly instead of calling vmtruncate() (which is saner anyway since we don't need anything vmtruncate() does except from calling .truncate in these paths). We also add inode to orphan list only if ext3_can_truncate() is true (currently, it can be false for symlinks when there are no blocks allocated) - otherwise orphan list processing will complain and ext3_truncate() will not remove inode from on-disk orphan list. Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 7447a66 commit 9eaaa2d

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

‎fs/ext3/inode.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,15 +1193,16 @@ static int ext3_write_begin(struct file *file, struct address_space *mapping,
11931193
* i_size_read because we hold i_mutex.
11941194
*
11951195
* Add inode to orphan list in case we crash before truncate
1196-
* finishes.
1196+
* finishes. Do this only if ext3_can_truncate() agrees so
1197+
* that orphan processing code is happy.
11971198
*/
1198-
if (pos + len > inode->i_size)
1199+
if (pos + len > inode->i_size && ext3_can_truncate(inode))
11991200
ext3_orphan_add(handle, inode);
12001201
ext3_journal_stop(handle);
12011202
unlock_page(page);
12021203
page_cache_release(page);
12031204
if (pos + len > inode->i_size)
1204-
vmtruncate(inode, inode->i_size);
1205+
ext3_truncate(inode);
12051206
}
12061207
if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries))
12071208
goto retry;
@@ -1287,7 +1288,7 @@ static int ext3_ordered_write_end(struct file *file,
12871288
* There may be allocated blocks outside of i_size because
12881289
* we failed to copy some data. Prepare for truncate.
12891290
*/
1290-
if (pos + len > inode->i_size)
1291+
if (pos + len > inode->i_size && ext3_can_truncate(inode))
12911292
ext3_orphan_add(handle, inode);
12921293
ret2 = ext3_journal_stop(handle);
12931294
if (!ret)
@@ -1296,7 +1297,7 @@ static int ext3_ordered_write_end(struct file *file,
12961297
page_cache_release(page);
12971298

12981299
if (pos + len > inode->i_size)
1299-
vmtruncate(inode, inode->i_size);
1300+
ext3_truncate(inode);
13001301
return ret ? ret : copied;
13011302
}
13021303

@@ -1315,14 +1316,14 @@ static int ext3_writeback_write_end(struct file *file,
13151316
* There may be allocated blocks outside of i_size because
13161317
* we failed to copy some data. Prepare for truncate.
13171318
*/
1318-
if (pos + len > inode->i_size)
1319+
if (pos + len > inode->i_size && ext3_can_truncate(inode))
13191320
ext3_orphan_add(handle, inode);
13201321
ret = ext3_journal_stop(handle);
13211322
unlock_page(page);
13221323
page_cache_release(page);
13231324

13241325
if (pos + len > inode->i_size)
1325-
vmtruncate(inode, inode->i_size);
1326+
ext3_truncate(inode);
13261327
return ret ? ret : copied;
13271328
}
13281329

@@ -1358,7 +1359,7 @@ static int ext3_journalled_write_end(struct file *file,
13581359
* There may be allocated blocks outside of i_size because
13591360
* we failed to copy some data. Prepare for truncate.
13601361
*/
1361-
if (pos + len > inode->i_size)
1362+
if (pos + len > inode->i_size && ext3_can_truncate(inode))
13621363
ext3_orphan_add(handle, inode);
13631364
EXT3_I(inode)->i_state |= EXT3_STATE_JDATA;
13641365
if (inode->i_size > EXT3_I(inode)->i_disksize) {
@@ -1375,7 +1376,7 @@ static int ext3_journalled_write_end(struct file *file,
13751376
page_cache_release(page);
13761377

13771378
if (pos + len > inode->i_size)
1378-
vmtruncate(inode, inode->i_size);
1379+
ext3_truncate(inode);
13791380
return ret ? ret : copied;
13801381
}
13811382

0 commit comments

Comments
 (0)