Skip to content

Commit

Permalink
md/md-bitmap: replace md_bitmap_status() with a new helper md_bitmap_…
Browse files Browse the repository at this point in the history
…get_stats()

There are no functional changes, and the new helper will be used in
multiple places in following patches to avoid dereferencing bitmap
directly.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240826074452.1490072-3-yukuai1@huaweicloud.com
Signed-off-by: Song Liu <song@kernel.org>
  • Loading branch information
Yu Kuai authored and Song Liu committed Aug 27, 2024
1 parent 2db4fa1 commit 38f287d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
25 changes: 6 additions & 19 deletions drivers/md/md-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2094,32 +2094,19 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
}
EXPORT_SYMBOL_GPL(md_bitmap_copy_from_slot);


void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats)
{
unsigned long chunk_kb;
struct bitmap_counts *counts;

if (!bitmap)
return;
return -ENOENT;

counts = &bitmap->counts;
stats->missing_pages = counts->missing_pages;
stats->pages = counts->pages;
stats->file = bitmap->storage.file;

chunk_kb = bitmap->mddev->bitmap_info.chunksize >> 10;
seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], "
"%lu%s chunk",
counts->pages - counts->missing_pages,
counts->pages,
(counts->pages - counts->missing_pages)
<< (PAGE_SHIFT - 10),
chunk_kb ? chunk_kb : bitmap->mddev->bitmap_info.chunksize,
chunk_kb ? "KB" : "B");
if (bitmap->storage.file) {
seq_printf(seq, ", file: ");
seq_file_path(seq, bitmap->storage.file, " \t\n");
}

seq_printf(seq, "\n");
return 0;
}

int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
Expand Down
8 changes: 7 additions & 1 deletion drivers/md/md-bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ struct bitmap {
int cluster_slot; /* Slot offset for clustered env */
};

struct md_bitmap_stats {
unsigned long missing_pages;
unsigned long pages;
struct file *file;
};

/* the bitmap API */

/* these are used only by md/bitmap */
Expand All @@ -244,7 +250,7 @@ void md_bitmap_destroy(struct mddev *mddev);

void md_bitmap_print_sb(struct bitmap *bitmap);
void md_bitmap_update_sb(struct bitmap *bitmap);
void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap);
int md_bitmap_get_stats(struct bitmap *bitmap, struct md_bitmap_stats *stats);

int md_bitmap_setallbits(struct bitmap *bitmap);
void md_bitmap_write_all(struct bitmap *bitmap);
Expand Down
29 changes: 28 additions & 1 deletion drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -8370,6 +8370,33 @@ static void md_seq_stop(struct seq_file *seq, void *v)
spin_unlock(&all_mddevs_lock);
}

static void md_bitmap_status(struct seq_file *seq, struct mddev *mddev)
{
struct md_bitmap_stats stats;
unsigned long used_pages;
unsigned long chunk_kb;
int err;

err = md_bitmap_get_stats(mddev->bitmap, &stats);
if (err)
return;

chunk_kb = mddev->bitmap_info.chunksize >> 10;
used_pages = stats.pages - stats.missing_pages;

seq_printf(seq, "bitmap: %lu/%lu pages [%luKB], %lu%s chunk",
used_pages, stats.pages, used_pages << (PAGE_SHIFT - 10),
chunk_kb ? chunk_kb : mddev->bitmap_info.chunksize,
chunk_kb ? "KB" : "B");

if (stats.file) {
seq_puts(seq, ", file: ");
seq_file_path(seq, stats.file, " \t\n");
}

seq_putc(seq, '\n');
}

static int md_seq_show(struct seq_file *seq, void *v)
{
struct mddev *mddev;
Expand Down Expand Up @@ -8453,7 +8480,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
} else
seq_printf(seq, "\n ");

md_bitmap_status(seq, mddev->bitmap);
md_bitmap_status(seq, mddev);

seq_printf(seq, "\n");
}
Expand Down

0 comments on commit 38f287d

Please sign in to comment.