Block update-subarray and refactor context update v2
v2 cover Block update-subarray and refactor context update v2
This is the v2 of the patchset I submitted long time ago. I applied the changes that were requested, but since long time has passed I'm submitting the whole patchset once again.
Mateusz Kusiak (10):
mdadm: Add option validation for --update-subarray Fix --update-subarray on active volume
Add code specific update options to enum.
super-ddf: Remove update_super_ddf.
super0: refactor the code for enum
super1: refactor the code for enum
super-intel: refactor the code for enum
Change update to enum in update_super and update_subarray Manage&Incremental: code refactor, string to enum Change char* to enum in context->update & refactor code
Assemble.c | 46 ++++++++------- Examine.c | 2 +- Grow.c | 17 +++--- Incremental.c | 8 +-- Manage.c | 42 ++++++++------ ReadMe.c | 31 ++++++++++ maps.c | 31 ++++++++++ mdadm.c | 129 ++++++++++++++---------------------------- mdadm.h | 65 ++++++++++++++++++--- super-ddf.c | 70 ----------------------- super-intel.c | 48 +++++++++------- super0.c | 103 ++++++++++++++++++++------------- super1.c | 153 ++++++++++++++++++++++++++++++-------------------- 13 files changed, 406 insertions(+), 339 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/10 mdadm: Add option validation for --update-subarray
Subset of options available for "--update" is not same as for "--update-subarray". Define maps and enum for update options and use them instead of direct comparisons. Add proper error message.
--- ReadMe.c | 31 +++++++++++++++++ maps.c | 31 +++++++++++++++++ mdadm.c | 104 +++++++++++++++++-------------------------------------- mdadm.h | 32 ++++++++++++++++- 4 files changed, 124 insertions(+), 74 deletions(-)
ReadMe.c +31 -0
@@ -655,3 +655,34 @@ char *mode_help[mode_count] = { [GROW] = Help_grow, [INCREMENTAL] = Help_incr, }; + +/** +* fprint_update_options() - Print valid update options depending on the mode. +* @outf: File (output stream) +* @update_mode: Used to distinguish update and update_subarray +*/ +void fprint_update_options (FILE *outf,enum update_opt update_mode) +{ +int counter =UOPT_NAME , breakpoint =UOPT_HELP ; +mapping_t *map = update_options; + +if (!outf) +return ; +if (update_mode ==UOPT_SUBARRAY_ONLY ) { + breakpoint =UOPT_SUBARRAY_ONLY ; +fprintf (outf,"Valid --update options for update-subarray are:\n\t" ); + }else +fprintf (outf,"Valid --update options are:\n\t" ); +while (map->num) { +if (map->num >= breakpoint) +break ; +fprintf (outf,"'%s', " , map->name); +if (counter %5 ==0 ) +fprintf (outf,"\n\t" ); + counter++; + map++; + } +if ((counter -1 ) %5 ) +fprintf (outf,"\n" ); +fprintf (outf,"\r" ); +}
maps.c +31 -0
@@ -165,6 +165,37 @@ mapping_t sysfs_array_states[] = { { "broken", ARRAY_BROKEN }, { NULL, ARRAY_UNKNOWN_STATE } }; +/** +* mapping_t update_options - stores supported update options. +*/ +mapping_t update_options[] = { + {"name" ,UOPT_NAME }, + {"ppl" ,UOPT_PPL }, + {"no-ppl" ,UOPT_NO_PPL }, + {"bitmap" ,UOPT_BITMAP }, + {"no-bitmap" ,UOPT_NO_BITMAP }, + {"sparc2.2" ,UOPT_SPARC22 }, + {"super-minor" ,UOPT_SUPER_MINOR }, + {"summaries" ,UOPT_SUMMARIES }, + {"resync" ,UOPT_RESYNC }, + {"uuid" ,UOPT_UUID }, + {"homehost" ,UOPT_HOMEHOST }, + {"home-cluster" ,UOPT_HOME_CLUSTER }, + {"nodes" ,UOPT_NODES }, + {"devicesize" ,UOPT_DEVICESIZE }, + {"bbl" ,UOPT_BBL }, + {"no-bbl" ,UOPT_NO_BBL }, + {"force-no-bbl" ,UOPT_FORCE_NO_BBL }, + {"metadata" ,UOPT_METADATA }, + {"revert-reshape" ,UOPT_REVERT_RESHAPE }, + {"layout-original" ,UOPT_LAYOUT_ORIGINAL }, + {"layout-alternate" ,UOPT_LAYOUT_ALTERNATE }, + {"layout-unspecified" ,UOPT_LAYOUT_UNSPECIFIED }, + {"byteorder" ,UOPT_BYTEORDER }, + {"help" ,UOPT_HELP }, + {"?" ,UOPT_HELP }, + {NULL ,UOPT_UNDEFINED } +};/** * map_num_s() - Safer alternative of map_num() function.
mdadm.c +31 -73
128 lines not on this page · raw message
mdadm.h +31 -1
@@ -497,6 +497,36 @@ enum special_options { ConsistencyPolicy, }; +enum update_opt { +UOPT_NAME =1 , +UOPT_PPL , +UOPT_NO_PPL , +UOPT_BITMAP , +UOPT_NO_BITMAP , +UOPT_SUBARRAY_ONLY , +UOPT_SPARC22 , +UOPT_SUPER_MINOR , +UOPT_SUMMARIES , +UOPT_RESYNC , +UOPT_UUID , +UOPT_HOMEHOST , +UOPT_HOME_CLUSTER , +UOPT_NODES , +UOPT_DEVICESIZE , +UOPT_BBL , +UOPT_NO_BBL , +UOPT_FORCE_NO_BBL , +UOPT_METADATA , +UOPT_REVERT_RESHAPE , +UOPT_LAYOUT_ORIGINAL , +UOPT_LAYOUT_ALTERNATE , +UOPT_LAYOUT_UNSPECIFIED , +UOPT_BYTEORDER , +UOPT_HELP , +UOPT_UNDEFINED +}; +extern void fprint_update_options (FILE *outf,enum update_opt update_mode); +enum prefix_standard {JEDEC ,IEC
@@ -777,7 +807,7 @@ extern char *map_num(mapping_t *map, int num);extern int map_name (mapping_t *map,char *name);extern mapping_t r0layout[], r5layout[], r6layout[], pers[], modes[], faultylayout[]; -extern mapping_t consistency_policies[], sysfs_array_states[]; +extern mapping_t consistency_policies[], sysfs_array_states[], update_options[];extern char *map_dev_preferred (int major,int minor,int create,char *prefer);
Signature · 1 line
2.26.2
PATCH v2 2/10 Fix --update-subarray on active volume
In reply to Mateusz KusiakOptions: bitmap, ppl and name should not be updated when array is active.
Those features are mutually exclusive and share the same data area in IMSM (danger of overwriting by kernel). Remove check for active subarrays from super-intel.
Since ddf is not supported, apply it globally for all options.
--- Manage.c | 7 +++++++ super-intel.c | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-)
Manage.c +7 -0
@@ -1745,6 +1745,13 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident goto free_super; } +if (is_subarray_active (subarray, st->devnm)) { +if (verbose >=0 ) +pr_err ("Subarray %s in %s is active, cannot update %s\n" , + subarray, dev, update); + goto free_super; + } +if (mdmon_running (st->devnm)) st->update_tail = &st->updates;
super-intel.c +0 -5
@@ -7914,11 +7914,6 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,char *ep;int vol; -if (is_subarray_active (subarray, st->devnm)) { -pr_err ("Unable to update name of active subarray\n" ); -return 2 ; - } -if (!check_name (super, name,0 ))return 2 ;
Signature · 1 line
2.26.2
PATCH v2 3/10 Add code specific update options to enum.
In reply to Mateusz KusiakSome of update options aren't taken from user input, but are hard-coded as strings.
Include those options in enum.
--- maps.c | 21 +++++++++++++++++++++ mdadm.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+)
maps.c +21 -0
@@ -194,6 +194,27 @@ mapping_t update_options[] = { { "byteorder", UOPT_BYTEORDER }, { "help", UOPT_HELP }, { "?", UOPT_HELP }, +/* +* Those enries are temporary and will be removed in this patchset. +* +* Before update_super:update can be changed to enum, +* all update_super sub-functions must be adapted first. +* Update options will be passed as string (as it is for now), +* and then mapped, so all options must be handled temporarily. +* +* Those options code specific and should not be accessible for user. +*/ + { "force-one", UOPT_SPEC_FORCE_ONE }, + { "force-array", UOPT_SPEC_FORCE_ARRAY }, + { "assemble", UOPT_SPEC_ASSEMBLE }, + { "linear-grow-new", UOPT_SPEC_LINEAR_GROW_NEW }, + { "linear-grow-update", UOPT_SPEC_LINEAR_GROW_UPDATE }, + { "_reshape_progress", UOPT_SPEC__RESHAPE_PROGRESS }, + { "writemostly", UOPT_SPEC_WRITEMOSTLY }, + { "readwrite", UOPT_SPEC_READWRITE }, + { "failfast", UOPT_SPEC_FAILFAST }, + { "nofailfast", UOPT_SPEC_NOFAILFAST }, + { "revert-reshape-nobackup", UOPT_SPEC_REVERT_RESHAPE_NOBACKUP }, { NULL, UOPT_UNDEFINED} };
mdadm.h +15 -0
@@ -523,6 +523,21 @@ enum update_opt {UOPT_LAYOUT_UNSPECIFIED ,UOPT_BYTEORDER ,UOPT_HELP , +UOPT_USER_ONLY , +/* +* Code specific options, cannot be set by the user +*/ +UOPT_SPEC_FORCE_ONE , +UOPT_SPEC_FORCE_ARRAY , +UOPT_SPEC_ASSEMBLE , +UOPT_SPEC_LINEAR_GROW_NEW , +UOPT_SPEC_LINEAR_GROW_UPDATE , +UOPT_SPEC__RESHAPE_PROGRESS , +UOPT_SPEC_WRITEMOSTLY , +UOPT_SPEC_READWRITE , +UOPT_SPEC_FAILFAST , +UOPT_SPEC_NOFAILFAST , +UOPT_SPEC_REVERT_RESHAPE_NOBACKUP ,UOPT_UNDEFINED };extern void fprint_update_options (FILE *outf,enum update_opt update_mode);
Signature · 1 line
2.26.2
PATCH v2 4/10 super-ddf: Remove update_super_ddf.
In reply to Mateusz KusiakThis is not supported by ddf.
It hides errors by returning success status for some updates. Remove update_super_dff().
--- super-ddf.c | 70 ----------------------------------------------------- 1 file changed, 70 deletions(-)
super-ddf.c +0 -70
@@ -2139,75 +2139,6 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha } } -static int update_super_ddf (struct supertype *st,struct mdinfo *info, -char *update, -char *devname,int verbose, -int uuid_set,char *homehost) -{ -/* For 'assemble' and 'force' we need to return non-zero if any -* change was made. For others, the return value is ignored. -* Update options are: -* force-one : This device looks a bit old but needs to be included, -* update age info appropriately. -* assemble: clear any 'faulty' flag to allow this device to -* be assembled. -* force-array: Array is degraded but being forced, mark it clean -* if that will be needed to assemble it. -* -* newdev: not used ???? -* grow: Array has gained a new device - this is currently for -* linear only -* resync: mark as dirty so a resync will happen. -* uuid: Change the uuid of the array to match what is given -* homehost: update the recorded homehost -* name: update the name - preserving the homehost -* _reshape_progress: record new reshape_progress position. -* -* Following are not relevant for this version: -* sparc2.2 : update from old dodgey metadata -* super-minor: change the preferred_minor number -* summaries: update redundant counters. -*/ -int rv =0 ; -// struct ddf_super *ddf = st->sb; -// struct vd_config *vd = find_vdcr(ddf, info->container_member); -// struct virtual_entry *ve = find_ve(ddf); - -/* we don't need to handle "force-*" or "assemble" as -* there is no need to 'trick' the kernel. When the metadata is -* first updated to activate the array, all the implied modifications -* will just happen. -*/ - -if (strcmp (update,"grow" ) ==0 ) { -/* FIXME */ - }else if (strcmp (update,"resync" ) ==0 ) { -// info->resync_checkpoint = 0; - }else if (strcmp (update,"homehost" ) ==0 ) { -/* homehost is stored in controller->vendor_data, -* or it is when we are the vendor -*/ -// if (info->vendor_is_local) -// strcpy(ddf->controller.vendor_data, homehost); - rv =-1 ; - }else if (strcmp (update,"name" ) ==0 ) { -/* name is stored in virtual_entry->name */ -// memset(ve->name, ' ', 16); -// strncpy(ve->name, info->name, 16); - rv =-1 ; - }else if (strcmp (update,"_reshape_progress" ) ==0 ) { -/* We don't support reshape yet */ - }else if (strcmp (update,"assemble" ) ==0 ) { -/* Do nothing, just succeed */ - rv =0 ; - }else - rv =-1 ; - -// update_all_csum(ddf); - -return rv; -} -static void make_header_guid (char *guid) {be32 stamp;
@@ -5211,7 +5142,6 @@ struct superswitch super_ddf = { .match_home = match_home_ddf, .uuid_from_super= uuid_from_super_ddf, .getinfo_super = getinfo_super_ddf, - .update_super = update_super_ddf, .avail_size = avail_size_ddf,
Signature · 1 line
2.26.2
PATCH v2 5/10 super0: refactor the code for enum
In reply to Mateusz KusiakIt prepares update_super0 for change context->update to enum. Change if else statements to switch.
--- super0.c | 102 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 39 deletions(-)
super0.c +63 -39
@@ -502,19 +502,39 @@ static int update_super0(struct supertype *st, struct mdinfo *info,int rv =0 ;int uuid[4 ];mdp_super_t *sb = st->sb; +enum update_opt update_enum =map_name (update_options, update); -if (strcmp (update,"homehost" ) ==0 && - homehost) { -/* note that 'homehost' is special as it is really +if (update_enum ==UOPT_HOMEHOST && homehost) { +/* +* note that 'homehost' is special as it is really * a "uuid" update. */ uuid_set =0 ; - update ="uuid" ; + update_enum =UOPT_UUID ; info->uuid[0 ] = sb->set_uuid0; info->uuid[1 ] = sb->set_uuid1; } -if (strcmp (update,"sparc2.2" )==0 ) { +switch (update_enum) { +case UOPT_UUID : +if (!uuid_set && homehost) { +char buf[20 ]; +memcpy (info->uuid+2 , +sha1_buffer (homehost,strlen (homehost), buf), +8 ); + } + sb->set_uuid0 = info->uuid[0 ]; + sb->set_uuid1 = info->uuid[1 ]; + sb->set_uuid2 = info->uuid[2 ]; + sb->set_uuid3 = info->uuid[3 ]; +if (sb->state & (1 <<MD_SB_BITMAP_PRESENT )) { +struct bitmap_super_s *bm; + bm = (struct bitmap_super_s *)(sb+1 ); +uuid_from_super0 (st, uuid); +memcpy (bm->uuid, uuid,16 ); + } +break ; +case UOPT_SPARC22 : {/* 2.2 sparc put the events in the wrong place * So we copy the tail of the superblock * up 4 bytes before continuing
@@ -527,12 +547,15 @@ static int update_super0(struct supertype *st, struct mdinfo *info,if (verbose >=0 )pr_err ("adjusting superblock of %s for 2.2/sparc compatibility.\n" , devname); - }else if (strcmp (update,"super-minor" ) ==0 ) { +break ; + } +case UOPT_SUPER_MINOR : sb->md_minor = info->array.md_minor;if (verbose >0 )pr_err ("updating superblock of %s with minor number %d\n" , devname, info->array.md_minor); - }else if (strcmp (update,"summaries" ) ==0 ) { +break ; +case UOPT_SUMMARIES : {unsigned int i;/* set nr_disks, active_disks, working_disks, * failed_disks, spare_disks based on disks[]
@@ -559,7 +582,9 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->spare_disks++; }else if (i >= sb->raid_disks && sb->disks[i].number ==0 ) sb->disks[i].state =0 ; - }else if (strcmp (update,"force-one" )==0 ) { +break ; + } +case UOPT_SPEC_FORCE_ONE : {/* Not enough devices for a working array, so * bring this one up-to-date. */
@@ -569,7 +594,9 @@ static int update_super0(struct supertype *st, struct mdinfo *info,if (sb->events_hi != ehi || sb->events_lo != elo) rv =1 ; - }else if (strcmp (update,"force-array" )==0 ) { +break ; + } +case UOPT_SPEC_FORCE_ARRAY :/* degraded array and 'force' requested, so * maybe need to mark it 'clean' */
@@ -579,7 +606,8 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->state |= (1 <<MD_SB_CLEAN ); rv =1 ; } - }else if (strcmp (update,"assemble" )==0 ) { +break ; +case UOPT_SPEC_ASSEMBLE : {int d = info->disk.number;int wonly = sb->disks[d].state & (1 <<MD_DISK_WRITEMOSTLY );int failfast = sb->disks[d].state & (1 <<MD_DISK_FAILFAST );
@@ -609,7 +637,9 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->reshape_position = info->reshape_progress; rv =1 ; } - }else if (strcmp (update,"linear-grow-new" ) ==0 ) { +break ; + } +case UOPT_SPEC_LINEAR_GROW_NEW :memset (&sb->disks[info->disk.number],0 ,sizeof (sb->disks[0 ])); sb->disks[info->disk.number].number = info->disk.number; sb->disks[info->disk.number].major = info->disk.major;
@@ -617,7 +647,8 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->disks[info->disk.number].raid_disk = info->disk.raid_disk; sb->disks[info->disk.number].state = info->disk.state; sb->this_disk = sb->disks[info->disk.number]; - }else if (strcmp (update,"linear-grow-update" ) ==0 ) { +break ; +case UOPT_SPEC_LINEAR_GROW_UPDATE : sb->raid_disks = info->array.raid_disks; sb->nr_disks = info->array.nr_disks; sb->active_disks = info->array.active_disks;
@@ -628,29 +659,15 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->disks[info->disk.number].minor = info->disk.minor; sb->disks[info->disk.number].raid_disk = info->disk.raid_disk; sb->disks[info->disk.number].state = info->disk.state; - }else if (strcmp (update,"resync" ) ==0 ) { -/* make sure resync happens */ +break ; +case UOPT_RESYNC : +/* +* make sure resync happens +*/ sb->state &= ~(1 <<MD_SB_CLEAN ); sb->recovery_cp =0 ; - }else if (strcmp (update,"uuid" ) ==0 ) { -if (!uuid_set && homehost) { -char buf[20 ]; -char *hash =sha1_buffer (homehost, -strlen (homehost), - buf); -memcpy (info->uuid+2 , hash,8 ); - } - sb->set_uuid0 = info->uuid[0 ]; - sb->set_uuid1 = info->uuid[1 ]; - sb->set_uuid2 = info->uuid[2 ]; - sb->set_uuid3 = info->uuid[3 ]; -if (sb->state & (1 <<MD_SB_BITMAP_PRESENT )) { -struct bitmap_super_s *bm; - bm = (struct bitmap_super_s *)(sb+1 ); -uuid_from_super0 (st, uuid); -memcpy (bm->uuid, uuid,16 ); - } - }else if (strcmp (update,"metadata" ) ==0 ) { +break ; +case UOPT_METADATA :/* Create some v1.0 metadata to match ours but make the * ctime bigger. Also update info->array.*_version. * We need to arrange that store_super writes out
@@ -670,7 +687,8 @@ static int update_super0(struct supertype *st, struct mdinfo *info,uuid_from_super0 (st, info->uuid); st->other =super1_make_v0 (st, info, st->sb); } - }else if (strcmp (update,"revert-reshape" ) ==0 ) { +break ; +case UOPT_REVERT_RESHAPE : rv =-2 ;if (sb->minor_version <=90 ) pr_err("No active reshape to revert on %s\n",
@@ -702,16 +720,22 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb->new_chunk = sb->chunk_size; sb->chunk_size = tmp; } - }else if (strcmp (update,"no-bitmap" ) ==0 ) { +break ; +case UOPT_NO_BITMAP : sb->state &= ~(1 <<MD_SB_BITMAP_PRESENT ); - }else if (strcmp (update,"_reshape_progress" )==0 ) +break ; +case UOPT_SPEC__RESHAPE_PROGRESS : sb->reshape_position = info->reshape_progress; -else if (strcmp (update,"writemostly" )==0 ) +break ; +case UOPT_SPEC_WRITEMOSTLY : sb->state |= (1 <<MD_DISK_WRITEMOSTLY ); -else if (strcmp (update,"readwrite" )==0 ) +break ; +case UOPT_SPEC_READWRITE : sb->state &= ~(1 <<MD_DISK_WRITEMOSTLY ); -else +break ; +default : rv =-1 ; + } sb->sb_csum =calc_sb0_csum (sb);return rv;
Signature · 1 line
2.26.2
PATCH v2 6/10 super1: refactor the code for enum
In reply to Mateusz KusiakIt prepares update_super1 for change context->update to enum. Change if else statements into switch.
--- super1.c | 152 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 61 deletions(-)
super1.c +91 -61
@@ -1218,30 +1218,55 @@ static int update_super1(struct supertype *st, struct mdinfo *info,int rv =0 ;struct mdp_superblock_1 *sb = st->sb;bitmap_super_t *bms = (bitmap_super_t *)(((char *)sb) +MAX_SB_SIZE ); +enum update_opt update_enum =map_name (update_options, update); -if (strcmp (update,"homehost" ) ==0 && - homehost) { -/* Note that 'homehost' is special as it is really +if (update_enum ==UOPT_HOMEHOST && homehost) { +/* +* Note that 'homehost' is special as it is really * a "name" update. */ char *c; - update ="name" ; + update_enum =UOPT_NAME ; c =strchr (sb->set_name,':' );if (c) -strncpy (info->name, c+1 ,31 - (c-sb->set_name)); +snprintf (info->name,sizeof (info->name),"%s" , c+1 );else -strncpy (info->name, sb->set_name,32 ); - info->name[32 ] =0 ; +snprintf (info->name,sizeof (info->name),"%s" , sb->set_name); } -if (strcmp (update,"force-one" )==0 ) { +switch (update_enum) { +case UOPT_NAME : { +int namelen; + +if (!info->name[0 ]) +snprintf (info->name,sizeof (info->name),"%d" , info->array.md_minor); +memset (sb->set_name,0 ,sizeof (sb->set_name)); + + namelen =strnlen (homehost,MD_NAME_MAX ) +1 +strnlen (info->name,MD_NAME_MAX ); +if (homehost && +strchr (info->name,':' ) ==NULL && + namelen <MD_NAME_MAX ) { +strcpy (sb->set_name, homehost); +strcat (sb->set_name,":" ); +strcat (sb->set_name, info->name); + }else { + namelen =min ((int )strnlen (info->name,MD_NAME_MAX ), + (int )sizeof (sb->set_name) -1 ); +memcpy (sb->set_name, info->name, namelen); +memset (&sb->set_name[namelen],'\0' , +sizeof (sb->set_name) - namelen); + } +break ; + } +case UOPT_SPEC_FORCE_ONE :/* Not enough devices for a working array, * so bring this one up-to-date */ if (sb->events !=__cpu_to_le64 (info->events)) rv =1 ; sb->events =__cpu_to_le64 (info->events); - }else if (strcmp (update,"force-array" )==0 ) { +break ; +case UOPT_SPEC_FORCE_ARRAY :/* Degraded array and 'force' requests to * maybe need to mark it 'clean'. */
@@ -1254,7 +1279,8 @@ static int update_super1(struct supertype *st, struct mdinfo *info, rv =1 ; sb->resync_offset = MaxSector; } - }else if (strcmp (update,"assemble" )==0 ) { +break ; +case UOPT_SPEC_ASSEMBLE : {int d = info->disk.number;int want;if (info->disk.state & (1 <<MD_DISK_ACTIVE ))
@@ -1287,7 +1313,9 @@ static int update_super1(struct supertype *st, struct mdinfo *info,__cpu_to_le64 (info->reshape_progress); rv =1 ; } - }else if (strcmp (update,"linear-grow-new" ) ==0 ) { +break ; + } +case UOPT_SPEC_LINEAR_GROW_NEW : {int i;int fd;int max =__le32_to_cpu (sb->max_dev);
@@ -1330,7 +1358,9 @@ static int update_super1(struct supertype *st, struct mdinfo *info, ds - __le64_to_cpu(sb->data_offset)); } } - }else if (strcmp (update,"linear-grow-update" ) ==0 ) { +break ; + } +case UOPT_SPEC_LINEAR_GROW_UPDATE : {int max =__le32_to_cpu (sb->max_dev);int i = info->disk.number;if (max >MAX_DEVS || i >MAX_DEVS )
@@ -1342,19 +1372,20 @@ static int update_super1(struct supertype *st, struct mdinfo *info, sb->raid_disks =__cpu_to_le32 (info->array.raid_disks); sb->dev_roles[info->disk.number] =__cpu_to_le16 (info->disk.raid_disk); - }else if (strcmp (update,"resync" ) ==0 ) { -/* make sure resync happens */ - sb->resync_offset =0ULL ; - }else if (strcmp (update,"uuid" ) ==0 ) { +break ; + } +case UOPT_UUID :copy_uuid (sb->set_uuid, info->uuid, super1.swapuuid);if (__le32_to_cpu (sb->feature_map) &MD_FEATURE_BITMAP_OFFSET )memcpy (bms->uuid, sb->set_uuid,16 ); - }else if (strcmp (update,"no-bitmap" ) ==0 ) { +break ; +case UOPT_NO_BITMAP : sb->feature_map &= ~__cpu_to_le32 (MD_FEATURE_BITMAP_OFFSET );if (bms->version ==BITMAP_MAJOR_CLUSTERED && !IsBitmapDirty (devname)) sb->resync_offset = MaxSector; - }else if (strcmp (update,"bbl" ) ==0 ) { +break ; +case UOPT_BBL : {/* only possible if there is room after the bitmap, or if * there is no bitmap */
@@ -1383,14 +1414,12 @@ static int update_super1(struct supertype *st, struct mdinfo *info, bb_offset = bitmap_offset + bm_sectors;while (bb_offset < (long )sb_offset +8 +32 *2 && bb_offset +8 +8 <= (long )data_offset) -/* too close to bitmap, and room to grow */ bb_offset +=8 ;if (bb_offset +8 <= (long )data_offset) { sb->bblog_size =__cpu_to_le16 (8 ); sb->bblog_offset =__cpu_to_le32 (bb_offset); } }else { -/* 1.0 - Put bbl just before super block */ if (bm_sectors && bitmap_offset <0 ) space = -bitmap_offset - bm_sectors;else
@@ -1401,7 +1430,9 @@ static int update_super1(struct supertype *st, struct mdinfo *info, sb->bblog_offset =__cpu_to_le32 ((unsigned )-8 ); } } - }else if (strcmp (update,"no-bbl" ) ==0 ) { +break ; + } +case UOPT_NO_BBL :if (sb->feature_map &__cpu_to_le32 (MD_FEATURE_BAD_BLOCKS ))pr_err ("Cannot remove active bbl from %s\n" ,devname);else {
@@ -1409,12 +1440,14 @@ static int update_super1(struct supertype *st, struct mdinfo *info, sb->bblog_shift =0 ; sb->bblog_offset =0 ; } - }else if (strcmp (update,"force-no-bbl" ) ==0 ) { +break ; +case UOPT_FORCE_NO_BBL : sb->feature_map &= ~__cpu_to_le32 (MD_FEATURE_BAD_BLOCKS ); sb->bblog_size =0 ; sb->bblog_shift =0 ; sb->bblog_offset =0 ; - }else if (strcmp (update,"ppl" ) ==0 ) { +break ; +case UOPT_PPL : {unsigned long long sb_offset =__le64_to_cpu (sb->super_offset);unsigned long long data_offset =__le64_to_cpu (sb->data_offset);unsigned long long data_size =__le64_to_cpu (sb->data_size);
@@ -1464,37 +1497,26 @@ static int update_super1(struct supertype *st, struct mdinfo *info, sb->ppl.offset =__cpu_to_le16 (offset); sb->ppl.size =__cpu_to_le16 (space); sb->feature_map |=__cpu_to_le32 (MD_FEATURE_PPL ); - }else if (strcmp (update,"no-ppl" ) ==0 ) { +break ; + } +case UOPT_NO_PPL : sb->feature_map &= ~__cpu_to_le32 (MD_FEATURE_PPL |MD_FEATURE_MUTLIPLE_PPLS ); - }else if (strcmp (update,"name" ) ==0 ) { -if (info->name[0 ] ==0 ) -sprintf (info->name,"%d" , info->array.md_minor); -memset (sb->set_name,0 ,sizeof (sb->set_name)); -if (homehost && -strchr (info->name,':' ) ==NULL && -strlen (homehost)+1 +strlen (info->name) <32 ) { -strcpy (sb->set_name, homehost); -strcat (sb->set_name,":" ); -strcat (sb->set_name, info->name); - }else { -int namelen; - - namelen =min ((int )strlen (info->name), - (int )sizeof (sb->set_name) -1 ); -memcpy (sb->set_name, info->name, namelen); -memset (&sb->set_name[namelen],'\0' , -sizeof (sb->set_name) - namelen); - } - }else if (strcmp (update,"devicesize" ) ==0 && -__le64_to_cpu (sb->super_offset) < -__le64_to_cpu (sb->data_offset)) { -/* set data_size to device size less data_offset */ +break ; +case UOPT_DEVICESIZE : +if (__le64_to_cpu (sb->super_offset) >= +__le64_to_cpu (sb->data_offset)) +break ; +/* +* set data_size to device size less data_offset +*/ struct misc_dev_info *misc = (struct misc_dev_info *) (st->sb +MAX_SB_SIZE +BM_SUPER_SIZE ); sb->data_size =__cpu_to_le64 ( misc->device_size -__le64_to_cpu (sb->data_offset)); - }else if (strncmp (update,"revert-reshape" ,14 ) ==0 ) { +break ; +case UOPT_SPEC_REVERT_RESHAPE_NOBACKUP : +case UOPT_REVERT_RESHAPE : rv =-2 ;if (!(sb->feature_map &__cpu_to_le32 (MD_FEATURE_RESHAPE_ACTIVE )))
@@ -1512,7 +1534,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,* If that couldn't happen, the "-nobackup" version * will be used. */ - if (strcmp(update, "revert-reshape-nobackup") == 0 && + if (update_enum == UOPT_SPEC_REVERT_RESHAPE_NOBACKUP && sb->reshape_position == 0 && (__le32_to_cpu(sb->delta_disks) > 0 || (__le32_to_cpu(sb->delta_disks) == 0 &&
@@ -1575,32 +1597,40 @@ static int update_super1(struct supertype *st, struct mdinfo *info, } done:; } - }else if (strcmp (update,"_reshape_progress" ) ==0 ) +break ; +case UOPT_SPEC__RESHAPE_PROGRESS : sb->reshape_position =__cpu_to_le64 (info->reshape_progress); -else if (strcmp (update,"writemostly" ) ==0 ) +break ; +case UOPT_SPEC_WRITEMOSTLY : sb->devflags |= WriteMostly1; -else if (strcmp (update,"readwrite" ) ==0 ) +break ; +case UOPT_SPEC_READWRITE : sb->devflags &= ~WriteMostly1; -else if (strcmp (update,"failfast" ) ==0 ) +break ; +case UOPT_SPEC_FAILFAST : sb->devflags |= FailFast1; -else if (strcmp (update,"nofailfast" ) ==0 ) +break ; +case UOPT_SPEC_NOFAILFAST : sb->devflags &= ~FailFast1; -else if (strcmp (update,"layout-original" ) ==0 || -strcmp (update,"layout-alternate" ) ==0 || -strcmp (update,"layout-unspecified" ) ==0 ) { +break ; +case UOPT_LAYOUT_ORIGINAL : +case UOPT_LAYOUT_ALTERNATE : +case UOPT_LAYOUT_UNSPECIFIED :if (__le32_to_cpu (sb->level) !=0 ) {pr_err ("%s: %s only supported for RAID0\n" , - devname?:"" , update); + devname ?:"" ,map_num (update_options, update_enum)); rv =-1 ; - }else if (strcmp (update,"layout-unspecified" ) ==0 ) { + }else if (update_enum ==UOPT_LAYOUT_UNSPECIFIED ) { sb->feature_map &= ~__cpu_to_le32 (MD_FEATURE_RAID0_LAYOUT ); sb->layout =0 ; }else { sb->feature_map |=__cpu_to_le32 (MD_FEATURE_RAID0_LAYOUT ); - sb->layout =__cpu_to_le32 (update[7 ] =='o' ?1 :2 ); + sb->layout =__cpu_to_le32 (update_enum ==UOPT_LAYOUT_ORIGINAL ?1 :2 ); } - }else +break ; +default : rv =-1 ; + } sb->sb_csum =calc_sb_1_csum (sb);
Signature · 1 line
2.26.2
PATCH v2 7/10 super-intel: refactor the code for enum
In reply to Mateusz KusiakIt prepares super-intel for change context->update to enum.
--- super-intel.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
super-intel.c +25 -12
@@ -3930,7 +3930,8 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info, mpb = super->anchor; -if (strcmp (update,"uuid" ) ==0 ) { +switch (map_name (update_options, update)) { +case UOPT_UUID :/* We take this to mean that the family_num should be updated. * However that is much smaller than the uuid so we cannot really * allow an explicit uuid to be given. And it is hard to reliably
@@ -3954,10 +3955,14 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info, }if (rv ==0 ) mpb->orig_family_num = info->uuid[0 ]; - }else if (strcmp (update,"assemble" ) ==0 ) +break ; +case UOPT_SPEC_ASSEMBLE : rv =0 ; -else +break ; +default : rv =-1 ; +break ; + }/* successful update? recompute checksum */ if (rv ==0 )
@@ -7889,17 +7894,25 @@ static int kill_subarray_imsm(struct supertype *st, char *subarray_id)return 0 ; } -static int get_rwh_policy_from_update (char *update) +/** +* get_rwh_policy_from_update() - Get the rwh policy for update option. +* @update: Update option. +*/ +static int get_rwh_policy_from_update (enum update_opt update) { -if (strcmp (update,"ppl" ) ==0 ) +switch (update) { +case UOPT_PPL :return RWH_MULTIPLE_DISTRIBUTED ; -else if (strcmp (update,"no-ppl" ) ==0 ) +case UOPT_NO_PPL :return RWH_MULTIPLE_OFF ; -else if (strcmp (update,"bitmap" ) ==0 ) +case UOPT_BITMAP :return RWH_BITMAP ; -else if (strcmp (update,"no-bitmap" ) ==0 ) +case UOPT_NO_BITMAP :return RWH_OFF ; -return -1 ; +default : +break ; + } +return UOPT_UNDEFINED ; } static int update_subarray_imsm(struct supertype *st, char *subarray,
@@ -7909,7 +7922,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,struct intel_super *super = st->sb;struct imsm_super *mpb = super->anchor; -if (strcmp (update,"name" ) ==0 ) { +if (map_name (update_options, update) ==UOPT_NAME ) {char *name = ident->name;char *ep;int vol;
@@ -7943,7 +7956,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray, } super->updates_pending++; } - }else if (get_rwh_policy_from_update (update) !=-1 ) { + }else if (get_rwh_policy_from_update (map_name (update_options, update)) !=UOPT_UNDEFINED ) {int new_policy;char *ep;int vol =strtoul (subarray, &ep,10 );
@@ -7951,7 +7964,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,if (*ep !='\0' || vol >= super->anchor->num_raid_devs)return 2 ; - new_policy =get_rwh_policy_from_update (update); + new_policy =get_rwh_policy_from_update (map_name (update_options, update));if (st->update_tail) {struct imsm_update_rwh_policy *u =xmalloc (sizeof (*u));
Signature · 1 line
2.26.2
PATCH v2 8/10 Change update to enum in update_super and update_subarray
In reply to Mateusz KusiakUse already existing enum, change update_super and update_subarray update to enum globally.
Refactor function references also.
Remove code specific options from update_options.
--- Assemble.c | 14 +++++++++----- Examine.c | 2 +- Grow.c | 9 +++++---- Manage.c | 14 ++++++++------ maps.c | 21 --------------------- mdadm.h | 12 +++++++++--- super-intel.c | 16 ++++++++-------- super0.c | 9 ++++----- super1.c | 17 ++++++++--------- 9 files changed, 52 insertions(+), 62 deletions(-)
Assemble.c +9 -5
@@ -695,12 +695,16 @@ static int load_devices(struct devs *devices, char *devmap, }else if (strcmp (c->update,"revert-reshape" ) ==0 && c->invalid_backup) err = tst->ss->update_super (tst, content, -"revert-reshape-nobackup" , +UOPT_SPEC_REVERT_RESHAPE_NOBACKUP , devname, c->verbose, ident->uuid_set, c->homehost);else - err = tst->ss->update_super (tst, content, c->update, +/* +* Mapping is temporary, will be removed in this patchset +*/ + err = tst->ss->update_super (tst, content, +map_name (update_options, c->update), devname, c->verbose, ident->uuid_set, c->homehost);
@@ -960,7 +964,7 @@ static int force_array(struct mdinfo *content,continue ; } content->events = devices[most_recent].i.events; - tst->ss->update_super (tst, content,"force-one" , + tst->ss->update_super (tst, content,UOPT_SPEC_FORCE_ONE , devices[chosen_drive].devname, c->verbose,0 ,NULL );
@@ -1788,7 +1792,7 @@ try_again:if (!(devices[j].i.array.state &1 )) clean =0 ; -if (st->ss->update_super (st, &devices[j].i,"assemble" ,NULL , +if (st->ss->update_super (st, &devices[j].i,UOPT_SPEC_ASSEMBLE ,NULL , c->verbose,0 ,NULL )) {if (c->force) {if (c->verbose >=0 )
@@ -1811,7 +1815,7 @@ try_again:if (c->force && !clean && !is_container (content->array.level) && !enough (content->array.level, content->array.raid_disks, content->array.layout, clean, avail)) { - change += st->ss->update_super (st, content,"force-array" , + change += st->ss->update_super (st, content,UOPT_SPEC_FORCE_ARRAY , devices[chosen_drive].devname, c->verbose,0 ,NULL ); was_forced =1 ;
Examine.c +1 -1
@@ -117,7 +117,7 @@ int Examine(struct mddev_dev *devlist, }if (c->SparcAdjust) - st->ss->update_super (st,NULL ,"sparc2.2" , + st->ss->update_super (st,NULL ,UOPT_SPARC22 , devlist->devname,0 ,0 ,NULL );/* Ok, its good enough to try, though the checksum could be wrong */
Grow.c +5 -4
@@ -196,7 +196,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) info.disk.minor =minor (rdev); info.disk.raid_disk = d; info.disk.state = (1 <<MD_DISK_SYNC ) | (1 <<MD_DISK_ACTIVE ); -if (st->ss->update_super (st, &info,"linear-grow-new" , newdev, +if (st->ss->update_super (st, &info,UOPT_SPEC_LINEAR_GROW_NEW , newdev,0 ,0 ,NULL ) !=0 ) {pr_err ("Preparing new metadata failed on %s\n" , newdev);close (nfd);
@@ -254,7 +254,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) info.array.active_disks = nd+1 ; info.array.working_disks = nd+1 ; -if (st->ss->update_super (st, &info,"linear-grow-update" , dv, +if (st->ss->update_super (st, &info,UOPT_SPEC_LINEAR_GROW_UPDATE , dv,0 ,0 ,NULL ) !=0 ) {pr_err ("Updating metadata failed on %s\n" , dv);close (fd2);
@@ -668,7 +668,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha goto free_info; } - ret = st->ss->update_super (st, sra,"ppl" , + ret = st->ss->update_super (st, sra,UOPT_PPL , devname, c->verbose,0 ,NULL );if (ret) {
@@ -4950,7 +4950,8 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist,continue ; st->ss->getinfo_super (st, &dinfo,NULL ); dinfo.reshape_progress = info->reshape_progress; - st->ss->update_super (st, &dinfo,"_reshape_progress" , + st->ss->update_super (st, &dinfo, +UOPT_SPEC__RESHAPE_PROGRESS ,NULL ,0 ,0 ,NULL ); st->ss->store_super (st, fdlist[j]); st->ss->free_super (st);
Manage.c +8 -6
@@ -605,6 +605,7 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,struct mdinfo mdi;int duuid[4 ];int ouuid[4 ]; +enum update_opt update_enum =map_name (update_options, update); dev_st->ss->getinfo_super (dev_st, &mdi,NULL ); dev_st->ss->uuid_from_super (dev_st, ouuid);
@@ -666,23 +667,23 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,if (dv->writemostly == FlagSet) rv = dev_st->ss->update_super ( - dev_st,NULL ,"writemostly" , + dev_st,NULL ,UOPT_SPEC_WRITEMOSTLY , devname, verbose,0 ,NULL );if (dv->writemostly == FlagClear) rv = dev_st->ss->update_super ( - dev_st,NULL ,"readwrite" , + dev_st,NULL ,UOPT_SPEC_READWRITE , devname, verbose,0 ,NULL );if (dv->failfast == FlagSet) rv = dev_st->ss->update_super ( - dev_st,NULL ,"failfast" , + dev_st,NULL ,UOPT_SPEC_FAILFAST , devname, verbose,0 ,NULL );if (dv->failfast == FlagClear) rv = dev_st->ss->update_super ( - dev_st,NULL ,"nofailfast" , + dev_st,NULL ,UOPT_SPEC_NOFAILFAST , devname, verbose,0 ,NULL );if (update) rv = dev_st->ss->update_super ( - dev_st,NULL , update, + dev_st,NULL , update_enum, devname, verbose,0 ,NULL );if (rv ==0 ) rv = dev_st->ss->store_super (dev_st, tfd);
@@ -1731,6 +1732,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_identstruct supertype supertype, *st = &supertype;int fd, rv =2 ;struct mdinfo *info =NULL ; +enum update_opt update_enum =map_name (update_options, update);memset (st,0 ,sizeof (*st));
@@ -1762,7 +1764,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident goto free_super; } - rv = st->ss->update_subarray (st, subarray, update, ident); + rv = st->ss->update_subarray (st, subarray, update_enum, ident);if (rv) {if (verbose >=0 )
maps.c +0 -21
@@ -194,27 +194,6 @@ mapping_t update_options[] = { { "byteorder", UOPT_BYTEORDER }, { "help", UOPT_HELP }, { "?", UOPT_HELP }, -/* -* Those enries are temporary and will be removed in this patchset. -* -* Before update_super:update can be changed to enum, -* all update_super sub-functions must be adapted first. -* Update options will be passed as string (as it is for now), -* and then mapped, so all options must be handled temporarily. -* -* Those options code specific and should not be accessible for user. -*/ - { "force-one", UOPT_SPEC_FORCE_ONE }, - { "force-array", UOPT_SPEC_FORCE_ARRAY }, - { "assemble", UOPT_SPEC_ASSEMBLE }, - { "linear-grow-new", UOPT_SPEC_LINEAR_GROW_NEW }, - { "linear-grow-update", UOPT_SPEC_LINEAR_GROW_UPDATE }, - { "_reshape_progress", UOPT_SPEC__RESHAPE_PROGRESS }, - { "writemostly", UOPT_SPEC_WRITEMOSTLY }, - { "readwrite", UOPT_SPEC_READWRITE }, - { "failfast", UOPT_SPEC_FAILFAST }, - { "nofailfast", UOPT_SPEC_NOFAILFAST }, - { "revert-reshape-nobackup", UOPT_SPEC_REVERT_RESHAPE_NOBACKUP }, { NULL, UOPT_UNDEFINED} };
mdadm.h +9 -3
@@ -1011,7 +1011,7 @@ extern struct superswitch {* it will resume going in the opposite direction. */ int (*update_super)(struct supertype *st,struct mdinfo *info, -char *update, +enum update_opt update,char *devname,int verbose,int uuid_set,char *homehost);
@@ -1137,9 +1137,15 @@ extern struct superswitch {/* Permit subarray's to be deleted from inactive containers */ int (*kill_subarray)(struct supertype *st,char *subarray_id);/* optional */ -/* Permit subarray's to be modified */ +/** +* update_subarray() - Permit subarray to be modified. +* @st: Supertype. +* @subarray: Subarray name. +* @update: Update option. +* @ident: Optional identifiers. +*/ int (*update_subarray)(struct supertype *st,char *subarray, -char *update,struct mddev_ident *ident);/* optional */ +enum update_opt update,struct mddev_ident *ident);/* Check if reshape is supported for this external format. * st is obtained from super_by_fd() where st->subarray[0] is * initialized to indicate if reshape is being performed at the
super-intel.c +8 -8
@@ -3893,8 +3893,8 @@ struct mdinfo *getinfo_super_disks_imsm(struct supertype *st) }static int update_super_imsm (struct supertype *st,struct mdinfo *info, -char *update,char *devname,int verbose, -int uuid_set,char *homehost) +enum update_opt update,char *devname, +int verbose,int uuid_set,char *homehost) {/* For 'assemble' and 'force' we need to return non-zero if any * change was made. For others, the return value is ignored.
@@ -3930,7 +3930,7 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info, mpb = super->anchor; -switch (map_name (update_options, update)) { +switch (update) {case UOPT_UUID :/* We take this to mean that the family_num should be updated. * However that is much smaller than the uuid so we cannot really
@@ -6538,7 +6538,7 @@ static int validate_ppl_imsm(struct supertype *st, struct mdinfo *info,if (mdmon_running (st->container_devnm)) st->update_tail = &st->updates; -if (st->ss->update_subarray (st, subarray,"ppl" ,NULL )) { +if (st->ss->update_subarray (st, subarray,UOPT_PPL ,NULL )) {pr_err ("Failed to update subarray %s\n" , subarray); }else {
@@ -7916,13 +7916,13 @@ static int get_rwh_policy_from_update(enum update_opt update) }static int update_subarray_imsm (struct supertype *st,char *subarray, -char *update,struct mddev_ident *ident) +enum update_opt update,struct mddev_ident *ident) {/* update the subarray currently referenced by ->current_vol */ struct intel_super *super = st->sb;struct imsm_super *mpb = super->anchor; -if (map_name (update_options, update) ==UOPT_NAME ) { +if (update ==UOPT_NAME ) {char *name = ident->name;char *ep;int vol;
@@ -7956,7 +7956,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray, } super->updates_pending++; } - }else if (get_rwh_policy_from_update (map_name (update_options, update)) !=UOPT_UNDEFINED ) { + }else if (get_rwh_policy_from_update (update) !=UOPT_UNDEFINED ) {int new_policy;char *ep;int vol =strtoul (subarray, &ep,10 );
@@ -7964,7 +7964,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,if (*ep !='\0' || vol >= super->anchor->num_raid_devs)return 2 ; - new_policy =get_rwh_policy_from_update (map_name (update_options, update)); + new_policy =get_rwh_policy_from_update (update);if (st->update_tail) {struct imsm_update_rwh_policy *u =xmalloc (sizeof (*u));
super0.c +4 -5
@@ -491,7 +491,7 @@ static struct mdinfo *container_content0(struct supertype *st, char *subarray) }static int update_super0 (struct supertype *st,struct mdinfo *info, -char *update, +enum update_opt update,char *devname,int verbose,int uuid_set,char *homehost) {
@@ -502,20 +502,19 @@ static int update_super0(struct supertype *st, struct mdinfo *info,int rv =0 ;int uuid[4 ];mdp_super_t *sb = st->sb; -enum update_opt update_enum =map_name (update_options, update); -if (update_enum ==UOPT_HOMEHOST && homehost) { +if (update ==UOPT_HOMEHOST && homehost) {/* * note that 'homehost' is special as it is really * a "uuid" update. */ uuid_set =0 ; - update_enum =UOPT_UUID ; + update =UOPT_UUID ; info->uuid[0 ] = sb->set_uuid0; info->uuid[1 ] = sb->set_uuid1; } -switch (update_enum) { +switch (update) {case UOPT_UUID :if (!uuid_set && homehost) {char buf[20 ];
super1.c +8 -9
@@ -1208,7 +1208,7 @@ static struct mdinfo *container_content1(struct supertype *st, char *subarray) }static int update_super1 (struct supertype *st,struct mdinfo *info, -char *update,char *devname,int verbose, +enum update_opt update,char *devname,int verbose,int uuid_set,char *homehost) {/* NOTE: for 'assemble' and 'force' we need to return non-zero
@@ -1218,15 +1218,14 @@ static int update_super1(struct supertype *st, struct mdinfo *info,int rv =0 ;struct mdp_superblock_1 *sb = st->sb;bitmap_super_t *bms = (bitmap_super_t *)(((char *)sb) +MAX_SB_SIZE ); -enum update_opt update_enum =map_name (update_options, update); -if (update_enum ==UOPT_HOMEHOST && homehost) { +if (update ==UOPT_HOMEHOST && homehost) {/* * Note that 'homehost' is special as it is really * a "name" update. */ char *c; - update_enum =UOPT_NAME ; + update =UOPT_NAME ; c =strchr (sb->set_name,':' );if (c)snprintf (info->name,sizeof (info->name),"%s" , c+1 );
@@ -1234,7 +1233,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,snprintf (info->name,sizeof (info->name),"%s" , sb->set_name); } -switch (update_enum) { +switch (update) {case UOPT_NAME : {int namelen;
@@ -1534,7 +1533,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,* If that couldn't happen, the "-nobackup" version * will be used. */ - if (update_enum == UOPT_SPEC_REVERT_RESHAPE_NOBACKUP && + if (update == UOPT_SPEC_REVERT_RESHAPE_NOBACKUP && sb->reshape_position == 0 && (__le32_to_cpu(sb->delta_disks) > 0 || (__le32_to_cpu(sb->delta_disks) == 0 &&
@@ -1618,14 +1617,14 @@ static int update_super1(struct supertype *st, struct mdinfo *info,case UOPT_LAYOUT_UNSPECIFIED :if (__le32_to_cpu (sb->level) !=0 ) {pr_err ("%s: %s only supported for RAID0\n" , - devname ?:"" ,map_num (update_options, update_enum)); + devname ?:"" ,map_num (update_options, update)); rv =-1 ; - }else if (update_enum ==UOPT_LAYOUT_UNSPECIFIED ) { + }else if (update ==UOPT_LAYOUT_UNSPECIFIED ) { sb->feature_map &= ~__cpu_to_le32 (MD_FEATURE_RAID0_LAYOUT ); sb->layout =0 ; }else { sb->feature_map |=__cpu_to_le32 (MD_FEATURE_RAID0_LAYOUT ); - sb->layout =__cpu_to_le32 (update_enum ==UOPT_LAYOUT_ORIGINAL ?1 :2 ); + sb->layout =__cpu_to_le32 (update ==UOPT_LAYOUT_ORIGINAL ?1 :2 ); }break ;default :
Signature · 1 line
2.26.2
PATCH v2 9/10 Manage&Incremental: code refactor, string to enum
In reply to Mateusz KusiakPrepare Manage and Incremental for later changing context->update to enum. Change update from string to enum in multiple functions and pass enum where already possible.
--- Grow.c | 8 ++++---- Incremental.c | 8 ++++---- Manage.c | 35 +++++++++++++++++------------------ mdadm.c | 23 ++++++++++++++++++----- mdadm.h | 4 ++-- 5 files changed, 45 insertions(+), 33 deletions(-)
Grow.c +4 -4
@@ -605,12 +605,12 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha }if (subarray) { -char *update; +enum update_opt update;if (s->consistency_policy ==CONSISTENCY_POLICY_PPL ) - update ="ppl" ; + update =UOPT_PPL ;else - update ="no-ppl" ; + update =UOPT_NO_PPL ;sprintf (container_dev,"/dev/%s" , st->container_devnm);
@@ -3243,7 +3243,7 @@ static int reshape_array(char *container, int fd, char *devname,* level and frozen, we can safely add them. */ if (devlist) { -if (Manage_subdevs (devname, fd, devlist, verbose,0 ,NULL ,0 )) +if (Manage_subdevs (devname, fd, devlist, verbose,0 ,UOPT_UNDEFINED ,0 )) goto release; }
Incremental.c +4 -4
@@ -1025,7 +1025,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,close (dfd); *dfdp =-1 ; rv =Manage_subdevs (chosen->sys_name, mdfd, &devlist, --1 ,0 ,NULL ,0 ); +-1 ,0 ,UOPT_UNDEFINED ,0 );close (mdfd); }if (verbose >0 ) {
@@ -1666,7 +1666,7 @@ static void remove_from_member_array(struct mdstat_ent *memb,if (subfd >=0 ) { rv =Manage_subdevs (memb->devnm, subfd, devlist, verbose, -0 ,NULL ,0 ); +0 ,UOPT_UNDEFINED ,0 );if (rv &2 ) {if (sysfs_init (&mmdi,-1 , memb->devnm)) pr_err("unable to initialize sysfs for: %s\n",
@@ -1758,7 +1758,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)free_mdstat (mdstat); }else { rv |=Manage_subdevs (ent->devnm, mdfd, &devlist, - verbose,0 ,NULL ,0 ); + verbose,0 ,UOPT_UNDEFINED ,0 );if (rv &2 ) {/* Failed due to EBUSY, try to stop the array. * Give udisks a chance to unmount it first.
@@ -1770,7 +1770,7 @@ int IncrementalRemove(char *devname, char *id_path, int verbose) devlist.disposition ='r' ; rv =Manage_subdevs (ent->devnm, mdfd, &devlist, - verbose,0 ,NULL ,0 ); + verbose,0 ,UOPT_UNDEFINED ,0 ); end:close (mdfd);free_mdstat (ent);
Manage.c +17 -18
@@ -598,14 +598,12 @@ static void add_set(struct mddev_dev *dv, int fd, char set_char)int attempt_re_add (int fd,int tfd,struct mddev_dev *dv,struct supertype *dev_st,struct supertype *tst, -unsigned long rdev, -char *update,char *devname,int verbose, -mdu_array_info_t *array) +unsigned long rdev,enum update_opt update, +char *devname,int verbose,mdu_array_info_t *array) {struct mdinfo mdi;int duuid[4 ];int ouuid[4 ]; -enum update_opt update_enum =map_name (update_options, update); dev_st->ss->getinfo_super (dev_st, &mdi,NULL ); dev_st->ss->uuid_from_super (dev_st, ouuid);
@@ -683,7 +681,7 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv, devname, verbose, 0, NULL);if (update) rv = dev_st->ss->update_super ( - dev_st,NULL , update_enum, + dev_st,NULL , update, devname, verbose,0 ,NULL );if (rv ==0 ) rv = dev_st->ss->store_super (dev_st, tfd);
@@ -715,8 +713,8 @@ skip_re_add:int Manage_add (int fd,int tfd,struct mddev_dev *dv,struct supertype *tst,mdu_array_info_t *array,int force,int verbose,char *devname, -char *update,unsigned long rdev,unsigned long long array_size, -int raid_slot) +enum update_opt update,unsigned long rdev, +unsigned long long array_size,int raid_slot) {unsigned long long ldsize;struct supertype *dev_st;
@@ -1332,7 +1330,7 @@ bool is_remove_safe(mdu_array_info_t *array, const int fd, char *devname, constint Manage_subdevs (char *devname,int fd,struct mddev_dev *devlist,int verbose,int test, -char *update,int force) +enum update_opt update,int force) {/* Do something to each dev. * devmode can be
@@ -1727,12 +1725,13 @@ int autodetect(void)return rv; } -int Update_subarray (char *dev,char *subarray,char *update,struct mddev_ident *ident,int verbose) +int Update_subarray (char *dev,char *subarray,enum update_opt update, +struct mddev_ident *ident,int verbose) {struct supertype supertype, *st = &supertype;int fd, rv =2 ;struct mdinfo *info =NULL ; -enum update_opt update_enum =map_name (update_options, update); +char *update_verb =map_num (update_options, update);memset (st,0 ,sizeof (*st));
@@ -1750,7 +1749,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_identif (is_subarray_active (subarray, st->devnm)) {if (verbose >=0 )pr_err ("Subarray %s in %s is active, cannot update %s\n" , - subarray, dev, update); + subarray, dev, update_verb); goto free_super; }
@@ -1759,23 +1758,23 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident info = st->ss->container_content (st, subarray); -if (strncmp (update,"ppl" ,3 ) ==0 && !is_level456 (info->array.level)) { +if (update ==UOPT_PPL && !is_level456 (info->array.level)) {pr_err ("RWH policy ppl is supported only for raid4, raid5 and raid6.\n" ); goto free_super; } - rv = st->ss->update_subarray (st, subarray, update_enum, ident); + rv = st->ss->update_subarray (st, subarray, update, ident);if (rv) {if (verbose >=0 )pr_err ("Failed to update %s of subarray-%s in %s\n" , - update, subarray, dev); + update_verb, subarray, dev); }else if (st->update_tail)flush_metadata_updates (st);else st->ss->sync_metadata (st); -if (rv ==0 &&strcmp (update,"name" ) ==0 && verbose >=0 ) +if (rv ==0 && update ==UOPT_NAME && verbose >=0 )pr_err ("Updated subarray-%s name from %s, UUIDs may have changed\n" , subarray, dev);
@@ -1816,10 +1815,10 @@ int move_spare(char *from_devname, char *to_devname, dev_t devid)sprintf (devname,"%d:%d" ,major (devid),minor (devid)); devlist.disposition ='r' ; -if (Manage_subdevs (from_devname, fd2, &devlist,-1 ,0 ,NULL ,0 ) ==0 ) { +if (Manage_subdevs (from_devname, fd2, &devlist,-1 ,0 ,UOPT_UNDEFINED ,0 ) ==0 ) { devlist.disposition ='a' ;if (Manage_subdevs (to_devname, fd1, &devlist,-1 ,0 , -NULL ,0 ) ==0 ) { +UOPT_UNDEFINED ,0 ) ==0 ) {/* make sure manager is aware of changes */ ping_manager (to_devname);ping_manager (from_devname);
@@ -1829,7 +1828,7 @@ int move_spare(char *from_devname, char *to_devname, dev_t devid) }else Manage_subdevs (from_devname, fd2, &devlist, --1 ,0 ,NULL ,0 ); +-1 ,0 ,UOPT_UNDEFINED ,0 ); }close (fd1);close (fd2);
mdadm.c +18 -5
@@ -1402,10 +1402,22 @@ int main(int argc, char *argv[])/* readonly, add/remove, readwrite, runstop */ if (c.readonly >0 ) rv =Manage_ro (devlist->devname, mdfd, c.readonly); -if (!rv && devs_found>1 ) - rv =Manage_subdevs (devlist->devname, mdfd, - devlist->next, c.verbose, c.test, - c.update, c.force); +if (!rv && devs_found >1 ) { +/* +* This is temporary and will be removed in next patches +* Null c.update will cause segfault +*/ +if (c.update) + rv =Manage_subdevs (devlist->devname, mdfd, + devlist->next, c.verbose, c.test, +map_name (update_options, c.update), + c.force); +else + rv =Manage_subdevs (devlist->devname, mdfd, + devlist->next, c.verbose, c.test, +UOPT_UNDEFINED , + c.force); + }if (!rv && c.readonly <0 ) rv =Manage_ro (devlist->devname, mdfd, c.readonly);if (!rv && c.runstop >0 )
@@ -1931,7 +1943,8 @@ static int misc_list(struct mddev_dev *devlist,continue ; } rv |=Update_subarray (dv->devname, c->subarray, - c->update, ident, c->verbose); +map_name (update_options, c->update), + ident, c->verbose);continue ;case Dump: rv |=Dump_metadata (dv->devname, dump_directory, c, ss);
mdadm.h +2 -2
@@ -1478,7 +1478,7 @@ extern int Manage_stop(char *devname, int fd, int quiet, int will_retry);extern int Manage_subdevs (char *devname,int fd,struct mddev_dev *devlist,int verbose,int test, -char *update,int force); +enum update_opt update,int force);extern int autodetect (void );extern int Grow_Add_device (char *devname,int fd,char *newdev); extern int Grow_addbitmap(char *devname, int fd,
@@ -1532,7 +1532,7 @@ extern int Monitor(struct mddev_dev *devlist,extern int Kill (char *dev,struct supertype *st,int force,int verbose,int noexcl);extern int Kill_subarray (char *dev,char *subarray,int verbose); -extern int Update_subarray (char *dev,char *subarray,char *update,struct mddev_ident *ident,int quiet); +extern int Update_subarray (char *dev,char *subarray,enum update_opt update,struct mddev_ident *ident,int quiet);extern int Wait (char *dev);extern int WaitClean (char *dev,int verbose);extern int SetAction (char *dev,char *action);
Signature · 1 line
2.26.2
PATCH v2 10/10 Change char* to enum in context->update & refactor code
In reply to Mateusz KusiakStoring update option in string is bad for frequent comparisons and error prone.
Replace char array with enum so already existing enum is passed around instead of string.
Adapt code to changes.
--- Assemble.c | 40 +++++++++++++++++----------------------- mdadm.c | 52 +++++++++++++++++++--------------------------------- mdadm.h | 2 +- 3 files changed, 37 insertions(+), 57 deletions(-)
Assemble.c +17 -23
@@ -135,17 +135,17 @@ static int ident_matches(struct mddev_ident *ident, struct mdinfo *content, struct supertype *tst, char *homehost, int require_homehost, - char *update, char *devname) + enum update_opt update, char *devname) { - if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) && + if (ident->uuid_set && update != UOPT_UUID && same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0 && memcmp(content->uuid, uuid_zero, sizeof(int[4])) != 0) { if (devname) pr_err("%s has wrong uuid.\n", devname); return 0; } - if (ident->name[0] && (!update || strcmp(update, "name")!= 0) && + if (ident->name[0] && update != UOPT_NAME && name_matches(content->name, ident->name, homehost, require_homehost)==0) { if (devname) pr_err("%s has wrong name.\n", devname);
@@ -648,11 +648,10 @@ static int load_devices(struct devs *devices, char *devmap,int err;fstat (mdfd, &stb2); -if (strcmp (c->update,"uuid" ) ==0 && !ident->uuid_set) +if (c->update ==UOPT_UUID && !ident->uuid_set)random_uuid ((__u8 *)ident->uuid); -if (strcmp (c->update,"ppl" ) ==0 && - ident->bitmap_fd >=0 ) { +if (c->update ==UOPT_PPL && ident->bitmap_fd >=0 ) {pr_err ("PPL is not compatible with bitmap\n" );close (mdfd);free (devices);
@@ -684,34 +683,30 @@ static int load_devices(struct devs *devices, char *devmap,strcpy (content->name, ident->name); content->array.md_minor =minor (stb2.st_rdev); -if (strcmp (c->update,"byteorder" ) ==0 ) +if (c->update ==UOPT_BYTEORDER ) err =0 ; -else if (strcmp (c->update,"home-cluster" ) ==0 ) { +else if (c->update ==UOPT_HOME_CLUSTER ) { tst->cluster_name = c->homecluster; err = tst->ss->write_bitmap (tst, dfd, NameUpdate); - }else if (strcmp (c->update,"nodes" ) ==0 ) { + }else if (c->update ==UOPT_NODES ) { tst->nodes = c->nodes; err = tst->ss->write_bitmap (tst, dfd, NodeNumUpdate); - }else if (strcmp (c->update,"revert-reshape" ) ==0 && - c->invalid_backup) + }else if (c->update ==UOPT_REVERT_RESHAPE && c->invalid_backup) err = tst->ss->update_super (tst, content,UOPT_SPEC_REVERT_RESHAPE_NOBACKUP , devname, c->verbose, ident->uuid_set, c->homehost);else -/* -* Mapping is temporary, will be removed in this patchset -*/ err = tst->ss->update_super (tst, content, -map_name (update_options, c->update), + c->update, devname, c->verbose, ident->uuid_set, c->homehost);if (err <0 ) {if (err ==-1 )pr_err ("--update=%s not understood for %s metadata\n" , - c->update, tst->ss->name); +map_num (update_options, c->update), tst->ss->name); tst->ss->free_super (tst);free (tst);close (mdfd);
@@ -721,7 +716,7 @@ static int load_devices(struct devs *devices, char *devmap, *stp = st;return -1 ; } -if (strcmp (c->update,"uuid" )==0 && +if (c->update ==UOPT_UUID && !ident->uuid_set) { ident->uuid_set =1 ;memcpy (ident->uuid, content->uuid,16 );
@@ -730,7 +725,7 @@ static int load_devices(struct devs *devices, char *devmap,pr_err ("Could not re-write superblock on %s.\n" , devname); -if (strcmp (c->update,"uuid" )==0 && +if (c->update ==UOPT_UUID && ident->bitmap_fd >=0 && !bitmap_done) { if (bitmap_update_uuid(ident->bitmap_fd, content->uuid,
@@ -1188,8 +1183,7 @@ static int start_array(int mdfd,pr_err ("%s: Need a backup file to complete reshape of this array.\n" , mddev);pr_err ("Please provided one with \"--backup-file=...\"\n" ); -if (c->update && -strcmp (c->update,"revert-reshape" ) ==0 ) +if (c->update ==UOPT_REVERT_RESHAPE )pr_err ("(Don't specify --update=revert-reshape again, that part succeeded.)\n" );return 1 ; }
@@ -1487,7 +1481,7 @@ try_again:*/ if (map_lock (&map))pr_err ("failed to get exclusive lock on mapfile - continue anyway...\n" ); -if (c->update &&strcmp (c->update,"uuid" ) ==0 ) +if (c->update ==UOPT_UUID ) mp =NULL ;else mp =map_by_uuid (&map, content->uuid);
@@ -1634,7 +1628,7 @@ try_again: goto out; } -if (c->update &&strcmp (c->update,"byteorder" )==0 ) +if (c->update ==UOPT_BYTEORDER ) st->minor_version =90 ; st->ss->getinfo_super (st, content,NULL );
@@ -1902,7 +1896,7 @@ try_again:/* First, fill in the map, so that udev can find our name * as soon as we become active. */ -if (c->update &&strcmp (c->update,"metadata" )==0 ) { +if (c->update ==UOPT_METADATA ) { content->array.major_version =1 ; content->array.minor_version =0 ;strcpy (content->text_version,"1.0" );
mdadm.c +19 -33
109 lines not on this page · raw message
mdadm.h +1 -1
@@ -616,7 +616,7 @@ struct context {int export;int test;char *subarray; -char *update; +enum update_opt update;int scan;int SparcAdjust;int autof;
Signature · 1 line
2.26.2
Jes Sorensen
AppliedQuoted 16 lines · Mateusz Kusiak
This is the v2 of the patchset I submitted long time ago. I applied the changes that were requested, but since long time has passed I'm submitting the whole patchset once again.
Mateusz Kusiak (10):
mdadm: Add option validation for --update-subarray Fix --update-subarray on active volume
Add code specific update options to enum.
super-ddf: Removeupdate_super_ddf.
super0: refactor the code for enum
super1: refactor the code for enum
super-intel: refactor the code for enum
Change update to enum inupdate_superandupdate_subarrayManage&Incremental: code refactor, string to enum Change char* to enum incontext->update& refactor code
Quoted 15 lines
Assemble.c | 46 ++++++++------- Examine.c | 2 +- Grow.c | 17 +++--- Incremental.c | 8 +-- Manage.c | 42 ++++++++------ ReadMe.c | 31 ++++++++++ maps.c | 31 ++++++++++ mdadm.c | 129 ++++++++++++++---------------------------- mdadm.h | 65 ++++++++++++++++++--- super-ddf.c | 70 ----------------------- super-intel.c | 48 +++++++++------- super0.c | 103 ++++++++++++++++++++------------- super1.c | 153 ++++++++++++++++++++++++++++++-------------------- 13 files changed, 406 insertions(+), 339 deletions(-)
Applied!
Thanks,
Jes