mdopen: open md devices O_RDONLY
PATCH 1/1 mdopen: open md devices O_RDONLY
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.
--- mdassemble.c | 2 +- mdopen.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
mdassemble.c +1 -1
@@ -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));
mdopen.c +1 -3
@@ -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",
Signature · 1 line
2.10.2
Jes Sorensen
AppliedQuoted 13 lines · NeilBrown
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.
Quoted 8 lines
So just use
O_RDONLYinstead ofO_RDWR.Reported-by Marc Smith <[email protected]>Signed-off-by NeilBrown <[email protected]>--- mdassemble.c | 2 +- mdopen.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
Applied!
Thanks,
Jes