From patchwork Mon Oct 10 09:41:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9369235 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DAA1260865 for ; Mon, 10 Oct 2016 09:42:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB84229434 for ; Mon, 10 Oct 2016 09:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFC20294E4; Mon, 10 Oct 2016 09:42:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28B1B29464 for ; Mon, 10 Oct 2016 09:42:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752274AbcJJJmE (ORCPT ); Mon, 10 Oct 2016 05:42:04 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:45017 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752263AbcJJJmD (ORCPT ); Mon, 10 Oct 2016 05:42:03 -0400 Received: from 80-109-146-114.cable.dynamic.surfer.at ([80.109.146.114] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1btX5u-0000Ol-B3; Mon, 10 Oct 2016 09:42:02 +0000 From: Christoph Hellwig To: Tatyana.E.Nikolova@intel.com, swise@opengridcomputing.com, robert.o.sharp@intel.com Cc: linux-rdma@vger.kernel.org Subject: [PATCH 1/3] iwpmd: use ccan list.h for pending_messages Date: Mon, 10 Oct 2016 11:41:52 +0200 Message-Id: <1476092514-18188-2-git-send-email-hch@lst.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1476092514-18188-1-git-send-email-hch@lst.de> References: <1476092514-18188-1-git-send-email-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include #include +#include #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);