Skip to contentSkip to conversation

Incremental: remove obsoleted calls to udisks

PATCH Superseded Coly Li 2 participants 3 messages May 5, 2023 MD RAID

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Coly Li

author
#0 lore raw

PATCH 1/1 Incremental: remove obsoleted calls to udisks

Utilility udisks is removed from udev upstream, calling this obsoleted command in run_udisks() doesn't make any sense now.

This patch removes the calls chain of udisks, which includes routines run_udisk(), force_remove(), and 2 locations where force_remove() are called.

In remove_from_member_array() and IncrementalRemove(), if return value of calling Manage_subdevs() is not 0, don't call force_remove() and only print error message when parameter 'verbose' is true.

Cc Mariusz Tkaczyk <[email protected]>
Cc Jes Sorensen <[email protected]>
---
 Incremental.c | 50 +++++++-------------------------------------------
 1 file changed, 7 insertions(+), 43 deletions(-)
Incremental.c +7 -43
index 49a71f7..e1a953a 100644
@@ -1630,54 +1630,18 @@ release:
 	return rv;
 }
 
-static void run_udisks(char *arg1, char *arg2)
-{
-	int pid = fork();
-	int status;
-	if (pid == 0) {
-		manage_fork_fds(1);
-		execl("/usr/bin/udisks", "udisks", arg1, arg2, NULL);
-		execl("/bin/udisks", "udisks", arg1, arg2, NULL);
-		exit(1);
-	}
-	while (pid > 0 && wait(&status) != pid)
-		;
-}
-
-static int force_remove(char *devnm, int fd, struct mdinfo *mdi, int verbose)
-{
-	int rv;
-	int devid = devnm2devid(devnm);
-
-	run_udisks("--unmount", map_dev(major(devid), minor(devid), 0));
-	rv = Manage_stop(devnm, fd, verbose, 1);
-	if (rv) {
-		/* At least we can try to trigger a 'remove' */
-		sysfs_uevent(mdi, "remove");
-		if (verbose)
-			pr_err("Fail to stop %s too.\n", devnm);
-	}
-	return rv;
-}
-
 static void remove_from_member_array(struct mdstat_ent *memb,
 				    struct mddev_dev *devlist, int verbose)
 {
 	int rv;
-	struct mdinfo mmdi;
 	int subfd = open_dev(memb->devnm);
 
 	if (subfd >= 0) {
 		rv = Manage_subdevs(memb->devnm, subfd, devlist, verbose,
 				    0, UOPT_UNDEFINED, 0);
-		if (rv & 2) {
-			if (sysfs_init(&mmdi, -1, memb->devnm))
-				pr_err("unable to initialize sysfs for: %s\n",
-				       memb->devnm);
-			else
-				force_remove(memb->devnm, subfd, &mmdi,
-					     verbose);
-		}
+		if ((rv & 2) && verbose)
+			pr_err("Fail to remove %s from array.\n", memb->devnm);
+
 		close(subfd);
 	}
 }
@@ -1763,10 +1727,10 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
 		rv |= Manage_subdevs(ent->devnm, mdfd, &devlist,
 				    verbose, 0, UOPT_UNDEFINED, 0);
 		if (rv & 2) {
-		/* Failed due to EBUSY, try to stop the array.
-		 * Give udisks a chance to unmount it first.
-		 */
-			rv = force_remove(ent->devnm, mdfd, &mdi, verbose);
+			if (verbose)
+				pr_err("Fail to remove %s from array.\n", ent->devnm);
+			/* Only return 0 or 1 */
+			rv = !!rv;
 			goto end;
 		}
 	}
Signature · 1 line
2.35.3
#1 lore raw
Quoted 37 lines · On Fri, 5 May 2023 13:22:31 +0800 Coly Li <[email protected]> wrote:

Utilility udisks is removed from udev upstream, calling this obsoleted command in run_udisks() doesn't make any sense now.

This patch removes the calls chain of udisks, which includes routines run_udisk(), force_remove(), and 2 locations where force_remove() are called.

In remove_from_member_array() and IncrementalRemove(), if return value of calling Manage_subdevs() is not 0, don't call force_remove() and only print error message when parameter 'verbose' is true.

Cc Mariusz Tkaczyk <[email protected]>
Cc Jes Sorensen <[email protected]>
---
 Incremental.c | 50 +++++++-------------------------------------------
 1 file changed, 7 insertions(+), 43 deletions(-)
Incremental.c +0 -11
index 49a71f7..e1a953a 100644
@@ -1630,54 +1630,18 @@ release:
 	return rv;
 }
 
