]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
md/md-bitmap: replace md_bitmap_status() with a new helper md_bitmap_get_stats()
authorYu Kuai <yukuai3@huawei.com>
Mon, 26 Aug 2024 07:44:12 +0000 (15:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Feb 2025 12:10:44 +0000 (04:10 -0800)
[ Upstream commit 38f287d7e495ae00d4481702f44ff7ca79f5c9bc ]

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>
Stable-dep-of: 8d28d0ddb986 ("md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/md-bitmap.c
drivers/md/md-bitmap.h
drivers/md/md.c

index 2085b1705f144f5997d56a1fdc36d88d2147915b..f7b02d87a6da752fc6403a6726d013fa8f3ae7fe 100644 (file)
@@ -2112,32 +2112,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,
index 8b89e260a93b71dde6690edb16eb8d72ddc995dc..60b86ee93908158aca4d3169571e10d66dcf3fa6 100644 (file)
@@ -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 */
@@ -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);
index 27a6a11b71ee474b56c5f91a89bd31b556483c6f..b73649fd8e039e3081ab63e02516c4fdf3f06c80 100644 (file)
@@ -8290,6 +8290,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 = list_entry(v, struct mddev, all_mddevs);
@@ -8365,7 +8392,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");
        }