From: nikita Date: Fri, 29 Sep 2006 11:12:24 +0000 (+0000) Subject: lu_context_key: make ->lct_used atomic to avoid races X-Git-Tag: v1_8_0_110~486^2~767 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=0d8425f4a408a02cee9c2d7e5e7cae606a224650;p=fs%2Flustre-release.git lu_context_key: make ->lct_used atomic to avoid races --- diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 105154c..65924a7 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -968,7 +968,7 @@ struct lu_context_key { * Internal implementation detail: number of values created for this * key. */ - unsigned lct_used; + atomic_t lct_used; }; /* diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index e3a81c9..c9a3755 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -744,7 +744,7 @@ int lu_context_key_register(struct lu_context_key *key) for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) { if (lu_keys[i] == NULL) { key->lct_index = i; - key->lct_used = 1; + atomic_set(&key->lct_used, 1); lu_keys[i] = key; result = 0; break; @@ -760,10 +760,10 @@ EXPORT_SYMBOL(lu_context_key_register); */ void lu_context_key_degister(struct lu_context_key *key) { - LASSERT(key->lct_used >= 1); + LASSERT(atomic_read(&key->lct_used) >= 1); LASSERT(0 <= key->lct_index && key->lct_index < ARRAY_SIZE(lu_keys)); - if (key->lct_used > 1) + if (atomic_read(&key->lct_used) > 1) CERROR("key has instances.\n"); spin_lock(&lu_keys_guard); lu_keys[key->lct_index] = NULL; @@ -794,10 +794,10 @@ static void keys_fini(struct lu_context *ctx) key = lu_keys[i]; LASSERT(key != NULL); LASSERT(key->lct_fini != NULL); - LASSERT(key->lct_used > 1); + LASSERT(atomic_read(&key->lct_used) > 1); key->lct_fini(ctx, key, ctx->lc_value[i]); - key->lct_used--; + atomic_dec(&key->lct_used); ctx->lc_value[i] = NULL; } } @@ -825,7 +825,7 @@ static int keys_fill(const struct lu_context *ctx) value = key->lct_init(ctx, key); if (IS_ERR(value)) return PTR_ERR(value); - key->lct_used++; + atomic_inc(&key->lct_used); ctx->lc_value[i] = value; } }