RETURN(-EINVAL);
}
- if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
- CERROR("client UUID must be less than 38 characters\n");
+ if (LUSTRE_CFG_BUFLEN(lcfg, 1) > UUID_MAX) {
+ CERROR("client UUID must be %u characters or less\n", UUID_MAX);
RETURN(-EINVAL);
}
RETURN(-EINVAL);
}
- if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
- CERROR("target UUID must be less than 38 characters\n");
+ if (LUSTRE_CFG_BUFLEN(lcfg, 2) > UUID_MAX) {
+ CERROR("target UUID must be %u characters or less\n", UUID_MAX);
RETURN(-EINVAL);
}
static inline int name_create(char **newname, char *prefix, char *suffix)
{
+ size_t newname_len = strlen(prefix) + strlen(suffix) + 1;
+
LASSERT(newname);
- OBD_ALLOC(*newname, strlen(prefix) + strlen(suffix) + 1);
+
+ OBD_ALLOC(*newname, newname_len);
if (!*newname)
return -ENOMEM;
- sprintf(*newname, "%s%s", prefix, suffix);
+
+ snprintf(*newname, newname_len, "%s%s", prefix, suffix);
return 0;
}
*name = NULL;
}
+static inline int niduuid_create(char **niduuid, char *nidstr)
+{
+ size_t niduuid_len = strlen(nidstr) + 1;
+
+ LASSERT(niduuid);
+
+ /* Large NIDs may be longer than UUID_MAX. In this case we skip bytes at
+ * the start of the string because the bytes at the end of the NID
+ * should be more unique
+ */
+ if (niduuid_len > UUID_MAX) {
+ nidstr += niduuid_len - UUID_MAX;
+ niduuid_len = strlen(nidstr) + 1;
+ }
+
+ OBD_ALLOC(*niduuid, niduuid_len);
+ if (!*niduuid)
+ return -ENOMEM;
+
+ snprintf(*niduuid, niduuid_len, "%s", nidstr);
+ return 0;
+}
+
+static inline void niduuid_destroy(char **niduuid)
+{
+ name_destroy(niduuid);
+}
+
static inline int name_create_osp(char **ospname, char **devtype, char *tgtname,
int index)
{
ptr = mrd->target.mti_params;
while (class_parse_nid(ptr, &nid, &ptr) == 0) {
if (!mrd->nodeuuid) {
- rc = name_create(&mrd->nodeuuid,
- libcfs_nidstr(&nid), "");
+ rc = niduuid_create(&mrd->nodeuuid,
+ libcfs_nidstr(&nid));
if (rc) {
CERROR("Can't create uuid for "
"nid %s, device %s\n",
libcfs_nidstr(&nid),
mrd->nodeuuid ? mrd->nodeuuid : "NULL",
mrd->target.mti_svname);
- name_destroy(&mrd->nodeuuid);
+ niduuid_destroy(&mrd->nodeuuid);
return -ENXIO;
} else {
mrd->state = REPLACE_SETUP;
/* s4 is not changed */
lustre_cfg_string(lcfg, 4));
- name_destroy(&mrd->nodeuuid);
+ niduuid_destroy(&mrd->nodeuuid);
if (rc)
return rc;
ptr = mrd->failover;
while (class_parse_nid(ptr, &nid, &ptr) == 0) {
if (mrd->nodeuuid == NULL) {
- rc = name_create(&mrd->nodeuuid,
- libcfs_nidstr(&nid),
- "");
+ rc = niduuid_create(&mrd->nodeuuid,
+ libcfs_nidstr(&nid));
if (rc)
return rc;
}
mrd->target.mti_svname,
libcfs_nidstr(&nid),
mrd->nodeuuid, rc);
- name_destroy(&mrd->nodeuuid);
+ niduuid_destroy(&mrd->nodeuuid);
return rc;
}
if (*ptr == ':') {
mrd->temp_llh,
lustre_cfg_string(lcfg, 0),
mrd->nodeuuid);
- name_destroy(&mrd->nodeuuid);
+ niduuid_destroy(&mrd->nodeuuid);
if (rc)
return rc;
}
rc = record_add_conn(env, mrd->temp_llh,
lustre_cfg_string(lcfg, 0),
mrd->nodeuuid);
- name_destroy(&mrd->nodeuuid);
+ niduuid_destroy(&mrd->nodeuuid);
if (rc)
return rc;
}
/* We don't know the failover node name,
* so just use the first nid as the uuid */
libcfs_nidstr_r(&nid, nidstr, sizeof(nidstr));
- rc = name_create(&failnodeuuid, nidstr, "");
+ rc = niduuid_create(&failnodeuuid, nidstr);
if (rc != 0)
return rc;
}
if (*ptr == ':') {
rc = record_add_conn(env, llh, cliname,
failnodeuuid);
- name_destroy(&failnodeuuid);
+ niduuid_destroy(&failnodeuuid);
failnodeuuid = NULL;
}
}
if (failnodeuuid) {
rc = record_add_conn(env, llh, cliname, failnodeuuid);
- name_destroy(&failnodeuuid);
+ niduuid_destroy(&failnodeuuid);
failnodeuuid = NULL;
}
}
nidstr = mti->mti_nidlist[0];
}
- rc = name_create(&nodeuuid, nidstr, "");
+ rc = niduuid_create(&nodeuuid, nidstr);
if (rc)
RETURN(rc);
rc = name_create(&mdcname, mti->mti_svname, "-mdc");
name_destroy(&lmvuuid);
name_destroy(&mdcuuid);
name_destroy(&mdcname);
- name_destroy(&nodeuuid);
+ niduuid_destroy(&nodeuuid);
RETURN(rc);
}
nidstr = mti->mti_nidlist[0];
}
- rc = name_create(&nodeuuid, nidstr, "");
+ rc = niduuid_create(&nodeuuid, nidstr);
if (rc)
GOTO(out_destory, rc);
name_destroy(&lovuuid);
name_destroy(&lovname);
name_destroy(&ospname);
- name_destroy(&nodeuuid);
+ niduuid_destroy(&nodeuuid);
name_destroy(&mdtname);
RETURN(rc);
}
nidstr = mti->mti_nidlist[0];
}
- rc = name_create(&nodeuuid, nidstr, "");
+ rc = niduuid_create(&nodeuuid, nidstr);
if (rc)
RETURN(rc);
rc = name_create(&svname, mti->mti_svname, "-osc");
name_destroy(&oscuuid);
name_destroy(&oscname);
name_destroy(&svname);
- name_destroy(&nodeuuid);
+ niduuid_destroy(&nodeuuid);
RETURN(rc);
}
static DEFINE_MUTEX(mgc_start_lock);
+/* 9 for '_%x' (INT_MAX as hex is 8 chars - '7FFFFFFF') and 1 for '\0' */
+#define NIDUUID_SUFFIX_MAX_LEN 10
+static inline int mgc_niduuid_create(char **niduuid, char *nidstr)
+{
+ size_t niduuid_len = strlen(nidstr) + strlen(LUSTRE_MGC_OBDNAME) +
+ NIDUUID_SUFFIX_MAX_LEN;
+
+ LASSERT(niduuid);
+
+ /* See comment in niduuid_create() */
+ if (niduuid_len > UUID_MAX) {
+ nidstr += niduuid_len - UUID_MAX;
+ niduuid_len = strlen(LUSTRE_MGC_OBDNAME) +
+ strlen(nidstr) + NIDUUID_SUFFIX_MAX_LEN;
+ }
+
+ OBD_ALLOC(*niduuid, niduuid_len);
+ if (!*niduuid)
+ return -ENOMEM;
+
+ snprintf(*niduuid, niduuid_len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
+ return 0;
+}
+
+static inline void mgc_niduuid_destroy(char **niduuid)
+{
+ if (*niduuid) {
+ char *tmp = strchr(*niduuid, '_');
+
+ /* If the "_%x" suffix hasn't been added yet then the size
+ * calculation below should still be correct
+ */
+ if (tmp)
+ *tmp = '\0';
+
+ OBD_FREE(*niduuid, strlen(*niduuid) + NIDUUID_SUFFIX_MAX_LEN);
+ }
+ *niduuid = NULL;
+}
+
/**
* Set up a MGC OBD to process startup logs
*
char nidstr[LNET_NIDSTR_SIZE];
char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
bool large_nids = false;
- char *ptr;
+ char *ptr, *niduuid_suffix;
int rc = 0, i = 0, j;
size_t len;
libcfs_nidstr_r(&nid, nidstr, sizeof(nidstr));
len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1;
OBD_ALLOC(mgcname, len);
- OBD_ALLOC(niduuid, len + 2);
- if (mgcname == NULL || niduuid == NULL)
+ rc = mgc_niduuid_create(&niduuid, nidstr);
+ if (rc || mgcname == NULL)
GOTO(out_free, rc = -ENOMEM);
+
snprintf(mgcname, len, "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
/* Add the primary NIDs for the MGS */
i = 0;
- snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
+ niduuid_suffix = niduuid + strlen(niduuid);
+ snprintf(niduuid_suffix, NIDUUID_SUFFIX_MAX_LEN, "_%x", i);
if (IS_SERVER(lsi)) {
ptr = lsi->lsi_lmd->lmd_mgs;
CDEBUG(D_MOUNT, "mgs NIDs %s.\n", ptr);
while (ptr && ((*ptr == ':' ||
class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
/* New failover node */
- sprintf(niduuid, "%s_%x", mgcname, i);
+ snprintf(niduuid_suffix, NIDUUID_SUFFIX_MAX_LEN, "_%x", i);
j = 0;
while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
if (!nid_is_nid4(&nid))
OBD_FREE_PTR(data);
if (mgcname)
OBD_FREE(mgcname, len);
- if (niduuid)
- OBD_FREE(niduuid, len + 2);
+ mgc_niduuid_destroy(&niduuid);
+
RETURN(rc);
}
EXPORT_SYMBOL(lustre_start_mgc);
{
struct lustre_sb_info *lsi = s2lsi(sb);
struct obd_device *obd;
- char niduuid[MAX_OBD_NAME + 6], *ptr = NULL;
+ char *niduuid = NULL, *niduuid_suffix;
+ char nidstr[LNET_NIDSTR_SIZE];
int i, rc = 0;
ENTRY;
RETURN(-ENOENT);
lsi->lsi_mgc = NULL;
+ /* Reconstruct the NID uuid from the obd_name */
+ strscpy(nidstr, &obd->obd_name[0] + strlen(LUSTRE_MGC_OBDNAME),
+ sizeof(nidstr));
+
+ rc = mgc_niduuid_create(&niduuid, nidstr);
+ if (rc)
+ RETURN(-ENOMEM);
+
+ niduuid_suffix = niduuid + strlen(niduuid);
+
mutex_lock(&mgc_start_lock);
LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
}
- /*
- * Cache the obdname for cleaning the nid uuids, which are
- * obdname_XX before calling class_manual_cleanup
- */
- strcpy(niduuid, obd->obd_name);
- ptr = niduuid + strlen(niduuid);
-
rc = class_manual_cleanup(obd);
if (rc)
GOTO(out, rc);
for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
- sprintf(ptr, "_%x", i);
+ snprintf(niduuid_suffix, NIDUUID_SUFFIX_MAX_LEN, "_%x", i);
rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
niduuid, NULL, NULL, NULL);
if (rc)
out:
/* class_import_put will get rid of the additional connections */
mutex_unlock(&mgc_start_lock);
+
+ mgc_niduuid_destroy(&niduuid);
+
RETURN(rc);
}
SERVER_ONLY_EXPORT_SYMBOL(lustre_stop_mgc);