Whamcloud - gitweb
LU-3259 clio: Revise read ahead implementation
[fs/lustre-release.git] / lustre / osc / osc_io.c
index 24f86ab..de25635 100644 (file)
@@ -92,6 +92,45 @@ static void osc_io_fini(const struct lu_env *env, const struct cl_io_slice *io)
 {
 }
 
+static void osc_read_ahead_release(const struct lu_env *env,
+                                  void *cbdata)
+{
+       struct ldlm_lock *dlmlock = cbdata;
+       struct lustre_handle lockh;
+
+       ldlm_lock2handle(dlmlock, &lockh);
+       ldlm_lock_decref(&lockh, LCK_PR);
+       LDLM_LOCK_PUT(dlmlock);
+}
+
+static int osc_io_read_ahead(const struct lu_env *env,
+                            const struct cl_io_slice *ios,
+                            pgoff_t start, struct cl_read_ahead *ra)
+{
+       struct osc_object       *osc = cl2osc(ios->cis_obj);
+       struct ldlm_lock        *dlmlock;
+       int                     result = -ENODATA;
+       ENTRY;
+
+       dlmlock = osc_dlmlock_at_pgoff(env, osc, start, 0);
+       if (dlmlock != NULL) {
+               if (dlmlock->l_req_mode != LCK_PR) {
+                       struct lustre_handle lockh;
+                       ldlm_lock2handle(dlmlock, &lockh);
+                       ldlm_lock_addref(&lockh, LCK_PR);
+                       ldlm_lock_decref(&lockh, dlmlock->l_req_mode);
+               }
+
+               ra->cra_end = cl_index(osc2cl(osc),
+                                      dlmlock->l_policy_data.l_extent.end);
+               ra->cra_release = osc_read_ahead_release;
+               ra->cra_cbdata = dlmlock;
+               result = 0;
+       }
+
+       RETURN(result);
+}
+
 /**
  * An implementation of cl_io_operations::cio_io_submit() method for osc
  * layer. Iterates over pages in the in-queue, prepares each for io by calling
@@ -730,6 +769,7 @@ static const struct cl_io_operations osc_io_ops = {
                        .cio_fini   = osc_io_fini
                }
        },
+       .cio_read_ahead             = osc_io_read_ahead,
        .cio_submit                 = osc_io_submit,
        .cio_commit_async           = osc_io_commit_async
 };
@@ -804,7 +844,7 @@ static void osc_req_attr_set(const struct lu_env *env,
                                     struct cl_page, cp_flight);
                opg = osc_cl_page_osc(apage, NULL);
                lock = osc_dlmlock_at_pgoff(env, cl2osc(obj), osc_index(opg),
-                                           1, 1);
+                               OSC_DAP_FL_TEST_LOCK | OSC_DAP_FL_CANCELING);
                if (lock == NULL && !opg->ops_srvlock) {
                        struct ldlm_resource *res;
                        struct ldlm_res_id *resname;