From 28bce06f17bf5b791e67d845f1d72a9a949b3c43 Mon Sep 17 00:00:00 2001 From: Adam Kwolek Date: Mon, 29 Nov 2010 12:28:01 +1100 Subject: [PATCH] imsm: Add support for general migration Internal IMSM procedures need to support the General Migration. It is used during operations like: - Online Capacity Expansion, - migration initialization, - finishing migration, - apply changes to raid disks etc. Signed-off-by: Adam Kwolek Signed-off-by: NeilBrown --- super-intel.c | 62 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/super-intel.c b/super-intel.c index 9b4ad19..46d216e 100644 --- a/super-intel.c +++ b/super-intel.c @@ -2183,7 +2183,8 @@ static void migrate(struct imsm_dev *dev, __u8 to_state, int migr_type) /* duplicate and then set the target end state in map[0] */ memcpy(dest, src, sizeof_imsm_map(src)); - if (migr_type == MIGR_REBUILD) { + if ((migr_type == MIGR_REBUILD) || + (migr_type == MIGR_GEN_MIGR)) { __u32 ord; int i; @@ -2200,18 +2201,26 @@ static void end_migration(struct imsm_dev *dev, __u8 map_state) { struct imsm_map *map = get_imsm_map(dev, 0); struct imsm_map *prev = get_imsm_map(dev, dev->vol.migr_state); - int i; + int i, j; /* merge any IMSM_ORD_REBUILD bits that were not successfully * completed in the last migration. * - * FIXME add support for online capacity expansion and - * raid-level-migration + * FIXME add support for raid-level-migration */ for (i = 0; i < prev->num_members; i++) - map->disk_ord_tbl[i] |= prev->disk_ord_tbl[i]; + for (j = 0; j < map->num_members; j++) + /* during online capacity expansion + * disks position can be changed if takeover is used + */ + if (ord_to_idx(map->disk_ord_tbl[j]) == + ord_to_idx(prev->disk_ord_tbl[i])) { + map->disk_ord_tbl[j] |= prev->disk_ord_tbl[i]; + break; + } dev->vol.migr_state = 0; + dev->vol.migr_type = 0; dev->vol.curr_migr_unit = 0; map->map_state = map_state; } @@ -4323,6 +4332,17 @@ static int update_subarray_imsm(struct supertype *st, char *subarray, } #endif /* MDASSEMBLE */ +static int is_gen_migration(struct imsm_dev *dev) +{ + if (!dev->vol.migr_state) + return 0; + + if (migr_type(dev) == MIGR_GEN_MIGR) + return 1; + + return 0; +} + static int is_rebuilding(struct imsm_dev *dev) { struct imsm_map *migr_map; @@ -4413,8 +4433,7 @@ static struct mdinfo *container_content_imsm(struct supertype *st, char *subarra * unsupported migration */ if (dev->vol.migr_state && - (migr_type(dev) == MIGR_GEN_MIGR || - migr_type(dev) == MIGR_STATE_CHANGE)) { + (migr_type(dev) == MIGR_STATE_CHANGE)) { fprintf(stderr, Name ": cannot assemble volume '%.16s':" " unsupported migration in progress\n", dev->volume); @@ -4697,6 +4716,8 @@ static void handle_missing(struct intel_super *super, struct imsm_dev *dev) super->updates_pending++; } +static void imsm_set_disk(struct active_array *a, int n, int state); + /* Handle dirty -> clean transititions and resync. Degraded and rebuild * states are handled in imsm_set_disk() with one exception, when a * resync is stopped due to a new failure this routine will set the @@ -4772,6 +4793,16 @@ static int imsm_set_array_state(struct active_array *a, int consistent) dev->vol.dirty = 1; super->updates_pending++; } + + /* finalize online capacity expansion/reshape */ + if ((a->curr_action != reshape) && + (a->prev_action == reshape)) { + struct mdinfo *mdi; + + for (mdi = a->info.devs; mdi; mdi = mdi->next) + imsm_set_disk(a, mdi->disk.raid_disk, mdi->curr_state); + } + return consistent; } @@ -4835,6 +4866,23 @@ static void imsm_set_disk(struct active_array *a, int n, int state) end_migration(dev, map_state); super->updates_pending++; a->last_checkpoint = 0; + } else if (is_gen_migration(dev)) { + dprintf("imsm: Detected General Migration in state: "); + if (map_state == IMSM_T_STATE_NORMAL) { + end_migration(dev, map_state); + map = get_imsm_map(dev, 0); + map->failed_disk_num = ~0; + dprintf("normal\n"); + } else { + if (map_state == IMSM_T_STATE_DEGRADED) { + printf("degraded\n"); + end_migration(dev, map_state); + } else { + dprintf("failed\n"); + } + map->map_state = map_state; + } + super->updates_pending++; } }