Provide duplicates with separate buffers for libcfs_*2str() functions.
Replace libcfs_nid2str() with libcfs_nid2str_r() function in critical
places.
Provide buffer size for nf_addr2str functions.
Use __u32 as nf_type always
Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Change-Id: I7505271954745d1b1e288ef4e09a7f52bd970536
Reviewed-on: http://review.whamcloud.com/13185
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
}
static int libcfs_lo_str2addr(const char *str, int nob, __u32 *addr);
-static void libcfs_ip_addr2str(__u32 addr, char *str);
+static void libcfs_ip_addr2str(__u32 addr, char *str, size_t size);
static int libcfs_ip_str2addr(const char *str, int nob, __u32 *addr);
static bool cfs_ip_is_contiguous(struct list_head *nidlist);
static void cfs_ip_min_max(struct list_head *nidlist, __u32 *min, __u32 *max);
-static void libcfs_decnum_addr2str(__u32 addr, char *str);
-static void libcfs_hexnum_addr2str(__u32 addr, char *str);
+static void libcfs_decnum_addr2str(__u32 addr, char *str, size_t size);
+static void libcfs_hexnum_addr2str(__u32 addr, char *str, size_t size);
static int libcfs_num_str2addr(const char *str, int nob, __u32 *addr);
static int libcfs_num_parse(char *str, int len, struct list_head *list);
static int libcfs_num_match(__u32 addr, struct list_head *list);
static void cfs_num_min_max(struct list_head *nidlist, __u32 *min, __u32 *max);
struct netstrfns {
- int nf_type;
+ __u32 nf_type;
char *nf_name;
char *nf_modname;
- void (*nf_addr2str)(__u32 addr, char *str);
+ void (*nf_addr2str)(__u32 addr, char *str, size_t size);
int (*nf_str2addr)(const char *str, int nob, __u32 *addr);
int (*nf_parse_addrlist)(char *str, int len,
struct list_head *list);
{/* .nf_type */ -1},
};
-static const int libcfs_nnetstrfns =
+static const size_t libcfs_nnetstrfns =
sizeof(libcfs_netstrfns)/sizeof(libcfs_netstrfns[0]);
-static int
-libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
+static int libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
{
- *addr = 0;
- return 1;
+ *addr = 0;
+ return 1;
}
static void
-libcfs_ip_addr2str(__u32 addr, char *str)
+libcfs_ip_addr2str(__u32 addr, char *str, size_t size)
{
-#if 0 /* never lookup */
-#if !defined(__KERNEL__) && defined HAVE_GETHOSTBYNAME
- __u32 netip = htonl(addr);
- struct hostent *he = gethostbyaddr(&netip, sizeof(netip), AF_INET);
-
- if (he != NULL) {
- snprintf(str, LNET_NIDSTR_SIZE, "%s", he->h_name);
- return;
- }
-#endif
-#endif
- snprintf(str, LNET_NIDSTR_SIZE, "%u.%u.%u.%u",
- (addr >> 24) & 0xff, (addr >> 16) & 0xff,
- (addr >> 8) & 0xff, addr & 0xff);
+ snprintf(str, size, "%u.%u.%u.%u",
+ (addr >> 24) & 0xff, (addr >> 16) & 0xff,
+ (addr >> 8) & 0xff, addr & 0xff);
}
/* CAVEAT EMPTOR XscanfX
* fine, if it doesn't, then the scan ended at the end of the string, which is
* fine too :) */
-static int
-libcfs_ip_str2addr(const char *str, int nob, __u32 *addr)
+static int libcfs_ip_str2addr(const char *str, int nob, __u32 *addr)
{
unsigned int a;
unsigned int b;
}
static void
-libcfs_decnum_addr2str(__u32 addr, char *str)
+libcfs_decnum_addr2str(__u32 addr, char *str, size_t size)
{
- snprintf(str, LNET_NIDSTR_SIZE, "%u", addr);
+ snprintf(str, size, "%u", addr);
}
static void
-libcfs_hexnum_addr2str(__u32 addr, char *str)
+libcfs_hexnum_addr2str(__u32 addr, char *str, size_t size)
{
- snprintf(str, LNET_NIDSTR_SIZE, "0x%x", addr);
+ snprintf(str, size, "0x%x", addr);
}
static int
}
static struct netstrfns *
-libcfs_lnd2netstrfns(int lnd)
+libcfs_lnd2netstrfns(__u32 lnd)
{
- int i;
+ __u32 i;
- if (lnd >= 0)
- for (i = 0; i < libcfs_nnetstrfns; i++)
- if (lnd == libcfs_netstrfns[i].nf_type)
- return &libcfs_netstrfns[i];
+ for (i = 0; i < libcfs_nnetstrfns; i++)
+ if (lnd == libcfs_netstrfns[i].nf_type)
+ return &libcfs_netstrfns[i];
- return NULL;
+ return NULL;
}
static struct netstrfns *
return NULL;
}
-int
-libcfs_isknown_lnd(int type)
-{
- return libcfs_lnd2netstrfns(type) != NULL;
-}
-
-char *
-libcfs_lnd2modname(int lnd)
+int libcfs_isknown_lnd(__u32 lnd)
{
- struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
-
- return (nf == NULL) ? NULL : nf->nf_modname;
+ return libcfs_lnd2netstrfns(lnd) != NULL;
}
-char *
-libcfs_lnd2str(int lnd)
+char *libcfs_lnd2modname(__u32 lnd)
{
- char *str;
- struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
+ struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
- if (nf != NULL)
- return nf->nf_name;
-
- str = libcfs_next_nidstring();
- snprintf(str, LNET_NIDSTR_SIZE, "?%u?", lnd);
- return str;
+ return (nf == NULL) ? NULL : nf->nf_modname;
}
int
return -1;
}
-char *
-libcfs_net2str(__u32 net)
+char *libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size)
{
- int lnd = LNET_NETTYP(net);
- int num = LNET_NETNUM(net);
- struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
- char *str = libcfs_next_nidstring();
+ struct netstrfns *nf;
- if (nf == NULL)
- snprintf(str, LNET_NIDSTR_SIZE, "<%u:%u>", lnd, num);
- else if (num == 0)
- snprintf(str, LNET_NIDSTR_SIZE, "%s", nf->nf_name);
- else
- snprintf(str, LNET_NIDSTR_SIZE, "%s%u", nf->nf_name, num);
+ nf = libcfs_lnd2netstrfns(lnd);
+ if (nf == NULL)
+ snprintf(buf, buf_size, "?%u?", lnd);
+ else
+ snprintf(buf, buf_size, "%s", nf->nf_name);
- return str;
+ return buf;
}
-char *
-libcfs_nid2str(lnet_nid_t nid)
+char *libcfs_net2str_r(__u32 net, char *buf, size_t buf_size)
{
- __u32 addr = LNET_NIDADDR(nid);
- __u32 net = LNET_NIDNET(nid);
- int lnd = LNET_NETTYP(net);
- int nnum = LNET_NETNUM(net);
- struct netstrfns *nf;
- char *str;
- int nob;
+ __u32 nnum = LNET_NETNUM(net);
+ __u32 lnd = LNET_NETTYP(net);
+ struct netstrfns *nf;
- if (nid == LNET_NID_ANY)
- return "<?>";
+ nf = libcfs_lnd2netstrfns(lnd);
+ if (nf == NULL)
+ snprintf(buf, buf_size, "<%u:%u>", lnd, nnum);
+ else if (nnum == 0)
+ snprintf(buf, buf_size, "%s", nf->nf_name);
+ else
+ snprintf(buf, buf_size, "%s%u", nf->nf_name, nnum);
- nf = libcfs_lnd2netstrfns(lnd);
- str = libcfs_next_nidstring();
+ return buf;
+}
- if (nf == NULL)
- snprintf(str, LNET_NIDSTR_SIZE, "%x@<%u:%u>", addr, lnd, nnum);
- else {
- nf->nf_addr2str(addr, str);
- nob = strlen(str);
- if (nnum == 0)
- snprintf(str + nob, LNET_NIDSTR_SIZE - nob, "@%s",
- nf->nf_name);
- else
- snprintf(str + nob, LNET_NIDSTR_SIZE - nob, "@%s%u",
- nf->nf_name, nnum);
- }
+char *libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size)
+{
+ __u32 addr = LNET_NIDADDR(nid);
+ __u32 net = LNET_NIDNET(nid);
+ __u32 nnum = LNET_NETNUM(net);
+ __u32 lnd = LNET_NETTYP(net);
+ struct netstrfns *nf;
+
+ if (nid == LNET_NID_ANY) {
+ strncpy(buf, "<?>", buf_size);
+ buf[buf_size - 1] = '\0';
+ return buf;
+ }
- return str;
+ nf = libcfs_lnd2netstrfns(lnd);
+ if (nf == NULL) {
+ snprintf(buf, buf_size, "%x@<%u:%u>", addr, lnd, nnum);
+ } else {
+ size_t addr_len;
+
+ nf->nf_addr2str(addr, buf, buf_size);
+ addr_len = strlen(buf);
+ if (nnum == 0)
+ snprintf(buf + addr_len, buf_size - addr_len, "@%s",
+ nf->nf_name);
+ else
+ snprintf(buf + addr_len, buf_size - addr_len, "@%s%u",
+ nf->nf_name, nnum);
+ }
+
+ return buf;
+}
+
+char *libcfs_lnd2str(__u32 lnd)
+{
+ return libcfs_lnd2str_r(lnd, libcfs_next_nidstring(),
+ LNET_NIDSTR_SIZE);
+}
+
+char *libcfs_net2str(__u32 net)
+{
+ return libcfs_net2str_r(net, libcfs_next_nidstring(),
+ LNET_NIDSTR_SIZE);
+}
+
+char *libcfs_nid2str(lnet_nid_t nid)
+{
+ return libcfs_nid2str_r(nid, libcfs_next_nidstring(),
+ LNET_NIDSTR_SIZE);
}
static struct netstrfns *
* \param *max_nid
*/
void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
- char *max_nid, int nidstr_length)
+ char *max_nid, size_t nidstr_length)
{
struct nidrange *nr;
struct netstrfns *nf = NULL;
nf->nf_min_max(nidlist, &min_addr, &max_addr);
}
- nf->nf_addr2str(min_addr, min_addr_str);
- nf->nf_addr2str(max_addr, max_addr_str);
+ nf->nf_addr2str(min_addr, min_addr_str, sizeof(min_addr_str));
+ nf->nf_addr2str(max_addr, max_addr_str, sizeof(max_addr_str));
snprintf(min_nid, nidstr_length, "%s@%s%d", min_addr_str, lndname,
netnum);
EXPORT_SYMBOL(libcfs_isknown_lnd);
EXPORT_SYMBOL(libcfs_lnd2modname);
EXPORT_SYMBOL(libcfs_lnd2str);
+EXPORT_SYMBOL(libcfs_lnd2str_r);
EXPORT_SYMBOL(libcfs_str2lnd);
EXPORT_SYMBOL(libcfs_net2str);
+EXPORT_SYMBOL(libcfs_net2str_r);
EXPORT_SYMBOL(libcfs_nid2str);
+EXPORT_SYMBOL(libcfs_nid2str_r);
EXPORT_SYMBOL(libcfs_str2net);
EXPORT_SYMBOL(libcfs_str2nid);
EXPORT_SYMBOL(libcfs_id2str);
struct list_head lnd_list; /* stash in the LND table */
int lnd_refcount; /* # active instances */
- /* fields initialised by the LND */
- unsigned int lnd_type;
+ /* fields initialized by the LND */
+ __u32 lnd_type;
int (*lnd_startup) (struct lnet_ni *ni);
void (*lnd_shutdown) (struct lnet_ni *ni);
#define LNET_NIDSTR_SIZE 32 /* size of each one (see below for usage) */
/* support decl needed both by kernel and liblustre */
-int libcfs_isknown_lnd(int type);
-char *libcfs_lnd2modname(int type);
-char *libcfs_lnd2str(int type);
+int libcfs_isknown_lnd(__u32 lnd);
+char *libcfs_lnd2modname(__u32 lnd);
+char *libcfs_lnd2str(__u32 lnd);
+char *libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size);
int libcfs_str2lnd(const char *str);
char *libcfs_net2str(__u32 net);
+char *libcfs_net2str_r(__u32 net, char *buf, size_t buf_size);
char *libcfs_nid2str(lnet_nid_t nid);
+char *libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size);
__u32 libcfs_str2net(const char *str);
lnet_nid_t libcfs_str2nid(const char *str);
int libcfs_str2anynid(lnet_nid_t *nid, const char *str);
int cfs_match_nid(lnet_nid_t nid, struct list_head *list);
bool cfs_nidrange_is_contiguous(struct list_head *nidlist);
void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
- char *max_nid, int nidstr_length);
+ char *max_nid, size_t nidstr_length);
void libcfs_init_nidstrings(void);
#endif /* _LNET_NIDSTRINGS_H */
CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.type) == 4);
}
-static lnd_t *
-lnet_find_lnd_by_type (int type)
+static lnd_t *lnet_find_lnd_by_type(__u32 type)
{
lnd_t *lnd;
struct list_head *tmp;
list_for_each(tmp, &the_lnet.ln_lnds) {
lnd = list_entry(tmp, lnd_t, lnd_list);
- if ((int)lnd->lnd_type == type)
+ if (lnd->lnd_type == type)
return lnd;
}
return NULL;
__s32 peer_cr, __s32 peer_buf_cr, __s32 credits)
{
int rc = -EINVAL;
- int lnd_type;
+ __u32 lnd_type;
lnd_t *lnd;
struct lnet_tx_queue *tq;
int i;
static void lnet_shuffle_seed(void)
{
- static int seeded = 0;
- int lnd_type, seed[2];
- struct timeval tv;
- lnet_ni_t *ni;
+ static int seeded;
+ __u32 lnd_type;
+ __u32 seed[2];
+ struct timeval tv;
+ lnet_ni_t *ni;
struct list_head *tmp;
if (seeded)
struct sptlrpc_rule *r;
char dirbuf[10];
char flvrbuf[40];
- char *net;
+ char net[LNET_NIDSTR_SIZE] = "default";
int i;
for (i = 0; i < rset->srs_nrule; i++) {
r = &rset->srs_rules[i];
- if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
- net = "default";
- else
- net = libcfs_net2str(r->sr_netid);
+ if (r->sr_netid != LNET_NIDNET(LNET_NID_ANY))
+ libcfs_net2str_r(r->sr_netid, net, sizeof(net));
if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
dirbuf[0] = '\0';
RETURN(rc);
if (lcfg->lcfg_command == LCFG_ADD_UUID) {
- uint64_t nodenid = lcfg->lcfg_nid;
+ __u64 nodenid = lcfg->lcfg_nid;
if (strlen(tmti->mti_uuid) == 0) {
/* target uuid not set, this config record is before
tmti->mti_nids[tmti->mti_nid_count] = nodenid;
tmti->mti_nid_count++;
} else {
+ char nidstr[LNET_NIDSTR_SIZE];
+
/* failover node nid */
+ libcfs_nid2str_r(nodenid, nidstr, sizeof(nidstr));
rc = add_param(tmti->mti_params, PARAM_FAILNODE,
- libcfs_nid2str(nodenid));
+ nidstr);
}
RETURN(rc);
*/
while (class_find_param(ptr, PARAM_FAILNODE, &ptr) == 0) {
while (class_parse_nid(ptr, &nid, &ptr) == 0) {
- if (failnodeuuid == NULL) {
- /* We don't know the failover node name,
- so just use the first nid as the uuid */
- rc = name_create(&failnodeuuid,
- libcfs_nid2str(nid), "");
- if (rc)
- return rc;
- }
- CDEBUG(D_MGS, "add nid %s for failover uuid %s, "
- "client %s\n", libcfs_nid2str(nid),
- failnodeuuid, cliname);
+ char nidstr[LNET_NIDSTR_SIZE];
+
+ if (failnodeuuid == NULL) {
+ /* We don't know the failover node name,
+ * so just use the first nid as the uuid */
+ libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
+ rc = name_create(&failnodeuuid, nidstr, "");
+ if (rc != 0)
+ return rc;
+ }
+ CDEBUG(D_MGS, "add nid %s for failover uuid %s, "
+ "client %s\n",
+ libcfs_nid2str_r(nid, nidstr, sizeof(nidstr)),
+ failnodeuuid, cliname);
rc = record_add_uuid(env, llh, nid, failnodeuuid);
/*
* If *ptr is ':', we have added all NIDs for
char *nodeuuid = NULL;
char *mdcuuid = NULL;
char *lmvuuid = NULL;
- char index[6];
- int i, rc;
- ENTRY;
+ char index[6];
+ char nidstr[LNET_NIDSTR_SIZE];
+ int i, rc;
+ ENTRY;
if (mgs_log_is_empty(env, mgs, logname)) {
CERROR("log is empty! Logical error\n");
CDEBUG(D_MGS, "adding mdc for %s to log %s:lmv(%s)\n",
mti->mti_svname, logname, lmvname);
- rc = name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
+ libcfs_nid2str_r(mti->mti_nids[0], nidstr, sizeof(nidstr));
+ rc = name_create(&nodeuuid, nidstr, "");
if (rc)
RETURN(rc);
rc = name_create(&mdcname, mti->mti_svname, "-mdc");
"add mdc");
if (rc)
GOTO(out_end, rc);
- for (i = 0; i < mti->mti_nid_count; i++) {
- CDEBUG(D_MGS, "add nid %s for mdt\n",
- libcfs_nid2str(mti->mti_nids[i]));
+ for (i = 0; i < mti->mti_nid_count; i++) {
+ CDEBUG(D_MGS, "add nid %s for mdt\n",
+ libcfs_nid2str_r(mti->mti_nids[i],
+ nidstr, sizeof(nidstr)));
rc = record_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);
if (rc)
GOTO(out_end, rc);
- }
+ }
rc = record_attach(env, llh, mdcname, LUSTRE_MDC_NAME, lmvuuid);
if (rc)
char *mdtname = NULL;
char *lovname = NULL;
char index_str[16];
+ char nidstr[LNET_NIDSTR_SIZE];
int i, rc;
ENTRY;
if (rc)
RETURN(rc);
- rc = name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
+ libcfs_nid2str_r(mti->mti_nids[0], nidstr, sizeof(nidstr));
+ rc = name_create(&nodeuuid, nidstr, "");
if (rc)
GOTO(out_destory, rc);
for (i = 0; i < mti->mti_nid_count; i++) {
CDEBUG(D_MGS, "add nid %s for mdt\n",
- libcfs_nid2str(mti->mti_nids[i]));
+ libcfs_nid2str_r(mti->mti_nids[i],
+ nidstr, sizeof(nidstr)));
rc = record_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);
if (rc)
GOTO(out_end, rc);
- }
+ }
rc = record_attach(env, llh, ospname, LUSTRE_OSP_NAME, lovuuid);
if (rc)
char *logname, char *suffix, char *lovname,
enum lustre_sec_part sec_part, int flags)
{
- struct llog_handle *llh = NULL;
+ struct llog_handle *llh = NULL;
char *nodeuuid = NULL;
char *oscname = NULL;
char *oscuuid = NULL;
char *lovuuid = NULL;
char *svname = NULL;
- char index[6];
- int i, rc;
+ char index[6];
+ char nidstr[LNET_NIDSTR_SIZE];
+ int i, rc;
+ ENTRY;
- ENTRY;
- CDEBUG(D_INFO, "adding osc for %s to log %s\n",
- mti->mti_svname, logname);
+ CDEBUG(D_INFO, "adding osc for %s to log %s\n",
+ mti->mti_svname, logname);
if (mgs_log_is_empty(env, mgs, logname)) {
- CERROR("log is empty! Logical error\n");
- RETURN (-EINVAL);
- }
+ CERROR("log is empty! Logical error\n");
+ RETURN(-EINVAL);
+ }
- rc = name_create(&nodeuuid, libcfs_nid2str(mti->mti_nids[0]), "");
+ libcfs_nid2str_r(mti->mti_nids[0], nidstr, sizeof(nidstr));
+ rc = name_create(&nodeuuid, nidstr, "");
if (rc)
RETURN(rc);
rc = name_create(&svname, mti->mti_svname, "-osc");
* (multiple interfaces), while nids after as failover node nids.
* See mgs_steal_client_llog_handler() LCFG_ADD_UUID.
*/
- for (i = 0; i < mti->mti_nid_count; i++) {
- CDEBUG(D_MGS, "add nid %s\n", libcfs_nid2str(mti->mti_nids[i]));
+ for (i = 0; i < mti->mti_nid_count; i++) {
+ CDEBUG(D_MGS, "add nid %s\n",
+ libcfs_nid2str_r(mti->mti_nids[i],
+ nidstr, sizeof(nidstr)));
rc = record_add_uuid(env, llh, mti->mti_nids[i], nodeuuid);
if (rc)
GOTO(out_end, rc);
- }
+ }
rc = record_attach(env, llh, oscname, LUSTRE_OSC_NAME, lovuuid);
if (rc)
GOTO(out_end, rc);
int lprocfs_import_seq_show(struct seq_file *m, void *data)
{
+ char nidstr[LNET_NIDSTR_SIZE];
struct lprocfs_counter ret;
struct lprocfs_counter_header *header;
struct obd_device *obd = (struct obd_device *)data;
spin_lock(&imp->imp_lock);
j = 0;
list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
- seq_printf(m, "%s%s", j ? ", " : "",
- libcfs_nid2str(conn->oic_conn->c_peer.nid));
+ libcfs_nid2str_r(conn->oic_conn->c_peer.nid,
+ nidstr, sizeof(nidstr));
+ seq_printf(m, "%s%s", j ? ", " : "", nidstr);
j++;
}
+ libcfs_nid2str_r(imp->imp_connection->c_peer.nid,
+ nidstr, sizeof(nidstr));
seq_printf(m, " ]\n"
" current_connection: %s\n"
" connection_attempts: %u\n"
" generation: %u\n"
" in-progress_invalidations: %u\n",
- imp->imp_connection == NULL ? "<none>" :
- libcfs_nid2str(imp->imp_connection->c_peer.nid),
+ imp->imp_connection == NULL ? "<none>" : nidstr,
imp->imp_conn_cnt,
imp->imp_generation,
atomic_read(&imp->imp_inval_count));
}
EXPORT_SYMBOL(lprocfs_free_per_client_stats);
-int lprocfs_exp_nid_seq_show(struct seq_file *m, void *data)
-{
- struct obd_export *exp = m->private;
- LASSERT(exp != NULL);
- return seq_printf(m, "%s\n", obd_export_nid2str(exp));
-}
-
static int lprocfs_exp_print_uuid_seq(cfs_hash_t *hs, cfs_hash_bd_t *bd,
struct hlist_node *hnode, void *cb_data)
-
{
struct seq_file *m = cb_data;
struct obd_export *exp = cfs_hash_object(hs, hnode);
struct nid_stat *new_stat, *old_stat;
struct obd_device *obd = NULL;
struct proc_dir_entry *entry;
- char *buffer = NULL;
+ char nidstr[LNET_NIDSTR_SIZE];
int rc = 0;
ENTRY;
if (nid == NULL || *nid == LNET_NID_ANY)
RETURN(-EALREADY);
+ libcfs_nid2str_r(*nid, nidstr, sizeof(nidstr));
+
spin_lock(&exp->exp_lock);
if (exp->exp_nid_stats != NULL) {
spin_unlock(&exp->exp_lock);
old_stat = cfs_hash_findadd_unique(obd->obd_nid_stats_hash,
nid, &new_stat->nid_hash);
CDEBUG(D_INFO, "Found stats %p for nid %s - ref %d\n",
- old_stat, libcfs_nid2str(*nid),
- atomic_read(&new_stat->nid_exp_ref_count));
+ old_stat, nidstr, atomic_read(&old_stat->nid_exp_ref_count));
/* Return -EALREADY here so that we know that the /proc
* entry already has been created */
GOTO(destroy_new, rc = -EALREADY);
}
/* not found - create */
- OBD_ALLOC(buffer, LNET_NIDSTR_SIZE);
- if (buffer == NULL)
- GOTO(destroy_new, rc = -ENOMEM);
-
- memcpy(buffer, libcfs_nid2str(*nid), LNET_NIDSTR_SIZE);
- new_stat->nid_proc = lprocfs_register(buffer,
+ new_stat->nid_proc = lprocfs_register(nidstr,
obd->obd_proc_exports_entry,
NULL, NULL);
- OBD_FREE(buffer, LNET_NIDSTR_SIZE);
if (IS_ERR(new_stat->nid_proc)) {
rc = PTR_ERR(new_stat->nid_proc);
new_stat->nid_proc = NULL;
CERROR("%s: cannot create proc entry for export %s: rc = %d\n",
- obd->obd_name, libcfs_nid2str(*nid), rc);
+ obd->obd_name, nidstr, rc);
GOTO(destroy_new_ns, rc);
}
if (lcfg->lcfg_num)
ptr += snprintf(ptr, end - ptr, ", num: %#08x",
lcfg->lcfg_num);
- if (lcfg->lcfg_nid)
+ if (lcfg->lcfg_nid) {
+ char nidstr[LNET_NIDSTR_SIZE];
+
+ libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
ptr += snprintf(ptr, end - ptr, ", nid: %s("LPX64")",
- libcfs_nid2str(lcfg->lcfg_nid),
- lcfg->lcfg_nid);
+ nidstr, lcfg->lcfg_nid);
+ }
if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0)
ptr += snprintf(ptr, end - ptr, ", device: %s",
if (lcfg->lcfg_num)
ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
- if (lcfg->lcfg_nid)
+ if (lcfg->lcfg_nid) {
+ char nidstr[LNET_NIDSTR_SIZE];
+
+ libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n ",
- libcfs_nid2str(lcfg->lcfg_nid),
- lcfg->lcfg_nid);
+ nidstr, lcfg->lcfg_nid);
+ }
if (lcfg->lcfg_command == LCFG_MARKER) {
struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
struct obd_uuid *uuid;
class_uuid_t uuidc;
lnet_nid_t nid;
+ char nidstr[LNET_NIDSTR_SIZE];
char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
char *ptr;
- int rc = 0, i = 0, j, len;
- ENTRY;
+ int rc = 0, i = 0, j;
+ size_t len;
+ ENTRY;
- LASSERT(lsi->lsi_lmd);
+ LASSERT(lsi->lsi_lmd);
- /* Find the first non-lo MGS nid for our MGC name */
+ /* Find the first non-lo MGS nid for our MGC name */
if (IS_SERVER(lsi)) {
/* mount -o mgsnode=nid */
ptr = lsi->lsi_lmd->lmd_mgs;
mutex_lock(&mgc_start_lock);
- len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
- OBD_ALLOC(mgcname, len);
- OBD_ALLOC(niduuid, len + 2);
- if (!mgcname || !niduuid)
- GOTO(out_free, rc = -ENOMEM);
- sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
+ libcfs_nid2str_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)
+ 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;
- sprintf(niduuid, "%s_%x", mgcname, i);
+ snprintf(niduuid, len + 2, "%s_%x", mgcname, i);
if (IS_SERVER(lsi)) {
ptr = lsi->lsi_lmd->lmd_mgs;
CDEBUG(D_MOUNT, "mgs nids %s.\n", ptr);
if (body->oa.o_valid & OBD_MD_FLCKSUM) {
static int cksum_counter;
u32 server_cksum = body->oa.o_cksum;
- char *via;
- char *router;
+ char *via = "";
+ char *router = "";
cksum_type_t cksum_type;
cksum_type = cksum_type_unpack(body->oa.o_valid &OBD_MD_FLFLAGS?
aa->aa_ppga, OST_READ,
cksum_type);
- if (peer->nid == req->rq_bulk->bd_sender) {
- via = router = "";
- } else {
- via = " via ";
- router = libcfs_nid2str(req->rq_bulk->bd_sender);
- }
+ if (peer->nid != req->rq_bulk->bd_sender) {
+ via = " via ";
+ router = libcfs_nid2str(req->rq_bulk->bd_sender);
+ }
if (server_cksum != client_cksum) {
LCONSOLE_ERROR_MSG(0x133, "%s: BAD READ CHECKSUM: from "
rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, srhi->srhi_seq);
- if (rc == 0) {
- req = srhi->srhi_req;
-
- /* Print common req fields.
- * CAVEAT EMPTOR: we're racing with the service handler
- * here. The request could contain any old crap, so you
- * must be just as careful as the service's request
- * parser. Currently I only print stuff here I know is OK
- * to look at coz it was set up in request_in_callback()!!! */
- seq_printf(s, LPD64":%s:%s:x"LPU64":%d:%s:%ld:%lds(%+lds) ",
- req->rq_history_seq, libcfs_nid2str(req->rq_self),
- libcfs_id2str(req->rq_peer), req->rq_xid,
- req->rq_reqlen, ptlrpc_rqphase2str(req),
- req->rq_arrival_time.tv_sec,
- req->rq_sent - req->rq_arrival_time.tv_sec,
- req->rq_sent - req->rq_deadline);
+ if (rc == 0) {
+ char nidstr[LNET_NIDSTR_SIZE];
+
+ req = srhi->srhi_req;
+
+ libcfs_nid2str_r(req->rq_self, nidstr, sizeof(nidstr));
+ /* Print common req fields.
+ * CAVEAT EMPTOR: we're racing with the service handler
+ * here. The request could contain any old crap, so you
+ * must be just as careful as the service's request
+ * parser. Currently I only print stuff here I know is OK
+ * to look at coz it was set up in request_in_callback()!!! */
+ seq_printf(s, LPD64":%s:%s:x"LPU64":%d:%s:%ld:%lds(%+lds) ",
+ req->rq_history_seq, nidstr,
+ libcfs_id2str(req->rq_peer), req->rq_xid,
+ req->rq_reqlen, ptlrpc_rqphase2str(req),
+ req->rq_arrival_time.tv_sec,
+ req->rq_sent - req->rq_arrival_time.tv_sec,
+ req->rq_sent - req->rq_deadline);
if (svc->srv_ops.so_req_printer == NULL)
seq_printf(s, "\n");
else
svc->srv_ops.so_req_printer(s, srhi->srhi_req);
- }
+ }
spin_unlock(&svcpt->scp_lock);
return rc;
struct lu_nodemap *nodemap = m->private;
struct lu_nid_range *range;
struct interval_node_extent ext;
+ char start_nidstr[LNET_NIDSTR_SIZE];
+ char end_nidstr[LNET_NIDSTR_SIZE];
bool cont = false;
seq_printf(m, "[\n");
seq_printf(m, ",\n");
cont = 1;
ext = range->rn_node.in_extent;
- seq_printf(m, " { id: %u, start_nid: %s, "
- "end_nid: %s }",
- range->rn_id, libcfs_nid2str(ext.start),
- libcfs_nid2str(ext.end));
+ libcfs_nid2str_r(ext.start, start_nidstr, sizeof(start_nidstr));
+ libcfs_nid2str_r(ext.end, end_nidstr, sizeof(end_nidstr));
+ seq_printf(m, " { id: %u, start_nid: %s, end_nid: %s }",
+ range->rn_id, start_nidstr, end_nidstr);
}
read_unlock(&nm_range_tree_lock);
seq_printf(m, "\n");
{
struct seq_file *m = data;
struct obd_export *exp;
- char *key;
+ char nidstr[LNET_NIDSTR_SIZE] = "<unknown>";
exp = hlist_entry(hnode, struct obd_export,
exp_target_data.ted_nodemap_member);
- key = cfs_hash_key(hs, hnode);
+ if (exp->exp_connection != NULL)
+ libcfs_nid2str_r(exp->exp_connection->c_peer.nid,
+ nidstr, sizeof(nidstr));
+
seq_printf(m, " { nid: %s, uuid: %s },",
- obd_export_nid2str(exp), exp->exp_client_uuid.uuid);
+ nidstr, exp->exp_client_uuid.uuid);
return 0;
}
*/
static int nodemap_exports_show(struct seq_file *m, void *data)
{
- struct lu_nodemap *nodemap = m->private;
+ struct lu_nodemap *nodemap = m->private;
seq_printf(m, "[\n");
static void rule2string(struct sptlrpc_rule *r, char *buf, int buflen)
{
- char dirbuf[8];
- char *net;
- char *ptr = buf;
+ char dirbuf[8];
+ char net[LNET_NIDSTR_SIZE] = "default";
+ char *ptr = buf;
- if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
- net = "default";
- else
- net = libcfs_net2str(r->sr_netid);
+ if (r->sr_netid != LNET_NIDNET(LNET_NID_ANY))
+ libcfs_net2str_r(r->sr_netid, net, sizeof(net));
if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
dirbuf[0] = '\0';
static int tgt_init_sec_level(struct ptlrpc_request *req)
{
struct lu_target *tgt = class_exp2tgt(req->rq_export);
- char *client = libcfs_nid2str(req->rq_peer.nid);
+ char *client;
struct obd_connect_data *data, *reply;
int rc = 0;
bool remote;
-
ENTRY;
data = req_capsule_client_get(&req->rq_pill, &RMF_CONNECT_DATA);
RETURN(0);
}
+ client = libcfs_nid2str(req->rq_peer.nid);
/* no GSS support case */
if (!req->rq_auth_gss) {
if (tgt->lut_sec_level > LUSTRE_SEC_NONE) {
{
struct obd_export *exp = req->rq_export;
struct ost_body *body;
- char *router;
- char *via;
+ char *router = "";
+ char *via = "";
body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
LASSERT(body != NULL);
- if (req->rq_peer.nid == desc->bd_sender) {
- via = router = "";
- } else {
+ if (req->rq_peer.nid != desc->bd_sender) {
via = " via ";
router = libcfs_nid2str(desc->bd_sender);
}