Re: [PATCH] mdadm/Monitor:dev should be a block file when use --waitclean

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Zhilong Liu <zlliu@xxxxxxxx> writes:
> Monitor: mdadm --wait-clean /dev/mdX, the dev should
> be a block file, otherwise fd2devnm returns NULL and
> then triggers core dumped.
>
> Signed-off-by: Zhilong Liu <zlliu@xxxxxxxx>
> ---
>  Monitor.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/Monitor.c b/Monitor.c
> index f8850d3..5a2b5ca 100644
> --- a/Monitor.c
> +++ b/Monitor.c
> @@ -1065,7 +1065,17 @@ int WaitClean(char *dev, int sock, int verbose)
>  	struct mdinfo *mdi;
>  	int rv = 1;
>  	char devnm[32];
> +	struct stat stb;
>  
> +	if (stat(dev, &stb) != 0) {
> +		pr_err("Cannot find %s: %s\n", dev,
> +			strerror(errno));

Please use the 80 characters in the line.

> +		return 2;
> +	}
> +	if ((S_IFMT & stb.st_mode) != S_IFBLK) {
> +		pr_err("%s is not a block device.\n", dev);
> +		return 2;
> +	}
>  	fd = open(dev, O_RDONLY);
>  	if (fd < 0) {
>  		if (verbose)

We have 7-8 instances of this throughout the code (stat and fstat).
Maybe we should make it a utility function instead of duplicating it
further.

Cheers,
Jes
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux