@@ -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
@@ -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;
}
@@ -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);
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@lst.de> --- iwpmd/iwarp_pm.h | 9 ++++----- iwpmd/iwarp_pm_helper.c | 22 +--------------------- iwpmd/iwarp_pm_server.c | 9 +++++---- 3 files changed, 10 insertions(+), 30 deletions(-)