IPC: message queue stealing feature introduced
PATCH 1/1 IPC: message queue stealing feature introduced
This patch is required for checkpoint/restore in userspace project. C/r requires some way to get all pending IPC messages without deleting them for the queue (checkpoint can fail and in this case tasks will be resumed, so queue have to be valid).
To achive this, new operation flag MSG_STEAL for sys_msgrcv() system call introduced.
If this flag is set, then passed struct msgbuf pointer will be used for storing array of structures:
struct msgbuf_a {
long mtype; /* type of message */ size_t msize; /* size of message */ char mtext[0]; /* message text */
};
each of which will be followed by corresponding message data.
--- include/linux/msg.h | 8 ++++++++ ipc/msg.c | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-)
include/linux/msg.h +8 -0
@@ -11,6 +11,7 @@/* msgrcv options */ #define MSG_NOERROR 010000/* no error if message is too big */ #define MSG_EXCEPT 020000/* recv any msg except of specified type.*/ +#define MSG_STEAL 040000/* copy (not remove) all queue messages */ /* Obsolete, used only for backwards compatibility and libc5 compiles */ struct msqid_ds {
@@ -38,6 +39,13 @@ struct msgbuf {char mtext[1 ];/* message text */ }; +/* message buffer for msgrcv in case of array calls */ +struct msgbuf_a { +long mtype;/* type of message */ +size_t msize;/* size of message */ +char mtext[0 ];/* message text */ +}; +/* buffer for msgctl calls IPC_INFO, MSG_INFO */ struct msginfo {int msgpool;
ipc/msg.c +38 -5
80 lines not on this page · raw message
Le mercredi 15 février 2012 à 13:08 +0400, Stanislav Kinsbursky a écrit :
Quoted 9 lines
This patch is required for checkpoint/restore in userspace project. C/r requires some way to get all pending IPC messages without deleting them for the queue (checkpoint can fail and in this case tasks will be resumed, so queue have to be valid).
To achive this, new operation flagMSG_STEALforsys_msgrcv()system call introduced.
If this flag is set, then passed struct msgbuf pointer will be used for storing array of structures:
Quoted 6 lines
struct
msgbuf_a{long mtype; /* type of message */ size_t msize; /* size of message */ char mtext[0]; /* message text */};
This structure is not 32/64 bit safe and will need compat tricks.
+ ret = do_steal_msg(mtext, arrsz, msg);
+ if (ret < 0) {
+ msg = ERR_PTR(ret);
+ goto out_unlock;
+ } + mtext += ret + sizeof(struct msgbuf_a); + arrsz -= ret + sizeof(struct msgbuf_a);
I cant see where alignement requirements are met.
(ret should be rounded up to a multiple of alignof(struct msgbuf_a)
15.02.2012 13:40, Eric Dumazet пишет:
Quoted 28 lines
Le mercredi 15 février 2012 à 13:08 +0400, Stanislav Kinsbursky a écrit :
Quoted 9 lines
This patch is required for checkpoint/restore in userspace project. C/r requires some way to get all pending IPC messages without deleting them for the queue (checkpoint can fail and in this case tasks will be resumed, so queue have to be valid).
To achive this, new operation flagMSG_STEALforsys_msgrcv()system call introduced.
If this flag is set, then passed struct msgbuf pointer will be used for storing array of structures:Quoted 6 lines
struct
msgbuf_a{long mtype; /* type of message */ size_t msize; /* size of message */ char mtext[0]; /* message text */};
This structure is not 32/64 bit safe and will need compat tricks.
ipc/msg.c +7
-0+ ret =do_steal_msg (mtext, arrsz, msg); +if (ret<0 ) { + msg =ERR_PTR (ret); + goto out_unlock; + } + mtext += ret +sizeof (struct msgbuf_a ); + arrsz -= ret +sizeof (struct msgbuf_a );
Quoted 4 lines
I cant see where alignement requirements are met.
(ret should be rounded up to a multiple of
alignof(struct msgbuf_a)
Thanks for reply, Eric.
Will fix and resend soon.
Signature · 2 lines
Best regards, Stanislav Kinsbursky