GOTO(out, rc);
}
- if (layout->li_opc == LAYOUT_INTENT_TRUNC) {
- /**
- * trunc transfers [size, eof) in the intent extent, while
- * we'd instantiated components covers [0, size).
- */
- layout->li_extent.e_end = layout->li_extent.e_start;
- layout->li_extent.e_start = 0;
- }
-
/* Make sure defined layout covers the requested write range. */
lod_comp = &lo->ldo_comp_entries[lo->ldo_comp_cnt - 1];
if (lo->ldo_comp_cnt > 1 &&
CDEBUG(D_LAYOUT, DFID": picked mirror %u as primary\n",
PFID(lod_object_fid(lo)), lo->ldo_mirrors[picked].lme_id);
- /* stale overlapping components from other mirrors */
- lod_stale_components(lo, picked, &extent);
-
- /* instantiate components for the picked mirror, start from 0 */
if (layout->li_opc == LAYOUT_INTENT_TRUNC) {
/**
- * trunc transfers [size, eof) in the intent extent, we'd
- * stale components overlapping [size, eof), while we'd
- * instantiated components covers [0, size).
+ * trunc transfers [0, size) in the intent extent, we'd
+ * stale components overlapping [size, eof).
*/
- extent.e_end = extent.e_start;
+ extent.e_start = extent.e_end;
+ extent.e_end = OBD_OBJECT_EOF;
}
+
+ /* stale overlapping components from other mirrors */
+ lod_stale_components(lo, picked, &extent);
+
+ /* restore truncate intent extent */
+ if (layout->li_opc == LAYOUT_INTENT_TRUNC)
+ extent.e_end = extent.e_start;
+
+ /* instantiate components for the picked mirror, start from 0 */
extent.e_start = 0;
lod_foreach_mirror_comp(lod_comp, lo, picked) {
CDEBUG(D_LAYOUT, DFID": intent to write: "DEXT"\n",
PFID(lod_object_fid(lo)), PEXT(&extent));
+ if (mlc->mlc_intent->li_opc == LAYOUT_INTENT_TRUNC) {
+ /**
+ * trunc transfers [0, size) in the intent extent, we'd
+ * stale components overlapping [size, eof).
+ */
+ extent.e_start = extent.e_end;
+ extent.e_end = OBD_OBJECT_EOF;
+ }
/* 1. stale overlapping components */
lod_stale_components(lo, primary, &extent);
/* 2. find out the components need instantiating.
* instantiate [0, mlc->mlc_intent->e_end) */
- if (mlc->mlc_intent->li_opc == LAYOUT_INTENT_TRUNC) {
- /**
- * trunc transfers [size, eof) in the intent extent,
- * we'd stale components overlapping [size, eof),
- * while we'd instantiated components covers [0, size).
- */
+
+ /* restore truncate intent extent */
+ if (mlc->mlc_intent->li_opc == LAYOUT_INTENT_TRUNC)
extent.e_end = extent.e_start;
- }
extent.e_start = 0;
lod_foreach_mirror_comp(lod_comp, lo, primary) {
PFID(lu_object_fid(lov2lu(obj))),
lio->lis_pos, lio->lis_endpos);
+ if (cl_io_is_trunc(io)) {
+ /**
+ * for truncate, we uses [size, EOF) to judge whether
+ * a write intent needs to be send, but we need to
+ * restore the write extent to [0, size).
+ */
+ io->ci_write_intent.e_start = 0;
+ io->ci_write_intent.e_end =
+ io->u.ci_setattr.sa_attr.lvb_size;
+ }
/* stop cl_io_init() loop */
RETURN(1);
}
static int lov_io_slice_init(struct lov_io *lio,
struct lov_object *obj, struct cl_io *io)
{
- struct lu_extent ext;
int index;
int result = 0;
ENTRY;
(cl_io_is_trunc(io) && io->u.ci_setattr.sa_attr.lvb_size > 0)))
GOTO(out, result = 0);
- io->ci_write_intent.e_start = lio->lis_pos;
- io->ci_write_intent.e_end = lio->lis_endpos;
-
- ext = io->ci_write_intent;
/* for truncate, it only needs to instantiate the components
* before the truncated size. */
if (cl_io_is_trunc(io)) {
- ext.e_start = 0;
- ext.e_end = io->u.ci_setattr.sa_attr.lvb_size;
+ io->ci_write_intent.e_start = 0;
+ io->ci_write_intent.e_end = io->u.ci_setattr.sa_attr.lvb_size;
+ } else {
+ io->ci_write_intent.e_start = lio->lis_pos;
+ io->ci_write_intent.e_end = lio->lis_endpos;
}
index = 0;
- lov_foreach_io_layout(index, lio, &ext) {
+ lov_foreach_io_layout(index, lio, &io->ci_write_intent) {
if (!lsm_entry_inited(obj->lo_lsm, index)) {
io->ci_need_write_intent = 1;
break;