[CRIU] [PATCH 05/19] unix: image -- Move uflags into enum

Cyrill Gorcunov gorcunov at gmail.com
Fri Sep 14 17:08:28 MSK 2018


This values are part of abi, so must be set in image file.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/sk-unix.c       | 31 +++++++++++++------------------
 images/sk-unix.proto | 10 ++++++++++
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 6f79b182b0c3..78040a5c10fe 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -54,11 +54,6 @@
  * as "external" and require the --ext-unix-sk option.
  */
 
-#define USK_EXTERN	(1 << 0)
-#define USK_SERVICE	(1 << 1)
-#define USK_CALLBACK	(1 << 2)
-#define USK_INHERIT	(1 << 3)
-
 #define FAKE_INO	0
 
 struct unix_sk_desc {
@@ -403,7 +398,7 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p)
 	if (unlikely(ue->peer == service_sk_ino)) {
 		ue->state = TCP_CLOSE;
 		ue->peer = 0;
-		ue->uflags |= USK_SERVICE;
+		ue->uflags |= UNIX_UFLAGS__SERVICE;
 	}
 
 	if (sk->namelen && *sk->name) {
@@ -538,7 +533,7 @@ static int dump_one_unix_fd(int lfd, uint32_t id, const struct fd_parms *p)
 	 *  Postpone writing the entry if a peer isn't found yet.
 	 *  It's required, because we may need to modify the entry.
 	 *  For example, if a socket is external and is dumped by
-	 *  a callback, the USK_CALLBACK flag must be set.
+	 *  a callback, the UNIX_UFLAGS__CALLBACK flag must be set.
 	 */
 	if (list_empty(&sk->peer_node) && write_unix_entry(sk))
 		return -1;
@@ -815,7 +810,7 @@ static int __dump_external_socket(struct unix_sk_desc *sk,
 		return -1;
 
 	if (ret == 0) {
-		sk->ue->uflags |= USK_CALLBACK;
+		sk->ue->uflags |= UNIX_UFLAGS__CALLBACK;
 		return 0;
 	}
 
@@ -892,7 +887,7 @@ int fix_external_unix_sockets(void)
 		e.state		= TCP_LISTEN;
 		e.name.data	= (void *)sk->name;
 		e.name.len	= (size_t)sk->namelen;
-		e.uflags	= USK_EXTERN;
+		e.uflags	= UNIX_UFLAGS__EXTERN;
 		e.peer		= 0;
 		e.fown		= &fown;
 		e.opts		= &skopts;
@@ -1288,7 +1283,7 @@ static int post_open_standalone(struct file_desc *d, int fd)
 
 	ui = container_of(d, struct unix_sk_info, d);
 	BUG_ON((ui->flags & (USK_PAIR_MASTER | USK_PAIR_SLAVE)) ||
-			(ui->ue->uflags & (USK_CALLBACK | USK_INHERIT)));
+			(ui->ue->uflags & (UNIX_UFLAGS__CALLBACK | UNIX_UFLAGS__INHERIT)));
 
 	if (chk_restored_scms(ui))
 		return 1;
@@ -1356,7 +1351,7 @@ static int post_open_standalone(struct file_desc *d, int fd)
 
 restore_queue:
 	if (peer->queuer == ui &&
-	    !(peer->ue->uflags & USK_EXTERN) &&
+	    !(peer->ue->uflags & UNIX_UFLAGS__EXTERN) &&
 	    restore_unix_queue(fd, peer))
 		return -1;
 restore_sk_common:
@@ -1805,7 +1800,7 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd)
 		return post_open_standalone(&ui->d, fle->fe->fd);
 
 	/* Fake socket will be restored by its peer */
-	if (!(ui->ue->uflags & USK_EXTERN) && ui->ue->ino == FAKE_INO)
+	if (!(ui->ue->uflags & UNIX_UFLAGS__EXTERN) && ui->ue->ino == FAKE_INO)
 		return 1;
 
 	if (set_netns(ui->ue->ns_id))
