diff options
Diffstat (limited to 'fs/nilfs2/segment.c')
-rw-r--r-- | fs/nilfs2/segment.c | 306 |
1 files changed, 139 insertions, 167 deletions
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index d926af62617..afe4f218345 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c | |||
@@ -104,8 +104,7 @@ struct nilfs_sc_operations { | |||
104 | static void nilfs_segctor_start_timer(struct nilfs_sc_info *); | 104 | static void nilfs_segctor_start_timer(struct nilfs_sc_info *); |
105 | static void nilfs_segctor_do_flush(struct nilfs_sc_info *, int); | 105 | static void nilfs_segctor_do_flush(struct nilfs_sc_info *, int); |
106 | static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *); | 106 | static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *); |
107 | static void nilfs_dispose_list(struct nilfs_sb_info *, struct list_head *, | 107 | static void nilfs_dispose_list(struct the_nilfs *, struct list_head *, int); |
108 | int); | ||
109 | 108 | ||
110 | #define nilfs_cnt32_gt(a, b) \ | 109 | #define nilfs_cnt32_gt(a, b) \ |
111 | (typecheck(__u32, a) && typecheck(__u32, b) && \ | 110 | (typecheck(__u32, a) && typecheck(__u32, b) && \ |
@@ -182,7 +181,6 @@ int nilfs_transaction_begin(struct super_block *sb, | |||
182 | struct nilfs_transaction_info *ti, | 181 | struct nilfs_transaction_info *ti, |
183 | int vacancy_check) | 182 | int vacancy_check) |
184 | { | 183 | { |
185 | struct nilfs_sb_info *sbi; | ||
186 | struct the_nilfs *nilfs; | 184 | struct the_nilfs *nilfs; |
187 | int ret = nilfs_prepare_segment_lock(ti); | 185 | int ret = nilfs_prepare_segment_lock(ti); |
188 | 186 | ||
@@ -193,8 +191,7 @@ int nilfs_transaction_begin(struct super_block *sb, | |||
193 | 191 | ||
194 | vfs_check_frozen(sb, SB_FREEZE_WRITE); | 192 | vfs_check_frozen(sb, SB_FREEZE_WRITE); |
195 | 193 | ||
196 | sbi = NILFS_SB(sb); | 194 | nilfs = sb->s_fs_info; |
197 | nilfs = sbi->s_nilfs; | ||
198 | down_read(&nilfs->ns_segctor_sem); | 195 | down_read(&nilfs->ns_segctor_sem); |
199 | if (vacancy_check && nilfs_near_disk_full(nilfs)) { | 196 | if (vacancy_check && nilfs_near_disk_full(nilfs)) { |
200 | up_read(&nilfs->ns_segctor_sem); | 197 | up_read(&nilfs->ns_segctor_sem); |
@@ -225,8 +222,7 @@ int nilfs_transaction_begin(struct super_block *sb, | |||
225 | int nilfs_transaction_commit(struct super_block *sb) | 222 | int nilfs_transaction_commit(struct super_block *sb) |
226 | { | 223 | { |
227 | struct nilfs_transaction_info *ti = current->journal_info; | 224 | struct nilfs_transaction_info *ti = current->journal_info; |
228 | struct nilfs_sb_info *sbi; | 225 | struct the_nilfs *nilfs = sb->s_fs_info; |
229 | struct nilfs_sc_info *sci; | ||
230 | int err = 0; | 226 | int err = 0; |
231 | 227 | ||
232 | BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); | 228 | BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); |
@@ -235,16 +231,15 @@ int nilfs_transaction_commit(struct super_block *sb) | |||
235 | ti->ti_count--; | 231 | ti->ti_count--; |
236 | return 0; | 232 | return 0; |
237 | } | 233 | } |
238 | sbi = NILFS_SB(sb); | 234 | if (nilfs->ns_writer) { |
239 | sci = NILFS_SC(sbi); | 235 | struct nilfs_sc_info *sci = nilfs->ns_writer; |
240 | if (sci != NULL) { | 236 | |
241 | if (ti->ti_flags & NILFS_TI_COMMIT) | 237 | if (ti->ti_flags & NILFS_TI_COMMIT) |
242 | nilfs_segctor_start_timer(sci); | 238 | nilfs_segctor_start_timer(sci); |
243 | if (atomic_read(&sbi->s_nilfs->ns_ndirtyblks) > | 239 | if (atomic_read(&nilfs->ns_ndirtyblks) > sci->sc_watermark) |
244 | sci->sc_watermark) | ||
245 | nilfs_segctor_do_flush(sci, 0); | 240 | nilfs_segctor_do_flush(sci, 0); |
246 | } | 241 | } |
247 | up_read(&sbi->s_nilfs->ns_segctor_sem); | 242 | up_read(&nilfs->ns_segctor_sem); |
248 | current->journal_info = ti->ti_save; | 243 | current->journal_info = ti->ti_save; |
249 | 244 | ||
250 | if (ti->ti_flags & NILFS_TI_SYNC) | 245 | if (ti->ti_flags & NILFS_TI_SYNC) |
@@ -257,13 +252,14 @@ int nilfs_transaction_commit(struct super_block *sb) | |||
257 | void nilfs_transaction_abort(struct super_block *sb) | 252 | void nilfs_transaction_abort(struct super_block *sb) |
258 | { | 253 | { |
259 | struct nilfs_transaction_info *ti = current->journal_info; | 254 | struct nilfs_transaction_info *ti = current->journal_info; |
255 | struct the_nilfs *nilfs = sb->s_fs_info; | ||
260 | 256 | ||
261 | BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); | 257 | BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); |
262 | if (ti->ti_count > 0) { | 258 | if (ti->ti_count > 0) { |
263 | ti->ti_count--; | 259 | ti->ti_count--; |
264 | return; | 260 | return; |
265 | } | 261 | } |
266 | up_read(&NILFS_SB(sb)->s_nilfs->ns_segctor_sem); | 262 | up_read(&nilfs->ns_segctor_sem); |
267 | 263 | ||
268 | current->journal_info = ti->ti_save; | 264 | current->journal_info = ti->ti_save; |
269 | if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC) | 265 | if (ti->ti_flags & NILFS_TI_DYNAMIC_ALLOC) |
@@ -272,9 +268,8 @@ void nilfs_transaction_abort(struct super_block *sb) | |||
272 | 268 | ||
273 | void nilfs_relax_pressure_in_lock(struct super_block *sb) | 269 | void nilfs_relax_pressure_in_lock(struct super_block *sb) |
274 | { | 270 | { |
275 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 271 | struct the_nilfs *nilfs = sb->s_fs_info; |
276 | struct nilfs_sc_info *sci = NILFS_SC(sbi); | 272 | struct nilfs_sc_info *sci = nilfs->ns_writer; |
277 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
278 | 273 | ||
279 | if (!sci || !sci->sc_flush_request) | 274 | if (!sci || !sci->sc_flush_request) |
280 | return; | 275 | return; |
@@ -294,11 +289,13 @@ void nilfs_relax_pressure_in_lock(struct super_block *sb) | |||
294 | downgrade_write(&nilfs->ns_segctor_sem); | 289 | downgrade_write(&nilfs->ns_segctor_sem); |
295 | } | 290 | } |
296 | 291 | ||
297 | static void nilfs_transaction_lock(struct nilfs_sb_info *sbi, | 292 | static void nilfs_transaction_lock(struct super_block *sb, |
298 | struct nilfs_transaction_info *ti, | 293 | struct nilfs_transaction_info *ti, |
299 | int gcflag) | 294 | int gcflag) |
300 | { | 295 | { |
301 | struct nilfs_transaction_info *cur_ti = current->journal_info; | 296 | struct nilfs_transaction_info *cur_ti = current->journal_info; |
297 | struct the_nilfs *nilfs = sb->s_fs_info; | ||
298 | struct nilfs_sc_info *sci = nilfs->ns_writer; | ||
302 | 299 | ||
303 | WARN_ON(cur_ti); | 300 | WARN_ON(cur_ti); |
304 | ti->ti_flags = NILFS_TI_WRITER; | 301 | ti->ti_flags = NILFS_TI_WRITER; |
@@ -309,30 +306,31 @@ static void nilfs_transaction_lock(struct nilfs_sb_info *sbi, | |||
309 | current->journal_info = ti; | 306 | current->journal_info = ti; |
310 | 307 | ||
311 | for (;;) { | 308 | for (;;) { |
312 | down_write(&sbi->s_nilfs->ns_segctor_sem); | 309 | down_write(&nilfs->ns_segctor_sem); |
313 | if (!test_bit(NILFS_SC_PRIOR_FLUSH, &NILFS_SC(sbi)->sc_flags)) | 310 | if (!test_bit(NILFS_SC_PRIOR_FLUSH, &sci->sc_flags)) |
314 | break; | 311 | break; |
315 | 312 | ||
316 | nilfs_segctor_do_immediate_flush(NILFS_SC(sbi)); | 313 | nilfs_segctor_do_immediate_flush(sci); |
317 | 314 | ||
318 | up_write(&sbi->s_nilfs->ns_segctor_sem); | 315 | up_write(&nilfs->ns_segctor_sem); |
319 | yield(); | 316 | yield(); |
320 | } | 317 | } |
321 | if (gcflag) | 318 | if (gcflag) |
322 | ti->ti_flags |= NILFS_TI_GC; | 319 | ti->ti_flags |= NILFS_TI_GC; |
323 | } | 320 | } |
324 | 321 | ||
325 | static void nilfs_transaction_unlock(struct nilfs_sb_info *sbi) | 322 | static void nilfs_transaction_unlock(struct super_block *sb) |
326 | { | 323 | { |
327 | struct nilfs_transaction_info *ti = current->journal_info; | 324 | struct nilfs_transaction_info *ti = current->journal_info; |
325 | struct the_nilfs *nilfs = sb->s_fs_info; | ||
328 | 326 | ||
329 | BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); | 327 | BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); |
330 | BUG_ON(ti->ti_count > 0); | 328 | BUG_ON(ti->ti_count > 0); |
331 | 329 | ||
332 | up_write(&sbi->s_nilfs->ns_segctor_sem); | 330 | up_write(&nilfs->ns_segctor_sem); |
333 | current->journal_info = ti->ti_save; | 331 | current->journal_info = ti->ti_save; |
334 | if (!list_empty(&ti->ti_garbage)) | 332 | if (!list_empty(&ti->ti_garbage)) |
335 | nilfs_dispose_list(sbi, &ti->ti_garbage, 0); | 333 | nilfs_dispose_list(nilfs, &ti->ti_garbage, 0); |
336 | } | 334 | } |
337 | 335 | ||
338 | static void *nilfs_segctor_map_segsum_entry(struct nilfs_sc_info *sci, | 336 | static void *nilfs_segctor_map_segsum_entry(struct nilfs_sc_info *sci, |
@@ -430,7 +428,8 @@ static void nilfs_segctor_begin_finfo(struct nilfs_sc_info *sci, | |||
430 | nilfs_segctor_map_segsum_entry( | 428 | nilfs_segctor_map_segsum_entry( |
431 | sci, &sci->sc_binfo_ptr, sizeof(struct nilfs_finfo)); | 429 | sci, &sci->sc_binfo_ptr, sizeof(struct nilfs_finfo)); |
432 | 430 | ||
433 | if (inode->i_sb && !test_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags)) | 431 | if (NILFS_I(inode)->i_root && |
432 | !test_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags)) | ||
434 | set_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); | 433 | set_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags); |
435 | /* skip finfo */ | 434 | /* skip finfo */ |
436 | } | 435 | } |
@@ -504,17 +503,6 @@ static int nilfs_segctor_add_file_block(struct nilfs_sc_info *sci, | |||
504 | return err; | 503 | return err; |
505 | } | 504 | } |
506 | 505 | ||
507 | static int nilfs_handle_bmap_error(int err, const char *fname, | ||
508 | struct inode *inode, struct super_block *sb) | ||
509 | { | ||
510 | if (err == -EINVAL) { | ||
511 | nilfs_error(sb, fname, "broken bmap (inode=%lu)\n", | ||
512 | inode->i_ino); | ||
513 | err = -EIO; | ||
514 | } | ||
515 | return err; | ||
516 | } | ||
517 | |||
518 | /* | 506 | /* |
519 | * Callback functions that enumerate, mark, and collect dirty blocks | 507 | * Callback functions that enumerate, mark, and collect dirty blocks |
520 | */ | 508 | */ |
@@ -524,9 +512,8 @@ static int nilfs_collect_file_data(struct nilfs_sc_info *sci, | |||
524 | int err; | 512 | int err; |
525 | 513 | ||
526 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); | 514 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); |
527 | if (unlikely(err < 0)) | 515 | if (err < 0) |
528 | return nilfs_handle_bmap_error(err, __func__, inode, | 516 | return err; |
529 | sci->sc_super); | ||
530 | 517 | ||
531 | err = nilfs_segctor_add_file_block(sci, bh, inode, | 518 | err = nilfs_segctor_add_file_block(sci, bh, inode, |
532 | sizeof(struct nilfs_binfo_v)); | 519 | sizeof(struct nilfs_binfo_v)); |
@@ -539,13 +526,7 @@ static int nilfs_collect_file_node(struct nilfs_sc_info *sci, | |||
539 | struct buffer_head *bh, | 526 | struct buffer_head *bh, |
540 | struct inode *inode) | 527 | struct inode *inode) |
541 | { | 528 | { |
542 | int err; | 529 | return nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); |
543 | |||
544 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); | ||
545 | if (unlikely(err < 0)) | ||
546 | return nilfs_handle_bmap_error(err, __func__, inode, | ||
547 | sci->sc_super); | ||
548 | return 0; | ||
549 | } | 530 | } |
550 | 531 | ||
551 | static int nilfs_collect_file_bmap(struct nilfs_sc_info *sci, | 532 | static int nilfs_collect_file_bmap(struct nilfs_sc_info *sci, |
@@ -588,9 +569,8 @@ static int nilfs_collect_dat_data(struct nilfs_sc_info *sci, | |||
588 | int err; | 569 | int err; |
589 | 570 | ||
590 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); | 571 | err = nilfs_bmap_propagate(NILFS_I(inode)->i_bmap, bh); |
591 | if (unlikely(err < 0)) | 572 | if (err < 0) |
592 | return nilfs_handle_bmap_error(err, __func__, inode, | 573 | return err; |
593 | sci->sc_super); | ||
594 | 574 | ||
595 | err = nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64)); | 575 | err = nilfs_segctor_add_file_block(sci, bh, inode, sizeof(__le64)); |
596 | if (!err) | 576 | if (!err) |
@@ -732,7 +712,7 @@ static void nilfs_lookup_dirty_node_buffers(struct inode *inode, | |||
732 | } | 712 | } |
733 | } | 713 | } |
734 | 714 | ||
735 | static void nilfs_dispose_list(struct nilfs_sb_info *sbi, | 715 | static void nilfs_dispose_list(struct the_nilfs *nilfs, |
736 | struct list_head *head, int force) | 716 | struct list_head *head, int force) |
737 | { | 717 | { |
738 | struct nilfs_inode_info *ii, *n; | 718 | struct nilfs_inode_info *ii, *n; |
@@ -740,7 +720,7 @@ static void nilfs_dispose_list(struct nilfs_sb_info *sbi, | |||
740 | unsigned nv = 0; | 720 | unsigned nv = 0; |
741 | 721 | ||
742 | while (!list_empty(head)) { | 722 | while (!list_empty(head)) { |
743 | spin_lock(&sbi->s_inode_lock); | 723 | spin_lock(&nilfs->ns_inode_lock); |
744 | list_for_each_entry_safe(ii, n, head, i_dirty) { | 724 | list_for_each_entry_safe(ii, n, head, i_dirty) { |
745 | list_del_init(&ii->i_dirty); | 725 | list_del_init(&ii->i_dirty); |
746 | if (force) { | 726 | if (force) { |
@@ -751,14 +731,14 @@ static void nilfs_dispose_list(struct nilfs_sb_info *sbi, | |||
751 | } else if (test_bit(NILFS_I_DIRTY, &ii->i_state)) { | 731 | } else if (test_bit(NILFS_I_DIRTY, &ii->i_state)) { |
752 | set_bit(NILFS_I_QUEUED, &ii->i_state); | 732 | set_bit(NILFS_I_QUEUED, &ii->i_state); |
753 | list_add_tail(&ii->i_dirty, | 733 | list_add_tail(&ii->i_dirty, |
754 | &sbi->s_dirty_files); | 734 | &nilfs->ns_dirty_files); |
755 | continue; | 735 | continue; |
756 | } | 736 | } |
757 | ivec[nv++] = ii; | 737 | ivec[nv++] = ii; |
758 | if (nv == SC_N_INODEVEC) | 738 | if (nv == SC_N_INODEVEC) |
759 | break; | 739 | break; |
760 | } | 740 | } |
761 | spin_unlock(&sbi->s_inode_lock); | 741 | spin_unlock(&nilfs->ns_inode_lock); |
762 | 742 | ||
763 | for (pii = ivec; nv > 0; pii++, nv--) | 743 | for (pii = ivec; nv > 0; pii++, nv--) |
764 | iput(&(*pii)->vfs_inode); | 744 | iput(&(*pii)->vfs_inode); |
@@ -776,9 +756,8 @@ static int nilfs_test_metadata_dirty(struct the_nilfs *nilfs, | |||
776 | ret++; | 756 | ret++; |
777 | if (nilfs_mdt_fetch_dirty(nilfs->ns_sufile)) | 757 | if (nilfs_mdt_fetch_dirty(nilfs->ns_sufile)) |
778 | ret++; | 758 | ret++; |
779 | if (ret || nilfs_doing_gc()) | 759 | if ((ret || nilfs_doing_gc()) && nilfs_mdt_fetch_dirty(nilfs->ns_dat)) |
780 | if (nilfs_mdt_fetch_dirty(nilfs_dat_inode(nilfs))) | 760 | ret++; |
781 | ret++; | ||
782 | return ret; | 761 | return ret; |
783 | } | 762 | } |
784 | 763 | ||
@@ -792,34 +771,33 @@ static int nilfs_segctor_clean(struct nilfs_sc_info *sci) | |||
792 | 771 | ||
793 | static int nilfs_segctor_confirm(struct nilfs_sc_info *sci) | 772 | static int nilfs_segctor_confirm(struct nilfs_sc_info *sci) |
794 | { | 773 | { |
795 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 774 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
796 | int ret = 0; | 775 | int ret = 0; |
797 | 776 | ||
798 | if (nilfs_test_metadata_dirty(sbi->s_nilfs, sci->sc_root)) | 777 | if (nilfs_test_metadata_dirty(nilfs, sci->sc_root)) |
799 | set_bit(NILFS_SC_DIRTY, &sci->sc_flags); | 778 | set_bit(NILFS_SC_DIRTY, &sci->sc_flags); |
800 | 779 | ||
801 | spin_lock(&sbi->s_inode_lock); | 780 | spin_lock(&nilfs->ns_inode_lock); |
802 | if (list_empty(&sbi->s_dirty_files) && nilfs_segctor_clean(sci)) | 781 | if (list_empty(&nilfs->ns_dirty_files) && nilfs_segctor_clean(sci)) |
803 | ret++; | 782 | ret++; |
804 | 783 | ||
805 | spin_unlock(&sbi->s_inode_lock); | 784 | spin_unlock(&nilfs->ns_inode_lock); |
806 | return ret; | 785 | return ret; |
807 | } | 786 | } |
808 | 787 | ||
809 | static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci) | 788 | static void nilfs_segctor_clear_metadata_dirty(struct nilfs_sc_info *sci) |
810 | { | 789 | { |
811 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 790 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
812 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
813 | 791 | ||
814 | nilfs_mdt_clear_dirty(sci->sc_root->ifile); | 792 | nilfs_mdt_clear_dirty(sci->sc_root->ifile); |
815 | nilfs_mdt_clear_dirty(nilfs->ns_cpfile); | 793 | nilfs_mdt_clear_dirty(nilfs->ns_cpfile); |
816 | nilfs_mdt_clear_dirty(nilfs->ns_sufile); | 794 | nilfs_mdt_clear_dirty(nilfs->ns_sufile); |
817 | nilfs_mdt_clear_dirty(nilfs_dat_inode(nilfs)); | 795 | nilfs_mdt_clear_dirty(nilfs->ns_dat); |
818 | } | 796 | } |
819 | 797 | ||
820 | static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci) | 798 | static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci) |
821 | { | 799 | { |
822 | struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; | 800 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
823 | struct buffer_head *bh_cp; | 801 | struct buffer_head *bh_cp; |
824 | struct nilfs_checkpoint *raw_cp; | 802 | struct nilfs_checkpoint *raw_cp; |
825 | int err; | 803 | int err; |
@@ -843,8 +821,7 @@ static int nilfs_segctor_create_checkpoint(struct nilfs_sc_info *sci) | |||
843 | 821 | ||
844 | static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci) | 822 | static int nilfs_segctor_fill_in_checkpoint(struct nilfs_sc_info *sci) |
845 | { | 823 | { |
846 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 824 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
847 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
848 | struct buffer_head *bh_cp; | 825 | struct buffer_head *bh_cp; |
849 | struct nilfs_checkpoint *raw_cp; | 826 | struct nilfs_checkpoint *raw_cp; |
850 | int err; | 827 | int err; |
@@ -923,7 +900,7 @@ static void nilfs_segctor_fill_in_super_root(struct nilfs_sc_info *sci, | |||
923 | nilfs->ns_nongc_ctime : sci->sc_seg_ctime); | 900 | nilfs->ns_nongc_ctime : sci->sc_seg_ctime); |
924 | raw_sr->sr_flags = 0; | 901 | raw_sr->sr_flags = 0; |
925 | 902 | ||
926 | nilfs_write_inode_common(nilfs_dat_inode(nilfs), (void *)raw_sr + | 903 | nilfs_write_inode_common(nilfs->ns_dat, (void *)raw_sr + |
927 | NILFS_SR_DAT_OFFSET(isz), 1); | 904 | NILFS_SR_DAT_OFFSET(isz), 1); |
928 | nilfs_write_inode_common(nilfs->ns_cpfile, (void *)raw_sr + | 905 | nilfs_write_inode_common(nilfs->ns_cpfile, (void *)raw_sr + |
929 | NILFS_SR_CPFILE_OFFSET(isz), 1); | 906 | NILFS_SR_CPFILE_OFFSET(isz), 1); |
@@ -1068,8 +1045,7 @@ static int nilfs_segctor_scan_file_dsync(struct nilfs_sc_info *sci, | |||
1068 | 1045 | ||
1069 | static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode) | 1046 | static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode) |
1070 | { | 1047 | { |
1071 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 1048 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
1072 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
1073 | struct list_head *head; | 1049 | struct list_head *head; |
1074 | struct nilfs_inode_info *ii; | 1050 | struct nilfs_inode_info *ii; |
1075 | size_t ndone; | 1051 | size_t ndone; |
@@ -1179,7 +1155,7 @@ static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode) | |||
1179 | sci->sc_stage.scnt++; /* Fall through */ | 1155 | sci->sc_stage.scnt++; /* Fall through */ |
1180 | case NILFS_ST_DAT: | 1156 | case NILFS_ST_DAT: |
1181 | dat_stage: | 1157 | dat_stage: |
1182 | err = nilfs_segctor_scan_file(sci, nilfs_dat_inode(nilfs), | 1158 | err = nilfs_segctor_scan_file(sci, nilfs->ns_dat, |
1183 | &nilfs_sc_dat_ops); | 1159 | &nilfs_sc_dat_ops); |
1184 | if (unlikely(err)) | 1160 | if (unlikely(err)) |
1185 | break; | 1161 | break; |
@@ -1563,7 +1539,6 @@ nilfs_segctor_update_payload_blocknr(struct nilfs_sc_info *sci, | |||
1563 | return 0; | 1539 | return 0; |
1564 | 1540 | ||
1565 | failed_bmap: | 1541 | failed_bmap: |
1566 | err = nilfs_handle_bmap_error(err, __func__, inode, sci->sc_super); | ||
1567 | return err; | 1542 | return err; |
1568 | } | 1543 | } |
1569 | 1544 | ||
@@ -1609,7 +1584,7 @@ nilfs_copy_replace_page_buffers(struct page *page, struct list_head *out) | |||
1609 | kunmap_atomic(kaddr, KM_USER0); | 1584 | kunmap_atomic(kaddr, KM_USER0); |
1610 | 1585 | ||
1611 | if (!TestSetPageWriteback(clone_page)) | 1586 | if (!TestSetPageWriteback(clone_page)) |
1612 | inc_zone_page_state(clone_page, NR_WRITEBACK); | 1587 | account_page_writeback(clone_page); |
1613 | unlock_page(clone_page); | 1588 | unlock_page(clone_page); |
1614 | 1589 | ||
1615 | return 0; | 1590 | return 0; |
@@ -1783,6 +1758,7 @@ static void nilfs_clear_copied_buffers(struct list_head *list, int err) | |||
1783 | if (!err) { | 1758 | if (!err) { |
1784 | set_buffer_uptodate(bh); | 1759 | set_buffer_uptodate(bh); |
1785 | clear_buffer_dirty(bh); | 1760 | clear_buffer_dirty(bh); |
1761 | clear_buffer_delay(bh); | ||
1786 | clear_buffer_nilfs_volatile(bh); | 1762 | clear_buffer_nilfs_volatile(bh); |
1787 | } | 1763 | } |
1788 | brelse(bh); /* for b_assoc_buffers */ | 1764 | brelse(bh); /* for b_assoc_buffers */ |
@@ -1878,7 +1854,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
1878 | { | 1854 | { |
1879 | struct nilfs_segment_buffer *segbuf; | 1855 | struct nilfs_segment_buffer *segbuf; |
1880 | struct page *bd_page = NULL, *fs_page = NULL; | 1856 | struct page *bd_page = NULL, *fs_page = NULL; |
1881 | struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; | 1857 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
1882 | int update_sr = false; | 1858 | int update_sr = false; |
1883 | 1859 | ||
1884 | list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) { | 1860 | list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) { |
@@ -1909,6 +1885,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) | |||
1909 | b_assoc_buffers) { | 1885 | b_assoc_buffers) { |
1910 | set_buffer_uptodate(bh); | 1886 | set_buffer_uptodate(bh); |
1911 | clear_buffer_dirty(bh); | 1887 | clear_buffer_dirty(bh); |
1888 | clear_buffer_delay(bh); | ||
1912 | clear_buffer_nilfs_volatile(bh); | 1889 | clear_buffer_nilfs_volatile(bh); |
1913 | clear_buffer_nilfs_redirected(bh); | 1890 | clear_buffer_nilfs_redirected(bh); |
1914 | if (bh == segbuf->sb_super_root) { | 1891 | if (bh == segbuf->sb_super_root) { |
@@ -1981,30 +1958,30 @@ static int nilfs_segctor_wait(struct nilfs_sc_info *sci) | |||
1981 | return ret; | 1958 | return ret; |
1982 | } | 1959 | } |
1983 | 1960 | ||
1984 | static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci, | 1961 | static int nilfs_segctor_collect_dirty_files(struct nilfs_sc_info *sci, |
1985 | struct nilfs_sb_info *sbi) | 1962 | struct the_nilfs *nilfs) |
1986 | { | 1963 | { |
1987 | struct nilfs_inode_info *ii, *n; | 1964 | struct nilfs_inode_info *ii, *n; |
1988 | struct inode *ifile = sci->sc_root->ifile; | 1965 | struct inode *ifile = sci->sc_root->ifile; |
1989 | 1966 | ||
1990 | spin_lock(&sbi->s_inode_lock); | 1967 | spin_lock(&nilfs->ns_inode_lock); |
1991 | retry: | 1968 | retry: |
1992 | list_for_each_entry_safe(ii, n, &sbi->s_dirty_files, i_dirty) { | 1969 | list_for_each_entry_safe(ii, n, &nilfs->ns_dirty_files, i_dirty) { |
1993 | if (!ii->i_bh) { | 1970 | if (!ii->i_bh) { |
1994 | struct buffer_head *ibh; | 1971 | struct buffer_head *ibh; |
1995 | int err; | 1972 | int err; |
1996 | 1973 | ||
1997 | spin_unlock(&sbi->s_inode_lock); | 1974 | spin_unlock(&nilfs->ns_inode_lock); |
1998 | err = nilfs_ifile_get_inode_block( | 1975 | err = nilfs_ifile_get_inode_block( |
1999 | ifile, ii->vfs_inode.i_ino, &ibh); | 1976 | ifile, ii->vfs_inode.i_ino, &ibh); |
2000 | if (unlikely(err)) { | 1977 | if (unlikely(err)) { |
2001 | nilfs_warning(sbi->s_super, __func__, | 1978 | nilfs_warning(sci->sc_super, __func__, |
2002 | "failed to get inode block.\n"); | 1979 | "failed to get inode block.\n"); |
2003 | return err; | 1980 | return err; |
2004 | } | 1981 | } |
2005 | nilfs_mdt_mark_buffer_dirty(ibh); | 1982 | nilfs_mdt_mark_buffer_dirty(ibh); |
2006 | nilfs_mdt_mark_dirty(ifile); | 1983 | nilfs_mdt_mark_dirty(ifile); |
2007 | spin_lock(&sbi->s_inode_lock); | 1984 | spin_lock(&nilfs->ns_inode_lock); |
2008 | if (likely(!ii->i_bh)) | 1985 | if (likely(!ii->i_bh)) |
2009 | ii->i_bh = ibh; | 1986 | ii->i_bh = ibh; |
2010 | else | 1987 | else |
@@ -2017,18 +1994,18 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci, | |||
2017 | list_del(&ii->i_dirty); | 1994 | list_del(&ii->i_dirty); |
2018 | list_add_tail(&ii->i_dirty, &sci->sc_dirty_files); | 1995 | list_add_tail(&ii->i_dirty, &sci->sc_dirty_files); |
2019 | } | 1996 | } |
2020 | spin_unlock(&sbi->s_inode_lock); | 1997 | spin_unlock(&nilfs->ns_inode_lock); |
2021 | 1998 | ||
2022 | return 0; | 1999 | return 0; |
2023 | } | 2000 | } |
2024 | 2001 | ||
2025 | static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci, | 2002 | static void nilfs_segctor_drop_written_files(struct nilfs_sc_info *sci, |
2026 | struct nilfs_sb_info *sbi) | 2003 | struct the_nilfs *nilfs) |
2027 | { | 2004 | { |
2028 | struct nilfs_transaction_info *ti = current->journal_info; | 2005 | struct nilfs_transaction_info *ti = current->journal_info; |
2029 | struct nilfs_inode_info *ii, *n; | 2006 | struct nilfs_inode_info *ii, *n; |
2030 | 2007 | ||
2031 | spin_lock(&sbi->s_inode_lock); | 2008 | spin_lock(&nilfs->ns_inode_lock); |
2032 | list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) { | 2009 | list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) { |
2033 | if (!test_and_clear_bit(NILFS_I_UPDATED, &ii->i_state) || | 2010 | if (!test_and_clear_bit(NILFS_I_UPDATED, &ii->i_state) || |
2034 | test_bit(NILFS_I_DIRTY, &ii->i_state)) | 2011 | test_bit(NILFS_I_DIRTY, &ii->i_state)) |
@@ -2040,7 +2017,7 @@ static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci, | |||
2040 | list_del(&ii->i_dirty); | 2017 | list_del(&ii->i_dirty); |
2041 | list_add_tail(&ii->i_dirty, &ti->ti_garbage); | 2018 | list_add_tail(&ii->i_dirty, &ti->ti_garbage); |
2042 | } | 2019 | } |
2043 | spin_unlock(&sbi->s_inode_lock); | 2020 | spin_unlock(&nilfs->ns_inode_lock); |
2044 | } | 2021 | } |
2045 | 2022 | ||
2046 | /* | 2023 | /* |
@@ -2048,15 +2025,14 @@ static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci, | |||
2048 | */ | 2025 | */ |
2049 | static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) | 2026 | static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) |
2050 | { | 2027 | { |
2051 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 2028 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
2052 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
2053 | struct page *failed_page; | 2029 | struct page *failed_page; |
2054 | int err; | 2030 | int err; |
2055 | 2031 | ||
2056 | sci->sc_stage.scnt = NILFS_ST_INIT; | 2032 | sci->sc_stage.scnt = NILFS_ST_INIT; |
2057 | sci->sc_cno = nilfs->ns_cno; | 2033 | sci->sc_cno = nilfs->ns_cno; |
2058 | 2034 | ||
2059 | err = nilfs_segctor_check_in_files(sci, sbi); | 2035 | err = nilfs_segctor_collect_dirty_files(sci, nilfs); |
2060 | if (unlikely(err)) | 2036 | if (unlikely(err)) |
2061 | goto out; | 2037 | goto out; |
2062 | 2038 | ||
@@ -2134,7 +2110,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode) | |||
2134 | } while (sci->sc_stage.scnt != NILFS_ST_DONE); | 2110 | } while (sci->sc_stage.scnt != NILFS_ST_DONE); |
2135 | 2111 | ||
2136 | out: | 2112 | out: |
2137 | nilfs_segctor_check_out_files(sci, sbi); | 2113 | nilfs_segctor_drop_written_files(sci, nilfs); |
2138 | return err; | 2114 | return err; |
2139 | 2115 | ||
2140 | failed_to_write: | 2116 | failed_to_write: |
@@ -2187,8 +2163,8 @@ static void nilfs_segctor_do_flush(struct nilfs_sc_info *sci, int bn) | |||
2187 | */ | 2163 | */ |
2188 | void nilfs_flush_segment(struct super_block *sb, ino_t ino) | 2164 | void nilfs_flush_segment(struct super_block *sb, ino_t ino) |
2189 | { | 2165 | { |
2190 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 2166 | struct the_nilfs *nilfs = sb->s_fs_info; |
2191 | struct nilfs_sc_info *sci = NILFS_SC(sbi); | 2167 | struct nilfs_sc_info *sci = nilfs->ns_writer; |
2192 | 2168 | ||
2193 | if (!sci || nilfs_doing_construction()) | 2169 | if (!sci || nilfs_doing_construction()) |
2194 | return; | 2170 | return; |
@@ -2277,8 +2253,8 @@ static void nilfs_segctor_wakeup(struct nilfs_sc_info *sci, int err) | |||
2277 | */ | 2253 | */ |
2278 | int nilfs_construct_segment(struct super_block *sb) | 2254 | int nilfs_construct_segment(struct super_block *sb) |
2279 | { | 2255 | { |
2280 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 2256 | struct the_nilfs *nilfs = sb->s_fs_info; |
2281 | struct nilfs_sc_info *sci = NILFS_SC(sbi); | 2257 | struct nilfs_sc_info *sci = nilfs->ns_writer; |
2282 | struct nilfs_transaction_info *ti; | 2258 | struct nilfs_transaction_info *ti; |
2283 | int err; | 2259 | int err; |
2284 | 2260 | ||
@@ -2315,8 +2291,8 @@ int nilfs_construct_segment(struct super_block *sb) | |||
2315 | int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode, | 2291 | int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode, |
2316 | loff_t start, loff_t end) | 2292 | loff_t start, loff_t end) |
2317 | { | 2293 | { |
2318 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 2294 | struct the_nilfs *nilfs = sb->s_fs_info; |
2319 | struct nilfs_sc_info *sci = NILFS_SC(sbi); | 2295 | struct nilfs_sc_info *sci = nilfs->ns_writer; |
2320 | struct nilfs_inode_info *ii; | 2296 | struct nilfs_inode_info *ii; |
2321 | struct nilfs_transaction_info ti; | 2297 | struct nilfs_transaction_info ti; |
2322 | int err = 0; | 2298 | int err = 0; |
@@ -2324,33 +2300,33 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode, | |||
2324 | if (!sci) | 2300 | if (!sci) |
2325 | return -EROFS; | 2301 | return -EROFS; |
2326 | 2302 | ||
2327 | nilfs_transaction_lock(sbi, &ti, 0); | 2303 | nilfs_transaction_lock(sb, &ti, 0); |
2328 | 2304 | ||
2329 | ii = NILFS_I(inode); | 2305 | ii = NILFS_I(inode); |
2330 | if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) || | 2306 | if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) || |
2331 | nilfs_test_opt(sbi, STRICT_ORDER) || | 2307 | nilfs_test_opt(nilfs, STRICT_ORDER) || |
2332 | test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) || | 2308 | test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) || |
2333 | nilfs_discontinued(sbi->s_nilfs)) { | 2309 | nilfs_discontinued(nilfs)) { |
2334 | nilfs_transaction_unlock(sbi); | 2310 | nilfs_transaction_unlock(sb); |
2335 | err = nilfs_segctor_sync(sci); | 2311 | err = nilfs_segctor_sync(sci); |
2336 | return err; | 2312 | return err; |
2337 | } | 2313 | } |
2338 | 2314 | ||
2339 | spin_lock(&sbi->s_inode_lock); | 2315 | spin_lock(&nilfs->ns_inode_lock); |
2340 | if (!test_bit(NILFS_I_QUEUED, &ii->i_state) && | 2316 | if (!test_bit(NILFS_I_QUEUED, &ii->i_state) && |
2341 | !test_bit(NILFS_I_BUSY, &ii->i_state)) { | 2317 | !test_bit(NILFS_I_BUSY, &ii->i_state)) { |
2342 | spin_unlock(&sbi->s_inode_lock); | 2318 | spin_unlock(&nilfs->ns_inode_lock); |
2343 | nilfs_transaction_unlock(sbi); | 2319 | nilfs_transaction_unlock(sb); |
2344 | return 0; | 2320 | return 0; |
2345 | } | 2321 | } |
2346 | spin_unlock(&sbi->s_inode_lock); | 2322 | spin_unlock(&nilfs->ns_inode_lock); |
2347 | sci->sc_dsync_inode = ii; | 2323 | sci->sc_dsync_inode = ii; |
2348 | sci->sc_dsync_start = start; | 2324 | sci->sc_dsync_start = start; |
2349 | sci->sc_dsync_end = end; | 2325 | sci->sc_dsync_end = end; |
2350 | 2326 | ||
2351 | err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC); | 2327 | err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC); |
2352 | 2328 | ||
2353 | nilfs_transaction_unlock(sbi); | 2329 | nilfs_transaction_unlock(sb); |
2354 | return err; | 2330 | return err; |
2355 | } | 2331 | } |
2356 | 2332 | ||
@@ -2406,8 +2382,7 @@ static void nilfs_segctor_notify(struct nilfs_sc_info *sci, int mode, int err) | |||
2406 | */ | 2382 | */ |
2407 | static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) | 2383 | static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) |
2408 | { | 2384 | { |
2409 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 2385 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
2410 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
2411 | struct nilfs_super_block **sbp; | 2386 | struct nilfs_super_block **sbp; |
2412 | int err = 0; | 2387 | int err = 0; |
2413 | 2388 | ||
@@ -2425,11 +2400,12 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) | |||
2425 | nilfs_discontinued(nilfs)) { | 2400 | nilfs_discontinued(nilfs)) { |
2426 | down_write(&nilfs->ns_sem); | 2401 | down_write(&nilfs->ns_sem); |
2427 | err = -EIO; | 2402 | err = -EIO; |
2428 | sbp = nilfs_prepare_super(sbi, | 2403 | sbp = nilfs_prepare_super(sci->sc_super, |
2429 | nilfs_sb_will_flip(nilfs)); | 2404 | nilfs_sb_will_flip(nilfs)); |
2430 | if (likely(sbp)) { | 2405 | if (likely(sbp)) { |
2431 | nilfs_set_log_cursor(sbp[0], nilfs); | 2406 | nilfs_set_log_cursor(sbp[0], nilfs); |
2432 | err = nilfs_commit_super(sbi, NILFS_SB_COMMIT); | 2407 | err = nilfs_commit_super(sci->sc_super, |
2408 | NILFS_SB_COMMIT); | ||
2433 | } | 2409 | } |
2434 | up_write(&nilfs->ns_sem); | 2410 | up_write(&nilfs->ns_sem); |
2435 | } | 2411 | } |
@@ -2461,16 +2437,15 @@ nilfs_remove_written_gcinodes(struct the_nilfs *nilfs, struct list_head *head) | |||
2461 | int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | 2437 | int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, |
2462 | void **kbufs) | 2438 | void **kbufs) |
2463 | { | 2439 | { |
2464 | struct nilfs_sb_info *sbi = NILFS_SB(sb); | 2440 | struct the_nilfs *nilfs = sb->s_fs_info; |
2465 | struct nilfs_sc_info *sci = NILFS_SC(sbi); | 2441 | struct nilfs_sc_info *sci = nilfs->ns_writer; |
2466 | struct the_nilfs *nilfs = sbi->s_nilfs; | ||
2467 | struct nilfs_transaction_info ti; | 2442 | struct nilfs_transaction_info ti; |
2468 | int err; | 2443 | int err; |
2469 | 2444 | ||
2470 | if (unlikely(!sci)) | 2445 | if (unlikely(!sci)) |
2471 | return -EROFS; | 2446 | return -EROFS; |
2472 | 2447 | ||
2473 | nilfs_transaction_lock(sbi, &ti, 1); | 2448 | nilfs_transaction_lock(sb, &ti, 1); |
2474 | 2449 | ||
2475 | err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat); | 2450 | err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat); |
2476 | if (unlikely(err)) | 2451 | if (unlikely(err)) |
@@ -2498,14 +2473,14 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | |||
2498 | set_current_state(TASK_INTERRUPTIBLE); | 2473 | set_current_state(TASK_INTERRUPTIBLE); |
2499 | schedule_timeout(sci->sc_interval); | 2474 | schedule_timeout(sci->sc_interval); |
2500 | } | 2475 | } |
2501 | if (nilfs_test_opt(sbi, DISCARD)) { | 2476 | if (nilfs_test_opt(nilfs, DISCARD)) { |
2502 | int ret = nilfs_discard_segments(nilfs, sci->sc_freesegs, | 2477 | int ret = nilfs_discard_segments(nilfs, sci->sc_freesegs, |
2503 | sci->sc_nfreesegs); | 2478 | sci->sc_nfreesegs); |
2504 | if (ret) { | 2479 | if (ret) { |
2505 | printk(KERN_WARNING | 2480 | printk(KERN_WARNING |
2506 | "NILFS warning: error %d on discard request, " | 2481 | "NILFS warning: error %d on discard request, " |
2507 | "turning discards off for the device\n", ret); | 2482 | "turning discards off for the device\n", ret); |
2508 | nilfs_clear_opt(sbi, DISCARD); | 2483 | nilfs_clear_opt(nilfs, DISCARD); |
2509 | } | 2484 | } |
2510 | } | 2485 | } |
2511 | 2486 | ||
@@ -2513,16 +2488,15 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, | |||
2513 | sci->sc_freesegs = NULL; | 2488 | sci->sc_freesegs = NULL; |
2514 | sci->sc_nfreesegs = 0; | 2489 | sci->sc_nfreesegs = 0; |
2515 | nilfs_mdt_clear_shadow_map(nilfs->ns_dat); | 2490 | nilfs_mdt_clear_shadow_map(nilfs->ns_dat); |
2516 | nilfs_transaction_unlock(sbi); | 2491 | nilfs_transaction_unlock(sb); |
2517 | return err; | 2492 | return err; |
2518 | } | 2493 | } |
2519 | 2494 | ||
2520 | static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) | 2495 | static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) |
2521 | { | 2496 | { |
2522 | struct nilfs_sb_info *sbi = sci->sc_sbi; | ||
2523 | struct nilfs_transaction_info ti; | 2497 | struct nilfs_transaction_info ti; |
2524 | 2498 | ||
2525 | nilfs_transaction_lock(sbi, &ti, 0); | 2499 | nilfs_transaction_lock(sci->sc_super, &ti, 0); |
2526 | nilfs_segctor_construct(sci, mode); | 2500 | nilfs_segctor_construct(sci, mode); |
2527 | 2501 | ||
2528 | /* | 2502 | /* |
@@ -2533,7 +2507,7 @@ static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) | |||
2533 | if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags)) | 2507 | if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags)) |
2534 | nilfs_segctor_start_timer(sci); | 2508 | nilfs_segctor_start_timer(sci); |
2535 | 2509 | ||
2536 | nilfs_transaction_unlock(sbi); | 2510 | nilfs_transaction_unlock(sci->sc_super); |
2537 | } | 2511 | } |
2538 | 2512 | ||
2539 | static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci) | 2513 | static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci) |
@@ -2579,7 +2553,7 @@ static int nilfs_segctor_flush_mode(struct nilfs_sc_info *sci) | |||
2579 | static int nilfs_segctor_thread(void *arg) | 2553 | static int nilfs_segctor_thread(void *arg) |
2580 | { | 2554 | { |
2581 | struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg; | 2555 | struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg; |
2582 | struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; | 2556 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
2583 | int timeout = 0; | 2557 | int timeout = 0; |
2584 | 2558 | ||
2585 | sci->sc_timer.data = (unsigned long)current; | 2559 | sci->sc_timer.data = (unsigned long)current; |
@@ -2690,17 +2664,17 @@ static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci) | |||
2690 | /* | 2664 | /* |
2691 | * Setup & clean-up functions | 2665 | * Setup & clean-up functions |
2692 | */ | 2666 | */ |
2693 | static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi, | 2667 | static struct nilfs_sc_info *nilfs_segctor_new(struct super_block *sb, |
2694 | struct nilfs_root *root) | 2668 | struct nilfs_root *root) |
2695 | { | 2669 | { |
2670 | struct the_nilfs *nilfs = sb->s_fs_info; | ||
2696 | struct nilfs_sc_info *sci; | 2671 | struct nilfs_sc_info *sci; |
2697 | 2672 | ||
2698 | sci = kzalloc(sizeof(*sci), GFP_KERNEL); | 2673 | sci = kzalloc(sizeof(*sci), GFP_KERNEL); |
2699 | if (!sci) | 2674 | if (!sci) |
2700 | return NULL; | 2675 | return NULL; |
2701 | 2676 | ||
2702 | sci->sc_sbi = sbi; | 2677 | sci->sc_super = sb; |
2703 | sci->sc_super = sbi->s_super; | ||
2704 | 2678 | ||
2705 | nilfs_get_root(root); | 2679 | nilfs_get_root(root); |
2706 | sci->sc_root = root; | 2680 | sci->sc_root = root; |
@@ -2720,10 +2694,10 @@ static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi, | |||
2720 | sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ; | 2694 | sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ; |
2721 | sci->sc_watermark = NILFS_SC_DEFAULT_WATERMARK; | 2695 | sci->sc_watermark = NILFS_SC_DEFAULT_WATERMARK; |
2722 | 2696 | ||
2723 | if (sbi->s_interval) | 2697 | if (nilfs->ns_interval) |
2724 | sci->sc_interval = sbi->s_interval; | 2698 | sci->sc_interval = nilfs->ns_interval; |
2725 | if (sbi->s_watermark) | 2699 | if (nilfs->ns_watermark) |
2726 | sci->sc_watermark = sbi->s_watermark; | 2700 | sci->sc_watermark = nilfs->ns_watermark; |
2727 | return sci; | 2701 | return sci; |
2728 | } | 2702 | } |
2729 | 2703 | ||
@@ -2734,12 +2708,11 @@ static void nilfs_segctor_write_out(struct nilfs_sc_info *sci) | |||
2734 | /* The segctord thread was stopped and its timer was removed. | 2708 | /* The segctord thread was stopped and its timer was removed. |
2735 | But some tasks remain. */ | 2709 | But some tasks remain. */ |
2736 | do { | 2710 | do { |
2737 | struct nilfs_sb_info *sbi = sci->sc_sbi; | ||
2738 | struct nilfs_transaction_info ti; | 2711 | struct nilfs_transaction_info ti; |
2739 | 2712 | ||
2740 | nilfs_transaction_lock(sbi, &ti, 0); | 2713 | nilfs_transaction_lock(sci->sc_super, &ti, 0); |
2741 | ret = nilfs_segctor_construct(sci, SC_LSEG_SR); | 2714 | ret = nilfs_segctor_construct(sci, SC_LSEG_SR); |
2742 | nilfs_transaction_unlock(sbi); | 2715 | nilfs_transaction_unlock(sci->sc_super); |
2743 | 2716 | ||
2744 | } while (ret && retrycount-- > 0); | 2717 | } while (ret && retrycount-- > 0); |
2745 | } | 2718 | } |
@@ -2754,10 +2727,10 @@ static void nilfs_segctor_write_out(struct nilfs_sc_info *sci) | |||
2754 | */ | 2727 | */ |
2755 | static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | 2728 | static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) |
2756 | { | 2729 | { |
2757 | struct nilfs_sb_info *sbi = sci->sc_sbi; | 2730 | struct the_nilfs *nilfs = sci->sc_super->s_fs_info; |
2758 | int flag; | 2731 | int flag; |
2759 | 2732 | ||
2760 | up_write(&sbi->s_nilfs->ns_segctor_sem); | 2733 | up_write(&nilfs->ns_segctor_sem); |
2761 | 2734 | ||
2762 | spin_lock(&sci->sc_state_lock); | 2735 | spin_lock(&sci->sc_state_lock); |
2763 | nilfs_segctor_kill_thread(sci); | 2736 | nilfs_segctor_kill_thread(sci); |
@@ -2771,9 +2744,9 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | |||
2771 | WARN_ON(!list_empty(&sci->sc_copied_buffers)); | 2744 | WARN_ON(!list_empty(&sci->sc_copied_buffers)); |
2772 | 2745 | ||
2773 | if (!list_empty(&sci->sc_dirty_files)) { | 2746 | if (!list_empty(&sci->sc_dirty_files)) { |
2774 | nilfs_warning(sbi->s_super, __func__, | 2747 | nilfs_warning(sci->sc_super, __func__, |
2775 | "dirty file(s) after the final construction\n"); | 2748 | "dirty file(s) after the final construction\n"); |
2776 | nilfs_dispose_list(sbi, &sci->sc_dirty_files, 1); | 2749 | nilfs_dispose_list(nilfs, &sci->sc_dirty_files, 1); |
2777 | } | 2750 | } |
2778 | 2751 | ||
2779 | WARN_ON(!list_empty(&sci->sc_segbufs)); | 2752 | WARN_ON(!list_empty(&sci->sc_segbufs)); |
@@ -2781,79 +2754,78 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci) | |||
2781 | 2754 | ||
2782 | nilfs_put_root(sci->sc_root); | 2755 | nilfs_put_root(sci->sc_root); |
2783 | 2756 | ||
2784 | down_write(&sbi->s_nilfs->ns_segctor_sem); | 2757 | down_write(&nilfs->ns_segctor_sem); |
2785 | 2758 | ||
2786 | del_timer_sync(&sci->sc_timer); | 2759 | del_timer_sync(&sci->sc_timer); |
2787 | kfree(sci); | 2760 | kfree(sci); |
2788 | } | 2761 | } |
2789 | 2762 | ||
2790 | /** | 2763 | /** |
2791 | * nilfs_attach_segment_constructor - attach a segment constructor | 2764 | * nilfs_attach_log_writer - attach log writer |
2792 | * @sbi: nilfs_sb_info | 2765 | * @sb: super block instance |
2793 | * @root: root object of the current filesystem tree | 2766 | * @root: root object of the current filesystem tree |
2794 | * | 2767 | * |
2795 | * nilfs_attach_segment_constructor() allocates a struct nilfs_sc_info, | 2768 | * This allocates a log writer object, initializes it, and starts the |
2796 | * initializes it, and starts the segment constructor. | 2769 | * log writer. |
2797 | * | 2770 | * |
2798 | * Return Value: On success, 0 is returned. On error, one of the following | 2771 | * Return Value: On success, 0 is returned. On error, one of the following |
2799 | * negative error code is returned. | 2772 | * negative error code is returned. |
2800 | * | 2773 | * |
2801 | * %-ENOMEM - Insufficient memory available. | 2774 | * %-ENOMEM - Insufficient memory available. |
2802 | */ | 2775 | */ |
2803 | int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, | 2776 | int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root) |
2804 | struct nilfs_root *root) | ||
2805 | { | 2777 | { |
2778 | struct the_nilfs *nilfs = sb->s_fs_info; | ||
2806 | int err; | 2779 | int err; |
2807 | 2780 | ||
2808 | if (NILFS_SC(sbi)) { | 2781 | if (nilfs->ns_writer) { |
2809 | /* | 2782 | /* |
2810 | * This happens if the filesystem was remounted | 2783 | * This happens if the filesystem was remounted |
2811 | * read/write after nilfs_error degenerated it into a | 2784 | * read/write after nilfs_error degenerated it into a |
2812 | * read-only mount. | 2785 | * read-only mount. |
2813 | */ | 2786 | */ |
2814 | nilfs_detach_segment_constructor(sbi); | 2787 | nilfs_detach_log_writer(sb); |
2815 | } | 2788 | } |
2816 | 2789 | ||
2817 | sbi->s_sc_info = nilfs_segctor_new(sbi, root); | 2790 | nilfs->ns_writer = nilfs_segctor_new(sb, root); |
2818 | if (!sbi->s_sc_info) | 2791 | if (!nilfs->ns_writer) |
2819 | return -ENOMEM; | 2792 | return -ENOMEM; |
2820 | 2793 | ||
2821 | err = nilfs_segctor_start_thread(NILFS_SC(sbi)); | 2794 | err = nilfs_segctor_start_thread(nilfs->ns_writer); |
2822 | if (err) { | 2795 | if (err) { |
2823 | kfree(sbi->s_sc_info); | 2796 | kfree(nilfs->ns_writer); |
2824 | sbi->s_sc_info = NULL; | 2797 | nilfs->ns_writer = NULL; |
2825 | } | 2798 | } |
2826 | return err; | 2799 | return err; |
2827 | } | 2800 | } |
2828 | 2801 | ||
2829 | /** | 2802 | /** |
2830 | * nilfs_detach_segment_constructor - destroy the segment constructor | 2803 | * nilfs_detach_log_writer - destroy log writer |
2831 | * @sbi: nilfs_sb_info | 2804 | * @sb: super block instance |
2832 | * | 2805 | * |
2833 | * nilfs_detach_segment_constructor() kills the segment constructor daemon, | 2806 | * This kills log writer daemon, frees the log writer object, and |
2834 | * frees the struct nilfs_sc_info, and destroy the dirty file list. | 2807 | * destroys list of dirty files. |
2835 | */ | 2808 | */ |
2836 | void nilfs_detach_segment_constructor(struct nilfs_sb_info *sbi) | 2809 | void nilfs_detach_log_writer(struct super_block *sb) |
2837 | { | 2810 | { |
2838 | struct the_nilfs *nilfs = sbi->s_nilfs; | 2811 | struct the_nilfs *nilfs = sb->s_fs_info; |
2839 | LIST_HEAD(garbage_list); | 2812 | LIST_HEAD(garbage_list); |
2840 | 2813 | ||
2841 | down_write(&nilfs->ns_segctor_sem); | 2814 | down_write(&nilfs->ns_segctor_sem); |
2842 | if (NILFS_SC(sbi)) { | 2815 | if (nilfs->ns_writer) { |
2843 | nilfs_segctor_destroy(NILFS_SC(sbi)); | 2816 | nilfs_segctor_destroy(nilfs->ns_writer); |
2844 | sbi->s_sc_info = NULL; | 2817 | nilfs->ns_writer = NULL; |
2845 | } | 2818 | } |
2846 | 2819 | ||
2847 | /* Force to free the list of dirty files */ | 2820 | /* Force to free the list of dirty files */ |
2848 | spin_lock(&sbi->s_inode_lock); | 2821 | spin_lock(&nilfs->ns_inode_lock); |
2849 | if (!list_empty(&sbi->s_dirty_files)) { | 2822 | if (!list_empty(&nilfs->ns_dirty_files)) { |
2850 | list_splice_init(&sbi->s_dirty_files, &garbage_list); | 2823 | list_splice_init(&nilfs->ns_dirty_files, &garbage_list); |
2851 | nilfs_warning(sbi->s_super, __func__, | 2824 | nilfs_warning(sb, __func__, |
2852 | "Non empty dirty list after the last " | 2825 | "Hit dirty file after stopped log writer\n"); |
2853 | "segment construction\n"); | 2826 | } |
2854 | } | 2827 | spin_unlock(&nilfs->ns_inode_lock); |
2855 | spin_unlock(&sbi->s_inode_lock); | ||
2856 | up_write(&nilfs->ns_segctor_sem); | 2828 | up_write(&nilfs->ns_segctor_sem); |
2857 | 2829 | ||
2858 | nilfs_dispose_list(sbi, &garbage_list, 1); | 2830 | nilfs_dispose_list(nilfs, &garbage_list, 1); |
2859 | } | 2831 | } |