Whamcloud - gitweb
b=21982 long file truncate problem
[fs/lustre-release.git] / lustre / lov / lov_io.c
index f3d8893..b21fd94 100644 (file)
@@ -42,7 +42,9 @@
 
 #include "lov_cl_internal.h"
 
-/** \addtogroup lov lov @{ */
+/** \addtogroup lov
+ *  @{
+ */
 
 static void lov_sub_enter(struct lov_io_sub *sub)
 {
@@ -98,7 +100,7 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
 
         switch(io->ci_type) {
         case CIT_TRUNC: {
-                size_t new_size = parent->u.ci_truncate.tr_size;
+                loff_t new_size = parent->u.ci_truncate.tr_size;
 
                 new_size = lov_size_to_stripe(lsm, new_size, stripe);
                 io->u.ci_truncate.tr_capa = parent->u.ci_truncate.tr_capa;
@@ -116,8 +118,12 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
         }
         case CIT_READ:
         case CIT_WRITE: {
-                io->u.ci_rw.crw_pos = start;
-                io->u.ci_rw.crw_count = end - start;
+                if (cl_io_is_append(parent)) {
+                        io->u.ci_wr.wr_append = 1;
+                } else {
+                        io->u.ci_rw.crw_pos = start;
+                        io->u.ci_rw.crw_count = end - start;
+                }
                 break;
         }
         default:
@@ -146,17 +152,8 @@ static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
         sub->sub_io_initialized = 0;
         sub->sub_borrowed = 0;
 
-        /*
-         * First sub-io. Use ->lis_single_subio and current environment, to
-         * avoid dynamic allocation.
-         */
-        if (lio->lis_active_subios == 0) {
-                sub->sub_io = &lio->lis_single_subio;
-                lio->lis_single_subio_index = stripe;
-                sub->sub_env = cl_env_get(&sub->sub_refcheck);
-                LASSERT(sub->sub_env == env);
-        } else if (lio->lis_mem_frozen) {
-                LASSERT(mutex_is_locked(&ld->ld_mutex));
+        if (lio->lis_mem_frozen) {
+                LASSERT(cfs_mutex_is_locked(&ld->ld_mutex));
                 sub->sub_io  = &ld->ld_emrg[stripe]->emrg_subio;
                 sub->sub_env = ld->ld_emrg[stripe]->emrg_env;
                 sub->sub_borrowed = 1;
@@ -167,12 +164,23 @@ static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
                 cookie = cl_env_reenter();
                 sub->sub_env = cl_env_get(&sub->sub_refcheck);
                 cl_env_reexit(cookie);
-
-                OBD_ALLOC_PTR(sub->sub_io);
                 if (IS_ERR(sub->sub_env))
                         result = PTR_ERR(sub->sub_env);
-                else if (sub->sub_io == NULL)
-                        result = -ENOMEM;
+
+                if (result == 0) {
+                        /*
+                         * First sub-io. Use ->lis_single_subio to
+                         * avoid dynamic allocation.
+                         */
+                        if (lio->lis_active_subios == 0) {
+                                sub->sub_io = &lio->lis_single_subio;
+                                lio->lis_single_subio_index = stripe;
+                        } else {
+                                OBD_ALLOC_PTR(sub->sub_io);
+                                if (sub->sub_io == NULL)
+                                        result = -ENOMEM;
+                        }
+                }
         }
 
         if (result == 0) {
@@ -394,7 +402,7 @@ static int lov_io_iter_init(const struct lu_env *env,
                         rc = PTR_ERR(sub);
 
                 if (!rc)
-                        list_add_tail(&sub->sub_linkage, &lio->lis_active);
+                        cfs_list_add_tail(&sub->sub_linkage, &lio->lis_active);
                 else
                         break;
         }
@@ -409,7 +417,7 @@ static int lov_io_rw_iter_init(const struct lu_env *env,
         struct lov_stripe_md *lsm = lov_r0(cl2lov(ios->cis_obj))->lo_lsm;
         loff_t start = io->u.ci_rw.crw_pos;
         loff_t next;
-        int ssize = lsm->lsm_stripe_size;
+        unsigned long ssize = lsm->lsm_stripe_size;
 
         LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
         ENTRY;
@@ -445,7 +453,7 @@ static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
         int rc = 0;
 
         ENTRY;
-        list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
+        cfs_list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
                 lov_sub_enter(sub);
                 rc = iofunc(sub->sub_env, sub->sub_io);
                 lov_sub_exit(sub);
@@ -511,8 +519,8 @@ static void lov_io_iter_fini(const struct lu_env *env,
         ENTRY;
         rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
         LASSERT(rc == 0);
-        while (!list_empty(&lio->lis_active))
-                list_del_init(lio->lis_active.next);
+        while (!cfs_list_empty(&lio->lis_active))
+                cfs_list_del_init(lio->lis_active.next);
         EXIT;
 }
 
@@ -604,7 +612,7 @@ static int lov_io_submit(const struct lu_env *env,
                  * In order to not make things worse, even don't try to
                  * allocate the memory with __GFP_NOWARN. -jay
                  */
-                mutex_lock(&ld->ld_mutex);
+                cfs_mutex_lock(&ld->ld_mutex);
                 lio->lis_mem_frozen = 1;
         }
 
@@ -618,7 +626,7 @@ static int lov_io_submit(const struct lu_env *env,
                 struct lov_io_sub   *sub;
                 struct cl_page_list *sub_qin = QIN(stripe);
 
-                if (list_empty(&sub_qin->pl_pages))
+                if (cfs_list_empty(&sub_qin->pl_pages))
                         continue;
 
                 cl_page_list_splice(sub_qin, &cl2q->c2_qin);
@@ -638,7 +646,7 @@ static int lov_io_submit(const struct lu_env *env,
         for (stripe = 0; stripe < lio->lis_nr_subios; stripe++) {
                 struct cl_page_list *sub_qin = QIN(stripe);
 
-                if (list_empty(&sub_qin->pl_pages))
+                if (cfs_list_empty(&sub_qin->pl_pages))
                         continue;
 
                 cl_page_list_splice(sub_qin, qin);
@@ -657,7 +665,7 @@ static int lov_io_submit(const struct lu_env *env,
                                 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
                 }
                 lio->lis_mem_frozen = 0;
-                mutex_unlock(&ld->ld_mutex);
+                cfs_mutex_unlock(&ld->ld_mutex);
         }
 
         RETURN(rc);