Whamcloud - gitweb
LU-14382 mdt: implement fallocate in MDC/MDT
[fs/lustre-release.git] / lustre / mdc / mdc_dev.c
index 72cf45c..5ef4480 100644 (file)
 
 #include <obd_class.h>
 #include <lustre_osc.h>
+#include <linux/falloc.h>
 #include <uapi/linux/lustre/lustre_param.h>
 
 #include "mdc_internal.h"
 
 static void mdc_lock_build_policy(const struct lu_env *env,
+                                 const struct cl_lock *lock,
                                  union ldlm_policy_data *policy)
 {
        memset(policy, 0, sizeof *policy);
        policy->l_inodebits.bits = MDS_INODELOCK_DOM;
+       if (lock) {
+               policy->l_inodebits.li_gid = lock->cll_descr.cld_gid;
+       }
 }
 
 int mdc_ldlm_glimpse_ast(struct ldlm_lock *dlmlock, void *data)
@@ -91,7 +96,8 @@ int mdc_dom_lock_match(const struct lu_env *env, struct obd_export *exp,
                       struct ldlm_res_id *res_id, enum ldlm_type type,
                       union ldlm_policy_data *policy, enum ldlm_mode mode,
                       __u64 *flags, struct osc_object *obj,
-                      struct lustre_handle *lockh, int unref)
+                      struct lustre_handle *lockh,
+                      enum ldlm_match_flags match_flags)
 {
        struct obd_device *obd = exp->exp_obd;
        __u64 lflags = *flags;
@@ -99,8 +105,8 @@ int mdc_dom_lock_match(const struct lu_env *env, struct obd_export *exp,
 
        ENTRY;
 
-       rc = ldlm_lock_match(obd->obd_namespace, lflags,
-                            res_id, type, policy, mode, lockh, unref);
+       rc = ldlm_lock_match_with_skip(obd->obd_namespace, lflags, 0,
+                            res_id, type, policy, mode, lockh, match_flags);
        if (rc == 0 || lflags & LDLM_FL_TEST_LOCK)
                RETURN(rc);
 
@@ -140,16 +146,24 @@ struct ldlm_lock *mdc_dlmlock_at_pgoff(const struct lu_env *env,
        struct ldlm_lock *lock = NULL;
        enum ldlm_mode mode;
        __u64 flags;
+       enum ldlm_match_flags match_flags = 0;
 
        ENTRY;
 
        fid_build_reg_res_name(lu_object_fid(osc2lu(obj)), resname);
-       mdc_lock_build_policy(env, policy);
+       mdc_lock_build_policy(env, NULL, policy);
+       policy->l_inodebits.li_gid = LDLM_GID_ANY;
 
        flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
        if (dap_flags & OSC_DAP_FL_TEST_LOCK)
                flags |= LDLM_FL_TEST_LOCK;
 
+       if (dap_flags & OSC_DAP_FL_AST)
+               match_flags |= LDLM_MATCH_AST;
+
+       if (dap_flags & OSC_DAP_FL_CANCELING)
+               match_flags |= LDLM_MATCH_UNREF;
+
 again:
        /* Next, search for already existing extent locks that will cover us */
        /* If we're trying to read, we also search for an existing PW lock.  The
@@ -157,8 +171,7 @@ again:
         * writers can share a single PW lock. */
        mode = mdc_dom_lock_match(env, osc_export(obj), resname, LDLM_IBITS,
                                  policy, LCK_PR | LCK_PW | LCK_GROUP, &flags,
-                                 obj, &lockh,
-                                 dap_flags & OSC_DAP_FL_CANCELING);
+                                 obj, &lockh, match_flags);
        if (mode != 0) {
                lock = ldlm_handle2lock(&lockh);
                /* RACE: the lock is cancelled so let's try again */
@@ -173,33 +186,38 @@ again:
  * Check if page @page is covered by an extra lock or discard it.
  */
 static bool mdc_check_and_discard_cb(const struct lu_env *env, struct cl_io *io,
-                                    struct osc_page *ops, void *cbdata)
+                                    void **pvec, int count, void *cbdata)
 {
        struct osc_thread_info *info = osc_env_info(env);
        struct osc_object *osc = cbdata;
        pgoff_t index;
-
-       index = osc_index(ops);
-       if (index >= info->oti_fn_index) {
-               struct ldlm_lock *tmp;
-               struct cl_page *page = ops->ops_cl.cpl_page;
-
-               /* refresh non-overlapped index */
-               tmp = mdc_dlmlock_at_pgoff(env, osc, index,
-                                          OSC_DAP_FL_TEST_LOCK);
-               if (tmp != NULL) {
-                       info->oti_fn_index = CL_PAGE_EOF;
-                       LDLM_LOCK_PUT(tmp);
-               } else if (cl_page_own(env, io, page) == 0) {
-                       /* discard the page */
-                       cl_page_discard(env, io, page);
-                       cl_page_disown(env, io, page);
-               } else {
-                       LASSERT(page->cp_state == CPS_FREEING);
+       int i;
+
+       for (i = 0; i < count; i++) {
+               struct osc_page *ops = pvec[i];
+
+               index = osc_index(ops);
+               if (index >= info->oti_fn_index) {
+                       struct ldlm_lock *tmp;
+                       struct cl_page *page = ops->ops_cl.cpl_page;
+
+                       /* refresh non-overlapped index */
+                       tmp = mdc_dlmlock_at_pgoff(env, osc, index,
+                                       OSC_DAP_FL_TEST_LOCK | OSC_DAP_FL_AST);
+                       if (tmp != NULL) {
+                               info->oti_fn_index = CL_PAGE_EOF;
+                               LDLM_LOCK_PUT(tmp);
+                       } else if (cl_page_own(env, io, page) == 0) {
+                               /* discard the page */
+                               cl_page_discard(env, io, page);
+                               cl_page_disown(env, io, page);
+                       } else {
+                               LASSERT(page->cp_state == CPS_FREEING);
+                       }
                }
-       }
 
-       info->oti_next_index = index + 1;
+               info->oti_next_index = index + 1;
+       }
        return true;
 }
 
@@ -289,9 +307,8 @@ void mdc_lock_lockless_cancel(const struct lu_env *env,
  * Helper for osc_dlm_blocking_ast() handling discrepancies between cl_lock
  * and ldlm_lock caches.
  */
-static int mdc_dlm_blocking_ast0(const struct lu_env *env,
-                                struct ldlm_lock *dlmlock,
-                                int flag)
+static int mdc_dlm_canceling(const struct lu_env *env,
+                            struct ldlm_lock *dlmlock)
 {
        struct cl_object *obj = NULL;
        int result = 0;
@@ -300,11 +317,8 @@ static int mdc_dlm_blocking_ast0(const struct lu_env *env,
 
        ENTRY;
 
-       LASSERT(flag == LDLM_CB_CANCELING);
-       LASSERT(dlmlock != NULL);
-
        lock_res_and_lock(dlmlock);
-       if (dlmlock->l_granted_mode != dlmlock->l_req_mode) {
+       if (!ldlm_is_granted(dlmlock)) {
                dlmlock->l_ast_data = NULL;
                unlock_res_and_lock(dlmlock);
                RETURN(0);
@@ -345,13 +359,13 @@ static int mdc_dlm_blocking_ast0(const struct lu_env *env,
 }
 
 int mdc_ldlm_blocking_ast(struct ldlm_lock *dlmlock,
-                         struct ldlm_lock_desc *new, void *data, int flag)
+                         struct ldlm_lock_desc *new, void *data, int reason)
 {
        int rc = 0;
 
        ENTRY;
 
-       switch (flag) {
+       switch (reason) {
        case LDLM_CB_BLOCKING: {
                struct lustre_handle lockh;
 
@@ -382,7 +396,7 @@ int mdc_ldlm_blocking_ast(struct ldlm_lock *dlmlock,
                        break;
                }
 
-               rc = mdc_dlm_blocking_ast0(env, dlmlock, flag);
+               rc = mdc_dlm_canceling(env, dlmlock);
                cl_env_put(env, &refcheck);
                break;
        }
@@ -430,6 +444,7 @@ void mdc_lock_lvb_update(const struct lu_env *env, struct osc_object *osc,
                        attr->cat_kms = size;
                        setkms = 1;
                }
+               ldlm_lock_allow_match_locked(dlmlock);
        }
 
        /* The size should not be less than the kms */
@@ -479,7 +494,7 @@ static void mdc_lock_granted(const struct lu_env *env, struct osc_lock *oscl,
 
        /* Lock must have been granted. */
        lock_res_and_lock(dlmlock);
-       if (dlmlock->l_granted_mode == dlmlock->l_req_mode) {
+       if (ldlm_is_granted(dlmlock)) {
                struct cl_lock_descr *descr = &oscl->ols_cl.cls_lock->cll_descr;
 
                /* extend the lock extent, otherwise it will have problem when
@@ -505,7 +520,7 @@ static void mdc_lock_granted(const struct lu_env *env, struct osc_lock *oscl,
 
 /**
  * Lock upcall function that is executed either when a reply to ENQUEUE rpc is
- * received from a server, or after osc_enqueue_base() matched a local DLM
+ * received from a server, or after mdc_enqueue_send() matched a local DLM
  * lock.
  */
 static int mdc_lock_upcall(void *cookie, struct lustre_handle *lockh,
@@ -537,18 +552,7 @@ static int mdc_lock_upcall(void *cookie, struct lustre_handle *lockh,
                mdc_lock_granted(env, oscl, lockh);
 
        /* Error handling, some errors are tolerable. */
-       if (oscl->ols_locklessable && rc == -EUSERS) {
-               /* This is a tolerable error, turn this lock into
-                * lockless lock.
-                */
-               osc_object_set_contended(cl2osc(slice->cls_obj));
-               LASSERT(slice->cls_ops != oscl->ols_lockless_ops);
-
-               /* Change this lock to ldlmlock-less lock. */
-               osc_lock_to_lockless(env, oscl, 1);
-               oscl->ols_state = OLS_GRANTED;
-               rc = 0;
-       } else if (oscl->ols_glimpse && rc == -ENAVAIL) {
+       if (oscl->ols_glimpse && rc == -ENAVAIL) {
                LASSERT(oscl->ols_flags & LDLM_FL_LVB_READY);
                mdc_lock_lvb_update(env, cl2osc(slice->cls_obj),
                                    NULL, &oscl->ols_lvb);
@@ -563,53 +567,66 @@ static int mdc_lock_upcall(void *cookie, struct lustre_handle *lockh,
        RETURN(rc);
 }
 
-int mdc_fill_lvb(struct ptlrpc_request *req, struct ost_lvb *lvb)
+/* This is needed only for old servers (before 2.14) support */
+int mdc_fill_lvb(struct req_capsule *pill, struct ost_lvb *lvb)
 {
        struct mdt_body *body;
 
-       body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
+       /* get LVB data from mdt_body otherwise */
+       body = req_capsule_server_get(pill, &RMF_MDT_BODY);
        if (!body)
                RETURN(-EPROTO);
 
-       lvb->lvb_mtime = body->mbo_mtime;
-       lvb->lvb_atime = body->mbo_atime;
-       lvb->lvb_ctime = body->mbo_ctime;
-       lvb->lvb_blocks = body->mbo_dom_blocks;
-       lvb->lvb_size = body->mbo_dom_size;
+       if (!(body->mbo_valid & OBD_MD_DOM_SIZE))
+               RETURN(-EPROTO);
 
+       mdc_body2lvb(body, lvb);
        RETURN(0);
 }
 
-int mdc_enqueue_fini(struct ptlrpc_request *req, osc_enqueue_upcall_f upcall,
-                    void *cookie, struct lustre_handle *lockh,
-                    enum ldlm_mode mode, __u64 *flags, int errcode)
+int mdc_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
+                    osc_enqueue_upcall_f upcall, void *cookie,
+                    struct lustre_handle *lockh, enum ldlm_mode mode,
+                    __u64 *flags, int errcode)
 {
        struct osc_lock *ols = cookie;
-       struct ldlm_lock *lock;
+       bool glimpse = *flags & LDLM_FL_HAS_INTENT;
        int rc = 0;
 
        ENTRY;
 
-       /* The request was created before ldlm_cli_enqueue call. */
-       if (errcode == ELDLM_LOCK_ABORTED) {
+       /* needed only for glimpse from an old server (< 2.14) */
+       if (glimpse && !exp_connect_dom_lvb(exp))
+               rc = mdc_fill_lvb(&req->rq_pill, &ols->ols_lvb);
+
+       if (glimpse && errcode == ELDLM_LOCK_ABORTED) {
                struct ldlm_reply *rep;
 
                rep = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
-               LASSERT(rep != NULL);
-
-               rep->lock_policy_res2 =
-                       ptlrpc_status_ntoh(rep->lock_policy_res2);
-               if (rep->lock_policy_res2)
-                       errcode = rep->lock_policy_res2;
-
-               rc = mdc_fill_lvb(req, &ols->ols_lvb);
+               if (likely(rep)) {
+                       rep->lock_policy_res2 =
+                               ptlrpc_status_ntoh(rep->lock_policy_res2);
+                       if (rep->lock_policy_res2)
+                               errcode = rep->lock_policy_res2;
+               } else {
+                       rc = -EPROTO;
+               }
                *flags |= LDLM_FL_LVB_READY;
        } else if (errcode == ELDLM_OK) {
+               struct ldlm_lock *lock;
+
                /* Callers have references, should be valid always */
                lock = ldlm_handle2lock(lockh);
-               LASSERT(lock);
 
-               rc = mdc_fill_lvb(req, &lock->l_ost_lvb);
+               /* At this point ols_lvb must be filled with correct LVB either
+                * by mdc_fill_lvb() above or by ldlm_cli_enqueue_fini().
+                * DoM uses l_ost_lvb to store LVB data, so copy it here from
+                * just updated ols_lvb.
+                */
+               lock_res_and_lock(lock);
+               memcpy(&lock->l_ost_lvb, &ols->ols_lvb,
+                      sizeof(lock->l_ost_lvb));
+               unlock_res_and_lock(lock);
                LDLM_LOCK_PUT(lock);
                *flags |= LDLM_FL_LVB_READY;
        }
@@ -633,6 +650,10 @@ int mdc_enqueue_interpret(const struct lu_env *env, struct ptlrpc_request *req,
        struct ldlm_lock *lock;
        struct lustre_handle *lockh = &aa->oa_lockh;
        enum ldlm_mode mode = aa->oa_mode;
+       struct ldlm_enqueue_info einfo = {
+               .ei_type = aa->oa_type,
+               .ei_mode = mode,
+       };
 
        ENTRY;
 
@@ -648,7 +669,8 @@ int mdc_enqueue_interpret(const struct lu_env *env, struct ptlrpc_request *req,
        /* Take an additional reference so that a blocking AST that
         * ldlm_cli_enqueue_fini() might post for a failed lock, is guaranteed
         * to arrive after an upcall has been executed by
-        * osc_enqueue_fini(). */
+        * mdc_enqueue_fini().
+        */
        ldlm_lock_addref(lockh, mode);
 
        /* Let cl_lock_state_wait fail with -ERESTARTSYS to unuse sublocks. */
@@ -658,12 +680,12 @@ int mdc_enqueue_interpret(const struct lu_env *env, struct ptlrpc_request *req,
        OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_CP_ENQ_RACE, 1);
 
        /* Complete obtaining the lock procedure. */
-       rc = ldlm_cli_enqueue_fini(aa->oa_exp, req, aa->oa_type, 1,
-                                  aa->oa_mode, aa->oa_flags, NULL, 0,
-                                  lockh, rc);
+       rc = ldlm_cli_enqueue_fini(aa->oa_exp, req, &einfo, 1, aa->oa_flags,
+                                  aa->oa_lvb, aa->oa_lvb ?
+                                  sizeof(*aa->oa_lvb) : 0, lockh, rc);
        /* Complete mdc stuff. */
-       rc = mdc_enqueue_fini(req, aa->oa_upcall, aa->oa_cookie, lockh, mode,
-                             aa->oa_flags, rc);
+       rc = mdc_enqueue_fini(aa->oa_exp, req, aa->oa_upcall, aa->oa_cookie,
+                             lockh, mode, aa->oa_flags, rc);
 
        OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_CP_CANCEL_RACE, 10);
 
@@ -681,8 +703,7 @@ int mdc_enqueue_interpret(const struct lu_env *env, struct ptlrpc_request *req,
  * release locks just after they are obtained. */
 int mdc_enqueue_send(const struct lu_env *env, struct obd_export *exp,
                     struct ldlm_res_id *res_id, __u64 *flags,
-                    union ldlm_policy_data *policy,
-                    struct ost_lvb *lvb, int kms_valid,
+                    union ldlm_policy_data *policy, struct ost_lvb *lvb,
                     osc_enqueue_upcall_f upcall, void *cookie,
                     struct ldlm_enqueue_info *einfo, int async)
 {
@@ -695,6 +716,8 @@ int mdc_enqueue_send(const struct lu_env *env, struct obd_export *exp,
        __u64 match_flags = *flags;
        LIST_HEAD(cancels);
        int rc, count;
+       int lvb_size;
+       bool compat_glimpse = glimpse && !exp_connect_dom_lvb(exp);
 
        ENTRY;
 
@@ -702,14 +725,11 @@ int mdc_enqueue_send(const struct lu_env *env, struct obd_export *exp,
        if (einfo->ei_mode == LCK_PR)
                mode |= LCK_PW;
 
+       match_flags |= LDLM_FL_LVB_READY;
        if (glimpse)
                match_flags |= LDLM_FL_BLOCK_GRANTED;
-       /* DOM locking uses LDLM_FL_KMS_IGNORE to mark locks wich have no valid
-        * LVB information, e.g. canceled locks or locks of just pruned object,
-        * such locks should be skipped.
-        */
        mode = ldlm_lock_match(obd->obd_namespace, match_flags, res_id,
-                              einfo->ei_type, policy, mode, &lockh, 0);
+                              einfo->ei_type, policy, mode, &lockh);
        if (mode) {
                struct ldlm_lock *matched;
 
@@ -738,7 +758,9 @@ int mdc_enqueue_send(const struct lu_env *env, struct obd_export *exp,
        if (*flags & (LDLM_FL_TEST_LOCK | LDLM_FL_MATCH_LOCK))
                RETURN(-ENOLCK);
 
-       req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_LDLM_INTENT);
+       /* Glimpse is intent on old server */
+       req = ptlrpc_request_alloc(class_exp2cliimp(exp), compat_glimpse ?
+                                  &RQF_LDLM_INTENT : &RQF_LDLM_ENQUEUE);
        if (req == NULL)
                RETURN(-ENOMEM);
 
@@ -756,20 +778,28 @@ int mdc_enqueue_send(const struct lu_env *env, struct obd_export *exp,
                RETURN(rc);
        }
 
-       /* pack the intent */
-       lit = req_capsule_client_get(&req->rq_pill, &RMF_LDLM_INTENT);
-       lit->opc = glimpse ? IT_GLIMPSE : IT_BRW;
-
-       req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, 0);
-       req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER, 0);
-       ptlrpc_request_set_replen(req);
+       if (compat_glimpse) {
+               /* pack the glimpse intent */
+               lit = req_capsule_client_get(&req->rq_pill, &RMF_LDLM_INTENT);
+               lit->opc = IT_GLIMPSE;
+       }
 
        /* users of mdc_enqueue() can pass this flag for ldlm_lock_match() */
        *flags &= ~LDLM_FL_BLOCK_GRANTED;
-       /* All MDC IO locks are intents */
-       *flags |= LDLM_FL_HAS_INTENT;
-       rc = ldlm_cli_enqueue(exp, &req, einfo, res_id, policy, flags, NULL,
-                             0, LVB_T_NONE, &lockh, async);
+
+       if (compat_glimpse) {
+               req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, 0);
+               req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER, 0);
+               lvb_size = 0;
+       } else {
+               lvb_size = sizeof(*lvb);
+               req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER,
+                                    lvb_size);
+       }
+       ptlrpc_request_set_replen(req);
+
+       rc = ldlm_cli_enqueue(exp, &req, einfo, res_id, policy, flags, lvb,
+                             lvb_size, LVB_T_OST, &lockh, async);
        if (async) {
                if (!rc) {
                        struct osc_enqueue_args *aa;
@@ -783,7 +813,7 @@ int mdc_enqueue_send(const struct lu_env *env, struct obd_export *exp,
                        aa->oa_cookie = cookie;
                        aa->oa_speculative = false;
                        aa->oa_flags = flags;
-                       aa->oa_lvb = lvb;
+                       aa->oa_lvb = compat_glimpse ? NULL : lvb;
 
                        req->rq_interpret_reply = mdc_enqueue_interpret;
                        ptlrpcd_add_req(req);
@@ -793,7 +823,7 @@ int mdc_enqueue_send(const struct lu_env *env, struct obd_export *exp,
                RETURN(rc);
        }
 
-       rc = mdc_enqueue_fini(req, upcall, cookie, &lockh, einfo->ei_mode,
+       rc = mdc_enqueue_fini(exp, req, upcall, cookie, &lockh, einfo->ei_mode,
                              flags, rc);
        ptlrpc_req_finished(req);
        RETURN(rc);
@@ -877,11 +907,10 @@ enqueue_base:
         * osc_lock.
         */
        fid_build_reg_res_name(lu_object_fid(osc2lu(osc)), resname);
-       mdc_lock_build_policy(env, policy);
+       mdc_lock_build_policy(env, lock, policy);
        LASSERT(!oscl->ols_speculative);
        result = mdc_enqueue_send(env, osc_export(osc), resname,
-                                 &oscl->ols_flags, policy,
-                                 &oscl->ols_lvb, osc->oo_oinfo->loi_kms_valid,
+                                 &oscl->ols_flags, policy, &oscl->ols_lvb,
                                  upcall, cookie, &oscl->ols_einfo, async);
        if (result == 0) {
                if (osc_lock_is_lockless(oscl)) {
@@ -943,6 +972,8 @@ int mdc_lock_init(const struct lu_env *env, struct cl_object *obj,
 
        ols->ols_flags = flags;
        ols->ols_speculative = !!(enqflags & CEF_SPECULATIVE);
+       if (lock->cll_descr.cld_mode == CLM_GROUP)
+               ols->ols_flags |= LDLM_FL_ATOMIC_CB;
 
        if (ols->ols_flags & LDLM_FL_HAS_INTENT) {
                ols->ols_flags |= LDLM_FL_BLOCK_GRANTED;
@@ -954,8 +985,6 @@ int mdc_lock_init(const struct lu_env *env, struct cl_object *obj,
 
        if (!(enqflags & CEF_MUST))
                osc_lock_to_lockless(env, ols, (enqflags & CEF_NEVER));
-       if (ols->ols_locklessable && !(enqflags & CEF_DISCARD_DATA))
-               ols->ols_flags |= LDLM_FL_DENY_ON_CONTENTION;
 
        if (io->ci_type == CIT_WRITE || cl_io_is_mkwrite(io))
                osc_lock_set_writer(env, io, obj, ols);
@@ -1029,6 +1058,11 @@ static int mdc_io_setattr_start(const struct lu_env *env,
                                              &oio->oi_trunc);
                if (rc < 0)
                        return rc;
+       } else if (cl_io_is_fallocate(io) &&
+                  io->u.ci_setattr.sa_falloc_mode & FALLOC_FL_PUNCH_HOLE) {
+               rc = osc_punch_start(env, io, obj);
+               if (rc < 0)
+                       return rc;
        }
 
        if (oio->oi_lockless == 0) {
@@ -1062,7 +1096,7 @@ static int mdc_io_setattr_start(const struct lu_env *env,
                        return rc;
        }
 
-       if (!(ia_avalid & ATTR_SIZE))
+       if (!(ia_avalid & ATTR_SIZE) && !cl_io_is_fallocate(io))
                return 0;
 
        memset(oa, 0, sizeof(*oa));
@@ -1070,12 +1104,10 @@ static int mdc_io_setattr_start(const struct lu_env *env,
        oa->o_mtime = attr->cat_mtime;
        oa->o_atime = attr->cat_atime;
        oa->o_ctime = attr->cat_ctime;
-
-       oa->o_size = size;
-       oa->o_blocks = OBD_OBJECT_EOF;
        oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLATIME |
                      OBD_MD_FLCTIME | OBD_MD_FLMTIME | OBD_MD_FLSIZE |
                      OBD_MD_FLBLOCKS;
+
        if (oio->oi_lockless) {
                oa->o_flags = OBD_FL_SRVLOCK;
                oa->o_valid |= OBD_MD_FLFLAGS;
@@ -1087,9 +1119,19 @@ static int mdc_io_setattr_start(const struct lu_env *env,
        }
 
        init_completion(&cbargs->opc_sync);
+       if (cl_io_is_fallocate(io)) {
+               int falloc_mode = io->u.ci_setattr.sa_falloc_mode;
 
-       rc = osc_punch_send(osc_export(cl2osc(obj)), oa,
-                           mdc_async_upcall, cbargs);
+               oa->o_size = io->u.ci_setattr.sa_falloc_offset;
+               oa->o_blocks = io->u.ci_setattr.sa_falloc_end;
+               rc = osc_fallocate_base(osc_export(cl2osc(obj)), oa,
+                                       mdc_async_upcall, cbargs, falloc_mode);
+       } else {
+               oa->o_size = size;
+               oa->o_blocks = OBD_OBJECT_EOF;
+               rc = osc_punch_send(osc_export(cl2osc(obj)), oa,
+                                   mdc_async_upcall, cbargs);
+       }
        cbargs->opc_rpc_sent = rc == 0;
        return rc;
 }
@@ -1099,6 +1141,7 @@ static int mdc_io_read_ahead(const struct lu_env *env,
                             pgoff_t start, struct cl_read_ahead *ra)
 {
        struct osc_object *osc = cl2osc(ios->cis_obj);
+       struct osc_io *oio = cl2osc_io(env, ios);
        struct ldlm_lock *dlmlock;
 
        ENTRY;
@@ -1107,6 +1150,7 @@ static int mdc_io_read_ahead(const struct lu_env *env,
        if (dlmlock == NULL)
                RETURN(-ENODATA);
 
+       oio->oi_is_readahead = 1;
        if (dlmlock->l_req_mode != LCK_PR) {
                struct lustre_handle lockh;
 
@@ -1118,7 +1162,8 @@ static int mdc_io_read_ahead(const struct lu_env *env,
        ra->cra_rpc_pages = osc_cli(osc)->cl_max_pages_per_rpc;
        ra->cra_end_idx = CL_PAGE_EOF;
        ra->cra_release = osc_read_ahead_release;
-       ra->cra_cbdata = dlmlock;
+       ra->cra_dlmlock = dlmlock;
+       ra->cra_oio = oio;
 
        RETURN(0);
 }
@@ -1278,15 +1323,15 @@ static void mdc_io_data_version_end(const struct lu_env *env,
        EXIT;
 }
 
-static struct cl_io_operations mdc_io_ops = {
+static const struct cl_io_operations mdc_io_ops = {
        .op = {
                [CIT_READ] = {
-                       .cio_iter_init = osc_io_rw_iter_init,
+                       .cio_iter_init = osc_io_iter_init,
                        .cio_iter_fini = osc_io_rw_iter_fini,
                        .cio_start     = osc_io_read_start,
                },
                [CIT_WRITE] = {
-                       .cio_iter_init = osc_io_rw_iter_init,
+                       .cio_iter_init = osc_io_iter_init,
                        .cio_iter_fini = osc_io_rw_iter_fini,
                        .cio_start     = osc_io_write_start,
                        .cio_end       = osc_io_end,
@@ -1311,10 +1356,16 @@ static struct cl_io_operations mdc_io_ops = {
                        .cio_start = mdc_io_fsync_start,
                        .cio_end   = osc_io_fsync_end,
                },
+               [CIT_LSEEK] = {
+                       .cio_start  = osc_io_lseek_start,
+                       .cio_end    = osc_io_lseek_end,
+               },
        },
        .cio_read_ahead   = mdc_io_read_ahead,
+       .cio_lru_reserve  = osc_io_lru_reserve,
        .cio_submit       = osc_io_submit,
        .cio_commit_async = osc_io_commit_async,
+       .cio_extent_release = osc_io_extent_release,
 };
 
 int mdc_io_init(const struct lu_env *env, struct cl_object *obj,
@@ -1439,7 +1490,7 @@ static int mdc_object_flush(const struct lu_env *env, struct cl_object *obj,
         * so init it here with given osc_object.
         */
        mdc_set_dom_lock_data(lock, cl2osc(obj));
-       RETURN(mdc_dlm_blocking_ast0(env, lock, LDLM_CB_CANCELING));
+       RETURN(mdc_dlm_canceling(env, lock));
 }
 
 static const struct cl_object_operations mdc_ops = {