slotmap: Return newly-created map from slotmap_add()

Change-Id: I1bc66fee1f457bcf9693491031d7d4c411fc582e
This commit is contained in:
Harald Welte 2019-03-03 21:54:52 +01:00
parent 91a0a4adda
commit f4e75043de
2 changed files with 7 additions and 6 deletions

View File

@ -63,7 +63,8 @@ struct slot_mapping *slotmap_by_bank(struct slotmaps *maps, const struct bank_sl
} }
/* thread-safe creating of a new bank<->client map */ /* thread-safe creating of a new bank<->client map */
int slotmap_add(struct slotmaps *maps, const struct bank_slot *bank, const struct client_slot *client) struct slot_mapping *slotmap_add(struct slotmaps *maps, const struct bank_slot *bank,
const struct client_slot *client)
{ {
struct slot_mapping *map; struct slot_mapping *map;
char mapname[64]; char mapname[64];
@ -76,20 +77,20 @@ int slotmap_add(struct slotmaps *maps, const struct bank_slot *bank, const struc
if (map) { if (map) {
fprintf(stderr, "BANKD %u:%u already in use, cannot add new map\n", fprintf(stderr, "BANKD %u:%u already in use, cannot add new map\n",
bank->bank_id, bank->slot_nr); bank->bank_id, bank->slot_nr);
return -EBUSY; return NULL;
} }
map = slotmap_by_client(maps, client); map = slotmap_by_client(maps, client);
if (map) { if (map) {
fprintf(stderr, "CLIENT %u:%u already in use, cannot add new map\n", fprintf(stderr, "CLIENT %u:%u already in use, cannot add new map\n",
client->client_id, client->slot_nr); client->client_id, client->slot_nr);
return -EBUSY; return NULL;
} }
/* allocate new mapping and add to list of mappings */ /* allocate new mapping and add to list of mappings */
map = talloc_zero(maps, struct slot_mapping); map = talloc_zero(maps, struct slot_mapping);
if (!map) if (!map)
return -ENOMEM; return NULL;
map->maps = maps; map->maps = maps;
map->bank = *bank; map->bank = *bank;
@ -105,7 +106,7 @@ int slotmap_add(struct slotmaps *maps, const struct bank_slot *bank, const struc
printf("Slot Map %s added\n", slotmap_name(mapname, sizeof(mapname), map)); printf("Slot Map %s added\n", slotmap_name(mapname, sizeof(mapname), map));
return 0; return map;
} }
/* thread-safe removal of a bank<->client map */ /* thread-safe removal of a bank<->client map */

View File

@ -74,7 +74,7 @@ struct slot_mapping *slotmap_by_client(struct slotmaps *maps, const struct clien
struct slot_mapping *slotmap_by_bank(struct slotmaps *maps, const struct bank_slot *bank); struct slot_mapping *slotmap_by_bank(struct slotmaps *maps, const struct bank_slot *bank);
/* thread-safe creating of a new bank<->client map */ /* thread-safe creating of a new bank<->client map */
int slotmap_add(struct slotmaps *maps, const struct bank_slot *bank, const struct client_slot *client); struct slot_mapping *slotmap_add(struct slotmaps *maps, const struct bank_slot *bank, const struct client_slot *client);
/* thread-safe removal of a bank<->client map */ /* thread-safe removal of a bank<->client map */
void slotmap_del(struct slotmaps *maps, struct slot_mapping *map); void slotmap_del(struct slotmaps *maps, struct slot_mapping *map);