Skip to content

Commit 40bb3c5

Browse files
fs/ntfs3: Always make file nonresident on fallocate call
xfstest 438 is starting to pass with this change. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent c935c66 commit 40bb3c5

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

fs/ntfs3/attrib.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,3 +2558,35 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
25582558

25592559
goto out;
25602560
}
2561+
2562+
/*
2563+
* attr_force_nonresident
2564+
*
2565+
* Convert default data attribute into non resident form.
2566+
*/
2567+
int attr_force_nonresident(struct ntfs_inode *ni)
2568+
{
2569+
int err;
2570+
struct ATTRIB *attr;
2571+
struct ATTR_LIST_ENTRY *le = NULL;
2572+
struct mft_inode *mi;
2573+
2574+
attr = ni_find_attr(ni, NULL, &le, ATTR_DATA, NULL, 0, NULL, &mi);
2575+
if (!attr) {
2576+
ntfs_bad_inode(&ni->vfs_inode, "no data attribute");
2577+
return -ENOENT;
2578+
}
2579+
2580+
if (attr->non_res) {
2581+
/* Already non resident. */
2582+
return 0;
2583+
}
2584+
2585+
down_write(&ni->file.run_lock);
2586+
err = attr_make_nonresident(ni, attr, le, mi,
2587+
le32_to_cpu(attr->res.data_size),
2588+
&ni->file.run, &attr, NULL);
2589+
up_write(&ni->file.run_lock);
2590+
2591+
return err;
2592+
}

fs/ntfs3/file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,15 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
578578
/* Check new size. */
579579
u8 cluster_bits = sbi->cluster_bits;
580580

581+
/* Be sure file is non resident. */
582+
if (is_resident(ni)) {
583+
ni_lock(ni);
584+
err = attr_force_nonresident(ni);
585+
ni_unlock(ni);
586+
if (err)
587+
goto out;
588+
}
589+
581590
/* generic/213: expected -ENOSPC instead of -EFBIG. */
582591
if (!is_supported_holes) {
583592
loff_t to_alloc = new_size - inode_get_bytes(inode);

fs/ntfs3/ntfs_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
452452
int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes);
453453
int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes);
454454
int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes, u32 *frame_size);
455+
int attr_force_nonresident(struct ntfs_inode *ni);
455456

456457
/* Functions from attrlist.c */
457458
void al_destroy(struct ntfs_inode *ni);

0 commit comments

Comments
 (0)