Whamcloud - gitweb
LU-14502 lov: fault page update cp_lov_index
[fs/lustre-release.git] / lustre / lov / lov_io.c
index f20c8f4..4cd93fa 100644 (file)
@@ -408,6 +408,9 @@ static int lov_io_mirror_init(struct lov_io *lio, struct lov_object *obj,
                if (!lre->lre_valid)
                        continue;
 
+               if (lre->lre_foreign)
+                       continue;
+
                lov_foreach_mirror_layout_entry(obj, lle, lre) {
                        if (!lle->lle_valid)
                                continue;
@@ -685,17 +688,16 @@ static void lov_io_sub_inherit(struct lov_io_sub *sub, struct lov_io *lio,
                                        parent->u.ci_setattr.sa_parent_fid;
                /* For SETATTR(fallocate) pass the subtype to lower IO */
                io->u.ci_setattr.sa_subtype = parent->u.ci_setattr.sa_subtype;
-               if (cl_io_is_trunc(io)) {
+               if (cl_io_is_fallocate(io)) {
+                       io->u.ci_setattr.sa_falloc_offset = start;
+                       io->u.ci_setattr.sa_falloc_end = end;
+               }
+               if (cl_io_is_trunc(io) || cl_io_is_fallocate(io)) {
                        loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
 
                        new_size = lov_size_to_stripe(lsm, index, new_size,
                                                      stripe);
                        io->u.ci_setattr.sa_attr.lvb_size = new_size;
-               } else if (cl_io_is_fallocate(io)) {
-                       io->u.ci_setattr.sa_falloc_offset = start;
-                       io->u.ci_setattr.sa_falloc_end = end;
-                       io->u.ci_setattr.sa_attr.lvb_size =
-                               parent->u.ci_setattr.sa_attr.lvb_size;
                }
                lov_lsm2layout(lsm, lsm->lsm_entries[index],
                               &io->u.ci_setattr.sa_layout);
@@ -763,6 +765,23 @@ static loff_t lov_offset_mod(loff_t val, int delta)
        return val;
 }
 
+static int lov_io_add_sub(const struct lu_env *env, struct lov_io *lio,
+                         struct lov_io_sub *sub, u64 start, u64 end)
+{
+       int rc;
+
+       end = lov_offset_mod(end, 1);
+       lov_io_sub_inherit(sub, lio, start, end);
+       rc = cl_io_iter_init(sub->sub_env, &sub->sub_io);
+       if (rc != 0) {
+               cl_io_iter_fini(sub->sub_env, &sub->sub_io);
+               return rc;
+       }
+
+       list_add_tail(&sub->sub_linkage, &lio->lis_active);
+
+       return rc;
+}
 static int lov_io_iter_init(const struct lu_env *env,
                            const struct cl_io_slice *ios)
 {
@@ -784,6 +803,9 @@ static int lov_io_iter_init(const struct lu_env *env,
                u64 start;
                u64 end;
                int stripe;
+               bool tested_trunc_stripe = false;
+
+               r0->lo_trunc_stripeno = -1;
 
                CDEBUG(D_VFSTRACE, "component[%d] flags %#x\n",
                       index, lsm->lsm_entries[index]->lsme_flags);
@@ -795,6 +817,9 @@ static int lov_io_iter_init(const struct lu_env *env,
                        continue;
                }
 
+               if (lsm_entry_is_foreign(lsm, index))
+                       continue;
+
                if (!le->lle_valid && !ios->cis_io->ci_designated_mirror) {
                        CERROR("I/O to invalid component: %d, mirror: %d\n",
                               index, lio->lis_mirror_index);
@@ -815,28 +840,79 @@ static int lov_io_iter_init(const struct lu_env *env,
                                continue;
                        }
 
-                       end = lov_offset_mod(end, 1);
+                       if (cl_io_is_trunc(ios->cis_io) &&
+                           !tested_trunc_stripe) {
+                               int prev;
+                               u64 tr_start;
+
+                               prev = (stripe == 0) ? r0->lo_nr - 1 :
+                                                       stripe - 1;
+                               /**
+                                * Only involving previous stripe if the
+                                * truncate in this component is at the
+                                * beginning of this stripe.
+                                */
+                               tested_trunc_stripe = true;
+                               if (ext.e_start < lsm->lsm_entries[index]->
+                                                       lsme_extent.e_start) {
+                                       /* need previous stripe involvement */
+                                       r0->lo_trunc_stripeno = prev;
+                               } else {
+                                       tr_start = ext.e_start;
+                                       tr_start = lov_do_div64(tr_start,
+                                                     stripe_width(lsm, index));
+                                       /* tr_start %= stripe_swidth */
+                                       if (tr_start == stripe * lsm->
+                                                       lsm_entries[index]->
+                                                       lsme_stripe_size)
+                                               r0->lo_trunc_stripeno = prev;
+                               }
+                       }
+
+                       /* if the last stripe is the trunc stripeno */
+                       if (r0->lo_trunc_stripeno == stripe)
+                               r0->lo_trunc_stripeno = -1;
+
                        sub = lov_sub_get(env, lio,
                                          lov_comp_index(index, stripe));
-                       if (IS_ERR(sub)) {
-                               rc = PTR_ERR(sub);
+                       if (IS_ERR(sub))
+                               return PTR_ERR(sub);
+
+                       rc = lov_io_add_sub(env, lio, sub, start, end);
+                       if (rc != 0)
                                break;
+               }
+               if (rc != 0)
+                       break;
+
+               if (r0->lo_trunc_stripeno != -1) {
+                       stripe = r0->lo_trunc_stripeno;
+                       if (unlikely(!r0->lo_sub[stripe])) {
+                               r0->lo_trunc_stripeno = -1;
+                               continue;
                        }
+                       sub = lov_sub_get(env, lio,
+                                         lov_comp_index(index, stripe));
+                       if (IS_ERR(sub))
+                               return PTR_ERR(sub);
 
-                       lov_io_sub_inherit(sub, lio, start, end);
-                       rc = cl_io_iter_init(sub->sub_env, &sub->sub_io);
-                       if (rc != 0)
-                               cl_io_iter_fini(sub->sub_env, &sub->sub_io);
+                       /**
+                        * the prev sub could be used by another truncate, we'd
+                        * skip it. LU-14128 happends when expand truncate +
+                        * read get wrong kms.
+                        */
+                       if (!list_empty(&sub->sub_linkage)) {
+                               r0->lo_trunc_stripeno = -1;
+                               continue;
+                       }
+
+                       (void)lov_stripe_intersects(lsm, index, stripe, &ext,
+                                                   &start, &end);
+                       rc = lov_io_add_sub(env, lio, sub, start, end);
                        if (rc != 0)
                                break;
 
-                       CDEBUG(D_VFSTRACE, "shrink: %d [%llu, %llu)\n",
-                              stripe, start, end);
-
-                       list_add_tail(&sub->sub_linkage, &lio->lis_active);
                }
-               if (rc != 0)
-                       break;
        }
        RETURN(rc);
 }
@@ -878,6 +954,9 @@ static int lov_io_rw_iter_init(const struct lu_env *env,
 
        lse = lov_lse(lio->lis_object, index);
 
+       if (lsme_is_foreign(lse))
+               RETURN(-EINVAL);
+
        next = MAX_LFS_FILESIZE;
        if (lse->lsme_stripe_count > 1) {
                unsigned long ssize = lse->lsme_stripe_size;
@@ -1064,7 +1143,8 @@ static int lov_io_read_ahead(const struct lu_env *env,
 
        offset = cl_offset(obj, start);
        index = lov_io_layout_at(lio, offset);
-       if (index < 0 || !lsm_entry_inited(loo->lo_lsm, index))
+       if (index < 0 || !lsm_entry_inited(loo->lo_lsm, index) ||
+           lsm_entry_is_foreign(loo->lo_lsm, index))
                RETURN(-ENODATA);
 
        /* avoid readahead to expand to stale components */
@@ -1268,6 +1348,10 @@ static int lov_io_commit_async(const struct lu_env *env,
                        break;
 
                from = 0;
+
+               if (lov_comp_entry(index) !=
+                   lov_comp_entry(page->cp_lov_index))
+                       cl_io_extent_release(sub->sub_env, &sub->sub_io);
        }
 
        /* for error case, add the page back into the qin list */
@@ -1287,11 +1371,50 @@ static int lov_io_fault_start(const struct lu_env *env,
        struct cl_fault_io *fio;
        struct lov_io      *lio;
        struct lov_io_sub  *sub;
+       loff_t offset;
+       int entry;
+       int stripe;
 
        ENTRY;
 
        fio = &ios->cis_io->u.ci_fault;
        lio = cl2lov_io(env, ios);
+
+       /**
+        * LU-14502: ft_page could be an existing cl_page associated with
+        * the vmpage covering the fault index, and the page may still
+        * refer to another mirror of an old IO.
+        */
+       if (lov_is_flr(lio->lis_object)) {
+               offset = cl_offset(ios->cis_obj, fio->ft_index);
+               entry = lov_io_layout_at(lio, offset);
+               if (entry < 0) {
+                       CERROR(DFID": page fault index %lu invalid component: "
+                              "%d, mirror: %d\n",
+                              PFID(lu_object_fid(&ios->cis_obj->co_lu)),
+                              fio->ft_index, entry,
+                              lio->lis_mirror_index);
+                       RETURN(-EIO);
+               }
+               stripe = lov_stripe_number(lio->lis_object->lo_lsm,
+                                          entry, offset);
+
+               if (fio->ft_page->cp_lov_index !=
+                   lov_comp_index(entry, stripe)) {
+                       CDEBUG(D_INFO, DFID": page fault at index %lu, "
+                              "at mirror %u comp entry %u stripe %u, "
+                              "been used with comp entry %u stripe %u\n",
+                              PFID(lu_object_fid(&ios->cis_obj->co_lu)),
+                              fio->ft_index, lio->lis_mirror_index,
+                              entry, stripe,
+                              lov_comp_entry(fio->ft_page->cp_lov_index),
+                              lov_comp_stripe(fio->ft_page->cp_lov_index));
+
+                       fio->ft_page->cp_lov_index =
+                                       lov_comp_index(entry, stripe);
+               }
+       }
+
        sub = lov_sub_get(env, lio, fio->ft_page->cp_lov_index);
        sub->sub_io.u.ci_fault.ft_nob = fio->ft_nob;
 
@@ -1737,6 +1860,8 @@ int lov_io_layout_at(struct lov_io *lio, __u64 offset)
        for (i = start_index; i <= end_index; i++) {
                struct lov_layout_entry *lle = lov_entry(lov, i);
 
+               LASSERT(!lsme_is_foreign(lle->lle_lsme));
+
                if ((offset >= lle->lle_extent->e_start &&
                     offset < lle->lle_extent->e_end) ||
                    (offset == OBD_OBJECT_EOF &&