[CRIU] [PATCH 04/14] crtools: add ability to create and close a service fd
Pavel Emelyanov
xemul at parallels.com
Fri Jan 11 05:34:49 EST 2013
On 01/11/2013 01:22 PM, Andrey Vagin wrote:
> A service fd should be created, otherwise get_service_fd returns -1
>
> v2: rename open_service_fd to install_service_fd
>
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
> include/crtools.h | 2 ++
> util.c | 35 +++++++++++++++++++++++++++++++++++
> 2 files changed, 37 insertions(+)
>
> diff --git a/include/crtools.h b/include/crtools.h
> index 64e11dd..a8813b3 100644
> --- a/include/crtools.h
> +++ b/include/crtools.h
> @@ -124,6 +124,8 @@ enum sfd_type {
> extern int clone_service_fd(int id);
> extern int init_service_fd(void);
> extern int get_service_fd(enum sfd_type type);
> +extern int open_service_fd(enum sfd_type type, int fd);
> +extern int close_service_fd(enum sfd_type type);
> extern bool is_service_fd(int fd, enum sfd_type type);
> extern bool is_any_service_fd(int fd);
>
> diff --git a/util.c b/util.c
> index af191d4..1ad0572 100644
> --- a/util.c
> +++ b/util.c
> @@ -308,12 +308,47 @@ static int __get_service_fd(enum sfd_type type, int service_fd_id)
> return service_fd_rlim_cur - type - SERVICE_FD_MAX * service_fd_id;
> }
>
> +static DECLARE_BITMAP(sfd_map, SERVICE_FD_MAX);
> +
> +int install_service_fd(enum sfd_type type, int fd)
> +{
> + int sfd = __get_service_fd(type, service_fd_id);
> +
> + BUG_ON((int)type <= SERVICE_FD_MIN || (int)type >= SERVICE_FD_MAX);
> +
> + if (dup2(fd, sfd) != sfd) {
> + pr_perror("Dup %d -> %d failed", fd, sfd);
> + return -1;
> + }
> +
> + set_bit(type, sfd_map);
> + return sfd;
> +}
> +
> int get_service_fd(enum sfd_type type)
> {
> BUG_ON((int)type <= SERVICE_FD_MIN || (int)type >= SERVICE_FD_MAX);
> +
> + if (!test_bit(type, sfd_map))
> + return -1;
This breaks git-bisect, isn't it? I mean -- right after this patch no
service fds will be available.
> +
> return __get_service_fd(type, service_fd_id);
> }
>
> +int close_service_fd(enum sfd_type type)
> +{
> + int fd = get_service_fd(type);
> +
> + if (fd < 0)
> + return 0;
> +
> + if (close_safe(&fd))
> + return -1;
> +
> + clear_bit(type, sfd_map);
> + return 0;
> +}
> +
> int clone_service_fd(int id)
> {
> int ret = -1, i;
>
More information about the CRIU
mailing list