]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
truncate: don't write beyong truncation with old trunc seq
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 2 Feb 2010 00:03:51 +0000 (16:03 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 2 Feb 2010 00:14:05 +0000 (16:14 -0800)
In a scenario where a truncation that followed a write got to
the osd before the preceding write, we shouldn't write beyond
that truncation when the write is handled in the osd.

src/osd/ReplicatedPG.cc

index df465767bcba1869f5afc7d4723911a005e94ba8..fb969023a1828eadb73b099cdac20124aa9dfbe1 100644 (file)
@@ -1045,6 +1045,12 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops,
 
     case CEPH_OSD_OP_WRITE:
       { // write
+        __u32 seq = oi.truncate_seq;
+        if (seq && (seq > op.extent.truncate_seq) &&
+            (op.extent.offset + op.extent.length > oi.size)) {
+         op.extent.length =  (op.extent.offset > oi.size ? 0 : oi.size - op.extent.offset);
+        }
+
         if (op.extent.length) {
          bufferlist nbl;
          bp.copy(op.extent.length, nbl);
@@ -1247,6 +1253,8 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops,
          oi.truncate_seq = op.extent.truncate_seq;
          oi.truncate_size = op.extent.truncate_size;
        } else {
+         dout(10) << " seq " << op.extent.truncate_seq << " > old_seq " << old_seq
+                  << " already truncated" << dendl;
          // object was already truncated, no-op.
        }
       }