Commit 4691dcf3 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

unix: Add support of ghost sockets

Unix sockets may be connected via deleted socket name,
moreover the name may be reused (ie same sun_addr but
different inodes).

To be able to handle them we do a few tricks:

 - when collecting sockets we figure out if "deleted"
   mark is present on the socket and if such we order
   this sockets creation and deletion with mutex, together
   with adding missing directories, and save this descriptors
   in fdstore if there are peers connected to

 - on restore we connect via procfs/fd/X as suggested by
   Andrew Vagin
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 787409df
...@@ -378,6 +378,10 @@ static int root_prepare_shared(void) ...@@ -378,6 +378,10 @@ static int root_prepare_shared(void)
if (ret) if (ret)
goto err; goto err;
ret = unix_prepare_root_shared();
if (ret)
goto err;
ret = add_fake_unix_queuers(); ret = add_fake_unix_queuers();
if (ret) if (ret)
goto err; goto err;
......
...@@ -58,6 +58,7 @@ extern int netlink_receive_one(struct nlmsghdr *hdr, struct ns_id *ns, void *arg ...@@ -58,6 +58,7 @@ extern int netlink_receive_one(struct nlmsghdr *hdr, struct ns_id *ns, void *arg
extern int unix_sk_id_add(unsigned int ino); extern int unix_sk_id_add(unsigned int ino);
extern int unix_sk_ids_parse(char *optarg); extern int unix_sk_ids_parse(char *optarg);
extern int unix_prepare_root_shared(void);
extern int do_dump_opt(int sk, int level, int name, void *val, int len); extern int do_dump_opt(int sk, int level, int name, void *val, int len);
#define dump_opt(s, l, n, f) do_dump_opt(s, l, n, f, sizeof(*f)) #define dump_opt(s, l, n, f) do_dump_opt(s, l, n, f, sizeof(*f))
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <sys/un.h> #include <sys/un.h>
#include <stdlib.h> #include <stdlib.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <libgen.h>
#include "libnetlink.h" #include "libnetlink.h"
#include "cr_options.h" #include "cr_options.h"
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
#include "fdstore.h" #include "fdstore.h"
#include "fdinfo.h" #include "fdinfo.h"
#include "kerndat.h" #include "kerndat.h"
#include "rst-malloc.h"
#include "protobuf.h" #include "protobuf.h"
#include "images/sk-unix.pb-c.h" #include "images/sk-unix.pb-c.h"
...@@ -90,11 +92,21 @@ struct unix_sk_desc { ...@@ -90,11 +92,21 @@ struct unix_sk_desc {
UnixSkEntry *ue; UnixSkEntry *ue;
}; };
/*
* The mutex_ghost is accessed from different tasks,
* so make sure it is in shared memory.
*/
static mutex_t *mutex_ghost;
static LIST_HEAD(unix_sockets); static LIST_HEAD(unix_sockets);
static LIST_HEAD(unix_ghost_addr);
static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d, static int unix_resolve_name(int lfd, uint32_t id, struct unix_sk_desc *d,
UnixSkEntry *ue, const struct fd_parms *p); UnixSkEntry *ue, const struct fd_parms *p);
struct unix_sk_info;
static int unlink_sk(struct unix_sk_info *ui);
struct unix_sk_listen_icon { struct unix_sk_listen_icon {
unsigned int peer_ino; unsigned int peer_ino;
struct unix_sk_desc *sk_desc; struct unix_sk_desc *sk_desc;
...@@ -887,12 +899,15 @@ struct unix_sk_info { ...@@ -887,12 +899,15 @@ struct unix_sk_info {
char *name; char *name;
char *name_dir; char *name_dir;
unsigned flags; unsigned flags;
int fdstore_id;
struct unix_sk_info *peer; struct unix_sk_info *peer;
struct pprep_head peer_resolve; /* XXX : union with the above? */ struct pprep_head peer_resolve; /* XXX : union with the above? */
struct file_desc d; struct file_desc d;
struct list_head connected; /* List of sockets, connected to me */ struct list_head connected; /* List of sockets, connected to me */
struct list_head node; /* To link in peer's connected list */ struct list_head node; /* To link in peer's connected list */
struct list_head scm_fles; struct list_head scm_fles;
struct list_head ghost_node;
size_t ghost_dir_pos;
/* /*
* For DGRAM sockets with queues, we should only restore the queue * For DGRAM sockets with queues, we should only restore the queue
...@@ -917,6 +932,7 @@ struct scm_fle { ...@@ -917,6 +932,7 @@ struct scm_fle {
#define USK_PAIR_MASTER 0x1 #define USK_PAIR_MASTER 0x1
#define USK_PAIR_SLAVE 0x2 #define USK_PAIR_SLAVE 0x2
#define USK_GHOST_FDSTORE 0x4 /* bound but removed address */
static struct unix_sk_info *find_unix_sk_by_ino(int ino) static struct unix_sk_info *find_unix_sk_by_ino(int ino)
{ {
...@@ -1241,6 +1257,7 @@ err: ...@@ -1241,6 +1257,7 @@ err:
static int post_open_standalone(struct file_desc *d, int fd) static int post_open_standalone(struct file_desc *d, int fd)
{ {
int fdstore_fd = -1, procfs_self_dir = -1, len;
struct unix_sk_info *ui; struct unix_sk_info *ui;
struct unix_sk_info *peer; struct unix_sk_info *peer;
struct sockaddr_un addr; struct sockaddr_un addr;
...@@ -1269,22 +1286,49 @@ static int post_open_standalone(struct file_desc *d, int fd) ...@@ -1269,22 +1286,49 @@ static int post_open_standalone(struct file_desc *d, int fd)
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
pr_info("\tConnect %d to %d\n", ui->ue->ino, peer->ue->ino); pr_info("\tConnect %d to %d\n", ui->ue->ino, peer->ue->ino);
if (prep_unix_sk_cwd(peer, &cwd_fd, NULL, &ns_fd)) if (prep_unix_sk_cwd(peer, &cwd_fd, &root_fd, &ns_fd))
return -1; return -1;
if (connect(fd, (struct sockaddr *)&addr, if (peer->flags & USK_GHOST_FDSTORE) {
sizeof(addr.sun_family) + procfs_self_dir = open_proc(getpid(), "fd");
peer->ue->name.len) < 0) { fdstore_fd = fdstore_get(peer->fdstore_id);
if (fdstore_fd < 0 || procfs_self_dir < 0)
goto err_revert_and_exit;
/*
* WARNING: After this call we rely on revert_unix_sk_cwd
* to restore the former directories so that connect
* will operate inside proc/$pid/fd/X.
*/
if (fchdir(procfs_self_dir)) {
pr_perror("Can't change to procfs");
goto err_revert_and_exit;
}
len = snprintf(addr.sun_path, UNIX_PATH_MAX, "%d", fdstore_fd);
} else {
memcpy(&addr.sun_path, peer->name, peer->ue->name.len);
len = peer->ue->name.len;
}
/*
* Make sure the target is not being renamed at the moment
* while we're connecting in sake of ghost sockets.
*/
mutex_lock(mutex_ghost);
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr.sun_family) + len) < 0) {
pr_perror("Can't connect %d socket", ui->ue->ino); pr_perror("Can't connect %d socket", ui->ue->ino);
revert_unix_sk_cwd(peer, &cwd_fd, &root_fd, &ns_fd); goto err_revert_and_exit;
return -1;
} }
mutex_unlock(mutex_ghost);
ui->is_connected = true; ui->is_connected = true;
close_safe(&procfs_self_dir);
close_safe(&fdstore_fd);
revert_unix_sk_cwd(peer, &cwd_fd, &root_fd, &ns_fd); revert_unix_sk_cwd(peer, &cwd_fd, &root_fd, &ns_fd);
restore_queue: restore_queue:
...@@ -1296,48 +1340,217 @@ restore_sk_common: ...@@ -1296,48 +1340,217 @@ restore_sk_common:
if (ui->queuer && !ui->queuer->peer_queue_restored) if (ui->queuer && !ui->queuer->peer_queue_restored)
return 1; return 1;
return restore_sk_common(fd, ui); return restore_sk_common(fd, ui);
err_revert_and_exit:
close_safe(&procfs_self_dir);
close_safe(&fdstore_fd);
revert_unix_sk_cwd(peer, &cwd_fd, &root_fd, &ns_fd);
return -1;
} }
static int bind_deleted_unix_sk(int sk, struct unix_sk_info *ui, static int restore_file_perms(struct unix_sk_info *ui)
struct sockaddr_un *addr)
{ {
char temp[PATH_MAX]; if (ui->ue->file_perms) {
int ret; FilePermsEntry *perms = ui->ue->file_perms;
char fname[PATH_MAX];
if (ui->ue->name.len >= sizeof(fname)) {
pr_err("The file name is too long\n");
return -E2BIG;
}
memcpy(fname, ui->name, ui->ue->name.len);
fname[ui->ue->name.len] = '\0';
if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) < 0) {
int errno_cpy = errno;
pr_perror("Unable to change file owner and group");
return -errno_cpy;
}
if (fchmodat(AT_FDCWD, fname, perms->mode, 0) < 0) {
int errno_cpy = errno;
pr_perror("Unable to change file mode bits");
return -errno_cpy;
}
}
pr_info("found duplicate unix socket bound at %s\n", addr->sun_path); return 0;
}
ret = snprintf(temp, sizeof(temp), static int keep_deleted(struct unix_sk_info *ui)
"%s-%s-%d", addr->sun_path, "criu-temp", getpid()); {
/* this shouldn't happen, since sun_addr is only 108 chars long */ int fd = open(ui->name, O_PATH);
if (ret < 0 || ret >= sizeof(temp)) { if (fd < 0) {
pr_err("snprintf of %s failed?\n", addr->sun_path); pr_perror("ghost: Can't open id %#x ino %d addr %s",
ui->ue->id, ui->ue->ino, ui->name);
return -1; return -1;
} }
ui->fdstore_id = fdstore_add(fd);
pr_debug("ghost: id %#x %d fdstore_id %d %s\n",
ui->ue->id, ui->ue->ino, ui->fdstore_id, ui->name);
close(fd);
return ui->fdstore_id;
}
#define UNIX_GHOST_FMT "%s.criu-sk-ghost"
/*
* When path where socket lives is deleted, we need to reconstruct
* it back up but allow caller to remove it after.
*/
static int bind_on_deleted(int sk, struct unix_sk_info *ui)
{
char path[PATH_MAX], path_parked[PATH_MAX], *pos;
struct sockaddr_un addr;
bool renamed = false;
int ret;
if (ui->ue->name.len >= sizeof(path)) {
pr_err("ghost: Too long name for socket id %#x ino %d name %s\n",
ui->ue->id, ui->ue->ino, ui->name);
return -ENOSPC;
}
memcpy(path, ui->name, ui->ue->name.len);
path[ui->ue->name.len] = '\0';
for (pos = strrchr(path, '/'); pos;
pos = strrchr(path, '/')) {
*pos = '\0';
ret = access(path, R_OK | W_OK | X_OK);
if (ret == 0) {
ui->ghost_dir_pos = pos - path;
pr_debug("ghost: socket id %#x ino %d name %s detected F_OK %s\n",
ui->ue->id, ui->ue->ino, ui->name, path);
break;
}
if (errno != ENOENT) {
ret = -errno;
pr_perror("ghost: Can't access %s for socket id %#x ino %d name %s",
path, ui->ue->id, ui->ue->ino, ui->name);
return ret;
}
}
ret = rename(addr->sun_path, temp); memcpy(path, ui->name, ui->ue->name.len);
path[ui->ue->name.len] = '\0';
pos = dirname(path);
pr_debug("ghost: socket id %#x ino %d name %s creating %s\n",
ui->ue->id, ui->ue->ino, ui->name, pos);
ret = mkdirpat(AT_FDCWD, pos, 0755);
if (ret) {
errno = -ret;
pr_perror("ghost: Can't create %s", pos);
return ret;
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
memcpy(&addr.sun_path, ui->name, ui->ue->name.len);
ret = bind(sk, (struct sockaddr *)&addr,
sizeof(addr.sun_family) + ui->ue->name.len);
if (ret < 0) { if (ret < 0) {
pr_perror("couldn't move socket for binding"); /*
return -1; * In case if there some real living socket
* with same name just move it aside for a
* while, we will move it back once ghost
* socket is processed.
*/
if (errno == EADDRINUSE) {
snprintf(path_parked, sizeof(path_parked), UNIX_GHOST_FMT, ui->name);
/*
* Say previous restore get killed in a middle due to
* any reason, be ready the file might already exist,
* clean it up.
*/
if (unlinkat(AT_FDCWD, path_parked, 0) == 0)
pr_debug("ghost: Unlinked stale socket id %#x ino %d name %s\n",
ui->ue->id, ui->ue->ino, path_parked);
if (rename(ui->name, path_parked)) {
ret = -errno;
pr_perror("ghost: Can't rename id %#x ino %d addr %s -> %s",
ui->ue->id, ui->ue->ino, ui->name, path_parked);
return ret;
}
pr_debug("ghost: id %#x ino %d renamed %s -> %s\n",
ui->ue->id, ui->ue->ino, ui->name, path_parked);
renamed = true;
ret = bind(sk, (struct sockaddr *)&addr,
sizeof(addr.sun_family) + ui->ue->name.len);
}
if (ret < 0) {
ret = -errno;
pr_perror("ghost: Can't bind on socket id %#x ino %d addr %s",
ui->ue->id, ui->ue->ino, ui->name);
return ret;
}
} }
ret = bind(sk, (struct sockaddr *)addr, ret = restore_file_perms(ui);
sizeof(addr->sun_family) + ui->ue->name.len); if (ret < 0)
return ret;
ret = keep_deleted(ui);
if (ret < 0) { if (ret < 0) {
pr_perror("Can't bind socket after move"); pr_err("ghost: Can't save socket %#x ino %d addr %s into fdstore\n",
return -1; ui->ue->id, ui->ue->ino, ui->name);
return -EIO;
} }
ret = rename(temp, addr->sun_path); /*
* Once everything is ready, just remove the socket from the
* filesystem and rename back the original one if it were here.
*/
ret = unlinkat(AT_FDCWD, ui->name, 0);
if (ret < 0) { if (ret < 0) {
pr_perror("couldn't move socket back"); ret = -errno;
return -1; pr_perror("ghost: Can't unlink socket %#x ino %d addr %s",
ui->ue->id, ui->ue->ino, ui->name);
return ret;
}
if (renamed) {
if (rename(path_parked, ui->name)) {
ret = -errno;
pr_perror("ghost: Can't rename id %#x ino %d addr %s -> %s",
ui->ue->id, ui->ue->ino, path_parked, ui->name);
return ret;
}
pr_debug("ghost: id %#x ino %d renamed %s -> %s\n",
ui->ue->id, ui->ue->ino, path_parked, ui->name);
} }
/* we've handled the deleted-ness of this /*
* socket and we don't want to delete it later * Finally remove directories we've created.
* since it's not /this/ socket.
*/ */
ui->ue->deleted = false; if (ui->ghost_dir_pos) {
char *pos;
memcpy(path, ui->name, ui->ue->name.len);
path[ui->ue->name.len] = '\0';
for (pos = strrchr(path, '/');
pos && (pos - path) > ui->ghost_dir_pos;
pos = strrchr(path, '/')) {
*pos = '\0';
if (rmdir(path)) {
ret = - errno;
pr_perror("ghost: Can't remove directory %s on id %#x ino %d",
path, ui->ue->id, ui->ue->ino);
return -1;
}
pr_debug("ghost: Removed %s on id %#x ino %d\n",
path, ui->ue->id, ui->ue->ino);
}
}
return 0; return 0;
} }
...@@ -1365,46 +1578,38 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui) ...@@ -1365,46 +1578,38 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
memcpy(&addr.sun_path, ui->name, ui->ue->name.len); memcpy(&addr.sun_path, ui->name, ui->ue->name.len);
if (ui->name[0] && prep_unix_sk_cwd(ui, &cwd_fd, NULL, &ns_fd)) if (ui->name[0] && prep_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd))
return -1; return -1;
ret = bind(sk, (struct sockaddr *)&addr, /*
sizeof(addr.sun_family) + ui->ue->name.len); * Order binding for sake of ghost sockets. We might rename
if (ret < 0) { * existing socket to some temp name, bind ghost, delete it,
if (ui->ue->has_deleted && ui->ue->deleted && errno == EADDRINUSE) { * and finally move the former back, thus while we're doing
if (bind_deleted_unix_sk(sk, ui, &addr)) * this stuff we should not be interruped by connection
goto done; * from another sockets.
} else { *
pr_perror("Can't bind socket"); * FIXME: Probably wort make it per address rather for
goto done; * optimization sake.
} */
} mutex_lock(mutex_ghost);
if (*ui->name && ui->ue->file_perms) { if (ui->flags & USK_GHOST_FDSTORE) {
FilePermsEntry *perms = ui->ue->file_perms; pr_debug("ghost: bind id %#x ino %d addr %s\n",
char fname[PATH_MAX]; ui->ue->id, ui->ue->ino, ui->name);
ret = bind_on_deleted(sk, ui);
if (ui->ue->name.len >= sizeof(fname)) { if (ret)
pr_err("The file name is too long\n"); errno = -ret;
goto done; } else {
} pr_debug("bind id %#x ino %d addr %s\n",
ui->ue->id, ui->ue->ino, ui->name);
memcpy(fname, ui->name, ui->ue->name.len); ret = bind(sk, (struct sockaddr *)&addr,
fname[ui->ue->name.len] = '\0'; sizeof(addr.sun_family) + ui->ue->name.len);
if (ret == 0 && restore_file_perms(ui))
if (fchownat(AT_FDCWD, fname, perms->uid, perms->gid, 0) == -1) {
pr_perror("Unable to change file owner and group");
goto done;
}
if (fchmodat(AT_FDCWD, fname, perms->mode, 0) == -1) {
pr_perror("Unable to change file mode bits");
goto done; goto done;
}
} }
if (ret < 0) {
if (ui->ue->deleted && unlink((char *)ui->ue->name.data) < 0) { pr_perror("Can't bind id %#x ino %d addr %s",
pr_perror("failed to unlink %s", ui->ue->name.data); ui->ue->id, ui->ue->ino, ui->name);
goto done; goto done;
} }
...@@ -1416,6 +1621,7 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui) ...@@ -1416,6 +1621,7 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
exit_code = 0; exit_code = 0;
done: done:
revert_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd); revert_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd);
mutex_unlock(mutex_ghost);
return exit_code; return exit_code;
} }
...@@ -1551,11 +1757,27 @@ static int setup_second_end(int *sks, struct fdinfo_list_entry *second_end) ...@@ -1551,11 +1757,27 @@ static int setup_second_end(int *sks, struct fdinfo_list_entry *second_end)
static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd) static int open_unixsk_standalone(struct unix_sk_info *ui, int *new_fd)
{ {
struct unix_sk_info *queuer = ui->queuer; struct unix_sk_info *queuer = ui->queuer;
struct fdinfo_list_entry *fle; struct unix_sk_info *peer = ui->peer;
struct fdinfo_list_entry *fle, *fle_peer;
int sk; int sk;
fle = file_master(&ui->d); fle = file_master(&ui->d);
pr_info_opening("standalone", ui, fle); pr_info_opening("standalone", ui, fle);
/*
* If we're about to connect to the peer which
* has been bound to removed address we should
* wait until it is processed and put into fdstore
* engine, later we will use the engine to connect
* into it in a special way.
*/
if (peer && (peer->flags & USK_GHOST_FDSTORE)) {
fle_peer = file_master(&peer->d);
if (fle_peer->stage < FLE_OPEN) {
return 1;
}
}
if (fle->stage == FLE_OPEN) if (fle->stage == FLE_OPEN)
return post_open_standalone(&ui->d, fle->fe->fd); return post_open_standalone(&ui->d, fle->fe->fd);
...@@ -1744,15 +1966,15 @@ static struct file_desc_ops unix_desc_ops = { ...@@ -1744,15 +1966,15 @@ static struct file_desc_ops unix_desc_ops = {
* Make FS clean from sockets we're about to * Make FS clean from sockets we're about to
* restore. See for how we bind them for details * restore. See for how we bind them for details
*/ */
static void unlink_sk(struct unix_sk_info *ui) static int unlink_sk(struct unix_sk_info *ui)
{ {
int ret, cwd_fd = -1, root_fd = -1, ns_fd = -1; int ret = 0, cwd_fd = -1, root_fd = -1, ns_fd = -1;
if (!ui->name || ui->name[0] == '\0' || (ui->ue->uflags & USK_EXTERN)) if (!ui->name || ui->name[0] == '\0' || (ui->ue->uflags & USK_EXTERN))
return; return 0;
if (prep_unix_sk_cwd(ui, &cwd_fd, &root_fd, NULL)) if (prep_unix_sk_cwd(ui, &cwd_fd, &root_fd, NULL))
return; return -1;
ret = unlinkat(AT_FDCWD, ui->name, 0) ? -1 : 0; ret = unlinkat(AT_FDCWD, ui->name, 0) ? -1 : 0;
if (ret < 0 && errno != ENOENT) { if (ret < 0 && errno != ENOENT) {
...@@ -1760,13 +1982,17 @@ static void unlink_sk(struct unix_sk_info *ui) ...@@ -1760,13 +1982,17 @@ static void unlink_sk(struct unix_sk_info *ui)
ui->ue->ino, ui->ue->peer, ui->ue->ino, ui->ue->peer,
ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-", ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-",
ui->name_dir ? ui->name_dir : "-"); ui->name_dir ? ui->name_dir : "-");
ret = -errno;
goto out;
} else if (ret == 0) { } else if (ret == 0) {
pr_debug("Unlinked socket %d peer %d (name %s dir %s)\n", pr_debug("Unlinked socket %d peer %d (name %s dir %s)\n",
ui->ue->ino, ui->ue->peer, ui->ue->ino, ui->ue->peer,
ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-", ui->name ? (ui->name[0] ? ui->name : &ui->name[1]) : "-",
ui->name_dir ? ui->name_dir : "-"); ui->name_dir ? ui->name_dir : "-");
} }
out:
revert_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd); revert_unix_sk_cwd(ui, &cwd_fd, &root_fd, &ns_fd);
return ret;
} }
static void try_resolve_unix_peer(struct unix_sk_info *ui); static void try_resolve_unix_peer(struct unix_sk_info *ui);
...@@ -1798,6 +2024,8 @@ static int init_unix_sk_info(struct unix_sk_info *ui, UnixSkEntry *ue) ...@@ -1798,6 +2024,8 @@ static int init_unix_sk_info(struct unix_sk_info *ui, UnixSkEntry *ue)
ui->name_dir = (void *)ue->name_dir; ui->name_dir = (void *)ue->name_dir;
ui->flags = 0; ui->flags = 0;
ui->fdstore_id = -1;
ui->ghost_dir_pos = 0;
ui->peer = NULL; ui->peer = NULL;
ui->queuer = NULL; ui->queuer = NULL;
ui->bound = 0; ui->bound = 0;
...@@ -1812,6 +2040,40 @@ static int init_unix_sk_info(struct unix_sk_info *ui, UnixSkEntry *ue) ...@@ -1812,6 +2040,40 @@ static int init_unix_sk_info(struct unix_sk_info *ui, UnixSkEntry *ue)
INIT_LIST_HEAD(&ui->connected); INIT_LIST_HEAD(&ui->connected);
INIT_LIST_HEAD(&ui->node); INIT_LIST_HEAD(&ui->node);
INIT_LIST_HEAD(&ui->scm_fles); INIT_LIST_HEAD(&ui->scm_fles);
INIT_LIST_HEAD(&ui->ghost_node);
return 0;
}
int unix_prepare_root_shared(void)
{
struct unix_sk_info *ui;
mutex_ghost = shmalloc(sizeof(*mutex_ghost));
if (!mutex_ghost) {
pr_err("ghost: Can't allocate mutex\n");
return -ENOMEM;
}
mutex_init(mutex_ghost);
pr_debug("ghost: Resolving addresses\n");
list_for_each_entry(ui, &unix_ghost_addr, ghost_node) {
pr_debug("ghost: id %#x type %s state %s ino %d peer %d address %s\n",
ui->ue->id, socket_type_name(ui->ue->type),
tcp_state_name(ui->ue->state),
ui->ue->ino, ui->peer ? ui->peer->ue->ino : 0,
ui->name);
/*
* Drop any existing trash on the FS and mark the
* peer as a ghost one, so we will put it into
* fdstore to be able to connect into it even
* when the address is removed from the FS.
*/
unlink_sk(ui);
ui->flags |= USK_GHOST_FDSTORE;
}
return 0; return 0;
} }
...@@ -1858,6 +2120,15 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i) ...@@ -1858,6 +2120,15 @@ static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
add_post_prepare_cb(&ui->peer_resolve); add_post_prepare_cb(&ui->peer_resolve);
} }
if (ui->ue->deleted) {
if (!ui->name || !ui->ue->name.len || !ui->name[0]) {
pr_err("No name present, ino %d\n", ui->ue->ino);
return -1;
}
list_add_tail(&ui->ghost_node, &unix_ghost_addr);
}
list_add_tail(&ui->list, &unix_sockets); list_add_tail(&ui->list, &unix_sockets);
return file_desc_add(&ui->d, ui->ue->id, &unix_desc_ops); return file_desc_add(&ui->d, ui->ue->id, &unix_desc_ops);
} }
......
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