Whamcloud - gitweb
LU-9019 quota : migrate to 64 bit time 52/26452/2
authorJames Simmons <uja.ornl@yahoo.com>
Sat, 8 Apr 2017 16:52:15 +0000 (12:52 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 19 Apr 2017 04:45:06 +0000 (04:45 +0000)
Replace cfs_time_current_sec() to avoid the overflow
issues in 2038 with ktime_get_real_seconds(). The
quota uses the libcfs 64 bit time abstraction it
developed before the linux kernel has created its
own. Replace all the libcfs 64 bit time handle with
generic time64_t handling.

Change-Id: Ibf9475c7ba8312561a57d48516ffa9b0b3ae4112
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/26452
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/quota/lquota_internal.h
lustre/quota/qmt_entry.c
lustre/quota/qmt_handler.c
lustre/quota/qmt_lock.c
lustre/quota/qsd_handler.c
lustre/quota/qsd_internal.h
lustre/quota/qsd_writeback.c

index b7fa192..5361b7d 100644 (file)
@@ -112,7 +112,7 @@ struct lquota_mst_entry {
        __u64                   lme_gracetime;
 
        /* last time we glimpsed */
-       __u64                   lme_revoke_time;
+       time64_t                lme_revoke_time;
 
        /* r/w semaphore used to protect concurrent access to the quota
         * parameters which are stored on disk */
@@ -153,16 +153,16 @@ struct lquota_slv_entry {
        __u64                   lse_usage;
 
        /* time to trigger quota adjust */
-       __u64                   lse_adjust_time;
+       time64_t                lse_adjust_time;
 
        /* return code of latest acquire RPC */
        int                     lse_acq_rc;
 
        /* when latest acquire RPC completed */
-       __u64                   lse_acq_time;
+       time64_t                lse_acq_time;
 
        /* when latest edquot set */
-       __u64                   lse_edquot_time;
+       time64_t                lse_edquot_time;
 };
 
 /* In-memory entry for each enforced quota id
index eebe9d9..615a29a 100644 (file)
@@ -114,7 +114,7 @@ static void qmt_lqe_debug(struct lquota_entry *lqe, void *arg,
        libcfs_debug_vmsg2(msgdata, fmt, args,
                           "qmt:%s pool:%d-%s id:%llu enforced:%d hard:%llu"
                           " soft:%llu granted:%llu time:%llu qunit:"
-                          "%llu edquot:%d may_rel:%llu revoke:%llu\n",
+                          "%llu edquot:%d may_rel:%llu revoke:%lld\n",
                           pool->qpi_qmt->qmt_svname,
                           pool->qpi_key & 0x0000ffff,
                           RES_NAME(pool->qpi_key >> 16),
@@ -426,6 +426,8 @@ void qmt_adjust_edquot(struct lquota_entry *lqe, __u64 now)
                /* See comment in qmt_adjust_qunit(). LU-4139 */
                if (qmt_hard_exhausted(lqe) ||
                    pool->qpi_key >> 16 != LQUOTA_RES_DT) {
+                       time64_t lapse;
+
                        /* we haven't reached the minimal qunit yet so there is
                         * still hope that the rebalancing process might free
                         * up some quota space */
@@ -437,10 +439,8 @@ void qmt_adjust_edquot(struct lquota_entry *lqe, __u64 now)
                                RETURN_EXIT;
 
                        /* Let's give more time to slave to release space */
-                       if (lqe->lqe_may_rel != 0 &&
-                           cfs_time_before_64(cfs_time_shift_64(
-                                                       -QMT_REBA_TIMEOUT),
-                                              lqe->lqe_revoke_time))
+                       lapse = ktime_get_seconds() - QMT_REBA_TIMEOUT;
+                       if (lqe->lqe_may_rel != 0 && lqe->lqe_revoke_time > lapse)
                                RETURN_EXIT;
                } else {
                        if (lqe->lqe_qunit > pool->qpi_soft_least_qunit)
@@ -675,7 +675,7 @@ done:
                qmt_id_lock_notify(pool->qpi_qmt, lqe);
        else if (lqe->lqe_qunit == pool->qpi_least_qunit)
                /* initial qunit value is the smallest one */
-               lqe->lqe_revoke_time = cfs_time_current_64();
+               lqe->lqe_revoke_time = ktime_get_seconds();
        EXIT;
 }
 
@@ -690,6 +690,6 @@ void qmt_revalidate(const struct lu_env *env, struct lquota_entry *lqe)
                 * were initialized */
                qmt_adjust_qunit(env, lqe);
                if (lqe->lqe_qunit != 0)
-                       qmt_adjust_edquot(lqe, cfs_time_current_sec());
+                       qmt_adjust_edquot(lqe, ktime_get_real_seconds());
        }
 }
