All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Monitor: don't assume mdadm parameter is a block device
@ 2017-06-16 14:02 Tomasz Majchrzak
       [not found] ` <585FFF8D-0238-4AB3-AA77-4C3C00C3C55D@suse.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Tomasz Majchrzak @ 2017-06-16 14:02 UTC (permalink / raw)
  To: linux-raid; +Cc: jes.sorensen, zlliu, Tomasz Majchrzak

If symlink (e.g. /dev/md/raid) is passed as a parameter to mdadm --wait,
it fails as it's not able to find a corresponding entry in /proc/mdstat
output. Get parameter file major:minor and look for block device name in
sysfs. This commit is partial revert of commit 9e04ac1c43e6
("mdadm/util: unify fstat checking blkdev into function").

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
---
 Monitor.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

v2:
 next Zhilong Liu commit id

diff --git a/Monitor.c b/Monitor.c
index bef2f1b..c9f24bd 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -982,12 +982,21 @@ static void link_containers_with_subarrays(struct state *list)
 int Wait(char *dev)
 {
 	char devnm[32];
+	dev_t rdev;
+	char *tmp;
 	int rv = 1;
 	int frozen_remaining = 3;
 
-	if (!stat_is_blkdev(dev, NULL))
+	if (!stat_is_blkdev(dev, &rdev))
+		return 2;
+
+	tmp = devid2devnm(rdev);
+	if (!tmp) {
+		pr_err("Cannot get md device name.\n");
 		return 2;
-	strcpy(devnm, dev);
+	}
+
+	strcpy(devnm, tmp);
 
 	while(1) {
 		struct mdstat_ent *ms = mdstat_read(1, 0);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Monitor: don't assume mdadm parameter is a block device
       [not found] ` <585FFF8D-0238-4AB3-AA77-4C3C00C3C55D@suse.com>
@ 2017-06-19  9:16   ` Tomasz Majchrzak
  2017-06-19  9:19     ` [PATCH v2] " Tomasz Majchrzak
  2017-06-20  0:30     ` [PATCH] " Zhilong Liu
  0 siblings, 2 replies; 5+ messages in thread
From: Tomasz Majchrzak @ 2017-06-19  9:16 UTC (permalink / raw)
  To: Zhilong Liu; +Cc: linux-raid, jes.sorensen

On Sun, Jun 18, 2017 at 10:10:02PM +0800, Zhilong Liu wrote:
> 
> 
> > 在 2017年6月16日,22:02,Tomasz Majchrzak <tomasz.majchrzak@intel.com> 写道:
> > 
> > If symlink (e.g. /dev/md/raid) is passed as a parameter to mdadm --wait,
> > it fails as it's not able to find a corresponding entry in /proc/mdstat
> > output. Get parameter file major:minor and look for block device name in
> > sysfs. This commit is partial revert of commit 9e04ac1c43e6
> > ("mdadm/util: unify fstat checking blkdev into function").
> > 
> 
> Thanks very much for catching this.  Just remind a typo in (commit title), correct fstat as stat.

Will do.

> 
> > Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
> > ---
> > Monitor.c | 13 +++++++++++--
> > 1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > v2:
> > next Zhilong Liu commit id
> > 
> > diff --git a/Monitor.c b/Monitor.c
> > index bef2f1b..c9f24bd 100644
> > --- a/Monitor.c
> > +++ b/Monitor.c
> > @@ -982,12 +982,21 @@ static void link_containers_with_subarrays(struct state *list)
> > int Wait(char *dev)
> > {
> >    char devnm[32];
> > +    dev_t rdev;
> > +    char *tmp;
> >    int rv = 1;
> >    int frozen_remaining = 3;
> > 
> > -    if (!stat_is_blkdev(dev, NULL))
> > +    if (!stat_is_blkdev(dev, &rdev))
> > +        return 2;
> > +
> > +    tmp = devid2devnm(rdev);
> > +    if (!tmp) {
> > +        pr_err("Cannot get md device name.\n");
> >        return 2;
> > -    strcpy(devnm, dev);
> > +    }
> > +
> > +    strcpy(devnm, tmp);
> > 
> 
> Quite agreed with the code here, just a small question,  I may use 
> > strcpy(devnm, devid2devnm(rdev));
> directly since stat_is_blkdev() has returned the major/minor devid. I don't know "get md device name " would be failed in which scenario. 
> I'm asking this question since I haven't been familiar with all raids situations. :-)
> 
> Thanks again,
> Zhilong

Well, there could be a race and RAID array might get stopped between two
calls (stat_is_blkdev, devid2devnm) so corresponding sysfs entry would not
exist. Also I don't think we should assume devid2devnm implementation won't
change one day. I just did it safe way, otherwise static code analyzers
would complain.

Tomek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] Monitor: don't assume mdadm parameter is a block device
  2017-06-19  9:16   ` Tomasz Majchrzak
