Whamcloud - gitweb
LU-14043 llite: allow DIO with unaligned IO count
[fs/lustre-release.git] / lustre / mdt / mdt_hsm_cdt_requests.c
index 4ab3db1..7135334 100644 (file)
@@ -23,7 +23,7 @@
  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
  *     alternatives
  *
- * Copyright (c) 2014, Intel Corporation.
+ * Copyright (c) 2014, 2017, Intel Corporation.
  */
 /*
  * lustre/mdt/mdt_hsm_cdt_requests.c
@@ -103,13 +103,13 @@ void dump_requests(char *prefix, struct coordinator *cdt)
        down_read(&cdt->cdt_request_lock);
        list_for_each_entry(car, &cdt->cdt_request_list, car_request_list) {
                CDEBUG(D_HSM, "%s fid="DFID" dfid="DFID
-                      " compound/cookie=%#llx/%#llx"
+                      " cookie=%#llx"
                       " action=%s archive#=%d flags=%#llx"
                       " extent=%#llx-%#llx"
                       " gid=%#llx refcount=%d canceled=%d\n",
                       prefix, PFID(&car->car_hai->hai_fid),
                       PFID(&car->car_hai->hai_dfid),
-                      car->car_compound_id, car->car_hai->hai_cookie,
+                      car->car_hai->hai_cookie,
                       hsm_copytool_action2name(car->car_hai->hai_action),
                       car->car_archive_id, car->car_flags,
                       car->car_hai->hai_extent.offset,
@@ -184,13 +184,11 @@ static void mdt_cdt_free_request_tree(struct cdt_req_progress *crp)
        }
        /* free all sub vectors */
        for (i = 0 ; i <= crp->crp_max / NODE_VECTOR_SZ ; i++)
-               OBD_FREE(crp->crp_node[i],
-                        NODE_VECTOR_SZ * sizeof(crp->crp_node[i][0]));
+               OBD_FREE_PTR_ARRAY(crp->crp_node[i], NODE_VECTOR_SZ);
 
        /* free main vector */
-       OBD_FREE(crp->crp_node,
-                sizeof(crp->crp_node[0]) *
-                 (crp->crp_max / NODE_VECTOR_SZ + 1));
+       OBD_FREE_PTR_ARRAY(crp->crp_node,
+                          (crp->crp_max / NODE_VECTOR_SZ + 1));
 
        crp->crp_cnt = 0;
        crp->crp_max = 0;
