Whamcloud - gitweb
LU-9679 ptlrpc: use OBD_ALLOC_PTR_ARRAY() and FREE
[fs/lustre-release.git] / lustre / ptlrpc / service.c
index ef341fd..f5d11fd 100644 (file)
@@ -229,7 +229,7 @@ struct ptlrpc_hr_partition {
 #define HRT_STOPPING 1
 
 struct ptlrpc_hr_service {
-       /* CPU partition table, it's just cfs_cpt_table for now */
+       /* CPU partition table, it's just cfs_cpt_tab for now */
        struct cfs_cpt_table            *hr_cpt_table;
        /** controller sleep waitq */
        wait_queue_head_t               hr_waitq;
@@ -684,13 +684,12 @@ static int ptlrpc_service_part_init(struct ptlrpc_service *svc,
 
  failed:
        if (array->paa_reqs_count != NULL) {
-               OBD_FREE(array->paa_reqs_count, sizeof(__u32) * size);
+               OBD_FREE_PTR_ARRAY(array->paa_reqs_count, size);
                array->paa_reqs_count = NULL;
        }
 
        if (array->paa_reqs_array != NULL) {
-               OBD_FREE(array->paa_reqs_array,
-                        sizeof(struct list_head) * array->paa_size);
+               OBD_FREE_PTR_ARRAY(array->paa_reqs_array, array->paa_size);
                array->paa_reqs_array = NULL;
        }
 
@@ -725,7 +724,7 @@ struct ptlrpc_service *ptlrpc_register_service(struct ptlrpc_service_conf *conf,
 
        cptable = cconf->cc_cptable;
        if (cptable == NULL)
-               cptable = cfs_cpt_table;
+               cptable = cfs_cpt_tab;
 
        if (conf->psc_thr.tc_cpu_bind > 1) {
                CERROR("%s: Invalid cpu bind value %d, only 1 or 0 allowed\n",
@@ -755,7 +754,7 @@ struct ptlrpc_service *ptlrpc_register_service(struct ptlrpc_service_conf *conf,
                                CERROR("%s: failed to parse CPT array %s: %d\n",
                                       conf->psc_name, cconf->cc_pattern, rc);
                                if (cpts != NULL)
-                                       OBD_FREE(cpts, sizeof(*cpts) * ncpts);
+                                       OBD_FREE_PTR_ARRAY(cpts, ncpts);
                                RETURN(ERR_PTR(rc < 0 ? rc : -EINVAL));
                        }
                        ncpts = rc;
@@ -765,7 +764,7 @@ struct ptlrpc_service *ptlrpc_register_service(struct ptlrpc_service_conf *conf,
        OBD_ALLOC(service, offsetof(struct ptlrpc_service, srv_parts[ncpts]));
        if (service == NULL) {
                if (cpts != NULL)
-                       OBD_FREE(cpts, sizeof(*cpts) * ncpts);
+                       OBD_FREE_PTR_ARRAY(cpts, ncpts);
                RETURN(ERR_PTR(-ENOMEM));
        }
 
@@ -1351,7 +1350,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
        struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
        struct ptlrpc_request *reqcopy;
        struct lustre_msg *reqmsg;
-       time64_t olddl = req->rq_deadline - ktime_get_real_seconds();
+       timeout_t olddl = req->rq_deadline - ktime_get_real_seconds();
        time64_t newdl;
        int rc;
 
@@ -1367,9 +1366,9 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
         * difference between clients' and servers' expectations
         */
        DEBUG_REQ(D_ADAPTTO, req,
-                 "%ssending early reply (deadline %+llds, margin %+llds) for %d+%d",
+                 "%ssending early reply (deadline %+ds, margin %+ds) for %d+%d",
                  AT_OFF ? "AT off - not " : "",
-                 (s64)olddl, (s64)(olddl - at_get(&svcpt->scp_at_estimate)),
+                 olddl, olddl - at_get(&svcpt->scp_at_estimate),
                  at_get(&svcpt->scp_at_estimate), at_extra);
 
        if (AT_OFF)
@@ -1378,8 +1377,8 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
        if (olddl < 0) {
                /* below message is checked in replay-ost-single.sh test_9 */
                DEBUG_REQ(D_WARNING, req,
-                         "Already past deadline (%+llds), not sending early reply. Consider increasing at_early_margin (%d)?",
-                         (s64)olddl, at_early_margin);
+                         "Already past deadline (%+ds), not sending early reply. Consider increasing at_early_margin (%d)?",
+                         olddl, at_early_margin);
 
                /* Return an error so we're not re-added to the timed list. */
                RETURN(-ETIMEDOUT);
@@ -1436,8 +1435,8 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
         */
        if (req->rq_deadline >= newdl) {
                DEBUG_REQ(D_WARNING, req,
-                         "Could not add any time (%lld/%lld), not sending early reply",
-                         (s64)olddl, (s64)(newdl - ktime_get_real_seconds()));
+                         "Could not add any time (%d/%lld), not sending early reply",
+                         olddl, newdl - ktime_get_real_seconds());
                RETURN(-ETIMEDOUT);
        }
 
@@ -1530,7 +1529,7 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service_part *svcpt)
        __u32 index, count;
        time64_t deadline;
        time64_t now = ktime_get_real_seconds();
-       s64 delay;
+       s64 delay_ms;
        int first, counter = 0;
 
        ENTRY;
@@ -1539,7 +1538,7 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service_part *svcpt)
                spin_unlock(&svcpt->scp_at_lock);
                RETURN(0);
        }
-       delay = ktime_ms_delta(ktime_get(), svcpt->scp_at_checktime);
+       delay_ms = ktime_ms_delta(ktime_get(), svcpt->scp_at_checktime);
        svcpt->scp_at_check = 0;
 
        if (array->paa_count == 0) {
@@ -1610,10 +1609,10 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service_part *svcpt)
                 */
                LCONSOLE_WARN("%s: This server is not able to keep up with request traffic (cpu-bound).\n",
                              svcpt->scp_service->srv_name);
-               CWARN("earlyQ=%d reqQ=%d recA=%d, svcEst=%d, delay=%lld\n",
+               CWARN("earlyQ=%d reqQ=%d recA=%d, svcEst=%d, delay=%lldms\n",
                      counter, svcpt->scp_nreqs_incoming,
                      svcpt->scp_nreqs_active,
-                     at_get(&svcpt->scp_at_estimate), delay);
+                     at_get(&svcpt->scp_at_estimate), delay_ms);
        }
 
        /*
@@ -2161,8 +2160,8 @@ static int ptlrpc_server_handle_req_in(struct ptlrpc_service_part *svcpt,
        /* req_in handling should/must be fast */
        if (ktime_get_real_seconds() - req->rq_arrival_time.tv_sec > 5)
                DEBUG_REQ(D_WARNING, req, "Slow req_in handling %llds",
-                         (s64)(ktime_get_real_seconds() -
-                               req->rq_arrival_time.tv_sec));
+                         ktime_get_real_seconds() -
+                         req->rq_arrival_time.tv_sec);
 
        /* Set rpc server deadline and add it to the timed list */
        deadline = (lustre_msghdr_get_flags(req->rq_reqmsg) &
@@ -2289,7 +2288,7 @@ static int ptlrpc_server_handle_request(struct ptlrpc_service_part *svcpt,
 
        CDEBUG(D_RPCTRACE,
               "Handling RPC req@%p pname:cluuid+ref:pid:xid:nid:opc:job %s:%s+%d:%d:x%llu:%s:%d:%s\n",
-              request, current_comm(),
+              request, current->comm,
               (request->rq_export ?
                (char *)request->rq_export->exp_client_uuid.uuid : "0"),
               (request->rq_export ?
@@ -2329,7 +2328,7 @@ put_conn:
        arrived_usecs = ktime_us_delta(work_end, arrived);
        CDEBUG(D_RPCTRACE,
               "Handled RPC req@%p pname:cluuid+ref:pid:xid:nid:opc:job %s:%s+%d:%d:x%llu:%s:%d:%s Request processed in %lldus (%lldus total) trans %llu rc %d/%d\n",
-              request, current_comm(),
+              request, current->comm,
               (request->rq_export ?
               (char *)request->rq_export->exp_client_uuid.uuid : "0"),
               (request->rq_export ?
@@ -2661,10 +2660,10 @@ static void ptlrpc_watchdog_fire(struct work_struct *w)
        }
 }
 
-static void ptlrpc_watchdog_init(struct delayed_work *work, time_t time)
+static void ptlrpc_watchdog_init(struct delayed_work *work, timeout_t timeout)
 {
        INIT_DELAYED_WORK(work, ptlrpc_watchdog_fire);
-       schedule_delayed_work(work, cfs_time_seconds(time));
+       schedule_delayed_work(work, cfs_time_seconds(timeout));
 }
 
 static void ptlrpc_watchdog_disable(struct delayed_work *work)
@@ -2672,13 +2671,13 @@ static void ptlrpc_watchdog_disable(struct delayed_work *work)
        cancel_delayed_work_sync(work);
 }
 
-static void ptlrpc_watchdog_touch(struct delayed_work *work, time_t time)
+static void ptlrpc_watchdog_touch(struct delayed_work *work, timeout_t timeout)
 {
        struct ptlrpc_thread *thread = container_of(&work->work,
                                                    struct ptlrpc_thread,
                                                    t_watchdog.work);
        thread->t_touched = ktime_get();
-       mod_delayed_work(system_wq, work, cfs_time_seconds(time));
+       mod_delayed_work(system_wq, work, cfs_time_seconds(timeout));
 }
 
 /**
@@ -2746,7 +2745,7 @@ static int ptlrpc_main(void *arg)
        ENTRY;
 
        thread->t_task = current;
-       thread->t_pid = current_pid();
+       thread->t_pid = current->pid;
        unshare_fs_struct();
 
        if (svc->srv_cpt_bind) {
@@ -2980,7 +2979,7 @@ static int ptlrpc_hr_main(void *arg)
        wake_up(&ptlrpc_hr.hr_waitq);
 
        while (!ptlrpc_hr.hr_stopping) {
-               l_wait_condition(hrt->hrt_waitq, hrt_dont_sleep(hrt, &replies));
+               wait_event_idle(hrt->hrt_waitq, hrt_dont_sleep(hrt, &replies));
 
                while (!list_empty(&replies)) {
                        struct ptlrpc_reply_state *rs;
@@ -3287,7 +3286,7 @@ int ptlrpc_hr_init(void)
        ENTRY;
 
        memset(&ptlrpc_hr, 0, sizeof(ptlrpc_hr));
-       ptlrpc_hr.hr_cpt_table = cfs_cpt_table;
+       ptlrpc_hr.hr_cpt_table = cfs_cpt_tab;
 
        ptlrpc_hr.hr_partitions = cfs_percpt_alloc(ptlrpc_hr.hr_cpt_table,
                                                   sizeof(*hrp));
@@ -3348,10 +3347,8 @@ void ptlrpc_hr_fini(void)
        ptlrpc_stop_hr_threads();
 
        cfs_percpt_for_each(hrp, cpt, ptlrpc_hr.hr_partitions) {
-               if (hrp->hrp_thrs != NULL) {
-                       OBD_FREE(hrp->hrp_thrs,
-                                hrp->hrp_nthrs * sizeof(hrp->hrp_thrs[0]));
-               }
+               if (hrp->hrp_thrs)
+                       OBD_FREE_PTR_ARRAY(hrp->hrp_thrs, hrp->hrp_nthrs);
        }
 
        cfs_percpt_free(ptlrpc_hr.hr_partitions);
@@ -3544,14 +3541,14 @@ ptlrpc_service_free(struct ptlrpc_service *svc)
                array = &svcpt->scp_at_array;
 
                if (array->paa_reqs_array != NULL) {
-                       OBD_FREE(array->paa_reqs_array,
-                                sizeof(struct list_head) * array->paa_size);
+                       OBD_FREE_PTR_ARRAY(array->paa_reqs_array,
+                                          array->paa_size);
                        array->paa_reqs_array = NULL;
                }
 
                if (array->paa_reqs_count != NULL) {
-                       OBD_FREE(array->paa_reqs_count,
-                                sizeof(__u32) * array->paa_size);
+                       OBD_FREE_PTR_ARRAY(array->paa_reqs_count,
+                                          array->paa_size);
                        array->paa_reqs_count = NULL;
                }
        }