* switch iwpm to ccan list.h
@ 2016-10-10 9:41 Christoph Hellwig
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2016-10-10 9:41 UTC (permalink / raw)
To: Tatyana.E.Nikolova-ral2JQCrhuEAvxtiuMwx3w,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
robert.o.sharp-ral2JQCrhuEAvxtiuMwx3w
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
I've started running sparse on the rdma-core code, and one of the
worst offenders is the iwpmd list code, so this (untested) patch
set converts it over to the ccan list.h helpers. Reviews and
testing appreciated.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] iwpmd: use ccan list.h for pending_messages
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
@ 2016-10-10 9:41 ` Christoph Hellwig
2016-10-10 9:41 ` [PATCH 2/3] iwpmd: use ccan list.h for mapping_reqs Christoph Hellwig
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2016-10-10 9:41 UTC (permalink / raw)
To: Tatyana.E.Nikolova-ral2JQCrhuEAvxtiuMwx3w,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
robert.o.sharp-ral2JQCrhuEAvxtiuMwx3w
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
The only change in semantics is that we remove the entry from the list
earlier in iwpm_pending_msgs_handler due to using the list_pop helper,
but given that we won't exist the loop early ever this should not change
behavior.
Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
---
iwpmd/iwarp_pm.h | 9 ++++-----
iwpmd/iwarp_pm_helper.c | 22 +---------------------
iwpmd/iwarp_pm_server.c | 9 +++++----
3 files changed, 10 insertions(+), 30 deletions(-)
diff --git a/iwpmd/iwarp_pm.h b/iwpmd/iwarp_pm.h
index 5b7c613..57153cc 100644
--- a/iwpmd/iwarp_pm.h
+++ b/iwpmd/iwarp_pm.h
@@ -52,6 +52,7 @@
#include <pthread.h>
#include <syslog.h>
#include <netlink/msg.h>
+#include <ccan/list.h>
#include "iwpm_netlink.h"
#define IWARP_PM_PORT 3935
@@ -134,7 +135,6 @@ typedef union sockaddr_union {
enum {
IWPM_LIST_MAPPED_PORTS,
IWPM_LIST_MAP_REQUESTS,
- IWPM_LIST_PENDING_MSGS
};
typedef struct iwpm_list {
@@ -189,8 +189,7 @@ typedef struct iwpm_mapping_request {
} iwpm_mapping_request;
typedef struct iwpm_pending_msg {
- struct iwpm_send_msg * next;
- struct iwpm_send_msg * prev;
+ struct list_node entry;
iwpm_send_msg send_msg;
} iwpm_pending_msg;
@@ -285,8 +284,6 @@ int send_iwpm_msg(void (*form_msg_type)(iwpm_wire_msg *, iwpm_msg_parms *),
int add_iwpm_pending_msg(iwpm_send_msg *);
-void remove_iwpm_pending_msg(iwpm_pending_msg *);
-
int check_same_sockaddr(struct sockaddr_storage *, struct sockaddr_storage *);
void add_list_element(iwpm_list **, iwpm_list **, int);
@@ -295,4 +292,6 @@ void remove_list_element(iwpm_list **, iwpm_list *, int);
void free_iwpm_mapped_ports(void);
+extern struct list_head pending_messages;
+
#endif
diff --git a/iwpmd/iwarp_pm_helper.c b/iwpmd/iwarp_pm_helper.c
index 89d2b6c..ebcff58 100644
--- a/iwpmd/iwarp_pm_helper.c
+++ b/iwpmd/iwarp_pm_helper.c
@@ -36,7 +36,6 @@
extern iwpm_mapped_port *mapped_ports;
extern iwpm_mapped_port *pending_ports;
extern iwpm_mapping_request *mapping_reqs;
-extern iwpm_send_msg *pending_messages;
extern pthread_cond_t cond_req_complete;
extern pthread_mutex_t map_req_mutex;
@@ -613,27 +612,13 @@ int add_iwpm_pending_msg(iwpm_send_msg *send_msg)
memcpy(&pending_msg->send_msg, send_msg, sizeof(iwpm_send_msg));
pthread_mutex_lock(&pending_msg_mutex);
- add_list_element((iwpm_list **)&pending_messages, (iwpm_list **)&pending_msg,
- IWPM_LIST_PENDING_MSGS);
+ list_add(&pending_messages, &pending_msg->entry);
pthread_mutex_unlock(&pending_msg_mutex);
/* signal the thread that a new message has been posted */
pthread_cond_signal(&cond_pending_msg);
return 0;
}
-/**
- * remove_iwpm_pending_msg - Free wire message buffer
- * @pending_msg: message to be removed
- *
- * Routine must be called within lock context
- */
-void remove_iwpm_pending_msg(iwpm_pending_msg *pending_msg)
-{
- remove_list_element((iwpm_list **)&pending_messages, (iwpm_list *)pending_msg,
- IWPM_LIST_PENDING_MSGS);
- free(pending_msg);
-}
-
/*
* assign_list_head - Make list_element the first element in the list
* (i.e. *list = *list_element)
@@ -642,7 +627,6 @@ static void assign_list_head(iwpm_list **list, iwpm_list *list_element, int list
{
iwpm_mapped_port **ports;
iwpm_mapping_request **requests;
- iwpm_send_msg **messages;
switch (list_type) {
case IWPM_LIST_MAPPED_PORTS:
@@ -653,10 +637,6 @@ static void assign_list_head(iwpm_list **list, iwpm_list *list_element, int list
requests = (iwpm_mapping_request **)list;
*requests = (iwpm_mapping_request *)list_element;
break;
- case IWPM_LIST_PENDING_MSGS:
- messages = (iwpm_send_msg **)list;
- *messages = (iwpm_send_msg *)list_element;
- break;
default:
break;
}
diff --git a/iwpmd/iwarp_pm_server.c b/iwpmd/iwarp_pm_server.c
index 39e0aa2..a45ccbd 100644
--- a/iwpmd/iwarp_pm_server.c
+++ b/iwpmd/iwarp_pm_server.c
@@ -39,7 +39,7 @@ int iwpm_version = 3;
iwpm_mapped_port *mapped_ports = NULL; /* list of mapped ports */
volatile iwpm_mapping_request *mapping_reqs = NULL; /* list of map tracking objects */
-volatile iwpm_pending_msg *pending_messages = NULL; /* list of pending wire messages */
+LIST_HEAD(pending_messages); /* list of pending wire messages */
iwpm_client client_list[IWARP_PM_MAX_CLIENTS];/* list of iwarp port mapper clients */
int mapinfo_num_list[IWARP_PM_MAX_CLIENTS]; /* list of iwarp port mapper clients */
@@ -160,9 +160,10 @@ void *iwpm_pending_msgs_handler()
pthread_mutex_unlock(&pending_msg_mutex);
goto pending_msgs_handler_exit;
}
+
/* try sending out each pending message and remove it from the list */
- while (pending_messages) {
- pending_msg = (iwpm_pending_msg *)pending_messages;
+ while ((pending_msg = list_pop(&pending_messages,
+ iwpm_pending_msg, entry))) {
retries = IWPM_SEND_MSG_RETRIES;
while (retries) {
send_msg = &pending_msg->send_msg;
@@ -179,7 +180,7 @@ void *iwpm_pending_msgs_handler()
} else
retries = 0; /* no need to retry */
}
- remove_iwpm_pending_msg(pending_msg);
+ free(pending_msg);
}
}
pthread_mutex_unlock(&pending_msg_mutex);
--
2.10.1.382.ga23ca1b
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] iwpmd: use ccan list.h for mapping_reqs
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-10-10 9:41 ` [PATCH 1/3] iwpmd: use ccan list.h for pending_messages Christoph Hellwig
@ 2016-10-10 9:41 ` Christoph Hellwig
2016-10-10 9:41 ` [PATCH 3/3] iwpmd: use ccan list.h for mapped_ports Christoph Hellwig
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2016-10-10 9:41 UTC (permalink / raw)
To: Tatyana.E.Nikolova-ral2JQCrhuEAvxtiuMwx3w,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
robert.o.sharp-ral2JQCrhuEAvxtiuMwx3w
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Trivial conversion, nothing to see here.
Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
---
iwpmd/iwarp_pm.h | 5 ++---
iwpmd/iwarp_pm_helper.c | 14 +++-----------
iwpmd/iwarp_pm_server.c | 11 ++++-------
3 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/iwpmd/iwarp_pm.h b/iwpmd/iwarp_pm.h
index 57153cc..48c9f80 100644
--- a/iwpmd/iwarp_pm.h
+++ b/iwpmd/iwarp_pm.h
@@ -134,7 +134,6 @@ typedef union sockaddr_union {
enum {
IWPM_LIST_MAPPED_PORTS,
- IWPM_LIST_MAP_REQUESTS,
};
typedef struct iwpm_list {
@@ -174,8 +173,7 @@ typedef struct iwpm_send_msg {
} iwpm_send_msg;
typedef struct iwpm_mapping_request {
- struct iwpm_mapping_request * next;
- struct iwpm_mapping_request * prev;
+ struct list_node entry;
struct sockaddr_storage src_addr;
struct sockaddr_storage remote_addr;
__u16 nlmsg_type; /* Message content */
@@ -293,5 +291,6 @@ void remove_list_element(iwpm_list **, iwpm_list *, int);
void free_iwpm_mapped_ports(void);
extern struct list_head pending_messages;
+extern struct list_head mapping_reqs;
#endif
diff --git a/iwpmd/iwarp_pm_helper.c b/iwpmd/iwarp_pm_helper.c
index ebcff58..8aa8e40 100644
--- a/iwpmd/iwarp_pm_helper.c
+++ b/iwpmd/iwarp_pm_helper.c
@@ -35,7 +35,6 @@
extern iwpm_mapped_port *mapped_ports;
extern iwpm_mapped_port *pending_ports;
-extern iwpm_mapping_request *mapping_reqs;
extern pthread_cond_t cond_req_complete;
extern pthread_mutex_t map_req_mutex;
@@ -96,8 +95,7 @@ iwpm_mapping_request *create_iwpm_map_request(struct nlmsghdr *req_nlh,
void add_iwpm_map_request(iwpm_mapping_request *iwpm_map_req)
{
pthread_mutex_lock(&map_req_mutex);
- add_list_element((iwpm_list **)&mapping_reqs, (iwpm_list **)&iwpm_map_req,
- IWPM_LIST_MAP_REQUESTS);
+ list_add(&mapping_reqs, &iwpm_map_req->entry);
/* if not wake, signal the thread that a new request has been posted */
if (!wake)
pthread_cond_signal(&cond_req_complete);
@@ -117,8 +115,7 @@ void remove_iwpm_map_request(iwpm_mapping_request *iwpm_map_req)
"Timeout for request (type = %u pid = %d)\n",
iwpm_map_req->msg_type, iwpm_map_req->nlmsg_pid);
}
- remove_list_element((iwpm_list **)&mapping_reqs, (iwpm_list *)iwpm_map_req,
- IWPM_LIST_MAP_REQUESTS);
+ list_del(&iwpm_map_req->entry);
if (iwpm_map_req->send_msg)
free(iwpm_map_req->send_msg);
free(iwpm_map_req);
@@ -140,7 +137,7 @@ int update_iwpm_map_request(__u64 assochandle, struct sockaddr_storage *src_addr
pthread_mutex_lock(&map_req_mutex);
/* look for a matching entry in the list */
- for (iwpm_map_req = mapping_reqs; iwpm_map_req != NULL; iwpm_map_req = iwpm_map_req->next) {
+ list_for_each(&mapping_reqs, iwpm_map_req, entry) {
if (assochandle == iwpm_map_req->assochandle &&
(msg_type & iwpm_map_req->msg_type) &&
check_same_sockaddr(src_addr, &iwpm_map_req->src_addr)) {
@@ -626,17 +623,12 @@ int add_iwpm_pending_msg(iwpm_send_msg *send_msg)
static void assign_list_head(iwpm_list **list, iwpm_list *list_element, int list_type)
{
iwpm_mapped_port **ports;
- iwpm_mapping_request **requests;
switch (list_type) {
case IWPM_LIST_MAPPED_PORTS:
ports = (iwpm_mapped_port **)list;
*ports = (iwpm_mapped_port *)list_element;
break;
- case IWPM_LIST_MAP_REQUESTS:
- requests = (iwpm_mapping_request **)list;
- *requests = (iwpm_mapping_request *)list_element;
- break;
default:
break;
}
diff --git a/iwpmd/iwarp_pm_server.c b/iwpmd/iwarp_pm_server.c
index a45ccbd..db73c6f 100644
--- a/iwpmd/iwarp_pm_server.c
+++ b/iwpmd/iwarp_pm_server.c
@@ -38,7 +38,7 @@ const char iwpm_ulib_name [] = "iWarpPortMapperUser";
int iwpm_version = 3;
iwpm_mapped_port *mapped_ports = NULL; /* list of mapped ports */
-volatile iwpm_mapping_request *mapping_reqs = NULL; /* list of map tracking objects */
+LIST_HEAD(mapping_reqs); /* list of map tracking objects */
LIST_HEAD(pending_messages); /* list of pending wire messages */
iwpm_client client_list[IWARP_PM_MAX_CLIENTS];/* list of iwarp port mapper clients */
int mapinfo_num_list[IWARP_PM_MAX_CLIENTS]; /* list of iwarp port mapper clients */
@@ -96,7 +96,7 @@ void *iwpm_mapping_reqs_handler()
while (1) {
pthread_mutex_lock(&map_req_mutex);
wake = 0;
- if (!mapping_reqs) {
+ if (list_empty(&mapping_reqs)) {
/* wait until a new mapping request is posted */
ret = pthread_cond_wait(&cond_req_complete, &map_req_mutex);
if (ret) {
@@ -111,9 +111,7 @@ void *iwpm_mapping_reqs_handler()
do {
pthread_mutex_lock(&map_req_mutex);
wake = 1;
- iwpm_map_req = (iwpm_mapping_request *)mapping_reqs;
- while (iwpm_map_req) {
- next_map_req = iwpm_map_req->next;
+ list_for_each_safe(&mapping_reqs, iwpm_map_req, next_map_req, entry) {
if (iwpm_map_req->timeout > 0) {
if (iwpm_map_req->timeout < IWPM_MAP_REQ_TIMEOUT &&
iwpm_map_req->msg_type != IWARP_PM_REQ_ACK) {
@@ -130,11 +128,10 @@ void *iwpm_mapping_reqs_handler()
} else {
remove_iwpm_map_request(iwpm_map_req);
}
- iwpm_map_req = next_map_req;
}
pthread_mutex_unlock(&map_req_mutex);
sleep(1);
- } while (mapping_reqs);
+ } while (!list_empty(&mapping_reqs));
}
mapping_reqs_handler_exit:
return NULL;
--
2.10.1.382.ga23ca1b
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] iwpmd: use ccan list.h for mapped_ports
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-10-10 9:41 ` [PATCH 1/3] iwpmd: use ccan list.h for pending_messages Christoph Hellwig
2016-10-10 9:41 ` [PATCH 2/3] iwpmd: use ccan list.h for mapping_reqs Christoph Hellwig
@ 2016-10-10 9:41 ` Christoph Hellwig
2016-10-10 14:07 ` switch iwpm to ccan list.h Bart Van Assche
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2016-10-10 9:41 UTC (permalink / raw)
To: Tatyana.E.Nikolova-ral2JQCrhuEAvxtiuMwx3w,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
robert.o.sharp-ral2JQCrhuEAvxtiuMwx3w
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
Also ѕtop passing mappped_ports ports as an argument to some function
and always use the global, which allows making mapped_ports static
in iwarp_pm_helper.c.
Now that no user of the iwpm_list infrastructure are left remove it.
Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
---
iwpmd/iwarp_pm.h | 26 ++++----------
iwpmd/iwarp_pm_helper.c | 92 +++++++++----------------------------------------
iwpmd/iwarp_pm_server.c | 27 +++++++--------
3 files changed, 35 insertions(+), 110 deletions(-)
diff --git a/iwpmd/iwarp_pm.h b/iwpmd/iwarp_pm.h
index 48c9f80..d282029 100644
--- a/iwpmd/iwarp_pm.h
+++ b/iwpmd/iwarp_pm.h
@@ -132,18 +132,8 @@ typedef union sockaddr_union {
struct sockaddr_nl nl_sockaddr;
} sockaddr_union;
-enum {
- IWPM_LIST_MAPPED_PORTS,
-};
-
-typedef struct iwpm_list {
- struct iwpm_list * next;
- struct iwpm_list * prev;
-} iwpm_list;
-
typedef struct iwpm_mapped_port {
- struct iwpm_mapped_port * next;
- struct iwpm_mapped_port * prev;
+ struct list_node entry;
int owner_client;
int sd;
struct sockaddr_storage local_addr;
@@ -252,15 +242,15 @@ iwpm_mapped_port *create_iwpm_mapped_port(struct sockaddr_storage *, int);
iwpm_mapped_port *reopen_iwpm_mapped_port(struct sockaddr_storage *, struct sockaddr_storage *, int);
-void add_iwpm_mapped_port(iwpm_mapped_port **, iwpm_mapped_port *);
+void add_iwpm_mapped_port(iwpm_mapped_port *);
-iwpm_mapped_port *find_iwpm_mapping(iwpm_mapped_port *, struct sockaddr_storage *, int);
+iwpm_mapped_port *find_iwpm_mapping(struct sockaddr_storage *, int);
-iwpm_mapped_port *find_iwpm_same_mapping(iwpm_mapped_port *, struct sockaddr_storage *, int);
+iwpm_mapped_port *find_iwpm_same_mapping(struct sockaddr_storage *, int);
-void remove_iwpm_mapped_port(iwpm_mapped_port **, iwpm_mapped_port *);
+void remove_iwpm_mapped_port(iwpm_mapped_port *);
-void print_iwpm_mapped_ports(iwpm_mapped_port *);
+void print_iwpm_mapped_ports(void);
void free_iwpm_port(iwpm_mapped_port *);
@@ -284,10 +274,6 @@ int add_iwpm_pending_msg(iwpm_send_msg *);
int check_same_sockaddr(struct sockaddr_storage *, struct sockaddr_storage *);
-void add_list_element(iwpm_list **, iwpm_list **, int);
-
-void remove_list_element(iwpm_list **, iwpm_list *, int);
-
void free_iwpm_mapped_ports(void);
extern struct list_head pending_messages;
diff --git a/iwpmd/iwarp_pm_helper.c b/iwpmd/iwarp_pm_helper.c
index 8aa8e40..dcd1ca9 100644
--- a/iwpmd/iwarp_pm_helper.c
+++ b/iwpmd/iwarp_pm_helper.c
@@ -33,8 +33,7 @@
#include "iwarp_pm.h"
-extern iwpm_mapped_port *mapped_ports;
-extern iwpm_mapped_port *pending_ports;
+static LIST_HEAD(mapped_ports); /* list of mapped ports */
extern pthread_cond_t cond_req_complete;
extern pthread_mutex_t map_req_mutex;
@@ -417,10 +416,9 @@ reopen_mapped_port_error:
/**
* add_iwpm_mapped_port - Add mapping to a global list
- * @iwpm_ports: list where to save the mapping
* @iwpm_port: mapping to be saved
*/
-void add_iwpm_mapped_port(iwpm_mapped_port **iwpm_ports, iwpm_mapped_port *iwpm_port)
+void add_iwpm_mapped_port(iwpm_mapped_port *iwpm_port)
{
static int dbg_idx = 1;
iwpm_debug(IWARP_PM_ALL_DBG, "add_iwpm_mapped_port: Adding a new mapping #%d\n", dbg_idx++);
@@ -429,8 +427,7 @@ void add_iwpm_mapped_port(iwpm_mapped_port **iwpm_ports, iwpm_mapped_port *iwpm_
if (iwpm_port->ref_cnt > 1)
return;
}
- add_list_element((iwpm_list **)iwpm_ports, (iwpm_list **)&iwpm_port,
- IWPM_LIST_MAPPED_PORTS);
+ list_add(&mapped_ports, &iwpm_port->entry);
}
/**
@@ -474,7 +471,6 @@ int check_same_sockaddr(struct sockaddr_storage *sockaddr_a, struct sockaddr_sto
/**
* find_iwpm_mapping - Find saved mapped port object
- * @iwpm_ports: list of mapped port object
* @search_addr: IP address and port to search for in the list
* @not_mapped: if set, compare local addresses, otherwise compare mapped addresses
*
@@ -482,13 +478,13 @@ int check_same_sockaddr(struct sockaddr_storage *sockaddr_a, struct sockaddr_sto
* to find a saved port object with the sockaddr or
* a wild card address with the same tcp port
*/
-iwpm_mapped_port *find_iwpm_mapping(iwpm_mapped_port *iwpm_ports,
- struct sockaddr_storage *search_addr, int not_mapped)
+iwpm_mapped_port *find_iwpm_mapping(struct sockaddr_storage *search_addr,
+ int not_mapped)
{
iwpm_mapped_port *iwpm_port, *saved_iwpm_port = NULL;
struct sockaddr_storage *current_addr;
- for (iwpm_port = iwpm_ports; iwpm_port != NULL; iwpm_port = iwpm_port->next) {
+ list_for_each(&mapped_ports, iwpm_port, entry) {
current_addr = (not_mapped)? &iwpm_port->local_addr : &iwpm_port->mapped_addr;
if (get_sockaddr_port(search_addr) == get_sockaddr_port(current_addr)) {
@@ -505,20 +501,19 @@ find_mapping_exit:
/**
* find_iwpm_same_mapping - Find saved mapped port object
- * @iwpm_ports: list of mapped port object
* @search_addr: IP address and port to search for in the list
* @not_mapped: if set, compare local addresses, otherwise compare mapped addresses
*
* Compares the search_sockaddr to the addresses in the list,
* to find a saved port object with the same sockaddr
*/
-iwpm_mapped_port *find_iwpm_same_mapping(iwpm_mapped_port *iwpm_ports,
- struct sockaddr_storage *search_addr, int not_mapped)
+iwpm_mapped_port *find_iwpm_same_mapping(struct sockaddr_storage *search_addr,
+ int not_mapped)
{
iwpm_mapped_port *iwpm_port, *saved_iwpm_port = NULL;
struct sockaddr_storage *current_addr;
- for (iwpm_port = iwpm_ports; iwpm_port != NULL; iwpm_port = iwpm_port->next) {
+ list_for_each(&mapped_ports, iwpm_port, entry) {
current_addr = (not_mapped)? &iwpm_port->local_addr : &iwpm_port->mapped_addr;
if (check_same_sockaddr(search_addr, current_addr)) {
saved_iwpm_port = iwpm_port;
@@ -556,29 +551,27 @@ void free_iwpm_port(iwpm_mapped_port *iwpm_port)
/**
* remove_iwpm_mapped_port - Remove a mapping from a global list
- * @iwpm_ports: list from which the mapping needs to be removed
* @iwpm_port: mapping to be removed
*
* Called only by the main iwarp port mapper thread
*/
-void remove_iwpm_mapped_port(iwpm_mapped_port **iwpm_ports, iwpm_mapped_port *iwpm_port)
+void remove_iwpm_mapped_port(iwpm_mapped_port *iwpm_port)
{
static int dbg_idx = 1;
iwpm_debug(IWARP_PM_ALL_DBG, "remove_iwpm_mapped_port: index = %d\n", dbg_idx++);
- remove_list_element((iwpm_list **)iwpm_ports, (iwpm_list *)iwpm_port,
- IWPM_LIST_MAPPED_PORTS);
+ list_del(&iwpm_port->entry);
}
-void print_iwpm_mapped_ports(iwpm_mapped_port *iwpm_ports)
+void print_iwpm_mapped_ports(void)
{
iwpm_mapped_port *iwpm_port;
- int i;
+ int i = 0;
syslog(LOG_WARNING, "print_iwpm_mapped_ports:\n");
- for (iwpm_port = iwpm_ports, i = 0; iwpm_port != NULL; iwpm_port = iwpm_port->next, i++) {
- syslog(LOG_WARNING, "Mapping #%d\n", i);
+ list_for_each(&mapped_ports, iwpm_port, entry) {
+ syslog(LOG_WARNING, "Mapping #%d\n", i++);
print_iwpm_sockaddr(&iwpm_port->local_addr, "Local address", IWARP_PM_DEBUG);
print_iwpm_sockaddr(&iwpm_port->mapped_addr, "Mapped address", IWARP_PM_DEBUG);
}
@@ -616,55 +609,6 @@ int add_iwpm_pending_msg(iwpm_send_msg *send_msg)
return 0;
}
-/*
- * assign_list_head - Make list_element the first element in the list
- * (i.e. *list = *list_element)
- */
-static void assign_list_head(iwpm_list **list, iwpm_list *list_element, int list_type)
-{
- iwpm_mapped_port **ports;
-
- switch (list_type) {
- case IWPM_LIST_MAPPED_PORTS:
- ports = (iwpm_mapped_port **)list;
- *ports = (iwpm_mapped_port *)list_element;
- break;
- default:
- break;
- }
-}
-
-/**
- * add_list_element - Add element to a doubly linked list
- */
-void add_list_element(iwpm_list **list, iwpm_list **list_element, int list_type)
-{
- /* add element to the beginning of the list*/
- (*list_element)->next = *list;
- if (*list)
- (*list)->prev = *list_element;
- (*list_element)->prev = NULL;
- assign_list_head(list, *list_element, list_type);
-}
-
-/**
- * remove_list_element - Remove element from a doubly linked list
- */
-void remove_list_element(iwpm_list **list, iwpm_list *list_element, int list_type)
-{
- /* remove element from the list */
- if (list_element->prev) {
- list_element->prev->next = list_element->next;
- if (list_element->next)
- list_element->next->prev = list_element->prev;
- } else {
- /* remove first element */
- assign_list_head(list, list_element->next, list_type);
- if (*list)
- (*list)->prev = NULL;
- }
-}
-
/**
* free_iwpm_mapped_ports - Free all iwpm mapped port objects
*/
@@ -672,10 +616,6 @@ void free_iwpm_mapped_ports(void)
{
iwpm_mapped_port *iwpm_port;
- while (mapped_ports) {
- iwpm_port = mapped_ports;
- mapped_ports = mapped_ports->next;
+ while ((iwpm_port = list_pop(&mapped_ports, iwpm_mapped_port, entry)))
free_iwpm_port(iwpm_port);
- }
- mapped_ports = NULL;
}
diff --git a/iwpmd/iwarp_pm_server.c b/iwpmd/iwarp_pm_server.c
index db73c6f..a9ca685 100644
--- a/iwpmd/iwarp_pm_server.c
+++ b/iwpmd/iwarp_pm_server.c
@@ -37,7 +37,6 @@
const char iwpm_ulib_name [] = "iWarpPortMapperUser";
int iwpm_version = 3;
-iwpm_mapped_port *mapped_ports = NULL; /* list of mapped ports */
LIST_HEAD(mapping_reqs); /* list of map tracking objects */
LIST_HEAD(pending_messages); /* list of pending wire messages */
iwpm_client client_list[IWARP_PM_MAX_CLIENTS];/* list of iwarp port mapper clients */
@@ -325,7 +324,7 @@ static int process_iwpm_add_mapping(struct nlmsghdr *req_nlh, int client_idx, in
}
local_addr = (struct sockaddr_storage *)nla_data(nltb[IWPM_NLA_MANAGE_ADDR]);
- iwpm_port = find_iwpm_mapping(mapped_ports, local_addr, not_mapped);
+ iwpm_port = find_iwpm_mapping(local_addr, not_mapped);
if (iwpm_port) {
if (check_same_sockaddr(local_addr, &iwpm_port->local_addr) && iwpm_port->wcard) {
iwpm_port->ref_cnt++;
@@ -366,7 +365,7 @@ static int process_iwpm_add_mapping(struct nlmsghdr *req_nlh, int client_idx, in
goto add_mapping_free_error;
}
/* add the new mapping to the list */
- add_iwpm_mapped_port(&mapped_ports, iwpm_port);
+ add_iwpm_mapped_port(iwpm_port);
nlmsg_free(resp_nlmsg);
return 0;
@@ -432,7 +431,7 @@ static int process_iwpm_query_mapping(struct nlmsghdr *req_nlh, int client_idx,
local_addr = (struct sockaddr_storage *)nla_data(nltb[IWPM_NLA_QUERY_LOCAL_ADDR]);
remote_addr = (struct sockaddr_storage *)nla_data(nltb[IWPM_NLA_QUERY_REMOTE_ADDR]);
- iwpm_port = find_iwpm_mapping(mapped_ports, local_addr, not_mapped);
+ iwpm_port = find_iwpm_mapping(local_addr, not_mapped);
if (iwpm_port) {
err_code = IWPM_DUPLICATE_MAPPING_ERR;
str_err = "Duplicate mapped port";
@@ -497,7 +496,7 @@ static int process_iwpm_query_mapping(struct nlmsghdr *req_nlh, int client_idx,
form_iwpm_send_msg(pm_client_sock, &dest_addr.s_sockaddr, msg_parms.msize, send_msg);
add_iwpm_map_request(iwpm_map_req);
- add_iwpm_mapped_port(&mapped_ports, iwpm_port);
+ add_iwpm_mapped_port(iwpm_port);
return send_iwpm_msg(form_iwpm_request, &msg_parms, &dest_addr.s_sockaddr, pm_client_sock);
query_mapping_free_error:
if (iwpm_port)
@@ -542,7 +541,7 @@ static int process_iwpm_remove_mapping(struct nlmsghdr *req_nlh, int client_idx,
iwpm_debug(IWARP_PM_NETLINK_DBG, "process_remove_mapping: Going to remove mapping"
" (client idx = %d)\n", client_idx);
- iwpm_port = find_iwpm_same_mapping(mapped_ports, local_addr, not_mapped);
+ iwpm_port = find_iwpm_same_mapping(local_addr, not_mapped);
if (!iwpm_port) {
iwpm_debug(IWARP_PM_NETLINK_DBG, "process_remove_mapping: Unable to find mapped port object\n");
print_iwpm_sockaddr(local_addr, "process_remove_mapping: Local address", IWARP_PM_ALL_DBG);
@@ -560,7 +559,7 @@ static int process_iwpm_remove_mapping(struct nlmsghdr *req_nlh, int client_idx,
if (ref_cnt)
goto remove_mapping_exit;
}
- remove_iwpm_mapped_port(&mapped_ports, iwpm_port);
+ remove_iwpm_mapped_port(iwpm_port);
free_iwpm_port(iwpm_port);
remove_mapping_exit:
return ret;
@@ -641,7 +640,7 @@ static int process_iwpm_wire_request(iwpm_msg_parms *msg_parms, int nl_sock,
copy_iwpm_sockaddr(msg_parms->address_family, NULL, &local_addr,
&msg_parms->apipaddr[0], NULL, &msg_parms->apport);
- iwpm_port = find_iwpm_mapping(mapped_ports, &local_addr, not_mapped);
+ iwpm_port = find_iwpm_mapping(&local_addr, not_mapped);
if (!iwpm_port) {
/* could not find mapping for the requested address */
iwpm_debug(IWARP_PM_WIRE_DBG, "process_wire_request: "
@@ -737,7 +736,7 @@ static int process_iwpm_wire_accept(iwpm_msg_parms *msg_parms, int nl_sock,
copy_iwpm_sockaddr(msg_parms->address_family, NULL, &remote_mapped_addr,
&msg_parms->apipaddr[0], NULL, &msg_parms->apport);
ret = -EINVAL;
- iwpm_port = find_iwpm_same_mapping(mapped_ports, &local_addr, not_mapped);
+ iwpm_port = find_iwpm_same_mapping(&local_addr, not_mapped);
if (!iwpm_port) {
iwpm_debug(IWARP_PM_WIRE_DBG, "process_wire_accept: "
"Received accept for unknown mapping.\n");
@@ -812,7 +811,7 @@ static int process_iwpm_wire_reject(iwpm_msg_parms *msg_parms, int nl_sock)
print_iwpm_sockaddr(&remote_addr, "process_wire_reject: Remote address",
IWARP_PM_ALL_DBG);
ret = -EINVAL;
- iwpm_port = find_iwpm_same_mapping(mapped_ports, &local_addr, not_mapped);
+ iwpm_port = find_iwpm_same_mapping(&local_addr, not_mapped);
if (!iwpm_port) {
syslog(LOG_WARNING, "process_wire_reject: Received reject for unknown mapping.\n");
return 0;
@@ -857,7 +856,7 @@ static int process_iwpm_wire_ack(iwpm_msg_parms *msg_parms)
copy_iwpm_sockaddr(msg_parms->address_family, NULL, &local_mapped_addr,
&msg_parms->apipaddr[0], NULL, &msg_parms->apport);
- iwpm_port = find_iwpm_mapping(mapped_ports, &local_mapped_addr, not_mapped);
+ iwpm_port = find_iwpm_mapping(&local_mapped_addr, not_mapped);
if (!iwpm_port) {
iwpm_debug(IWARP_PM_WIRE_DBG, "process_wire_ack: Received ack for unknown mapping.\n");
return 0;
@@ -905,7 +904,7 @@ static int process_iwpm_mapinfo(struct nlmsghdr *req_nlh, int client_idx, int nl
local_addr = (struct sockaddr_storage *)nla_data(nltb[IWPM_NLA_MAPINFO_LOCAL_ADDR]);
local_mapped_addr = (struct sockaddr_storage *)nla_data(nltb[IWPM_NLA_MAPINFO_MAPPED_ADDR]);
- iwpm_port = find_iwpm_mapping(mapped_ports, local_addr, not_mapped);
+ iwpm_port = find_iwpm_mapping(local_addr, not_mapped);
if (iwpm_port) {
/* Can be safely ignored, if the mapinfo is exactly the same,
* because the client will provide all the port information it has and
@@ -926,7 +925,7 @@ static int process_iwpm_mapinfo(struct nlmsghdr *req_nlh, int client_idx, int nl
goto process_mapinfo_error;
}
/* add the new mapping to the list */
- add_iwpm_mapped_port(&mapped_ports, iwpm_port);
+ add_iwpm_mapped_port(iwpm_port);
process_mapinfo_exit:
mapinfo_num_list[client_idx]++;
return 0;
@@ -1301,7 +1300,7 @@ static int iwarp_port_mapper()
do {
do {
if (print_mappings) {
- print_iwpm_mapped_ports(mapped_ports);
+ print_iwpm_mapped_ports();
print_mappings = 0;
}
/* initialize the file sets for select */
--
2.10.1.382.ga23ca1b
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: switch iwpm to ccan list.h
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
` (2 preceding siblings ...)
2016-10-10 9:41 ` [PATCH 3/3] iwpmd: use ccan list.h for mapped_ports Christoph Hellwig
@ 2016-10-10 14:07 ` Bart Van Assche
2016-10-11 14:57 ` Steve Wise
2016-10-13 8:56 ` Leon Romanovsky
5 siblings, 0 replies; 7+ messages in thread
From: Bart Van Assche @ 2016-10-10 14:07 UTC (permalink / raw)
To: Christoph Hellwig, Tatyana.E.Nikolova-ral2JQCrhuEAvxtiuMwx3w,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
robert.o.sharp-ral2JQCrhuEAvxtiuMwx3w
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
On 10/10/16 02:41, Christoph Hellwig wrote:
> I've started running sparse on the rdma-core code, and one of the
> worst offenders is the iwpmd list code, so this (untested) patch
> set converts it over to the ccan list.h helpers. Reviews and
> testing appreciated.
For the whole series:
Reviewed-by: Bart Van Assche <bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: switch iwpm to ccan list.h
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
` (3 preceding siblings ...)
2016-10-10 14:07 ` switch iwpm to ccan list.h Bart Van Assche
@ 2016-10-11 14:57 ` Steve Wise
2016-10-13 8:56 ` Leon Romanovsky
5 siblings, 0 replies; 7+ messages in thread
From: Steve Wise @ 2016-10-11 14:57 UTC (permalink / raw)
To: 'Christoph Hellwig',
Tatyana.E.Nikolova-ral2JQCrhuEAvxtiuMwx3w,
robert.o.sharp-ral2JQCrhuEAvxtiuMwx3w
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA
>
> I've started running sparse on the rdma-core code, and one of the
> worst offenders is the iwpmd list code, so this (untested) patch
> set converts it over to the ccan list.h helpers. Reviews and
> testing appreciated.
Looks good...tests out ok.
Acked-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
Tested-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: switch iwpm to ccan list.h
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
` (4 preceding siblings ...)
2016-10-11 14:57 ` Steve Wise
@ 2016-10-13 8:56 ` Leon Romanovsky
5 siblings, 0 replies; 7+ messages in thread
From: Leon Romanovsky @ 2016-10-13 8:56 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Tatyana.E.Nikolova-ral2JQCrhuEAvxtiuMwx3w,
swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW,
robert.o.sharp-ral2JQCrhuEAvxtiuMwx3w,
linux-rdma-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 536 bytes --]
On Mon, Oct 10, 2016 at 11:41:51AM +0200, Christoph Hellwig wrote:
> I've started running sparse on the rdma-core code, and one of the
> worst offenders is the iwpmd list code, so this (untested) patch
> set converts it over to the ccan list.h helpers. Reviews and
> testing appreciated.
Thanks, applied.
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-13 8:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-10 9:41 switch iwpm to ccan list.h Christoph Hellwig
[not found] ` <1476092514-18188-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-10-10 9:41 ` [PATCH 1/3] iwpmd: use ccan list.h for pending_messages Christoph Hellwig
2016-10-10 9:41 ` [PATCH 2/3] iwpmd: use ccan list.h for mapping_reqs Christoph Hellwig
2016-10-10 9:41 ` [PATCH 3/3] iwpmd: use ccan list.h for mapped_ports Christoph Hellwig
2016-10-10 14:07 ` switch iwpm to ccan list.h Bart Van Assche
2016-10-11 14:57 ` Steve Wise
2016-10-13 8:56 ` Leon Romanovsky
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.