summaryrefslogtreecommitdiff
path: root/super-intel.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2023-03-20 14:43:54 +1100
committerJes Sorensen <jes@trained-monkey.org>2023-03-20 13:08:27 -0400
commit420dafcd38c5949c2ddb90ad6873e7edd625db30 (patch)
tree7834af59ed9da285ae1598a925a66d91175690d7 /super-intel.c
parent2e10c46d0906b1a1ec40e8f5005ccb63125dcd9e (diff)
downloadmdadm-420dafcd38c5949c2ddb90ad6873e7edd625db30.tar.gz
Improvements for IMSM_NO_PLATFORM testing.
Factor out IMSM_NO_PLATFORM testing into a single function that caches the result. Allow mdmon to explicitly set the result to "1" so that we don't need the ENV var in the unit file Check if the kernel command line contains "mdadm.imsm.test=1" and in that case assert NO_PLATFORM. This simplifies testing in a virtual machine. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to 'super-intel.c')
-rw-r--r--super-intel.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/super-intel.c b/super-intel.c
index e155a8a..a5c86cb 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -20,6 +20,7 @@
#define HAVE_STDINT_H 1
#include "mdadm.h"
#include "mdmon.h"
+#include "dlink.h"
#include "sha1.h"
#include "platform-intel.h"
#include <values.h>
@@ -629,6 +630,44 @@ static const char *_sys_dev_type[] = {
[SYS_DEV_VMD] = "VMD"
};
+static int no_platform = -1;
+
+static int check_no_platform(void)
+{
+ static const char search[] = "mdadm.imsm.test=1";
+ FILE *fp;
+
+ if (no_platform >= 0)
+ return no_platform;
+
+ if (check_env("IMSM_NO_PLATFORM")) {
+ no_platform = 1;
+ return 1;
+ }
+ fp = fopen("/proc/cmdline", "r");
+ if (fp) {
+ char *l = conf_line(fp);
+ char *w = l;
+
+ do {
+ if (strcmp(w, search) == 0)
+ no_platform = 1;
+ w = dl_next(w);
+ } while (w != l);
+ free_line(l);
+ fclose(fp);
+ if (no_platform >= 0)
+ return no_platform;
+ }
+ no_platform = 0;
+ return 0;
+}
+
+void imsm_set_no_platform(int v)
+{
+ no_platform = v;
+}
+
const char *get_sys_dev_type(enum sys_dev_type type)
{
if (type >= SYS_DEV_MAX)
@@ -2699,7 +2738,7 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
int result=1;
if (enumerate_only) {
- if (check_env("IMSM_NO_PLATFORM"))
+ if (check_no_platform())
return 0;
list = find_intel_devices();
if (!list)
@@ -4722,7 +4761,7 @@ static int find_intel_hba_capability(int fd, struct intel_super *super, char *de
devname);
return 1;
}
- if (!is_fd_valid(fd) || check_env("IMSM_NO_PLATFORM")) {
+ if (!is_fd_valid(fd) || check_no_platform()) {
super->orom = NULL;
super->hba = NULL;
return 0;
@@ -10697,7 +10736,7 @@ static int imsm_get_allowed_degradation(int level, int raid_disks,
******************************************************************************/
int validate_container_imsm(struct mdinfo *info)
{
- if (check_env("IMSM_NO_PLATFORM"))
+ if (check_no_platform())
return 0;
struct sys_dev *idev;