Whamcloud - gitweb
LU-10199 utils: strip // from fid2path 75/31775/2
authorBen Evans <bevans@cray.com>
Tue, 14 Nov 2017 15:28:12 +0000 (10:28 -0500)
committerJohn L. Hammond <john.hammond@intel.com>
Thu, 5 Apr 2018 20:35:51 +0000 (20:35 +0000)
There are a few ways to get a path with a // back from
fid2path, make sure we strip them all out

Lustre-commit: 116b73d69bf2462fa9e9b8b9f629794bbda90ee5
Lustre-change: https://review.whamcloud.com/30078

Signed-off-by: Ben Evans <bevans@cray.com>
Signed-off-by: Bob Glossman <bob.glossman@intel.com>
Change-Id: I30591585ccf62e4d793ee658d2772ce1db242034
Reviewed-on: https://review.whamcloud.com/30078
Reviewed-by: Steve Guminski <stephenx.guminski@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-on: https://review.whamcloud.com/31775
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Nunez <james.a.nunez@intel.com>
lustre/utils/liblustreapi.c

index c774d0d..6598f13 100644 (file)
@@ -4550,6 +4550,8 @@ int llapi_fid2path(const char *device, const char *fidstr, char *buf,
        const char *fidstr_orig = fidstr;
        struct lu_fid fid;
        struct getinfo_fid2path *gf;
+       char *a;
+       char *b;
        int rc;
 
        while (*fidstr == '[')
@@ -4578,11 +4580,21 @@ int llapi_fid2path(const char *device, const char *fidstr, char *buf,
        if (rc)
                goto out_free;
 
-       memcpy(buf, gf->gf_u.gf_path, gf->gf_pathlen);
+       b = buf;
+       /* strip out instances of // */
+       for (a = gf->gf_u.gf_path; *a != '\0'; a++) {
+               if ((*a == '/') && (*(a + 1) == '/'))
+                       continue;
+               *b = *a;
+               b++;
+       }
+       *b = '\0';
+
        if (buf[0] == '\0') { /* ROOT path */
                buf[0] = '/';
                buf[1] = '\0';
        }
+
        *recno = gf->gf_recno;
        *linkno = gf->gf_linkno;