@@ -1816,7 +1811,7 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd)
 	 * If so, put response, that dumping and restoring
 	 * was successful.
 	 */
-	if (ui->ue->uflags & USK_SERVICE) {
+	if (ui->ue->uflags & UNIX_UFLAGS__SERVICE) {
 		int sks[2];
 
 		if (socketpair(PF_UNIX, ui->ue->type, 0, sks)) {
@@ -1886,7 +1881,7 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd)
 
 		sk = sks[0];
 	} else {
-		if (ui->ue->uflags & USK_CALLBACK) {
+		if (ui->ue->uflags & UNIX_UFLAGS__CALLBACK) {
 			sk = run_plugins(RESTORE_UNIX_SK, ui->ue->ino);
 			if (sk >= 0)
 				goto out;
@@ -1896,7 +1891,7 @@ static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd)
 		 * Connect to external sockets requires
 		 * special option to be passed.
 		 */
-		if (ui->peer && (ui->peer->ue->uflags & USK_EXTERN) &&
+		if (ui->peer && (ui->peer->ue->uflags & UNIX_UFLAGS__EXTERN) &&
 				!(opts.ext_unix_sk)) {
 			pr_err("External socket found in image. "
 					"Consider using the --" USK_EXT_PARAM
@@ -1952,7 +1947,7 @@ static int open_unix_sk(struct file_desc *d, int *new_fd)
 	ui = container_of(d, struct unix_sk_info, d);
 
 	if (inherited_fd(d, new_fd)) {
-		ui->ue->uflags |= USK_INHERIT;
+		ui->ue->uflags |= UNIX_UFLAGS__INHERIT;
 		ret = *new_fd >= 0 ? 0 : -1;
 	} else if (ui->flags & USK_PAIR_MASTER)
 		ret = open_unixsk_pair_master(ui, new_fd);
@@ -1993,7 +1988,7 @@ static int unlink_sk(struct unix_sk_info *ui)
 {
 	int ret = 0, cwd_fd = -1, root_fd = -1, ns_fd = -1;
 
-	if (!ui->name || ui->name[0] == '\0' || (ui->ue->uflags & USK_EXTERN))
+	if (!ui->name || ui->name[0] == '\0' || (ui->ue->uflags & UNIX_UFLAGS__EXTERN))
 		return 0;
 
 	if (prep_unix_sk_cwd(ui, &cwd_fd, &root_fd, NULL))
@@ -2229,7 +2224,7 @@ int add_fake_unix_queuers(void)
 	struct unix_sk_info *ui;
 
 	list_for_each_entry(ui, &unix_sockets, list) {
-		if ((ui->ue->uflags & (USK_EXTERN | USK_CALLBACK)) || ui->queuer)
+		if ((ui->ue->uflags & (UNIX_UFLAGS__EXTERN | UNIX_UFLAGS__CALLBACK)) || ui->queuer)
 			continue;
 		if (!(ui->ue->state == TCP_ESTABLISHED && !ui->peer) &&
 		     ui->ue->type != SOCK_DGRAM)
diff --git a/images/sk-unix.proto b/images/sk-unix.proto
index fc033997a8a8..b7173eac9119 100644
--- a/images/sk-unix.proto
+++ b/images/sk-unix.proto
@@ -10,6 +10,16 @@ message file_perms_entry {
 	required uint32			gid		= 3;
 }
 
+/*
+ * Bitmask for unix_sk_entry::uflags
+ */
+enum unix_uflags {
+	EXTERN		= 1;
+	SERVICE		= 2;
+	CALLBACK	= 4;
+	INHERIT		= 8;
+}
+
 message unix_sk_entry {
 	/*
 	 * Few words about why we need both -- id and ino.
-- 
2.17.1



More information about the CRIU mailing list