* [mdadm PATCH] mdopen: open md devices O_RDONLY
@ 2016-12-05 6:27 NeilBrown
2016-12-05 14:26 ` Jes Sorensen
0 siblings, 1 reply; 2+ messages in thread
From: NeilBrown @ 2016-12-05 6:27 UTC (permalink / raw)
To: Jes Sorensen; +Cc: linux-raid, Marc Smith
[-- Attachment #1: Type: text/plain, Size: 1684 bytes --]
There is no need to request write access when opening
the md device, as we never write to it, and none of the
ioctls we use require write access.
If we do open with write access, then when we close, udev notices that
the device was closed after being open for write access, and it
generates a CHANGE event.
This is generally unwanted, and particularly problematic when mdadm is
trying to --stop the array, as the CHANGE event can cause the array to
be re-opened before it completely closed, which results in a new mddev
being allocated.
So just use O_RDONLY instead of O_RDWR.
Reported-by: Marc Smith <marc.smith@mcc.edu>
Signed-off-by: NeilBrown <neilb@suse.com>
---
mdassemble.c | 2 +-
mdopen.c | 4 +---
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/mdassemble.c b/mdassemble.c
index 78d363a328c7..471ffeb03ae4 100644
--- a/mdassemble.c
+++ b/mdassemble.c
@@ -32,7 +32,7 @@ char const Name[] = "mdassemble";
/* from mdopen.c */
int open_mddev(char *dev, int report_errors/*unused*/)
{
- int mdfd = open(dev, O_RDWR);
+ int mdfd = open(dev, O_RDONLY);
if (mdfd < 0)
pr_err("error opening %s: %s\n",
dev, strerror(errno));
diff --git a/mdopen.c b/mdopen.c
index 0ea38749a582..685ca3287304 100644
--- a/mdopen.c
+++ b/mdopen.c
@@ -416,9 +416,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
*/
int open_mddev(char *dev, int report_errors)
{
- int mdfd = open(dev, O_RDWR);
- if (mdfd < 0 && errno == EACCES)
- mdfd = open(dev, O_RDONLY);
+ int mdfd = open(dev, O_RDONLY);
if (mdfd < 0) {
if (report_errors)
pr_err("error opening %s: %s\n",
--
2.10.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [mdadm PATCH] mdopen: open md devices O_RDONLY
2016-12-05 6:27 [mdadm PATCH] mdopen: open md devices O_RDONLY NeilBrown
@ 2016-12-05 14:26 ` Jes Sorensen
0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2016-12-05 14:26 UTC (permalink / raw)
To: NeilBrown; +Cc: linux-raid, Marc Smith
NeilBrown <neilb@suse.com> writes:
> There is no need to request write access when opening
> the md device, as we never write to it, and none of the
> ioctls we use require write access.
>
> If we do open with write access, then when we close, udev notices that
> the device was closed after being open for write access, and it
> generates a CHANGE event.
>
> This is generally unwanted, and particularly problematic when mdadm is
> trying to --stop the array, as the CHANGE event can cause the array to
> be re-opened before it completely closed, which results in a new mddev
> being allocated.
>
> So just use O_RDONLY instead of O_RDWR.
>
> Reported-by: Marc Smith <marc.smith@mcc.edu>
> Signed-off-by: NeilBrown <neilb@suse.com>
> ---
> mdassemble.c | 2 +-
> mdopen.c | 4 +---
> 2 files changed, 2 insertions(+), 4 deletions(-)
Applied!
Thanks,
Jes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-12-05 14:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-05 6:27 [mdadm PATCH] mdopen: open md devices O_RDONLY NeilBrown
2016-12-05 14:26 ` Jes Sorensen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.