Skip to content

Commit

Permalink
Merge tag 'md-6.15-20250312' of https://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/mdraid/linux into for-6.15/block

Merge MD changes from Yu:

"- fix recovery can preempt resync (Li Nan)
 - fix md-bitmap IO limit (Su Yue)
 - fix raid10 discard with REQ_NOWAIT (Xiao Ni)
 - fix raid1 memory leak (Zheng Qixing)
 - fix mddev uaf (Yu Kuai)
 - fix raid1,raid10 IO flags (Yu Kuai)
 - some refactor and cleanup (Yu Kuai)"

* tag 'md-6.15-20250312' of https://git.kernel.org/pub/scm/linux/kernel/git/mdraid/linux:
  md/raid10: wait barrier before returning discard request with REQ_NOWAIT
  md/md-bitmap: fix wrong bitmap_limit for clustermd when write sb
  md/raid1,raid10: don't ignore IO flags
  md/raid5: merge reshape_progress checking inside get_reshape_loc()
  md: fix mddev uaf while iterating all_mddevs list
  md: switch md-cluster to use md_submodle_head
  md: don't export md_cluster_ops
  md/md-cluster: cleanup md_cluster_ops reference
  md: switch personalities to use md_submodule_head
  md: introduce struct md_submodule_head and APIs
  md: only include md-cluster.h if necessary
  md: merge common code into find_pers()
  md/raid1: fix memory leak in raid1_run() if no active rdev
  md: ensure resync is prioritized over recovery
  • Loading branch information
Jens Axboe committed Mar 13, 2025
2 parents 26064d3 + 3db4404 commit 017ff37
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 269 deletions.
14 changes: 8 additions & 6 deletions drivers/md/md-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
#include <linux/buffer_head.h>
#include <linux/seq_file.h>
#include <trace/events/block.h>

#include "md.h"
#include "md-bitmap.h"
#include "md-cluster.h"

#define BITMAP_MAJOR_LO 3
/* version 4 insists the bitmap is in little-endian order
Expand Down Expand Up @@ -426,8 +428,8 @@ static int __write_sb_page(struct md_rdev *rdev, struct bitmap *bitmap,
struct block_device *bdev;
struct mddev *mddev = bitmap->mddev;
struct bitmap_storage *store = &bitmap->storage;
unsigned int bitmap_limit = (bitmap->storage.file_pages - pg_index) <<
PAGE_SHIFT;
unsigned long num_pages = bitmap->storage.file_pages;
unsigned int bitmap_limit = (num_pages - pg_index % num_pages) << PAGE_SHIFT;
loff_t sboff, offset = mddev->bitmap_info.offset;
sector_t ps = pg_index * PAGE_SIZE / SECTOR_SIZE;
unsigned int size = PAGE_SIZE;
Expand All @@ -436,7 +438,7 @@ static int __write_sb_page(struct md_rdev *rdev, struct bitmap *bitmap,

bdev = (rdev->meta_bdev) ? rdev->meta_bdev : rdev->bdev;
/* we compare length (page numbers), not page offset. */
if ((pg_index - store->sb_index) == store->file_pages - 1) {
if ((pg_index - store->sb_index) == num_pages - 1) {
unsigned int last_page_size = store->bytes & (PAGE_SIZE - 1);

if (last_page_size == 0)
Expand Down Expand Up @@ -942,7 +944,7 @@ static int md_bitmap_read_sb(struct bitmap *bitmap)
bmname(bitmap), err);
goto out_no_sb;
}
bitmap->cluster_slot = md_cluster_ops->slot_number(bitmap->mddev);
bitmap->cluster_slot = bitmap->mddev->cluster_ops->slot_number(bitmap->mddev);
goto re_read;
}

Expand Down Expand Up @@ -2021,7 +2023,7 @@ static void md_bitmap_free(void *data)
sysfs_put(bitmap->sysfs_can_clear);

if (mddev_is_clustered(bitmap->mddev) && bitmap->mddev->cluster_info &&
bitmap->cluster_slot == md_cluster_ops->slot_number(bitmap->mddev))
bitmap->cluster_slot == bitmap->mddev->cluster_ops->slot_number(bitmap->mddev))
md_cluster_stop(bitmap->mddev);

