Commit 8e86499e authored by Gioh Kim's avatar Gioh Kim Committed by Jason Gunthorpe

RDMA/rtrs: New function converting rtrs_addr to string

There is common code converting addresses of source machine and
destination machine to a string.  We already have a struct rtrs_addr to
store two addresses.  This patch introduces a new function that converts
two addresses into one string with struct rtrs_addr.

Link: https://lore.kernel.org/r/20210325153308.1214057-14-gi-oh.kim@ionos.comSigned-off-by: default avatarGioh Kim <gi-oh.kim@ionos.com>
Signed-off-by: default avatarJack Wang <jinpu.wang@ionos.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 57dae8ba
......@@ -396,14 +396,13 @@ int rtrs_clt_create_sess_files(struct rtrs_clt_sess *sess)
{
struct rtrs_clt *clt = sess->clt;
char str[NAME_MAX];
int err, cnt;
cnt = sockaddr_to_str((struct sockaddr *)&sess->s.src_addr,
str, sizeof(str));
cnt += scnprintf(str + cnt, sizeof(str) - cnt, "@");
sockaddr_to_str((struct sockaddr *)&sess->s.dst_addr,
str + cnt, sizeof(str) - cnt);
int err;
struct rtrs_addr path = {
.src = &sess->s.src_addr,
.dst = &sess->s.dst_addr,
};
rtrs_addr_to_str(&path, str, sizeof(str));
err = kobject_init_and_add(&sess->kobj, &ktype_sess, clt->kobj_paths,
"%s", str);
if (err) {
......
......@@ -259,14 +259,13 @@ int rtrs_srv_create_sess_files(struct rtrs_srv_sess *sess)
struct rtrs_srv *srv = sess->srv;
struct rtrs_sess *s = &sess->s;
char str[NAME_MAX];
int err, cnt;
cnt = sockaddr_to_str((struct sockaddr *)&sess->s.dst_addr,
str, sizeof(str));
cnt += scnprintf(str + cnt, sizeof(str) - cnt, "@");
sockaddr_to_str((struct sockaddr *)&sess->s.src_addr,
str + cnt, sizeof(str) - cnt);
int err;
struct rtrs_addr path = {
.src = &sess->s.dst_addr,
.dst = &sess->s.src_addr,
};
rtrs_addr_to_str(&path, str, sizeof(str));
err = rtrs_srv_create_once_sysfs_root_folders(sess);
if (err)
return err;
......
......@@ -463,6 +463,30 @@ int sockaddr_to_str(const struct sockaddr *addr, char *buf, size_t len)
}
EXPORT_SYMBOL(sockaddr_to_str);
/**
* rtrs_addr_to_str() - convert rtrs_addr to a string "src@dst"
* @addr: the rtrs_addr structure to be converted
* @buf: string containing source and destination addr of a path
* separated by '@' I.e. "ip:1.1.1.1@ip:1.1.1.2"
* "ip:1.1.1.1@ip:1.1.1.2".
* @len: string length
*
* The return value is the number of characters written into buf not
* including the trailing '\0'.
*/
int rtrs_addr_to_str(const struct rtrs_addr *addr, char *buf, size_t len)
{
int cnt;
cnt = sockaddr_to_str((struct sockaddr *)addr->src,
buf, len);
cnt += scnprintf(buf + cnt, len - cnt, "@");
sockaddr_to_str((struct sockaddr *)addr->dst,
buf + cnt, len - cnt);
return cnt;
}
EXPORT_SYMBOL(rtrs_addr_to_str);
/**
* rtrs_addr_to_sockaddr() - convert path string "src,dst" or "src@dst"
* to sockaddreses
......
......@@ -184,4 +184,5 @@ int rtrs_addr_to_sockaddr(const char *str, size_t len, u16 port,
struct rtrs_addr *addr);
int sockaddr_to_str(const struct sockaddr *addr, char *buf, size_t len);
int rtrs_addr_to_str(const struct rtrs_addr *addr, char *buf, size_t len);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment