From b4ddcced65aeec22b9b43252a5e16cefa869cfd3 Mon Sep 17 00:00:00 2001 From: ericm Date: Sat, 28 Oct 2006 04:25:03 +0000 Subject: [PATCH] branch: b_new_cmd - replace spinlock with rwlock for policy table protection. - fix concurrent load ptlrpc_gss module. - minor message adjustment. --- lustre/include/liblustre.h | 8 +++++ lustre/ptlrpc/sec.c | 50 +++++++++++++++++---------- lustre/utils/gss/lsupport.c | 2 +- lustre/utils/gss/nfs-utils-1.0.10-lustre.diff | 4 +-- lustre/utils/gss/svcgssd_proc.c | 2 +- 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/lustre/include/liblustre.h b/lustre/include/liblustre.h index 3321d23..96fafa8 100644 --- a/lustre/include/liblustre.h +++ b/lustre/include/liblustre.h @@ -315,6 +315,14 @@ static inline void spin_unlock_bh(spinlock_t *l) {} static inline void spin_lock_irqsave(spinlock_t *a, unsigned long b) {} static inline void spin_unlock_irqrestore(spinlock_t *a, unsigned long b) {} +typedef spinlock_t rwlock_t; +#define RW_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED +#define read_lock(l) spin_lock(l) +#define read_unlock(l) spin_unlock(l) +#define write_lock(l) spin_lock(l) +#define write_unlock(l) spin_unlock(l) + + #define min(x,y) ((x)<(y) ? (x) : (y)) #define max(x,y) ((x)>(y) ? (x) : (y)) diff --git a/lustre/ptlrpc/sec.c b/lustre/ptlrpc/sec.c index 279615a..4332e51 100644 --- a/lustre/ptlrpc/sec.c +++ b/lustre/ptlrpc/sec.c @@ -51,7 +51,7 @@ static void sptlrpc_ctx_refresh(struct ptlrpc_cli_ctx *ctx); * policy registers * ***********************************************/ -static spinlock_t policy_lock = SPIN_LOCK_UNLOCKED; +static rwlock_t policy_lock = RW_LOCK_UNLOCKED; static struct ptlrpc_sec_policy *policies[SPTLRPC_POLICY_MAX] = { NULL, }; @@ -67,13 +67,13 @@ int sptlrpc_register_policy(struct ptlrpc_sec_policy *policy) if (number >= SPTLRPC_POLICY_MAX) return -EINVAL; - spin_lock(&policy_lock); - if (policies[number]) { - spin_unlock(&policy_lock); + write_lock(&policy_lock); + if (unlikely(policies[number])) { + write_unlock(&policy_lock); return -EALREADY; } policies[number] = policy; - spin_unlock(&policy_lock); + write_unlock(&policy_lock); CDEBUG(D_SEC, "%s: registered\n", policy->sp_name); return 0; @@ -86,16 +86,16 @@ int sptlrpc_unregister_policy(struct ptlrpc_sec_policy *policy) LASSERT(number < SPTLRPC_POLICY_MAX); - spin_lock(&policy_lock); - if (!policies[number]) { - spin_unlock(&policy_lock); + write_lock(&policy_lock); + if (unlikely(policies[number] == NULL)) { + write_unlock(&policy_lock); CERROR("%s: already unregistered\n", policy->sp_name); return -EINVAL; } LASSERT(policies[number] == policy); policies[number] = NULL; - spin_unlock(&policy_lock); + write_unlock(&policy_lock); CDEBUG(D_SEC, "%s: unregistered\n", policy->sp_name); return 0; @@ -105,27 +105,39 @@ EXPORT_SYMBOL(sptlrpc_unregister_policy); static struct ptlrpc_sec_policy * sptlrpc_flavor2policy(ptlrpc_sec_flavor_t flavor) { - static int load_module = 0; - struct ptlrpc_sec_policy *policy; - __u32 number = SEC_FLAVOR_POLICY(flavor); + static DECLARE_MUTEX(load_mutex); + static atomic_t loaded = ATOMIC_INIT(0); + struct ptlrpc_sec_policy *policy; + __u32 number = SEC_FLAVOR_POLICY(flavor), flag = 0; if (number >= SPTLRPC_POLICY_MAX) return NULL; again: - spin_lock(&policy_lock); + read_lock(&policy_lock); policy = policies[number]; if (policy && !try_module_get(policy->sp_owner)) policy = NULL; - spin_unlock(&policy_lock); + if (policy == NULL) + flag = atomic_read(&loaded); + read_unlock(&policy_lock); #ifdef CONFIG_KMOD /* if failure, try to load gss module, once */ - if (policy == NULL && load_module == 0 && - number == SPTLRPC_POLICY_GSS) { - load_module = 1; - if (request_module("ptlrpc_gss") == 0) - goto again; + if (unlikely(policy == NULL) && + number == SPTLRPC_POLICY_GSS && flag == 0) { + mutex_down(&load_mutex); + if (atomic_read(&loaded) == 0) { + if (request_module("ptlrpc_gss") != 0) + CERROR("Unable to load module ptlrpc_gss\n"); + else + CDEBUG(D_INFO, "module ptlrpc_gss loaded\n"); + + atomic_set(&loaded, 1); + } + mutex_up(&load_mutex); + + goto again; } #endif diff --git a/lustre/utils/gss/lsupport.c b/lustre/utils/gss/lsupport.c index b82d380..33926d1 100644 --- a/lustre/utils/gss/lsupport.c +++ b/lustre/utils/gss/lsupport.c @@ -767,7 +767,7 @@ int lookup_mapping(char *princ, lnet_nid_t nid, uid_t *uid) return 0; } } - printerr(1, "no mapping for %s/%#Lx\n", princ, nid); + printerr(2, "no mapping for %s/%#Lx\n", princ, nid); *uid = -1; return -1; } diff --git a/lustre/utils/gss/nfs-utils-1.0.10-lustre.diff b/lustre/utils/gss/nfs-utils-1.0.10-lustre.diff index fc10241..25c4914 100644 --- a/lustre/utils/gss/nfs-utils-1.0.10-lustre.diff +++ b/lustre/utils/gss/nfs-utils-1.0.10-lustre.diff @@ -1100,7 +1100,7 @@ + return -1; + } + memcpy(sname, name.value, name.length); -+ printerr(1, "authenticate user %s\n", sname); ++ printerr(1, "authenticated %s from %016llx\n", sname, nid); + gss_release_buffer(&min_stat, &name); + + lookup_mapping(sname, nid, &cred->cr_mapped_uid); @@ -3065,7 +3065,7 @@ + return 0; + } + } -+ printerr(1, "no mapping for %s/%#Lx\n", princ, nid); ++ printerr(2, "no mapping for %s/%#Lx\n", princ, nid); + *uid = -1; + return -1; +} diff --git a/lustre/utils/gss/svcgssd_proc.c b/lustre/utils/gss/svcgssd_proc.c index 3b17dca..1ba2fc8 100644 --- a/lustre/utils/gss/svcgssd_proc.c +++ b/lustre/utils/gss/svcgssd_proc.c @@ -321,7 +321,7 @@ get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred, return -1; } memcpy(sname, name.value, name.length); - printerr(1, "authenticate user %s\n", sname); + printerr(1, "authenticated %s from %016llx\n", sname, nid); gss_release_buffer(&min_stat, &name); lookup_mapping(sname, nid, &cred->cr_mapped_uid); -- 1.8.3.1