@@ -221,7 +219,7 @@ static int hsm_update_work(struct cdt_req_progress *crp,
        if (crp->crp_cnt >= crp->crp_max) {
                /* no more room */
                /* allocate a new vector */
-               OBD_ALLOC(v, NODE_VECTOR_SZ * sizeof(v[0]));
+               OBD_ALLOC_PTR_ARRAY(v, NODE_VECTOR_SZ);
                if (v == NULL)
                        GOTO(out, rc = -ENOMEM);
 
@@ -235,7 +233,7 @@ static int hsm_update_work(struct cdt_req_progress *crp,
                /* increase main vector size */
                OBD_ALLOC(new_vv, nsz);
                if (new_vv == NULL) {
-                       OBD_FREE(v, NODE_VECTOR_SZ * sizeof(v[0]));
+                       OBD_FREE_PTR_ARRAY(v, NODE_VECTOR_SZ);
                        GOTO(out, rc = -ENOMEM);
                }
 
@@ -280,7 +278,6 @@ static void mdt_cdt_init_request_tree(struct cdt_req_progress *crp)
 
 /** Allocate/init an agent request and its sub-structures.
  *
- * \param compound_id [IN]
  * \param archive_id [IN]
  * \param flags [IN]
  * \param uuid [IN]
@@ -288,8 +285,8 @@ static void mdt_cdt_init_request_tree(struct cdt_req_progress *crp)
  * \retval car [OUT] success valid structure
  * \retval car [OUT]
  */
-struct cdt_agent_req *mdt_cdt_alloc_request(__u64 compound_id, __u32 archive_id,
-                                           __u64 flags, struct obd_uuid *uuid,
+struct cdt_agent_req *mdt_cdt_alloc_request(__u32 archive_id, __u64 flags,
+                                           struct obd_uuid *uuid,
                                            struct hsm_action_item *hai)
 {
        struct cdt_agent_req *car;
@@ -300,11 +297,10 @@ struct cdt_agent_req *mdt_cdt_alloc_request(__u64 compound_id, __u32 archive_id,
                RETURN(ERR_PTR(-ENOMEM));
 
        atomic_set(&car->car_refcount, 1);
-       car->car_compound_id = compound_id;
        car->car_archive_id = archive_id;
        car->car_flags = flags;
        car->car_canceled = 0;
-       car->car_req_start = cfs_time_current_sec();
+       car->car_req_start = ktime_get_real_seconds();
        car->car_req_update = car->car_req_start;
        car->car_uuid = *uuid;
        OBD_ALLOC(car->car_hai, hai->hai_len);
@@ -382,6 +378,17 @@ int mdt_cdt_add_request(struct coordinator *cdt, struct cdt_agent_req *car)
 
        mdt_hsm_agent_update_statistics(cdt, 0, 0, 1, &car->car_uuid);
 
+       switch (car->car_hai->hai_action) {
+       case HSMA_ARCHIVE:
+               atomic_inc(&cdt->cdt_archive_count);
+               break;
+       case HSMA_RESTORE:
+               atomic_inc(&cdt->cdt_restore_count);
+               break;
+       case HSMA_REMOVE:
+               atomic_inc(&cdt->cdt_remove_count);
+               break;
+       }
        atomic_inc(&cdt->cdt_request_count);
 
        RETURN(0);
@@ -427,11 +434,27 @@ int mdt_cdt_remove_request(struct coordinator *cdt, __u64 cookie)
        list_del(&car->car_request_list);
        up_write(&cdt->cdt_request_lock);
 
+       switch (car->car_hai->hai_action) {
+       case HSMA_ARCHIVE:
+               atomic_dec(&cdt->cdt_archive_count);
+               break;
+       case HSMA_RESTORE:
+               atomic_dec(&cdt->cdt_restore_count);
+               break;
+       case HSMA_REMOVE:
+               atomic_dec(&cdt->cdt_remove_count);
+               break;
+       }
+
        /* Drop reference from cdt_request_list. */
        mdt_cdt_put_request(car);
 
        LASSERT(atomic_read(&cdt->cdt_request_count) >= 1);
-       atomic_dec(&cdt->cdt_request_count);
+       if (atomic_dec_and_test(&cdt->cdt_request_count)) {
+               /* request count is empty, nudge coordinator for more work */
+               cdt->cdt_wakeup_coordinator = true;
+               wake_up_interruptible(&cdt->cdt_waitq);
+       }
 
        RETURN(0);
 }
@@ -455,7 +478,7 @@ struct cdt_agent_req *mdt_cdt_update_request(struct coordinator *cdt,
        if (car == NULL)
                RETURN(ERR_PTR(-ENOENT));
 
-       car->car_req_update = cfs_time_current_sec();
+       car->car_req_update = ktime_get_real_seconds();
 
        /* update data move progress done by copy tool */
        if (car->car_hai->hai_action != HSMA_REMOVE && pgs->hpk_errval == 0 &&
@@ -554,7 +577,7 @@ static int mdt_hsm_active_requests_proc_show(struct seq_file *s, void *v)
                   " data=[%s] canceled=%d uuid=%s done=%llu\n",
                   PFID(&car->car_hai->hai_fid),
                   PFID(&car->car_hai->hai_dfid),
-                  car->car_compound_id, car->car_hai->hai_cookie,
+                  0ULL /* compound_id */, car->car_hai->hai_cookie,
                   hsm_copytool_action2name(car->car_hai->hai_action),
                   car->car_archive_id, car->car_flags,
                   car->car_hai->hai_extent.offset,
@@ -592,8 +615,8 @@ static const struct seq_operations mdt_hsm_active_requests_proc_ops = {
  * public function called at open of /proc file to get
  * list of agents
  */
-static int lprocfs_open_hsm_active_requests(struct inode *inode,
-                                           struct file *file)
+static int ldebugfs_open_hsm_active_requests(struct inode *inode,
+                                            struct file *file)
 {
        struct seq_file *s;
        int              rc;
@@ -604,7 +627,7 @@ static int lprocfs_open_hsm_active_requests(struct inode *inode,
                RETURN(rc);
        }
        s = file->private_data;
-       s->private = PDE_DATA(inode);
+       s->private = inode->i_private;
 
        RETURN(rc);
 }
@@ -612,9 +635,9 @@ static int lprocfs_open_hsm_active_requests(struct inode *inode,
 /* methods to access hsm request list */
 const struct file_operations mdt_hsm_active_requests_fops = {
        .owner          = THIS_MODULE,
-       .open           = lprocfs_open_hsm_active_requests,
+       .open           = ldebugfs_open_hsm_active_requests,
        .read           = seq_read,
        .llseek         = seq_lseek,
-       .release        = lprocfs_seq_release,
+       .release        = seq_release,
 };