Whamcloud - gitweb
LU-5061 obd: add lnb_ prefix to members of struct niobuf_local
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index 98fb3e0..6905ce6 100644 (file)
@@ -50,6 +50,7 @@
 #include <md_object.h>
 #include <lustre_fid.h>
 #include <lustre_acl.h>
+#include <lustre_ioctl.h>
 #include <lustre_net.h>
 
 #include "echo_internal.h"
@@ -75,9 +76,9 @@ struct echo_object {
         struct cl_object_header eo_hdr;
 
         struct echo_device     *eo_dev;
-        cfs_list_t              eo_obj_chain;
+       struct list_head        eo_obj_chain;
         struct lov_stripe_md   *eo_lsm;
-       atomic_t            eo_npages;
+       atomic_t                eo_npages;
         int                     eo_deleted;
 };
 
@@ -92,11 +93,11 @@ struct echo_page {
 };
 
 struct echo_lock {
-        struct cl_lock_slice   el_cl;
-        cfs_list_t             el_chain;
-        struct echo_object    *el_object;
-        __u64                  el_cookie;
-       atomic_t           el_refcount;
+       struct cl_lock_slice    el_cl;
+       struct list_head        el_chain;
+       struct echo_object     *el_object;
+       __u64                   el_cookie;
+       atomic_t                el_refcount;
 };
 
 static int echo_client_setup(const struct lu_env *env,
@@ -168,9 +169,6 @@ struct echo_object_conf *cl2echo_conf(const struct cl_object_conf *c)
 static struct echo_object *cl_echo_object_find(struct echo_device *d,
                                                struct lov_stripe_md **lsm);
 static int cl_echo_object_put(struct echo_object *eco);
-static int cl_echo_enqueue   (struct echo_object *eco, obd_off start,
-                              obd_off end, int mode, __u64 *cookie);
-static int cl_echo_cancel    (struct echo_device *d, __u64 cookie);
 static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
                              struct page **pages, int npages, int async);
 
