Whamcloud - gitweb
LU-10383 hsm: add action count to hsm scan data 35/31235/3
authorJohn L. Hammond <john.hammond@intel.com>
Thu, 8 Feb 2018 19:19:39 +0000 (13:19 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 9 Apr 2018 19:47:36 +0000 (19:47 +0000)
Add an 'hsm_action_count' member to struct hsm_scan_data to count the
total number of actions in all requests in the hsd. Add an 'hsd_'
prefix to all pre-existing members of struct hsm_scan_data.

Test-Parameters: trivial testlist=sanity-hsm
Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: Iab784a0f281d697bc0db758f20ce500315b8194a
Reviewed-on: https://review.whamcloud.com/31235
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Quentin Bouget <quentin.bouget@cea.fr>
Reviewed-by: Faccini Bruno <bruno.faccini@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdt/mdt_coordinator.c

index c89318b..b240afe 100644 (file)
@@ -136,16 +136,16 @@ struct hsm_scan_request {
 };
 
 struct hsm_scan_data {
 };
 
 struct hsm_scan_data {
-       struct mdt_thread_info          *mti;
-       char                             fs_name[MTI_NAME_MAXLEN+1];
+       struct mdt_thread_info  *hsd_mti;
+       char                     hsd_fsname[MTI_NAME_MAXLEN + 1];
        /* are we scanning the logs for housekeeping, or just looking
         * for new work?
         */
        /* are we scanning the logs for housekeeping, or just looking
         * for new work?
         */
-       bool                             housekeeping;
-       /* request to be send to agents */
-       int                              max_requests;  /** vector size */
-       int                              request_cnt;   /** used count */
-       struct hsm_scan_request         *request;
+       bool                     hsd_housekeeping;
+       int                      hsd_action_count;
+       int                      hsd_request_len; /* array alloc len */
+       int                      hsd_request_count; /* array used count */
+       struct hsm_scan_request *hsd_request;
 };
 
 static int mdt_cdt_waiting_cb(const struct lu_env *env,
 };
 
 static int mdt_cdt_waiting_cb(const struct lu_env *env,
@@ -160,16 +160,30 @@ static int mdt_cdt_waiting_cb(const struct lu_env *env,
        int i;
 
        /* Are agents full? */
        int i;
 
        /* Are agents full? */
-       if (atomic_read(&cdt->cdt_request_count) >= cdt->cdt_max_requests)
-               RETURN(0);
+       if (hsd->hsd_action_count + atomic_read(&cdt->cdt_request_count) >=
+           cdt->cdt_max_requests) {
+               if (hsd->hsd_housekeeping) {
+                       /* Unknown request and no more room for a new
+                        * request. Continue to scan to find other
+                        * entries for already existing requests. */
+                       RETURN(0);
+               } else {
+                       /* We cannot send and more requests, stop
+                        * here. There might be more known requests
+                        * that could be merged, but this avoid
+                        * analyzing too many llogs for minor
+                        * gains. */
+                       RETURN(LLOG_PROC_BREAK);
+               }
+       }
 
        /* first search whether the request is found in the list we
         * have built. */
        request = NULL;
 
        /* first search whether the request is found in the list we
         * have built. */
        request = NULL;
-       for (i = 0; i < hsd->request_cnt; i++) {
-               if (hsd->request[i].hal->hal_compound_id ==
+       for (i = 0; i < hsd->hsd_request_count; i++) {
+               if (hsd->hsd_request[i].hal->hal_compound_id ==
                    larr->arr_compound_id) {
                    larr->arr_compound_id) {
-                       request = &hsd->request[i];
+                       request = &hsd->hsd_request[i];
                        break;
                }
        }
                        break;
                }
        }
@@ -177,24 +191,15 @@ static int mdt_cdt_waiting_cb(const struct lu_env *env,
        if (!request) {
                struct hsm_action_list *hal;
 
        if (!request) {
                struct hsm_action_list *hal;
 
-               if (hsd->request_cnt == hsd->max_requests) {
-                       if (!hsd->housekeeping) {
-                               /* The request array is full, stop
-                                * here. There might be more known
-                                * requests that could be merged, but
-                                * this avoid analyzing too many llogs
-                                * for minor gains. */
-                               RETURN(LLOG_PROC_BREAK);
-                       } else {
-                               /* Unknown request and no more room
-                                * for a new request. Continue to scan
-                                * to find other entries for already
-                                * existing requests. */
+               if (hsd->hsd_request_count == hsd->hsd_request_len) {
+                       /* Logic as above. */
+                       if (hsd->hsd_housekeeping)
                                RETURN(0);
                                RETURN(0);
-                       }
+                       else
+                               RETURN(LLOG_PROC_BREAK);
                }
 
                }
 
-               request = &hsd->request[hsd->request_cnt];
+               request = &hsd->hsd_request[hsd->hsd_request_count];
 
                /* allocates hai vector size just needs to be large
                 * enough */
 
                /* allocates hai vector size just needs to be large
                 * enough */
@@ -206,14 +211,14 @@ static int mdt_cdt_waiting_cb(const struct lu_env *env,
                        RETURN(-ENOMEM);
 
                hal->hal_version = HAL_VERSION;
                        RETURN(-ENOMEM);
 
                hal->hal_version = HAL_VERSION;
-               strlcpy(hal->hal_fsname, hsd->fs_name, MTI_NAME_MAXLEN + 1);
+               strlcpy(hal->hal_fsname, hsd->hsd_fsname, MTI_NAME_MAXLEN + 1);
                hal->hal_compound_id = larr->arr_compound_id;
                hal->hal_archive_id = larr->arr_archive_id;
                hal->hal_flags = larr->arr_flags;
                hal->hal_count = 0;
                request->hal_used_sz = hal_size(hal);
                request->hal = hal;
                hal->hal_compound_id = larr->arr_compound_id;
                hal->hal_archive_id = larr->arr_archive_id;
                hal->hal_flags = larr->arr_flags;
                hal->hal_count = 0;
                request->hal_used_sz = hal_size(hal);
                request->hal = hal;
-               hsd->request_cnt++;
+               hsd->hsd_request_count++;
                hai = hai_first(hal);
        } else {
                /* request is known */
                hai = hai_first(hal);
        } else {
                /* request is known */
@@ -254,6 +259,8 @@ static int mdt_cdt_waiting_cb(const struct lu_env *env,
        request->hal_used_sz += cfs_size_round(hai->hai_len);
        request->hal->hal_count++;
 
        request->hal_used_sz += cfs_size_round(hai->hai_len);
        request->hal->hal_count++;
 
+       hsd->hsd_action_count++;
+
        if (hai->hai_action != HSMA_CANCEL)
                cdt_agent_record_hash_add(cdt, hai->hai_cookie,
                                          llh->lgh_hdr->llh_cat_idx,
        if (hai->hai_action != HSMA_CANCEL)
                cdt_agent_record_hash_add(cdt, hai->hai_cookie,
                                          llh->lgh_hdr->llh_cat_idx,
@@ -276,7 +283,7 @@ static int mdt_cdt_started_cb(const struct lu_env *env,
        int cl_flags;
        int rc;
 
        int cl_flags;
        int rc;
 
-       if (!hsd->housekeeping)
+       if (!hsd->hsd_housekeeping)
                RETURN(0);
 
        /* we search for a running request
                RETURN(0);
 
        /* we search for a running request
@@ -332,11 +339,11 @@ static int mdt_cdt_started_cb(const struct lu_env *env,
                             &hai->hai_fid);
 
        if (hai->hai_action == HSMA_RESTORE)
                             &hai->hai_fid);
 
        if (hai->hai_action == HSMA_RESTORE)
-               cdt_restore_handle_del(hsd->mti, cdt, &hai->hai_fid);
+               cdt_restore_handle_del(hsd->hsd_mti, cdt, &hai->hai_fid);
 
        larr->arr_status = ARS_CANCELED;
        larr->arr_req_change = now;
 
        larr->arr_status = ARS_CANCELED;
        larr->arr_req_change = now;
-       rc = llog_write(hsd->mti->mti_env, llh, &larr->arr_hdr,
+       rc = llog_write(hsd->hsd_mti->mti_env, llh, &larr->arr_hdr,
                        larr->arr_hdr.lrh_index);
        if (rc < 0) {
                CERROR("%s: cannot update agent log: rc = %d\n",
                        larr->arr_hdr.lrh_index);
        if (rc < 0) {
                CERROR("%s: cannot update agent log: rc = %d\n",
@@ -372,7 +379,7 @@ static int mdt_coordinator_cb(const struct lu_env *env,
 {
        struct llog_agent_req_rec *larr = (struct llog_agent_req_rec *)hdr;
        struct hsm_scan_data *hsd = data;
 {
        struct llog_agent_req_rec *larr = (struct llog_agent_req_rec *)hdr;
        struct hsm_scan_data *hsd = data;
-       struct mdt_device *mdt = hsd->mti->mti_mdt;
+       struct mdt_device *mdt = hsd->hsd_mti->mti_mdt;
        struct coordinator *cdt = &mdt->mdt_coordinator;
        ENTRY;
 
        struct coordinator *cdt = &mdt->mdt_coordinator;
        ENTRY;
 
@@ -384,7 +391,7 @@ static int mdt_coordinator_cb(const struct lu_env *env,
        case ARS_STARTED:
                RETURN(mdt_cdt_started_cb(env, mdt, llh, larr, hsd));
        default:
        case ARS_STARTED:
                RETURN(mdt_cdt_started_cb(env, mdt, llh, larr, hsd));
        default:
-               if (!hsd->housekeeping)
+               if (!hsd->hsd_housekeeping)
                        RETURN(0);
 
                if ((larr->arr_req_change + cdt->cdt_grace_delay) <
                        RETURN(0);
 
                if ((larr->arr_req_change + cdt->cdt_grace_delay) <
@@ -563,8 +570,9 @@ static int mdt_coordinator(void *data)
        CDEBUG(D_HSM, "%s: coordinator thread starting, pid=%d\n",
               mdt_obd_name(mdt), current_pid());
 
        CDEBUG(D_HSM, "%s: coordinator thread starting, pid=%d\n",
               mdt_obd_name(mdt), current_pid());
 
-       hsd.mti = mti;
-       obd_uuid2fsname(hsd.fs_name, mdt_obd_name(mdt), MTI_NAME_MAXLEN);
+       hsd.hsd_mti = mti;
+       obd_uuid2fsname(hsd.hsd_fsname, mdt_obd_name(mdt),
+                       sizeof(hsd.hsd_fsname));
 
        set_cdt_state(cdt, CDT_RUNNING);
 
 
        set_cdt_state(cdt, CDT_RUNNING);
 
@@ -608,9 +616,9 @@ static int mdt_coordinator(void *data)
                if (last_housekeeping + cdt->cdt_loop_period <=
                    ktime_get_real_seconds()) {
                        last_housekeeping = ktime_get_real_seconds();
                if (last_housekeeping + cdt->cdt_loop_period <=
                    ktime_get_real_seconds()) {
                        last_housekeeping = ktime_get_real_seconds();
-                       hsd.housekeeping = true;
+                       hsd.hsd_housekeeping = true;
                } else if (cdt->cdt_event) {
                } else if (cdt->cdt_event) {
-                       hsd.housekeeping = false;
+                       hsd.hsd_housekeeping = false;
                } else {
                        continue;
                }
                } else {
                        continue;
                }
@@ -619,7 +627,7 @@ static int mdt_coordinator(void *data)
 
                CDEBUG(D_HSM, "coordinator starts reading llog\n");
 
 
                CDEBUG(D_HSM, "coordinator starts reading llog\n");
 
-               if (hsd.max_requests != cdt->cdt_max_requests) {
+               if (hsd.hsd_request_len != cdt->cdt_max_requests) {
                        /* cdt_max_requests has changed,
                         * we need to allocate a new buffer
                         */
                        /* cdt_max_requests has changed,
                         * we need to allocate a new buffer
                         */
@@ -630,26 +638,29 @@ static int mdt_coordinator(void *data)
                        if (!tmp) {
                                CERROR("Failed to resize request buffer, "
                                       "keeping it at %d\n",
                        if (!tmp) {
                                CERROR("Failed to resize request buffer, "
                                       "keeping it at %d\n",
-                                      hsd.max_requests);
+                                      hsd.hsd_request_len);
                        } else {
                        } else {
-                               if (hsd.request != NULL)
-                                       OBD_FREE_LARGE(hsd.request, request_sz);
+                               if (hsd.hsd_request != NULL)
+                                       OBD_FREE_LARGE(hsd.hsd_request,
+                                                      request_sz);
 
 
-                               hsd.max_requests = max_requests;
-                               request_sz = hsd.max_requests *
+                               hsd.hsd_request_len = max_requests;
+                               request_sz = hsd.hsd_request_len *
                                        sizeof(struct hsm_scan_request);
                                        sizeof(struct hsm_scan_request);
-                               hsd.request = tmp;
+                               hsd.hsd_request = tmp;
                        }
                }
 
                        }
                }
 
-               hsd.request_cnt = 0;
+               hsd.hsd_action_count = 0;
+               hsd.hsd_request_count = 0;
 
                rc = cdt_llog_process(mti->mti_env, mdt, mdt_coordinator_cb,
                                      &hsd, 0, 0, WRITE);
                if (rc < 0)
                        goto clean_cb_alloc;
 
 
                rc = cdt_llog_process(mti->mti_env, mdt, mdt_coordinator_cb,
                                      &hsd, 0, 0, WRITE);
                if (rc < 0)
                        goto clean_cb_alloc;
 
-               CDEBUG(D_HSM, "found %d requests to send\n", hsd.request_cnt);
+               CDEBUG(D_HSM, "found %d requests to send\n",
+                      hsd.hsd_request_count);
 
                if (list_empty(&cdt->cdt_agents)) {
                        CDEBUG(D_HSM, "no agent available, "
 
                if (list_empty(&cdt->cdt_agents)) {
                        CDEBUG(D_HSM, "no agent available, "
@@ -659,9 +670,9 @@ static int mdt_coordinator(void *data)
 
                /* Compute how many HAI we have in all the requests */
                updates_cnt = 0;
 
                /* Compute how many HAI we have in all the requests */
                updates_cnt = 0;
-               for (i = 0; i < hsd.request_cnt; i++) {
+               for (i = 0; i < hsd.hsd_request_count; i++) {
                        const struct hsm_scan_request *request =
                        const struct hsm_scan_request *request =
-                               &hsd.request[i];
+                               &hsd.hsd_request[i];
 
                        updates_cnt += request->hal->hal_count;
                }
 
                        updates_cnt += request->hal->hal_count;
                }
@@ -678,8 +689,8 @@ static int mdt_coordinator(void *data)
                }
 
                /* here hsd contains a list of requests to be started */
                }
 
                /* here hsd contains a list of requests to be started */
-               for (i = 0; i < hsd.request_cnt; i++) {
-                       struct hsm_scan_request *request = &hsd.request[i];
+               for (i = 0; i < hsd.hsd_request_count; i++) {
+                       struct hsm_scan_request *request = &hsd.hsd_request[i];
                        struct hsm_action_list  *hal = request->hal;
                        struct hsm_action_item  *hai;
                        int                      j;
                        struct hsm_action_list  *hal = request->hal;
                        struct hsm_action_item  *hai;
                        int                      j;
@@ -722,15 +733,15 @@ static int mdt_coordinator(void *data)
 
 clean_cb_alloc:
                /* free hal allocated by callback */
 
 clean_cb_alloc:
                /* free hal allocated by callback */
-               for (i = 0; i < hsd.request_cnt; i++) {
-                       struct hsm_scan_request *request = &hsd.request[i];
+               for (i = 0; i < hsd.hsd_request_count; i++) {
+                       struct hsm_scan_request *request = &hsd.hsd_request[i];
 
                        OBD_FREE(request->hal, request->hal_sz);
                }
        }
 
 
                        OBD_FREE(request->hal, request->hal_sz);
                }
        }
 
-       if (hsd.request)
-               OBD_FREE_LARGE(hsd.request, request_sz);
+       if (hsd.hsd_request != NULL)
+               OBD_FREE_LARGE(hsd.hsd_request, request_sz);
 
        mdt_hsm_cdt_cleanup(mdt);
 
 
        mdt_hsm_cdt_cleanup(mdt);