Skip to content

Commit

Permalink
nilfs2: fix misuse of a semaphore in sysfs code
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Ryusuke Konishi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
konis authored and torvalds committed Aug 2, 2016
1 parent a7d3f10 commit ad980c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
44 changes: 22 additions & 22 deletions fs/nilfs2/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ nilfs_checkpoints_next_checkpoint_show(struct nilfs_checkpoints_attr *attr,
{
__u64 cno;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
cno = nilfs->ns_cno;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
}
Expand Down Expand Up @@ -511,9 +511,9 @@ nilfs_segctor_current_seg_sequence_show(struct nilfs_segctor_attr *attr,
{
u64 seg_seq;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
seg_seq = nilfs->ns_seg_seq;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%llu\n", seg_seq);
}
Expand All @@ -525,9 +525,9 @@ nilfs_segctor_current_last_full_seg_show(struct nilfs_segctor_attr *attr,
{
__u64 segnum;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
segnum = nilfs->ns_segnum;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%llu\n", segnum);
}
Expand All @@ -539,9 +539,9 @@ nilfs_segctor_next_full_seg_show(struct nilfs_segctor_attr *attr,
{
__u64 nextnum;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
nextnum = nilfs->ns_nextnum;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%llu\n", nextnum);
}
Expand All @@ -553,9 +553,9 @@ nilfs_segctor_next_pseg_offset_show(struct nilfs_segctor_attr *attr,
{
unsigned long pseg_offset;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
pseg_offset = nilfs->ns_pseg_offset;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%lu\n", pseg_offset);
}
Expand All @@ -567,9 +567,9 @@ nilfs_segctor_next_checkpoint_show(struct nilfs_segctor_attr *attr,
{
__u64 cno;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
cno = nilfs->ns_cno;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
}
Expand All @@ -581,9 +581,9 @@ nilfs_segctor_last_seg_write_time_show(struct nilfs_segctor_attr *attr,
{
time_t ctime;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
ctime = nilfs->ns_ctime;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return NILFS_SHOW_TIME(ctime, buf);
}
Expand All @@ -595,9 +595,9 @@ nilfs_segctor_last_seg_write_time_secs_show(struct nilfs_segctor_attr *attr,
{
time_t ctime;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
ctime = nilfs->ns_ctime;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)ctime);
}
Expand All @@ -609,9 +609,9 @@ nilfs_segctor_last_nongc_write_time_show(struct nilfs_segctor_attr *attr,
{
time_t nongc_ctime;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
nongc_ctime = nilfs->ns_nongc_ctime;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return NILFS_SHOW_TIME(nongc_ctime, buf);
}
Expand All @@ -623,9 +623,9 @@ nilfs_segctor_last_nongc_write_time_secs_show(struct nilfs_segctor_attr *attr,
{
time_t nongc_ctime;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
nongc_ctime = nilfs->ns_nongc_ctime;
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%llu\n",
(unsigned long long)nongc_ctime);
Expand All @@ -638,9 +638,9 @@ nilfs_segctor_dirty_data_blocks_count_show(struct nilfs_segctor_attr *attr,
{
u32 ndirtyblks;

down_read(&nilfs->ns_sem);
down_read(&nilfs->ns_segctor_sem);
ndirtyblks = atomic_read(&nilfs->ns_ndirtyblks);
up_read(&nilfs->ns_sem);
up_read(&nilfs->ns_segctor_sem);

return snprintf(buf, PAGE_SIZE, "%u\n", ndirtyblks);
}
Expand Down
7 changes: 2 additions & 5 deletions fs/nilfs2/the_nilfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,8 @@ struct the_nilfs {
unsigned int ns_sb_update_freq;

/*
* Following fields are dedicated to a writable FS-instance.
* Except for the period seeking checkpoint, code outside the segment
* constructor must lock a segment semaphore while accessing these
* fields.
* The writable FS-instance is sole during a lifetime of the_nilfs.
* The following fields are updated by a writable FS-instance.
* These fields are protected by ns_segctor_sem outside load_nilfs().
*/
u64 ns_seg_seq;
__u64 ns_segnum;
Expand Down

0 comments on commit ad980c9

Please sign in to comment.