index 9fda736..e0c99ad 100644 (file)
@@ -99,7 +99,8 @@ static int qmt_set(const struct lu_env *env, struct qmt_device *qmt,
        struct qmt_thread_info  *qti = qmt_info(env);
        struct lquota_entry     *lqe;
        struct thandle          *th = NULL;
-       __u64                    ver, now;
+       time64_t now;
+       __u64                    ver;
        bool                     dirtied = false;
        int                      rc = 0;
        ENTRY;
@@ -115,7 +116,7 @@ static int qmt_set(const struct lu_env *env, struct qmt_device *qmt,
        if (IS_ERR(th))
                GOTO(out_nolock, rc = PTR_ERR(th));
 
-       now = cfs_time_current_sec();
+       now = ktime_get_real_seconds();
 
        lqe_write_lock(lqe);
        LQUOTA_DEBUG(lqe, "changing quota settings valid:%x hard:%llu soft:"
@@ -407,7 +408,7 @@ int qmt_dqacq0(const struct lu_env *env, struct lquota_entry *lqe,
        slv_granted_bck = slv_granted;
 
        /* record current time for soft limit & grace time management */
-       now = (__u64)cfs_time_current_sec();
+       now = ktime_get_real_seconds();
 
        if (req_is_rel(qb_flags)) {
                /* Slave would like to release quota space */
index 872070e..50fa1b3 100644 (file)
@@ -699,7 +699,7 @@ static void qmt_id_lock_glimpse(const struct lu_env *env,
                lqe_write_lock(lqe);
                if (lqe->lqe_revoke_time == 0 &&
                    lqe->lqe_qunit == pool->qpi_least_qunit)
-                       lqe->lqe_revoke_time = cfs_time_current_64();
+                       lqe->lqe_revoke_time = ktime_get_seconds();
                lqe_write_unlock(lqe);
                RETURN_EXIT;
        }
@@ -737,8 +737,8 @@ static void qmt_id_lock_glimpse(const struct lu_env *env,
        if (lqe->lqe_revoke_time == 0 &&
            qti->qti_gl_desc.lquota_desc.gl_qunit == pool->qpi_least_qunit &&
            lqe->lqe_qunit == pool->qpi_least_qunit) {
-               lqe->lqe_revoke_time = cfs_time_current_64();
-               qmt_adjust_edquot(lqe, cfs_time_current_sec());
+               lqe->lqe_revoke_time = ktime_get_seconds();
+               qmt_adjust_edquot(lqe, ktime_get_real_seconds());
        }
        LASSERT(lqe->lqe_gl);
        lqe->lqe_gl = false;
index e2fdd35..a8d842d 100644 (file)
@@ -402,7 +402,7 @@ out:
        adjust = qsd_adjust_needed(lqe);
        if (reqbody && req_is_acq(reqbody->qb_flags) && ret != -EDQUOT) {
                lqe->lqe_acq_rc = ret;
-               lqe->lqe_acq_time = cfs_time_current_64();
+               lqe->lqe_acq_time = ktime_get_seconds();
        }
 out_noadjust:
        qsd_request_exit(lqe);
@@ -463,8 +463,7 @@ static int qsd_acquire_local(struct lquota_entry *lqe, __u64 space)
         * sometimes due to the race reply of dqacq vs. id lock glimpse
         * (see LU-4505), so we revalidate it every 5 seconds. */
        } else if (lqe->lqe_edquot &&
-                  cfs_time_before_64(cfs_time_shift_64(-5),
-                                     lqe->lqe_edquot_time)) {
+                  (lqe->lqe_edquot_time > ktime_get_seconds() - 5)) {
                rc = -EDQUOT;
        }else {
                rc = -EAGAIN;
@@ -563,7 +562,7 @@ static int qsd_acquire_remote(const struct lu_env *env,
 
        /* check whether an acquire request completed recently */
        if (lqe->lqe_acq_rc != 0 &&
-           cfs_time_before_64(cfs_time_shift_64(-1), lqe->lqe_acq_time)) {
+           lqe->lqe_acq_time > ktime_get_seconds() - 1) {
                lqe_write_unlock(lqe);
                LQUOTA_DEBUG(lqe, "using cached return code %d", lqe->lqe_acq_rc);
                RETURN(lqe->lqe_acq_rc);
index 488602c..e6271c7 100644 (file)
@@ -322,7 +322,7 @@ static inline void qsd_set_edquot(struct lquota_entry *lqe, bool edquot)
 {
        lqe->lqe_edquot = edquot;
        if (edquot)
-               lqe->lqe_edquot_time = cfs_time_current_64();
+               lqe->lqe_edquot_time = ktime_get_seconds();
 }
 
 #define QSD_WB_INTERVAL        60 /* 60 seconds */
index 628c661..47fd727 100644 (file)
@@ -338,12 +338,14 @@ void qsd_adjust_schedule(struct lquota_entry *lqe, bool defer, bool cancel)
        }
 
        if (list_empty(&lqe->lqe_link)) {
-               if (cancel)
+               if (!cancel) {
+                       lqe->lqe_adjust_time = ktime_get_seconds();
+                       if (defer)
+                               lqe->lqe_adjust_time += QSD_WB_INTERVAL;
+               } else {
                        lqe->lqe_adjust_time = 0;
-               else
-                       lqe->lqe_adjust_time = defer ?
-                               cfs_time_shift_64(QSD_WB_INTERVAL) :
-                               cfs_time_current_64();
+               }
+
                /* lqe reference transferred to list */
                if (defer)
                        list_add_tail(&lqe->lqe_link,
@@ -376,8 +378,7 @@ static bool qsd_job_pending(struct qsd_instance *qsd, struct list_head *upd,
                struct lquota_entry *lqe;
                lqe = list_entry(qsd->qsd_adjust_list.next,
                                     struct lquota_entry, lqe_link);
-               if (cfs_time_beforeq_64(lqe->lqe_adjust_time,
-                                       cfs_time_current_64()))
+               if (ktime_get_seconds() > lqe->lqe_adjust_time)
                        job_pending = true;
        }
        spin_unlock(&qsd->qsd_adjust_lock);
@@ -421,7 +422,7 @@ static int qsd_upd_thread(void *arg)
        int                      qtype, rc = 0;
        bool                     uptodate;
        struct lquota_entry     *lqe;
-       __u64                    cur_time;
+       time64_t cur_time;
        ENTRY;
 
        OBD_ALLOC_PTR(env);
@@ -452,13 +453,12 @@ static int qsd_upd_thread(void *arg)
                }
 
                spin_lock(&qsd->qsd_adjust_lock);
-               cur_time = cfs_time_current_64();
+               cur_time = ktime_get_seconds();
                while (!list_empty(&qsd->qsd_adjust_list)) {
                        lqe = list_entry(qsd->qsd_adjust_list.next,
                                         struct lquota_entry, lqe_link);
                        /* deferred items are sorted by time */
-                       if (!cfs_time_beforeq_64(lqe->lqe_adjust_time,
-                                                cur_time))
+                       if (lqe->lqe_adjust_time > cur_time)
                                break;
 
                        list_del_init(&lqe->lqe_link);