Whamcloud - gitweb
LU-14382 mdt: implement fallocate in MDC/MDT
[fs/lustre-release.git] / lustre / mdc / mdc_dev.c
index 75d44ba..5ef4480 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <obd_class.h>
 #include <lustre_osc.h>
+#include <linux/falloc.h>
 #include <uapi/linux/lustre/lustre_param.h>
 
 #include "mdc_internal.h"
@@ -185,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 | 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);
+       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;
 }
 
@@ -546,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);
@@ -573,12 +568,12 @@ static int mdc_lock_upcall(void *cookie, struct lustre_handle *lockh,
 }
 
 /* This is needed only for old servers (before 2.14) support */
-int mdc_fill_lvb(struct ptlrpc_request *req, struct ost_lvb *lvb)
+int mdc_fill_lvb(struct req_capsule *pill, struct ost_lvb *lvb)
 {
        struct mdt_body *body;
 
        /* get LVB data from mdt_body otherwise */
-       body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
+       body = req_capsule_server_get(pill, &RMF_MDT_BODY);
        if (!body)
                RETURN(-EPROTO);
 
@@ -602,7 +597,7 @@ int mdc_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
 
        /* needed only for glimpse from an old server (< 2.14) */
        if (glimpse && !exp_connect_dom_lvb(exp))
-               rc = mdc_fill_lvb(req, &ols->ols_lvb);
+               rc = mdc_fill_lvb(&req->rq_pill, &ols->ols_lvb);
 
        if (glimpse && errcode == ELDLM_LOCK_ABORTED) {
                struct ldlm_reply *rep;
@@ -990,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);
@@ -1065,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) {
@@ -1098,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));
@@ -1106,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;
@@ -1123,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;
 }
@@ -1135,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;
@@ -1143,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;
 
@@ -1154,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);
 }
@@ -1314,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,
@@ -1353,8 +1362,10 @@ static struct cl_io_operations mdc_io_ops = {
                },
        },
        .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,