+update_idmaps() { #LU-10040
+ [ $(lustre_version_code mgs) -lt $(version_code 2.10.55) ] &&
+ skip "Need MGS >= 2.10.55" &&
+ return
+ local csum=${HOSTNAME_CHECKSUM}_0
+ local old_id_client=$ID0
+ local old_id_fs=$((ID0 + 1))
+ local new_id=$((ID0 + 100))
+ local tmp_id
+ local cmd
+ local run
+ local idtype
+ local rc=0
+
+ echo "Start to update idmaps ..."
+
+ #Inserting an existed idmap should return error
+ cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
+ if do_facet mgs \
+ $cmd --idmap $old_id_client:$old_id_fs 2>/dev/null; then
+ error "insert idmap {$old_id_client:$old_id_fs} " \
+ "should return error"
+ rc=$((rc + 1))
+ return rc
+ fi
+
+ #Update id_fs and check it
+ if ! do_facet mgs $cmd --idmap $old_id_client:$new_id; then
+ error "$cmd --idmap $old_id_client:$new_id failed"
+ rc=$((rc + 1))
+ return $rc
+ fi
+ tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
+ awk '{ print $7 }' | sed -n '2p')
+ [ $tmp_id != $new_id ] && { error "new id_fs $tmp_id != $new_id"; \
+ rc=$((rc + 1)); return $rc; }
+
+ #Update id_client and check it
+ if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
+ error "$cmd --idmap $new_id:$new_id failed"
+ rc=$((rc + 1))
+ return $rc
+ fi
+ tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
+ awk '{ print $5 }' | sed -n "$((NODEMAP_ID_COUNT + 1)) p")
+ tmp_id=$(echo ${tmp_id%,*}) #e.g. "501,"->"501"
+ [ $tmp_id != $new_id ] && { error "new id_client $tmp_id != $new_id"; \
+ rc=$((rc + 1)); return $rc; }
+
+ #Delete above updated idmap
+ cmd="$LCTL nodemap_del_idmap --name $csum --idtype uid"
+ if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
+ error "$cmd --idmap $new_id:$new_id failed"
+ rc=$((rc + 1))
+ return $rc
+ fi
+
+ #restore the idmaps to make delete_idmaps work well
+ cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
+ if ! do_facet mgs $cmd --idmap $old_id_client:$old_id_fs; then
+ error "$cmd --idmap $old_id_client:$old_id_fs failed"
+ rc=$((rc + 1))
+ return $rc
+ fi
+
+ return $rc
+}
+