Commit b790b586 authored by Artem Kuzmitskiy's avatar Artem Kuzmitskiy Committed by Pavel Emelyanov

Add restoring of 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: 's avatarArtem Kuzmitskiy <artem.kuzmitskiy@lge.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 79fd764a
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#define USK_EXTERN (1 << 0) #define USK_EXTERN (1 << 0)
#define USK_SERVICE (1 << 1) #define USK_SERVICE (1 << 1)
#define USK_CALLBACK (1 << 2) #define USK_CALLBACK (1 << 2)
#define USK_INHERIT (1 << 3)
/* /*
* VMA_AREA status: * VMA_AREA status:
......
...@@ -160,7 +160,6 @@ static bool unix_sk_exception_lookup_id(ino_t ino) ...@@ -160,7 +160,6 @@ static bool unix_sk_exception_lookup_id(ino_t ino)
return ret; return ret;
} }
static int write_unix_entry(struct unix_sk_desc *sk) static int write_unix_entry(struct unix_sk_desc *sk)
{ {
int ret; int ret;
...@@ -843,16 +842,19 @@ static int post_open_unix_sk(struct file_desc *d, int fd) ...@@ -843,16 +842,19 @@ static int post_open_unix_sk(struct file_desc *d, int fd)
if (ui->ue->uflags & USK_CALLBACK) if (ui->ue->uflags & USK_CALLBACK)
return 0; return 0;
pr_info("\tConnect %#x to %#x\n", ui->ue->ino, peer->ue->ino);
/* Skip external sockets */ /* Skip external sockets */
if (!list_empty(&peer->d.fd_info_head)) if (!list_empty(&peer->d.fd_info_head))
futex_wait_while(&peer->prepared, 0); futex_wait_while(&peer->prepared, 0);
if (ui->ue->uflags & USK_INHERIT)
return 0;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
memcpy(&addr.sun_path, peer->name, peer->ue->name.len); memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
pr_info("\tConnect %#x to %#x\n", ui->ue->ino, peer->ue->ino);
if (prep_unix_sk_cwd(peer)) if (prep_unix_sk_cwd(peer))
return -1; return -1;
...@@ -1139,7 +1141,13 @@ static int open_unix_sk(struct file_desc *d) ...@@ -1139,7 +1141,13 @@ static int open_unix_sk(struct file_desc *d)
struct unix_sk_info *ui; struct unix_sk_info *ui;
ui = container_of(d, struct unix_sk_info, d); 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); return open_unixsk_pair_master(ui);
else if (ui->flags & USK_PAIR_SLAVE) else if (ui->flags & USK_PAIR_SLAVE)
return open_unixsk_pair_slave(ui); return open_unixsk_pair_slave(ui);
...@@ -1147,11 +1155,27 @@ static int open_unix_sk(struct file_desc *d) ...@@ -1147,11 +1155,27 @@ static int open_unix_sk(struct file_desc *d)
return open_unixsk_standalone(ui); 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 = { static struct file_desc_ops unix_desc_ops = {
.type = FD_TYPES__UNIXSK, .type = FD_TYPES__UNIXSK,
.open = open_unix_sk, .open = open_unix_sk,
.post_open = post_open_unix_sk, .post_open = post_open_unix_sk,
.want_transport = unixsk_should_open_transport, .want_transport = unixsk_should_open_transport,
.name = socket_d_name,
}; };
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment