if (!lre->lre_valid)
continue;
+ if (lre->lre_foreign)
+ continue;
+
lov_foreach_mirror_layout_entry(obj, lle, lre) {
if (!lle->lle_valid)
continue;
/* check if it needs to instantiate layout */
if (!(io->ci_type == CIT_WRITE || cl_io_is_mkwrite(io) ||
+ cl_io_is_fallocate(io) ||
(cl_io_is_trunc(io) && io->u.ci_setattr.sa_attr.lvb_size > 0)))
GOTO(out, result = 0);
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);
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)
{
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);
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);
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);
}
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;
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 */
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 */
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;
struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
struct lov_io_sub *sub;
loff_t offset = -ENXIO;
+ __u64 hole_off = 0;
bool seek_hole = io->u.ci_lseek.ls_whence == SEEK_HOLE;
ENTRY;
int index = lov_comp_entry(sub->sub_subio_index);
int stripe = lov_comp_stripe(sub->sub_subio_index);
loff_t sub_off, lov_off;
+ __u64 comp_end = lsm->lsm_entries[index]->lsme_extent.e_end;
lov_io_end_wrapper(sub->sub_env, subio);
/* resulting offset can be out of component range if stripe
* object is full and its file size was returned as virtual
* hole start. Skip this result, the next component will give
- * us correct lseek result.
+ * us correct lseek result but keep possible hole offset in
+ * case there is no more components ahead
*/
- if (lov_off >= lsm->lsm_entries[index]->lsme_extent.e_end)
+ if (lov_off >= comp_end) {
+ /* must be SEEK_HOLE case */
+ if (likely(seek_hole)) {
+ /* save comp end as potential hole offset */
+ hole_off = max_t(__u64, comp_end, hole_off);
+ } else {
+ io->ci_result = -EINVAL;
+ CDEBUG(D_INFO,
+ "off %lld >= comp_end %llu: rc = %d\n",
+ lov_off, comp_end, io->ci_result);
+ }
continue;
+ }
CDEBUG(D_INFO, "SEEK_%s: %lld->%lld/%lld: rc = %d\n",
seek_hole ? "HOLE" : "DATA",
sub->sub_io.ci_result);
offset = min_t(__u64, offset, lov_off);
}
+ /* no result but some component returns hole as component end */
+ if (seek_hole && offset == -ENXIO && hole_off > 0)
+ offset = hole_off;
+
io->u.ci_lseek.ls_result = offset;
RETURN_EXIT;
}
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 &&