diff mbox series

[09/13] Manage: check device policies in manage_add_external()

Message ID 20240229115217.26543-10-mariusz.tkaczyk@linux.intel.com (mailing list archive)
State Accepted
Headers show
Series Custom drives policies verification | expand

Commit Message

Mariusz Tkaczyk Feb. 29, 2024, 11:52 a.m. UTC
Only IMSM is going to use device policies so it is added to
manage_add_external(). Test policies before adding the drive to
container.

The change blocks adding new device to the container which already
contains not matching devices

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
 Manage.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/Manage.c b/Manage.c
index 969d0ea9d81f..96e5ee5427a2 100644
--- a/Manage.c
+++ b/Manage.c
@@ -704,6 +704,7 @@  mdadm_status_t manage_add_external(struct supertype *st, int fd, char *disk_name
 {
 	mdadm_status_t rv = MDADM_STATUS_ERROR;
 	char container_devpath[MD_NAME_MAX];
+	struct dev_policy *pols = NULL;
 	struct mdinfo new_mdi;
 	struct mdinfo *sra = NULL;
 	int container_fd;
@@ -722,6 +723,9 @@  mdadm_status_t manage_add_external(struct supertype *st, int fd, char *disk_name
 				       0, 1))
 		goto out;
 
+	if (mddev_test_and_add_drive_policies(st, &pols, container_fd, 1))
+		goto out;
+
 	Kill(disk_name, NULL, 0, -1, 0);
 
 	disk_fd = dev_open(disk_name, O_RDWR | O_EXCL | O_DIRECT);
@@ -730,6 +734,9 @@  mdadm_status_t manage_add_external(struct supertype *st, int fd, char *disk_name
 		goto out;
 	}
 
+	if (drive_test_and_add_policies(st, &pols, disk_fd, 1))
+		goto out;
+
 	if (st->ss->add_to_super(st, disc, disk_fd, disk_name, INVALID_SECTORS))
 		goto out;
 
@@ -760,6 +767,7 @@  mdadm_status_t manage_add_external(struct supertype *st, int fd, char *disk_name
 
 out:
 	close(container_fd);
+	dev_policy_free(pols);
 
 	if (sra)
 		sysfs_free(sra);