]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdopen: open md devices O_RDONLY
authorNeilBrown <neilb@suse.com>
Mon, 5 Dec 2016 06:27:03 +0000 (17:27 +1100)
committerJes Sorensen <Jes.Sorensen@redhat.com>
Mon, 5 Dec 2016 14:26:22 +0000 (09:26 -0500)
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>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
mdassemble.c
mdopen.c

index 78d363a328c7e7449cc3b23f91534ee1a88ea5ca..471ffeb03ae410641eb44f8f29d2ba8469d49a05 100644 (file)
@@ -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));
index 0ea38749a58226f9766a36621ef1e4ae521082d2..685ca3287304fc3b4f9ff22488cd717895dc4c21 100644 (file)
--- 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",