[CRIU] [PATCH] ipc: rename struct ipc_seg

Kinsbursky Stanislav skinsbursky at openvz.org
Fri Feb 10 05:15:46 EST 2012


This name for the structure is obfuscating, because structure will be used
also for queues and semaphores sets migration.
This patch renames this structure int ipc_obj_entry. It also renames all
related functions and prints to reflect structure name change.

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

---
 include/image.h |    4 ++--
 ipc_ns.c        |   55 ++++++++++++++++++++++++++++---------------------------
 2 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/include/image.h b/include/image.h
index 01a3b86..9db94c5 100644
--- a/include/image.h
+++ b/include/image.h
@@ -126,7 +126,7 @@ struct ipc_var_entry {
 	u32	mq_msgsize_max;
 } __packed;
 
-struct ipc_seg {
+struct ipc_obj_entry {
 	u32	key;
 	u32	uid;
 	u32	gid;
@@ -138,7 +138,7 @@ struct ipc_seg {
 } __packed;
 
 struct ipc_shm_entry {
-	struct ipc_seg seg;
+	struct ipc_obj_entry obj;
 	u64	size;
 } __packed;
 
diff --git a/ipc_ns.c b/ipc_ns.c
index cb40b9a..339c770 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -27,28 +27,29 @@
 #define SHM_SET			15
 #endif
 
-static void print_ipc_seg(const struct ipc_seg *seg)
+static void print_ipc_obj_entry(const struct ipc_obj_entry *obj)
 {
-	pr_info("id: %-10d key: 0x%08x ", seg->id, seg->key);
-	pr_info("uid: %-10d gid: %-10d ", seg->uid, seg->gid);
-	pr_info("cuid: %-10d cgid: %-10d ", seg->cuid, seg->cgid);
-	pr_info("mode: %-10o ", seg->mode);
+	pr_info("id: %-10d key: 0x%08x ", obj->id, obj->key);
+	pr_info("uid: %-10d gid: %-10d ", obj->uid, obj->gid);
+	pr_info("cuid: %-10d cgid: %-10d ", obj->cuid, obj->cgid);
+	pr_info("mode: %-10o ", obj->mode);
 }
 
-static void fill_ipc_seg(int id, struct ipc_seg *seg, const struct ipc_perm *ipcp)
+static void fill_ipc_obj(int id, struct ipc_obj_entry *obj,
+				const struct ipc_perm *ipcp)
 {
-	seg->id = id;
-	seg->key = ipcp->KEY;
-	seg->uid = ipcp->uid;
-	seg->gid = ipcp->gid;
-	seg->cuid = ipcp->cuid;
-	seg->cgid = ipcp->cgid;
-	seg->mode = ipcp->mode;
+	obj->id = id;
+	obj->key = ipcp->KEY;
+	obj->uid = ipcp->uid;
+	obj->gid = ipcp->gid;
+	obj->cuid = ipcp->cuid;
+	obj->cgid = ipcp->cgid;
+	obj->mode = ipcp->mode;
 }
 
 static void print_ipc_shm(const struct ipc_shm_entry *shm)
 {
-	print_ipc_seg(&shm->seg);
+	print_ipc_obj_entry(&shm->obj);
 	pr_info("size: %-10lu\n", shm->size);
 }
 
@@ -119,7 +120,7 @@ static int dump_ipc_shm_pages(int fd, const struct ipc_shm_entry *shm)
 	void *data;
 	int ret;
 
-	data = shmat(shm->seg.id, NULL, SHM_RDONLY);
+	data = shmat(shm->obj.id, NULL, SHM_RDONLY);
 	if (data == (void *)-1) {
 		pr_perror("Failed to attach IPC shared memory");
 		return -errno;
@@ -136,18 +137,18 @@ static int dump_ipc_shm_pages(int fd, const struct ipc_shm_entry *shm)
 	return 0;
 }
 
-static int dump_ipc_shm_seg(int fd, int id, const struct shmid_ds *ds)
+static int dump_ipc_shm_obj(int fd, int id, const struct shmid_ds *ds)
 {
 	struct ipc_shm_entry shm;
 	int ret;
 
-	fill_ipc_seg(id, &shm.seg, &ds->shm_perm);
+	fill_ipc_obj(id, &shm.obj, &ds->shm_perm);
 	shm.size = ds->shm_segsz;
 	print_ipc_shm(&shm);
 
 	ret = write_img(fd, &shm);
 	if (ret < 0) {
-		pr_err("Failed to write IPC shared memory segment\n");
+		pr_err("Failed to write IPC shared memory object\n");
 		return ret;
 	}
 	return dump_ipc_shm_pages(fd, &shm);
@@ -183,7 +184,7 @@ static int dump_ipc_shm(int fd)
 			return -EFAULT;
 		}
 
-		ret = dump_ipc_shm_seg(fd, id, &ds);
+		ret = dump_ipc_shm_obj(fd, id, &ds);
 		if (ret < 0)
 			return ret;
 		slot++;
@@ -303,7 +304,7 @@ static int prepare_ipc_shm_pages(int fd, const struct ipc_shm_entry *shm)
 	int ret;
 	void *data;
 
-	data = shmat(shm->seg.id, NULL, 0);
+	data = shmat(shm->obj.id, NULL, 0);
 	if (data == (void *)-1) {
 		pr_perror("Failed to attach IPC shared memory");
 		return -errno;
@@ -320,21 +321,21 @@ static int prepare_ipc_shm_pages(int fd, const struct ipc_shm_entry *shm)
 	return 0;
 }
 
-static int prepare_ipc_shm_seg(int fd, const struct ipc_shm_entry *shm)
+static int prepare_ipc_shm_obj(int fd, const struct ipc_shm_entry *shm)
 {
 	int ret, id;
 	struct shmid_ds ds;
 
-	id = shmget(shm->seg.id, shm->size,
-		     shm->seg.mode | IPC_CREAT | IPC_EXCL | IPC_PRESET);
+	id = shmget(shm->obj.id, shm->size,
+		     shm->obj.mode | IPC_CREAT | IPC_EXCL | IPC_PRESET);
 	if (id == -1) {
 		pr_perror("Failed to create shm segment");
 		return -errno;
 	}
 
-	if (id != shm->seg.id) {
+	if (id != shm->obj.id) {
 		pr_err("Failed to preset id (%d instead of %d)\n",
-							id, shm->seg.id);
+							id, shm->obj.id);
 		return -EFAULT;
 	}
 
@@ -344,7 +345,7 @@ static int prepare_ipc_shm_seg(int fd, const struct ipc_shm_entry *shm)
 		return -errno;
 	}
 
-	ds.shm_perm.KEY = shm->seg.key;
+	ds.shm_perm.KEY = shm->obj.key;
 	ret = shmctl(id, SHM_SET, &ds);
 	if (ret < 0) {
 		pr_perror("Failed to update shm key");
@@ -379,7 +380,7 @@ static int prepare_ipc_shm(int pid)
 
 		print_ipc_shm(&shm);
 
-		ret = prepare_ipc_shm_seg(fd, &shm);
+		ret = prepare_ipc_shm_obj(fd, &shm);
 		if (ret < 0) {
 			pr_err("Failed to prepare shm segment\n");
 			return ret;



More information about the CRIU mailing list