mdopen/open_mddev: Use md_get_array_info() to determine valid array

md_get_array_info() can be used instead of md_get_version() to
determine this is in fact a valid array.

Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
This commit is contained in:
Jes Sorensen 2017-04-05 15:44:20 -04:00
parent 15d924d363
commit 40b054e1dc
1 changed files with 5 additions and 1 deletions

View File

@ -416,19 +416,23 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
*/
int open_mddev(char *dev, int report_errors)
{
struct mdu_array_info_s array;
int mdfd = open(dev, O_RDONLY);
if (mdfd < 0) {
if (report_errors)
pr_err("error opening %s: %s\n",
dev, strerror(errno));
return -1;
}
if (md_get_version(mdfd) <= 0) {
if (md_get_array_info(mdfd, &array) != 0) {
close(mdfd);
if (report_errors)
pr_err("%s does not appear to be an md device\n", dev);
return -2;
}
return mdfd;
}