Message ID | 20220531102727.9315-2-mariusz.tkaczyk@linux.intel.com (mailing list archive) |
---|---|
State | Accepted, archived |
Delegated to: | Jes Sorensen |
Headers | show |
Series | IMSM autolayout improvements | expand |
> 2022年5月31日 18:27,Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> 写道: > > The routine was added to remove unnecessary get_imsm_dev() and > get_imsm_map() calls, used only to determine disk slot. > > Additionally, enum for IMSM return statues was added for further usage. > > Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Acked-by: Coly Li <colyli@suse.de> Thanks. Coly Li > --- > super-intel.c | 47 ++++++++++++++++++++++++++++++++++++----------- > 1 file changed, 36 insertions(+), 11 deletions(-) > > diff --git a/super-intel.c b/super-intel.c > index d5fad102..f0196948 100644 > --- a/super-intel.c > +++ b/super-intel.c > @@ -366,6 +366,18 @@ struct migr_record { > }; > ASSERT_SIZE(migr_record, 128) > > +/** > + * enum imsm_status - internal IMSM return values representation. > + * @STATUS_OK: function succeeded. > + * @STATUS_ERROR: General error ocurred (not specified). > + * > + * Typedefed to imsm_status_t. > + */ > +typedef enum imsm_status { > + IMSM_STATUS_ERROR = -1, > + IMSM_STATUS_OK = 0, > +} imsm_status_t; > + > struct md_list { > /* usage marker: > * 1: load metadata > @@ -1151,7 +1163,7 @@ static void set_imsm_ord_tbl_ent(struct imsm_map *map, int slot, __u32 ord) > map->disk_ord_tbl[slot] = __cpu_to_le32(ord); > } > > -static int get_imsm_disk_slot(struct imsm_map *map, unsigned idx) > +static int get_imsm_disk_slot(struct imsm_map *map, const unsigned int idx) > { > int slot; > __u32 ord; > @@ -1162,7 +1174,7 @@ static int get_imsm_disk_slot(struct imsm_map *map, unsigned idx) > return slot; > } > > - return -1; > + return IMSM_STATUS_ERROR; > } > > static int get_imsm_raid_level(struct imsm_map *map) > @@ -1177,6 +1189,23 @@ static int get_imsm_raid_level(struct imsm_map *map) > return map->raid_level; > } > > +/** > + * get_disk_slot_in_dev() - retrieve disk slot from &imsm_dev. > + * @super: &intel_super pointer, not NULL. > + * @dev_idx: imsm device index. > + * @idx: disk index. > + * > + * Return: Slot on success, IMSM_STATUS_ERROR otherwise. > + */ > +static int get_disk_slot_in_dev(struct intel_super *super, const __u8 dev_idx, > + const unsigned int idx) > +{ > + struct imsm_dev *dev = get_imsm_dev(super, dev_idx); > + struct imsm_map *map = get_imsm_map(dev, MAP_0); > + > + return get_imsm_disk_slot(map, idx); > +} > + > static int cmp_extent(const void *av, const void *bv) > { > const struct extent *a = av; > @@ -1193,13 +1222,9 @@ static int count_memberships(struct dl *dl, struct intel_super *super) > int memberships = 0; > int i; > > - for (i = 0; i < super->anchor->num_raid_devs; i++) { > - struct imsm_dev *dev = get_imsm_dev(super, i); > - struct imsm_map *map = get_imsm_map(dev, MAP_0); > - > - if (get_imsm_disk_slot(map, dl->index) >= 0) > + for (i = 0; i < super->anchor->num_raid_devs; i++) > + if (get_disk_slot_in_dev(super, i, dl->index) >= 0) > memberships++; > - } > > return memberships; > } > @@ -1909,6 +1934,7 @@ void examine_migr_rec_imsm(struct intel_super *super) > > /* first map under migration */ > map = get_imsm_map(dev, MAP_0); > + > if (map) > slot = get_imsm_disk_slot(map, super->disks->index); > if (map == NULL || slot > 1 || slot < 0) { > @@ -9629,10 +9655,9 @@ static int apply_update_activate_spare(struct imsm_update_activate_spare *u, > /* count arrays using the victim in the metadata */ > found = 0; > for (a = active_array; a ; a = a->next) { > - dev = get_imsm_dev(super, a->info.container_member); > - map = get_imsm_map(dev, MAP_0); > + int dev_idx = a->info.container_member; > > - if (get_imsm_disk_slot(map, victim) >= 0) > + if (get_disk_slot_in_dev(super, dev_idx, victim) >= 0) > found++; > } > > -- > 2.26.2 >
diff --git a/super-intel.c b/super-intel.c index d5fad102..f0196948 100644 --- a/super-intel.c +++ b/super-intel.c @@ -366,6 +366,18 @@ struct migr_record { }; ASSERT_SIZE(migr_record, 128) +/** + * enum imsm_status - internal IMSM return values representation. + * @STATUS_OK: function succeeded. + * @STATUS_ERROR: General error ocurred (not specified). + * + * Typedefed to imsm_status_t. + */ +typedef enum imsm_status { + IMSM_STATUS_ERROR = -1, + IMSM_STATUS_OK = 0, +} imsm_status_t; + struct md_list { /* usage marker: * 1: load metadata @@ -1151,7 +1163,7 @@ static void set_imsm_ord_tbl_ent(struct imsm_map *map, int slot, __u32 ord) map->disk_ord_tbl[slot] = __cpu_to_le32(ord); } -static int get_imsm_disk_slot(struct imsm_map *map, unsigned idx) +static int get_imsm_disk_slot(struct imsm_map *map, const unsigned int idx) { int slot; __u32 ord; @@ -1162,7 +1174,7 @@ static int get_imsm_disk_slot(struct imsm_map *map, unsigned idx) return slot; } - return -1; + return IMSM_STATUS_ERROR; } static int get_imsm_raid_level(struct imsm_map *map) @@ -1177,6 +1189,23 @@ static int get_imsm_raid_level(struct imsm_map *map) return map->raid_level; } +/** + * get_disk_slot_in_dev() - retrieve disk slot from &imsm_dev. + * @super: &intel_super pointer, not NULL. + * @dev_idx: imsm device index. + * @idx: disk index. + * + * Return: Slot on success, IMSM_STATUS_ERROR otherwise. + */ +static int get_disk_slot_in_dev(struct intel_super *super, const __u8 dev_idx, + const unsigned int idx) +{ + struct imsm_dev *dev = get_imsm_dev(super, dev_idx); + struct imsm_map *map = get_imsm_map(dev, MAP_0); + + return get_imsm_disk_slot(map, idx); +} + static int cmp_extent(const void *av, const void *bv) { const struct extent *a = av; @@ -1193,13 +1222,9 @@ static int count_memberships(struct dl *dl, struct intel_super *super) int memberships = 0; int i; - for (i = 0; i < super->anchor->num_raid_devs; i++) { - struct imsm_dev *dev = get_imsm_dev(super, i); - struct imsm_map *map = get_imsm_map(dev, MAP_0); - - if (get_imsm_disk_slot(map, dl->index) >= 0) + for (i = 0; i < super->anchor->num_raid_devs; i++) + if (get_disk_slot_in_dev(super, i, dl->index) >= 0) memberships++; - } return memberships; } @@ -1909,6 +1934,7 @@ void examine_migr_rec_imsm(struct intel_super *super) /* first map under migration */ map = get_imsm_map(dev, MAP_0); + if (map) slot = get_imsm_disk_slot(map, super->disks->index); if (map == NULL || slot > 1 || slot < 0) { @@ -9629,10 +9655,9 @@ static int apply_update_activate_spare(struct imsm_update_activate_spare *u, /* count arrays using the victim in the metadata */ found = 0; for (a = active_array; a ; a = a->next) { - dev = get_imsm_dev(super, a->info.container_member); - map = get_imsm_map(dev, MAP_0); + int dev_idx = a->info.container_member; - if (get_imsm_disk_slot(map, victim) >= 0) + if (get_disk_slot_in_dev(super, dev_idx, victim) >= 0) found++; }
The routine was added to remove unnecessary get_imsm_dev() and get_imsm_map() calls, used only to determine disk slot. Additionally, enum for IMSM return statues was added for further usage. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> --- super-intel.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-)