/* * Free a map. */ void mapc_free(mnt_map *m) { /* * Decrement the reference count. * If the reference count hits zero * then throw the map away. */ if (m && --m->refc == 0) { mapc_clear(m); free((void *)m->map_name); rem_que(&m->hdr); free((void *)m); } }
/* * Get map cache in sync with physical representation */ static void mapc_sync(mnt_map *m) { if (m->alloc != MAPC_ROOT) { mapc_clear(m); if (m->alloc >= MAPC_ALL) if (mapc_reload_map(m)) m->alloc = MAPC_INC; /* * Attempt to find the wildcard entry */ if (m->alloc < MAPC_ALL) mapc_find_wildcard(m); } }
/* * Do a map reload. * Attempt to reload without losing current data by switching the hashes * round. * If reloading was needed and succeeded, return 1; else return 0. */ static int mapc_reload_map(mnt_map *m) { int error, ret = 0; kv *maphash[NKVHASH]; time_t t; error = (*m->mtime) (m, m->map_name, &t); if (error) { t = m->modify; } /* * skip reloading maps that have not been modified, unless * amq -f was used (do_mapc_reload is 0) */ if (m->reloads != 0 && do_mapc_reload != 0) { if (t <= m->modify) { plog(XLOG_INFO, "reload of map %s is not needed (in sync)", m->map_name); dlog("map %s last load time is %d, last modify time is %d", m->map_name, (int) m->modify, (int) t); return ret; } } /* copy the old hash and zero the map */ memcpy((voidp) maphash, (voidp) m->kvhash, sizeof(m->kvhash)); memset((voidp) m->kvhash, 0, sizeof(m->kvhash)); dlog("calling map reload on %s", m->map_name); m->nentries = 0; error = (*m->reload) (m, m->map_name, mapc_add_kv); if (error) { if (m->reloads == 0) plog(XLOG_FATAL, "first time load of map %s failed!", m->map_name); else plog(XLOG_ERROR, "reload of map %s failed - using old values", m->map_name); mapc_clear(m); memcpy((voidp) m->kvhash, (voidp) maphash, sizeof(m->kvhash)); } else { if (m->reloads++ == 0) plog(XLOG_INFO, "first time load of map %s succeeded", m->map_name); else plog(XLOG_INFO, "reload #%d of map %s succeeded", m->reloads, m->map_name); mapc_clear_kvhash(maphash); if (m->wildcard) { XFREE(m->wildcard); m->wildcard = NULL; } m->modify = t; ret = 1; } dlog("calling mapc_search for wildcard"); error = mapc_search(m, wildcard, &m->wildcard); if (error) m->wildcard = NULL; return ret; }