[CRIU] [PATCH v2 3/8] ipc: add new flag for preset shmem id on creation

Stanislav Kinsbursky skinsbursky at parallels.com
Wed Feb 8 08:18:13 EST 2012


This patch is required for checkpoint/restore of IPC shared memory segments.

The patch makes IPC_PRESET flag enterpreted as an order to use passed key as
the id of new segment to create on sys_shmget() call. IOW, kernel will try
allocate new segment in specified slot. If slot is not emply, them -EEXIST
returned.
Note: key and id will be identical for such segment after creation.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at parallels.com>

---
 ipc/shm.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index b76be5b..3aa21a7 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -467,6 +467,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
 		return -ENOMEM;
 
 	shp->shm_perm.key = key;
+	shp->shm_perm.id = 0;
 	shp->shm_perm.mode = (shmflg & S_IRWXUGO);
 	shp->mlock_user = NULL;
 
@@ -498,6 +499,11 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
 	if (IS_ERR(file))
 		goto no_file;
 
+	if (shmflg & IPC_PRESET) {
+		shp->shm_perm.id = key;
+		shp->shm_perm.seq = (unsigned long) key / SEQ_MULTIPLIER;
+	}
+
 	id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
 	if (id < 0) {
 		error = id;



More information about the CRIU mailing list