Whamcloud - gitweb
LU-7318 out: dynamic reply size
[fs/lustre-release.git] / lustre / osp / osp_trans.c
index be7db77..b055d33 100644 (file)
@@ -20,7 +20,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2014, Intel Corporation.
+ * Copyright (c) 2014, 2015, Intel Corporation.
  */
 /*
  * lustre/osp/osp_trans.c
@@ -130,6 +130,9 @@ int osp_object_update_request_create(struct osp_update_request *our,
        if (ours == NULL)
                return -ENOMEM;
 
+       if (size < OUT_UPDATE_INIT_BUFFER_SIZE)
+               size = OUT_UPDATE_INIT_BUFFER_SIZE;
+
        ours->ours_req = object_update_request_alloc(size);
 
        if (IS_ERR(ours->ours_req)) {
@@ -140,6 +143,7 @@ int osp_object_update_request_create(struct osp_update_request *our,
        ours->ours_req_size = size;
        INIT_LIST_HEAD(&ours->ours_list);
        list_add_tail(&ours->ours_list, &our->our_req_list);
+       our->our_req_nr++;
 
        return 0;
 }
@@ -225,12 +229,13 @@ object_update_request_dump(const struct object_update_request *ourq,
 
                update = object_update_request_get(ourq, i, &size);
                LASSERT(update != NULL);
-               CDEBUG(mask, "i = %u fid = "DFID" op = %s master = %u"
-                      "params = %d batchid = "LPU64" size = %zu\n",
+               CDEBUG(mask, "i = %u fid = "DFID" op = %s "
+                      "params = %d batchid = "LPU64" size = %zu repsize %u\n",
                       i, PFID(&update->ou_fid),
                       update_op_str(update->ou_type),
-                      update->ou_master_index, update->ou_params_count,
-                      update->ou_batchid, size);
+                      update->ou_params_count,
+                      update->ou_batchid, size,
+                      (unsigned)update->ou_result_size);
 
                total_size += size;
        }
@@ -240,6 +245,57 @@ object_update_request_dump(const struct object_update_request *ourq,
 }
 
 /**
+ * Prepare inline update request
+ *
+ * Prepare OUT update ptlrpc inline request, and the request usually includes
+ * one update buffer, which does not need bulk transfer.
+ *
+ * \param[in] env      execution environment
+ * \param[in] req      ptlrpc request
+ * \param[in] ours     sub osp_update_request to be packed
+ *
+ * \retval             0 if packing succeeds
+ * \retval             negative errno if packing fails
+ */
+int osp_prep_inline_update_req(const struct lu_env *env,
+                              struct ptlrpc_request *req,
+                              struct osp_update_request *our,
+                              int repsize)
+{
+       struct osp_update_request_sub *ours;
+       struct out_update_header *ouh;
+       __u32 update_req_size;
+       int rc;
+
+       ours = list_entry(our->our_req_list.next,
+                         struct osp_update_request_sub, ours_list);
+       update_req_size = object_update_request_size(ours->ours_req);
+       req_capsule_set_size(&req->rq_pill, &RMF_OUT_UPDATE_HEADER, RCL_CLIENT,
+                            update_req_size + sizeof(*ouh));
+
+       rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, OUT_UPDATE);
+       if (rc != 0)
+               RETURN(rc);
+
+       ouh = req_capsule_client_get(&req->rq_pill, &RMF_OUT_UPDATE_HEADER);
+       ouh->ouh_magic = OUT_UPDATE_HEADER_MAGIC;
+       ouh->ouh_count = 1;
+       ouh->ouh_inline_length = update_req_size;
+       ouh->ouh_reply_size = repsize;
+
+       memcpy(ouh->ouh_inline_data, ours->ours_req, update_req_size);
+
+       req_capsule_set_size(&req->rq_pill, &RMF_OUT_UPDATE_REPLY,
+                            RCL_SERVER, repsize);
+
+       ptlrpc_request_set_replen(req);
+       req->rq_request_portal = OUT_PORTAL;
+       req->rq_reply_portal = OSC_REPLY_PORTAL;
+
+       RETURN(rc);
+}
+
+/**
  * Prepare update request.
  *
  * Prepare OUT update ptlrpc request, and the request usually includes
@@ -260,21 +316,65 @@ int osp_prep_update_req(const struct lu_env *env, struct obd_import *imp,
        struct ptlrpc_request           *req;
        struct ptlrpc_bulk_desc         *desc;
        struct osp_update_request_sub   *ours;
+       const struct object_update_request *ourq;
        struct out_update_header        *ouh;
        struct out_update_buffer        *oub;
        __u32                           buf_count = 0;
-       int                             rc;
+       int                             repsize = 0;
+       struct object_update_reply      *reply;
+       int                             rc, i;
+       int                             total = 0;
        ENTRY;
 
        list_for_each_entry(ours, &our->our_req_list, ours_list) {
                object_update_request_dump(ours->ours_req, D_INFO);
+
+               ourq = ours->ours_req;
+               for (i = 0; i < ourq->ourq_count; i++) {
+                       struct object_update    *update;
+                       size_t                  size = 0;
+
+
+                       /* XXX: it's very inefficient to lookup update
+                        *      this way, iterating from the beginning
+                        *      each time */
+                       update = object_update_request_get(ourq, i, &size);
+                       LASSERT(update != NULL);
+
+                       repsize += sizeof(reply->ourp_lens[0]);
+                       repsize += sizeof(struct object_update_result);
+                       repsize += update->ou_result_size;
+               }
+
                buf_count++;
        }
