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 {
struct inet_sk_entry {
u32 id;
u32 ino;
u8 family;
u8 type;
u8 proto;
......
......@@ -47,8 +47,7 @@ extern char *skstate2s(u32 state);
extern struct socket_desc *lookup_socket(int ino);
extern int dump_one_inet(struct socket_desc *_sk, struct fd_parms *p,
int lfd, const struct cr_fdset *cr_fdset);
extern int dump_one_inet(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);
......
......@@ -92,30 +92,24 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk)
#define tcp_connection(sk) (((sk)->proto == IPPROTO_TCP) && \
((sk)->state == TCP_ESTABLISHED))
int dump_one_inet(struct socket_desc *_sk, struct fd_parms *p,
int lfd, const struct cr_fdset *cr_fdset)
static int dump_one_inet_fd(int lfd, u32 id, const struct fd_parms *p)
{
struct inet_sk_desc *sk = (struct inet_sk_desc *)_sk;
struct inet_sk_desc *sk;
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;
fe.fd = p->fd;
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))
if (!can_dump_inet_sk(sk))
goto err;
if (sk->sd.already_dumped)
return 0;
BUG_ON(sk->sd.already_dumped);
memset(&ie, 0, sizeof(ie));
ie.id = sk->sd.ino;
ie.id = id;
ie.ino = sk->sd.ino;
ie.family = sk->sd.family;
ie.type = sk->type;
ie.proto = sk->proto;
......@@ -148,6 +142,17 @@ err:
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)
{
struct inet_sk_desc *d;
......@@ -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",
ie.id, skfamily2s(ie.family), sktype2s(ie.type), skproto2s(ie.proto),
pr_msg("id %#x ino %#x family %s type %s proto %s state %s %s:%d <-> %s:%d flags 0x%2x\n",
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);
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)
int ifd;
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);
if (ifd < 0)
......
......@@ -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);
case AF_INET:
case AF_INET6:
return dump_one_inet(sk, p, lfd, cr_fdset);
return dump_one_inet(p, lfd, cr_fdset);
default:
pr_err("BUG! Unknown socket collected\n");
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