Change in osmo-remsim[master]: slotmap: Introduce the concept of a slotmap state

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Mar 7 17:34:46 UTC 2019


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/13179


Change subject: slotmap: Introduce the concept of a slotmap state
......................................................................

slotmap: Introduce the concept of a slotmap state

... which is required in remsim-server

Change-Id: I56f5ecd6194ef62c87d87d2965ca0315e3d0fc2d
---
M src/slotmap.c
M src/slotmap.h
2 files changed, 80 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-remsim refs/changes/79/13179/1

diff --git a/src/slotmap.c b/src/slotmap.c
index a3ae792..924452b 100644
--- a/src/slotmap.c
+++ b/src/slotmap.c
@@ -9,9 +9,18 @@
 #include <talloc.h>
 
 #include <osmocom/core/linuxlist.h>
+#include <osmocom/core/utils.h>
 
 #include "slotmap.h"
 
+const struct value_string slot_map_state_name[] = {
+	{ SLMAP_S_NEW,			"NEW" },
+	{ SLMAP_S_UNACKNOWLEDGED,	"UNACKNOWLEDGED" },
+	{ SLMAP_S_ACTIVE,		"ACTIVE" },
+	{ SLMAP_S_DELETING,		"DELETING" },
+	{ 0, NULL }
+};
+
 const char *slotmap_name(char *buf, size_t buf_len, const struct slot_mapping *map)
 {
 	snprintf(buf, buf_len, "B(%u:%u) <-> C(%u:%u)",
@@ -82,11 +91,16 @@
 	if (!map)
 		return -ENOMEM;
 
+	map->maps = maps;
 	map->bank = *bank;
 	map->client = *client;
 
 	pthread_rwlock_wrlock(&maps->rwlock);
 	llist_add_tail(&map->list, &maps->mappings);
+#ifdef REMSIM_SERVER
+	map->state = SLMAP_S_NEW;
+	INIT_LLIST_HEAD(&map->bank_list); /* to ensure llist_del() always succeeds */
+#endif
 	pthread_rwlock_unlock(&maps->rwlock);
 
 	printf("Slot Map %s added\n", slotmap_name(mapname, sizeof(mapname), map));
@@ -103,6 +117,9 @@
 
 	pthread_rwlock_wrlock(&maps->rwlock);
 	llist_del(&map->list);
+#ifdef REMSIM_SERVER
+	llist_del(&map->bank_list);
+#endif
 	pthread_rwlock_unlock(&maps->rwlock);
 
 	talloc_free(map);
@@ -117,3 +134,37 @@
 
 	return sm;
 }
+
+#ifdef REMSIM_SERVER
+
+void _slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state,
+			   struct llist_head *new_bank_list)
+{
+	char mapname[64];
+
+	printf("Slot Map %s state change: %s -> %s\n", slotmap_name(mapname, sizeof(mapname), map),
+		get_value_string(slot_map_state_name, map->state),
+		get_value_string(slot_map_state_name, new_state));
+
+	map->state = new_state;
+#ifdef REMSIM_SERVER
+	llist_del(&map->bank_list);
+#endif
+	if (new_bank_list)
+		llist_add_tail(&map->bank_list, new_bank_list);
+#ifdef REMSIM_SERVER
+	else
+		INIT_LLIST_HEAD(&map->bank_list);
+#endif
+}
+
+
+void slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state,
+			  struct llist_head *new_bank_list)
+{
+	pthread_rwlock_wrlock(&map->maps->rwlock);
+	_slotmap_state_change(map, new_state, new_bank_list);
+	pthread_rwlock_unlock(&map->maps->rwlock);
+}
+
+#endif
diff --git a/src/slotmap.h b/src/slotmap.h
index 92eb6f4..27d7e1b 100644
--- a/src/slotmap.h
+++ b/src/slotmap.h
@@ -4,6 +4,8 @@
 #include <pthread.h>
 #include <osmocom/core/linuxlist.h>
 
+#define REMSIM_SERVER 1
+
 struct bank_slot {
 	uint16_t bank_id;
 	uint16_t slot_nr;
@@ -30,14 +32,33 @@
 		return false;
 }
 
+enum slot_mapping_state {
+	SLMAP_S_NEW,		/* created; not yet sent to bankd */
+	SLMAP_S_UNACKNOWLEDGED,	/* created + sent to bankd but not yet acknowledge by bankd */
+	SLMAP_S_ACTIVE,		/* fully active map; acknowledged by bankd */
+	SLMAP_S_DELETING,	/* we were asked to delete it; bankd hasn't confirmed yet */
+};
+extern const struct value_string slot_map_state_name[];
+static inline const char *slotmap_state_name(enum slot_mapping_state st)
+{
+	return get_value_string(slot_map_state_name, st);
+}
+
 /* slot mappings are created / removed by the server */
 struct slot_mapping {
 	/* global lits of bankd slot mappings */
 	struct llist_head list;
+	struct slotmaps *maps;
+
 	/* slot on bank side */
 	struct bank_slot bank;
 	/* slot on client side */
 	struct client_slot client;
+
+#ifdef REMSIM_SERVER
+	struct llist_head bank_list;
+	enum slot_mapping_state state;
+#endif
 };
 
 /* collection of slot mappings */
@@ -60,3 +81,11 @@
 
 /* initialize the entire map collection */
 struct slotmaps *slotmap_init(void *ctx);
+
+#ifdef REMSIM_SERVER
+void _slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state,
+			   struct llist_head *new_bank_list);
+/* thread-safe way to change the state of given slot map */
+void slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state,
+			  struct llist_head *new_bank_list);
+#endif

-- 
To view, visit https://gerrit.osmocom.org/13179
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I56f5ecd6194ef62c87d87d2965ca0315e3d0fc2d
Gerrit-Change-Number: 13179
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190307/2e149463/attachment.htm>


More information about the gerrit-log mailing list