Commit 424a4adb authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

sockets, inet: Use general machnism for checkpoint/restore v2

Use fdtype_ops facility to c/r inet sockets.

v2:
 - Use BUG_ON if socket is attempted to be dumped
   several times
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c26b68dc
...@@ -195,6 +195,7 @@ struct unix_sk_entry { ...@@ -195,6 +195,7 @@ struct unix_sk_entry {
struct inet_sk_entry { struct inet_sk_entry {
u32 id; u32 id;
u32 ino;
u8 family; u8 family;
u8 type; u8 type;
u8 proto; u8 proto;
......
...@@ -47,8 +47,7 @@ extern char *skstate2s(u32 state); ...@@ -47,8 +47,7 @@ extern char *skstate2s(u32 state);
extern struct socket_desc *lookup_socket(int ino); extern struct socket_desc *lookup_socket(int ino);
extern int dump_one_inet(struct socket_desc *_sk, struct fd_parms *p, extern int dump_one_inet(struct fd_parms *p, int lfd, const struct cr_fdset *set);
int lfd, const struct cr_fdset *cr_fdset);
extern int dump_one_unix(struct fd_parms *p, int lfd, const struct cr_fdset *set); extern int dump_one_unix(struct fd_parms *p, int lfd, const struct cr_fdset *set);
extern int inet_collect_one(struct nlmsghdr *h, int family, int type, int proto); extern int inet_collect_one(struct nlmsghdr *h, int family, int type, int proto);
......
...@@ -92,30 +92,24 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk) ...@@ -92,30 +92,24 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk)
#define tcp_connection(sk) (((sk)->proto == IPPROTO_TCP) && \ #define tcp_connection(sk) (((sk)->proto == IPPROTO_TCP) && \
((sk)->state == TCP_ESTABLISHED)) ((sk)->state == TCP_ESTABLISHED))
int dump_one_inet(struct socket_desc *_sk, struct fd_parms *p, static int dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p)
int lfd, const struct cr_fdset *cr_fdset)
{ {
struct inet_sk_desc *sk = (struct inet_sk_desc *)_sk; struct inet_sk_desc *sk;
struct inet_sk_entry ie; struct inet_sk_entry ie;
struct fdinfo_entry fe;
if (!can_dump_inet_sk(sk)) sk = (struct inet_sk_desc *)lookup_socket(p->stat.st_ino);
if (!sk)
goto err; goto err;
fe.fd = p->fd; if (!can_dump_inet_sk(sk))
fe.type = FDINFO_INETSK;
fe.id = sk->sd.ino;
fe.flags = p->fd_flags;
if (write_img(fdset_fd(cr_fdset, CR_FD_FDINFO), &fe))
goto err; goto err;
if (sk->sd.already_dumped) BUG_ON(sk->sd.already_dumped);
return 0;
memset(&ie, 0, sizeof(ie)); memset(&ie, 0, sizeof(ie));
ie.id = sk->sd.ino; ie.id = id;
ie.ino = sk->sd.ino;
ie.family = sk->sd.family; ie.family = sk->sd.family;
ie.type = sk->type; ie.type = sk->type;
ie.proto = sk->proto; ie.proto = sk->proto;
...@@ -148,6 +142,17 @@ err: ...@@ -148,6 +142,17 @@ err:
return -1; return -1;
} }
static const struct fdtype_ops inet_dump_ops = {
.type = FDINFO_INETSK,
.make_gen_id = make_gen_id,
.dump = dump_one_inet_fd,
};
int dump_one_inet(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &inet_dump_ops, set);
}
int inet_collect_one(struct nlmsghdr *h, int family, int type, int proto) int inet_collect_one(struct nlmsghdr *h, int family, int type, int proto)
{ {
struct inet_sk_desc *d; struct inet_sk_desc *d;
...@@ -381,8 +386,8 @@ void show_inetsk(int fd, struct cr_options *o) ...@@ -381,8 +386,8 @@ void show_inetsk(int fd, struct cr_options *o)
} }
} }
pr_msg("id %#x family %s type %s proto %s state %s %s:%d <-> %s:%d flags 0x%2x\n", pr_msg("id %#x ino %#x family %s type %s proto %s state %s %s:%d <-> %s:%d flags 0x%2x\n",
ie.id, skfamily2s(ie.family), sktype2s(ie.type), skproto2s(ie.proto), ie.id, ie.ino, skfamily2s(ie.family), sktype2s(ie.type), skproto2s(ie.proto),
skstate2s(ie.state), src_addr, ie.src_port, dst_addr, ie.dst_port, ie.flags); skstate2s(ie.state), src_addr, ie.src_port, dst_addr, ie.dst_port, ie.flags);
pr_msg("\t"), show_fown_cont(&ie.fown), pr_msg("\n"); pr_msg("\t"), show_fown_cont(&ie.fown), pr_msg("\n");
......
...@@ -436,7 +436,7 @@ static int restore_tcp_conn_state(int sk, struct inet_sk_info *ii) ...@@ -436,7 +436,7 @@ static int restore_tcp_conn_state(int sk, struct inet_sk_info *ii)
int ifd; int ifd;
struct tcp_stream_entry tse; struct tcp_stream_entry tse;
pr_info("Restoring TCP connection %x\n", ii->ie.id); pr_info("Restoring TCP connection id %x ino %x\n", ii->ie.id, ii->ie.ino);
ifd = open_image_ro(CR_FD_TCP_STREAM, ii->ie.id); ifd = open_image_ro(CR_FD_TCP_STREAM, ii->ie.id);
if (ifd < 0) if (ifd < 0)
......
...@@ -122,7 +122,7 @@ int dump_socket(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset) ...@@ -122,7 +122,7 @@ int dump_socket(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset)
return dump_one_unix(p, lfd, cr_fdset); return dump_one_unix(p, lfd, cr_fdset);
case AF_INET: case AF_INET:
case AF_INET6: case AF_INET6:
return dump_one_inet(sk, p, lfd, cr_fdset); return dump_one_inet(p, lfd, cr_fdset);
default: default:
pr_err("BUG! Unknown socket collected\n"); pr_err("BUG! Unknown socket collected\n");
break; break;
......
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