Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH] policy: NULL path isn't really acceptable - use the devname
@ 2013-12-19 12:02 Lukasz Dorau
  2013-12-19 12:06 ` Dorau, Lukasz
  2014-01-06  6:12 ` NeilBrown
  0 siblings, 2 replies; 3+ messages in thread
From: Lukasz Dorau @ 2013-12-19 12:02 UTC (permalink / raw)
  To: neilb; +Cc: linux-raid, pawel.baldysiak

According to:
	commit b451aa4846c5ccca5447a6b6d45e5623b8c8e961
	Fix handling for "auto" line in mdadm.conf

a NULL path isn't really acceptable and the devname should be used instead.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
---
 policy.c |   35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/policy.c b/policy.c
index b4f3943..104695d 100644
--- a/policy.c
+++ b/policy.c
@@ -200,26 +200,25 @@ static char *disk_path(struct mdinfo *disk)
 	int rv;
 
 	by_path = opendir(symlink);
-	if (!by_path)
-		return NULL;
-	prefix_len = strlen(symlink);
-
-	while ((ent = readdir(by_path)) != NULL) {
-		if (ent->d_type != DT_LNK)
-			continue;
-		strncpy(symlink + prefix_len,
-			ent->d_name,
-			sizeof(symlink) - prefix_len);
-		if (stat(symlink, &stb) < 0)
-			continue;
-		if ((stb.st_mode & S_IFMT) != S_IFBLK)
-			continue;
-		if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
-			continue;
+	if (by_path) {
+		prefix_len = strlen(symlink);
+		while ((ent = readdir(by_path)) != NULL) {
+			if (ent->d_type != DT_LNK)
+				continue;
+			strncpy(symlink + prefix_len,
+					ent->d_name,
+					sizeof(symlink) - prefix_len);
+			if (stat(symlink, &stb) < 0)
+				continue;
+			if ((stb.st_mode & S_IFMT) != S_IFBLK)
+				continue;
+			if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
+				continue;
+			closedir(by_path);
+			return xstrdup(ent->d_name);
+		}
 		closedir(by_path);
-		return xstrdup(ent->d_name);
 	}
-	closedir(by_path);
 	/* A NULL path isn't really acceptable - use the devname.. */
 	sprintf(symlink, "/sys/dev/block/%d:%d", disk->disk.major, disk->disk.minor);
 	rv = readlink(symlink, nm, sizeof(nm)-1);


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

* RE: [PATCH] policy: NULL path isn't really acceptable - use the devname
  2013-12-19 12:02 [PATCH] policy: NULL path isn't really acceptable - use the devname Lukasz Dorau
@ 2013-12-19 12:06 ` Dorau, Lukasz
  2014-01-06  6:12 ` NeilBrown
  1 sibling, 0 replies; 3+ messages in thread
From: Dorau, Lukasz @ 2013-12-19 12:06 UTC (permalink / raw)
  To: neilb@suse.de; +Cc: linux-raid@vger.kernel.org, Baldysiak, Pawel

On Thursday, December 19, 2013 1:02 PM Lukasz Dorau <lukasz.dorau@intel.com> wrote:
> 
> According to:
> 	commit b451aa4846c5ccca5447a6b6d45e5623b8c8e961
> 	Fix handling for "auto" line in mdadm.conf
> 
> a NULL path isn't really acceptable and the devname should be used instead.
> 
> Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
> ---
>  policy.c |   35 +++++++++++++++++------------------
>  1 file changed, 17 insertions(+), 18 deletions(-)
> 
> diff --git a/policy.c b/policy.c
> index b4f3943..104695d 100644
> --- a/policy.c
> +++ b/policy.c
> @@ -200,26 +200,25 @@ static char *disk_path(struct mdinfo *disk)
>  	int rv;
> 
>  	by_path = opendir(symlink);
> -	if (!by_path)
> -		return NULL;
> -	prefix_len = strlen(symlink);
> -
> -	while ((ent = readdir(by_path)) != NULL) {
> -		if (ent->d_type != DT_LNK)
> -			continue;
> -		strncpy(symlink + prefix_len,
> -			ent->d_name,
> -			sizeof(symlink) - prefix_len);
> -		if (stat(symlink, &stb) < 0)
> -			continue;
> -		if ((stb.st_mode & S_IFMT) != S_IFBLK)
> -			continue;
> -		if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
> -			continue;
> +	if (by_path) {
> +		prefix_len = strlen(symlink);
> +		while ((ent = readdir(by_path)) != NULL) {
> +			if (ent->d_type != DT_LNK)
> +				continue;
> +			strncpy(symlink + prefix_len,
> +					ent->d_name,
> +					sizeof(symlink) - prefix_len);
> +			if (stat(symlink, &stb) < 0)
> +				continue;
> +			if ((stb.st_mode & S_IFMT) != S_IFBLK)
> +				continue;
> +			if (stb.st_rdev != makedev(disk->disk.major, disk-
> >disk.minor))
> +				continue;
> +			closedir(by_path);
> +			return xstrdup(ent->d_name);
> +		}
>  		closedir(by_path);
> -		return xstrdup(ent->d_name);
>  	}
> -	closedir(by_path);
>  	/* A NULL path isn't really acceptable - use the devname.. */
>  	sprintf(symlink, "/sys/dev/block/%d:%d", disk->disk.major, disk->disk.minor);
>  	rv = readlink(symlink, nm, sizeof(nm)-1);
> 

The same thing could be done like that:

diff --git a/policy.c b/policy.c
index b4f3943..bafe215 100644
--- a/policy.c
+++ b/policy.c
@@ -201,7 +201,7 @@ static char *disk_path(struct mdinfo *disk)
 
 	by_path = opendir(symlink);
 	if (!by_path)
-		return NULL;
+		goto use_devname;
 	prefix_len = strlen(symlink);
 
 	while ((ent = readdir(by_path)) != NULL) {
@@ -220,6 +220,7 @@ static char *disk_path(struct mdinfo *disk)
 		return xstrdup(ent->d_name);
 	}
 	closedir(by_path);
+use_devname:
 	/* A NULL path isn't really acceptable - use the devname.. */
 	sprintf(symlink, "/sys/dev/block/%d:%d", disk->disk.major, disk->disk.minor);
 	rv = readlink(symlink, nm, sizeof(nm)-1);
--

Lukasz


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

* Re: [PATCH] policy: NULL path isn't really acceptable - use the devname
  2013-12-19 12:02 [PATCH] policy: NULL path isn't really acceptable - use the devname Lukasz Dorau
  2013-12-19 12:06 ` Dorau, Lukasz
@ 2014-01-06  6:12 ` NeilBrown
  1 sibling, 0 replies; 3+ messages in thread
From: NeilBrown @ 2014-01-06  6:12 UTC (permalink / raw)
  To: Lukasz Dorau; +Cc: linux-raid, pawel.baldysiak

[-- Attachment #1: Type: text/plain, Size: 2016 bytes --]

On Thu, 19 Dec 2013 13:02:12 +0100 Lukasz Dorau <lukasz.dorau@intel.com>
wrote:

> According to:
> 	commit b451aa4846c5ccca5447a6b6d45e5623b8c8e961
> 	Fix handling for "auto" line in mdadm.conf
> 
> a NULL path isn't really acceptable and the devname should be used instead.
> 
> Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
> ---
>  policy.c |   35 +++++++++++++++++------------------
>  1 file changed, 17 insertions(+), 18 deletions(-)
> 
> diff --git a/policy.c b/policy.c
> index b4f3943..104695d 100644
> --- a/policy.c
> +++ b/policy.c
> @@ -200,26 +200,25 @@ static char *disk_path(struct mdinfo *disk)
>  	int rv;
>  
>  	by_path = opendir(symlink);
> -	if (!by_path)
> -		return NULL;
> -	prefix_len = strlen(symlink);
> -
> -	while ((ent = readdir(by_path)) != NULL) {
> -		if (ent->d_type != DT_LNK)
> -			continue;
> -		strncpy(symlink + prefix_len,
> -			ent->d_name,
> -			sizeof(symlink) - prefix_len);
> -		if (stat(symlink, &stb) < 0)
> -			continue;
> -		if ((stb.st_mode & S_IFMT) != S_IFBLK)
> -			continue;
> -		if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
> -			continue;
> +	if (by_path) {
> +		prefix_len = strlen(symlink);
> +		while ((ent = readdir(by_path)) != NULL) {
> +			if (ent->d_type != DT_LNK)
> +				continue;
> +			strncpy(symlink + prefix_len,
> +					ent->d_name,
> +					sizeof(symlink) - prefix_len);
> +			if (stat(symlink, &stb) < 0)
> +				continue;
> +			if ((stb.st_mode & S_IFMT) != S_IFBLK)
> +				continue;
> +			if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
> +				continue;
> +			closedir(by_path);
> +			return xstrdup(ent->d_name);
> +		}
>  		closedir(by_path);
> -		return xstrdup(ent->d_name);
>  	}
> -	closedir(by_path);
>  	/* A NULL path isn't really acceptable - use the devname.. */
>  	sprintf(symlink, "/sys/dev/block/%d:%d", disk->disk.major, disk->disk.minor);
>  	rv = readlink(symlink, nm, sizeof(nm)-1);


Applied, thanks.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

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

end of thread, other threads:[~2014-01-06  6:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-19 12:02 [PATCH] policy: NULL path isn't really acceptable - use the devname Lukasz Dorau
2013-12-19 12:06 ` Dorau, Lukasz
2014-01-06  6:12 ` NeilBrown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox