diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2016-08-02 17:05:25 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-08-02 19:35:20 -0400 |
commit | ad980c9ab77cc4e0edc5dd3361fd69daabeb99f9 (patch) | |
tree | 4758726d573e01f8861e31a0b29eeb434e57af2c /fs/nilfs2 | |
parent | a7d3f104da57eecb2b9881127d6bdf9abe7fde99 (diff) |
nilfs2: fix misuse of a semaphore in sysfs code
Variables ns_seg_seq, ns_segnum, ns_nextnum, ns_pseg_offset, ns_cno,
ns_ctime, ns_nongc_ctime, and ns_ndirtyblks, are protected by
ns_segctor_sem, but ns_sem is wrongly used by the nilfs sysfs code when
reading these variables. This fixes the misuse and clarifies which
semaphore protects them in the comment of the_nilfs struct.
Link: http://lkml.kernel.org/r/1465825507-3407-2-git-send-email-konishi.ryusuke@lab.ntt.co.jp
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/nilfs2')
-rw-r--r-- | fs/nilfs2/sysfs.c | 44 | ||||
-rw-r--r-- | fs/nilfs2/the_nilfs.h | 7 |
2 files changed, 24 insertions, 27 deletions
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c index 8e57bb91fe16..490303e3d517 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c | |||
@@ -326,9 +326,9 @@ nilfs_checkpoints_next_checkpoint_show(struct nilfs_checkpoints_attr *attr, | |||
326 | { | 326 | { |
327 | __u64 cno; | 327 | __u64 cno; |
328 | 328 | ||
329 | down_read(&nilfs->ns_sem); | 329 | down_read(&nilfs->ns_segctor_sem); |
330 | cno = nilfs->ns_cno; | 330 | cno = nilfs->ns_cno; |
331 | up_read(&nilfs->ns_sem); | 331 | up_read(&nilfs->ns_segctor_sem); |
332 | 332 | ||
333 | return snprintf(buf, PAGE_SIZE, "%llu\n", cno); | 333 | return snprintf(buf, PAGE_SIZE, "%llu\n", cno); |
334 | } | 334 | } |
@@ -511,9 +511,9 @@ nilfs_segctor_current_seg_sequence_show(struct nilfs_segctor_attr *attr, | |||
511 | { | 511 | { |
512 | u64 seg_seq; | 512 | u64 seg_seq; |
513 | 513 | ||
514 | down_read(&nilfs->ns_sem); | 514 | down_read(&nilfs->ns_segctor_sem); |
515 | seg_seq = nilfs->ns_seg_seq; | 515 | seg_seq = nilfs->ns_seg_seq; |
516 | up_read(&nilfs->ns_sem); | 516 | up_read(&nilfs->ns_segctor_sem); |
517 | 517 | ||
518 | return snprintf(buf, PAGE_SIZE, "%llu\n", seg_seq); | 518 | return snprintf(buf, PAGE_SIZE, "%llu\n", seg_seq); |
519 | } | 519 | } |
@@ -525,9 +525,9 @@ nilfs_segctor_current_last_full_seg_show(struct nilfs_segctor_attr *attr, | |||
525 | { | 525 | { |
526 | __u64 segnum; | 526 | __u64 segnum; |
527 | 527 | ||
528 | down_read(&nilfs->ns_sem); | 528 | down_read(&nilfs->ns_segctor_sem); |
529 | segnum = nilfs->ns_segnum; | 529 | segnum = nilfs->ns_segnum; |
530 | up_read(&nilfs->ns_sem); | 530 | up_read(&nilfs->ns_segctor_sem); |
531 | 531 | ||
532 | return snprintf(buf, PAGE_SIZE, "%llu\n", segnum); | 532 | return snprintf(buf, PAGE_SIZE, "%llu\n", segnum); |
533 | } | 533 | } |
@@ -539,9 +539,9 @@ nilfs_segctor_next_full_seg_show(struct nilfs_segctor_attr *attr, | |||
539 | { | 539 | { |
540 | __u64 nextnum; | 540 | __u64 nextnum; |
541 | 541 | ||
542 | down_read(&nilfs->ns_sem); | 542 | down_read(&nilfs->ns_segctor_sem); |
543 | nextnum = nilfs->ns_nextnum; | 543 | nextnum = nilfs->ns_nextnum; |
544 | up_read(&nilfs->ns_sem); | 544 | up_read(&nilfs->ns_segctor_sem); |
545 | 545 | ||
546 | return snprintf(buf, PAGE_SIZE, "%llu\n", nextnum); | 546 | return snprintf(buf, PAGE_SIZE, "%llu\n", nextnum); |
547 | } | 547 | } |
@@ -553,9 +553,9 @@ nilfs_segctor_next_pseg_offset_show(struct nilfs_segctor_attr *attr, | |||
553 | { | 553 | { |
554 | unsigned long pseg_offset; | 554 | unsigned long pseg_offset; |
555 | 555 | ||
556 | down_read(&nilfs->ns_sem); | 556 | down_read(&nilfs->ns_segctor_sem); |
557 | pseg_offset = nilfs->ns_pseg_offset; | 557 | pseg_offset = nilfs->ns_pseg_offset; |
558 | up_read(&nilfs->ns_sem); | 558 | up_read(&nilfs->ns_segctor_sem); |
559 | 559 | ||
560 | return snprintf(buf, PAGE_SIZE, "%lu\n", pseg_offset); | 560 | return snprintf(buf, PAGE_SIZE, "%lu\n", pseg_offset); |
561 | } | 561 | } |
@@ -567,9 +567,9 @@ nilfs_segctor_next_checkpoint_show(struct nilfs_segctor_attr *attr, | |||
567 | { | 567 | { |
568 | __u64 cno; | 568 | __u64 cno; |
569 | 569 | ||
570 | down_read(&nilfs->ns_sem); | 570 | down_read(&nilfs->ns_segctor_sem); |
571 | cno = nilfs->ns_cno; | 571 | cno = nilfs->ns_cno; |
572 | up_read(&nilfs->ns_sem); | 572 | up_read(&nilfs->ns_segctor_sem); |
573 | 573 | ||
574 | return snprintf(buf, PAGE_SIZE, "%llu\n", cno); | 574 | return snprintf(buf, PAGE_SIZE, "%llu\n", cno); |
575 | } | 575 | } |
@@ -581,9 +581,9 @@ nilfs_segctor_last_seg_write_time_show(struct nilfs_segctor_attr *attr, | |||
581 | { | 581 | { |
582 | time_t ctime; | 582 | time_t ctime; |
583 | 583 | ||
584 | down_read(&nilfs->ns_sem); | 584 | down_read(&nilfs->ns_segctor_sem); |
585 | ctime = nilfs->ns_ctime; | 585 | ctime = nilfs->ns_ctime; |
586 | up_read(&nilfs->ns_sem); | 586 | up_read(&nilfs->ns_segctor_sem); |
587 | 587 | ||
588 | return NILFS_SHOW_TIME(ctime, buf); | 588 | return NILFS_SHOW_TIME(ctime, buf); |
589 | } | 589 | } |
@@ -595,9 +595,9 @@ nilfs_segctor_last_seg_write_time_secs_show(struct nilfs_segctor_attr *attr, | |||
595 | { | 595 | { |
596 | time_t ctime; | 596 | time_t ctime; |
597 | 597 | ||
598 | down_read(&nilfs->ns_sem); | 598 | down_read(&nilfs->ns_segctor_sem); |
599 | ctime = nilfs->ns_ctime; | 599 | ctime = nilfs->ns_ctime; |
600 | up_read(&nilfs->ns_sem); | 600 | up_read(&nilfs->ns_segctor_sem); |
601 | 601 | ||
602 | return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)ctime); | 602 | return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)ctime); |
603 | } | 603 | } |
@@ -609,9 +609,9 @@ nilfs_segctor_last_nongc_write_time_show(struct nilfs_segctor_attr *attr, | |||
609 | { | 609 | { |
610 | time_t nongc_ctime; | 610 | time_t nongc_ctime; |
611 | 611 | ||
612 | down_read(&nilfs->ns_sem); | 612 | down_read(&nilfs->ns_segctor_sem); |
613 | nongc_ctime = nilfs->ns_nongc_ctime; | 613 | nongc_ctime = nilfs->ns_nongc_ctime; |
614 | up_read(&nilfs->ns_sem); | 614 | up_read(&nilfs->ns_segctor_sem); |
615 | 615 | ||
616 | return NILFS_SHOW_TIME(nongc_ctime, buf); | 616 | return NILFS_SHOW_TIME(nongc_ctime, buf); |
617 | } | 617 | } |
@@ -623,9 +623,9 @@ nilfs_segctor_last_nongc_write_time_secs_show(struct nilfs_segctor_attr *attr, | |||
623 | { | 623 | { |
624 | time_t nongc_ctime; | 624 | time_t nongc_ctime; |
625 | 625 | ||
626 | down_read(&nilfs->ns_sem); | 626 | down_read(&nilfs->ns_segctor_sem); |
627 | nongc_ctime = nilfs->ns_nongc_ctime; | 627 | nongc_ctime = nilfs->ns_nongc_ctime; |
628 | up_read(&nilfs->ns_sem); | 628 | up_read(&nilfs->ns_segctor_sem); |
629 | 629 | ||
630 | return snprintf(buf, PAGE_SIZE, "%llu\n", | 630 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
631 | (unsigned long long)nongc_ctime); | 631 | (unsigned long long)nongc_ctime); |
@@ -638,9 +638,9 @@ nilfs_segctor_dirty_data_blocks_count_show(struct nilfs_segctor_attr *attr, | |||
638 | { | 638 | { |
639 | u32 ndirtyblks; | 639 | u32 ndirtyblks; |
640 | 640 | ||
641 | down_read(&nilfs->ns_sem); | 641 | down_read(&nilfs->ns_segctor_sem); |
642 | ndirtyblks = atomic_read(&nilfs->ns_ndirtyblks); | 642 | ndirtyblks = atomic_read(&nilfs->ns_ndirtyblks); |
643 | up_read(&nilfs->ns_sem); | 643 | up_read(&nilfs->ns_segctor_sem); |
644 | 644 | ||
645 | return snprintf(buf, PAGE_SIZE, "%u\n", ndirtyblks); | 645 | return snprintf(buf, PAGE_SIZE, "%u\n", ndirtyblks); |
646 | } | 646 | } |
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h index 79d1421896d0..b305c6f033e7 100644 --- a/fs/nilfs2/the_nilfs.h +++ b/fs/nilfs2/the_nilfs.h | |||
@@ -122,11 +122,8 @@ struct the_nilfs { | |||
122 | unsigned int ns_sb_update_freq; | 122 | unsigned int ns_sb_update_freq; |
123 | 123 | ||
124 | /* | 124 | /* |
125 | * Following fields are dedicated to a writable FS-instance. | 125 | * The following fields are updated by a writable FS-instance. |
126 | * Except for the period seeking checkpoint, code outside the segment | 126 | * These fields are protected by ns_segctor_sem outside load_nilfs(). |
127 | * constructor must lock a segment semaphore while accessing these | ||
128 | * fields. | ||
129 | * The writable FS-instance is sole during a lifetime of the_nilfs. | ||
130 | */ | 127 | */ |
131 | u64 ns_seg_seq; | 128 | u64 ns_seg_seq; |
132 | __u64 ns_segnum; | 129 | __u64 ns_segnum; |