Commit b3867516 authored by Pavel Emelyanov's avatar Pavel Emelyanov

sockets: Rework unix sockets onto fdinfo scheme

This is a big change, yes. Dump unix sockets in the same manner
as all the other files are done now. A few notes however.

1. We explicitly drop names for connected stream sockets. This is
   done to avoid conflicts with names -- accepted sockets share their
   names with the listening parent. This can be done later by binding
   a socket to a name, them renaming it to some temporary uniq one
   and at the very very end renaming some back to original.

2. Interconnected sockets are restored via socketpair() call. This is
   correct, but names are dropped. Need to bind() sockets after this
   (yes, this can be done), but for this we need to implement the trick
   with renames described before.

3. FD for socket queues is constantly re-opened not to resolve fd
   conflicts. Need to use service fds engine for this later.

4. Some code cleanup is still required, yes (will follow shortly).
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 87d2ff5e
...@@ -290,11 +290,10 @@ static int prepare_shared(void) ...@@ -290,11 +290,10 @@ static int prepare_shared(void)
if (collect_inet_sockets()) if (collect_inet_sockets())
return -1; return -1;
list_for_each_entry(pi, &tasks, list) { if (collect_unix_sockets())
ret = collect_unix_sockets(pi->pid);
if (ret < 0)
return -1; return -1;
list_for_each_entry(pi, &tasks, list) {
ret = prepare_shmem_pid(pi->pid); ret = prepare_shmem_pid(pi->pid);
if (ret < 0) if (ret < 0)
break; break;
...@@ -305,6 +304,7 @@ static int prepare_shared(void) ...@@ -305,6 +304,7 @@ static int prepare_shared(void)
} }
mark_pipe_master(); mark_pipe_master();
ret = resolve_unix_peers();
if (!ret) { if (!ret) {
show_saved_shmems(); show_saved_shmems();
...@@ -507,9 +507,6 @@ static int restore_one_alive_task(int pid) ...@@ -507,9 +507,6 @@ static int restore_one_alive_task(int pid)
{ {
pr_info("%d: Restoring resources\n", pid); pr_info("%d: Restoring resources\n", pid);
if (prepare_sockets(pid))
return -1;
if (prepare_fds(pid)) if (prepare_fds(pid))
return -1; return -1;
......
...@@ -64,6 +64,7 @@ static char *fdtype2s(u8 type) ...@@ -64,6 +64,7 @@ static char *fdtype2s(u8 type)
[FDINFO_EXE] = "exe", [FDINFO_EXE] = "exe",
[FDINFO_INETSK] = "isk", [FDINFO_INETSK] = "isk",
[FDINFO_PIPE] = "pipe", [FDINFO_PIPE] = "pipe",
[FDINFO_UNIXSK] = "usk",
}; };
if (type > FDINFO_UND && type < FD_INFO_MAX) if (type > FDINFO_UND && type < FD_INFO_MAX)
......
...@@ -90,6 +90,8 @@ static struct list_head *find_fi_list(struct fdinfo_entry *fe) ...@@ -90,6 +90,8 @@ static struct list_head *find_fi_list(struct fdinfo_entry *fe)
return find_inetsk_fd(fe->id); return find_inetsk_fd(fe->id);
if (fe->type == FDINFO_PIPE) if (fe->type == FDINFO_PIPE)
return find_pipe_fd(fe->id); return find_pipe_fd(fe->id);
if (fe->type == FDINFO_UNIXSK)
return find_unixsk_fd(fe->id);
BUG_ON(1); BUG_ON(1);
return NULL; return NULL;
...@@ -296,6 +298,8 @@ static int should_open_transport(struct fdinfo_entry *fe, struct list_head *fd_l ...@@ -296,6 +298,8 @@ static int should_open_transport(struct fdinfo_entry *fe, struct list_head *fd_l
{ {
if (fe->type == FDINFO_PIPE) if (fe->type == FDINFO_PIPE)
return pipe_should_open_transport(fe, fd_list); return pipe_should_open_transport(fe, fd_list);
if (fe->type == FDINFO_UNIXSK)
return unixsk_should_open_transport(fe, fd_list);
return 0; return 0;
} }
...@@ -371,6 +375,9 @@ static int open_fd(int pid, struct fdinfo_entry *fe, ...@@ -371,6 +375,9 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
case FDINFO_PIPE: case FDINFO_PIPE:
tmp = open_pipe(fd_list); tmp = open_pipe(fd_list);
break; break;
case FDINFO_UNIXSK:
tmp = open_unix_sk(fd_list);
break;
default: default:
tmp = -1; tmp = -1;
break; break;
...@@ -569,7 +576,8 @@ int prepare_fds(int pid) ...@@ -569,7 +576,8 @@ int prepare_fds(int pid)
} }
close(fdinfo_fd); close(fdinfo_fd);
return ret;
return run_unix_connections();
} }
static struct fmap_fd *pull_fmap_fd(int pid, unsigned long start) static struct fmap_fd *pull_fmap_fd(int pid, unsigned long start)
......
...@@ -24,7 +24,6 @@ enum { ...@@ -24,7 +24,6 @@ enum {
CR_FD_CORE, CR_FD_CORE,
CR_FD_VMAS, CR_FD_VMAS,
CR_FD_SIGACT, CR_FD_SIGACT,
CR_FD_UNIXSK,
CR_FD_ITIMERS, CR_FD_ITIMERS,
CR_FD_CREDS, CR_FD_CREDS,
_CR_FD_TASK_TO, _CR_FD_TASK_TO,
...@@ -48,6 +47,7 @@ enum { ...@@ -48,6 +47,7 @@ enum {
CR_FD_SK_QUEUES, CR_FD_SK_QUEUES,
CR_FD_REG_FILES, CR_FD_REG_FILES,
CR_FD_INETSK, CR_FD_INETSK,
CR_FD_UNIXSK,
CR_FD_PIPES, CR_FD_PIPES,
CR_FD_PIPES_DATA, CR_FD_PIPES_DATA,
_CR_FD_GLOB_TO, _CR_FD_GLOB_TO,
...@@ -103,7 +103,7 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX]; ...@@ -103,7 +103,7 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
#define FMT_FNAME_PIPES_DATA "pipes-data.img" #define FMT_FNAME_PIPES_DATA "pipes-data.img"
#define FMT_FNAME_PSTREE "pstree.img" #define FMT_FNAME_PSTREE "pstree.img"
#define FMT_FNAME_SIGACTS "sigacts-%d.img" #define FMT_FNAME_SIGACTS "sigacts-%d.img"
#define FMT_FNAME_UNIXSK "unixsk-%d.img" #define FMT_FNAME_UNIXSK "unixsk.img"
#define FMT_FNAME_INETSK "inetsk.img" #define FMT_FNAME_INETSK "inetsk.img"
#define FMT_FNAME_ITIMERS "itimers-%d.img" #define FMT_FNAME_ITIMERS "itimers-%d.img"
#define FMT_FNAME_CREDS "creds-%d.img" #define FMT_FNAME_CREDS "creds-%d.img"
......
...@@ -37,6 +37,7 @@ enum fd_types { ...@@ -37,6 +37,7 @@ enum fd_types {
FDINFO_PIPE, FDINFO_PIPE,
FDINFO_MAP, FDINFO_MAP,
FDINFO_INETSK, FDINFO_INETSK,
FDINFO_UNIXSK,
FDINFO_CWD, FDINFO_CWD,
FDINFO_EXE, FDINFO_EXE,
...@@ -95,7 +96,6 @@ struct pipe_data_entry { ...@@ -95,7 +96,6 @@ struct pipe_data_entry {
#define USK_INFLIGHT 1 #define USK_INFLIGHT 1
struct unix_sk_entry { struct unix_sk_entry {
u32 fd;
u32 id; u32 id;
u8 type; u8 type;
u8 state; u8 state;
......
...@@ -12,11 +12,17 @@ extern int dump_socket(struct fd_parms *p, int lfd, ...@@ -12,11 +12,17 @@ extern int dump_socket(struct fd_parms *p, int lfd,
struct fdinfo_list_entry; struct fdinfo_list_entry;
struct list_head *find_inetsk_fd(int id); struct list_head *find_inetsk_fd(int id);
struct list_head *find_unixsk_fd(int id);
struct fdinfo_entry;
extern int unixsk_should_open_transport(struct fdinfo_entry *,
struct list_head *);
extern int collect_sockets(void); extern int collect_sockets(void);
extern int collect_inet_sockets(void); extern int collect_inet_sockets(void);
extern int collect_unix_sockets(int pid); extern int collect_unix_sockets(void);
extern int prepare_sockets(int pid); extern int resolve_unix_peers(void);
extern int run_unix_connections(void);
extern int open_inet_sk(struct list_head *); extern int open_inet_sk(struct list_head *);
extern int open_unix_sk(struct list_head *);
struct cr_options; struct cr_options;
extern void show_unixsk(int fd, struct cr_options *); extern void show_unixsk(int fd, struct cr_options *);
extern void show_inetsk(int fd, struct cr_options *); extern void show_inetsk(int fd, struct cr_options *);
......
This diff is collapsed.
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