Commit 80feb1ef authored by Dmitry Eremin's avatar Dmitry Eremin Committed by Greg Kroah-Hartman
Browse files

staging: lustre: 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: default avatarDmitry Eremin <dmitry.eremin@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6070
Reviewed-on: http://review.whamcloud.com/13185


Reviewed-by: default avatarJohn L. Hammond <john.hammond@intel.com>
Reviewed-by: default avatarAndreas Dilger <andreas.dilger@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 335ea564
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -57,12 +57,29 @@ struct list_head;
#define LNET_NIDSTR_COUNT  1024    /* # of nidstrings */
#define LNET_NIDSTR_SIZE   32      /* size of each one (see below for usage) */

int libcfs_isknown_lnd(int type);
char *libcfs_lnd2modname(int type);
char *libcfs_lnd2str(int type);
/* support decl needed by both kernel and user space */
char *libcfs_next_nidstring(void);
int libcfs_isknown_lnd(__u32 lnd);
char *libcfs_lnd2modname(__u32 lnd);
char *libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size);
static inline char *libcfs_lnd2str(__u32 lnd)
{
	return libcfs_lnd2str_r(lnd, libcfs_next_nidstring(),
				LNET_NIDSTR_SIZE);
}
int libcfs_str2lnd(const char *str);
char *libcfs_net2str(__u32 net);
char *libcfs_nid2str(lnet_nid_t nid);
char *libcfs_net2str_r(__u32 net, char *buf, size_t buf_size);
static inline char *libcfs_net2str(__u32 net)
{
	return libcfs_net2str_r(net, libcfs_next_nidstring(),
				LNET_NIDSTR_SIZE);
}
char *libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size);
static inline char *libcfs_nid2str(lnet_nid_t nid)
{
	return libcfs_nid2str_r(nid, libcfs_next_nidstring(),
				LNET_NIDSTR_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);
@@ -79,10 +96,10 @@ void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
			       char *max_nid, size_t nidstr_length);

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);
+3 −3
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ static void lnet_assert_wire_constants(void)
}

static lnd_t *
lnet_find_lnd_by_type(int type)
lnet_find_lnd_by_type(__u32 type)
{
	lnd_t *lnd;
	struct list_head *tmp;
@@ -272,7 +272,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;
	}

@@ -962,7 +962,7 @@ lnet_startup_lndnis(void)
	struct list_head nilist;
	int i;
	int rc = 0;
	int lnd_type;
	__u32 lnd_type;
	int nicount = 0;
	char *nets = lnet_get_networks();

+69 −69
Original line number Diff line number Diff line
@@ -693,8 +693,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);
@@ -777,9 +777,9 @@ libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
}

static void
libcfs_ip_addr2str(__u32 addr, char *str)
libcfs_ip_addr2str(__u32 addr, char *str, size_t size)
{
	snprintf(str, LNET_NIDSTR_SIZE, "%u.%u.%u.%u",
	snprintf(str, size, "%u.%u.%u.%u",
		 (addr >> 24) & 0xff, (addr >> 16) & 0xff,
		 (addr >> 8) & 0xff, addr & 0xff);
}
@@ -888,15 +888,15 @@ cfs_ip_addr_match(__u32 addr, struct list_head *list)
}

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
@@ -1105,14 +1105,13 @@ static struct netstrfns libcfs_netstrfns[] = {
	{/* .nf_type      */  -1},
};

static const int libcfs_nnetstrfns = ARRAY_SIZE(libcfs_netstrfns);
static const size_t libcfs_nnetstrfns = ARRAY_SIZE(libcfs_netstrfns);

static struct netstrfns *
libcfs_lnd2netstrfns(int lnd)
libcfs_lnd2netstrfns(__u32 lnd)
{
	int i;

	if (lnd >= 0)
	for (i = 0; i < libcfs_nnetstrfns; i++)
		if (lnd == libcfs_netstrfns[i].nf_type)
			return &libcfs_netstrfns[i];
@@ -1149,14 +1148,14 @@ libcfs_name2netstrfns(const char *name)
}

int
libcfs_isknown_lnd(int type)
libcfs_isknown_lnd(__u32 lnd)
{
	return libcfs_lnd2netstrfns(type) != NULL;
	return libcfs_lnd2netstrfns(lnd) != NULL;
}
EXPORT_SYMBOL(libcfs_isknown_lnd);

char *
libcfs_lnd2modname(int lnd)
libcfs_lnd2modname(__u32 lnd)
{
	struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);

