From: James Simmons Date: Thu, 7 Nov 2019 13:49:00 +0000 (-0500) Subject: LU-9325 mds: replace simple_strtol use with target_name2index() X-Git-Tag: 2.13.51~142 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=7d37148e36854a293fdc40d7d771769f0a6b64e0 LU-9325 mds: replace simple_strtol use with target_name2index() With simple_strtol() going away in the future we should move to kstrtoXXX functions. Looking a the simple_strtol() use in lod and osp layer that its use is really target_name2index(). We can migrate to this function so we have one stop to update from using simple_strtol(). Change-Id: Ia3d0208c1b1c6bfbe9aa03ce3c068d41ed2c7595 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/36551 Tested-by: jenkins Reviewed-by: Shaun Tancheff Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index e4bbf62..927c764 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -528,8 +528,8 @@ void lod_sub_fini_llog(const struct lu_env *env, */ int lodname2mdt_index(char *lodname, u32 *mdt_index) { - unsigned long index; - char *ptr, *tmp; + u32 index; + const char *ptr, *tmp; int rc; /* 1.8 configs don't have "-MDT0000" at the end */ @@ -564,8 +564,8 @@ int lodname2mdt_index(char *lodname, u32 *mdt_index) return rc; } - index = simple_strtol(ptr - 4, &tmp, 16); - if (*tmp != '-' || index > INT_MAX) { + rc = target_name2index(ptr - 7, &index, &tmp); + if (rc < 0 || rc & LDD_F_SV_ALL || *tmp != '-') { rc = -EINVAL; CERROR("invalid MDT index in '%s': rc = %d\n", lodname, rc); return rc; diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 8c2fde7..f754121 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -893,6 +893,9 @@ int target_name2index(const char *tgtname, __u32 *idx, const char **endptr) if (idx != NULL) *idx = index; + if (index > 0xffff) + return -ERANGE; + return rc; } EXPORT_SYMBOL(target_name2index); diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index 4b94888..ba348ef 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -1014,9 +1014,10 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp, { struct obd_device *obd; struct obd_import *imp; - char *src, *tgt, *mdt, *osdname = NULL; + char *src, *tgt, *osdname = NULL; + const char *mdt; int rc; - long idx; + u32 idx; ENTRY; @@ -1063,8 +1064,8 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp, RETURN(-EINVAL); } - idx = simple_strtol(tgt + 4, &mdt, 16); - if (mdt[0] != '-' || idx > INT_MAX || idx < 0) { + rc = target_name2index(tgt + 1, &idx, &mdt); + if (rc < 0 || rc & LDD_F_SV_ALL || mdt[0] != '-') { CERROR("%s: invalid OST index in '%s': rc = %d\n", osp->opd_obd->obd_name, src, -EINVAL); RETURN(-EINVAL); @@ -1082,8 +1083,8 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp, RETURN(-EINVAL); } - idx = simple_strtol(tgt + 4, &mdt, 16); - if (*mdt != '\0' || idx > INT_MAX || idx < 0) { + rc = target_name2index(tgt + 1, &idx, &mdt); + if (rc < 0 || rc & LDD_F_SV_ALL || *mdt != '\0') { CERROR("%s: invalid OST index in '%s': rc = %d\n", osp->opd_obd->obd_name, src, -EINVAL); RETURN(-EINVAL); @@ -1102,8 +1103,8 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp, if (strncmp(tgt - 12, "-MDT", 4) == 0) osp->opd_connect_mdt = 1; - idx = simple_strtol(tgt - 8, &mdt, 16); - if (mdt[0] != '-' || idx > INT_MAX || idx < 0) { + rc = target_name2index(tgt - 11, &idx, &mdt); + if (rc < 0 || rc & LDD_F_SV_ALL || mdt[0] != '-') { CERROR("%s: invalid OST index in '%s': rc =%d\n", osp->opd_obd->obd_name, src, -EINVAL); RETURN(-EINVAL);