[CRIU] Re: [PATCH 2/5] fowners: Prepare ground for dump and restore
Cyrill Gorcunov
gorcunov at openvz.org
Mon Apr 9 07:02:57 EDT 2012
On Mon, Apr 09, 2012 at 12:17:17PM +0400, Pavel Emelyanov wrote:
>
> How about sockets? They should have fowners too.
>
Pavel, this patch is on top of _this_ series, what do you think?
Cyrill
-------------- next part --------------
>From d50fe710d04205fee156c7b233e831ea8e6e789e Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon, 9 Apr 2012 14:59:56 +0400
Subject: [PATCH] sockets: Add checkpoint restore for file owners
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
cr-show.c | 2 +-
include/crtools.h | 1 +
include/image.h | 2 ++
sockets.c | 31 ++++++++++++++++++++++---------
4 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/cr-show.c b/cr-show.c
index 72ff1e0..4b5c4c2 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -96,7 +96,7 @@ out:
pr_img_tail(CR_FD_FDINFO);
}
-static void show_fown(fown_t *fown)
+void show_fown(fown_t *fown)
{
if (fown->pid)
pr_msg("\tfown: uid: %x euid: %x signum: %x pid_type: %x pid: %x\n",
diff --git a/include/crtools.h b/include/crtools.h
index 55681c8..5b25009 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -90,6 +90,7 @@ void show_pstree(int fd_pstree, struct cr_options *o);
void show_sigacts(int fd_sigacts, struct cr_options *o);
void show_itimers(int fd, struct cr_options *o);
void show_creds(int fd, struct cr_options *o);
+void show_fown(fown_t *fown);
extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
diff --git a/include/image.h b/include/image.h
index b03695b..8ed37a0 100644
--- a/include/image.h
+++ b/include/image.h
@@ -111,6 +111,7 @@ struct unix_sk_entry {
u8 pad;
u32 backlog;
u32 peer;
+ fown_t fown;
u8 name[0];
} __packed;
@@ -123,6 +124,7 @@ struct inet_sk_entry {
u16 src_port;
u16 dst_port;
u32 backlog;
+ fown_t fown;
u32 src_addr[4];
u32 dst_addr[4];
} __packed;
diff --git a/sockets.c b/sockets.c
index 65d45ff..71d2315 100644
--- a/sockets.c
+++ b/sockets.c
@@ -294,7 +294,7 @@ static int can_dump_inet_sk(const struct inet_sk_desc *sk)
return 1;
}
-static int dump_one_inet(struct socket_desc *_sk, int fd,
+static int dump_one_inet(struct socket_desc *_sk, struct fd_parms *p,
const struct cr_fdset *cr_fdset)
{
struct inet_sk_desc *sk = (struct inet_sk_desc *)_sk;
@@ -304,7 +304,7 @@ static int dump_one_inet(struct socket_desc *_sk, int fd,
if (!can_dump_inet_sk(sk))
goto err;
- fe.addr = fd;
+ fe.addr = p->fd_name;
fe.type = FDINFO_INETSK;
fe.id = sk->sd.ino;
@@ -324,13 +324,14 @@ static int dump_one_inet(struct socket_desc *_sk, int fd,
ie.src_port = sk->src_port;
ie.dst_port = sk->dst_port;
ie.backlog = sk->wqlen;
+ ie.fown = p->fown;
memcpy(ie.src_addr, sk->src_addr, sizeof(u32) * 4);
memcpy(ie.dst_addr, sk->dst_addr, sizeof(u32) * 4);
if (write_img(fdset_fd(glob_fdset, CR_FD_INETSK), &ie))
goto err;
- pr_info("Dumping inet socket at %d\n", fd);
+ pr_info("Dumping inet socket at %d\n", (int)p->fd_name);
show_one_inet("Dumping", sk);
show_one_inet_img("Dumped", &ie);
sk->sd.already_dumped = 1;
@@ -365,8 +366,8 @@ static int can_dump_unix_sk(const struct unix_sk_desc *sk)
return 1;
}
-static int dump_one_unix(const struct socket_desc *_sk, int fd, int lfd,
- const struct cr_fdset *cr_fdset)
+static int dump_one_unix(const struct socket_desc *_sk, struct fd_parms *p,
+ int lfd, const struct cr_fdset *cr_fdset)
{
struct unix_sk_desc *sk = (struct unix_sk_desc *)_sk;
struct fdinfo_entry fe;
@@ -375,7 +376,7 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd, int lfd,
if (!can_dump_unix_sk(sk))
goto err;
- fe.addr = fd;
+ fe.addr = p->fd_name;
fe.type = FDINFO_UNIXSK;
fe.id = sk->sd.ino;
@@ -391,6 +392,7 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd, int lfd,
ue.namelen = sk->namelen;
ue.backlog = sk->wqlen;
ue.peer = sk->peer_ino;
+ ue.fown = p->fown;
if (ue.peer) {
struct unix_sk_desc *peer;
@@ -452,7 +454,7 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd, int lfd,
if (dump_socket_queue(lfd, ue.id))
goto err;
- pr_info("Dumping unix socket at %d\n", fd);
+ pr_info("Dumping unix socket at %d\n", (int)p->fd_name);
show_one_unix("Dumping", sk);
show_one_unix_img("Dumped", &ue);
@@ -475,9 +477,9 @@ int dump_socket(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset)
switch (sk->family) {
case AF_UNIX:
- return dump_one_unix(sk, p->fd_name, lfd, cr_fdset);
+ return dump_one_unix(sk, p, lfd, cr_fdset);
case AF_INET:
- return dump_one_inet(sk, p->fd_name, cr_fdset);
+ return dump_one_inet(sk, p, cr_fdset);
default:
pr_err("BUG! Unknown socket collected\n");
break;
@@ -953,6 +955,9 @@ static int open_inet_sk(struct file_desc *d)
return -1;
}
+ if (restore_fown(getpid(), sk, &ii->ie.fown))
+ goto err;
+
/*
* Listen sockets are easiest ones -- simply
* bind() and listen(), and that's all.
@@ -1080,6 +1085,7 @@ 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\n",
ie.id, skfamily2s(ie.family), sktype2s(ie.type), skproto2s(ie.proto),
skstate2s(ie.state), src_addr, ie.src_port, dst_addr, ie.dst_port);
+ show_fown(&ie.fown);
}
out:
@@ -1116,6 +1122,7 @@ void show_unixsk(int fd, struct cr_options *o)
pr_msg(" --> %s\n", buf);
} else
pr_msg("\n");
+ show_fown(&ue.fown);
}
out:
pr_img_tail(CR_FD_UNIXSK);
@@ -1262,6 +1269,9 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui)
return -1;
}
+ if (restore_fown(getpid(), sk[0], &ui->ue.fown))
+ return -1;
+
if (restore_socket_queue(sk[0], peer->ue.id))
return -1;
if (restore_socket_queue(sk[1], ui->ue.id))
@@ -1324,6 +1334,9 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
return -1;
}
+ if (restore_fown(getpid(), sk, &ui->ue.fown))
+ return -1;
+
if (bind_unix_sk(sk, ui))
return -1;
--
1.7.7.6
More information about the CRIU
mailing list