From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: manfred@colorfullife.com, viro@zeniv.linux.org.uk,
brauner@kernel.org, chuck.lever@oracle.com, jlayton@kernel.org,
rstoyanov@fedoraproject.org, ptikhomirov@virtuozzo.com,
Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
Subject: [RFC PATCH 1/3] mqueue: uapi: add struct mq_peek_attr and F_MQ_PEEK
Date: Thu, 26 Mar 2026 00:30:23 +0530 [thread overview]
Message-ID: <20260325190025.40312-2-ssrane_b23@ee.vjti.ac.in> (raw)
In-Reply-To: <20260325190025.40312-1-ssrane_b23@ee.vjti.ac.in>
Add the user-visible interface for non-destructive POSIX message queue
inspection via fcntl(2).
POSIX message queues have no way to inspect queued messages without
consuming them: mq_receive() always dequeues the message it returns.
This makes it impossible for checkpoint/restore tools such as CRIU to
save and replay message queue contents without destroying the queue
state in the process.
struct mq_peek_attr describes the request: the caller specifies an
index into the queue in receive order (0 = next message that
mq_receive() would return, i.e. highest priority, FIFO within same
priority) and a buffer to receive the payload. On return, msg_prio is
filled with the message priority and the return value is the number of
bytes copied.
F_MQ_PEEK = F_LINUX_SPECIFIC_BASE + 17 is the new fcntl command that
accepts a pointer to struct mq_peek_attr.
Link: https://github.com/checkpoint-restore/criu/issues/2285
Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
---
include/uapi/linux/fcntl.h | 6 ++++++
include/uapi/linux/mqueue.h | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h
index aadfbf6e0cb3..ea34f87de0fb 100644
--- a/include/uapi/linux/fcntl.h
+++ b/include/uapi/linux/fcntl.h
@@ -84,6 +84,12 @@
#define F_GETDELEG (F_LINUX_SPECIFIC_BASE + 15)
#define F_SETDELEG (F_LINUX_SPECIFIC_BASE + 16)
+/*
+ * Peek at a POSIX message queue message by index without consuming it.
+ * Argument is a pointer to struct mq_peek_attr (see <linux/mqueue.h>).
+ */
+#define F_MQ_PEEK (F_LINUX_SPECIFIC_BASE + 17)
+
/* Argument structure for F_GETDELEG and F_SETDELEG */
struct delegation {
__u32 d_flags; /* Must be 0 */
diff --git a/include/uapi/linux/mqueue.h b/include/uapi/linux/mqueue.h
index b516b66840ad..7133b84c70d1 100644
--- a/include/uapi/linux/mqueue.h
+++ b/include/uapi/linux/mqueue.h
@@ -53,4 +53,25 @@ struct mq_attr {
#define NOTIFY_COOKIE_LEN 32
+/*
+ * Argument structure for fcntl(F_MQ_PEEK).
+ *
+ * Peek at a POSIX message queue message by index without removing it.
+ * @offset: Index in receive order (0 = highest priority, next to dequeue).
+ * FIFO ordering is preserved within the same priority level.
+ * @msg_prio: Output: priority of the message at @offset.
+ * @buf_len: Size of the caller-provided buffer at @buf.
+ * @buf: Output: message payload is written here; truncated to @buf_len
+ * bytes if the message is larger.
+ *
+ * Returns the number of bytes copied on success, -ENOMSG if @offset is
+ * >= mq_curmsgs, or a negative error code on failure.
+ */
+struct mq_peek_attr {
+ __s32 offset;
+ __u32 msg_prio;
+ __kernel_size_t buf_len;
+ char __user *buf;
+};
+
#endif
--
2.34.1
next prev parent reply other threads:[~2026-03-25 19:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-25 19:00 [RFC PATCH 0/3] ipc/mqueue: add fcntl(F_MQ_PEEK) for non-destructive message inspection Shaurya Rane
2026-03-25 19:00 ` Shaurya Rane [this message]
2026-03-25 19:00 ` [RFC PATCH 2/3] msg: move struct msg_msgseg and DATALEN_* to include/linux/msg.h Shaurya Rane
2026-03-25 19:00 ` [RFC PATCH 3/3] ipc/mqueue: implement fcntl(F_MQ_PEEK) for non-destructive message inspection Shaurya Rane
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=20260325190025.40312-2-ssrane_b23@ee.vjti.ac.in \
--to=ssrane_b23@ee.vjti.ac.in \
--cc=brauner@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=ptikhomirov@virtuozzo.com \
--cc=rstoyanov@fedoraproject.org \
--cc=viro@zeniv.linux.org.uk \
/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