@@ -347,7 +345,7 @@ static void echo_lock_fini(const struct lu_env *env,
 {
         struct echo_lock *ecl = cl2echo_lock(slice);
 
-        LASSERT(cfs_list_empty(&ecl->el_chain));
+       LASSERT(list_empty(&ecl->el_chain));
         OBD_SLAB_FREE_PTR(ecl, echo_lock_kmem);
 }
 
@@ -356,7 +354,7 @@ static void echo_lock_delete(const struct lu_env *env,
 {
         struct echo_lock *ecl      = cl2echo_lock(slice);
 
-        LASSERT(cfs_list_empty(&ecl->el_chain));
+       LASSERT(list_empty(&ecl->el_chain));
 }
 
 static int echo_lock_fits_into(const struct lu_env *env,
@@ -412,7 +410,7 @@ static int echo_lock_init(const struct lu_env *env,
        if (el != NULL) {
                cl_lock_slice_add(lock, &el->el_cl, obj, &echo_lock_ops);
                el->el_object = cl2echo_obj(obj);
-               CFS_INIT_LIST_HEAD(&el->el_chain);
+               INIT_LIST_HEAD(&el->el_chain);
                atomic_set(&el->el_refcount, 0);
        }
        RETURN(el == NULL ? -ENOMEM : 0);
@@ -475,7 +473,7 @@ static int echo_object_init(const struct lu_env *env, struct lu_object *obj,
        cl_object_page_init(lu2cl(obj), sizeof(struct echo_page));
 
        spin_lock(&ec->ec_lock);
-       cfs_list_add_tail(&eco->eo_obj_chain, &ec->ec_objects);
+       list_add_tail(&eco->eo_obj_chain, &ec->ec_objects);
        spin_unlock(&ec->ec_lock);
 
        RETURN(0);
@@ -541,7 +539,7 @@ static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
        LASSERT(atomic_read(&eco->eo_npages) == 0);
 
        spin_lock(&ec->ec_lock);
-        cfs_list_del_init(&eco->eo_obj_chain);
+       list_del_init(&eco->eo_obj_chain);
        spin_unlock(&ec->ec_lock);
 
         lu_object_fini(obj);
@@ -842,7 +840,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
                 ls = next->ld_site;
 
                spin_lock(&ls->ls_ld_lock);
-               cfs_list_for_each_entry(ld, &ls->ls_ld_linkage, ld_linkage) {
+               list_for_each_entry(ld, &ls->ls_ld_linkage, ld_linkage) {
                        if (strcmp(ld->ld_type->ldt_name, tgt_type_name) == 0) {
                                found = 1;
                                break;
@@ -983,7 +981,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
          * parallelly accessed.
          */
        spin_lock(&ec->ec_lock);
-       cfs_list_for_each_entry(eco, &ec->ec_objects, eo_obj_chain)
+       list_for_each_entry(eco, &ec->ec_objects, eo_obj_chain)
                eco->eo_deleted = 1;
        spin_unlock(&ec->ec_lock);
 
@@ -995,7 +993,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
 
        /* Wait for the last reference to be dropped. */
        spin_lock(&ec->ec_lock);
-       while (!cfs_list_empty(&ec->ec_objects)) {
+       while (!list_empty(&ec->ec_objects)) {
                spin_unlock(&ec->ec_lock);
                CERROR("echo_client still has objects at cleanup time, "
                       "wait for 1 second\n");
@@ -1006,7 +1004,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
        }
        spin_unlock(&ec->ec_lock);
 
-        LASSERT(cfs_list_empty(&ec->ec_locks));
+       LASSERT(list_empty(&ec->ec_locks));
 
        CDEBUG(D_INFO, "No object exists, exiting...\n");
 
@@ -1180,8 +1178,8 @@ static int cl_echo_enqueue0(struct lu_env *env, struct echo_object *eco,
                 if (rc == 0) {
                         el = cl2echo_lock(cl_lock_at(lck, &echo_device_type));
                        spin_lock(&ec->ec_lock);
-                       if (cfs_list_empty(&el->el_chain)) {
-                               cfs_list_add(&el->el_chain, &ec->ec_locks);
+                       if (list_empty(&el->el_chain)) {
+                               list_add(&el->el_chain, &ec->ec_locks);
                                el->el_cookie = ++ec->ec_unique;
                        }
                        atomic_inc(&el->el_refcount);
@@ -1194,56 +1192,24 @@ static int cl_echo_enqueue0(struct lu_env *env, struct echo_object *eco,
        RETURN(rc);
 }
 
-static int cl_echo_enqueue(struct echo_object *eco, obd_off start, obd_off end,
-                           int mode, __u64 *cookie)
-{
-        struct echo_thread_info *info;
-        struct lu_env *env;
-        struct cl_io *io;
-        int refcheck;
-        int result;
-        ENTRY;
-
-        env = cl_env_get(&refcheck);
-        if (IS_ERR(env))
-                RETURN(PTR_ERR(env));
-
-        info = echo_env_info(env);
-        io = &info->eti_io;
-
-       io->ci_ignore_layout = 1;
-        result = cl_io_init(env, io, CIT_MISC, echo_obj2cl(eco));
-        if (result < 0)
-                GOTO(out, result);
-        LASSERT(result == 0);
-
-        result = cl_echo_enqueue0(env, eco, start, end, mode, cookie, 0);
-        cl_io_fini(env, io);
-
-        EXIT;
-out:
-        cl_env_put(env, &refcheck);
-        return result;
-}
-
 static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
                            __u64 cookie)
 {
         struct echo_client_obd *ec = ed->ed_ec;
         struct echo_lock       *ecl = NULL;
-        cfs_list_t             *el;
+       struct list_head        *el;
         int found = 0, still_used = 0;
         ENTRY;
 
         LASSERT(ec != NULL);
        spin_lock(&ec->ec_lock);
-        cfs_list_for_each (el, &ec->ec_locks) {
-                ecl = cfs_list_entry (el, struct echo_lock, el_chain);
+       list_for_each(el, &ec->ec_locks) {
+               ecl = list_entry(el, struct echo_lock, el_chain);
                 CDEBUG(D_INFO, "ecl: %p, cookie: "LPX64"\n", ecl, ecl->el_cookie);
                 found = (ecl->el_cookie == cookie);
                 if (found) {
                        if (atomic_dec_and_test(&ecl->el_refcount))
-                                cfs_list_del_init(&ecl->el_chain);
+                               list_del_init(&ecl->el_chain);
                         else
                                 still_used = 1;
                         break;
@@ -1258,23 +1224,6 @@ static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
         RETURN(0);
 }
 
-static int cl_echo_cancel(struct echo_device *ed, __u64 cookie)
-{
-        struct lu_env *env;
-        int refcheck;
-        int rc;
-        ENTRY;
-
-        env = cl_env_get(&refcheck);
-        if (IS_ERR(env))
-                RETURN(PTR_ERR(env));
-
-        rc = cl_echo_cancel0(env, ed, cookie);
-
-        cl_env_put(env, &refcheck);
-        RETURN(rc);
-}
-
 static void echo_commit_callback(const struct lu_env *env, struct cl_io *io,
                                struct cl_page *page)
 {
@@ -1389,27 +1338,6 @@ out:
 static obd_id last_object_id;
 
 static int
-echo_copyout_lsm (struct lov_stripe_md *lsm, void *_ulsm, int ulsm_nob)
-{
-        struct lov_stripe_md *ulsm = _ulsm;
-        int nob, i;
-
-        nob = offsetof (struct lov_stripe_md, lsm_oinfo[lsm->lsm_stripe_count]);
-        if (nob > ulsm_nob)
-                return (-EINVAL);
-
-       if (copy_to_user (ulsm, lsm, sizeof(*ulsm)))
-                return (-EFAULT);
-
-        for (i = 0; i < lsm->lsm_stripe_count; i++) {
-               if (copy_to_user (ulsm->lsm_oinfo[i], lsm->lsm_oinfo[i],
-                                      sizeof(lsm->lsm_oinfo[0])))
-                        return (-EFAULT);
-        }
-        return 0;
-}
-
-static int
 echo_copyin_lsm (struct echo_device *ed, struct lov_stripe_md *lsm,
                  void *ulsm, int ulsm_nob)
 {
@@ -2361,8 +2289,12 @@ static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
 
 static void echo_put_object(struct echo_object *eco)
 {
-        if (cl_echo_object_put(eco))
-                CERROR("echo client: drop an object failed");
+       int rc;
+
+       rc = cl_echo_object_put(eco);
+       if (rc)
+               CERROR("%s: echo client drop an object failed: rc = %d\n",
+                      eco->eo_dev->ed_ec->ec_exp->exp_obd->obd_name, rc);
 }
 
 static void
@@ -2606,7 +2538,6 @@ static int echo_client_prep_commit(const struct lu_env *env,
                 }
 
                 ioo.ioo_bufcnt = npages;
-                oti->oti_transno = 0;
 
                 lpages = npages;
                ret = obd_preprw(env, rw, exp, oa, 1, &ioo, rnb, &lpages,
@@ -2616,14 +2547,14 @@ static int echo_client_prep_commit(const struct lu_env *env,
                 LASSERT(lpages == npages);
 
                 for (i = 0; i < lpages; i++) {
-                       struct page *page = lnb[i].page;
+                       struct page *page = lnb[i].lnb_page;
 
-                        /* read past eof? */
-                        if (page == NULL && lnb[i].rc == 0)
-                                continue;
+                       /* read past eof? */
+                       if (page == NULL && lnb[i].lnb_rc == 0)
+                               continue;
 
-                        if (async)
-                                lnb[i].flags |= OBD_BRW_ASYNC;
+                       if (async)
+                               lnb[i].lnb_flags |= OBD_BRW_ASYNC;
 
                        if (ostid_id(&oa->o_oi) == ECHO_PERSISTENT_OBJID ||
                            (oa->o_valid & OBD_MD_FLFLAGS) == 0 ||
@@ -2674,7 +2605,7 @@ static int echo_client_brw_ioctl(const struct lu_env *env, int rw,
         struct obdo *oa = &data->ioc_obdo1;
         struct echo_object *eco;
         int rc;
-        int async = 1;
+        int async = 0;
         long test_mode;
         ENTRY;
 
@@ -2688,14 +2619,14 @@ static int echo_client_brw_ioctl(const struct lu_env *env, int rw,
 
        /* OFD/obdfilter works only via prep/commit */
         test_mode = (long)data->ioc_pbuf1;
-        if (test_mode == 1)
-                async = 0;
-
         if (ed->ed_next == NULL && test_mode != 3) {
                 test_mode = 3;
                 data->ioc_plen1 = data->ioc_count;
         }
 
+       if (test_mode == 3)
+               async = 1;
+
         /* Truncate batch size to maximum */
         if (data->ioc_plen1 > PTLRPC_MAX_BRW_SIZE)
                 data->ioc_plen1 = PTLRPC_MAX_BRW_SIZE;
@@ -2722,54 +2653,6 @@ static int echo_client_brw_ioctl(const struct lu_env *env, int rw,
 }
 
 static int
-echo_client_enqueue(struct obd_export *exp, struct obdo *oa,
-                    int mode, obd_off offset, obd_size nob)
-{
-        struct echo_device     *ed = obd2echo_dev(exp->exp_obd);
-        struct lustre_handle   *ulh = &oa->o_handle;
-        struct echo_object     *eco;
-        obd_off                 end;
-        int                     rc;
-        ENTRY;
-
-        if (ed->ed_next == NULL)
-                RETURN(-EOPNOTSUPP);
-
-        if (!(mode == LCK_PR || mode == LCK_PW))
-                RETURN(-EINVAL);
-
-        if ((offset & (~CFS_PAGE_MASK)) != 0 ||
-            (nob & (~CFS_PAGE_MASK)) != 0)
-                RETURN(-EINVAL);
-
-        rc = echo_get_object (&eco, ed, oa);
-        if (rc != 0)
-                RETURN(rc);
-
-        end = (nob == 0) ? ((obd_off) -1) : (offset + nob - 1);
-        rc = cl_echo_enqueue(eco, offset, end, mode, &ulh->cookie);
-        if (rc == 0) {
-                oa->o_valid |= OBD_MD_FLHANDLE;
-                CDEBUG(D_INFO, "Cookie is "LPX64"\n", ulh->cookie);
-        }
-        echo_put_object(eco);
-        RETURN(rc);
-}
-
-static int
-echo_client_cancel(struct obd_export *exp, struct obdo *oa)
-{
-        struct echo_device *ed     = obd2echo_dev(exp->exp_obd);
-        __u64               cookie = oa->o_handle.cookie;
-
-        if ((oa->o_valid & OBD_MD_FLHANDLE) == 0)
-                return -EINVAL;
-
-        CDEBUG(D_INFO, "Cookie is "LPX64"\n", cookie);
-        return cl_echo_cancel(ed, cookie);
-}
-
-static int
 echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                       void *karg, void *uarg)
 {
@@ -2952,46 +2835,6 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                rc = echo_client_brw_ioctl(env, rw, exp, data, &dummy_oti);
                 GOTO(out, rc);
 
-        case ECHO_IOC_GET_STRIPE:
-                rc = echo_get_object(&eco, ed, oa);
-                if (rc == 0) {
-                        rc = echo_copyout_lsm(eco->eo_lsm, data->ioc_pbuf1,
-                                              data->ioc_plen1);
-                        echo_put_object(eco);
-                }
-                GOTO(out, rc);
-
-        case ECHO_IOC_SET_STRIPE:
-                if (!cfs_capable(CFS_CAP_SYS_ADMIN))
-                        GOTO (out, rc = -EPERM);
-
-                if (data->ioc_pbuf1 == NULL) {  /* unset */
-                        rc = echo_get_object(&eco, ed, oa);
-                        if (rc == 0) {
-                                eco->eo_deleted = 1;
-                                echo_put_object(eco);
-                        }
-                } else {
-                        rc = echo_create_object(env, ed, 0, oa,
-                                                data->ioc_pbuf1,
-                                                data->ioc_plen1, &dummy_oti);
-                }
-                GOTO (out, rc);
-
-        case ECHO_IOC_ENQUEUE:
-                if (!cfs_capable(CFS_CAP_SYS_ADMIN))
-                        GOTO (out, rc = -EPERM);
-
-                rc = echo_client_enqueue(exp, oa,
-                                         data->ioc_conn1, /* lock mode */
-                                         data->ioc_offset,
-                                         data->ioc_count);/*extent*/
-                GOTO (out, rc);
-
-        case ECHO_IOC_CANCEL:
-                rc = echo_client_cancel(exp, oa);
-                GOTO (out, rc);
-
         default:
                 CERROR ("echo_ioctl(): unrecognised ioctl %#x\n", cmd);
                 GOTO (out, rc = -ENOTTY);
@@ -3042,8 +2885,8 @@ static int echo_client_setup(const struct lu_env *env,
         }
 
        spin_lock_init(&ec->ec_lock);
-        CFS_INIT_LIST_HEAD (&ec->ec_objects);
-        CFS_INIT_LIST_HEAD (&ec->ec_locks);
+       INIT_LIST_HEAD(&ec->ec_objects);
+       INIT_LIST_HEAD(&ec->ec_locks);
         ec->ec_unique = 0;
         ec->ec_nstripes = 0;
 
@@ -3079,7 +2922,7 @@ static int echo_client_setup(const struct lu_env *env,
         if (rc == 0) {
                 /* Turn off pinger because it connects to tgt obd directly. */
                spin_lock(&tgt->obd_dev_lock);
-               cfs_list_del_init(&ec->ec_exp->exp_obd_chain_timed);
+               list_del_init(&ec->ec_exp->exp_obd_chain_timed);
                spin_unlock(&tgt->obd_dev_lock);
         }
 
@@ -3116,7 +2959,7 @@ static int echo_client_cleanup(struct obd_device *obddev)
                 RETURN(0);
         }
 
-        if (!cfs_list_empty(&obddev->obd_exports)) {
+       if (!list_empty(&obddev->obd_exports)) {
                 CERROR("still has clients!\n");
                 RETURN(-EBUSY);
         }