diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-12-15 13:23:09 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-12-18 17:25:34 +0100 |
commit | 08c72b84d85d482f030a30cf74786695f097e91c (patch) | |
tree | b86b9e4f70d31859377ab267d23cf088387b6ef3 /src/responder/autofs | |
parent | 06cb67c391dd8c2b1542a7d87fb5568fdad448cb (diff) | |
download | sssd-08c72b84d85d482f030a30cf74786695f097e91c.tar.gz sssd-08c72b84d85d482f030a30cf74786695f097e91c.tar.bz2 sssd-08c72b84d85d482f030a30cf74786695f097e91c.zip |
AUTOFS: allow removing entries from hash table
There is a timed desctructor in the autofs responder that, when the
entry timeout passes, removes the autofs map from the hash table while
the map is freed. This patch adds a hash delete callback so that if the
map is removed from the hash table with hash_delete, its hash table
pointer will be invalidated. Later, when the entry is being freed, the
destructor won't attempt to remove it from the hash table.
Diffstat (limited to 'src/responder/autofs')
-rw-r--r-- | src/responder/autofs/autofs_private.h | 3 | ||||
-rw-r--r-- | src/responder/autofs/autofssrv.c | 3 | ||||
-rw-r--r-- | src/responder/autofs/autofssrv_cmd.c | 27 |
3 files changed, 32 insertions, 1 deletions
diff --git a/src/responder/autofs/autofs_private.h b/src/responder/autofs/autofs_private.h index bb0c6189..a2af36e4 100644 --- a/src/responder/autofs/autofs_private.h +++ b/src/responder/autofs/autofs_private.h @@ -76,6 +76,9 @@ struct autofs_map_ctx { struct sss_cmd_table *get_autofs_cmds(void); +void autofs_map_hash_delete_cb(hash_entry_t *item, + hash_destroy_enum deltype, void *pvt); + enum sss_dp_autofs_type { SSS_DP_AUTOFS }; diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c index 86a816a3..d7c10d6c 100644 --- a/src/responder/autofs/autofssrv.c +++ b/src/responder/autofs/autofssrv.c @@ -158,7 +158,8 @@ autofs_process_init(TALLOC_CTX *mem_ctx, } /* Create the lookup table for setautomntent results */ - hret = sss_hash_create(autofs_ctx, 10, &autofs_ctx->maps); + hret = sss_hash_create_ex(autofs_ctx, 10, &autofs_ctx->maps, 0, 0, 0, 0, + autofs_map_hash_delete_cb, NULL); if (hret != HASH_SUCCESS) { DEBUG(SSSDBG_CRIT_FAILURE, ("Unable to initialize automount maps hash table\n")); diff --git a/src/responder/autofs/autofssrv_cmd.c b/src/responder/autofs/autofssrv_cmd.c index 3af4a846..0cfdbec5 100644 --- a/src/responder/autofs/autofssrv_cmd.c +++ b/src/responder/autofs/autofssrv_cmd.c @@ -118,6 +118,27 @@ get_autofs_map(struct autofs_ctx *actx, static int autofs_map_hash_remove (TALLOC_CTX *ctx); +void +autofs_map_hash_delete_cb(hash_entry_t *item, + hash_destroy_enum deltype, void *pvt) +{ + struct autofs_map_ctx *map; + + if (deltype != HASH_ENTRY_DESTROY) { + return; + } + + map = talloc_get_type(item->value.ptr, struct autofs_map_ctx); + if (!map) { + DEBUG(SSSDBG_OP_FAILURE, ("Invalid autofs map\n")); + return; + } + + /* So that the destructor wouldn't attempt to remove the map from hash + * table */ + map->map_table = NULL; +} + static errno_t set_autofs_map(struct autofs_ctx *actx, struct autofs_map_ctx *map) @@ -158,6 +179,12 @@ autofs_map_hash_remove(TALLOC_CTX *ctx) struct autofs_map_ctx *map = talloc_get_type(ctx, struct autofs_map_ctx); + if (map->map_table == NULL) { + DEBUG(SSSDBG_TRACE_LIBS, ("autofs map [%s] was already removed\n", + map->mapname)); + return 0; + } + key.type = HASH_KEY_STRING; key.str = map->mapname; |