Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 394ed8e4 authored by Shaohua Li's avatar Shaohua Li
Browse files

md: cleanup mddev flag clear for takeover



Commit 6995f0b2 (md: takeover should clear unrelated bits) clear
unrelated bits, but it's quite fragile. To avoid error in the future,
define a macro for unsupported mddev flags for each raid type and use it
to clear unsupported mddev flags. This should be less error-prone.

Suggested-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarShaohua Li <shli@fb.com>
parent 99f17890
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@ extern int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
				int is_new);
struct md_cluster_info;

/* change UNSUPPORTED_MDDEV_FLAGS for each array type if new flag is added */
enum mddev_flags {
	MD_ARRAY_FIRST_USE,	/* First use of array, needs initialization */
	MD_CLOSING,		/* If set, we are closing the array, do not open
@@ -702,4 +703,11 @@ static inline int mddev_is_clustered(struct mddev *mddev)
{
	return mddev->cluster_info && mddev->bitmap_info.nodes > 1;
}

/* clear unsupported mddev_flags */
static inline void mddev_clear_unsupported_flags(struct mddev *mddev,
	unsigned long unsupported_flags)
{
	mddev->flags &= ~unsupported_flags;
}
#endif /* _MD_MD_H */
+8 −4
Original line number Diff line number Diff line
@@ -26,6 +26,11 @@
#include "raid0.h"
#include "raid5.h"

#define UNSUPPORTED_MDDEV_FLAGS		\
	((1L << MD_HAS_JOURNAL) |	\
	 (1L << MD_JOURNAL_CLEAN) |	\
	 (1L << MD_FAILFAST_SUPPORTED))

static int raid0_congested(struct mddev *mddev, int bits)
{
	struct r0conf *conf = mddev->private;
@@ -539,8 +544,7 @@ static void *raid0_takeover_raid45(struct mddev *mddev)
	mddev->delta_disks = -1;
	/* make sure it will be not marked as dirty */
	mddev->recovery_cp = MaxSector;
	clear_bit(MD_HAS_JOURNAL, &mddev->flags);
	clear_bit(MD_JOURNAL_CLEAN, &mddev->flags);
	mddev_clear_unsupported_flags(mddev, UNSUPPORTED_MDDEV_FLAGS);

	create_strip_zones(mddev, &priv_conf);

@@ -583,7 +587,7 @@ static void *raid0_takeover_raid10(struct mddev *mddev)
	mddev->degraded = 0;
	/* make sure it will be not marked as dirty */
	mddev->recovery_cp = MaxSector;
	clear_bit(MD_FAILFAST_SUPPORTED, &mddev->flags);
	mddev_clear_unsupported_flags(mddev, UNSUPPORTED_MDDEV_FLAGS);

	create_strip_zones(mddev, &priv_conf);
	return priv_conf;
@@ -626,7 +630,7 @@ static void *raid0_takeover_raid1(struct mddev *mddev)
	mddev->raid_disks = 1;
	/* make sure it will be not marked as dirty */
	mddev->recovery_cp = MaxSector;
	clear_bit(MD_FAILFAST_SUPPORTED, &mddev->flags);
	mddev_clear_unsupported_flags(mddev, UNSUPPORTED_MDDEV_FLAGS);

	create_strip_zones(mddev, &priv_conf);
	return priv_conf;
+6 −2
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@
#include "raid1.h"
#include "bitmap.h"

#define UNSUPPORTED_MDDEV_FLAGS		\
	((1L << MD_HAS_JOURNAL) |	\
	 (1L << MD_JOURNAL_CLEAN))

/*
 * Number of guaranteed r1bios in case of extreme VM load:
 */
@@ -3257,8 +3261,8 @@ static void *raid1_takeover(struct mddev *mddev)
		if (!IS_ERR(conf)) {
			/* Array must appear to be quiesced */
			conf->array_frozen = 1;
			clear_bit(MD_HAS_JOURNAL, &mddev->flags);
			clear_bit(MD_JOURNAL_CLEAN, &mddev->flags);
			mddev_clear_unsupported_flags(mddev,
				UNSUPPORTED_MDDEV_FLAGS);
		}
		return conf;
	}
+4 −1
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@
#include "raid0.h"
#include "bitmap.h"

#define UNSUPPORTED_MDDEV_FLAGS	(1L << MD_FAILFAST_SUPPORTED)

#define cpu_to_group(cpu) cpu_to_node(cpu)
#define ANY_GROUP NUMA_NO_NODE

@@ -7830,7 +7832,8 @@ static void *raid5_takeover_raid1(struct mddev *mddev)

	ret = setup_conf(mddev);
	if (!IS_ERR_VALUE(ret))
		clear_bit(MD_FAILFAST_SUPPORTED, &mddev->flags);
		mddev_clear_unsupported_flags(mddev,
			UNSUPPORTED_MDDEV_FLAGS);
	return ret;
}