/* Shouldn't be needed - but just in case.... */
Expand Down Expand Up @@ -2229,7 +2231,7 @@ static int bitmap_load(struct mddev *mddev)
mddev_create_serial_pool(mddev, rdev);

if (mddev_is_clustered(mddev))
md_cluster_ops->load_bitmaps(mddev, mddev->bitmap_info.nodes);
mddev->cluster_ops->load_bitmaps(mddev, mddev->bitmap_info.nodes);

/* Clear out old bitmap info first: Either there is none, or we
* are resuming after someone else has possibly changed things,
Expand Down
18 changes: 12 additions & 6 deletions drivers/md/md-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
struct dlm_lock_resource *bm_lockres;
char str[64];

if (i == md_cluster_ops->slot_number(mddev))
if (i == slot_number(mddev))
continue;

bitmap = mddev->bitmap_ops->get_from_slot(mddev, i);
Expand Down Expand Up @@ -1216,7 +1216,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
*/
static int cluster_check_sync_size(struct mddev *mddev)
{
int current_slot = md_cluster_ops->slot_number(mddev);
int current_slot = slot_number(mddev);
int node_num = mddev->bitmap_info.nodes;
struct dlm_lock_resource *bm_lockres;
struct md_bitmap_stats stats;
Expand Down Expand Up @@ -1612,7 +1612,14 @@ static int gather_bitmaps(struct md_rdev *rdev)
return err;
}

static const struct md_cluster_operations cluster_ops = {
static struct md_cluster_operations cluster_ops = {
.head = {
.type = MD_CLUSTER,
.id = ID_CLUSTER,
.name = "cluster",
.owner = THIS_MODULE,
},

.join = join,
.leave = leave,
.slot_number = slot_number,
Expand Down Expand Up @@ -1642,13 +1649,12 @@ static int __init cluster_init(void)
{
pr_warn("md-cluster: support raid1 and raid10 (limited support)\n");
pr_info("Registering Cluster MD functions\n");
register_md_cluster_operations(&cluster_ops, THIS_MODULE);
return 0;
return register_md_submodule(&cluster_ops.head);
}

static void cluster_exit(void)
{
unregister_md_cluster_operations();
unregister_md_submodule(&cluster_ops.head);
}

module_init(cluster_init);
Expand Down
6 changes: 6 additions & 0 deletions drivers/md/md-cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct mddev;
struct md_rdev;

struct md_cluster_operations {
struct md_submodule_head head;

int (*join)(struct mddev *mddev, int nodes);
int (*leave)(struct mddev *mddev);
int (*slot_number)(struct mddev *mddev);
Expand All @@ -35,4 +37,8 @@ struct md_cluster_operations {
void (*update_size)(struct mddev *mddev, sector_t old_dev_sectors);
};

extern int md_setup_cluster(struct mddev *mddev, int nodes);
extern void md_cluster_stop(struct mddev *mddev);
extern void md_reload_sb(struct mddev *mddev, int raid_disk);

#endif /* _MD_CLUSTER_H */
15 changes: 9 additions & 6 deletions drivers/md/md-linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include <linux/blkdev.h>
#include <linux/raid/md_u.h>
#include <linux/seq_file.h>
#include <linux/module.h>
#include <linux/slab.h>
Expand Down Expand Up @@ -320,9 +319,13 @@ static void linear_quiesce(struct mddev *mddev, int state)
}

static struct md_personality linear_personality = {
.name = "linear",
.level = LEVEL_LINEAR,
.owner = THIS_MODULE,
.head = {
.type = MD_PERSONALITY,
.id = ID_LINEAR,
.name = "linear",
.owner = THIS_MODULE,
},

.make_request = linear_make_request,
.run = linear_run,
.free = linear_free,
Expand All @@ -335,12 +338,12 @@ static struct md_personality linear_personality = {

static int __init linear_init(void)
{
return register_md_personality(&linear_personality);
return register_md_submodule(&linear_personality.head);
}

static void linear_exit(void)
{
unregister_md_personality(&linear_personality);
unregister_md_submodule(&linear_personality.head);
}

module_init(linear_init);
Expand Down
Loading

0 comments on commit 017ff37

Please sign in to comment.