>From 12a4ceeb6d635d2fbc86c4d82627bf8222be8f35 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sat, 15 Dec 2012 13:22:34 +0100 Subject: [PATCH 5/7] AUTOFS: remove all maps from hash if request for auto.master comes in https://fedorahosted.org/sssd/ticket/1592 When a request for auto.master comes in, we need to remove all the maps from the lookup hash table. We can't simply delete the maps, because another request might be processing them, so instead the maps are removed from the hash table, effectively becoming orphaned. The maps will get freed when the timed destructor is invoked. --- src/responder/autofs/autofs_private.h | 2 ++ src/responder/autofs/autofssrv_cmd.c | 60 +++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/responder/autofs/autofs_private.h b/src/responder/autofs/autofs_private.h index a2af36e40115c02301594bca12c45411513b2174..58445f35b584b1a42debe97eb67b3bb2af1c417e 100644 --- a/src/responder/autofs/autofs_private.h +++ b/src/responder/autofs/autofs_private.h @@ -79,6 +79,8 @@ struct sss_cmd_table *get_autofs_cmds(void); void autofs_map_hash_delete_cb(hash_entry_t *item, hash_destroy_enum deltype, void *pvt); +errno_t autofs_orphan_maps(struct autofs_ctx *actx); + enum sss_dp_autofs_type { SSS_DP_AUTOFS }; diff --git a/src/responder/autofs/autofssrv_cmd.c b/src/responder/autofs/autofssrv_cmd.c index 0cfdbec59c8adcd5bb0c4727876a16e0bef8a026..b85079d0dde5f4f783922748f4061444d9f6c217 100644 --- a/src/responder/autofs/autofssrv_cmd.c +++ b/src/responder/autofs/autofssrv_cmd.c @@ -90,6 +90,34 @@ autofs_setent_notify(struct autofs_map_ctx *map_ctx, errno_t ret) setent_notify(&map_ctx->reqs, ret); } +errno_t +autofs_orphan_maps(struct autofs_ctx *actx) +{ + int hret; + unsigned long mcount; + unsigned long i; + hash_key_t *maps; + + if (!actx || !actx->maps) { + return EINVAL; + } + + hret = hash_keys(actx->maps, &mcount, &maps); + if (hret != HASH_SUCCESS) { + return EIO; + } + + for (i = 0; i < mcount; i++) { + hret = hash_delete(actx->maps, &maps[i]); + if (hret != HASH_SUCCESS) { + DEBUG(SSSDBG_MINOR_FAILURE, ("Could not delete key from hash\n")); + continue; + } + } + + return EOK; +} + static errno_t get_autofs_map(struct autofs_ctx *actx, char *mapname, @@ -369,6 +397,11 @@ set_autofs_map_lifetime(uint32_t lifetime, } } +static errno_t +setautomntent_get_autofs_map(struct autofs_ctx *actx, + char *mapname, + struct autofs_map_ctx **map); + static struct tevent_req * setautomntent_send(TALLOC_CTX *mem_ctx, const char *rawname, @@ -442,7 +475,7 @@ setautomntent_send(TALLOC_CTX *mem_ctx, /* Is the result context already available? * Check for existing lookups for this map */ - ret = get_autofs_map(actx, state->mapname, &state->map); + ret = setautomntent_get_autofs_map(actx, state->mapname, &state->map); if (ret == EOK) { /* Another process already requested this map * Check whether it's ready for processing. @@ -559,6 +592,25 @@ fail: } static errno_t +setautomntent_get_autofs_map(struct autofs_ctx *actx, + char *mapname, + struct autofs_map_ctx **map) +{ + errno_t ret; + + if (strcmp(mapname, "auto.master") == 0) { + /* Iterate over the hash and remove all maps */ + ret = autofs_orphan_maps(actx); + if (ret != EOK) { + DEBUG(SSSDBG_MINOR_FAILURE, ("Could not remove existing maps from hash\n")); + } + return ENOENT; + } + + return get_autofs_map(actx, mapname, map); +} + +static errno_t lookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx); static errno_t @@ -718,8 +770,10 @@ lookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx) struct dp_callback_ctx *cb_ctx = NULL; if (dctx->map != NULL) { - cache_expire = ldb_msg_find_attr_as_uint64(dctx->map, - SYSDB_CACHE_EXPIRE, 0); + if (strcmp(lookup_ctx->mapname, "auto.master") != 0) { + cache_expire = ldb_msg_find_attr_as_uint64(dctx->map, + SYSDB_CACHE_EXPIRE, 0); + } /* if we have any reply let's check cache validity */ ret = sss_cmd_check_cache(dctx->map, 0, cache_expire); -- 1.8.0.2