summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-31 05:50:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-01-31 05:50:16 +0000
commit19c986195eab02a3b1da7b532df623cf46d92418 (patch)
tree639e479365923111fbeb91a7d24dad570d50d0ff
parentAdding upstream version 4.2+20231121. (diff)
downloadmdadm-19c986195eab02a3b1da7b532df623cf46d92418.tar.xz
mdadm-19c986195eab02a3b1da7b532df623cf46d92418.zip
Adding upstream version 4.2+20240118.upstream/4.2+20240118
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--Assemble.c9
-rw-r--r--Build.c4
-rw-r--r--Create.c2
-rw-r--r--Detail.c7
-rw-r--r--Grow.c51
-rw-r--r--Incremental.c4
-rw-r--r--Manage.c13
-rw-r--r--Monitor.c6
-rw-r--r--config.c2
-rw-r--r--managemon.c6
-rw-r--r--maps.c4
-rw-r--r--mdadm.c7
-rw-r--r--mdadm.h18
-rw-r--r--monitor.c24
-rw-r--r--msg.c4
-rw-r--r--super-intel.c63
-rw-r--r--super1.c20
-rw-r--r--sysfs.c78
-rwxr-xr-xtest4
-rw-r--r--tests/00linear5
-rw-r--r--tests/00names8
-rw-r--r--tests/00raid04
-rw-r--r--tests/00readonly8
-rw-r--r--tests/02lineargrow5
-rw-r--r--tests/03assem-incr8
-rw-r--r--tests/03r0assem4
-rw-r--r--tests/04r0update6
-rw-r--r--tests/func.sh11
-rw-r--r--util.c2
29 files changed, 158 insertions, 229 deletions
diff --git a/Assemble.c b/Assemble.c
index 0557a00..9d04205 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -1806,12 +1806,6 @@ try_again:
i, mddev, devices[j].devname);
}
}
-#if 0
- if (!(super.disks[i].i.disk.state & (1 << MD_DISK_FAULTY))) {
- pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
- i, mddev);
- }
-#endif
}
if (c->force && !clean && !is_container(content->array.level) &&
!enough(content->array.level, content->array.raid_disks,
@@ -2021,8 +2015,7 @@ int assemble_container_content(struct supertype *st, int mdfd,
if (dev)
continue;
/* Don't want this one any more */
- if (sysfs_set_str(sra, dev2, "slot", "none") < 0 &&
- errno == EBUSY) {
+ if (sysfs_set_str(sra, dev2, "slot", STR_COMMON_NONE) < 0 && errno == EBUSY) {
pr_err("Cannot remove old device %s: not updating %s\n", dev2->sys_name, sra->sys_name);
sysfs_free(sra);
return 1;
diff --git a/Build.c b/Build.c
index 657ab31..1fbf859 100644
--- a/Build.c
+++ b/Build.c
@@ -82,7 +82,7 @@ int Build(struct mddev_ident *ident, struct mddev_dev *devlist, struct shape *s,
return 1;
}
- map_update(&map, fd2devnm(mdfd), "none", uuid, chosen_name);
+ map_update(&map, fd2devnm(mdfd), STR_COMMON_NONE, uuid, chosen_name);
map_unlock(&map);
array.level = s->level;
@@ -111,7 +111,7 @@ int Build(struct mddev_ident *ident, struct mddev_dev *devlist, struct shape *s,
goto abort;
}
- if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0)
+ if (s->bitmap_file && str_is_none(s->bitmap_file) == true)
s->bitmap_file = NULL;
if (s->bitmap_file && s->level <= 0) {
pr_err("bitmaps not meaningful with level %s\n",
diff --git a/Create.c b/Create.c
index ddd1a79..8082f54 100644
--- a/Create.c
+++ b/Create.c
@@ -938,7 +938,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
pr_err("automatically enabling write-intent bitmap on large array\n");
s->bitmap_file = "internal";
}
- if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0)
+ if (s->bitmap_file && str_is_none(s->bitmap_file) == true)
s->bitmap_file = NULL;
if (s->consistency_policy == CONSISTENCY_POLICY_PPL &&
diff --git a/Detail.c b/Detail.c
index 57ac336..aaa3dd6 100644
--- a/Detail.c
+++ b/Detail.c
@@ -603,13 +603,6 @@ int Detail(char *dev, struct context *c)
}
if ((st && st->sb) && (info && info->reshape_active)) {
-#if 0
-This is pretty boring
- printf(" Reshape pos'n : %llu%s\n",
- (unsigned long long) info->reshape_progress << 9,
- human_size((unsigned long long)
- info->reshape_progress << 9));
-#endif
if (info->delta_disks != 0)
printf(" Delta Devices : %d, (%d->%d)\n",
info->delta_disks,
diff --git a/Grow.c b/Grow.c
index 8fa9787..f95dae8 100644
--- a/Grow.c
+++ b/Grow.c
@@ -309,7 +309,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
return 1;
}
if (bmf.pathname[0]) {
- if (strcmp(s->bitmap_file,"none") == 0) {
+ if (str_is_none(s->bitmap_file) == true) {
if (ioctl(fd, SET_BITMAP_FILE, -1) != 0) {
pr_err("failed to remove bitmap %s\n",
bmf.pathname);
@@ -325,7 +325,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
return 1;
}
if (array.state & (1 << MD_SB_BITMAP_PRESENT)) {
- if (strcmp(s->bitmap_file, "none")==0) {
+ if (str_is_none(s->bitmap_file) == true) {
array.state &= ~(1 << MD_SB_BITMAP_PRESENT);
if (md_set_array_info(fd, &array) != 0) {
if (array.state & (1 << MD_SB_CLUSTERED))
@@ -340,7 +340,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
return 1;
}
- if (strcmp(s->bitmap_file, "none") == 0) {
+ if (str_is_none(s->bitmap_file) == true) {
pr_err("no bitmap found on %s\n", devname);
return 1;
}
@@ -545,7 +545,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
char *subarray = NULL;
int ret = 0;
char container_dev[PATH_MAX];
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (s->consistency_policy != CONSISTENCY_POLICY_RESYNC &&
s->consistency_policy != CONSISTENCY_POLICY_PPL) {
@@ -594,7 +594,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
}
if (s->consistency_policy == CONSISTENCY_POLICY_PPL) {
- if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0) {
+ if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0) {
ret = 1;
goto free_info;
} else if (strcmp(buf, "reshape\n") == 0) {
@@ -817,12 +817,12 @@ static int freeze(struct supertype *st)
else {
struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
int err;
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (!sra)
return -1;
/* Need to clear any 'read-auto' status */
- if (sysfs_get_str(sra, NULL, "array_state", buf, 20) > 0 &&
+ if (sysfs_get_str(sra, NULL, "array_state", buf, sizeof(buf)) > 0 &&
strncmp(buf, "read-auto", 9) == 0)
sysfs_set_str(sra, NULL, "array_state", "clean");
@@ -838,10 +838,10 @@ static void unfreeze(struct supertype *st)
return unfreeze_container(st);
else {
struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (sra &&
- sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 &&
+ sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
strcmp(buf, "frozen\n") == 0)
sysfs_set_str(sra, NULL, "sync_action", "idle");
sysfs_free(sra);
@@ -851,12 +851,12 @@ static void unfreeze(struct supertype *st)
static void wait_reshape(struct mdinfo *sra)
{
int fd = sysfs_get_fd(sra, NULL, "sync_action");
- char action[20];
+ char action[SYSFS_MAX_BUF_SIZE];
if (fd < 0)
return;
- while (sysfs_fd_get_str(fd, action, 20) > 0 &&
+ while (sysfs_fd_get_str(fd, action, sizeof(action)) > 0 &&
strncmp(action, "reshape", 7) == 0)
sysfs_wait(fd, NULL);
close(fd);
@@ -902,7 +902,7 @@ static int subarray_set_num(char *container, struct mdinfo *sra, char *name, int
* to close a race with the array_state going clean before the
* next write to raid_disks / stripe_cache_size
*/
- char safe[50];
+ char safe[SYSFS_MAX_BUF_SIZE];
int rc;
/* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
@@ -1067,7 +1067,7 @@ int remove_disks_for_takeover(struct supertype *st,
remaining = sd->next;
sysfs_set_str(sra, sd, "state", "faulty");
- sysfs_set_str(sra, sd, "slot", "none");
+ sysfs_set_str(sra, sd, "slot", STR_COMMON_NONE);
/* for external metadata disks should be removed in mdmon */
if (!st->ss->external)
sysfs_set_str(sra, sd, "state", "remove");
@@ -2145,8 +2145,7 @@ size_change_error:
* a backport has been arranged.
*/
if (sra == NULL ||
- sysfs_set_str(sra, NULL, "resync_start",
- "none") < 0)
+ sysfs_set_str(sra, NULL, "resync_start", STR_COMMON_NONE) < 0)
pr_err("--assume-clean not supported with --grow on this kernel\n");
}
md_get_array_info(fd, &array);
@@ -2396,11 +2395,11 @@ release:
static int verify_reshape_position(struct mdinfo *info, int level)
{
int ret_val = 0;
- char buf[40];
+ char buf[SYSFS_MAX_BUF_SIZE];
int rv;
/* read sync_max, failure can mean raid0 array */
- rv = sysfs_get_str(info, NULL, "sync_max", buf, 40);
+ rv = sysfs_get_str(info, NULL, "sync_max", buf, sizeof(buf));
if (rv > 0) {
char *ep;
@@ -3040,7 +3039,7 @@ static int reshape_array(char *container, int fd, char *devname,
unsigned long long array_size;
int done;
struct mdinfo *sra = NULL;
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
/* when reshaping a RAID0, the component_size might be zero.
* So try to fix that up.
@@ -3916,7 +3915,7 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
unsigned long long array_size = (info->component_size
* reshape->before.data_disks);
int fd;
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
/* First, we unsuspend any region that is now known to be safe.
* If suspend_point is on the 'wrong' side of reshape_progress, then
@@ -4094,8 +4093,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
/* Check that sync_action is still 'reshape' to avoid
* waiting forever on a dead array
*/
- char action[20];
- if (sysfs_get_str(info, NULL, "sync_action", action, 20) <= 0 ||
+ char action[SYSFS_MAX_BUF_SIZE];
+ if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) <= 0 ||
strncmp(action, "reshape", 7) != 0)
break;
/* Some kernels reset 'sync_completed' to zero
@@ -4121,8 +4120,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
*/
if (completed == 0) {
unsigned long long reshapep;
- char action[20];
- if (sysfs_get_str(info, NULL, "sync_action", action, 20) > 0 &&
+ char action[SYSFS_MAX_BUF_SIZE];
+ if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) > 0 &&
strncmp(action, "idle", 4) == 0 &&
sysfs_get_ll(info, NULL,
"reshape_position", &reshapep) == 0)
@@ -4159,8 +4158,8 @@ check_progress:
* it was just a device failure that leaves us degraded but
* functioning.
*/
- if (sysfs_get_str(info, NULL, "reshape_position", buf,
- sizeof(buf)) < 0 || strncmp(buf, "none", 4) != 0) {
+ if (sysfs_get_str(info, NULL, "reshape_position", buf, sizeof(buf)) < 0 ||
+ str_is_none(buf) == false) {
/* The abort might only be temporary. Wait up to 10
* seconds for fd to contain a valid number again.
*/
@@ -4240,7 +4239,7 @@ static int grow_backup(struct mdinfo *sra,
if (sd->disk.state & (1<<MD_DISK_FAULTY))
continue;
if (sd->disk.state & (1<<MD_DISK_SYNC)) {
- char sbuf[100];
+ char sbuf[SYSFS_MAX_BUF_SIZE];
if (sysfs_get_str(sra, sd, "state",
sbuf, sizeof(sbuf)) < 0 ||
diff --git a/Incremental.c b/Incremental.c
index 3551c65..6cbc164 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -670,7 +670,7 @@ static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
continue;
if (d->disk.raid_disk > -1)
- sysfs_set_str(sra, d, "slot", "none");
+ sysfs_set_str(sra, d, "slot", STR_COMMON_NONE);
if (sysfs_set_str(sra, d, "state", "remove") == 0)
if (verbose >= 0)
pr_err("removing old device %s from %s\n",
@@ -1650,7 +1650,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
struct mdstat_ent *ent;
struct mddev_dev devlist;
struct mdinfo mdi;
- char buf[32];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (!id_path)
dprintf("incremental removal without --path <id_path> lacks the possibility to re-add new device in this port\n");
diff --git a/Manage.c b/Manage.c
index f0d4cb0..30302ac 100644
--- a/Manage.c
+++ b/Manage.c
@@ -181,7 +181,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
char container[32];
int err;
int count;
- char buf[32];
+ char buf[SYSFS_MAX_BUF_SIZE];
unsigned long long rd1, rd2;
if (will_retry && verbose == 0)
@@ -312,7 +312,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
if (mdi && is_level456(mdi->array.level) &&
sysfs_attribute_available(mdi, NULL, "sync_action") &&
sysfs_attribute_available(mdi, NULL, "reshape_direction") &&
- sysfs_get_str(mdi, NULL, "sync_action", buf, 20) > 0 &&
+ sysfs_get_str(mdi, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
strcmp(buf, "reshape\n") == 0 &&
sysfs_get_two(mdi, NULL, "raid_disks", &rd1, &rd2) == 2) {
unsigned long long position, curr;
@@ -402,7 +402,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
unsigned long long max_completed;
sysfs_get_ll(mdi, NULL, "reshape_position", &curr);
sysfs_fd_get_str(scfd, buf, sizeof(buf));
- if (strncmp(buf, "none", 4) == 0) {
+ if (str_is_none(buf) == true) {
/* Either reshape has aborted, or hasn't
* quite started yet. Wait a bit and
* check 'sync_action' to see.
@@ -1519,8 +1519,8 @@ int Manage_subdevs(char *devname, int fd,
sprintf(dname, "dev-%s", dv->devname);
sysfd = sysfs_open(fd2devnm(fd), dname, "block/dev");
if (sysfd >= 0) {
- char dn[20];
- if (sysfs_fd_get_str(sysfd, dn, 20) > 0 &&
+ char dn[SYSFS_MAX_BUF_SIZE];
+ if (sysfs_fd_get_str(sysfd, dn, sizeof(dn)) > 0 &&
sscanf(dn, "%d:%d", &mj,&mn) == 2) {
rdev = makedev(mj,mn);
found = 1;
@@ -1749,6 +1749,7 @@ int Update_subarray(char *dev, char *subarray, enum update_opt update,
int fd, rv = 2;
struct mdinfo *info = NULL;
char *update_verb = map_num(update_options, update);
+ bool allow_active = update == UOPT_PPL || update == UOPT_NO_PPL;
memset(st, 0, sizeof(*st));
@@ -1763,7 +1764,7 @@ int Update_subarray(char *dev, char *subarray, enum update_opt update,
goto free_super;
}
- if (is_subarray_active(subarray, st->devnm)) {
+ if (!allow_active && is_subarray_active(subarray, st->devnm)) {
if (verbose >= 0)
pr_err("Subarray %s in %s is active, cannot update %s\n",
subarray, dev, update_verb);
diff --git a/Monitor.c b/Monitor.c
index 9a1f251..824a69f 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -1309,12 +1309,12 @@ int Wait(char *dev)
* sync_action does.
*/
struct mdinfo mdi;
- char buf[21];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (sysfs_init(&mdi, -1, devnm))
return 2;
if (sysfs_get_str(&mdi, NULL, "sync_action",
- buf, 20) > 0 &&
+ buf, sizeof(buf)) > 0 &&
strcmp(buf,"idle\n") != 0) {
e->percent = RESYNC_UNKNOWN;
if (strcmp(buf, "frozen\n") == 0) {
@@ -1393,7 +1393,7 @@ int WaitClean(char *dev, int verbose)
if (rv) {
int state_fd = sysfs_open(fd2devnm(fd), NULL, "array_state");
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
int delay = 5000;
/* minimize the safe_mode_delay and prepare to wait up to 5s
diff --git a/config.c b/config.c
index 5f12a1f..9a04cae 100644
--- a/config.c
+++ b/config.c
@@ -998,7 +998,7 @@ void load_conffile(void)
dl_add(list, dl_strdup("partitions"));
devline(list);
free_line(list);
- } else if (strcmp(conffile, "none") != 0) {
+ } else if (str_is_none(conffile) == false) {
f = fopen(conffile, "r");
/* Debian chose to relocate mdadm.conf into /etc/mdadm/.
* To allow Debian users to compile from clean source and still
diff --git a/managemon.c b/managemon.c
index a7bfa8f..358459e 100644
--- a/managemon.c
+++ b/managemon.c
@@ -454,7 +454,7 @@ static void manage_member(struct mdstat_ent *mdstat,
* trying to find and assign a spare.
* We do that whenever the monitor tells us too.
*/
- char buf[64];
+ char buf[SYSFS_MAX_BUF_SIZE];
int frozen;
struct supertype *container = a->container;
struct mdinfo *mdi;
@@ -664,7 +664,7 @@ static void manage_new(struct mdstat_ent *mdstat,
struct mdinfo *mdi = NULL, *di;
int i, inst;
int failed = 0;
- char buf[40];
+ char buf[SYSFS_MAX_BUF_SIZE];
/* check if array is ready to be monitored */
if (!mdstat->active || !mdstat->level)
@@ -738,7 +738,7 @@ static void manage_new(struct mdstat_ent *mdstat,
* read this information for new arrays only (empty victim)
*/
if ((victim == NULL) &&
- (sysfs_get_str(mdi, NULL, "sync_action", buf, 40) > 0) &&
+ (sysfs_get_str(mdi, NULL, "sync_action", buf, sizeof(buf)) > 0) &&
(strncmp(buf, "reshape", 7) == 0)) {
if (sysfs_get_ll(mdi, NULL, "reshape_position",
&new->last_checkpoint) != 0)
diff --git a/maps.c b/maps.c
index b586679..17f8b54 100644
--- a/maps.c
+++ b/maps.c
@@ -137,14 +137,14 @@ mapping_t faultylayout[] = {
{ "clear", ClearErrors},
{ "flush", ClearFaults},
- { "none", ClearErrors},
+ { STR_COMMON_NONE, ClearErrors},
{ "default", ClearErrors},
{ NULL, UnSet }
};
mapping_t consistency_policies[] = {
{ "unknown", CONSISTENCY_POLICY_UNKNOWN},
- { "none", CONSISTENCY_POLICY_NONE},
+ { STR_COMMON_NONE, CONSISTENCY_POLICY_NONE},
{ "resync", CONSISTENCY_POLICY_RESYNC},
{ "bitmap", CONSISTENCY_POLICY_BITMAP},
{ "journal", CONSISTENCY_POLICY_JOURNAL},
diff --git a/mdadm.c b/mdadm.c
index 62f981d..3f19128 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -1099,7 +1099,7 @@ int main(int argc, char *argv[])
exit(2);
}
if (strcmp(optarg, "internal") == 0 ||
- strcmp(optarg, "none") == 0 ||
+ strcmp(optarg, STR_COMMON_NONE) == 0 ||
strchr(optarg, '/') != NULL) {
s.bitmap_file = optarg;
continue;
@@ -1234,13 +1234,12 @@ int main(int argc, char *argv[])
pr_err("PPL consistency policy is only supported for RAID level 5.\n");
exit(2);
} else if (s.consistency_policy == CONSISTENCY_POLICY_BITMAP &&
- (!s.bitmap_file ||
- strcmp(s.bitmap_file, "none") == 0)) {
+ (!s.bitmap_file || str_is_none(s.bitmap_file) == true)) {
pr_err("--bitmap is required for consistency policy: %s\n",
map_num_s(consistency_policies, s.consistency_policy));
exit(2);
} else if (s.bitmap_file &&
- strcmp(s.bitmap_file, "none") != 0 &&
+ str_is_none(s.bitmap_file) == false &&
s.consistency_policy != CONSISTENCY_POLICY_BITMAP &&
s.consistency_policy != CONSISTENCY_POLICY_JOURNAL) {
pr_err("--bitmap is not compatible with consistency policy: %s\n",
diff --git a/mdadm.h b/mdadm.h
index 8dcd8b8..709b610 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -767,6 +767,8 @@ enum sysfs_read_flags {
GET_DEVS_ALL = (1 << 27),
};
+#define SYSFS_MAX_BUF_SIZE 64
+
/* If fd >= 0, get the array it is open on,
* else use devnm.
*/
@@ -2025,3 +2027,19 @@ static inline int is_container(const int level)
return 1;
return 0;
}
+
+#define STR_COMMON_NONE "none"
+
+/**
+ * str_is_none() - check if @str starts with "none".
+ * @str: string
+ *
+ * return:
+ * true if string starts with "none", false otherwise.
+ */
+static inline bool str_is_none(char *str)
+{
+ if (strncmp(str, STR_COMMON_NONE, sizeof(STR_COMMON_NONE) - 1) == 0)
+ return true;
+ return false;
+}
diff --git a/monitor.c b/monitor.c
index 820a93d..4acec67 100644
--- a/monitor.c
+++ b/monitor.c
@@ -81,15 +81,15 @@ static int read_attr(char *buf, int len, int fd)
static void read_resync_start(int fd, unsigned long long *v)
{
- char buf[30];
+ char buf[SYSFS_MAX_BUF_SIZE];
int n;
- n = read_attr(buf, 30, fd);
+ n = read_attr(buf, sizeof(buf), fd);
if (n <= 0) {
dprintf("Failed to read resync_start (%d)\n", fd);
return;
}
- if (strncmp(buf, "none", 4) == 0)
+ if (str_is_none(buf) == true)
*v = MaxSector;
else
*v = strtoull(buf, NULL, 10);
@@ -98,11 +98,11 @@ static void read_resync_start(int fd, unsigned long long *v)
static unsigned long long read_sync_completed(int fd)
{
unsigned long long val;
- char buf[50];
+ char buf[SYSFS_MAX_BUF_SIZE];
int n;
char *ep;
- n = read_attr(buf, 50, fd);
+ n = read_attr(buf, sizeof(buf), fd);
if (n <= 0)
return 0;
@@ -115,8 +115,8 @@ static unsigned long long read_sync_completed(int fd)
static enum array_state read_state(int fd)
{
- char buf[20];
- int n = read_attr(buf, 20, fd);
+ char buf[SYSFS_MAX_BUF_SIZE];
+ int n = read_attr(buf, sizeof(buf), fd);
if (n <= 0)
return bad_word;
@@ -125,8 +125,8 @@ static enum array_state read_state(int fd)
static enum sync_action read_action( int fd)
{
- char buf[20];
- int n = read_attr(buf, 20, fd);
+ char buf[SYSFS_MAX_BUF_SIZE];
+ int n = read_attr(buf, sizeof(buf), fd);
if (n <= 0)
return bad_action;
@@ -135,7 +135,7 @@ static enum sync_action read_action( int fd)
int read_dev_state(int fd)
{
- char buf[100];
+ char buf[SYSFS_MAX_BUF_SIZE];
int n = read_attr(buf, sizeof(buf), fd);
char *cp;
int rv = 0;
@@ -595,12 +595,12 @@ static int read_and_act(struct active_array *a, fd_set *fds)
*/
if ((a->curr_action != reshape) &&
(a->prev_action == reshape)) {
- char buf[40];
+ char buf[SYSFS_MAX_BUF_SIZE];
if ((sysfs_get_str(&a->info, NULL,
"reshape_position",
buf,
sizeof(buf)) >= 0) &&
- strncmp(buf, "none", 4) == 0)
+ str_is_none(buf) == true)
a->last_checkpoint = a->info.component_size;
}
a->container->ss->set_array_state(a, a->curr_state <= clean);
diff --git a/msg.c b/msg.c
index 45cd450..ba0e25b 100644
--- a/msg.c
+++ b/msg.c
@@ -324,7 +324,7 @@ int block_monitor(char *container, const int freeze)
{
struct mdstat_ent *ent, *e, *e2;
struct mdinfo *sra = NULL;
- char buf[64];
+ char buf[SYSFS_MAX_BUF_SIZE];
int rv = 0;
if (check_mdmon_version(container))
@@ -366,7 +366,7 @@ int block_monitor(char *container, const int freeze)
!sysfs_attribute_available(sra, NULL, "sync_action")) ||
(freeze &&
sysfs_attribute_available(sra, NULL, "sync_action") &&
- sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 &&
+ sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
strcmp(buf, "frozen\n") == 0))
/* pass */;
else {
diff --git a/super-intel.c b/super-intel.c
index 6bdd5c4..6a664a2 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -1825,7 +1825,7 @@ static void print_imsm_dev(struct intel_super *super,
printf("\n");
printf(" Failed disk : ");
if (map->failed_disk_num == 0xff)
- printf("none");
+ printf(STR_COMMON_NONE);
else
printf("%i", map->failed_disk_num);
printf("\n");
@@ -2976,34 +2976,6 @@ static void uuid_from_super_imsm(struct supertype *st, int uuid[4])
memcpy(uuid, buf, 4*4);
}
-#if 0
-static void
-get_imsm_numerical_version(struct imsm_super *mpb, int *m, int *p)
-{
- __u8 *v = get_imsm_version(mpb);
- __u8 *end = mpb->sig + MAX_SIGNATURE_LENGTH;
- char major[] = { 0, 0, 0 };
- char minor[] = { 0 ,0, 0 };
- char patch[] = { 0, 0, 0 };
- char *ver_parse[] = { major, minor, patch };
- int i, j;
-
- i = j = 0;
- while (*v != '\0' && v < end) {
- if (*v != '.' && j < 2)
- ver_parse[i][j++] = *v;
- else {
- i++;
- j = 0;
- }
- v++;
- }
-
- *m = strtol(minor, NULL, 0);
- *p = strtol(patch, NULL, 0);
-}
-#endif
-
static __u32 migr_strip_blocks_resync(struct imsm_dev *dev)
{
/* migr_strip_size when repairing or initializing parity */
@@ -8706,23 +8678,6 @@ static int imsm_set_array_state(struct active_array *a, int consistent)
/* still reshaping, maybe update vol_curr_migr_unit */
goto mark_checkpoint;
} else {
- if (a->last_checkpoint == 0 && a->prev_action == reshape) {
- /* for some reason we aborted the reshape.
- *
- * disable automatic metadata rollback
- * user action is required to recover process
- */
- if (0) {
- struct imsm_map *map2 =
- get_imsm_map(dev, MAP_1);
- dev->vol.migr_state = 0;
- set_migr_type(dev, 0);
- set_vol_curr_migr_unit(dev, 0);
- memcpy(map, map2,
- sizeof_imsm_map(map2));
- super->updates_pending++;
- }
- }
if (a->last_checkpoint >= a->info.component_size) {
unsigned long long array_blocks;
int used_disks;
@@ -11184,11 +11139,11 @@ int recover_backup_imsm(struct supertype *st, struct mdinfo *info)
unsigned int sector_size = super->sector_size;
unsigned long long curr_migr_unit = current_migr_unit(migr_rec);
unsigned long long num_migr_units = get_num_migr_units(migr_rec);
- char buffer[20];
+ char buffer[SYSFS_MAX_BUF_SIZE];
int skipped_disks = 0;
struct dl *dl_disk;
- err = sysfs_get_str(info, NULL, "array_state", (char *)buffer, 20);
+ err = sysfs_get_str(info, NULL, "array_state", (char *)buffer, sizeof(buffer));
if (err < 1)
return 1;
@@ -12107,14 +12062,14 @@ exit_imsm_reshape_super:
static int read_completed(int fd, unsigned long long *val)
{
int ret;
- char buf[50];
+ char buf[SYSFS_MAX_BUF_SIZE];
- ret = sysfs_fd_get_str(fd, buf, 50);
+ ret = sysfs_fd_get_str(fd, buf, sizeof(buf));
if (ret < 0)
return ret;
ret = COMPLETED_OK;
- if (strncmp(buf, "none", 4) == 0) {
+ if (str_is_none(buf) == true) {
ret = COMPLETED_NONE;
} else if (strncmp(buf, "delayed", 7) == 0) {
ret = COMPLETED_DELAYED;
@@ -12182,12 +12137,12 @@ int wait_for_reshape_imsm(struct mdinfo *sra, int ndata)
do {
int rc;
- char action[20];
+ char action[SYSFS_MAX_BUF_SIZE];
int timeout = 3000;
sysfs_wait(fd, &timeout);
if (sysfs_get_str(sra, NULL, "sync_action",
- action, 20) > 0 &&
+ action, sizeof(action)) > 0 &&
strncmp(action, "reshape", 7) != 0) {
if (strncmp(action, "idle", 4) == 0)
break;
@@ -12234,7 +12189,7 @@ int check_degradation_change(struct mdinfo *info,
if (sd->disk.state & (1<<MD_DISK_FAULTY))
continue;
if (sd->disk.state & (1<<MD_DISK_SYNC)) {
- char sbuf[100];
+ char sbuf[SYSFS_MAX_BUF_SIZE];
int raid_disk = sd->disk.raid_disk;
if (sysfs_get_str(info,
diff --git a/super1.c b/super1.c
index 1da71b9..dfde462 100644
--- a/super1.c
+++ b/super1.c
@@ -544,26 +544,6 @@ static void examine_super1(struct supertype *st, char *homehost)
break;
}
printf("\n");
-#if 0
- /* This turns out to just be confusing */
- printf(" Array Slot : %d (", __le32_to_cpu(sb->dev_number));
- for (i = __le32_to_cpu(sb->max_dev); i > 0 ; i--)
- if (__le16_to_cpu(sb->dev_roles[i-1]) != MD_DISK_ROLE_SPARE)
- break;
- for (d = 0; d < i; d++) {
- int role = __le16_to_cpu(sb->dev_roles[d]);
- if (d)
- printf(", ");
- if (role == MD_DISK_ROLE_SPARE)
- printf("empty");
- else
- if(role == MD_DISK_ROLE_FAULTY)
- printf("failed");
- else
- printf("%d", role);
- }
- printf(")\n");
-#endif
printf(" Device Role : ");
role = role_from_sb(sb);
if (role >= MD_DISK_ROLE_FAULTY)
diff --git a/sysfs.c b/sysfs.c
index 94d02f5..f95ef70 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -148,7 +148,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
strcpy(base, "metadata_version");
if (load_sys(fname, buf, sizeof(buf)))
goto abort;
- if (strncmp(buf, "none", 4) == 0) {
+ if (str_is_none(buf) == true) {
sra->array.major_version =
sra->array.minor_version = -1;
strcpy(sra->text_version, "");
@@ -244,7 +244,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
goto abort;
if (strncmp(buf, "file", 4) == 0)
sra->bitmap_offset = 1;
- else if (strncmp(buf, "none", 4) == 0)
+ else if (str_is_none(buf) == true)
sra->bitmap_offset = 0;
else if (buf[0] == '+')
sra->bitmap_offset = strtol(buf+1, NULL, 10);
@@ -664,7 +664,7 @@ int sysfs_set_array(struct mdinfo *info, int vers)
ver[0] = 0;
if (info->array.major_version == -1 &&
info->array.minor_version == -2) {
- char buf[1024];
+ char buf[SYSFS_MAX_BUF_SIZE];
strcat(strcpy(ver, "external:"), info->text_version);
@@ -675,7 +675,7 @@ int sysfs_set_array(struct mdinfo *info, int vers)
* version first, and preserve the flag
*/
if (sysfs_get_str(info, NULL, "metadata_version",
- buf, 1024) > 0)
+ buf, sizeof(buf)) > 0)
if (strlen(buf) >= 9 && buf[9] == '-')
ver[9] = '-';
@@ -803,72 +803,6 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume)
return rv;
}
-#if 0
-int sysfs_disk_to_sg(int fd)
-{
- /* from an open block device, try find and open its corresponding
- * scsi_generic interface
- */
- struct stat st;
- char path[256];
- char sg_path[256];
- char sg_major_minor[10];
- char *c;
- DIR *dir;
- struct dirent *de;
- int major, minor, rv;
-
- if (fstat(fd, &st))
- return -1;
-
- snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/device",
- major(st.st_rdev), minor(st.st_rdev));
-
- dir = opendir(path);
- if (!dir)
- return -1;
-
- de = readdir(dir);
- while (de) {
- if (strncmp("scsi_generic:", de->d_name,
- strlen("scsi_generic:")) == 0)
- break;
- de = readdir(dir);
- }
- closedir(dir);
-
- if (!de)
- return -1;
-
- snprintf(sg_path, sizeof(sg_path), "%s/%s/dev", path, de->d_name);
- fd = open(sg_path, O_RDONLY);
- if (fd < 0)
- return fd;
-
- rv = read(fd, sg_major_minor, sizeof(sg_major_minor));
- close(fd);
- if (rv < 0 || rv == sizeof(sg_major_minor))
- return -1;
- else
- sg_major_minor[rv - 1] = '\0';
-
- c = strchr(sg_major_minor, ':');
- *c = '\0';
- c++;
- major = strtol(sg_major_minor, NULL, 10);
- minor = strtol(c, NULL, 10);
- snprintf(path, sizeof(path), "/dev/.tmp.md.%d:%d:%d",
- (int) getpid(), major, minor);
- if (mknod(path, S_IFCHR|0600, makedev(major, minor))==0) {
- fd = open(path, O_RDONLY);
- unlink(path);
- return fd;
- }
-
- return -1;
-}
-#endif
-
int sysfs_disk_to_scsi_id(int fd, __u32 *id)
{
/* from an open block device, try to retrieve it scsi_id */
@@ -966,11 +900,11 @@ int sysfs_freeze_array(struct mdinfo *sra)
* return 0 if this kernel doesn't support 'frozen'
* return 1 if it worked.
*/
- char buf[20];
+ char buf[SYSFS_MAX_BUF_SIZE];
if (!sysfs_attribute_available(sra, NULL, "sync_action"))
return 1; /* no sync_action == frozen */
- if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0)
+ if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0)
return 0;
if (strcmp(buf, "frozen\n") == 0)
/* Already frozen */
diff --git a/test b/test
index b244453..49a36c3 100755
--- a/test
+++ b/test
@@ -140,6 +140,7 @@ do_help() {
--raidtype= raid0|linear|raid1|raid456|raid10|ddf|imsm
--disable-multipath Disable any tests involving multipath
--disable-integrity Disable slow tests of RAID[56] consistency
+ --disable-linear Disable any tests involving linear
--logdir=directory Directory to save all logfiles in
--save-logs Usually use with --logdir together
--keep-going | --no-error Don't stop on error, ie. run all tests
@@ -255,6 +256,9 @@ parse_args() {
--disable-integrity )
unset INTEGRITY
;;
+ --disable-linear )
+ unset LINEAR
+ ;;
--dev=* )
case ${i##*=} in
loop )
diff --git a/tests/00linear b/tests/00linear
index e3ac655..5a11608 100644
--- a/tests/00linear
+++ b/tests/00linear
@@ -1,6 +1,11 @@
# create a simple linear
+if [ "$LINEAR" != "yes" ]; then
+ echo -ne 'skipping... '
+ exit 0
+fi
+
mdadm -CR $md0 -l linear -n3 $dev0 $dev1 $dev2
check linear
testdev $md0 3 $mdsize2_l 1
diff --git a/tests/00names b/tests/00names
index 7a066d8..d996bef 100644
--- a/tests/00names
+++ b/tests/00names
@@ -4,7 +4,13 @@ set -x -e
conf=$targetdir/mdadm.conf
echo "CREATE names=yes" > $conf
-for i in linear raid0 raid1 raid4 raid5 raid6
+levels=(raid0 raid1 raid4 raid5 raid6)
+
+if [ "$LINEAR" == "yes" ]; then
+ levels+=( linear )
+fi
+
+for i in ${levels[@]}
do
mdadm -CR --config $conf /dev/md/$i -l $i -n 4 $dev4 $dev3 $dev2 $dev1
check $i
diff --git a/tests/00raid0 b/tests/00raid0
index 9b8896c..6407c32 100644
--- a/tests/00raid0
+++ b/tests/00raid0
@@ -16,6 +16,10 @@ check raid0
testdev $md0 5 $size 512
mdadm -S $md0
+if [ "$LINEAR" != "yes" ]; then
+ echo -ne 'skipping... '
+ exit 0
+fi
# now same again with different chunk size
for chunk in 4 32 256
diff --git a/tests/00readonly b/tests/00readonly
index afe243b..80b6362 100644
--- a/tests/00readonly
+++ b/tests/00readonly
@@ -1,8 +1,14 @@
#!/bin/bash
+levels=(raid0 raid1 raid4 raid5 raid6 raid10)
+
+if [ "$LINEAR" == "yes" ]; then
+ levels+=( linear )
+fi
+
for metadata in 0.9 1.0 1.1 1.2
do
- for level in linear raid0 raid1 raid4 raid5 raid6 raid10
+ for level in ${levels[@]}
do
if [[ $metadata == "0.9" && $level == "raid0" ]];
then
diff --git a/tests/02lineargrow b/tests/02lineargrow
index 595bf9f..d17e232 100644
--- a/tests/02lineargrow
+++ b/tests/02lineargrow
@@ -1,6 +1,11 @@
# create a liner array, and add more drives to to.
+if [ "$LINEAR" != "yes" ]; then
+ echo -ne 'skipping... '
+ exit 0
+fi
+
for e in 0.90 1 1.1 1.2
do
case $e in
diff --git a/tests/03assem-incr b/tests/03assem-incr
index f10a1a4..38880a7 100644
--- a/tests/03assem-incr
+++ b/tests/03assem-incr
@@ -6,7 +6,13 @@ set -x -e
# Here just test that a partly "-I" assembled array can
# be completed with "-A"
-for l in 0 1 5 linear
+levels=(raid0 raid1 raid5)
+
+if [ "$LINEAR" == "yes" ]; then
+ levels+=( linear )
+fi
+
+for l in ${levels[@]}
do
mdadm -CR $md0 -l $l -n5 $dev0 $dev1 $dev2 $dev3 $dev4 --assume-clean
mdadm -S md0
diff --git a/tests/03r0assem b/tests/03r0assem
index 44df064..f7c29e8 100644
--- a/tests/03r0assem
+++ b/tests/03r0assem
@@ -64,6 +64,10 @@ mdadm --assemble --scan --config=$conf $md2
$tst
mdadm -S $md2
+if [ "$LINEAR" != "yes" ]; then
+ echo -ne 'skipping... '
+ exit 0
+fi
### Now for version 0...
diff --git a/tests/04r0update b/tests/04r0update
index b95efb0..c495f34 100644
--- a/tests/04r0update
+++ b/tests/04r0update
@@ -1,5 +1,11 @@
# create a raid0, re-assemble with a different super-minor
+
+if [ "$LINEAR" != "yes" ]; then
+ echo -ne 'skipping... '
+ exit 0
+fi
+
mdadm -CR -e 0.90 $md0 -llinear -n3 $dev0 $dev1 $dev2
testdev $md0 3 $mdsize0 1
minor1=`mdadm -E $dev0 | sed -n -e 's/.*Preferred Minor : //p'`
diff --git a/tests/func.sh b/tests/func.sh
index 5053b01..1c1a28a 100644
--- a/tests/func.sh
+++ b/tests/func.sh
@@ -123,6 +123,17 @@ check_env() {
modprobe multipath 2> /dev/null
grep -sq 'Personalities : .*multipath' /proc/mdstat &&
MULTIPATH="yes"
+ if [ "$MULTIPATH" != "yes" ]; then
+ echo "test: skipping tests for multipath, which is removed in upstream 6.8+ kernels"
+ fi
+
+ # Check whether to run linear tests
+ modprobe linear 2> /dev/null
+ grep -sq 'Personalities : .*linear' /proc/mdstat &&
+ LINEAR="yes"
+ if [ "$LINEAR" != "yes" ]; then
+ echo "test: skipping tests for linear, which is removed in upstream 6.8+ kernels"
+ fi
}
do_setup() {
diff --git a/util.c b/util.c
index fa378eb..b145447 100644
--- a/util.c
+++ b/util.c
@@ -1852,7 +1852,7 @@ int remove_disk(int mdfd, struct supertype *st,
/* Remove the disk given by 'info' from the array */
if (st->ss->external)
- rv = sysfs_set_str(sra, info, "slot", "none");
+ rv = sysfs_set_str(sra, info, "slot", STR_COMMON_NONE);
else
rv = ioctl(mdfd, HOT_REMOVE_DISK, makedev(info->disk.major,
info->disk.minor));