Whamcloud - gitweb
LU-4088 obdecho: Copy entire lsm, not just pointer size
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index b15483f..0b22468 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -47,6 +47,7 @@
 #include <lustre_debug.h>
 #include <lprocfs_status.h>
 #include <cl_object.h>
+#include <md_object.h>
 #include <lustre_fid.h>
 #include <lustre_acl.h>
 #include <lustre_net.h>
@@ -89,7 +90,7 @@ struct echo_object_conf {
 struct echo_page {
         struct cl_page_slice   ep_cl;
        struct mutex            ep_lock;
-        cfs_page_t            *ep_vmpage;
+       struct page            *ep_vmpage;
 };
 
 struct echo_lock {
@@ -174,14 +175,6 @@ struct echo_object_conf *cl2echo_conf(const struct cl_object_conf *c)
         return container_of(c, struct echo_object_conf, eoc_cl);
 }
 
-static inline void lsm2fid(struct lov_stripe_md *lsm, struct lu_fid *fid)
-{
-        fid_zero(fid);
-        fid->f_seq = FID_SEQ_ECHO;
-        /* truncated to 32 bits by assignment */
-        fid->f_oid = lsm->lsm_object_id;
-        fid->f_ver = lsm->lsm_object_id >> 32;
-}
 /** @} echo_helpers */
 
 static struct echo_object *cl_echo_object_find(struct echo_device *d,
@@ -191,30 +184,32 @@ 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,
-                              cfs_page_t **pages, int npages, int async);
+                             struct page **pages, int npages, int async);
 
 static struct echo_thread_info *echo_env_info(const struct lu_env *env);
 
 struct echo_thread_info {
-        struct echo_object_conf eti_conf;
-        struct lustre_md        eti_md;
+       struct echo_object_conf eti_conf;
+       struct lustre_md        eti_md;
 
-        struct cl_2queue        eti_queue;
-        struct cl_io            eti_io;
-        struct cl_lock_descr    eti_descr;
-        struct lu_fid           eti_fid;
+       struct cl_2queue        eti_queue;
+       struct cl_io            eti_io;
+       struct cl_lock_descr    eti_descr;
+       struct lu_fid           eti_fid;
        struct lu_fid           eti_fid2;
-        struct md_op_spec       eti_spec;
-        struct lov_mds_md_v3    eti_lmm;
-        struct lov_user_md_v3   eti_lum;
-        struct md_attr          eti_ma;
-        struct lu_name          eti_lname;
+#ifdef HAVE_SERVER_SUPPORT
+       struct md_op_spec       eti_spec;
+       struct lov_mds_md_v3    eti_lmm;
+       struct lov_user_md_v3   eti_lum;
+       struct md_attr          eti_ma;
+       struct lu_name          eti_lname;
        /* per-thread values, can be re-used */
        void                    *eti_big_lmm;
        int                     eti_big_lmmsize;
-        char                    eti_name[20];
-        struct lu_buf           eti_buf;
-        char                    eti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
+       char                    eti_name[20];
+       struct lu_buf           eti_buf;
+       char                    eti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
+#endif
 };
 
 /* No session used right now */
@@ -222,20 +217,14 @@ struct echo_session_info {
         unsigned long dummy;
 };
 
