]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdmon: bad block support for external metadata - sysfs file open
authorTomasz Majchrzak <tomasz.majchrzak@intel.com>
Thu, 27 Oct 2016 08:53:43 +0000 (10:53 +0200)
committerJes Sorensen <Jes.Sorensen@redhat.com>
Mon, 28 Nov 2016 22:45:56 +0000 (17:45 -0500)
Open 'badblocks' and 'unacknowledged_bad_blocks' sysfs files for each
disk in the array. Add them to the list of files observed by monitor.

Signed-off-by: Tomasz Majchrzak <tomasz.majchrzak@intel.com>
Reviewed-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
managemon.c
mdadm.h
monitor.c

index 6d1b3d859cfb9c87c7fc96fa48f0634fbf199171..3c1d4cb070dec004a6c1f2d200232c4c136816d2 100644 (file)
@@ -115,6 +115,8 @@ static void close_aa(struct active_array *aa)
        for (d = aa->info.devs; d; d = d->next) {
                close(d->recovery_fd);
                close(d->state_fd);
+               close(d->bb_fd);
+               close(d->ubb_fd);
        }
 
        if (aa->action_fd >= 0)
@@ -433,6 +435,21 @@ static int disk_init_and_add(struct mdinfo *disk, struct mdinfo *clone,
                close(disk->recovery_fd);
                return -1;
        }
+       disk->bb_fd = sysfs_open2(aa->info.sys_name, disk->sys_name,
+                                "bad_blocks");
+       if (disk->bb_fd < 0) {
+               close(disk->recovery_fd);
+               close(disk->state_fd);
+               return -1;
+       }
+       disk->ubb_fd = sysfs_open2(aa->info.sys_name, disk->sys_name,
+                                 "unacknowledged_bad_blocks");
+       if (disk->ubb_fd < 0) {
+               close(disk->recovery_fd);
+               close(disk->state_fd);
+               close(disk->bb_fd);
+               return -1;
+       }
        disk->prev_state = read_dev_state(disk->state_fd);
        disk->curr_state = disk->prev_state;
        disk->next = aa->info.devs;
diff --git a/mdadm.h b/mdadm.h
index 62a373bf58b07c6a56c00407154bc70d48b54ec3..ccdda789484bb0b10e75a4917e6bbe7c218301c0 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -311,6 +311,8 @@ struct mdinfo {
        /* Device info for mdmon: */
        int recovery_fd;
        int state_fd;
+       int bb_fd;
+       int ubb_fd;
        #define DS_FAULTY       1
        #define DS_INSYNC       2
        #define DS_WRITE_MOSTLY 4
index 3c554abaf144f2ae1e7bd69ea3de757a1f71f83e..bdb58deeb020f1420a34bed6fdc09ea272171e17 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -454,6 +454,8 @@ static int read_and_act(struct active_array *a)
                                dprintf_cont(" %d:removed", mdi->disk.raid_disk);
                                close(mdi->state_fd);
                                close(mdi->recovery_fd);
+                               close(mdi->bb_fd);
+                               close(mdi->ubb_fd);
                                mdi->state_fd = -1;
                        } else
                                ret |= ARRAY_BUSY;
@@ -583,8 +585,11 @@ static int wait_and_act(struct supertype *container, int nowait)
                add_fd(&rfds, &maxfd, a->info.state_fd);
                add_fd(&rfds, &maxfd, a->action_fd);
                add_fd(&rfds, &maxfd, a->sync_completed_fd);
-               for (mdi = a->info.devs ; mdi ; mdi = mdi->next)
+               for (mdi = a->info.devs ; mdi ; mdi = mdi->next) {
                        add_fd(&rfds, &maxfd, mdi->state_fd);
+                       add_fd(&rfds, &maxfd, mdi->bb_fd);
+                       add_fd(&rfds, &maxfd, mdi->ubb_fd);
+               }
 
                ap = &(*ap)->next;
        }