From: Xiubo Li via B4 Relay <devnull+xiubo.li.clyso.com@kernel.org>
To: Ilya Dryomov <idryomov@gmail.com>,
Alex Markuze <amarkuze@redhat.com>,
Viacheslav Dubeyko <slava@dubeyko.com>
Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
Xiubo Li <xiubo.li@clyso.com>
Subject: [PATCH 1/2] libceph: add the CMPEXT OSD op
Date: Fri, 04 Dec 2026 01:22:11 +0100 [thread overview]
Message-ID: <20261204-ceph-mmap-no-overwrite-v1-1-323689b39a29@clyso.com> (raw)
In-Reply-To: <20261204-ceph-mmap-no-overwrite-v1-0-323689b39a29@clyso.com>
From: Xiubo Li <xiubo.li@clyso.com>
CMPEXT compares an extent of an object with the data it carries and
fails, with -MAX_ERRNO - <offset of the first mismatch>, if they differ.
Bytes beyond the end of the object compare as zeros. Placed before a
WRITE in the same request, it makes that write conditional: the OSD
applies the request as a whole or not at all.
Add the op code, and let osd_req_op_extent_init() set it up as an
extent op whose data goes out with the request, like a WRITE.
Signed-off-by: Xiubo Li <xiubo.li@clyso.com>
---
include/linux/ceph/rados.h | 1 +
net/ceph/osd_client.c | 10 ++++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/include/linux/ceph/rados.h b/include/linux/ceph/rados.h
index 5b5c33845301..697e98270108 100644
--- a/include/linux/ceph/rados.h
+++ b/include/linux/ceph/rados.h
@@ -268,6 +268,7 @@ extern const char *ceph_osd_state_name(int s);
f(UNDIRTY, __CEPH_OSD_OP(WR, DATA, 28), "undirty") \
f(ISDIRTY, __CEPH_OSD_OP(RD, DATA, 29), "isdirty") \
f(COPY_GET, __CEPH_OSD_OP(RD, DATA, 30), "copy-get") \
+ f(CMPEXT, __CEPH_OSD_OP(RD, DATA, 32), "cmpext") \
f(CACHE_FLUSH, __CEPH_OSD_OP(CACHE, DATA, 31), "cache-flush") \
f(CACHE_EVICT, __CEPH_OSD_OP(CACHE, DATA, 32), "cache-evict") \
f(CACHE_TRY_FLUSH, __CEPH_OSD_OP(CACHE, DATA, 33), "cache-try-flush") \
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 22a793a4bdc8..ffbb0adb8924 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -383,6 +383,7 @@ static void osd_req_op_data_release(struct ceph_osd_request *osd_req,
case CEPH_OSD_OP_SPARSE_READ:
case CEPH_OSD_OP_WRITE:
case CEPH_OSD_OP_WRITEFULL:
+ case CEPH_OSD_OP_CMPEXT:
kfree(op->extent.sparse_ext);
ceph_osd_data_release(&op->extent.osd_data);
break;
@@ -665,6 +666,7 @@ static void get_num_data_items(struct ceph_osd_request *req,
/* request */
case CEPH_OSD_OP_WRITE:
case CEPH_OSD_OP_WRITEFULL:
+ case CEPH_OSD_OP_CMPEXT:
case CEPH_OSD_OP_SETXATTR:
case CEPH_OSD_OP_CMPXATTR:
case CEPH_OSD_OP_NOTIFY_ACK:
@@ -745,13 +747,15 @@ void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
opcode != CEPH_OSD_OP_WRITEFULL && opcode != CEPH_OSD_OP_ZERO &&
- opcode != CEPH_OSD_OP_TRUNCATE && opcode != CEPH_OSD_OP_SPARSE_READ);
+ opcode != CEPH_OSD_OP_TRUNCATE && opcode != CEPH_OSD_OP_SPARSE_READ &&
+ opcode != CEPH_OSD_OP_CMPEXT);
op->extent.offset = offset;
op->extent.length = length;
op->extent.truncate_size = truncate_size;
op->extent.truncate_seq = truncate_seq;
- if (opcode == CEPH_OSD_OP_WRITE || opcode == CEPH_OSD_OP_WRITEFULL)
+ if (opcode == CEPH_OSD_OP_WRITE || opcode == CEPH_OSD_OP_WRITEFULL ||
+ opcode == CEPH_OSD_OP_CMPEXT)
payload_len += length;
op->indata_len = payload_len;
@@ -977,6 +981,7 @@ static u32 osd_req_encode_op(struct ceph_osd_op *dst,
case CEPH_OSD_OP_WRITEFULL:
case CEPH_OSD_OP_ZERO:
case CEPH_OSD_OP_TRUNCATE:
+ case CEPH_OSD_OP_CMPEXT:
dst->extent.offset = cpu_to_le64(src->extent.offset);
dst->extent.length = cpu_to_le64(src->extent.length);
dst->extent.truncate_size =
@@ -2057,6 +2062,7 @@ static void setup_request_data(struct ceph_osd_request *req)
/* request */
case CEPH_OSD_OP_WRITE:
case CEPH_OSD_OP_WRITEFULL:
+ case CEPH_OSD_OP_CMPEXT:
WARN_ON(op->indata_len != op->extent.length);
ceph_osdc_msg_data_add(request_msg,
&op->extent.osd_data);
--
2.53.0
next prev parent reply other threads:[~2026-12-04 0:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:22 [PATCH 0/2] ceph: don't let a mapped write overwrite other clients' writes Xiubo Li via B4 Relay
2026-12-04 0:22 ` Xiubo Li via B4 Relay [this message]
2026-12-04 0:22 ` [PATCH 2/2] " Xiubo Li via B4 Relay
2026-12-05 9:55 ` kernel test robot
2026-12-05 10:55 ` Xiubo Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204-ceph-mmap-no-overwrite-v1-1-323689b39a29@clyso.com \
--to=devnull+xiubo.li.clyso.com@kernel.org \
--cc=amarkuze@redhat.com \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=xiubo.li@clyso.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®