[6/6] files: Move make_gen_id into separate kcmp_fd_make_gen_id helper

Submitted by Cyrill Gorcunov on April 3, 2018, 5:46 p.m.

Details

Message ID 20180403174650.30628-7-gorcunov@gmail.com
State Rejected
Series "Preparatory patches for handling duped tfd on epoll"
Headers show

Commit Message

Cyrill Gorcunov April 3, 2018, 5:46 p.m.
We will need it for epoll targets.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/files.c            | 17 +++--------------
 criu/include/file-ids.h | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/files.c b/criu/files.c
index 8c83d41f05f3..8055614b4a3a 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -307,26 +307,15 @@  static int fixup_overlayfs(struct fd_parms *p, struct fd_link *link)
 	return 0;
 }
 
-/*
- * The gen_id thing is used to optimize the comparison of shared files.
- * If two files have different gen_ids, then they are different for sure.
- * If it matches, we don't know it and have to call sys_kcmp().
- *
- * The kcmp-ids.c engine does this trick, see comments in it for more info.
- */
-
-static u32 make_gen_id(const struct fd_parms *p)
-{
-	return ((u32)p->stat.st_dev) ^ ((u32)p->stat.st_ino) ^ ((u32)p->pos);
-}
-
 int do_dump_gen_file(struct fd_parms *p, int lfd,
 		const struct fdtype_ops *ops, FdinfoEntry *e)
 {
 	int ret = -1;
 
 	e->type	= ops->type;
-	e->id	= make_gen_id(p);
+	e->id	= kcmp_fd_make_gen_id((uint32_t)p->stat.st_dev,
+				      (uint32_t)p->stat.st_ino,
+				      (uint32_t)p->pos);
 	e->fd	= p->fd;
 	e->flags = p->fd_flags;
 
diff --git a/criu/include/file-ids.h b/criu/include/file-ids.h
index 845cfaa9f9db..e796f403a57e 100644
--- a/criu/include/file-ids.h
+++ b/criu/include/file-ids.h
@@ -1,6 +1,8 @@ 
 #ifndef __CR_FILE_IDS_H__
 #define __CR_FILE_IDS_H__
 
+#include <stdint.h>
+
 #include "common/compiler.h"
 #include "rbtree.h"
 
@@ -16,4 +18,16 @@  struct fd_parms;
 extern int fd_id_generate(pid_t pid, FdinfoEntry *fe, struct fd_parms *p);
 extern int fd_id_generate_special(struct fd_parms *p, u32 *id);
 
+/*
+ * The gen_id thing is used to optimize the comparison of shared files.
+ * If two files have different gen_ids, then they are different for sure.
+ * If it matches, we don't know it and have to call sys_kcmp().
+ *
+ * The kcmp-ids.c engine does this trick, see comments in it for more info.
+ */
+static inline uint32_t kcmp_fd_make_gen_id(uint32_t st_dev, uint32_t st_ino, uint32_t f_pos)
+{
+	return st_dev ^ st_ino ^ f_pos;
+}
+
 #endif /* __CR_FILE_IDS_H__ */