-static cfs_mem_cache_t *echo_page_kmem;
-static cfs_mem_cache_t *echo_lock_kmem;
-static cfs_mem_cache_t *echo_object_kmem;
-static cfs_mem_cache_t *echo_thread_kmem;
-static cfs_mem_cache_t *echo_session_kmem;
-//static cfs_mem_cache_t *echo_req_kmem;
+static struct kmem_cache *echo_lock_kmem;
+static struct kmem_cache *echo_object_kmem;
+static struct kmem_cache *echo_thread_kmem;
+static struct kmem_cache *echo_session_kmem;
+/* static struct kmem_cache *echo_req_kmem; */
 
 static struct lu_kmem_descr echo_caches[] = {
         {
-                .ckd_cache = &echo_page_kmem,
-                .ckd_name  = "echo_page_kmem",
-                .ckd_size  = sizeof (struct echo_page)
-        },
-        {
                 .ckd_cache = &echo_lock_kmem,
                 .ckd_name  = "echo_lock_kmem",
                 .ckd_size  = sizeof (struct echo_lock)
@@ -273,7 +262,7 @@ static struct lu_kmem_descr echo_caches[] = {
  *
  * @{
  */
-static cfs_page_t *echo_page_vmpage(const struct lu_env *env,
+static struct page *echo_page_vmpage(const struct lu_env *env,
                                     const struct cl_page_slice *slice)
 {
         return cl2echo_page(slice)->ep_vmpage;
@@ -325,17 +314,14 @@ static void echo_page_completion(const struct lu_env *env,
 }
 
 static void echo_page_fini(const struct lu_env *env,
-                           struct cl_page_slice *slice)
+                          struct cl_page_slice *slice)
 {
-        struct echo_page *ep    = cl2echo_page(slice);
-        struct echo_object *eco = cl2echo_obj(slice->cpl_obj);
-        cfs_page_t *vmpage      = ep->ep_vmpage;
-        ENTRY;
+       struct echo_object *eco = cl2echo_obj(slice->cpl_obj);
+       ENTRY;
 
-        cfs_atomic_dec(&eco->eo_npages);
-        page_cache_release(vmpage);
-        OBD_SLAB_FREE_PTR(ep, echo_page_kmem);
-        EXIT;
+       cfs_atomic_dec(&eco->eo_npages);
+       page_cache_release(cl2echo_page(slice)->ep_vmpage);
+       EXIT;
 }
 
 static int echo_page_prep(const struct lu_env *env,
@@ -422,23 +408,19 @@ static struct cl_lock_operations echo_lock_ops = {
  *
  * @{
  */
-static struct cl_page *echo_page_init(const struct lu_env *env,
-                                      struct cl_object *obj,
-                                      struct cl_page *page, cfs_page_t *vmpage)
+static int echo_page_init(const struct lu_env *env, struct cl_object *obj,
+                       struct cl_page *page, struct page *vmpage)
 {
-        struct echo_page *ep;
+        struct echo_page *ep = cl_object_page_slice(obj, page);
+       struct echo_object *eco = cl2echo_obj(obj);
         ENTRY;
 
-        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;
-                page_cache_get(vmpage);
-               mutex_init(&ep->ep_lock);
-                cl_page_slice_add(page, &ep->ep_cl, obj, &echo_page_ops);
-                cfs_atomic_inc(&eco->eo_npages);
-        }
-        RETURN(ERR_PTR(ep ? 0 : -ENOMEM));
+       ep->ep_vmpage = vmpage;
+       page_cache_get(vmpage);
+       mutex_init(&ep->ep_lock);
+       cl_page_slice_add(page, &ep->ep_cl, obj, &echo_page_ops);
+       cfs_atomic_inc(&eco->eo_npages);
+        RETURN(0);
 }
 
 static int echo_io_init(const struct lu_env *env, struct cl_object *obj,
@@ -454,7 +436,7 @@ static int echo_lock_init(const struct lu_env *env,
         struct echo_lock *el;
         ENTRY;
 
-        OBD_SLAB_ALLOC_PTR_GFP(el, echo_lock_kmem, CFS_ALLOC_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(el, echo_lock_kmem, __GFP_IO);
         if (el != NULL) {
                 cl_lock_slice_add(lock, &el->el_cl, obj, &echo_lock_ops);
                 el->el_object = cl2echo_obj(obj);
@@ -518,6 +500,7 @@ static int echo_object_init(const struct lu_env *env, struct lu_object *obj,
 
         eco->eo_dev = ed;
         cfs_atomic_set(&eco->eo_npages, 0);
+       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);
@@ -553,6 +536,7 @@ static int echo_alloc_memmd(struct echo_device *ed,
 
        loi_init((*lsmp)->lsm_oinfo[0]);
        (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
+       ostid_set_seq_echo(&(*lsmp)->lsm_oi);
 
        RETURN(lsm_size);
 }
@@ -631,7 +615,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_GFP(eco, echo_object_kmem, CFS_ALLOC_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, __GFP_IO);
         if (eco != NULL) {
                 struct cl_object_header *hdr = &eco->eo_hdr;
 
@@ -695,7 +679,7 @@ static void *echo_thread_key_init(const struct lu_context *ctx,
 {
         struct echo_thread_info *info;
 
-        OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, CFS_ALLOC_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, __GFP_IO);
         if (info == NULL)
                 info = ERR_PTR(-ENOMEM);
         return info;
@@ -725,7 +709,7 @@ static void *echo_session_key_init(const struct lu_context *ctx,
 {
         struct echo_session_info *session;
 
-        OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, CFS_ALLOC_IO);
+       OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, __GFP_IO);
         if (session == NULL)
                 session = ERR_PTR(-ENOMEM);
         return session;
@@ -752,7 +736,8 @@ static struct lu_context_key echo_session_key = {
 
 LU_TYPE_INIT_FINI(echo, &echo_thread_key, &echo_session_key);
 
-#define ECHO_SEQ_WIDTH 0xffffffff
+#ifdef HAVE_SERVER_SUPPORT
+# define ECHO_SEQ_WIDTH 0xffffffff
 static int echo_fid_init(struct echo_device *ed, char *obd_name,
                         struct seq_server_site *ss)
 {
@@ -800,6 +785,7 @@ static int echo_fid_fini(struct obd_device *obddev)
 
         RETURN(0);
 }
+#endif /* HAVE_SERVER_SUPPORT */
 
 static struct lu_device *echo_device_alloc(const struct lu_env *env,
                                            struct lu_device_type *t,
@@ -859,6 +845,7 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
         cleanup = 4;
 
         if (ed->ed_next_ismd) {
+#ifdef HAVE_SERVER_SUPPORT
                 /* Suppose to connect to some Metadata layer */
                 struct lu_site *ls;
                 struct lu_device *ld;
@@ -905,6 +892,12 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
                        CERROR("echo fid init error %d\n", rc);
                        GOTO(out, rc);
                }
+#else /* !HAVE_SERVER_SUPPORT */
+               CERROR("Local operations are NOT supported on client side. "
+                      "Only remote operations are supported. Metadata client "
+                      "must be run on server side.\n");
+               GOTO(out, rc = -EOPNOTSUPP);
+#endif
         } else {
                  /* if echo client is to be stacked upon ost device, the next is
                   * NULL since ost is not a clio device so far */
@@ -1032,7 +1025,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
                spin_unlock(&ec->ec_lock);
                CERROR("echo_client still has objects at cleanup time, "
                       "wait for 1 second\n");
-               cfs_schedule_timeout_and_set_state(CFS_TASK_UNINT,
+               schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE,
                                                   cfs_time_seconds(1));
                lu_site_purge(env, &ed->ed_site->cs_lu, -1);
                spin_lock(&ec->ec_lock);
@@ -1041,12 +1034,14 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
 
         LASSERT(cfs_list_empty(&ec->ec_locks));
 
-        CDEBUG(D_INFO, "No object exists, exiting...\n");
+       CDEBUG(D_INFO, "No object exists, exiting...\n");
 
-        echo_client_cleanup(d->ld_obd);
-        echo_fid_fini(d->ld_obd);
-        while (next && !ed->ed_next_ismd)
-                next = next->ld_type->ldt_ops->ldto_device_free(env, next);
+       echo_client_cleanup(d->ld_obd);
+#ifdef HAVE_SERVER_SUPPORT
+       echo_fid_fini(d->ld_obd);
+#endif
+       while (next && !ed->ed_next_ismd)
+               next = next->ld_type->ldt_ops->ldto_device_free(env, next);
 
         LASSERT(ed->ed_site == lu2cl_site(d->ld_site));
         echo_site_fini(env, ed);
@@ -1096,12 +1091,15 @@ static struct echo_object *cl_echo_object_find(struct echo_device *d,
         struct cl_object   *obj;
         struct lu_fid *fid;
         int refcheck;
-        ENTRY;
+       int rc;
+       ENTRY;
 
-        LASSERT(lsmp);
-        lsm = *lsmp;
-        LASSERT(lsm);
-        LASSERT(lsm->lsm_object_id);
+       LASSERT(lsmp);
+       lsm = *lsmp;
+       LASSERT(lsm);
+       LASSERTF(ostid_id(&lsm->lsm_oi) != 0, DOSTID"\n", POSTID(&lsm->lsm_oi));
+       LASSERTF(ostid_seq(&lsm->lsm_oi) == FID_SEQ_ECHO, DOSTID"\n",
+                POSTID(&lsm->lsm_oi));
 
         /* Never return an object if the obd is to be freed. */
         if (echo_dev2cl(d)->cd_lu_dev.ld_obd->obd_stopping)
@@ -1117,8 +1115,7 @@ static struct echo_object *cl_echo_object_find(struct echo_device *d,
                 if (!d->ed_next_islov) {
                         struct lov_oinfo *oinfo = lsm->lsm_oinfo[0];
                         LASSERT(oinfo != NULL);
-                        oinfo->loi_id = lsm->lsm_object_id;
-                        oinfo->loi_seq = lsm->lsm_object_seq;
+                       oinfo->loi_oi = lsm->lsm_oi;
                         conf->eoc_cl.u.coc_oinfo = oinfo;
                 } else {
                         struct lustre_md *md;
@@ -1130,8 +1127,10 @@ static struct echo_object *cl_echo_object_find(struct echo_device *d,
         }
         conf->eoc_md = lsmp;
 
-        fid  = &info->eti_fid;
-        lsm2fid(lsm, fid);
+       fid  = &info->eti_fid;
+       rc = ostid_to_fid(fid, &lsm->lsm_oi, 0);
+       if (rc != 0)
+               GOTO(out, eco = ERR_PTR(rc));
 
        /* In the function below, .hs_keycmp resolves to
         * lu_obj_hop_keycmp() */
@@ -1215,7 +1214,7 @@ static int cl_echo_enqueue0(struct lu_env *env, struct echo_object *eco,
                        *cookie = el->el_cookie;
                        spin_unlock(&ec->ec_lock);
                } else {
-                       cl_lock_release(env, lck, "ec enqueue", cfs_current());
+                       cl_lock_release(env, lck, "ec enqueue", current);
                }
        }
        RETURN(rc);
@@ -1302,26 +1301,21 @@ static int cl_echo_cancel(struct echo_device *ed, __u64 cookie)
         RETURN(rc);
 }
 
-static int cl_echo_async_brw(const struct lu_env *env, struct cl_io *io,
-                             enum cl_req_type unused, struct cl_2queue *queue)
+static void echo_commit_callback(const struct lu_env *env, struct cl_io *io,
+                               struct cl_page *page)
 {
-        struct cl_page *clp;
-        struct cl_page *temp;
-        int result = 0;
-        ENTRY;
+       struct echo_thread_info *info;
+       struct cl_2queue        *queue;
 
-        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;
-                result = result ?: rc;
-        }
-        RETURN(result);
+       info = echo_env_info(env);
+       LASSERT(io == &info->eti_io);
+
+       queue = &info->eti_queue;
+       cl_page_list_add(&queue->c2_qout, page);
 }
 
 static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
-                              cfs_page_t **pages, int npages, int async)
+                             struct page **pages, int npages, int async)
 {
         struct lu_env           *env;
         struct echo_thread_info *info;
@@ -1357,7 +1351,7 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
 
 
         rc = cl_echo_enqueue0(env, eco, offset,
-                              offset + npages * CFS_PAGE_SIZE - 1,
+                             offset + npages * PAGE_CACHE_SIZE - 1,
                               rw == READ ? LCK_PR : LCK_PW, &lh.cookie,
                               CEF_NEVER);
         if (rc < 0)
@@ -1395,8 +1389,10 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
 
                 async = async && (typ == CRT_WRITE);
                 if (async)
-                        rc = cl_echo_async_brw(env, io, typ, queue);
-                else
+                       rc = cl_io_commit_async(env, io, &queue->c2_qin,
+                                               0, PAGE_SIZE,
+                                               echo_commit_callback);
+               else
                        rc = cl_io_submit_sync(env, io, typ, queue, 0);
                 CDEBUG(D_INFO, "echo_client %s write returns %d\n",
                        async ? "async" : "sync", rc);
@@ -1428,11 +1424,11 @@ echo_copyout_lsm (struct lov_stripe_md *lsm, void *_ulsm, int ulsm_nob)
         if (nob > ulsm_nob)
                 return (-EINVAL);
 
-        if (cfs_copy_to_user (ulsm, lsm, sizeof(ulsm)))
+       if (copy_to_user (ulsm, lsm, sizeof(*ulsm)))
                 return (-EFAULT);
 
         for (i = 0; i < lsm->lsm_stripe_count; i++) {
-                if (cfs_copy_to_user (ulsm->lsm_oinfo[i], lsm->lsm_oinfo[i],
+               if (copy_to_user (ulsm->lsm_oinfo[i], lsm->lsm_oinfo[i],
                                       sizeof(lsm->lsm_oinfo[0])))
                         return (-EFAULT);
         }
@@ -1449,7 +1445,7 @@ echo_copyin_lsm (struct echo_device *ed, struct lov_stripe_md *lsm,
         if (ulsm_nob < sizeof (*lsm))
                 return (-EINVAL);
 
-        if (cfs_copy_from_user (lsm, ulsm, sizeof (*lsm)))
+       if (copy_from_user (lsm, ulsm, sizeof (*lsm)))
                 return (-EFAULT);
 
         if (lsm->lsm_stripe_count > ec->ec_nstripes ||
@@ -1460,7 +1456,7 @@ echo_copyin_lsm (struct echo_device *ed, struct lov_stripe_md *lsm,
 
 
         for (i = 0; i < lsm->lsm_stripe_count; i++) {
-                if (cfs_copy_from_user(lsm->lsm_oinfo[i],
+               if (copy_from_user(lsm->lsm_oinfo[i],
                                        ((struct lov_stripe_md *)ulsm)-> \
                                        lsm_oinfo[i],
                                        sizeof(lsm->lsm_oinfo[0])))
@@ -1469,6 +1465,7 @@ echo_copyin_lsm (struct echo_device *ed, struct lov_stripe_md *lsm,
         return (0);
 }
 
+#ifdef HAVE_SERVER_SUPPORT
 static inline void echo_md_build_name(struct lu_name *lname, char *name,
                                      __u64 id)
 {
@@ -1530,7 +1527,7 @@ int echo_attr_get_complex(const struct lu_env *env, struct md_object *next,
 {
        struct echo_thread_info *info = echo_env_info(env);
        struct lu_buf           *buf = &info->eti_buf;
-       cfs_umode_t              mode = lu_object_attr(&next->mo_lu);
+       umode_t          mode = lu_object_attr(&next->mo_lu);
        int                      need = ma->ma_need;
        int                      rc = 0, rc2;
 
@@ -1758,6 +1755,9 @@ static struct lu_object *echo_md_lookup(const struct lu_env *env,
                 RETURN(ERR_PTR(rc));
         }
 
+       /* In the function below, .hs_keycmp resolves to
+        * lu_obj_hop_keycmp() */
+       /* coverity[overrun-buffer-val] */
         child = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, fid, NULL);
 
         RETURN(child);
@@ -1960,15 +1960,20 @@ static int echo_md_destroy_internal(const struct lu_env *env,
                 GOTO(out_put, rc = -EINVAL);
         }
 
+       if (lu_object_remote(child)) {
+               CERROR("Can not destroy remote object %s: rc = %d\n",
+                      lname->ln_name, -EPERM);
+               GOTO(out_put, rc = -EPERM);
+       }
         CDEBUG(D_RPCTRACE, "Start destroy object "DFID" %s %p\n",
                PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
 
-        rc = mdo_unlink(env, parent, lu2md(child), lname, ma);
-        if (rc) {
-                CERROR("Can not unlink child %s: rc = %d\n",
-                        lname->ln_name, rc);
-                GOTO(out_put, rc);
-        }
+       rc = mdo_unlink(env, parent, lu2md(child), lname, ma, 0);
+       if (rc) {
+               CERROR("Can not unlink child %s: rc = %d\n",
+                       lname->ln_name, rc);
+               GOTO(out_put, rc);
+       }
         CDEBUG(D_RPCTRACE, "End destroy object "DFID" %s %p\n",
                PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
 out_put:
@@ -2051,6 +2056,9 @@ static struct lu_object *echo_resolve_path(const struct lu_env *env,
                 RETURN(ERR_PTR(rc));
         }
 
+       /* In the function below, .hs_keycmp resolves to
+        * lu_obj_hop_keycmp() */
+       /* coverity[overrun-buffer-val] */
         parent = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, fid, NULL);
         if (IS_ERR(parent)) {
                 CERROR("Can not find the parent "DFID": rc = %ld\n",
@@ -2108,10 +2116,10 @@ static void echo_ucred_init(struct lu_env *env)
        ucred->uc_suppgids[0] = -1;
        ucred->uc_suppgids[1] = -1;
 
-       ucred->uc_uid   = ucred->uc_o_uid   = cfs_curproc_uid();
-       ucred->uc_gid   = ucred->uc_o_gid   = cfs_curproc_gid();
-       ucred->uc_fsuid = ucred->uc_o_fsuid = cfs_curproc_fsuid();
-       ucred->uc_fsgid = ucred->uc_o_fsgid = cfs_curproc_fsgid();
+       ucred->uc_uid   = ucred->uc_o_uid   = current_uid();
+       ucred->uc_gid   = ucred->uc_o_gid   = current_gid();
+       ucred->uc_fsuid = ucred->uc_o_fsuid = current_fsuid();
+       ucred->uc_fsgid = ucred->uc_o_fsgid = current_fsgid();
        ucred->uc_cap   = cfs_curproc_cap_pack();
 
        /* remove fs privilege for non-root user. */
@@ -2127,10 +2135,10 @@ static void echo_ucred_fini(struct lu_env *env)
 }
 
 #define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
-#define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION)
+#define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION | LCT_SERVER_SESSION)
 static int echo_md_handler(struct echo_device *ed, int command,
-                           char *path, int path_len, int id, int count,
-                           struct obd_ioctl_data *data)
+                          char *path, int path_len, __u64 id, int count,
+                          struct obd_ioctl_data *data)
 {
        struct echo_thread_info *info;
         struct lu_device      *ld = ed->ed_next;
@@ -2179,7 +2187,7 @@ static int echo_md_handler(struct echo_device *ed, int command,
                 OBD_ALLOC(name, namelen + 1);
                 if (name == NULL)
                        GOTO(out_put, rc = -ENOMEM);
-               if (cfs_copy_from_user(name, data->ioc_pbuf2, namelen))
+               if (copy_from_user(name, data->ioc_pbuf2, namelen))
                        GOTO(out_name, rc = -EFAULT);
         }
 
@@ -2194,9 +2202,10 @@ static int echo_md_handler(struct echo_device *ed, int command,
                 int stripe_count = (int)data->ioc_obdo2.o_misc;
                 int stripe_index = (int)data->ioc_obdo2.o_stripe_idx;
 
-                fid->f_seq = data->ioc_obdo1.o_seq;
-                fid->f_oid = (__u32)data->ioc_obdo1.o_id;
-                fid->f_ver = 0;
+               rc = ostid_to_fid(fid, &data->ioc_obdo1.o_oi, 0);
+               if (rc != 0)
+                       break;
+
                /* In the function below, .hs_keycmp resolves to
                 * lu_obj_hop_keycmp() */
                /* coverity[overrun-buffer-val] */
@@ -2243,6 +2252,7 @@ out_env:
         cl_env_put(env, &refcheck);
         return rc;
 }
+#endif /* HAVE_SERVER_SUPPORT */
 
 static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
                               int on_target, struct obdo *oa, void *ulsm,
@@ -2279,42 +2289,44 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
                         lsm->lsm_stripe_count = ec->ec_nstripes;
 
                 if (lsm->lsm_stripe_size == 0)
-                        lsm->lsm_stripe_size = CFS_PAGE_SIZE;
+                       lsm->lsm_stripe_size = PAGE_CACHE_SIZE;
 
                 idx = cfs_rand();
 
-                /* setup stripes: indices + default ids if required */
-                for (i = 0; i < lsm->lsm_stripe_count; i++) {
-                        if (lsm->lsm_oinfo[i]->loi_id == 0)
-                                lsm->lsm_oinfo[i]->loi_id = lsm->lsm_object_id;
+               /* setup stripes: indices + default ids if required */
+               for (i = 0; i < lsm->lsm_stripe_count; i++) {
+                       if (ostid_id(&lsm->lsm_oinfo[i]->loi_oi) == 0)
+                               lsm->lsm_oinfo[i]->loi_oi = lsm->lsm_oi;
 
-                        lsm->lsm_oinfo[i]->loi_ost_idx =
-                                (idx + i) % ec->ec_nstripes;
-                }
+                       lsm->lsm_oinfo[i]->loi_ost_idx =
+                               (idx + i) % ec->ec_nstripes;
+               }
         }
 
-        /* setup object ID here for !on_target and LOV hint */
-        if (oa->o_valid & OBD_MD_FLID)
-                lsm->lsm_object_id = oa->o_id;
+       /* setup object ID here for !on_target and LOV hint */
+       if (oa->o_valid & OBD_MD_FLID) {
+               LASSERT(oa->o_valid & OBD_MD_FLGROUP);
+               lsm->lsm_oi = oa->o_oi;
+       }
 
-        if (lsm->lsm_object_id == 0)
-                lsm->lsm_object_id = ++last_object_id;
+       if (ostid_id(&lsm->lsm_oi) == 0)
+               ostid_set_id(&lsm->lsm_oi, ++last_object_id);
 
         rc = 0;
-        if (on_target) {
-                /* Only echo objects are allowed to be created */
-                LASSERT((oa->o_valid & OBD_MD_FLGROUP) &&
-                        (oa->o_seq == FID_SEQ_ECHO));
-                rc = obd_create(env, ec->ec_exp, oa, &lsm, oti);
-                if (rc != 0) {
-                        CERROR("Cannot create objects: rc = %d\n", rc);
-                        GOTO(failed, rc);
-                }
-                created = 1;
-        }
+       if (on_target) {
+               /* Only echo objects are allowed to be created */
+               LASSERT((oa->o_valid & OBD_MD_FLGROUP) &&
+                       (ostid_seq(&oa->o_oi) == FID_SEQ_ECHO));
+               rc = obd_create(env, ec->ec_exp, oa, &lsm, oti);
+               if (rc != 0) {
+                       CERROR("Cannot create objects: rc = %d\n", rc);
+                       GOTO(failed, rc);
+               }
+               created = 1;
+       }
 
         /* See what object ID we were given */
-        oa->o_id = lsm->lsm_object_id;
+       oa->o_oi = lsm->lsm_oi;
         oa->o_valid |= OBD_MD_FLID;
 
         eco = cl_echo_object_find(ed, &lsm);
@@ -2322,7 +2334,7 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
                 GOTO(failed, rc = PTR_ERR(eco));
         cl_echo_object_put(eco);
 
-        CDEBUG(D_INFO, "oa->o_id = %lx\n", (long)oa->o_id);
+        CDEBUG(D_INFO, "oa oid "DOSTID"\n", POSTID(&oa->o_oi));
         EXIT;
 
  failed:
@@ -2343,9 +2355,8 @@ static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
         int                     rc;
         ENTRY;
 
-        if ((oa->o_valid & OBD_MD_FLID) == 0 ||
-            oa->o_id == 0)  /* disallow use of object id 0 */
-        {
+        if ((oa->o_valid & OBD_MD_FLID) == 0 || ostid_id(&oa->o_oi) == 0) {
+               /* disallow use of object id 0 */
                 CERROR ("No valid oid\n");
                 RETURN(-EINVAL);
         }
@@ -2354,11 +2365,9 @@ static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
         if (rc < 0)
                 RETURN(rc);
 
-        lsm->lsm_object_id = oa->o_id;
-        if (oa->o_valid & OBD_MD_FLGROUP)
-                lsm->lsm_object_seq = oa->o_seq;
-        else
-                lsm->lsm_object_seq = FID_SEQ_ECHO;
+       lsm->lsm_oi = oa->o_oi;
+       if (!(oa->o_valid & OBD_MD_FLGROUP))
+               ostid_set_seq_echo(&lsm->lsm_oi);
 
         rc = 0;
         eco = cl_echo_object_find(ed, &lsm);
@@ -2402,13 +2411,13 @@ echo_get_stripe_off_id (struct lov_stripe_md *lsm, obd_off *offp, obd_id *idp)
 
         stripe_index = woffset / stripe_size;
 
-        *idp = lsm->lsm_oinfo[stripe_index]->loi_id;
-        *offp = offset * stripe_size + woffset % stripe_size;
+       *idp = ostid_id(&lsm->lsm_oinfo[stripe_index]->loi_oi);
+       *offp = offset * stripe_size + woffset % stripe_size;
 }
 
 static void
 echo_client_page_debug_setup(struct lov_stripe_md *lsm,
-                             cfs_page_t *page, int rw, obd_id id,
+                            struct page *page, int rw, obd_id id,
                              obd_off offset, obd_off count)
 {
         char    *addr;
@@ -2417,11 +2426,11 @@ echo_client_page_debug_setup(struct lov_stripe_md *lsm,
         int      delta;
 
         /* no partial pages on the client */
-        LASSERT(count == CFS_PAGE_SIZE);
+       LASSERT(count == PAGE_CACHE_SIZE);
 
-        addr = cfs_kmap(page);
+       addr = kmap(page);
 
-        for (delta = 0; delta < CFS_PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
+       for (delta = 0; delta < PAGE_CACHE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
                 if (rw == OBD_BRW_WRITE) {
                         stripe_off = offset + delta;
                         stripe_id = id;
@@ -2434,11 +2443,11 @@ echo_client_page_debug_setup(struct lov_stripe_md *lsm,
                                   stripe_off, stripe_id);
         }
 
-        cfs_kunmap(page);
+       kunmap(page);
 }
 
 static int echo_client_page_debug_check(struct lov_stripe_md *lsm,
-                                        cfs_page_t *page, obd_id id,
+                                       struct page *page, obd_id id,
                                         obd_off offset, obd_off count)
 {
         obd_off stripe_off;
@@ -2449,11 +2458,11 @@ static int echo_client_page_debug_check(struct lov_stripe_md *lsm,
         int     rc2;
 
         /* no partial pages on the client */
-        LASSERT(count == CFS_PAGE_SIZE);
+       LASSERT(count == PAGE_CACHE_SIZE);
 
-        addr = cfs_kmap(page);
+       addr = kmap(page);
 
-        for (rc = delta = 0; delta < CFS_PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
+       for (rc = delta = 0; delta < PAGE_CACHE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
                 stripe_off = offset + delta;
                 stripe_id = id;
                 echo_get_stripe_off_id (lsm, &stripe_off, &stripe_id);
@@ -2467,7 +2476,7 @@ static int echo_client_page_debug_check(struct lov_stripe_md *lsm,
                 }
         }
 
-        cfs_kunmap(page);
+       kunmap(page);
         return rc;
 }
 
@@ -2480,7 +2489,7 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
         obd_count               npages;
         struct brw_page        *pga;
         struct brw_page        *pgp;
-        cfs_page_t            **pages;
+       struct page            **pages;
         obd_off                 off;
         int                     i;
         int                     rc;
@@ -2489,22 +2498,22 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
         int                     brw_flags = 0;
         ENTRY;
 
-        verify = ((oa->o_id) != ECHO_PERSISTENT_OBJID &&
+        verify = (ostid_id(&oa->o_oi) != ECHO_PERSISTENT_OBJID &&
                   (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
                   (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
 
-        gfp_mask = ((oa->o_id & 2) == 0) ? CFS_ALLOC_STD : CFS_ALLOC_HIGHUSER;
+       gfp_mask = ((ostid_id(&oa->o_oi) & 2) == 0) ? GFP_IOFS : GFP_HIGHUSER;
 
-        LASSERT(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ);
-        LASSERT(lsm != NULL);
-        LASSERT(lsm->lsm_object_id == oa->o_id);
+       LASSERT(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ);
+       LASSERT(lsm != NULL);
+       LASSERT(ostid_id(&lsm->lsm_oi) == ostid_id(&oa->o_oi));
 
         if (count <= 0 ||
             (count & (~CFS_PAGE_MASK)) != 0)
                 RETURN(-EINVAL);
 
         /* XXX think again with misaligned I/O */
-        npages = count >> CFS_PAGE_SHIFT;
+       npages = count >> PAGE_CACHE_SHIFT;
 
         if (rw == OBD_BRW_WRITE)
                 brw_flags = OBD_BRW_ASYNC;
@@ -2521,7 +2530,7 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
 
         for (i = 0, pgp = pga, off = offset;
              i < npages;
-             i++, pgp++, off += CFS_PAGE_SIZE) {
+            i++, pgp++, off += PAGE_CACHE_SIZE) {
 
                 LASSERT (pgp->pg == NULL);      /* for cleanup */
 
@@ -2531,13 +2540,14 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                         goto out;
 
                 pages[i] = pgp->pg;
-                pgp->count = CFS_PAGE_SIZE;
+               pgp->count = PAGE_CACHE_SIZE;
                 pgp->off = off;
                 pgp->flag = brw_flags;
 
-                if (verify)
-                        echo_client_page_debug_setup(lsm, pgp->pg, rw,
-                                                     oa->o_id, off, pgp->count);
+               if (verify)
+                       echo_client_page_debug_setup(lsm, pgp->pg, rw,
+                                                    ostid_id(&oa->o_oi), off,
+                                                    pgp->count);
         }
 
         /* brw mode can only be used at client */
@@ -2552,14 +2562,15 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                 if (pgp->pg == NULL)
                         continue;
 
-                if (verify) {
-                        int vrc;
-                        vrc = echo_client_page_debug_check(lsm, pgp->pg, oa->o_id,
-                                                           pgp->off, pgp->count);
-                        if (vrc != 0 && rc == 0)
-                                rc = vrc;
-                }
-                OBD_PAGE_FREE(pgp->pg);
+               if (verify) {
+                       int vrc;
+                       vrc = echo_client_page_debug_check(lsm, pgp->pg,
+                                                          ostid_id(&oa->o_oi),
+                                                          pgp->off, pgp->count);
+                       if (vrc != 0 && rc == 0)
+                               rc = vrc;
+               }
+               OBD_PAGE_FREE(pgp->pg);
         }
         OBD_FREE(pga, npages * sizeof(*pga));
         OBD_FREE(pages, npages * sizeof(*pages));
@@ -2583,12 +2594,12 @@ static int echo_client_prep_commit(const struct lu_env *env,
 
         ENTRY;
 
-        if (count <= 0 || (count & (~CFS_PAGE_MASK)) != 0 ||
-            (lsm != NULL && lsm->lsm_object_id != oa->o_id))
-                RETURN(-EINVAL);
+       if (count <= 0 || (count & (~CFS_PAGE_MASK)) != 0 ||
+           (lsm != NULL && ostid_id(&lsm->lsm_oi) != ostid_id(&oa->o_oi)))
+               RETURN(-EINVAL);
 
-        npages = batch >> CFS_PAGE_SHIFT;
-        tot_pages = count >> CFS_PAGE_SHIFT;
+       npages = batch >> PAGE_CACHE_SHIFT;
+       tot_pages = count >> PAGE_CACHE_SHIFT;
 
         OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local));
         OBD_ALLOC(rnb, npages * sizeof(struct niobuf_remote));
@@ -2609,9 +2620,9 @@ static int echo_client_prep_commit(const struct lu_env *env,
                 if (tot_pages < npages)
                         npages = tot_pages;
 
-                for (i = 0; i < npages; i++, off += CFS_PAGE_SIZE) {
+               for (i = 0; i < npages; i++, off += PAGE_CACHE_SIZE) {
                         rnb[i].offset = off;
-                        rnb[i].len = CFS_PAGE_SIZE;
+                       rnb[i].len = PAGE_CACHE_SIZE;
                        rnb[i].flags = brw_flags;
                 }
 
@@ -2626,7 +2637,7 @@ static int echo_client_prep_commit(const struct lu_env *env,
                 LASSERT(lpages == npages);
 
                 for (i = 0; i < lpages; i++) {
-                        cfs_page_t *page = lnb[i].page;
+                       struct page *page = lnb[i].page;
 
                         /* read past eof? */
                         if (page == NULL && lnb[i].rc == 0)
@@ -2635,22 +2646,22 @@ static int echo_client_prep_commit(const struct lu_env *env,
                         if (async)
                                 lnb[i].flags |= OBD_BRW_ASYNC;
 
-                        if (oa->o_id == ECHO_PERSISTENT_OBJID ||
-                            (oa->o_valid & OBD_MD_FLFLAGS) == 0 ||
-                            (oa->o_flags & OBD_FL_DEBUG_CHECK) == 0)
-                                continue;
-
-                        if (rw == OBD_BRW_WRITE)
-                                echo_client_page_debug_setup(lsm, page, rw,
-                                                             oa->o_id,
-                                                             rnb[i].offset,
-                                                             rnb[i].len);
-                        else
-                                echo_client_page_debug_check(lsm, page,
-                                                             oa->o_id,
-                                                             rnb[i].offset,
-                                                             rnb[i].len);
-                }
+                       if (ostid_id(&oa->o_oi) == ECHO_PERSISTENT_OBJID ||
+                           (oa->o_valid & OBD_MD_FLFLAGS) == 0 ||
+                           (oa->o_flags & OBD_FL_DEBUG_CHECK) == 0)
+                               continue;
+
+                       if (rw == OBD_BRW_WRITE)
+                               echo_client_page_debug_setup(lsm, page, rw,
+                                                           ostid_id(&oa->o_oi),
+                                                            rnb[i].offset,
+                                                            rnb[i].len);
+                       else
+                               echo_client_page_debug_check(lsm, page,
+                                                           ostid_id(&oa->o_oi),
+                                                            rnb[i].offset,
+                                                            rnb[i].len);
+               }
 
                ret = obd_commitrw(env, rw, exp, oa, 1, &ioo,
                                   rnb, npages, lnb, oti, ret);
@@ -2659,6 +2670,10 @@ static int echo_client_prep_commit(const struct lu_env *env,
 
                 /* Reset oti otherwise it would confuse ldiskfs. */
                 memset(oti, 0, sizeof(*oti));
+
+               /* Reuse env context. */
+               lu_context_exit((struct lu_context *)&env->le_ctx);
+               lu_context_enter((struct lu_context *)&env->le_ctx);
         }
 
 out:
@@ -2779,6 +2794,9 @@ static int
 echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                       void *karg, void *uarg)
 {
+#ifdef HAVE_SERVER_SUPPORT
+       struct tgt_session_info *tsi;
+#endif
         struct obd_device      *obd = exp->exp_obd;
         struct echo_device     *ed = obd2echo_dev(obd);
         struct echo_client_obd *ec = ed->ed_ec;
@@ -2792,18 +2810,21 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         int                     rw = OBD_BRW_READ;
         int                     rc = 0;
         int                     i;
+#ifdef HAVE_SERVER_SUPPORT
+       struct lu_context        echo_session;
+#endif
         ENTRY;
 
         memset(&dummy_oti, 0, sizeof(dummy_oti));
 
-        oa = &data->ioc_obdo1;
-        if (!(oa->o_valid & OBD_MD_FLGROUP)) {
-                oa->o_valid |= OBD_MD_FLGROUP;
-                oa->o_seq = FID_SEQ_ECHO;
-        }
+       oa = &data->ioc_obdo1;
+       if (!(oa->o_valid & OBD_MD_FLGROUP)) {
+               oa->o_valid |= OBD_MD_FLGROUP;
+               ostid_set_seq_echo(&oa->o_oi);
+       }
 
         /* This FID is unpacked just for validation at this point */
-        rc = fid_ostid_unpack(&fid, &oa->o_oi, 0);
+        rc = ostid_to_fid(&fid, &oa->o_oi, 0);
         if (rc < 0)
                 RETURN(rc);
 
@@ -2811,10 +2832,20 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         if (env == NULL)
                 RETURN(-ENOMEM);
 
-        rc = lu_env_init(env, LCT_DT_THREAD);
-        if (rc)
-                GOTO(out, rc = -ENOMEM);
+       rc = lu_env_init(env, LCT_DT_THREAD);
+       if (rc)
+               GOTO(out_alloc, rc = -ENOMEM);
 
+#ifdef HAVE_SERVER_SUPPORT
+       env->le_ses = &echo_session;
+       rc = lu_context_init(env->le_ses, LCT_SERVER_SESSION | LCT_NOREF);
+       if (unlikely(rc < 0))
+               GOTO(out_env, rc);
+       lu_context_enter(env->le_ses);
+
+       tsi = tgt_ses_info(env);
+       tsi->tsi_exp = ec->ec_exp;
+#endif
         switch (cmd) {
         case OBD_IOC_CREATE:                    /* may create echo object */
                 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
@@ -2824,35 +2855,35 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                                         data->ioc_plen1, &dummy_oti);
                 GOTO(out, rc);
 
-        case OBD_IOC_ECHO_MD: {
-                int count;
-                int cmd;
-                char *dir = NULL;
-                int dirlen;
-                __u64 id;
-
-                if (!cfs_capable(CFS_CAP_SYS_ADMIN))
-                        GOTO(out, rc = -EPERM);
-
-                count = data->ioc_count;
-                cmd = data->ioc_command;
-
-                id = data->ioc_obdo2.o_id;
-
-                dirlen = data->ioc_plen1;
-                OBD_ALLOC(dir, dirlen + 1);
-                if (dir == NULL)
-                        GOTO(out, rc = -ENOMEM);
-
-                if (cfs_copy_from_user(dir, data->ioc_pbuf1, dirlen)) {
-                        OBD_FREE(dir, data->ioc_plen1 + 1);
-                        GOTO(out, rc = -EFAULT);
-                }
+#ifdef HAVE_SERVER_SUPPORT
+       case OBD_IOC_ECHO_MD: {
+               int count;
+               int cmd;
+               char *dir = NULL;
+               int dirlen;
+               __u64 id;
+
+               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+                       GOTO(out, rc = -EPERM);
+
+               count = data->ioc_count;
+               cmd = data->ioc_command;
+
+               id = data->ioc_obdo2.o_oi.oi.oi_id;
+               dirlen = data->ioc_plen1;
+               OBD_ALLOC(dir, dirlen + 1);
+               if (dir == NULL)
+                       GOTO(out, rc = -ENOMEM);
+
+               if (copy_from_user(dir, data->ioc_pbuf1, dirlen)) {
+                       OBD_FREE(dir, data->ioc_plen1 + 1);
+                       GOTO(out, rc = -EFAULT);
+               }
 
-                rc = echo_md_handler(ed, cmd, dir, dirlen, id, count, data);
-                OBD_FREE(dir, dirlen + 1);
-                GOTO(out, rc);
-        }
+               rc = echo_md_handler(ed, cmd, dir, dirlen, id, count, data);
+               OBD_FREE(dir, dirlen + 1);
+               GOTO(out, rc);
+       }
         case OBD_IOC_ECHO_ALLOC_SEQ: {
                 struct lu_env   *cl_env;
                 int              refcheck;
@@ -2881,15 +2912,16 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         GOTO(out, rc);
                 }
 
-                if (cfs_copy_to_user(data->ioc_pbuf1, &seq, data->ioc_plen1))
+               if (copy_to_user(data->ioc_pbuf1, &seq, data->ioc_plen1))
                         return -EFAULT;
 
                max_count = LUSTRE_METADATA_SEQ_MAX_WIDTH;
-               if (cfs_copy_to_user(data->ioc_pbuf2, &max_count,
+               if (copy_to_user(data->ioc_pbuf2, &max_count,
                                     data->ioc_plen2))
                        return -EFAULT;
                GOTO(out, rc);
         }
+#endif /* HAVE_SERVER_SUPPORT */
         case OBD_IOC_DESTROY:
                 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
                         GOTO (out, rc = -EPERM);
@@ -2987,7 +3019,13 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
         EXIT;
 out:
+#ifdef HAVE_SERVER_SUPPORT
+       lu_context_exit(env->le_ses);
+       lu_context_fini(env->le_ses);
+out_env:
+#endif
         lu_env_fini(env);
+out_alloc:
         OBD_FREE_PTR(env);
 
         /* XXX this should be in a helper also called by target_send_reply */
@@ -3029,11 +3067,17 @@ static int echo_client_setup(const struct lu_env *env,
         ec->ec_unique = 0;
         ec->ec_nstripes = 0;
 
-        if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
-                lu_context_tags_update(ECHO_MD_CTX_TAG);
-                lu_session_tags_update(ECHO_MD_SES_TAG);
-                RETURN(0);
-        }
+       if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
+#ifdef HAVE_SERVER_SUPPORT
+               lu_context_tags_update(ECHO_MD_CTX_TAG);
+               lu_session_tags_update(ECHO_MD_SES_TAG);
+#else
+               CERROR("Local operations are NOT supported on client side. "
+                      "Only remote operations are supported. Metadata client "
+                      "must be run on server side.\n");
+#endif
+               RETURN(0);
+       }
 
         OBD_ALLOC(ocd, sizeof(*ocd));
         if (ocd == NULL) {
@@ -3043,8 +3087,11 @@ static int echo_client_setup(const struct lu_env *env,
         }
 
         ocd->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_REQPORTAL |
+                                OBD_CONNECT_BRW_SIZE |
                                  OBD_CONNECT_GRANT | OBD_CONNECT_FULL20 |
-                                OBD_CONNECT_64BITHASH | OBD_CONNECT_LVB_TYPE;
+                                OBD_CONNECT_64BITHASH | OBD_CONNECT_LVB_TYPE |
+                                OBD_CONNECT_FID;
+       ocd->ocd_brw_size = DT_MAX_BRW_SIZE;
         ocd->ocd_version = LUSTRE_VERSION_CODE;
         ocd->ocd_group = FID_SEQ_ECHO;
 
@@ -3079,8 +3126,13 @@ static int echo_client_cleanup(struct obd_device *obddev)
                 RETURN(0);
 
         if (ed->ed_next_ismd) {
-                lu_context_tags_clear(ECHO_MD_CTX_TAG);
-                lu_session_tags_clear(ECHO_MD_SES_TAG);
+#ifdef HAVE_SERVER_SUPPORT
+               lu_context_tags_clear(ECHO_MD_CTX_TAG);
+               lu_session_tags_clear(ECHO_MD_SES_TAG);
+#else
+               CERROR("This is client-side only module, does not support "
+                       "metadata echo client.\n");
+#endif
                 RETURN(0);
         }
 
@@ -3174,16 +3226,18 @@ int echo_client_init(void)
 
         lprocfs_echo_init_vars(&lvars);
 
-        rc = lu_kmem_init(echo_caches);
-        if (rc == 0) {
-                rc = class_register_type(&echo_client_obd_ops, NULL,
-                                         lvars.module_vars,
-                                         LUSTRE_ECHO_CLIENT_NAME,
-                                         &echo_device_type);
-                if (rc)
-                        lu_kmem_fini(echo_caches);
-        }
-        return rc;
+       rc = lu_kmem_init(echo_caches);
+       if (rc == 0) {
+               rc = class_register_type(&echo_client_obd_ops, NULL, NULL,
+#ifndef HAVE_ONLY_PROCFS_SEQ
+                                       lvars.module_vars,
+#endif
+                                       LUSTRE_ECHO_CLIENT_NAME,
+                                       &echo_device_type);
+               if (rc)
+                       lu_kmem_fini(echo_caches);
+       }
+       return rc;
 }
 
 void echo_client_exit(void)
@@ -3201,7 +3255,7 @@ static int __init obdecho_init(void)
         ENTRY;
         LCONSOLE_INFO("Echo OBD driver; http://www.lustre.org/\n");
 
-        LASSERT(CFS_PAGE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
+       LASSERT(PAGE_CACHE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
 
         lprocfs_echo_init_vars(&lvars);
 
@@ -3210,10 +3264,13 @@ static int __init obdecho_init(void)
         if (rc != 0)
                 goto failed_0;
 
-        rc = class_register_type(&echo_obd_ops, NULL, lvars.module_vars,
-                                 LUSTRE_ECHO_NAME, NULL);
-        if (rc != 0)
-                goto failed_1;
+       rc = class_register_type(&echo_obd_ops, NULL, NULL,
+#ifndef HAVE_ONLY_PROCFS_SEQ
+                               lvars.module_vars,
+#endif
+                               LUSTRE_ECHO_NAME, NULL);
+       if (rc != 0)
+               goto failed_1;
 # endif
 
         rc = echo_client_init();