[CRIU] [PATCH 2/3] Add restore for unnamed unix sockets
artem.kuzmitskiy at lge.com
artem.kuzmitskiy at lge.com
Mon Jul 27 09:20:30 PDT 2015
From: Artem Kuzmitskiy <artem.kuzmitskiy at lge.com>
Subject: [PATCH 2/3] Add restore for unnamed unix sockets
Added functionality for restoring unnamed unix sockets
using already implemented feature - inherit fd and using same command line
option.
Usage example:
criu restore -d -D images -o restore.log --pidfile restore.pid -v4 \
-x --inherit-fd fd[3]:socket:[9677263]
Signed-off-by: Artem Kuzmitskiy <artem.kuzmitskiy at lge.com>
---
files.c | 19 +++++++++++++++----
include/files.h | 2 +-
include/image.h | 1 +
sk-unix.c | 47 +++++++++++++++++++++++++++++++++++------------
4 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/files.c b/files.c
index 613289a..887b55c 100644
--- a/files.c
+++ b/files.c
@@ -1404,6 +1404,19 @@ static int inherit_fd_lookup_id(char *id)
return ret;
}
+bool inherit_fd_lookup_desc(struct file_desc *d)
+{
+ char buf[32], *id_str;
+
+ if (!d->ops->name)
+ return -1;
+
+ id_str = d->ops->name(d, buf, sizeof(buf));
+ int ret = inherit_fd_lookup_id(id_str);
+
+ return (ret < 0 ? false : true);
+}
+
bool inherited_fd(struct file_desc *d, int *fd_p)
{
char buf[32], *id_str;
@@ -1421,12 +1434,10 @@ bool inherited_fd(struct file_desc *d, int *fd_p)
return true;
*fd_p = dup(i_fd);
- if (*fd_p < 0) {
+ if (*fd_p < 0)
pr_perror("Inherit fd DUP failed");
- return false;
- }
else
- pr_info("File %s will be restored from fd %d duped "
+ pr_info("File %s will be restored from fd %d dumped "
"from inherit fd %d\n", id_str, *fd_p, i_fd);
return true;
}
diff --git a/include/files.h b/include/files.h
index db7e108..25d69ad 100644
--- a/include/files.h
+++ b/include/files.h
@@ -174,7 +174,7 @@ extern int inherit_fd_add(int fd, char *key);
extern void inherit_fd_log(void);
extern int inherit_fd_resolve_clash(int fd);
extern int inherit_fd_fini(void);
-
+extern bool inherit_fd_lookup_desc(struct file_desc *);
extern bool inherited_fd(struct file_desc *, int *fdp);
#endif /* __CR_FILES_H__ */
diff --git a/include/image.h b/include/image.h
index c13ead0..305febf 100644
--- a/include/image.h
+++ b/include/image.h
@@ -41,6 +41,7 @@
#define USK_EXTERN (1 << 0)
#define USK_SERVICE (1 << 1)
#define USK_CALLBACK (1 << 2)
+#define USK_INHERIT (1 << 3)
/*
* VMA_AREA status:
diff --git a/sk-unix.c b/sk-unix.c
index 33d83e6..a7cdd85 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -150,7 +150,6 @@ static bool unix_sk_exception_lookup_id(ino_t ino)
return ret;
}
-
static int write_unix_entry(struct unix_sk_desc *sk)
{
int ret;
@@ -718,21 +717,23 @@ static int post_open_unix_sk(struct file_desc *d, int fd)
if (ui->ue->uflags & USK_CALLBACK)
return 0;
- pr_info("\tConnect %#x to %#x\n", ui->ue->ino, peer->ue->ino);
-
/* Skip external sockets */
if (!list_empty(&peer->d.fd_info_head))
futex_wait_while(&peer->prepared, 0);
- memset(&addr, 0, sizeof(addr));
- addr.sun_family = AF_UNIX;
- memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
+ if (!(ui->ue->uflags & USK_INHERIT)) {
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
- if (connect(fd, (struct sockaddr *)&addr,
- sizeof(addr.sun_family) +
- peer->ue->name.len) < 0) {
- pr_perror("Can't connect %#x socket", ui->ue->ino);
- return -1;
+ pr_info("\tConnect %#x to %#x\n", ui->ue->ino, peer->ue->ino);
+
+ if (connect(fd, (struct sockaddr *)&addr,
+ sizeof(addr.sun_family) +
+ peer->ue->name.len) < 0) {
+ pr_perror("Can't connect %#x socket", ui->ue->ino);
+ return -1;
+ }
}
if (restore_sk_queue(fd, peer->ue->id))
@@ -1008,7 +1009,13 @@ static int open_unix_sk(struct file_desc *d)
struct unix_sk_info *ui;
ui = container_of(d, struct unix_sk_info, d);
- if (ui->flags & USK_PAIR_MASTER)
+
+ int unixsk_fd = -1;
+
+ if (inherited_fd(d, &unixsk_fd)) {
+ ui->ue->uflags |= USK_INHERIT;
+ return unixsk_fd;
+ } else if (ui->flags & USK_PAIR_MASTER)
return open_unixsk_pair_master(ui);
else if (ui->flags & USK_PAIR_SLAVE)
return open_unixsk_pair_slave(ui);
@@ -1016,11 +1023,27 @@ static int open_unix_sk(struct file_desc *d)
return open_unixsk_standalone(ui);
}
+static char *socket_d_name(struct file_desc *d, char *buf, size_t s)
+{
+ struct unix_sk_info *ui;
+
+ ui = container_of(d, struct unix_sk_info, d);
+
+ if (snprintf(buf, s, "socket:[%d]", ui->ue->ino) >= s) {
+ pr_err("Not enough room for unixsk %d identifier string\n",
+ ui->ue->ino);
+ return NULL;
+ }
+
+ return buf;
+}
+
static struct file_desc_ops unix_desc_ops = {
.type = FD_TYPES__UNIXSK,
.open = open_unix_sk,
.post_open = post_open_unix_sk,
.want_transport = unixsk_should_open_transport,
+ .name = socket_d_name,
};
static int collect_one_unixsk(void *o, ProtobufCMessage *base)
--
2.1.4
Best regards,
Artem Kuzmitskiy
LG Russia R&D Lab, St.-Petersburg
Web Team Web 3 Part
Local phone 128
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20150727/384f7594/attachment-0001.html>
More information about the CRIU
mailing list