-static void run_udisks(char *arg1, char *arg2)
-{
-	int pid = fork();
-	int status;
-	if (pid == 0) {
-		manage_fork_fds(1);
-		execl("/usr/bin/udisks", "udisks", arg1, arg2, NULL);
-		execl("/bin/udisks", "udisks", arg1, arg2, NULL);
-		exit(1);
-	}
-	while (pid > 0 && wait(&status) != pid)

Incremental.c release: · line 1653

Quoted 10 lines
Incremental.c +0 -10
-		;
-}
-
-static int force_remove(char *devnm, int fd, struct mdinfo *mdi, int verbose)
-{
-	int rv;
-	int devid = devnm2devid(devnm);
-
-	run_udisks("--unmount", map_dev(major(devid), minor(devid), 0));
-	rv = Manage_stop(devnm, fd, verbose, 1);

Hi Coly,
Please see that you removed Manage_stop(). Now mdadm won't try to stop failed arrays. It is good change but please describe it.

Quoted 19 lines
Incremental.c +0 -10
-	if (rv) {
-		/* At least we can try to trigger a 'remove' */
-		sysfs_uevent(mdi, "remove");
-		if (verbose)
-			pr_err("Fail to stop %s too.\n", devnm);
-	}
-	return rv;
-}
-
 static void remove_from_member_array(struct mdstat_ent *memb,
 				    struct mddev_dev *devlist, int verbose)
 {
 	int rv;
-	struct mdinfo mmdi;
 	int subfd = open_dev(memb->devnm);
 
 	if (subfd >= 0) {
 		rv = Manage_subdevs(memb->devnm, subfd, devlist, verbose,
 				    0, UOPT_UNDEFINED, 0);

Incremental.c release: · line 1642

Quoted 10 lines
Incremental.c +1 -8
-		if (rv & 2) {
-			if (sysfs_init(&mmdi, -1, memb->devnm))
-				pr_err("unable to initialize sysfs for:
 %s\n",
-				       memb->devnm);
-			else
-				force_remove(memb->devnm, subfd, &mmdi,
-					     verbose);
-		}
+		if ((rv & 2) && verbose)

There is a rule (at least we at Intel tried to follow) to use indirect comparisons only for pointers. I know that we don't have log level in mdadm, we need to compare with values directly:
if ((rv & 2) && verbose > 0)

It is not mandatory, just to let you know.

Incremental.c release: · line 1645

Quoted 2 lines
Incremental.c +1 -0
+			pr_err("Fail to remove %s from array.\n",
 memb->devnm);

Could we make this error less "dangerous"? I mean that someone may think that something is wrong here but it is not - the message is expected in case when raid becomes failed. Note that for raid5 disk is removed from array but EBUSY is returned anyway. Maybe we should check for MD_BROKEN in array_state to differentiate and make errors more detailed?

Same applies to the native case below.

Quoted 6 lines
Incremental.c +0 -0
 		close(subfd);
 	}
 }
@@ -1763,10 +1727,10 @@ int IncrementalRemove(char *devname, char *id_path,
 int verbose) rv |= Manage_subdevs(ent->devnm, mdfd, &devlist,
 				    verbose, 0, UOPT_UNDEFINED, 0);

Incremental.c int IncrementalRemove(char *devname, char *id_path, · line 1734

Quoted 10 lines
Incremental.c +4 -4
 		if (rv & 2) {
-		/* Failed due to EBUSY, try to stop the array.
-		 * Give udisks a chance to unmount it first.
-		 */
-			rv = force_remove(ent->devnm, mdfd, &mdi, verbose);
+			if (verbose)
+				pr_err("Fail to remove %s from array.\n",
 ent->devnm);
+			/* Only return 0 or 1 */
+			rv = !!rv;

we are in if (rv & 2) so I think that we can simply set rv = 1, am I right?

Quoted 3 lines
Incremental.c +0 -0
 			goto end;
 		}

}

Thanks,
Mariusz

author
#2 lore raw
Quoted 46 lines · Mariusz Tkaczyk
Quoted 43 lines · On Fri, 5 May 2023 13:22:31 +0800 Coly Li <[email protected]> wrote:

Utilility udisks is removed from udev upstream, calling this obsoleted command in run_udisks() doesn't make any sense now.

This patch removes the calls chain of udisks, which includes routines run_udisk(), force_remove(), and 2 locations where force_remove() are called.

In remove_from_member_array() and IncrementalRemove(), if return value of calling Manage_subdevs() is not 0, don't call force_remove() and only print error message when parameter 'verbose' is true.

Cc Mariusz Tkaczyk <[email protected]>
Cc Jes Sorensen <[email protected]>

---
Incremental.c | 50 +++++++-------------------------------------------