@@ -1164,21 +1163,6 @@ libcfs_lnd2modname(int lnd)
}
EXPORT_SYMBOL(libcfs_lnd2modname);

char *
libcfs_lnd2str(int lnd)
{
	char	   *str;
	struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);

	if (nf != NULL)
		return nf->nf_name;

	str = libcfs_next_nidstring();
	snprintf(str, LNET_NIDSTR_SIZE, "?%d?", lnd);
	return str;
}
EXPORT_SYMBOL(libcfs_lnd2str);

int
libcfs_str2lnd(const char *str)
{
@@ -1192,57 +1176,73 @@ libcfs_str2lnd(const char *str)
EXPORT_SYMBOL(libcfs_str2lnd);

char *
libcfs_net2str(__u32 net)
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;

	nf = libcfs_lnd2netstrfns(lnd);
	if (nf == NULL)
		snprintf(str, LNET_NIDSTR_SIZE, "<%d:%d>", lnd, num);
	else if (num == 0)
		snprintf(str, LNET_NIDSTR_SIZE, "%s", nf->nf_name);
		snprintf(buf, buf_size, "?%u?", lnd);
	else
		snprintf(str, LNET_NIDSTR_SIZE, "%s%d", nf->nf_name, num);
		snprintf(buf, buf_size, "%s", nf->nf_name);

	return str;
	return buf;
}
EXPORT_SYMBOL(libcfs_net2str);
EXPORT_SYMBOL(libcfs_lnd2str_r);

char *
libcfs_nid2str(lnet_nid_t nid)
libcfs_net2str_r(__u32 net, char *buf, size_t buf_size)
{
	__u32 nnum = LNET_NETNUM(net);
	__u32 lnd = LNET_NETTYP(net);
	struct netstrfns *nf;

	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);

	return buf;
}
EXPORT_SYMBOL(libcfs_net2str_r);

char *
libcfs_nid2str_r(lnet_nid_t nid, 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);
	__u32 nnum = LNET_NETNUM(net);
	__u32 lnd = LNET_NETTYP(net);
	struct netstrfns *nf;
	char	     *str;
	int	       nob;

	if (nid == LNET_NID_ANY)
		return "<?>";
	if (nid == LNET_NID_ANY) {
		strncpy(buf, "<?>", buf_size);
		buf[buf_size - 1] = '\0';
		return buf;
	}

	nf = libcfs_lnd2netstrfns(lnd);
	str = libcfs_next_nidstring();

	if (nf == NULL)
		snprintf(str, LNET_NIDSTR_SIZE, "%x@<%d:%d>", addr, lnd, nnum);
		snprintf(buf, buf_size, "%x@<%u:%u>", addr, lnd, nnum);
	else {
		nf->nf_addr2str(addr, str);
		nob = strlen(str);
		size_t addr_len;

		nf->nf_addr2str(addr, buf, buf_size);
		addr_len = strlen(buf);
		if (nnum == 0)
			snprintf(str + nob, LNET_NIDSTR_SIZE - nob, "@%s",
			snprintf(buf + addr_len, buf_size - addr_len, "@%s",
				 nf->nf_name);
		else
			snprintf(str + nob, LNET_NIDSTR_SIZE - nob, "@%s%d",
			snprintf(buf + addr_len, buf_size - addr_len, "@%s%u",
				 nf->nf_name, nnum);
	}

	return str;
	return buf;
}
EXPORT_SYMBOL(libcfs_nid2str);
EXPORT_SYMBOL(libcfs_nid2str_r);

static struct netstrfns *
libcfs_str2net_internal(const char *str, __u32 *net)
+1 −1
Original line number Diff line number Diff line
@@ -235,7 +235,7 @@ lnet_find_net_locked(__u32 net)
static void lnet_shuffle_seed(void)
{
	static int seeded;
	int lnd_type, seed[2];
	__u32 lnd_type, seed[2];
	struct timespec64 ts;
	lnet_ni_t *ni;
	struct list_head *tmp;
+7 −4
Original line number Diff line number Diff line
@@ -610,6 +610,7 @@ static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep

int lprocfs_rd_import(struct seq_file *m, void *data)
{
	char				nidstr[LNET_NIDSTR_SIZE];
	struct lprocfs_counter		ret;
	struct lprocfs_counter_header	*header;
	struct obd_device		*obd	= data;
@@ -647,18 +648,20 @@ int lprocfs_rd_import(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 ? "<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));
Loading