return fd;
}
-void sysfs_init_dev(struct mdinfo *mdi, unsigned long devid)
+void sysfs_init_dev(struct mdinfo *mdi, dev_t devid)
{
snprintf(mdi->sys_name,
sizeof(mdi->sys_name), "dev-%s", devid2kname(devid));
goto abort;
sra->array.layout = strtoul(buf, NULL, 0);
}
- if (options & GET_DISKS) {
+ if (options & (GET_DISKS|GET_STATE)) {
strcpy(base, "raid_disks");
if (load_sys(fname, buf, sizeof(buf)))
goto abort;
sra->array.raid_disks = strtoul(buf, NULL, 0);
}
- if (options & GET_DEGRADED) {
- strcpy(base, "degraded");
- if (load_sys(fname, buf, sizeof(buf)))
- goto abort;
- sra->array.failed_disks = strtoul(buf, NULL, 0);
- }
if (options & GET_COMPONENT) {
strcpy(base, "component_size");
if (load_sys(fname, buf, sizeof(buf)))
dev->disk.raid_disk = strtoul(buf, &ep, 10);
if (*ep) dev->disk.raid_disk = -1;
+ sra->array.nr_disks++;
strcpy(dbase, "block/dev");
if (load_sys(fname, buf, sizeof(buf))) {
/* assume this is a stale reference to a hot
* removed device
*/
- free(dev);
- continue;
+ if (!(options & GET_DEVS_ALL)) {
+ free(dev);
+ continue;
+ }
+ } else {
+ sscanf(buf, "%d:%d", &dev->disk.major, &dev->disk.minor);
}
- sra->array.nr_disks++;
- sscanf(buf, "%d:%d", &dev->disk.major, &dev->disk.minor);
- /* special case check for block devices that can go 'offline' */
- strcpy(dbase, "block/device/state");
- if (load_sys(fname, buf, sizeof(buf)) == 0 &&
- strncmp(buf, "offline", 7) == 0) {
- free(dev);
- continue;
+ if (!(options & GET_DEVS_ALL)) {
+ /* special case check for block devices that can go 'offline' */
+ strcpy(dbase, "block/device/state");
+ if (load_sys(fname, buf, sizeof(buf)) == 0 &&
+ strncmp(buf, "offline", 7) == 0) {
+ free(dev);
+ continue;
+ }
}
/* finally add this disk to the array */
strcpy(dbase, "state");
if (load_sys(fname, buf, sizeof(buf)))
goto abort;
- if (strstr(buf, "faulty")) {
+ if (strstr(buf, "faulty"))
dev->disk.state |= (1<<MD_DISK_FAULTY);
- sra->array.failed_disks++;
- } else {
+ else {
sra->array.working_disks++;
if (strstr(buf, "in_sync")) {
dev->disk.state |= (1<<MD_DISK_SYNC);
dev->errors = strtoul(buf, NULL, 0);
}
}
+
+ if ((options & GET_STATE) && sra->array.raid_disks)
+ sra->array.failed_disks = sra->array.raid_disks -
+ sra->array.active_disks - sra->array.spare_disks;
+
closedir(dir);
return sra;
if (sysfs_set_str(info, NULL, "consistency_policy",
map_num(consistency_policies,
info->consistency_policy))) {
- pr_err("This kernel does not support PPL\n");
- return 1;
+ pr_err("This kernel does not support PPL. Falling back to consistency-policy=resync.\n");
+ info->consistency_policy = CONSISTENCY_POLICY_RESYNC;
}
}
rv = sysfs_set_num(sra, sd, "offset", sd->data_offset);
rv |= sysfs_set_num(sra, sd, "size", (sd->component_size+1) / 2);
if (sra->array.level != LEVEL_CONTAINER) {
- if (sd->consistency_policy == CONSISTENCY_POLICY_PPL) {
+ if (sra->consistency_policy == CONSISTENCY_POLICY_PPL) {
rv |= sysfs_set_num(sra, sd, "ppl_sector", sd->ppl_sector);
rv |= sysfs_set_num(sra, sd, "ppl_size", sd->ppl_size);
}