DPDK patches and discussions
 help / color / mirror / Atom feed
From: Remy Horton <remy.horton@intel.com>
To: dev@dpdk.org
Cc: John McNamara <john.mcnamara@intel.com>
Subject: [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit
Date: Thu, 27 Apr 2017 13:37:06 +0100	[thread overview]
Message-ID: <1493296626-28128-3-git-send-email-remy.horton@intel.com> (raw)
In-Reply-To: <1493296626-28128-1-git-send-email-remy.horton@intel.com>

This patch adds the unlinking/unmapping of shared host memory
on termination of l2fwd-keepalive. Previously it was only
cleaned on re-running of the example application.

Fixes: e64833f2273a ("examples/l2fwd-keepalive: add sample application")

Signed-off-by: Remy Horton <remy.horton@intel.com>
---
 examples/l2fwd-keepalive/main.c |  6 ++++--
 examples/l2fwd-keepalive/shm.c  | 10 ++++++++++
 examples/l2fwd-keepalive/shm.h  |  9 +++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c
index 5fdbdef..3745348 100644
--- a/examples/l2fwd-keepalive/main.c
+++ b/examples/l2fwd-keepalive/main.c
@@ -567,6 +567,7 @@ main(int argc, char **argv)
 	unsigned lcore_id, rx_lcore_id;
 	unsigned nb_ports_in_mask = 0;
 	struct sigaction signal_handler;
+	struct rte_keepalive_shm *ka_shm;
 
 	memset(&signal_handler, 0, sizeof(signal_handler));
 	terminate_signal_received = 0;
@@ -751,9 +752,8 @@ main(int argc, char **argv)
 	rte_timer_subsystem_init();
 	rte_timer_init(&stats_timer);
 
+	ka_shm = NULL;
 	if (check_period > 0) {
-		struct rte_keepalive_shm *ka_shm;
-
 		ka_shm = rte_keepalive_shm_create();
 		if (ka_shm == NULL)
 			rte_exit(EXIT_FAILURE,
@@ -813,5 +813,7 @@ main(int argc, char **argv)
 			return -1;
 	}
 
+	if (ka_shm != NULL)
+		rte_keepalive_shm_cleanup(ka_shm);
 	return 0;
 }
diff --git a/examples/l2fwd-keepalive/shm.c b/examples/l2fwd-keepalive/shm.c
index 177aa5b..fbf5bd7 100644
--- a/examples/l2fwd-keepalive/shm.c
+++ b/examples/l2fwd-keepalive/shm.c
@@ -129,3 +129,13 @@ void rte_keepalive_relayed_state(struct rte_keepalive_shm *shm,
 				strerror(errno));
 	}
 }
+
+void rte_keepalive_shm_cleanup(struct rte_keepalive_shm *ka_shm)
+{
+	if (shm_unlink(RTE_KEEPALIVE_SHM_NAME) == -1 && errno != ENOENT)
+		printf("Warning: Error unlinking  %s (%s)\n",
+			RTE_KEEPALIVE_SHM_NAME, strerror(errno));
+
+	if (ka_shm && munmap(ka_shm, sizeof(struct rte_keepalive_shm)) != 0)
+		printf("Warning: munmap() failed\n");
+}
diff --git a/examples/l2fwd-keepalive/shm.h b/examples/l2fwd-keepalive/shm.h
index 25e1b61..66a6060 100644
--- a/examples/l2fwd-keepalive/shm.h
+++ b/examples/l2fwd-keepalive/shm.h
@@ -87,3 +87,12 @@ struct rte_keepalive_shm *rte_keepalive_shm_create(void);
 void rte_keepalive_relayed_state(struct rte_keepalive_shm *shm,
 	const int id_core, const enum rte_keepalive_state core_state,
 	uint64_t last_alive);
+
+/** Shutdown cleanup of shared host memory keepalive object.
+ * @param *shm
+ *  Pointer to SHM keepalive structure. May be NULL.
+ *
+ *  If *shm is NULL, this function will only attempt to remove the
+ *  shared host memory handle and not unmap the underlying memory.
+ */
+void rte_keepalive_shm_cleanup(struct rte_keepalive_shm *ka_shm);
-- 
2.5.5

  parent reply	other threads:[~2017-04-27 12:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27 12:37 [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Remy Horton
2017-04-27 12:37 ` [dpdk-dev] [PATCH v1 1/2] examples/l2fwd-keepalive: add graceful exit Remy Horton
2017-04-28  8:37   ` Mcnamara, John
2017-04-27 12:37 ` Remy Horton [this message]
2017-04-28  8:37   ` [dpdk-dev] [PATCH v1 2/2] examples/l2fwd-keepalive: add SHM cleanup on exit Mcnamara, John
2017-05-01 14:42 ` [dpdk-dev] [PATCH v1 0/2] l2fwd-keepalive: Termination cleanup Thomas Monjalon

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=1493296626-28128-3-git-send-email-remy.horton@intel.com \
    --to=remy.horton@intel.com \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.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).