aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/segment.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nilfs2/segment.c')
-rw-r--r--fs/nilfs2/segment.c90
1 files changed, 41 insertions, 49 deletions
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index b14788ec0d1..90e3130303a 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -181,7 +181,6 @@ int nilfs_transaction_begin(struct super_block *sb,
181 struct nilfs_transaction_info *ti, 181 struct nilfs_transaction_info *ti,
182 int vacancy_check) 182 int vacancy_check)
183{ 183{
184 struct nilfs_sb_info *sbi;
185 struct the_nilfs *nilfs; 184 struct the_nilfs *nilfs;
186 int ret = nilfs_prepare_segment_lock(ti); 185 int ret = nilfs_prepare_segment_lock(ti);
187 186
@@ -192,8 +191,7 @@ int nilfs_transaction_begin(struct super_block *sb,
192 191
193 vfs_check_frozen(sb, SB_FREEZE_WRITE); 192 vfs_check_frozen(sb, SB_FREEZE_WRITE);
194 193
195 sbi = NILFS_SB(sb); 194 nilfs = NILFS_SB(sb)->s_nilfs;
196 nilfs = sbi->s_nilfs;
197 down_read(&nilfs->ns_segctor_sem); 195 down_read(&nilfs->ns_segctor_sem);
198 if (vacancy_check && nilfs_near_disk_full(nilfs)) { 196 if (vacancy_check && nilfs_near_disk_full(nilfs)) {
199 up_read(&nilfs->ns_segctor_sem); 197 up_read(&nilfs->ns_segctor_sem);
@@ -290,12 +288,12 @@ void nilfs_relax_pressure_in_lock(struct super_block *sb)
290 downgrade_write(&nilfs->ns_segctor_sem); 288 downgrade_write(&nilfs->ns_segctor_sem);
291} 289}
292 290
293static void nilfs_transaction_lock(struct nilfs_sb_info *sbi, 291static void nilfs_transaction_lock(struct super_block *sb,
294 struct nilfs_transaction_info *ti, 292 struct nilfs_transaction_info *ti,
295 int gcflag) 293 int gcflag)
296{ 294{
297 struct nilfs_transaction_info *cur_ti = current->journal_info; 295 struct nilfs_transaction_info *cur_ti = current->journal_info;
298 struct the_nilfs *nilfs = sbi->s_nilfs; 296 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
299 struct nilfs_sc_info *sci = nilfs->ns_writer; 297 struct nilfs_sc_info *sci = nilfs->ns_writer;
300 298
301 WARN_ON(cur_ti); 299 WARN_ON(cur_ti);
@@ -313,17 +311,17 @@ static void nilfs_transaction_lock(struct nilfs_sb_info *sbi,
313 311
314 nilfs_segctor_do_immediate_flush(sci); 312 nilfs_segctor_do_immediate_flush(sci);
315 313
316 up_write(&sbi->s_nilfs->ns_segctor_sem); 314 up_write(&nilfs->ns_segctor_sem);
317 yield(); 315 yield();
318 } 316 }
319 if (gcflag) 317 if (gcflag)
320 ti->ti_flags |= NILFS_TI_GC; 318 ti->ti_flags |= NILFS_TI_GC;
321} 319}
322 320
323static void nilfs_transaction_unlock(struct nilfs_sb_info *sbi) 321static void nilfs_transaction_unlock(struct super_block *sb)
324{ 322{
325 struct nilfs_transaction_info *ti = current->journal_info; 323 struct nilfs_transaction_info *ti = current->journal_info;
326 struct the_nilfs *nilfs = sbi->s_nilfs; 324 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
327 325
328 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); 326 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC);
329 BUG_ON(ti->ti_count > 0); 327 BUG_ON(ti->ti_count > 0);
@@ -2292,8 +2290,7 @@ int nilfs_construct_segment(struct super_block *sb)
2292int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode, 2290int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2293 loff_t start, loff_t end) 2291 loff_t start, loff_t end)
2294{ 2292{
2295 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2293 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2296 struct the_nilfs *nilfs = sbi->s_nilfs;
2297 struct nilfs_sc_info *sci = nilfs->ns_writer; 2294 struct nilfs_sc_info *sci = nilfs->ns_writer;
2298 struct nilfs_inode_info *ii; 2295 struct nilfs_inode_info *ii;
2299 struct nilfs_transaction_info ti; 2296 struct nilfs_transaction_info ti;
@@ -2302,14 +2299,14 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2302 if (!sci) 2299 if (!sci)
2303 return -EROFS; 2300 return -EROFS;
2304 2301
2305 nilfs_transaction_lock(sbi, &ti, 0); 2302 nilfs_transaction_lock(sb, &ti, 0);
2306 2303
2307 ii = NILFS_I(inode); 2304 ii = NILFS_I(inode);
2308 if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) || 2305 if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) ||
2309 nilfs_test_opt(nilfs, STRICT_ORDER) || 2306 nilfs_test_opt(nilfs, STRICT_ORDER) ||
2310 test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) || 2307 test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) ||
2311 nilfs_discontinued(nilfs)) { 2308 nilfs_discontinued(nilfs)) {
2312 nilfs_transaction_unlock(sbi); 2309 nilfs_transaction_unlock(sb);
2313 err = nilfs_segctor_sync(sci); 2310 err = nilfs_segctor_sync(sci);
2314 return err; 2311 return err;
2315 } 2312 }
@@ -2318,7 +2315,7 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2318 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) && 2315 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) &&
2319 !test_bit(NILFS_I_BUSY, &ii->i_state)) { 2316 !test_bit(NILFS_I_BUSY, &ii->i_state)) {
2320 spin_unlock(&nilfs->ns_inode_lock); 2317 spin_unlock(&nilfs->ns_inode_lock);
2321 nilfs_transaction_unlock(sbi); 2318 nilfs_transaction_unlock(sb);
2322 return 0; 2319 return 0;
2323 } 2320 }
2324 spin_unlock(&nilfs->ns_inode_lock); 2321 spin_unlock(&nilfs->ns_inode_lock);
@@ -2328,7 +2325,7 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2328 2325
2329 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC); 2326 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC);
2330 2327
2331 nilfs_transaction_unlock(sbi); 2328 nilfs_transaction_unlock(sb);
2332 return err; 2329 return err;
2333} 2330}
2334 2331
@@ -2384,8 +2381,7 @@ static void nilfs_segctor_notify(struct nilfs_sc_info *sci, int mode, int err)
2384 */ 2381 */
2385static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) 2382static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode)
2386{ 2383{
2387 struct nilfs_sb_info *sbi = NILFS_SB(sci->sc_super); 2384 struct the_nilfs *nilfs = NILFS_SB(sci->sc_super)->s_nilfs;
2388 struct the_nilfs *nilfs = sbi->s_nilfs;
2389 struct nilfs_super_block **sbp; 2385 struct nilfs_super_block **sbp;
2390 int err = 0; 2386 int err = 0;
2391 2387
@@ -2403,11 +2399,12 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode)
2403 nilfs_discontinued(nilfs)) { 2399 nilfs_discontinued(nilfs)) {
2404 down_write(&nilfs->ns_sem); 2400 down_write(&nilfs->ns_sem);
2405 err = -EIO; 2401 err = -EIO;
2406 sbp = nilfs_prepare_super(sbi, 2402 sbp = nilfs_prepare_super(sci->sc_super,
2407 nilfs_sb_will_flip(nilfs)); 2403 nilfs_sb_will_flip(nilfs));
2408 if (likely(sbp)) { 2404 if (likely(sbp)) {
2409 nilfs_set_log_cursor(sbp[0], nilfs); 2405 nilfs_set_log_cursor(sbp[0], nilfs);
2410 err = nilfs_commit_super(sbi, NILFS_SB_COMMIT); 2406 err = nilfs_commit_super(sci->sc_super,
2407 NILFS_SB_COMMIT);
2411 } 2408 }
2412 up_write(&nilfs->ns_sem); 2409 up_write(&nilfs->ns_sem);
2413 } 2410 }
@@ -2439,8 +2436,7 @@ nilfs_remove_written_gcinodes(struct the_nilfs *nilfs, struct list_head *head)
2439int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, 2436int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2440 void **kbufs) 2437 void **kbufs)
2441{ 2438{
2442 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2439 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2443 struct the_nilfs *nilfs = sbi->s_nilfs;
2444 struct nilfs_sc_info *sci = nilfs->ns_writer; 2440 struct nilfs_sc_info *sci = nilfs->ns_writer;
2445 struct nilfs_transaction_info ti; 2441 struct nilfs_transaction_info ti;
2446 int err; 2442 int err;
@@ -2448,7 +2444,7 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2448 if (unlikely(!sci)) 2444 if (unlikely(!sci))
2449 return -EROFS; 2445 return -EROFS;
2450 2446
2451 nilfs_transaction_lock(sbi, &ti, 1); 2447 nilfs_transaction_lock(sb, &ti, 1);
2452 2448
2453 err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat); 2449 err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat);
2454 if (unlikely(err)) 2450 if (unlikely(err))
@@ -2491,16 +2487,15 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2491 sci->sc_freesegs = NULL; 2487 sci->sc_freesegs = NULL;
2492 sci->sc_nfreesegs = 0; 2488 sci->sc_nfreesegs = 0;
2493 nilfs_mdt_clear_shadow_map(nilfs->ns_dat); 2489 nilfs_mdt_clear_shadow_map(nilfs->ns_dat);
2494 nilfs_transaction_unlock(sbi); 2490 nilfs_transaction_unlock(sb);
2495 return err; 2491 return err;
2496} 2492}
2497 2493
2498static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) 2494static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode)
2499{ 2495{
2500 struct nilfs_sb_info *sbi = NILFS_SB(sci->sc_super);
2501 struct nilfs_transaction_info ti; 2496 struct nilfs_transaction_info ti;
2502 2497
2503 nilfs_transaction_lock(sbi, &ti, 0); 2498 nilfs_transaction_lock(sci->sc_super, &ti, 0);
2504 nilfs_segctor_construct(sci, mode); 2499 nilfs_segctor_construct(sci, mode);
2505 2500
2506 /* 2501 /*
@@ -2511,7 +2506,7 @@ static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode)
2511 if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags)) 2506 if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags))
2512 nilfs_segctor_start_timer(sci); 2507 nilfs_segctor_start_timer(sci);
2513 2508
2514 nilfs_transaction_unlock(sbi); 2509 nilfs_transaction_unlock(sci->sc_super);
2515} 2510}
2516 2511
2517static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci) 2512static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci)
@@ -2668,17 +2663,17 @@ static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci)
2668/* 2663/*
2669 * Setup & clean-up functions 2664 * Setup & clean-up functions
2670 */ 2665 */
2671static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi, 2666static struct nilfs_sc_info *nilfs_segctor_new(struct super_block *sb,
2672 struct nilfs_root *root) 2667 struct nilfs_root *root)
2673{ 2668{
2674 struct the_nilfs *nilfs = sbi->s_nilfs; 2669 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2675 struct nilfs_sc_info *sci; 2670 struct nilfs_sc_info *sci;
2676 2671
2677 sci = kzalloc(sizeof(*sci), GFP_KERNEL); 2672 sci = kzalloc(sizeof(*sci), GFP_KERNEL);
2678 if (!sci) 2673 if (!sci)
2679 return NULL; 2674 return NULL;
2680 2675
2681 sci->sc_super = sbi->s_super; 2676 sci->sc_super = sb;
2682 2677
2683 nilfs_get_root(root); 2678 nilfs_get_root(root);
2684 sci->sc_root = root; 2679 sci->sc_root = root;
@@ -2712,12 +2707,11 @@ static void nilfs_segctor_write_out(struct nilfs_sc_info *sci)
2712 /* The segctord thread was stopped and its timer was removed. 2707 /* The segctord thread was stopped and its timer was removed.
2713 But some tasks remain. */ 2708 But some tasks remain. */
2714 do { 2709 do {
2715 struct nilfs_sb_info *sbi = NILFS_SB(sci->sc_super);
2716 struct nilfs_transaction_info ti; 2710 struct nilfs_transaction_info ti;
2717 2711
2718 nilfs_transaction_lock(sbi, &ti, 0); 2712 nilfs_transaction_lock(sci->sc_super, &ti, 0);
2719 ret = nilfs_segctor_construct(sci, SC_LSEG_SR); 2713 ret = nilfs_segctor_construct(sci, SC_LSEG_SR);
2720 nilfs_transaction_unlock(sbi); 2714 nilfs_transaction_unlock(sci->sc_super);
2721 2715
2722 } while (ret && retrycount-- > 0); 2716 } while (ret && retrycount-- > 0);
2723} 2717}
@@ -2766,22 +2760,21 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci)
2766} 2760}
2767 2761
2768/** 2762/**
2769 * nilfs_attach_segment_constructor - attach a segment constructor 2763 * nilfs_attach_log_writer - attach log writer
2770 * @sbi: nilfs_sb_info 2764 * @sb: super block instance
2771 * @root: root object of the current filesystem tree 2765 * @root: root object of the current filesystem tree
2772 * 2766 *
2773 * nilfs_attach_segment_constructor() allocates a struct nilfs_sc_info, 2767 * This allocates a log writer object, initializes it, and starts the
2774 * initializes it, and starts the segment constructor. 2768 * log writer.
2775 * 2769 *
2776 * Return Value: On success, 0 is returned. On error, one of the following 2770 * Return Value: On success, 0 is returned. On error, one of the following
2777 * negative error code is returned. 2771 * negative error code is returned.
2778 * 2772 *
2779 * %-ENOMEM - Insufficient memory available. 2773 * %-ENOMEM - Insufficient memory available.
2780 */ 2774 */
2781int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, 2775int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root)
2782 struct nilfs_root *root)
2783{ 2776{
2784 struct the_nilfs *nilfs = sbi->s_nilfs; 2777 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2785 int err; 2778 int err;
2786 2779
2787 if (nilfs->ns_writer) { 2780 if (nilfs->ns_writer) {
@@ -2790,10 +2783,10 @@ int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi,
2790 * read/write after nilfs_error degenerated it into a 2783 * read/write after nilfs_error degenerated it into a
2791 * read-only mount. 2784 * read-only mount.
2792 */ 2785 */
2793 nilfs_detach_segment_constructor(sbi); 2786 nilfs_detach_log_writer(sb);
2794 } 2787 }
2795 2788
2796 nilfs->ns_writer = nilfs_segctor_new(sbi, root); 2789 nilfs->ns_writer = nilfs_segctor_new(sb, root);
2797 if (!nilfs->ns_writer) 2790 if (!nilfs->ns_writer)
2798 return -ENOMEM; 2791 return -ENOMEM;
2799 2792
@@ -2806,15 +2799,15 @@ int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi,
2806} 2799}
2807 2800
2808/** 2801/**
2809 * nilfs_detach_segment_constructor - destroy the segment constructor 2802 * nilfs_detach_log_writer - destroy log writer
2810 * @sbi: nilfs_sb_info 2803 * @sb: super block instance
2811 * 2804 *
2812 * nilfs_detach_segment_constructor() kills the segment constructor daemon, 2805 * This kills log writer daemon, frees the log writer object, and
2813 * frees the struct nilfs_sc_info, and destroy the dirty file list. 2806 * destroys list of dirty files.
2814 */ 2807 */
2815void nilfs_detach_segment_constructor(struct nilfs_sb_info *sbi) 2808void nilfs_detach_log_writer(struct super_block *sb)
2816{ 2809{
2817 struct the_nilfs *nilfs = sbi->s_nilfs; 2810 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2818 LIST_HEAD(garbage_list); 2811 LIST_HEAD(garbage_list);
2819 2812
2820 down_write(&nilfs->ns_segctor_sem); 2813 down_write(&nilfs->ns_segctor_sem);
@@ -2827,9 +2820,8 @@ void nilfs_detach_segment_constructor(struct nilfs_sb_info *sbi)
2827 spin_lock(&nilfs->ns_inode_lock); 2820 spin_lock(&nilfs->ns_inode_lock);
2828 if (!list_empty(&nilfs->ns_dirty_files)) { 2821 if (!list_empty(&nilfs->ns_dirty_files)) {
2829 list_splice_init(&nilfs->ns_dirty_files, &garbage_list); 2822 list_splice_init(&nilfs->ns_dirty_files, &garbage_list);
2830 nilfs_warning(sbi->s_super, __func__, 2823 nilfs_warning(sb, __func__,
2831 "Non empty dirty list after the last " 2824 "Hit dirty file after stopped log writer\n");
2832 "segment construction\n");
2833 } 2825 }
2834 spin_unlock(&nilfs->ns_inode_lock); 2826 spin_unlock(&nilfs->ns_inode_lock);
2835 up_write(&nilfs->ns_segctor_sem); 2827 up_write(&nilfs->ns_segctor_sem);