Whamcloud - gitweb
LU-1030 clio: reimplement ll_fsync in clio way
[fs/lustre-release.git] / lustre / lov / lov_io.c
index 20d3319..3cf97dd 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  *  @{
  */
 
-static void lov_sub_enter(struct lov_io_sub *sub)
+static inline void lov_sub_enter(struct lov_io_sub *sub)
 {
-        ENTRY;
-        if (sub->sub_reenter++ == 0) {
-                sub->sub_cookie = cl_env_reenter();
-                cl_env_implant(sub->sub_env, &sub->sub_refcheck2);
-        }
-        EXIT;
+        sub->sub_reenter++;
 }
-
-static void lov_sub_exit(struct lov_io_sub *sub)
+static inline void lov_sub_exit(struct lov_io_sub *sub)
 {
-        ENTRY;
-        if (--sub->sub_reenter == 0) {
-                cl_env_unplant(sub->sub_env, &sub->sub_refcheck2);
-                cl_env_reexit(sub->sub_cookie);
-        }
-        EXIT;
+        sub->sub_reenter--;
 }
 
 static void lov_io_sub_fini(const struct lu_env *env, struct lov_io *lio,
@@ -120,6 +109,13 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
                 io->u.ci_fault.ft_index = cl_index(obj, off);
                 break;
         }
+       case CIT_FSYNC: {
+               io->u.ci_fsync.fi_start = start;
+               io->u.ci_fsync.fi_end = end;
+               io->u.ci_fsync.fi_capa = parent->u.ci_fsync.fi_capa;
+               io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
+               break;
+       }
         case CIT_READ:
         case CIT_WRITE: {
                 if (cl_io_is_append(parent)) {
@@ -290,8 +286,8 @@ static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
          * Need to be optimized, we can't afford to allocate a piece of memory
          * when writing a page. -jay
          */
-        OBD_ALLOC(lio->lis_subs,
-                  lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
+        OBD_ALLOC_LARGE(lio->lis_subs,
+                        lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
         if (lio->lis_subs != NULL) {
                 lio->lis_nr_subios = lio->lis_stripe_count;
                 lio->lis_single_subio_index = -1;
@@ -342,6 +338,12 @@ static void lov_io_slice_init(struct lov_io *lio,
                 break;
         }
 
+       case CIT_FSYNC: {
+               lio->lis_pos = io->u.ci_fsync.fi_start;
+               lio->lis_endpos = io->u.ci_fsync.fi_end;
+               break;
+       }
+
         case CIT_MISC:
                 lio->lis_pos = 0;
                 lio->lis_endpos = OBD_OBJECT_EOF;
@@ -363,7 +365,7 @@ static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
         if (lio->lis_subs != NULL) {
                 for (i = 0; i < lio->lis_nr_subios; i++)
                         lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
-                OBD_FREE(lio->lis_subs,
+                OBD_FREE_LARGE(lio->lis_subs,
                          lio->lis_nr_subios * sizeof lio->lis_subs[0]);
                 lio->lis_nr_subios = 0;
         }
@@ -403,7 +405,7 @@ static int lov_io_iter_init(const struct lu_env *env,
                                            start, end);
                         rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
                         lov_sub_put(sub);
-                        CDEBUG(D_VFSTRACE, "shrink: %i ["LPU64", "LPU64")\n",
+                        CDEBUG(D_VFSTRACE, "shrink: %d ["LPU64", "LPU64")\n",
                                stripe, start, end);
                 } else
                         rc = PTR_ERR(sub);
@@ -432,19 +434,19 @@ static int lov_io_rw_iter_init(const struct lu_env *env,
         /* fast path for common case. */
         if (lio->lis_nr_subios != 1 && !cl_io_is_append(io)) {
 
-                do_div(start, ssize);
-                next = (start + 1) * ssize;
-                if (next <= start * ssize)
-                        next = ~0ull;
+               lov_do_div64(start, ssize);
+               next = (start + 1) * ssize;
+               if (next <= start * ssize)
+                       next = ~0ull;
 
                 io->ci_continue = next < lio->lis_io_endpos;
                 io->u.ci_rw.crw_count = min_t(loff_t, lio->lis_io_endpos,
                                               next) - io->u.ci_rw.crw_pos;
                 lio->lis_pos    = io->u.ci_rw.crw_pos;
                 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
-                CDEBUG(D_VFSTRACE, "stripe: "LPU64" chunk: ["LPU64", "LPU64") "LPU64"\n",
-                       (__u64)start, lio->lis_pos, lio->lis_endpos,
-                       (__u64)lio->lis_io_endpos);
+               CDEBUG(D_VFSTRACE, "stripe: "LPU64" chunk: ["LPU64", "LPU64") "
+                      LPU64"\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
+                      (__u64)lio->lis_io_endpos);
         }
         /*
          * XXX The following call should be optimized: we know, that
@@ -456,6 +458,7 @@ static int lov_io_rw_iter_init(const struct lu_env *env,
 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
                        int (*iofunc)(const struct lu_env *, struct cl_io *))
 {
+       struct cl_io *parent = lio->lis_cl.cis_io;
         struct lov_io_sub *sub;
         int rc = 0;
 
@@ -466,6 +469,9 @@ static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
                 lov_sub_exit(sub);
                 if (rc)
                         break;
+
+               if (parent->ci_result == 0)
+                       parent->ci_result = sub->sub_io->ci_result;
         }
         RETURN(rc);
 }
@@ -606,8 +612,8 @@ static int lov_io_submit(const struct lu_env *env,
 
         LASSERT(lio->lis_subs != NULL);
         if (alloc) {
-                OBD_ALLOC(stripes_qin,
-                          sizeof(*stripes_qin) * lio->lis_nr_subios);
+                OBD_ALLOC_LARGE(stripes_qin,
+                                sizeof(*stripes_qin) * lio->lis_nr_subios);
                 if (stripes_qin == NULL)
                         RETURN(-ENOMEM);
 
@@ -660,7 +666,7 @@ static int lov_io_submit(const struct lu_env *env,
         }
 
         if (alloc) {
-                OBD_FREE(stripes_qin,
+                OBD_FREE_LARGE(stripes_qin,
                          sizeof(*stripes_qin) * lio->lis_nr_subios);
         } else {
                 int i;
@@ -775,6 +781,15 @@ static const struct cl_io_operations lov_io_ops = {
                         .cio_start     = lov_io_fault_start,
                         .cio_end       = lov_io_end
                 },
+               [CIT_FSYNC] = {
+                       .cio_fini      = lov_io_fini,
+                       .cio_iter_init = lov_io_iter_init,
+                       .cio_iter_fini = lov_io_iter_fini,
+                       .cio_lock      = lov_io_lock,
+                       .cio_unlock    = lov_io_unlock,
+                       .cio_start     = lov_io_start,
+                       .cio_end       = lov_io_end
+               },
                 [CIT_MISC] = {
                         .cio_fini   = lov_io_fini
                 }
@@ -847,6 +862,9 @@ static const struct cl_io_operations lov_empty_io_ops = {
                         .cio_start     = LOV_EMPTY_IMPOSSIBLE,
                         .cio_end       = LOV_EMPTY_IMPOSSIBLE
                 },
+               [CIT_FSYNC] = {
+                       .cio_fini   = lov_empty_io_fini
+               },
                 [CIT_MISC] = {
                         .cio_fini   = lov_empty_io_fini
                 }
@@ -890,6 +908,7 @@ int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
         switch (io->ci_type) {
         default:
                 LBUG();
+       case CIT_FSYNC:
         case CIT_MISC:
         case CIT_READ:
                 result = 0;