From c637b2cdf77a7ddefdc367164454502bbb3207ec Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 3 Apr 2018 11:53:09 -0400 Subject: [PATCH] librbd: create+truncate for whole-object layered discards 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 -- parent blocks are still seen afterwards. A non-exclusive create on an existing object is also a no-op, so the fix is to do a compound create+truncate instead. (derived from commit 0514480b16b0a1e76a9ba31cc3ba58a32b7bee18) Signed-off-by: Jason Dillaman --- src/librbd/AioObjectRequest.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librbd/AioObjectRequest.h b/src/librbd/AioObjectRequest.h index d33d3f4cdf8e8..13b0a1fa6ba75 100644 --- a/src/librbd/AioObjectRequest.h +++ b/src/librbd/AioObjectRequest.h @@ -294,6 +294,7 @@ public: protected: virtual void add_write_ops(librados::ObjectWriteOperation *wr) { if (has_parent()) { + wr->create(false); wr->truncate(0); } else { wr->remove(); @@ -302,7 +303,7 @@ protected: virtual const char* get_write_type() const { if (has_parent()) { - return "remove (trunc)"; + return "remove (create+trunc)"; } return "remove"; } -- 2.39.5