aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ufs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2015-06-18 02:18:54 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2015-07-06 17:39:44 -0400
commita138b4b688c10eb82044451b81534c382d1cddbd (patch)
treed5a9aeb84133d5c61ebbe7a1ca05e55e65880328 /fs/ufs
parenta96574233c5d2e50736d83abf65161ec5fa55852 (diff)
ufs: unify the logics for collecting adjacent data blocks to free
open-coded in several places... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/ufs')
-rw-r--r--fs/ufs/inode.c56
1 files changed, 22 insertions, 34 deletions
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 480c34ee1805..39de7782b7c5 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -960,6 +960,22 @@ void ufs_evict_inode(struct inode * inode)
960 ufs_free_inode(inode); 960 ufs_free_inode(inode);
961} 961}
962 962
963struct to_free {
964 struct inode *inode;
965 u64 to;
966 unsigned count;
967};
968
969static inline void free_data(struct to_free *ctx, u64 from, unsigned count)
970{
971 if (ctx->count && ctx->to != from) {
972 ufs_free_blocks(ctx->inode, ctx->to - ctx->count, ctx->count);
973 ctx->count = 0;
974 }
975 ctx->count += count;
976 ctx->to = from + count;
977}
978
963#define DIRECT_BLOCK ((inode->i_size + uspi->s_bsize - 1) >> uspi->s_bshift) 979#define DIRECT_BLOCK ((inode->i_size + uspi->s_bsize - 1) >> uspi->s_bshift)
964#define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift) 980#define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize - 1) >> uspi->s_fshift)
965 981
@@ -970,7 +986,7 @@ static void ufs_trunc_direct(struct inode *inode)
970 struct ufs_sb_private_info * uspi; 986 struct ufs_sb_private_info * uspi;
971 void *p; 987 void *p;
972 u64 frag1, frag2, frag3, frag4, block1, block2; 988 u64 frag1, frag2, frag3, frag4, block1, block2;
973 unsigned frag_to_free, free_count; 989 struct to_free ctx = {.inode = inode};
974 unsigned i, tmp; 990 unsigned i, tmp;
975 991
976 UFSD("ENTER: ino %lu\n", inode->i_ino); 992 UFSD("ENTER: ino %lu\n", inode->i_ino);
@@ -978,9 +994,6 @@ static void ufs_trunc_direct(struct inode *inode)
978 sb = inode->i_sb; 994 sb = inode->i_sb;
979 uspi = UFS_SB(sb)->s_uspi; 995 uspi = UFS_SB(sb)->s_uspi;
980 996
981 frag_to_free = 0;
982 free_count = 0;
983
984 frag1 = DIRECT_FRAGMENT; 997 frag1 = DIRECT_FRAGMENT;
985 frag4 = min_t(u64, UFS_NDIR_FRAGMENT, ufsi->i_lastfrag); 998 frag4 = min_t(u64, UFS_NDIR_FRAGMENT, ufsi->i_lastfrag);
986 frag2 = ((frag1 & uspi->s_fpbmask) ? ((frag1 | uspi->s_fpbmask) + 1) : frag1); 999 frag2 = ((frag1 & uspi->s_fpbmask) ? ((frag1 | uspi->s_fpbmask) + 1) : frag1);
@@ -1015,7 +1028,6 @@ static void ufs_trunc_direct(struct inode *inode)
1015 1028
1016 ufs_free_fragments(inode, tmp + frag1, frag2); 1029 ufs_free_fragments(inode, tmp + frag1, frag2);
1017 mark_inode_dirty(inode); 1030 mark_inode_dirty(inode);
1018 frag_to_free = tmp + frag1;
1019 1031
1020next1: 1032next1:
1021 /* 1033 /*
@@ -1030,21 +1042,11 @@ next1:
1030 ufs_data_ptr_clear(uspi, p); 1042 ufs_data_ptr_clear(uspi, p);
1031 write_sequnlock(&ufsi->meta_lock); 1043 write_sequnlock(&ufsi->meta_lock);
1032 1044
1033 if (free_count == 0) { 1045 free_data(&ctx, tmp, uspi->s_fpb);
1034 frag_to_free = tmp;
1035 free_count = uspi->s_fpb;
1036 } else if (free_count > 0 && frag_to_free == tmp - free_count)
1037 free_count += uspi->s_fpb;
1038 else {
1039 ufs_free_blocks (inode, frag_to_free, free_count);
1040 frag_to_free = tmp;
1041 free_count = uspi->s_fpb;
1042 }
1043 mark_inode_dirty(inode); 1046 mark_inode_dirty(inode);
1044 } 1047 }
1045 1048
1046 if (free_count > 0) 1049 free_data(&ctx, 0, 0);
1047 ufs_free_blocks (inode, frag_to_free, free_count);
1048 1050
1049 if (frag3 >= frag4) 1051 if (frag3 >= frag4)
1050 goto next3; 1052 goto next3;
@@ -1102,8 +1104,7 @@ static void ufs_trunc_branch(struct inode *inode, unsigned *offsets, int depth2,
1102 ubh_mark_buffer_dirty(ubh); 1104 ubh_mark_buffer_dirty(ubh);
1103 } 1105 }
1104 } else { 1106 } else {
1105 u64 frag_to_free = 0; 1107 struct to_free ctx = {.inode = inode};
1106 unsigned free_count = 0;
1107 1108
1108 for (i = from; i < uspi->s_apb; i++) { 1109 for (i = from; i < uspi->s_apb; i++) {
1109 void *ind = ubh_get_data_ptr(uspi, ubh, i); 1110 void *ind = ubh_get_data_ptr(uspi, ubh, i);
@@ -1115,23 +1116,10 @@ static void ufs_trunc_branch(struct inode *inode, unsigned *offsets, int depth2,
1115 ufs_data_ptr_clear(uspi, ind); 1116 ufs_data_ptr_clear(uspi, ind);
1116 write_sequnlock(&UFS_I(inode)->meta_lock); 1117 write_sequnlock(&UFS_I(inode)->meta_lock);
1117 ubh_mark_buffer_dirty(ubh); 1118 ubh_mark_buffer_dirty(ubh);
1118 if (free_count == 0) { 1119 free_data(&ctx, tmp, uspi->s_fpb);
1119 frag_to_free = tmp;
1120 free_count = uspi->s_fpb;
1121 } else if (free_count > 0 && frag_to_free == tmp - free_count)
1122 free_count += uspi->s_fpb;
1123 else {
1124 ufs_free_blocks (inode, frag_to_free, free_count);
1125 frag_to_free = tmp;
1126 free_count = uspi->s_fpb;
1127 }
1128
1129 mark_inode_dirty(inode); 1120 mark_inode_dirty(inode);
1130 } 1121 }
1131 1122 free_data(&ctx, 0, 0);
1132 if (free_count > 0) {
1133 ufs_free_blocks (inode, frag_to_free, free_count);
1134 }
1135 } 1123 }
1136 if (free_it) { 1124 if (free_it) {
1137 tmp = ufs_data_ptr_to_cpu(sb, p); 1125 tmp = ufs_data_ptr_to_cpu(sb, p);