static inline bool filename_is_volatile(const char *name, size_t namelen,
int *idx)
{
- const char *start;
- char *end;
+ const char *start;
+ int rnd, fd, rc;
if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0)
return false;
}
/* we have an idx, read it */
start = name + LUSTRE_VOLATILE_HDR_LEN + 1;
- *idx = simple_strtoul(start, &end, 16);
- /* error cases:
- * no digit, no trailing :, negative value
+ rc = sscanf(start, "%4x:%4x:fd=%2d", idx, &rnd, &fd);
+ /* error cases: no digit or negative value
+ * rc will never be larger then 3
*/
- if (((*idx == 0) && (end == start)) ||
- (*end != ':') || (*idx < 0))
+ if (rc <= 0 || *idx < 0)
goto bad_format;
return true;
* Get the index from the target name MDTXXXX/OSTXXXX
* rc = server type, or rc < 0 on error
**/
-int target_name2index(const char *tgtname, __u32 *idx, const char **endptr)
+int target_name2index(const char *tgtname, u32 *idx, const char **endptr)
{
const char *dash = tgtname;
- unsigned long index;
- int rc;
+ int type, len, rc;
+ u16 index;
if (strncmp(dash, "MDT", 3) == 0)
- rc = LDD_F_SV_TYPE_MDT;
+ type = LDD_F_SV_TYPE_MDT;
else if (strncmp(dash, "OST", 3) == 0)
- rc = LDD_F_SV_TYPE_OST;
+ type = LDD_F_SV_TYPE_OST;
else
return -EINVAL;
if (strncmp(dash, "all", 3) == 0) {
if (endptr != NULL)
*endptr = dash + 3;
- return rc | LDD_F_SV_ALL;
+ return type | LDD_F_SV_ALL;
}
- index = simple_strtoul(dash, (char **)endptr, 16);
- if (idx != NULL)
+ len = strspn(dash, "0123456789ABCDEFabcdef");
+ if (len > 4)
+ return -ERANGE;
+
+ if (strlen(dash) != len) {
+ char num[5];
+
+ num[4] = '\0';
+ memcpy(num, dash, sizeof(num) - 1);
+ rc = kstrtou16(num, 16, &index);
+ if (rc < 0)
+ return rc;
+ } else {
+ rc = kstrtou16(dash, 16, &index);
+ if (rc < 0)
+ return rc;
+ }
+
+ if (idx)
*idx = index;
- if (index > 0xffff)
- return -ERANGE;
+ if (endptr)
+ *endptr = dash + len;
- return rc;
+ return type;
}
EXPORT_SYMBOL(target_name2index);