From: Dmitry Eremin Date: Thu, 25 Dec 2014 12:12:02 +0000 (+0300) Subject: LU-6070 libcfs: provide separate buffers for libcfs_*2str() X-Git-Tag: 2.7.51~74 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=907a321c9b9e2cd5f5ccf488cc516ba05dee0ad8 LU-6070 libcfs: provide separate buffers for libcfs_*2str() 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 Change-Id: I7505271954745d1b1e288ef4e09a7f52bd970536 Reviewed-on: http://review.whamcloud.com/13185 Tested-by: Jenkins Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/libcfs/libcfs/nidstrings.c b/libcfs/libcfs/nidstrings.c index b11cc9c..73bd389 100644 --- a/libcfs/libcfs/nidstrings.c +++ b/libcfs/libcfs/nidstrings.c @@ -101,12 +101,12 @@ libcfs_next_nidstring (void) } 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); @@ -118,10 +118,10 @@ static bool cfs_num_is_contiguous(struct list_head *nidlist); 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); @@ -278,33 +278,21 @@ static struct netstrfns libcfs_netstrfns[] = { {/* .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 @@ -314,8 +302,7 @@ libcfs_ip_addr2str(__u32 addr, char *str) * 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; @@ -362,15 +349,15 @@ libcfs_ip_str2addr(const char *str, int nob, __u32 *addr) } 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 @@ -394,16 +381,15 @@ libcfs_num_str2addr(const char *str, int nob, __u32 *addr) } 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 * @@ -434,32 +420,16 @@ libcfs_name2netstrfns(const char *name) 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 @@ -473,55 +443,85 @@ libcfs_str2lnd(const char *str) 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 * @@ -1282,7 +1282,7 @@ static bool cfs_ip_is_contiguous(struct list_head *nidlist) * \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; @@ -1301,8 +1301,8 @@ void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid, 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); @@ -1382,9 +1382,12 @@ static void cfs_ip_min_max(struct list_head *nidlist, __u32 *min_nid, 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); diff --git a/lnet/include/lnet/lib-types.h b/lnet/include/lnet/lib-types.h index 65900fe..093a8c9 100644 --- a/lnet/include/lnet/lib-types.h +++ b/lnet/include/lnet/lib-types.h @@ -310,8 +310,8 @@ typedef struct lnet_lnd 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); diff --git a/lnet/include/lnet/nidstr.h b/lnet/include/lnet/nidstr.h index cf2efbe..b9e398e 100644 --- a/lnet/include/lnet/nidstr.h +++ b/lnet/include/lnet/nidstr.h @@ -35,12 +35,15 @@ struct list_head; #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); @@ -51,7 +54,7 @@ int cfs_print_nidlist(char *buffer, int count, struct list_head *list); 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 */ diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 780647c..99a1af7 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -273,8 +273,7 @@ static void lnet_assert_wire_constants(void) 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; @@ -283,7 +282,7 @@ lnet_find_lnd_by_type (int type) 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; @@ -1222,7 +1221,7 @@ lnet_startup_lndni(struct lnet_ni *ni, __s32 peer_timeout, __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; diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index 38dae7a..b53545b 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -237,10 +237,11 @@ lnet_find_net_locked (__u32 net) 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) diff --git a/lustre/mgs/lproc_mgs.c b/lustre/mgs/lproc_mgs.c index 8ae52ea..2e4adf4 100644 --- a/lustre/mgs/lproc_mgs.c +++ b/lustre/mgs/lproc_mgs.c @@ -90,16 +90,14 @@ static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname, 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'; diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 361aaa6..5ce98a6 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -1642,7 +1642,7 @@ static int mgs_steal_client_llog_handler(const struct lu_env *env, 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 @@ -1651,9 +1651,12 @@ static int mgs_steal_client_llog_handler(const struct lu_env *env, 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); @@ -1899,17 +1902,20 @@ static int mgs_write_log_failnids(const struct lu_env *env, */ 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 @@ -1943,9 +1949,10 @@ static int mgs_write_log_mdc_to_lmv(const struct lu_env *env, 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"); @@ -1955,7 +1962,8 @@ static int mgs_write_log_mdc_to_lmv(const struct lu_env *env, 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"); @@ -1975,14 +1983,15 @@ static int mgs_write_log_mdc_to_lmv(const struct lu_env *env, "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) @@ -2071,6 +2080,7 @@ static int mgs_write_log_osp_to_mdt(const struct lu_env *env, char *mdtname = NULL; char *lovname = NULL; char index_str[16]; + char nidstr[LNET_NIDSTR_SIZE]; int i, rc; ENTRY; @@ -2086,7 +2096,8 @@ static int mgs_write_log_osp_to_mdt(const struct lu_env *env, 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); @@ -2122,11 +2133,12 @@ static int mgs_write_log_osp_to_mdt(const struct lu_env *env, 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) @@ -2344,25 +2356,27 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env, 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"); @@ -2413,12 +2427,14 @@ static int mgs_write_log_osc_to_lov(const struct lu_env *env, * (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); diff --git a/lustre/obdclass/lprocfs_status.c b/lustre/obdclass/lprocfs_status.c index fe49186..ba82789 100644 --- a/lustre/obdclass/lprocfs_status.c +++ b/lustre/obdclass/lprocfs_status.c @@ -744,6 +744,7 @@ static void obd_connect_data_seqprint(struct seq_file *m, 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; @@ -780,17 +781,19 @@ int lprocfs_import_seq_show(struct seq_file *m, void *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 ? "" : - libcfs_nid2str(imp->imp_connection->c_peer.nid), + imp->imp_connection == NULL ? "" : nidstr, imp->imp_conn_cnt, imp->imp_generation, atomic_read(&imp->imp_inval_count)); diff --git a/lustre/obdclass/lprocfs_status_server.c b/lustre/obdclass/lprocfs_status_server.c index 76b1b99..290e4e5 100644 --- a/lustre/obdclass/lprocfs_status_server.c +++ b/lustre/obdclass/lprocfs_status_server.c @@ -154,16 +154,8 @@ void lprocfs_free_per_client_stats(struct obd_device *obd) } 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); @@ -287,7 +279,7 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid) 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; @@ -301,6 +293,8 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid) 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); @@ -324,8 +318,7 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid) 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 */ @@ -340,21 +333,15 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid) 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); } diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 610244f..b386331 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -1733,10 +1733,13 @@ int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size) 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", @@ -1782,10 +1785,13 @@ static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size) 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); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 7d2e7f1..6e2e116 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -223,14 +223,16 @@ int lustre_start_mgc(struct super_block *sb) 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; @@ -260,12 +262,13 @@ int lustre_start_mgc(struct super_block *sb) 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 : ""; @@ -337,7 +340,7 @@ int lustre_start_mgc(struct super_block *sb) /* 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); diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 75d1290..e60a1b0 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -1453,8 +1453,8 @@ static int osc_brw_fini_request(struct ptlrpc_request *req, int rc) 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? @@ -1463,12 +1463,10 @@ static int osc_brw_fini_request(struct ptlrpc_request *req, int rc) 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 " diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index 6764351..a86b460 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -942,27 +942,30 @@ static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter) 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; diff --git a/lustre/ptlrpc/nodemap_lproc.c b/lustre/ptlrpc/nodemap_lproc.c index 9f3b742..43c38f8 100644 --- a/lustre/ptlrpc/nodemap_lproc.c +++ b/lustre/ptlrpc/nodemap_lproc.c @@ -113,6 +113,8 @@ static int nodemap_ranges_show(struct seq_file *m, void *data) 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"); @@ -122,10 +124,10 @@ static int nodemap_ranges_show(struct seq_file *m, void *data) 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"); @@ -162,13 +164,16 @@ static int nodemap_exports_show_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd, { struct seq_file *m = data; struct obd_export *exp; - char *key; + char nidstr[LNET_NIDSTR_SIZE] = ""; 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; } @@ -183,7 +188,7 @@ static int nodemap_exports_show_cb(cfs_hash_t *hs, cfs_hash_bd_t *bd, */ 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"); diff --git a/lustre/ptlrpc/sec_config.c b/lustre/ptlrpc/sec_config.c index 08576ca..6812d82 100644 --- a/lustre/ptlrpc/sec_config.c +++ b/lustre/ptlrpc/sec_config.c @@ -931,14 +931,12 @@ EXPORT_SYMBOL(sptlrpc_conf_client_adapt); 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'; diff --git a/lustre/target/tgt_handler.c b/lustre/target/tgt_handler.c index 55b1869..f0f1ed6 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -740,11 +740,10 @@ static inline void tgt_init_sec_none(struct obd_connect_data *reply) 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); @@ -758,6 +757,7 @@ static int tgt_init_sec_level(struct ptlrpc_request *req) 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) { @@ -1857,15 +1857,13 @@ static void tgt_warn_on_cksum(struct ptlrpc_request *req, { 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); }