Whamcloud - gitweb
b=18881
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index 01b9572..f84459f 100644 (file)
@@ -78,7 +78,6 @@ struct echo_object_conf {
 
 struct echo_page {
         struct cl_page_slice   ep_cl;
-        struct cl_sync_io     *ep_sync_io;
         cfs_page_t            *ep_vmpage;
 };
 
@@ -187,7 +186,6 @@ struct echo_thread_info {
 
         struct cl_2queue        eti_queue;
         struct cl_io            eti_io;
-        struct cl_sync_io       eti_anchor;
         struct cl_lock_descr    eti_descr;
         struct lu_fid           eti_fid;
 };
@@ -256,7 +254,7 @@ cfs_page_t *echo_page_vmpage(const struct lu_env *env,
 
 static void echo_page_discard(const struct lu_env *env,
                               const struct cl_page_slice *slice,
-                              struct cl_io *_)
+                              struct cl_io *unused)
 {
         cl_page_delete(env, slice->cpl_page);
 }
@@ -271,14 +269,7 @@ static void echo_page_completion(const struct lu_env *env,
                                  const struct cl_page_slice *slice,
                                  int ioret)
 {
-        struct echo_page *ecp     = cl2echo_page(slice);
-        struct cl_sync_io *anchor = ecp->ep_sync_io;
-        ENTRY;
-
-        LASSERT(anchor != NULL);
-        ecp->ep_sync_io = NULL;
-        cl_sync_io_note(anchor, ioret);
-        EXIT;
+        LASSERT(slice->cpl_page->cp_sync_io != NULL);
 }
 
 static void echo_page_fini(const struct lu_env *env,
@@ -297,7 +288,7 @@ static void echo_page_fini(const struct lu_env *env,
 
 static int echo_page_prep(const struct lu_env *env,
                           const struct cl_page_slice *slice,
-                          struct cl_io *_)
+                          struct cl_io *unused)
 {
         return 0;
 }
@@ -358,7 +349,7 @@ static void echo_lock_delete(const struct lu_env *env,
 static int echo_lock_fits_into(const struct lu_env *env,
                                const struct cl_lock_slice *slice,
                                const struct cl_lock_descr *need,
-                               const struct cl_io *_)
+                               const struct cl_io *unused)
 {
         return 1;
 }
@@ -384,7 +375,7 @@ static struct cl_page *echo_page_init(const struct lu_env *env,
         struct echo_page *ep;
         ENTRY;
 
-        OBD_SLAB_ALLOC_PTR(ep, echo_page_kmem);
+        OBD_SLAB_ALLOC_PTR_GFP(ep, echo_page_kmem, CFS_ALLOC_IO);
         if (ep != NULL) {
                 struct echo_object *eco = cl2echo_obj(obj);
                 ep->ep_vmpage = vmpage;
@@ -403,12 +394,12 @@ static int echo_io_init(const struct lu_env *env, struct cl_object *obj,
 
 static int echo_lock_init(const struct lu_env *env,
                           struct cl_object *obj, struct cl_lock *lock,
-                          const struct cl_io *_)
+                          const struct cl_io *unused)
 {
         struct echo_lock *el;
         ENTRY;
 
-        OBD_SLAB_ALLOC_PTR(el, echo_lock_kmem);
+        OBD_SLAB_ALLOC_PTR_GFP(el, echo_lock_kmem, CFS_ALLOC_IO);
         if (el != NULL) {
                 cl_lock_slice_add(lock, &el->el_cl, obj, &echo_lock_ops);
                 el->el_object = cl2echo_obj(obj);
@@ -531,7 +522,7 @@ static struct lu_object *echo_object_alloc(const struct lu_env *env,
 
         /* we're the top dev. */
         LASSERT(hdr == NULL);
-        OBD_SLAB_ALLOC_PTR(eco, echo_object_kmem);
+        OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, CFS_ALLOC_IO);
         if (eco != NULL) {
                 struct cl_object_header *hdr = &eco->eo_hdr;
 
@@ -593,7 +584,7 @@ static void *echo_thread_key_init(const struct lu_context *ctx,
 {
         struct echo_thread_info *info;
 
-        OBD_SLAB_ALLOC_PTR(info, echo_thread_kmem);
+        OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, CFS_ALLOC_IO);
         if (info == NULL)
                 info = ERR_PTR(-ENOMEM);
         return info;
@@ -623,7 +614,7 @@ static void *echo_session_key_init(const struct lu_context *ctx,
 {
         struct echo_session_info *session;
 
-        OBD_SLAB_ALLOC_PTR(session, echo_session_kmem);
+        OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, CFS_ALLOC_IO);
         if (session == NULL)
                 session = ERR_PTR(-ENOMEM);
         return session;
@@ -694,7 +685,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
         tgt = class_name2obd(lustre_cfg_string(cfg, 1));
         LASSERT(tgt != NULL);
         next = tgt->obd_lu_dev;
-        if (!lu_device_is_cl(next))
+        if (next != NULL && !lu_device_is_cl(next))
                 next = NULL;
 
         /*
@@ -1049,23 +1040,21 @@ static int cl_echo_cancel(struct echo_device *ed, __u64 cookie)
 }
 
 static int cl_echo_async_brw(const struct lu_env *env, struct cl_io *io,
-                             enum cl_req_type _, struct cl_2queue *queue)
+                             enum cl_req_type unused, struct cl_2queue *queue)
 {
         struct cl_page *clp;
         struct cl_page *temp;
         int result = 0;
         ENTRY;
 
-        cl_page_list_splice(&queue->c2_qin, &queue->c2_qout);
-        cl_page_list_for_each_safe(clp, temp, &queue->c2_qout) {
+        cl_page_list_for_each_safe(clp, temp, &queue->c2_qin) {
                 int rc;
                 rc = cl_page_cache_add(env, io, clp, CRT_WRITE);
                 if (rc == 0)
                         continue;
-                cl_page_list_move(&queue->c2_qin, &queue->c2_qout, clp);
                 result = result ?: rc;
         }
-        RETURN(list_empty(&queue->c2_qout.pl_pages) ? result : 0);
+        RETURN(result);
 }
 
 static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
@@ -1075,11 +1064,9 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
         struct echo_thread_info *info;
         struct cl_object        *obj = echo_obj2cl(eco);
         struct echo_device      *ed  = eco->eo_dev;
-        struct cl_sync_io       *anchor;
         struct cl_2queue        *queue;
         struct cl_io            *io;
         struct cl_page          *clp;
-        struct echo_page        *ep;
 
         int page_size = cl_page_size(obj);
         int refcheck;
@@ -1094,10 +1081,8 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
 
         info    = echo_env_info(env);
         io      = &info->eti_io;
-        anchor  = &info->eti_anchor;
         queue   = &info->eti_queue;
 
-        cl_sync_io_init(anchor, npages);
         cl_2queue_init(queue);
         rc = cl_io_init(env, io, CIT_MISC, obj);
         if (rc < 0)
@@ -1121,8 +1106,6 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
                         break;
                 }
 
-                ep = cl2echo_page(cl_page_at(clp, &echo_device_type));
-                ep->ep_sync_io = anchor;
                 cl_2queue_add(queue, clp);
 
                 /* drop the reference count for cl_page_find, so that the page
@@ -1135,22 +1118,13 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
                 enum cl_req_type typ = rw == READ ? CRT_READ : CRT_WRITE;
 
                 async = async && (typ == CRT_WRITE);
-                rc = (async ? cl_echo_async_brw : cl_io_submit_rw)(env, io,
-                                                                   typ, queue);
+                if (async)
+                        rc = cl_echo_async_brw(env, io, typ, queue);
+                else
+                        rc = cl_io_submit_sync(env, io, typ, queue,
+                                               CRP_NORMAL, 0);
                 CDEBUG(D_INFO, "echo_client %s write returns %d\n",
                        async ? "async" : "sync", rc);
-                if (rc == 0) {
-                        /*
-                         * If some pages weren't sent for any reason (e.g.,
-                         * direct-io read found up-to-date pages in the
-                         * cache), count them as completed to avoid infinite
-                         * wait.
-                         */
-                        cl_page_list_for_each(clp, &queue->c2_qin)
-                                cl_sync_io_note(anchor, +1);
-                        /* wait for the IO to be finished. */
-                        rc = cl_sync_io_wait(env, io, &queue->c2_qout, anchor);
-                }
         }
 
         cl_2queue_discard(env, io, queue);
@@ -1870,7 +1844,6 @@ static int echo_client_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
 {
         struct echo_client_obd *ec = &obddev->u.echo_client;
         struct obd_device *tgt;
-        struct lustre_handle conn = {0, };
         struct obd_uuid echo_uuid = { "ECHO_UUID" };
         struct obd_connect_data *ocd = NULL;
         int rc;
@@ -1906,7 +1879,7 @@ static int echo_client_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
         ocd->ocd_version = LUSTRE_VERSION_CODE;
         ocd->ocd_group = FILTER_GROUP_ECHO;
 
-        rc = obd_connect(NULL, &conn, tgt, &echo_uuid, ocd, NULL);
+        rc = obd_connect(NULL, &ec->ec_exp, tgt, &echo_uuid, ocd, NULL);
 
         OBD_FREE(ocd, sizeof(*ocd));
 
@@ -1915,7 +1888,6 @@ static int echo_client_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
                        lustre_cfg_string(lcfg, 1));
                 return (rc);
         }
-        ec->ec_exp = class_conn2export(&conn);
 
         RETURN(rc);
 }
@@ -1939,18 +1911,17 @@ static int echo_client_cleanup(struct obd_device *obddev)
 }
 
 static int echo_client_connect(const struct lu_env *env,
-                               struct lustre_handle *conn,
+                               struct obd_export **exp,
                                struct obd_device *src, struct obd_uuid *cluuid,
                                struct obd_connect_data *data, void *localdata)
 {
-        struct obd_export *exp;
         int                rc;
+        struct lustre_handle conn = { 0 };
 
         ENTRY;
-        rc = class_connect(conn, src, cluuid);
+        rc = class_connect(&conn, src, cluuid);
         if (rc == 0) {
-                exp = class_conn2export(conn);
-                class_export_put(exp);
+                *exp = class_conn2export(&conn);
         }
 
         RETURN (rc);