Whamcloud - gitweb
LU-9325 mds: replace simple_strtol use with target_name2index() 51/36551/5
authorJames Simmons <jsimmons@infradead.org>
Thu, 7 Nov 2019 13:49:00 +0000 (08:49 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 6 Dec 2019 01:10:19 +0000 (01:10 +0000)
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 <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/36551
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/lod/lod_dev.c
lustre/obdclass/obd_mount.c
lustre/osp/osp_dev.c

index e4bbf62..927c764 100644 (file)
@@ -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;
index 8c2fde7..f754121 100644 (file)
@@ -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);
index 4b94888..ba348ef 100644 (file)
@@ -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);