From: jmaloy@redhat.com
To: netdev@vger.kernel.org, davem@davemloft.net
Cc: tipc-discussion@lists.sourceforge.net,
tung.q.nguyen@dektech.com.au, hoang.h.le@dektech.com.au,
tuong.t.lien@dektech.com.au, jmaloy@redhat.com,
maloy@donjonn.com, xinl@redhat.com, ying.xue@windriver.com,
parthasarathy.bhuvaragan@gmail.com
Subject: [net-next 02/16] tipc: move creation of publication item one level up in call chain
Date: Tue, 16 Mar 2021 22:06:09 -0400 [thread overview]
Message-ID: <20210317020623.1258298-3-jmaloy@redhat.com> (raw)
In-Reply-To: <20210317020623.1258298-1-jmaloy@redhat.com>
From: Jon Maloy <jmaloy@redhat.com>
We instantiate struct publication in tipc_nametbl_insert_publ()
instead of as currently in tipc_service_insert_publ(). This has the
advantage that we can pass a pointer to the publication struct to
the next call levels, instead of the numerous individual parameters
we pass on now. It also gives us a location to keep the contents of
the additional fields we will introduce in a later commit.
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Acked-by: Hoang Le <hoang.h.le@dektech.com.au>
Acked-by: Tung Nguyen <tung.q.nguyen@dektech.com.au>
Acked-by: Xin Long <lucien.xin@gmail.com>
---
net/tipc/name_table.c | 65 +++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 33 deletions(-)
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index c2410ba7be5c..c37cef09b54c 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -327,49 +327,48 @@ static struct service_range *tipc_service_create_range(struct tipc_service *sc,
return sr;
}
-static struct publication *tipc_service_insert_publ(struct net *net,
- struct tipc_service *sc,
- u32 type, u32 lower,
- u32 upper, u32 scope,
- u32 node, u32 port,
- u32 key)
+static bool tipc_service_insert_publ(struct net *net,
+ struct tipc_service *sc,
+ struct publication *p)
{
struct tipc_subscription *sub, *tmp;
struct service_range *sr;
- struct publication *p;
+ struct publication *_p;
+ u32 node = p->sk.node;
bool first = false;
+ bool res = false;
- sr = tipc_service_create_range(sc, lower, upper);
+ spin_lock_bh(&sc->lock);
+ sr = tipc_service_create_range(sc, p->sr.lower, p->sr.upper);
if (!sr)
- goto err;
+ goto exit;
first = list_empty(&sr->all_publ);
/* Return if the publication already exists */
- list_for_each_entry(p, &sr->all_publ, all_publ) {
- if (p->key == key && (!p->sk.node || p->sk.node == node))
- return NULL;
+ list_for_each_entry(_p, &sr->all_publ, all_publ) {
+ if (_p->key == p->key && (!_p->sk.node || _p->sk.node == node))
+ goto exit;
}
- /* Create and insert publication */
- p = tipc_publ_create(type, lower, upper, scope, node, port, key);
- if (!p)
- goto err;
- /* Suppose there shouldn't be a huge gap btw publs i.e. >INT_MAX */
- p->id = sc->publ_cnt++;
- if (in_own_node(net, node))
+ if (in_own_node(net, p->sk.node))
list_add(&p->local_publ, &sr->local_publ);
list_add(&p->all_publ, &sr->all_publ);
+ p->id = sc->publ_cnt++;
/* Any subscriptions waiting for notification? */
list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) {
- tipc_sub_report_overlap(sub, p->sr.lower, p->sr.upper, TIPC_PUBLISHED,
- p->sk.ref, p->sk.node, p->scope, first);
+ tipc_sub_report_overlap(sub, p->sr.lower, p->sr.upper,
+ TIPC_PUBLISHED, p->sk.ref, p->sk.node,
+ p->scope, first);
}
- return p;
-err:
- pr_warn("Failed to bind to %u,%u,%u, no memory\n", type, lower, upper);
- return NULL;
+ res = true;
+exit:
+ if (!res)
+ pr_warn("Failed to bind to %u,%u,%u\n",
+ p->sr.type, p->sr.lower, p->sr.upper);
+ spin_unlock_bh(&sc->lock);
+ return res;
}
/**
@@ -482,6 +481,10 @@ struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
struct tipc_service *sc;
struct publication *p;
+ p = tipc_publ_create(type, lower, upper, scope, node, port, key);
+ if (!p)
+ return NULL;
+
if (scope > TIPC_NODE_SCOPE || lower > upper) {
pr_debug("Failed to bind illegal {%u,%u,%u} with scope %u\n",
type, lower, upper, scope);
@@ -490,14 +493,10 @@ struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
sc = tipc_service_find(net, type);
if (!sc)
sc = tipc_service_create(type, &nt->services[hash(type)]);
- if (!sc)
- return NULL;
-
- spin_lock_bh(&sc->lock);
- p = tipc_service_insert_publ(net, sc, type, lower, upper,
- scope, node, port, key);
- spin_unlock_bh(&sc->lock);
- return p;
+ if (sc && tipc_service_insert_publ(net, sc, p))
+ return p;
+ kfree(p);
+ return NULL;
}
struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
--
2.29.2
next prev parent reply other threads:[~2021-03-17 2:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 2:06 [net-next 00/16] tipc: cleanups and simplifications jmaloy
2021-03-17 2:06 ` [net-next 01/16] tipc: re-organize members of struct publication jmaloy
2021-03-17 2:06 ` jmaloy [this message]
2021-03-17 2:06 ` [net-next 03/16] tipc: introduce new unified address type for internal use jmaloy
2021-03-17 2:06 ` [net-next 04/16] tipc: simplify signature of tipc_namtbl_publish() jmaloy
2021-03-17 2:06 ` [net-next 05/16] tipc: simplify call signatures for publication creation jmaloy
2021-03-17 2:06 ` [net-next 06/16] tipc: simplify signature of tipc_nametbl_withdraw() functions jmaloy
2021-03-17 2:06 ` [net-next 07/16] tipc: rename binding table lookup functions jmaloy
2021-03-17 2:06 ` [net-next 08/16] tipc: refactor tipc_sendmsg() and tipc_lookup_anycast() jmaloy
2021-03-17 2:06 ` [net-next 09/16] tipc: simplify signature of tipc_namtbl_lookup_mcast_sockets() jmaloy
2021-03-17 2:06 ` [net-next 10/16] tipc: simplify signature of tipc_nametbl_lookup_mcast_nodes() jmaloy
2021-03-17 2:06 ` [net-next 11/16] tipc: simplify signature of tipc_nametbl_lookup_group() jmaloy
2021-03-17 2:06 ` [net-next 12/16] tipc: simplify signature of tipc_service_find_range() jmaloy
2021-03-17 2:06 ` [net-next 13/16] tipc: simplify signature of tipc_find_service() jmaloy
2021-03-17 2:06 ` [net-next 14/16] tipc: simplify api between binding table and topology server jmaloy
2021-03-17 2:06 ` [net-next 15/16] tipc: add host-endian copy of user subscription to struct tipc_subscription jmaloy
2021-03-17 2:06 ` [net-next 16/16] tipc: remove some unnecessary warnings jmaloy
2021-03-17 19:00 ` [net-next 00/16] tipc: cleanups and simplifications patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210317020623.1258298-3-jmaloy@redhat.com \
--to=jmaloy@redhat.com \
--cc=davem@davemloft.net \
--cc=hoang.h.le@dektech.com.au \
--cc=maloy@donjonn.com \
--cc=netdev@vger.kernel.org \
--cc=parthasarathy.bhuvaragan@gmail.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=tung.q.nguyen@dektech.com.au \
--cc=tuong.t.lien@dektech.com.au \
--cc=xinl@redhat.com \
--cc=ying.xue@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).