From: Andreas Dilger Date: Sat, 25 Apr 2020 09:19:04 +0000 (-0600) Subject: LU-12931 ldlm: use proper units for timeouts X-Git-Tag: 2.13.54~75 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=3108bbb0b8485484bc1ac8ba5bac4276fc11c7c3 LU-12931 ldlm: use proper units for timeouts Use timeout_t for ns_ctime_age_limit since this is a relative time and not an absolute time. Use ktime_t for ns_dirty_age_limit internally, even though the user interface is in seconds, since this is frequenty used together with other ktime_t values in the kernel. Fixes: e920be681451 ("LU-9019 ldlm: migrate the rest of the code to 64 bit time") Signed-off-by: Andreas Dilger Change-Id: Idb5ece834e56a95cd781cb871b1b7c20bf3ebbe5 Reviewed-on: https://review.whamcloud.com/38365 Reviewed-by: James Simmons Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index 28d2cd9..07970ea 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -435,7 +435,9 @@ struct ldlm_namespace { */ unsigned int ns_max_unused; - /** Maximum allowed age (last used time) for locks in the LRU */ + /** Maximum allowed age (last used time) for locks in the LRU. Set in + * seconds from userspace, but stored in ns to avoid repeat conversions. + */ ktime_t ns_max_age; /** @@ -444,19 +446,20 @@ struct ldlm_namespace { */ unsigned int ns_timeouts; /** - * Number of seconds since the file change time after which the - * MDT will return an UPDATE lock along with a LOOKUP lock. + * Number of seconds since the file change time after which + * the MDT will return an UPDATE lock along with a LOOKUP lock. * This allows the client to start caching negative dentries * for a directory and may save an RPC for a later stat. */ - time64_t ns_ctime_age_limit; + timeout_t ns_ctime_age_limit; /** - * Number of seconds since the lock was last used. The client may - * cancel the lock limited by this age and flush related data if - * any other client shows interest in it doing glimpse request. - * This allows to cache stat data locally for such files early. + * Number of (nano)seconds since the lock was last used. The client + * may cancel the lock older than this age and flush related data if + * another client shows interest in this lock by doing glimpse request. + * This allows to cache stat data locally for such files early. Set in + * seconds from userspace, but stored in ns to avoid repeat conversions. */ - time64_t ns_dirty_age_limit; + ktime_t ns_dirty_age_limit; /** * Used to rate-limit ldlm_namespace_dump calls. * \see ldlm_namespace_dump. Increased by 10 seconds every time diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index bfe424b..9b16cb6 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -2083,8 +2083,7 @@ static void ldlm_handle_gl_callback(struct ptlrpc_request *req, if (lock->l_granted_mode == LCK_PW && !lock->l_readers && !lock->l_writers && ktime_after(ktime_get(), - ktime_add(lock->l_last_used, - ktime_set(ns->ns_dirty_age_limit, 0)))) { + ktime_add(lock->l_last_used, ns->ns_dirty_age_limit))) { unlock_res_and_lock(lock); /* For MDS glimpse it is always DOM lock, set corresponding diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 5410fb1..735fad3 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -458,7 +458,8 @@ static ssize_t dirty_age_limit_show(struct kobject *kobj, struct ldlm_namespace *ns = container_of(kobj, struct ldlm_namespace, ns_kobj); - return sprintf(buf, "%llu\n", ns->ns_dirty_age_limit); + return snprintf(buf, PAGE_SIZE, "%llu\n", + ktime_divns(ns->ns_dirty_age_limit, NSEC_PER_SEC)); } static ssize_t dirty_age_limit_store(struct kobject *kobj, @@ -472,7 +473,7 @@ static ssize_t dirty_age_limit_store(struct kobject *kobj, if (kstrtoull(buffer, 10, &tmp)) return -EINVAL; - ns->ns_dirty_age_limit = tmp; + ns->ns_dirty_age_limit = ktime_set(tmp, 0); return count; } @@ -485,7 +486,7 @@ static ssize_t ctime_age_limit_show(struct kobject *kobj, struct ldlm_namespace *ns = container_of(kobj, struct ldlm_namespace, ns_kobj); - return sprintf(buf, "%llu\n", ns->ns_ctime_age_limit); + return snprintf(buf, PAGE_SIZE, "%u\n", ns->ns_ctime_age_limit); } static ssize_t ctime_age_limit_store(struct kobject *kobj, @@ -494,9 +495,9 @@ static ssize_t ctime_age_limit_store(struct kobject *kobj, { struct ldlm_namespace *ns = container_of(kobj, struct ldlm_namespace, ns_kobj); - unsigned long long tmp; + unsigned long tmp; - if (kstrtoull(buffer, 10, &tmp)) + if (kstrtoul(buffer, 10, &tmp)) return -EINVAL; ns->ns_ctime_age_limit = tmp; @@ -915,7 +916,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE; ns->ns_max_age = ktime_set(LDLM_DEFAULT_MAX_ALIVE, 0); ns->ns_ctime_age_limit = LDLM_CTIME_AGE_LIMIT; - ns->ns_dirty_age_limit = LDLM_DIRTY_AGE_LIMIT; + ns->ns_dirty_age_limit = ktime_set(LDLM_DIRTY_AGE_LIMIT, 0); ns->ns_timeouts = 0; ns->ns_orig_connect_flags = 0; ns->ns_connect_flags = 0; diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index de22581..92a99c4 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -416,8 +416,7 @@ int ll_md_need_convert(struct ldlm_lock *lock) /* is lock is too old to be converted? */ lock_res_and_lock(lock); if (ktime_after(ktime_get(), - ktime_add(lock->l_last_used, - ktime_set(ns->ns_dirty_age_limit, 0)))) { + ktime_add(lock->l_last_used, ns->ns_dirty_age_limit))) { unlock_res_and_lock(lock); return 0; }