extern int Restore_metadata(char *dev, char *dir, struct context *c,
struct supertype *st, int only);
+int md_array_valid(int fd);
int md_array_active(int fd);
int md_get_array_info(int fd, struct mdu_array_info_s *array);
int md_set_array_info(int fd, struct mdu_array_info_s *array);
*/
int open_mddev(char *dev, int report_errors)
{
- struct mdu_array_info_s array;
int mdfd = open(dev, O_RDONLY);
if (mdfd < 0) {
return -1;
}
- if (md_get_array_info(mdfd, &array) != 0) {
+ if (md_array_valid(mdfd) == 0) {
close(mdfd);
if (report_errors)
pr_err("%s does not appear to be an md device\n", dev);
return ret;
}
+int md_array_valid(int fd)
+{
+ struct mdinfo *sra;
+ int ret;
+
+ sra = sysfs_read(fd, NULL, GET_ARRAY_STATE);
+ if (sra) {
+ if (sra->array_state != ARRAY_UNKNOWN_STATE)
+ ret = 0;
+ else
+ ret = -ENODEV;
+
+ free(sra);
+ } else {
+ /*
+ * GET_ARRAY_INFO doesn't provide access to the proper state
+ * information, so fallback to a basic check for raid_disks != 0
+ */
+ ret = ioctl(fd, RAID_VERSION);
+ }
+
+ return !ret;
+}
+
int md_array_active(int fd)
{
struct mdinfo *sra;