+       repsize += sizeof(*reply);
+       repsize = (repsize + OUT_UPDATE_REPLY_SIZE - 1) &
+                       ~(OUT_UPDATE_REPLY_SIZE - 1);
+       LASSERT(buf_count > 0);
 
        req = ptlrpc_request_alloc(imp, &RQF_OUT_UPDATE);
        if (req == NULL)
                RETURN(-ENOMEM);
 
+       if (buf_count == 1) {
+               ours = list_entry(our->our_req_list.next,
+                                 struct osp_update_request_sub, ours_list);
+
+               /* Let's check if it can be packed inline */
+               if (object_update_request_size(ours->ours_req) +
+                   sizeof(struct out_update_header) <
+                               OUT_UPDATE_MAX_INLINE_SIZE) {
+                       rc = osp_prep_inline_update_req(env, req, our, repsize);
+                       if (rc == 0)
+                               *reqp = req;
+                       GOTO(out_req, rc);
+               }
+       }
+
+       req_capsule_set_size(&req->rq_pill, &RMF_OUT_UPDATE_HEADER, RCL_CLIENT,
+                            sizeof(struct osp_update_request));
+
        req_capsule_set_size(&req->rq_pill, &RMF_OUT_UPDATE_BUF, RCL_CLIENT,
                             buf_count * sizeof(*oub));
 
