diff --git a/CHANGELOG b/CHANGELOG index fe73ab8..b469121 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,6 +25,7 @@ - correction for expire of multi-mounts. - spelling corrections to release notes (Jeff Moyer). - expire individual submounts. +- add ino_index locking. 13/7/2006 autofs-5.0.1 rc1 -------------------------- diff --git a/include/automount.h b/include/automount.h index 267c7d1..3192c92 100644 --- a/include/automount.h +++ b/include/automount.h @@ -129,6 +129,7 @@ #define EXPIRE_RETRIES 25 struct mapent_cache { pthread_rwlock_t rwlock; unsigned int size; + pthread_mutex_t ino_index_mutex; struct list_head *ino_index; struct mapent **hash; }; diff --git a/lib/cache.c b/lib/cache.c index 432270b..35dfa5a 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -96,6 +96,7 @@ void cache_lock_cleanup(void *arg) struct mapent_cache *mc = (struct mapent_cache *) arg; cache_unlock(mc); + return; } void cache_multi_lock(struct mapent *me) @@ -128,6 +129,29 @@ void cache_multi_unlock(struct mapent *m return; } +void cache_multi_lock_cleanup(void *arg) +{ + struct mapent *me = (struct mapent *) arg; + cache_multi_unlock(me); + return; +} + +static inline void ino_index_lock(struct mapent_cache *mc) +{ + int status = pthread_mutex_lock(&mc->ino_index_mutex); + if (status) + fatal(status); + return; +} + +static inline void ino_index_unlock(struct mapent_cache *mc) +{ + int status = pthread_mutex_unlock(&mc->ino_index_mutex); + if (status) + fatal(status); + return; +} + struct mapent_cache *cache_init(struct map_source *map) { struct mapent_cache *mc; @@ -156,6 +180,10 @@ struct mapent_cache *cache_init(struct m return NULL; } + status = pthread_mutex_init(&mc->ino_index_mutex, NULL); + if (status) + fatal(status); + status = pthread_rwlock_init(&mc->rwlock, NULL); if (status) fatal(status); @@ -201,10 +229,12 @@ int cache_set_ino_index(struct mapent_ca if (!me) return 0; + ino_index_lock(mc); + list_del_init(&me->ino_index); list_add(&me->ino_index, &mc->ino_index[ino_index]); - me->dev = dev; me->ino = ino; + ino_index_unlock(mc); return 1; } @@ -216,6 +246,7 @@ struct mapent *cache_lookup_ino(struct m struct list_head *head, *p; unsigned int ino_index; + ino_index_lock(mc); ino_index = ino_hash(dev, ino); head = &mc->ino_index[ino_index]; @@ -225,8 +256,10 @@ struct mapent *cache_lookup_ino(struct m if (me->dev != dev || me->ino != ino) continue; + ino_index_unlock(mc); return me; } + ino_index_unlock(mc); return NULL; } @@ -647,8 +680,9 @@ int cache_delete(struct mapent_cache *mc status = pthread_mutex_destroy(&me->multi_mutex); if (status) fatal(status); - if (!list_empty(&me->ino_index)) - list_del(&me->ino_index); + ino_index_lock(mc); + list_del(&me->ino_index); + ino_index_unlock(mc); free(me->key); if (me->mapent) free(me->mapent); @@ -670,8 +704,9 @@ int cache_delete(struct mapent_cache *mc status = pthread_mutex_destroy(&me->multi_mutex); if (status) fatal(status); - if (!list_empty(&me->ino_index)) - list_del(&me->ino_index); + ino_index_lock(mc); + list_del(&me->ino_index); + ino_index_unlock(mc); free(me->key); if (me->mapent) free(me->mapent); @@ -774,6 +809,10 @@ void cache_release(struct map_source *ma cache_unlock(mc); + status = pthread_mutex_destroy(&mc->ino_index_mutex); + if (status) + fatal(status); + status = pthread_rwlock_destroy(&mc->rwlock); if (status) fatal(status);