rbd: create+truncate for whole-object layered discards
authorIlya Dryomov <idryomov@gmail.com>
Tue, 6 Feb 2018 18:26:34 +0000 (19:26 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 2 Apr 2018 08:12:43 +0000 (10:12 +0200)
A whole-object layered discard is implemented as a truncate rather
than a delete: a dummy object is needed to prevent the CoW machinery
from kicking in.  However, a truncate on a non-existent object is
a no-op.  If the object doesn't exist in HEAD, a discard request is
effectively ignored, which violates our "discard zeroes data" promise
and breaks REQ_OP_WRITE_ZEROES implementation.

A non-exclusive create on an existing object is also a no-op, so the
fix is to do a compound create+truncate instead.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
drivers/block/rbd.c

index 0aa95e08664d69ce18306db53370379d18dc21be..fc94e2c45e285ea2e871096f622157b3879780a9 100644 (file)
@@ -1884,6 +1884,8 @@ static void __rbd_obj_setup_discard(struct rbd_obj_request *obj_req,
 
        if (rbd_obj_is_entire(obj_req)) {
                if (obj_req->num_img_extents) {
+                       osd_req_op_init(obj_req->osd_req, which++,
+                                       CEPH_OSD_OP_CREATE, 0);
                        opcode = CEPH_OSD_OP_TRUNCATE;
                } else {
                        osd_req_op_init(obj_req->osd_req, which++,
@@ -1917,7 +1919,10 @@ static int rbd_obj_setup_discard(struct rbd_obj_request *obj_req)
 
        if (rbd_obj_is_entire(obj_req)) {
                obj_req->write_state = RBD_OBJ_WRITE_FLAT;
-               num_osd_ops = 1; /* truncate/delete */
+               if (obj_req->num_img_extents)
+                       num_osd_ops = 2; /* create + truncate */
+               else
+                       num_osd_ops = 1; /* delete */
        } else {
                if (obj_req->num_img_extents) {
                        obj_req->write_state = RBD_OBJ_WRITE_GUARD;