1 file changed, 7 insertions(+), 43 deletions(-)
Incremental.c +0 -17
index 49a71f7..e1a953a 100644
@@ -1630,54 +1630,18 @@ release:
 	return rv;
 }
 
-static void run_udisks(char *arg1, char *arg2)
-{
-	int pid = fork();
-	int status;
-	if (pid == 0) {
-		manage_fork_fds(1);
-		execl("/usr/bin/udisks", "udisks", arg1, arg2, NULL);
-		execl("/bin/udisks", "udisks", arg1, arg2, NULL);
-		exit(1);
-	}
-	while (pid > 0 && wait(&status) != pid)
-		;
-}
-
-static int force_remove(char *devnm, int fd, struct mdinfo *mdi, int verbose)
-{
-	int rv;
Quoted 8 lines

Incremental.c release: · line 1653

Quoted 4 lines
Incremental.c +0 -4
-	int devid = devnm2devid(devnm);
-
-	run_udisks("--unmount", map_dev(major(devid), minor(devid), 0));
-	rv = Manage_stop(devnm, fd, verbose, 1);

Hi Coly,
Please see that you removed Manage_stop(). Now mdadm won't try to stop failed arrays. It is good change but please describe it.

Copied. I will describe in commit log when I remove the call to Manage_stop().

Quoted 36 lines
Quoted 20 lines
Incremental.c +0 -10
-	if (rv) {
-		/* At least we can try to trigger a 'remove' */
-		sysfs_uevent(mdi, "remove");
-		if (verbose)
-			pr_err("Fail to stop %s too.\n", devnm);
-	}
-	return rv;
-}
-
 static void remove_from_member_array(struct mdstat_ent *memb,
 				    struct mddev_dev *devlist, int verbose)
 {
 	int rv;
-	struct mdinfo mmdi;
 	int subfd = open_dev(memb->devnm);
 
 	if (subfd >= 0) {
 		rv = Manage_subdevs(memb->devnm, subfd, devlist, verbose,
 				    0, UOPT_UNDEFINED, 0);

Incremental.c release: · line 1642

Quoted 10 lines
Incremental.c +1 -8
-		if (rv & 2) {
-			if (sysfs_init(&mmdi, -1, memb->devnm))
-				pr_err("unable to initialize sysfs for:
 %s\n",
-				       memb->devnm);
-			else
-				force_remove(memb->devnm, subfd, &mmdi,
-					     verbose);
-		}
+		if ((rv & 2) && verbose)

There is a rule (at least we at Intel tried to follow) to use indirect comparisons only for pointers. I know that we don't have log level in mdadm, we need to compare with values directly:
if ((rv & 2) && verbose > 0)

Quoted 1 line

It is not mandatory, just to let you know.

I see difference ways to check verbose are mixed. But yes, comparing directly with values is better. I will follow your suggestion.

Quoted 10 lines

Incremental.c release: · line 1645

Quoted 2 lines
Incremental.c +1 -0
+			pr_err("Fail to remove %s from array.\n",
 memb->devnm);

Could we make this error less "dangerous"? I mean that someone may think that something is wrong here but it is not - the message is expected in case when raid becomes failed. Note that for raid5 disk is removed from array but EBUSY is returned anyway. Maybe we should check for MD_BROKEN in array_state to differentiate and make errors more detailed?

Same applies to the native case below.

I agree. Let me improve this.

Quoted 10 lines
Quoted 10 lines
Incremental.c +0 -0
 		close(subfd);
	}
}
Incremental.c +0 -2
@@ -1763,10 +1727,10 @@ int IncrementalRemove(char *devname, char *id_path,
 int verbose) rv |= Manage_subdevs(ent->devnm, mdfd, &devlist,
 				    verbose, 0, UOPT_UNDEFINED, 0);
 		if (rv & 2) {
-		/* Failed due to EBUSY, try to stop the array.
-		 * Give udisks a chance to unmount it first.
Quoted 9 lines

Incremental.c int IncrementalRemove(char *devname, char *id_path, int verbose) · line 1733

Quoted 7 lines
Incremental.c +4 -2
-		 */
-			rv = force_remove(ent->devnm, mdfd, &mdi, verbose);
+			if (verbose)
+				pr_err("Fail to remove %s from array.\n",
 ent->devnm);
+			/* Only return 0 or 1 */
+			rv = !!rv;

we are in if (rv & 2) so I think that we can simply set rv = 1, am I right?

OK, I will change it.

Quoted 3 lines
Quoted 3 lines
Incremental.c +0 -0
 			goto end;
 		}
	}

Thanks for your review.

Signature · 1 line
Coly Li