@ 2017-06-19  9:19     ` Tomasz Majchrzak
  2017-07-10 17:40       ` Jes Sorensen
  2017-06-20  0:30     ` [PATCH] " Zhilong Liu
  1 sibling, 1 reply; 5+ messages in thread
From: Tomasz Majchrzak @ 2017-06-19  9:19 UTC (permalink / raw)
  To: linux-raid; +Cc: jes.sorensen, zlliu, Tomasz Majchrzak

If symlink (e.g. /dev/md/raid) is passed as a parameter to mdadm --wait,
it fails as it's not able to find a corresponding entry in /proc/mdstat
output. Get parameter file major:minor and look for block device name in
sysfs. This commit is partial revert of commit 9e04ac1c43e6
("mdadm/util: unify stat checking blkdev into function").

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
---
 Monitor.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

v2:
  corrected referenced commit title in commit message

diff --git a/Monitor.c b/Monitor.c
index bef2f1b..c9f24bd 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -982,12 +982,21 @@ static void link_containers_with_subarrays(struct state *list)
 int Wait(char *dev)
 {
 	char devnm[32];
+	dev_t rdev;
+	char *tmp;
 	int rv = 1;
 	int frozen_remaining = 3;
 
-	if (!stat_is_blkdev(dev, NULL))
+	if (!stat_is_blkdev(dev, &rdev))
+		return 2;
+
+	tmp = devid2devnm(rdev);
+	if (!tmp) {
+		pr_err("Cannot get md device name.\n");
 		return 2;
-	strcpy(devnm, dev);
+	}
+
+	strcpy(devnm, tmp);
 
 	while(1) {
 		struct mdstat_ent *ms = mdstat_read(1, 0);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Monitor: don't assume mdadm parameter is a block device
  2017-06-19  9:16   ` Tomasz Majchrzak
  2017-06-19  9:19     ` [PATCH v2] " Tomasz Majchrzak
@ 2017-06-20  0:30     ` Zhilong Liu
  1 sibling, 0 replies; 5+ messages in thread
From: Zhilong Liu @ 2017-06-20  0:30 UTC (permalink / raw)
  To: Tomasz Majchrzak; +Cc: linux-raid, jes.sorensen



> 在 2017年6月19日,17:16,Tomasz Majchrzak <tomasz.majchrzak@intel.com> 写道:
> 
>> On Sun, Jun 18, 2017 at 10:10:02PM +0800, Zhilong Liu wrote:
>> 
>> 
>>> 在 2017年6月16日,22:02,Tomasz Majchrzak <tomasz.majchrzak@intel.com> 写道:
>>> 
>>> If symlink (e.g. /dev/md/raid) is passed as a parameter to mdadm --wait,
>>> it fails as it's not able to find a corresponding entry in /proc/mdstat
>>> output. Get parameter file major:minor and look for block device name in
>>> sysfs. This commit is partial revert of commit 9e04ac1c43e6
>>> ("mdadm/util: unify fstat checking blkdev into function").
>>> 
>> 
>> Thanks very much for catching this.  Just remind a typo in (commit title), correct fstat as stat.
> 
> Will do.
> 
>> 
>>> Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
>>> ---
>>> Monitor.c | 13 +++++++++++--
>>> 1 file changed, 11 insertions(+), 2 deletions(-)
>>> 
>>> v2:
>>> next Zhilong Liu commit id
>>> 
>>> diff --git a/Monitor.c b/Monitor.c
>>> index bef2f1b..c9f24bd 100644
>>> --- a/Monitor.c
>>> +++ b/Monitor.c
>>> @@ -982,12 +982,21 @@ static void link_containers_with_subarrays(struct state *list)
>>> int Wait(char *dev)
>>> {
>>>   char devnm[32];
>>> +    dev_t rdev;
>>> +    char *tmp;
>>>   int rv = 1;
>>>   int frozen_remaining = 3;
>>> 
>>> -    if (!stat_is_blkdev(dev, NULL))
>>> +    if (!stat_is_blkdev(dev, &rdev))
>>> +        return 2;
>>> +
>>> +    tmp = devid2devnm(rdev);
>>> +    if (!tmp) {
>>> +        pr_err("Cannot get md device name.\n");
>>>       return 2;
>>> -    strcpy(devnm, dev);
>>> +    }
>>> +
>>> +    strcpy(devnm, tmp);
>>> 
>> 
>> Quite agreed with the code here, just a small question,  I may use 
>>> strcpy(devnm, devid2devnm(rdev));
>> directly since stat_is_blkdev() has returned the major/minor devid. I don't know "get md device name " would be failed in which scenario. 
>> I'm asking this question since I haven't been familiar with all raids situations. :-)
>> 
>> Thanks again,
>> Zhilong
> 
> Well, there could be a race and RAID array might get stopped between two
> calls (stat_is_blkdev, devid2devnm) so corresponding sysfs entry would not
> exist. Also I don't think we should assume devid2devnm implementation won't
> change one day. I just did it safe way, otherwise static code analyzers
> would complain.
> 

Thanks very much for the correction. :-)

Zhilong 


> Tomek
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Monitor: don't assume mdadm parameter is a block device
  2017-06-19  9:19     ` [PATCH v2] " Tomasz Majchrzak
@ 2017-07-10 17:40       ` Jes Sorensen
  0 siblings, 0 replies; 5+ messages in thread
From: Jes Sorensen @ 2017-07-10 17:40 UTC (permalink / raw)
  To: Tomasz Majchrzak, linux-raid; +Cc: zlliu

On 06/19/2017 05:19 AM, Tomasz Majchrzak wrote:
> If symlink (e.g. /dev/md/raid) is passed as a parameter to mdadm --wait,
> it fails as it's not able to find a corresponding entry in /proc/mdstat
> output. Get parameter file major:minor and look for block device name in
> sysfs. This commit is partial revert of commit 9e04ac1c43e6
> ("mdadm/util: unify stat checking blkdev into function").
> 
> Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
> ---
>   Monitor.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
> 
> v2:
>    corrected referenced commit title in commit message

Applied!

Thanks,
Jes


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-07-10 17:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-16 14:02 [PATCH] Monitor: don't assume mdadm parameter is a block device Tomasz Majchrzak
     [not found] ` <585FFF8D-0238-4AB3-AA77-4C3C00C3C55D@suse.com>
2017-06-19  9:16   ` Tomasz Majchrzak
2017-06-19  9:19     ` [PATCH v2] " Tomasz Majchrzak
2017-07-10 17:40       ` Jes Sorensen
2017-06-20  0:30     ` [PATCH] " Zhilong Liu

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.