Skip to content

Commit a8b0c9f

Browse files
fs/ntfs3: Fix multithreaded stress test
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 865e7a7 commit a8b0c9f

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

fs/ntfs3/attrib.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
886886
struct runs_tree *run = &ni->file.run;
887887
struct ntfs_sb_info *sbi;
888888
u8 cluster_bits;
889-
struct ATTRIB *attr = NULL, *attr_b;
889+
struct ATTRIB *attr, *attr_b;
890890
struct ATTR_LIST_ENTRY *le, *le_b;
891891
struct mft_inode *mi, *mi_b;
892892
CLST hint, svcn, to_alloc, evcn1, next_svcn, asize, end, vcn0, alen;
@@ -904,12 +904,8 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
904904
*len = 0;
905905
up_read(&ni->file.run_lock);
906906

907-
if (*len) {
908-
if (*lcn != SPARSE_LCN || !new)
909-
return 0; /* Fast normal way without allocation. */
910-
else if (clen > *len)
911-
clen = *len;
912-
}
907+
if (*len && (*lcn != SPARSE_LCN || !new))
908+
return 0; /* Fast normal way without allocation. */
913909

914910
/* No cluster in cache or we need to allocate cluster in hole. */
915911
sbi = ni->mi.sbi;
@@ -918,6 +914,17 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
918914
ni_lock(ni);
919915
down_write(&ni->file.run_lock);
920916

917+
/* Repeat the code above (under write lock). */
918+
if (!run_lookup_entry(run, vcn, lcn, len, NULL))
919+
*len = 0;
920+
921+
if (*len) {
922+
if (*lcn != SPARSE_LCN || !new)
923+
goto out; /* normal way without allocation. */
924+
if (clen > *len)
925+
clen = *len;
926+
}
927+
921928
le_b = NULL;
922929
attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL, 0, NULL, &mi_b);
923930
if (!attr_b) {

0 commit comments

Comments
 (0)