@@ -285,7 +385,8 @@ int osp_prep_update_req(const struct lu_env *env, struct obd_import *imp,
        ouh = req_capsule_client_get(&req->rq_pill, &RMF_OUT_UPDATE_HEADER);
        ouh->ouh_magic = OUT_UPDATE_HEADER_MAGIC;
        ouh->ouh_count = buf_count;
-
+       ouh->ouh_inline_length = 0;
+       ouh->ouh_reply_size = repsize;
        oub = req_capsule_client_get(&req->rq_pill, &RMF_OUT_UPDATE_BUF);
        list_for_each_entry(ours, &our->our_req_list, ours_list) {
                oub->oub_size = ours->ours_req_size;
@@ -301,12 +402,15 @@ int osp_prep_update_req(const struct lu_env *env, struct obd_import *imp,
                GOTO(out_req, rc = -ENOMEM);
 
        /* NB req now owns desc and will free it when it gets freed */
-       list_for_each_entry(ours, &our->our_req_list, ours_list)
+       list_for_each_entry(ours, &our->our_req_list, ours_list) {
                desc->bd_frag_ops->add_iov_frag(desc, ours->ours_req,
                                                ours->ours_req_size);
+               total += ours->ours_req_size;
+       }
+       CDEBUG(D_OTHER, "total %d in %u\n", total, our->our_update_nr);
 
        req_capsule_set_size(&req->rq_pill, &RMF_OUT_UPDATE_REPLY,
-                            RCL_SERVER, OUT_UPDATE_REPLY_SIZE);
+                            RCL_SERVER, repsize);
 
        ptlrpc_request_set_replen(req);
        req->rq_request_portal = OUT_PORTAL;
@@ -333,7 +437,6 @@ out_req:
  * \retval             0 if RPC succeeds.
  * \retval             negative errno if RPC fails.
  */
-
 int osp_remote_sync(const struct lu_env *env, struct osp_device *osp,
                    struct osp_update_request *our,
                    struct ptlrpc_request **reqp)
@@ -564,7 +667,7 @@ int osp_unplug_async_request(const struct lu_env *env,
                args->oaua_waitq = NULL;
                args->oaua_flow_control = false;
                req->rq_interpret_reply = osp_update_interpret;
-               ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
+               ptlrpcd_add_req(req);
        }
 
        return rc;
@@ -649,6 +752,7 @@ int osp_insert_update_callback(const struct lu_env *env,
  * \param[in] lens             buffer length array for the subsequent \a bufs
  * \param[in] bufs             the buffers to compose the request
  * \param[in] data             pointer to the data used by the interpreter
+ * \param[in] repsize          how many bytes the caller allocated for \a data
  * \param[in] interpreter      pointer to the interpreter function
  *
  * \retval                     0 for success
@@ -656,7 +760,8 @@ int osp_insert_update_callback(const struct lu_env *env,
  */
 int osp_insert_async_request(const struct lu_env *env, enum update_type op,
                             struct osp_object *obj, int count,
-                            __u16 *lens, const void **bufs, void *data,
+                            __u16 *lens, const void **bufs,
+                            void *data, __u32 repsize,
                             osp_update_interpreter_t interpreter)
 {
        struct osp_device               *osp;
@@ -682,7 +787,8 @@ again:
 
        object_update = update_buffer_get_update(ureq, ureq->ourq_count);
        rc = out_update_pack(env, object_update, &max_update_size, op,
-                            lu_object_fid(osp2lu_obj(obj)), count, lens, bufs);
+                            lu_object_fid(osp2lu_obj(obj)), count, lens, bufs,
+                            repsize);
        /* The queue is full. */
        if (rc == -E2BIG) {
                osp->opd_async_requests = NULL;
@@ -703,6 +809,7 @@ again:
                        RETURN(rc);
 
                ureq->ourq_count++;
+               our->our_update_nr++;
        }
 
        rc = osp_insert_update_callback(env, our, obj, data, interpreter);
@@ -727,9 +834,6 @@ int osp_trans_update_request_create(struct thandle *th)
        oth->ot_our = our;
        our->our_th = oth;
 
-       if (oth->ot_super.th_sync)
-               oth->ot_our->our_flags |= UPDATE_FL_SYNC;
-
        return 0;
 }
 
@@ -964,7 +1068,7 @@ static int osp_send_update_req(const struct lu_env *env,
                        atomic_inc(args->oaua_count);
                }
 
-               ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
+               ptlrpcd_add_req(req);
                req = NULL;
        } else {
                osp_thandle_get(oth); /* hold for commit callback */
@@ -982,9 +1086,11 @@ static int osp_send_update_req(const struct lu_env *env,
                if (top_device->ld_obd->obd_recovering)
                        req->rq_allow_replay = 1;
 
-               osp_get_rpc_lock(osp);
+               if (osp->opd_connect_mdt)
+                       osp_get_rpc_lock(osp);
                rc = ptlrpc_queue_wait(req);
-               osp_put_rpc_lock(osp);
+               if (osp->opd_connect_mdt)
+                       osp_put_rpc_lock(osp);
                if ((rc == -ENOMEM && req->rq_set == NULL) ||
                    (req->rq_transno == 0 && !req->rq_committed)) {
                        if (args->oaua_update != NULL) {
@@ -1270,6 +1376,8 @@ int osp_trans_start(const struct lu_env *env, struct dt_device *dt,
 {
        struct osp_thandle      *oth = thandle_to_osp_thandle(th);
 
+       if (oth->ot_super.th_sync)
+               oth->ot_our->our_flags |= UPDATE_FL_SYNC;
        /* For remote thandle, if there are local thandle, start it here*/
        if (is_only_remote_trans(th) && oth->ot_storage_th != NULL)
                return dt_trans_start(env, oth->ot_storage_th->th_dev,
@@ -1319,6 +1427,7 @@ int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
        }
 
        if (!osp->opd_connect_mdt) {
+               osp_trans_callback(env, oth, th->th_result);
                rc = osp_send_update_req(env, osp, oth->ot_our);
                GOTO(out, rc);
        }