提交 429189ac 编写于 作者: J Jon Maloy 提交者: David S. Miller

tipc: add host-endian copy of user subscription to struct tipc_subscription

We reduce and localize the usage of the tipc_sub_xx() macros by adding a
corresponding member, with fields set in host-endian format, to struct
tipc_subscription.
Signed-off-by: NJon Maloy <jmaloy@redhat.com>
Acked-by: NYing Xue <ying.xue@windriver.com>
Acked-by: NHoang Le <hoang.h.le@dektech.com.au>
Acked-by: NTung Nguyen <tung.q.nguyen@dektech.com.au>
Acked-by: NXin Long <lucien.xin@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 09f78b85
...@@ -416,17 +416,14 @@ static int tipc_publ_sort(void *priv, struct list_head *a, ...@@ -416,17 +416,14 @@ static int tipc_publ_sort(void *priv, struct list_head *a,
static void tipc_service_subscribe(struct tipc_service *service, static void tipc_service_subscribe(struct tipc_service *service,
struct tipc_subscription *sub) struct tipc_subscription *sub)
{ {
struct tipc_subscr *sb = &sub->evt.s;
struct publication *p, *first, *tmp; struct publication *p, *first, *tmp;
struct list_head publ_list; struct list_head publ_list;
struct service_range *sr; struct service_range *sr;
struct tipc_service_range r; u32 filter, lower, upper;
u32 filter;
r.type = tipc_sub_read(sb, seq.type); filter = sub->s.filter;
r.lower = tipc_sub_read(sb, seq.lower); lower = sub->s.seq.lower;
r.upper = tipc_sub_read(sb, seq.upper); upper = sub->s.seq.upper;
filter = tipc_sub_read(sb, filter);
tipc_sub_get(sub); tipc_sub_get(sub);
list_add(&sub->service_list, &service->subscriptions); list_add(&sub->service_list, &service->subscriptions);
...@@ -435,7 +432,7 @@ static void tipc_service_subscribe(struct tipc_service *service, ...@@ -435,7 +432,7 @@ static void tipc_service_subscribe(struct tipc_service *service,
return; return;
INIT_LIST_HEAD(&publ_list); INIT_LIST_HEAD(&publ_list);
service_range_foreach_match(sr, service, r.lower, r.upper) { service_range_foreach_match(sr, service, lower, upper) {
first = NULL; first = NULL;
list_for_each_entry(p, &sr->all_publ, all_publ) { list_for_each_entry(p, &sr->all_publ, all_publ) {
if (filter & TIPC_SUB_PORTS) if (filter & TIPC_SUB_PORTS)
...@@ -826,14 +823,13 @@ void tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua, ...@@ -826,14 +823,13 @@ void tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua,
bool tipc_nametbl_subscribe(struct tipc_subscription *sub) bool tipc_nametbl_subscribe(struct tipc_subscription *sub)
{ {
struct tipc_net *tn = tipc_net(sub->net); struct tipc_net *tn = tipc_net(sub->net);
struct tipc_subscr *s = &sub->evt.s; u32 type = sub->s.seq.type;
u32 type = tipc_sub_read(s, seq.type);
struct tipc_service *sc; struct tipc_service *sc;
struct tipc_uaddr ua; struct tipc_uaddr ua;
bool res = true; bool res = true;
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type,
tipc_sub_read(s, seq.lower), tipc_sub_read(s, seq.upper)); sub->s.seq.lower, sub->s.seq.upper);
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
sc = tipc_service_find(sub->net, &ua); sc = tipc_service_find(sub->net, &ua);
if (!sc) if (!sc)
...@@ -843,9 +839,8 @@ bool tipc_nametbl_subscribe(struct tipc_subscription *sub) ...@@ -843,9 +839,8 @@ bool tipc_nametbl_subscribe(struct tipc_subscription *sub)
tipc_service_subscribe(sc, sub); tipc_service_subscribe(sc, sub);
spin_unlock_bh(&sc->lock); spin_unlock_bh(&sc->lock);
} else { } else {
pr_warn("Failed to subscribe for {%u,%u,%u}\n", type, pr_warn("Failed to subscribe for {%u,%u,%u}\n",
tipc_sub_read(s, seq.lower), type, sub->s.seq.lower, sub->s.seq.upper);
tipc_sub_read(s, seq.upper));
res = false; res = false;
} }
spin_unlock_bh(&tn->nametbl_lock); spin_unlock_bh(&tn->nametbl_lock);
...@@ -859,13 +854,11 @@ bool tipc_nametbl_subscribe(struct tipc_subscription *sub) ...@@ -859,13 +854,11 @@ bool tipc_nametbl_subscribe(struct tipc_subscription *sub)
void tipc_nametbl_unsubscribe(struct tipc_subscription *sub) void tipc_nametbl_unsubscribe(struct tipc_subscription *sub)
{ {
struct tipc_net *tn = tipc_net(sub->net); struct tipc_net *tn = tipc_net(sub->net);
struct tipc_subscr *s = &sub->evt.s;
u32 type = tipc_sub_read(s, seq.type);
struct tipc_service *sc; struct tipc_service *sc;
struct tipc_uaddr ua; struct tipc_uaddr ua;
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE,
tipc_sub_read(s, seq.lower), tipc_sub_read(s, seq.upper)); sub->s.seq.type, sub->s.seq.lower, sub->s.seq.upper);
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
sc = tipc_service_find(sub->net, &ua); sc = tipc_service_find(sub->net, &ua);
if (!sc) if (!sc)
......
...@@ -65,37 +65,32 @@ static void tipc_sub_send_event(struct tipc_subscription *sub, ...@@ -65,37 +65,32 @@ static void tipc_sub_send_event(struct tipc_subscription *sub,
/** /**
* tipc_sub_check_overlap - test for subscription overlap with the given values * tipc_sub_check_overlap - test for subscription overlap with the given values
* @seq: tipc_name_seq to check * @subscribed: the service range subscribed for
* @found_lower: lower value to test * @found: the service range we are checning for match
* @found_upper: upper value to test
* *
* Returns true if there is overlap, otherwise false. * Returns true if there is overlap, otherwise false.
*/ */
bool tipc_sub_check_overlap(struct tipc_service_range *sr, static bool tipc_sub_check_overlap(struct tipc_service_range *subscribed,
u32 found_lower, u32 found_upper) struct tipc_service_range *found)
{ {
if (found_lower < sr->lower) u32 found_lower = found->lower;
found_lower = sr->lower; u32 found_upper = found->upper;
if (found_upper > sr->upper)
found_upper = sr->upper; if (found_lower < subscribed->lower)
if (found_lower > found_upper) found_lower = subscribed->lower;
return false; if (found_upper > subscribed->upper)
return true; found_upper = subscribed->upper;
return found_lower <= found_upper;
} }
void tipc_sub_report_overlap(struct tipc_subscription *sub, void tipc_sub_report_overlap(struct tipc_subscription *sub,
struct publication *p, struct publication *p,
u32 event, bool must) u32 event, bool must)
{ {
struct tipc_subscr *s = &sub->evt.s; struct tipc_service_range *sr = &sub->s.seq;
u32 filter = tipc_sub_read(s, filter); u32 filter = sub->s.filter;
struct tipc_service_range seq;
seq.type = tipc_sub_read(s, seq.type);
seq.lower = tipc_sub_read(s, seq.lower);
seq.upper = tipc_sub_read(s, seq.upper);
if (!tipc_sub_check_overlap(&seq, p->sr.lower, p->sr.upper)) if (!tipc_sub_check_overlap(sr, &p->sr))
return; return;
if (!must && !(filter & TIPC_SUB_PORTS)) if (!must && !(filter & TIPC_SUB_PORTS))
return; return;
...@@ -137,12 +132,14 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net, ...@@ -137,12 +132,14 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net,
struct tipc_subscr *s, struct tipc_subscr *s,
int conid) int conid)
{ {
u32 lower = tipc_sub_read(s, seq.lower);
u32 upper = tipc_sub_read(s, seq.upper);
u32 filter = tipc_sub_read(s, filter); u32 filter = tipc_sub_read(s, filter);
struct tipc_subscription *sub; struct tipc_subscription *sub;
u32 timeout; u32 timeout;
if ((filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE) || if ((filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE) ||
(tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))) { lower > upper) {
pr_warn("Subscription rejected, illegal request\n"); pr_warn("Subscription rejected, illegal request\n");
return NULL; return NULL;
} }
...@@ -157,6 +154,12 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net, ...@@ -157,6 +154,12 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net,
sub->conid = conid; sub->conid = conid;
sub->inactive = false; sub->inactive = false;
memcpy(&sub->evt.s, s, sizeof(*s)); memcpy(&sub->evt.s, s, sizeof(*s));
sub->s.seq.type = tipc_sub_read(s, seq.type);
sub->s.seq.lower = lower;
sub->s.seq.upper = upper;
sub->s.filter = filter;
sub->s.timeout = tipc_sub_read(s, timeout);
memcpy(sub->s.usr_handle, s->usr_handle, 8);
spin_lock_init(&sub->lock); spin_lock_init(&sub->lock);
kref_init(&sub->kref); kref_init(&sub->kref);
if (!tipc_nametbl_subscribe(sub)) { if (!tipc_nametbl_subscribe(sub)) {
......
...@@ -60,12 +60,13 @@ struct tipc_conn; ...@@ -60,12 +60,13 @@ struct tipc_conn;
* @lock: serialize up/down and timer events * @lock: serialize up/down and timer events
*/ */
struct tipc_subscription { struct tipc_subscription {
struct tipc_subscr s;
struct tipc_event evt;
struct kref kref; struct kref kref;
struct net *net; struct net *net;
struct timer_list timer; struct timer_list timer;
struct list_head service_list; struct list_head service_list;
struct list_head sub_list; struct list_head sub_list;
struct tipc_event evt;
int conid; int conid;
bool inactive; bool inactive;
spinlock_t lock; spinlock_t lock;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册