Commit 742ba02a51c8d0bf5446b154531179760c1ed0a2
Committed by
Linus Torvalds
1 parent
3f2587bb22
Exists in
master
and in
7 other branches
udf: create common function for changing free space counter
Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com> Acked-by: Jan Kara <jack@suse.cz> Cc: Christoph Hellwig <hch@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 20 additions and 29 deletions Side-by-side Diff
fs/udf/balloc.c
... | ... | @@ -140,6 +140,20 @@ |
140 | 140 | return slot; |
141 | 141 | } |
142 | 142 | |
143 | +static bool udf_add_free_space(struct udf_sb_info *sbi, | |
144 | + u16 partition, u32 cnt) | |
145 | +{ | |
146 | + struct logicalVolIntegrityDesc *lvid; | |
147 | + | |
148 | + if (sbi->s_lvid_bh) | |
149 | + return false; | |
150 | + | |
151 | + lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | |
152 | + lvid->freeSpaceTable[partition] = cpu_to_le32(le32_to_cpu( | |
153 | + lvid->freeSpaceTable[partition]) + cnt); | |
154 | + return true; | |
155 | +} | |
156 | + | |
143 | 157 | static void udf_bitmap_free_blocks(struct super_block *sb, |
144 | 158 | struct inode *inode, |
145 | 159 | struct udf_bitmap *bitmap, |
... | ... | @@ -194,11 +208,7 @@ |
194 | 208 | } else { |
195 | 209 | if (inode) |
196 | 210 | DQUOT_FREE_BLOCK(inode, 1); |
197 | - if (sbi->s_lvid_bh) { | |
198 | - struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | |
199 | - lvid->freeSpaceTable[sbi->s_partition] = | |
200 | - cpu_to_le32(le32_to_cpu(lvid->freeSpaceTable[sbi->s_partition]) + 1); | |
201 | - } | |
211 | + udf_add_free_space(sbi, sbi->s_partition, 1); | |
202 | 212 | } |
203 | 213 | } |
204 | 214 | mark_buffer_dirty(bh); |
205 | 215 | |
... | ... | @@ -268,12 +278,8 @@ |
268 | 278 | if (block_count > 0) |
269 | 279 | goto repeat; |
270 | 280 | out: |
271 | - if (sbi->s_lvid_bh) { | |
272 | - struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | |
273 | - lvid->freeSpaceTable[partition] = | |
274 | - cpu_to_le32(le32_to_cpu(lvid->freeSpaceTable[partition]) - alloc_count); | |
281 | + if (udf_add_free_space(sbi, partition, -alloc_count)) | |
275 | 282 | mark_buffer_dirty(sbi->s_lvid_bh); |
276 | - } | |
277 | 283 | sb->s_dirt = 1; |
278 | 284 | mutex_unlock(&sbi->s_alloc_mutex); |
279 | 285 | return alloc_count; |
280 | 286 | |
... | ... | @@ -404,12 +410,8 @@ |
404 | 410 | |
405 | 411 | mark_buffer_dirty(bh); |
406 | 412 | |
407 | - if (sbi->s_lvid_bh) { | |
408 | - struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | |
409 | - lvid->freeSpaceTable[partition] = | |
410 | - cpu_to_le32(le32_to_cpu(lvid->freeSpaceTable[partition]) - 1); | |
413 | + if (udf_add_free_space(sbi, partition, -1)) | |
411 | 414 | mark_buffer_dirty(sbi->s_lvid_bh); |
412 | - } | |
413 | 415 | sb->s_dirt = 1; |
414 | 416 | mutex_unlock(&sbi->s_alloc_mutex); |
415 | 417 | *err = 0; |
416 | 418 | |
... | ... | @@ -450,12 +452,8 @@ |
450 | 452 | could occure, but.. oh well */ |
451 | 453 | if (inode) |
452 | 454 | DQUOT_FREE_BLOCK(inode, count); |
453 | - if (sbi->s_lvid_bh) { | |
454 | - struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | |
455 | - lvid->freeSpaceTable[sbi->s_partition] = | |
456 | - cpu_to_le32(le32_to_cpu(lvid->freeSpaceTable[sbi->s_partition]) + count); | |
455 | + if (udf_add_free_space(sbi, sbi->s_partition, count)) | |
457 | 456 | mark_buffer_dirty(sbi->s_lvid_bh); |
458 | - } | |
459 | 457 | |
460 | 458 | start = bloc.logicalBlockNum + offset; |
461 | 459 | end = bloc.logicalBlockNum + offset + count - 1; |
... | ... | @@ -719,10 +717,7 @@ |
719 | 717 | |
720 | 718 | brelse(epos.bh); |
721 | 719 | |
722 | - if (alloc_count && sbi->s_lvid_bh) { | |
723 | - struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | |
724 | - lvid->freeSpaceTable[partition] = | |
725 | - cpu_to_le32(le32_to_cpu(lvid->freeSpaceTable[partition]) - alloc_count); | |
720 | + if (alloc_count && udf_add_free_space(sbi, partition, -alloc_count)) { | |
726 | 721 | mark_buffer_dirty(sbi->s_lvid_bh); |
727 | 722 | sb->s_dirt = 1; |
728 | 723 | } |
729 | 724 | |
... | ... | @@ -822,12 +817,8 @@ |
822 | 817 | udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); |
823 | 818 | brelse(goal_epos.bh); |
824 | 819 | |
825 | - if (sbi->s_lvid_bh) { | |
826 | - struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; | |
827 | - lvid->freeSpaceTable[partition] = | |
828 | - cpu_to_le32(le32_to_cpu(lvid->freeSpaceTable[partition]) - 1); | |
820 | + if (udf_add_free_space(sbi, partition, -1)) | |
829 | 821 | mark_buffer_dirty(sbi->s_lvid_bh); |
830 | - } | |
831 | 822 | |
832 | 823 | sb->s_dirt = 1; |
833 | 824 | mutex_unlock(&sbi->s_alloc_mutex); |