Skip to content

Commit bac89bb

Browse files
fs/ntfs3: Accumulated refactoring changes
Changes made to improve readability and debuggability. Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 678c190 commit bac89bb

File tree

4 files changed

+21
-50
lines changed

4 files changed

+21
-50
lines changed

fs/ntfs3/bitmap.c

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -710,20 +710,17 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
710710
{
711711
int err = 0;
712712
struct super_block *sb = wnd->sb;
713-
size_t bits0 = bits;
714713
u32 wbits = 8 * sb->s_blocksize;
715714
size_t iw = bit >> (sb->s_blocksize_bits + 3);
716715
u32 wbit = bit & (wbits - 1);
717716
struct buffer_head *bh;
717+
u32 op;
718718

719-
while (iw < wnd->nwnd && bits) {
720-
u32 tail, op;
721-
719+
for (; iw < wnd->nwnd && bits; iw++, bit += op, bits -= op, wbit = 0) {
722720
if (iw + 1 == wnd->nwnd)
723721
wbits = wnd->bits_last;
724722

725-
tail = wbits - wbit;
726-
op = min_t(u32, tail, bits);
723+
op = min_t(u32, wbits - wbit, bits);
727724

728725
bh = wnd_map(wnd, iw);
729726
if (IS_ERR(bh)) {
@@ -736,20 +733,15 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
736733
ntfs_bitmap_clear_le(bh->b_data, wbit, op);
737734

738735
wnd->free_bits[iw] += op;
736+
wnd->total_zeroes += op;
739737

740738
set_buffer_uptodate(bh);
741739
mark_buffer_dirty(bh);
742740
unlock_buffer(bh);
743741
put_bh(bh);
744742

745-
wnd->total_zeroes += op;
746-
bits -= op;
747-
wbit = 0;
748-
iw += 1;
743+
wnd_add_free_ext(wnd, bit, op, false);
749744
}
750-
751-
wnd_add_free_ext(wnd, bit, bits0, false);
752-
753745
return err;
754746
}
755747

@@ -760,20 +752,17 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
760752
{
761753
int err = 0;
762754
struct super_block *sb = wnd->sb;
763-
size_t bits0 = bits;
764755
size_t iw = bit >> (sb->s_blocksize_bits + 3);
765756
u32 wbits = 8 * sb->s_blocksize;
766757
u32 wbit = bit & (wbits - 1);
767758
struct buffer_head *bh;
759+
u32 op;
768760

769-
while (iw < wnd->nwnd && bits) {
770-
u32 tail, op;
771-
761+
for (; iw < wnd->nwnd && bits; iw++, bit += op, bits -= op, wbit = 0) {
772762
if (unlikely(iw + 1 == wnd->nwnd))
773763
wbits = wnd->bits_last;
774764

775-
tail = wbits - wbit;
776-
op = min_t(u32, tail, bits);
765+
op = min_t(u32, wbits - wbit, bits);
777766

778767
bh = wnd_map(wnd, iw);
779768
if (IS_ERR(bh)) {
@@ -785,21 +774,16 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
785774

786775
ntfs_bitmap_set_le(bh->b_data, wbit, op);
787776
wnd->free_bits[iw] -= op;
777+
wnd->total_zeroes -= op;
788778

789779
set_buffer_uptodate(bh);
790780
mark_buffer_dirty(bh);
791781
unlock_buffer(bh);
792782
put_bh(bh);
793783

794-
wnd->total_zeroes -= op;
795-
bits -= op;
796-
wbit = 0;
797-
iw += 1;
784+
if (!RB_EMPTY_ROOT(&wnd->start_tree))
785+
wnd_remove_free_ext(wnd, bit, op);
798786
}
799-
800-
if (!RB_EMPTY_ROOT(&wnd->start_tree))
801-
wnd_remove_free_ext(wnd, bit, bits0);
802-
803787
return err;
804788
}
805789

@@ -852,15 +836,13 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
852836
size_t iw = bit >> (sb->s_blocksize_bits + 3);
853837
u32 wbits = 8 * sb->s_blocksize;
854838
u32 wbit = bit & (wbits - 1);
839+
u32 op;
855840

856-
while (iw < wnd->nwnd && bits) {
857-
u32 tail, op;
858-
841+
for (; iw < wnd->nwnd && bits; iw++, bits -= op, wbit = 0) {
859842
if (unlikely(iw + 1 == wnd->nwnd))
860843
wbits = wnd->bits_last;
861844

862-
tail = wbits - wbit;
863-
op = min_t(u32, tail, bits);
845+
op = min_t(u32, wbits - wbit, bits);
864846

865847
if (wbits != wnd->free_bits[iw]) {
866848
bool ret;
@@ -875,10 +857,6 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
875857
if (!ret)
876858
return false;
877859
}
878-
879-
bits -= op;
880-
wbit = 0;
881-
iw += 1;
882860
}
883861

884862
return true;
@@ -928,6 +906,7 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
928906
size_t iw = bit >> (sb->s_blocksize_bits + 3);
929907
u32 wbits = 8 * sb->s_blocksize;
930908
u32 wbit = bit & (wbits - 1);
909+
u32 op;
931910
size_t end;
932911
struct rb_node *n;
933912
struct e_node *e;
@@ -945,14 +924,11 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
945924
return false;
946925

947926
use_wnd:
948-
while (iw < wnd->nwnd && bits) {
949-
u32 tail, op;
950-
927+
for (; iw < wnd->nwnd && bits; iw++, bits -= op, wbit = 0) {
951928
if (unlikely(iw + 1 == wnd->nwnd))
952929
wbits = wnd->bits_last;
953930

954-
tail = wbits - wbit;
955-
op = min_t(u32, tail, bits);
931+
op = min_t(u32, wbits - wbit, bits);
956932

957933
if (wnd->free_bits[iw]) {
958934
bool ret;
@@ -966,10 +942,6 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
966942
if (!ret)
967943
goto out;
968944
}
969-
970-
bits -= op;
971-
wbit = 0;
972-
iw += 1;
973945
}
974946
ret = true;
975947

fs/ntfs3/frecord.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,6 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
19581958
if (end > alloc_size)
19591959
end = alloc_size;
19601960

1961-
19621961
while (vbo < end) {
19631962
if (idx == -1) {
19641963
ok = run_lookup_entry(&run, vcn, &lcn, &clen, &idx);

fs/ntfs3/fsntfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,4 +2699,4 @@ int ntfs_set_label(struct ntfs_sb_info *sbi, u8 *label, int len)
26992699
out:
27002700
__putname(uni);
27012701
return err;
2702-
}
2702+
}

fs/ntfs3/run.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,9 @@ int run_unpack_ex(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,
11121112
err = wnd_set_used_safe(wnd, lcn, len, &done);
11131113
if (zone) {
11141114
/* Restore zone. Lock mft run. */
1115-
struct rw_semaphore *lock;
1116-
lock = is_mounted(sbi) ? &sbi->mft.ni->file.run_lock :
1117-
NULL;
1115+
struct rw_semaphore *lock =
1116+
is_mounted(sbi) ? &sbi->mft.ni->file.run_lock :
1117+
NULL;
11181118
if (lock)
11191119
down_read(lock);
11201120
ntfs_refresh_zone(sbi);

0 commit comments

Comments
 (0)