linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: jes@trained-monkey.org
Cc: linux-raid@vger.kernel.org,
	Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Subject: [PATCH 08/13] Create: Use device policies
Date: Thu, 29 Feb 2024 12:52:12 +0100	[thread overview]
Message-ID: <20240229115217.26543-9-mariusz.tkaczyk@linux.intel.com> (raw)
In-Reply-To: <20240229115217.26543-1-mariusz.tkaczyk@linux.intel.com>

Generate and compare policies, abort if policies do not match.
It is tested for both create modes, with container and disk list
specified directly. It is used if supertype supports it.

For a case when disk list is specified, container may contain more
devices, so additional check on container is done to analyze all disks.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
 Create.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/Create.c b/Create.c
index 0b7762661c76..4397ff49554d 100644
--- a/Create.c
+++ b/Create.c
@@ -497,6 +497,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 	 */
 	int mdfd;
 	unsigned long long minsize = 0, maxsize = 0;
+	dev_policy_t *custom_pols = NULL;
 	char *mindisc = NULL;
 	char *maxdisc = NULL;
 	char *name = ident->name;
@@ -588,6 +589,9 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 				first_missing = subdevs * 2;
 				second_missing = subdevs * 2;
 				insert_point = subdevs * 2;
+
+				if (mddev_test_and_add_drive_policies(st, &custom_pols, fd, 1))
+					exit(1);
 			}
 		}
 		if (fd >= 0)
@@ -739,7 +743,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 			close(dfd);
 			exit(2);
 		}
-		close(dfd);
+
 		info.array.working_disks++;
 		if (dnum < s->raiddisks && dv->disposition != 'j')
 			info.array.active_disks++;
@@ -812,6 +816,11 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 			}
 		}
 
+		if (drive_test_and_add_policies(st, &custom_pols, dfd, 1))
+			exit(1);
+
+		close(dfd);
+
 		if (dv->disposition == 'j')
 			goto skip_size_check;  /* skip write journal for size check */
 
@@ -886,6 +895,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 			close(fd);
 		}
 	}
+
 	if (missing_disks == dnum && !have_container) {
 		pr_err("Subdevs can't be all missing\n");
 		return 1;
@@ -1140,25 +1150,30 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 		goto abort_locked;
 	}
 
-	if (did_default && c->verbose >= 0) {
+	if (did_default) {
 		if (is_subarray(info.text_version)) {
 			char devnm[MD_NAME_MAX];
 			struct mdinfo *mdi;
 
 			sysfs_get_container_devnm(&info, devnm);
 
-			mdi = sysfs_read(-1, devnm, GET_VERSION);
+			mdi = sysfs_read(-1, devnm, GET_VERSION | GET_DEVS);
 			if (!mdi) {
 				pr_err("Cannot open sysfs for container %s\n", devnm);
 				goto abort_locked;
 			}
 
-			pr_info("Creating array inside %s container /dev/%s\n", mdi->text_version,
-				devnm);
+			if (sysfs_test_and_add_drive_policies(st, &custom_pols, mdi, 1))
+				goto abort_locked;
+
+			if (c->verbose >= 0)
+				pr_info("Creating array inside %s container /dev/%s\n",
+					mdi->text_version, devnm);
 
 			sysfs_free(mdi);
-		} else
+		} else if (c->verbose >= 0) {
 			pr_info("Defaulting to version %s metadata\n", info.text_version);
+		}
 	}
 
 	map_update(&map, fd2devnm(mdfd), info.text_version,
@@ -1328,6 +1343,8 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 	udev_unblock();
 	close(mdfd);
 	sysfs_uevent(&info, "change");
+	dev_policy_free(custom_pols);
+
 	return 0;
 
  abort:
@@ -1339,5 +1356,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
 
 	if (mdfd >= 0)
 		close(mdfd);
+
+	dev_policy_free(custom_pols);
 	return 1;
 }
-- 
2.35.3


  parent reply	other threads:[~2024-02-29 11:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 11:52 [PATCH 00/13] Custom drives policies verification Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 01/13] mdadm: Add functions for spare criteria verification Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 02/13] mdadm: drop get_required_spare_criteria() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 03/13] Manage: fix check after dereference issue Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 04/13] Manage: implement manage_add_external() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 05/13] mdadm: introduce sysfs_get_container_devnm() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 06/13] mdadm.h: Introduce custom device policies Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 07/13] mdadm: test_and_add device policies implementation Mariusz Tkaczyk
2024-02-29 11:52 ` Mariusz Tkaczyk [this message]
2024-02-29 11:52 ` [PATCH 09/13] Manage: check device policies in manage_add_external() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 10/13] Monitor, Incremental: use device policies Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 11/13] imsm: test_and_add_device_policies() implementation Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 12/13] mdadm: drop get_disk_controller_domain() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 13/13] Revert "policy.c: Avoid to take spare without defined domain by imsm" Mariusz Tkaczyk
2024-03-11 10:05 ` [PATCH 00/13] Custom drives policies verification Mariusz Tkaczyk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240229115217.26543-9-mariusz.tkaczyk@linux.intel.com \
    --to=mariusz.tkaczyk@linux.intel.com \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).