From 0efd98b4450c20ea6f5e8fdf46a0062fa38045e5 Mon Sep 17 00:00:00 2001 From: lsy Date: Tue, 20 Sep 2005 06:03:08 +0000 Subject: [PATCH] capa_renew should increase the refc. --- lustre/include/linux/lustre_sec.h | 2 +- lustre/llite/llite_capa.c | 11 +++++++++-- lustre/mds/mds_capa.c | 1 + lustre/obdclass/capa.c | 13 +++++++------ lustre/obdfilter/filter_capa.c | 5 ++++- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lustre/include/linux/lustre_sec.h b/lustre/include/linux/lustre_sec.h index 5e4e05e..f937450 100644 --- a/lustre/include/linux/lustre_sec.h +++ b/lustre/include/linux/lustre_sec.h @@ -613,7 +613,7 @@ void capa_hmac(struct crypto_tfm *tfm, __u8 *key, struct lustre_capa *capa); void capa_dup(void *dst, struct obd_capa *ocapa); void capa_dup2(void *dst, struct lustre_capa *capa); int capa_expired(struct lustre_capa *capa); -int __capa_is_to_expire(struct obd_capa *ocapa); +int __capa_is_to_expire(struct obd_capa *ocapa, struct timeval *tv); int capa_is_to_expire(struct obd_capa *ocapa); #define CAPA_EXPIRY_SHIFT 10 /* 1024 sec */ diff --git a/lustre/llite/llite_capa.c b/lustre/llite/llite_capa.c index aeb7a32..6142812 100644 --- a/lustre/llite/llite_capa.c +++ b/lustre/llite/llite_capa.c @@ -46,12 +46,15 @@ static inline int have_expired_capa(void) struct lustre_capa *capa; int expired = 0; unsigned long expiry; + struct timeval tv; + ENTRY; + do_gettimeofday(&tv); spin_lock(&capa_lock); if (!list_empty(ll_capa_list)) { ocapa = list_entry(ll_capa_list->next, struct obd_capa, c_list); - expired = __capa_is_to_expire(ocapa); + expired = __capa_is_to_expire(ocapa, &tv); if (!expired) { capa = &ocapa->c_capa; expiry = expiry_to_jiffies(capa->lc_expiry - @@ -123,6 +126,7 @@ static int ll_capa_thread(void *arg) struct obd_capa *ocapa, tcapa, *tmp, *next = NULL; unsigned long expiry, sleep = CAPA_PRE_EXPIRY; struct inode *inode; + struct timeval tv; l_wait_event(capa_thread.t_ctl_waitq, (have_expired_capa() || ll_capa_check_stop()), @@ -131,6 +135,7 @@ static int ll_capa_thread(void *arg) if (ll_capa_check_stop()) break; + do_gettimeofday(&tv); spin_lock(&capa_lock); list_for_each_entry_safe(ocapa, tmp, ll_capa_list, c_list) { if (ocapa->c_capa.lc_flags & CAPA_FL_SHORT) @@ -139,7 +144,7 @@ static int ll_capa_thread(void *arg) if (ocapa->c_capa.lc_op == CAPA_TRUNC) continue; - if (__capa_is_to_expire(ocapa)) { + if (__capa_is_to_expire(ocapa, &tv)) { inode = igrab(ocapa->c_inode); if (inode == NULL) continue; @@ -274,6 +279,8 @@ int ll_set_capa(struct inode *inode, struct lookup_intent *it, list_add(&ocapa->c_lli_list, &lli->lli_capas); spin_unlock(&lli->lli_lock); + capa_put(ocapa); + expiry = expiry_to_jiffies(capa->lc_expiry - capa_pre_expiry(capa)); spin_lock(&capa_lock); diff --git a/lustre/mds/mds_capa.c b/lustre/mds/mds_capa.c index f72fcff..6f8d091 100644 --- a/lustre/mds/mds_capa.c +++ b/lustre/mds/mds_capa.c @@ -560,6 +560,7 @@ int mds_pack_capa(struct obd_device *obd, struct mds_export_data *med, ocapa = capa_renew(capa, MDS_CAPA); if (!ocapa) rc = -ENOMEM; + capa_put(ocapa); out: if (rc == 0) body->valid |= OBD_MD_CAPA; diff --git a/lustre/obdclass/capa.c b/lustre/obdclass/capa.c index a28472d..27ef044 100644 --- a/lustre/obdclass/capa.c +++ b/lustre/obdclass/capa.c @@ -247,6 +247,7 @@ get_new_capa_locked(struct hlist_head *head, int type, struct lustre_capa *capa) hlist_add_head(&ocapa->c_hash, head); if (type == CLIENT_CAPA) INIT_LIST_HEAD(&ocapa->c_lli_list); + __capa_get(ocapa); capa_count[type]++; @@ -372,24 +373,24 @@ int capa_expired(struct lustre_capa *capa) return ((unsigned long )capa->lc_expiry <= tv.tv_sec) ? 1 : 0; } -int __capa_is_to_expire(struct obd_capa *ocapa) +int __capa_is_to_expire(struct obd_capa *ocapa, struct timeval *tv) { - struct timeval tv; int pre_expiry = capa_pre_expiry(&ocapa->c_capa); - do_gettimeofday(&tv); - /* XXX: in case the lock is inaccurate, minus one more + /* XXX: in case the clock is inaccurate, minus one more * pre_expiry to make sure the expiry won't miss */ return ((unsigned long)ocapa->c_capa.lc_expiry - - 2 * pre_expiry <= tv.tv_sec)? 1 : 0; + 2 * pre_expiry <= tv->tv_sec)? 1 : 0; } int capa_is_to_expire(struct obd_capa *ocapa) { + struct timeval tv; int rc; + do_gettimeofday(&tv); spin_lock(&capa_lock); - rc = __capa_is_to_expire(ocapa); + rc = __capa_is_to_expire(ocapa, &tv); spin_unlock(&capa_lock); return rc; diff --git a/lustre/obdfilter/filter_capa.c b/lustre/obdfilter/filter_capa.c index 33c4026..c5decbd 100644 --- a/lustre/obdfilter/filter_capa.c +++ b/lustre/obdfilter/filter_capa.c @@ -255,7 +255,10 @@ filter_verify_capa(int cmd, struct obd_export *exp, struct lustre_capa *capa) capa->lc_ino, capa->lc_igen, FILTER_CAPA); verify: if (ocapa) { + struct timeval tv; + /* fo_capa_lock protects capa too */ + do_gettimeofday(&tv); spin_lock(&filter->fo_capa_lock); if (capa->lc_keyid == ocapa->c_capa.lc_keyid) { rc = memcmp(capa, &ocapa->c_capa, sizeof(*capa)); @@ -269,7 +272,7 @@ verify: goto new_capa; } - if (rc && __capa_is_to_expire(ocapa)) { + if (rc && __capa_is_to_expire(ocapa, &tv)) { /* client should use new expiry now */ ocapa->c_bvalid = 0; goto new_capa; -- 1.8.3.1