Commit b9f13599 authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Simpler regfiles and sockets open

The list_head ptr passed into it can be converted into
the respective _info with container_of, rather than search.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent d1c9f0d7
...@@ -212,16 +212,12 @@ int prepare_fd_pid(int pid) ...@@ -212,16 +212,12 @@ int prepare_fd_pid(int pid)
return ret; return ret;
} }
static int open_fe_fd(struct fdinfo_entry *fe) static int open_fe_fd(struct list_head *l)
{ {
struct reg_file_info *rfi; struct reg_file_info *rfi;
int tmp; int tmp;
rfi = find_reg_file(fe->id); rfi = container_of(l, struct reg_file_info, fd_head);
if (!rfi) {
pr_err("Can't find file id %x\n", fe->id);
return -1;
}
tmp = open(rfi->path, rfi->rfe.flags); tmp = open(rfi->path, rfi->rfe.flags);
if (tmp < 0) { if (tmp < 0) {
...@@ -233,12 +229,25 @@ static int open_fe_fd(struct fdinfo_entry *fe) ...@@ -233,12 +229,25 @@ static int open_fe_fd(struct fdinfo_entry *fe)
return tmp; return tmp;
} }
static int find_open_fe_fd(struct fdinfo_entry *fe)
{
struct reg_file_info *rfi;
int tmp;
rfi = find_reg_file(fe->id);
if (!rfi) {
pr_err("Can't find file id %x\n", fe->id);
return -1;
}
return open_fe_fd(&rfi->fd_head);
}
static int restore_cwd(struct fdinfo_entry *fe, int fd) static int restore_cwd(struct fdinfo_entry *fe, int fd)
{ {
int cfd; int cfd;
cfd = open_fe_fd(fe); cfd = find_open_fe_fd(fe);
if (cfd < 0) if (cfd < 0)
return cfd; return cfd;
...@@ -267,7 +276,7 @@ static int restore_exe_early(struct fdinfo_entry *fe, int fd) ...@@ -267,7 +276,7 @@ static int restore_exe_early(struct fdinfo_entry *fe, int fd)
if (self_exe_fd < 0) if (self_exe_fd < 0)
return self_exe_fd; return self_exe_fd;
tmp = open_fe_fd(fe); tmp = find_open_fe_fd(fe);
if (tmp < 0) if (tmp < 0)
return tmp; return tmp;
...@@ -360,10 +369,10 @@ static int open_fd(int pid, struct fdinfo_entry *fe, ...@@ -360,10 +369,10 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
switch (fe->type) { switch (fe->type) {
case FDINFO_REG: case FDINFO_REG:
tmp = open_fe_fd(fe); tmp = open_fe_fd(fd_list);
break; break;
case FDINFO_INETSK: case FDINFO_INETSK:
tmp = open_inet_sk(fe); tmp = open_inet_sk(fd_list);
break; break;
default: default:
tmp = -1; tmp = -1;
...@@ -444,7 +453,7 @@ static int open_fmap(int pid, struct fdinfo_entry *fe, int fd) ...@@ -444,7 +453,7 @@ static int open_fmap(int pid, struct fdinfo_entry *fe, int fd)
struct fmap_fd *new; struct fmap_fd *new;
int tmp; int tmp;
tmp = open_fe_fd(fe); tmp = find_open_fe_fd(fe);
if (tmp < 0) if (tmp < 0)
return -1; return -1;
......
...@@ -17,8 +17,7 @@ extern int collect_sockets(void); ...@@ -17,8 +17,7 @@ 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(int pid);
extern int prepare_sockets(int pid); extern int prepare_sockets(int pid);
struct fdinfo_entry; extern int open_inet_sk(struct list_head *);
extern int open_inet_sk(struct fdinfo_entry *fe);
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 *);
......
...@@ -1320,17 +1320,13 @@ int collect_inet_sockets(void) ...@@ -1320,17 +1320,13 @@ int collect_inet_sockets(void)
return 0; return 0;
} }
int open_inet_sk(struct fdinfo_entry *fe) int open_inet_sk(struct list_head *l)
{ {
int sk; int sk;
struct sockaddr_in addr; struct sockaddr_in addr;
struct inet_sk_info *ii; struct inet_sk_info *ii;
ii = find_inet_sk(fe->id); ii = container_of(l, struct inet_sk_info, fd_head);
if (ii == NULL) {
pr_err("Can't find inet sk %u\n", fe->id);
return -1;
}
show_one_inet_img("Restore", &ii->ie); show_one_inet_img("Restore", &ii->ie);
......
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