Commit 43367e25 authored by Pavel Emelyanov's avatar Pavel Emelyanov

fdinfo: Rename fdinfo_entry addr to fd

Now we store only real fdtable entries in this file, so it's
time to name the field properly and change type to u32.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 14e5cdcb
...@@ -303,7 +303,7 @@ static int do_dump_one_fdinfo(const struct fd_parms *p, int lfd, ...@@ -303,7 +303,7 @@ static int do_dump_one_fdinfo(const struct fd_parms *p, int lfd,
int ret = -1; int ret = -1;
e.type = p->type; e.type = p->type;
e.addr = p->fd_name; e.fd = p->fd_name;
e.id = p->id; e.id = p->id;
ret = fd_id_generate(p->pid, &e); ret = fd_id_generate(p->pid, &e);
......
...@@ -83,8 +83,8 @@ void show_files(int fd_files, struct cr_options *o) ...@@ -83,8 +83,8 @@ void show_files(int fd_files, struct cr_options *o)
if (ret <= 0) if (ret <= 0)
goto out; goto out;
pr_msg("type: %5s addr: %16lx id: %8x", pr_msg("type: %5s fd: %5d id: %8x",
fdtype2s(e.type), e.addr, e.id); fdtype2s(e.type), e.fd, e.id);
pr_msg("\n"); pr_msg("\n");
} }
......
...@@ -139,7 +139,7 @@ static struct fd_id_entry *alloc_fd_id_entry(pid_t pid, struct fdinfo_entry *fe) ...@@ -139,7 +139,7 @@ static struct fd_id_entry *alloc_fd_id_entry(pid_t pid, struct fdinfo_entry *fe)
e->subid = fd_id_entries_subid++; e->subid = fd_id_entries_subid++;
e->genid = fe->id; e->genid = fe->id;
e->pid = pid; e->pid = pid;
e->fd = (int)fe->addr; e->fd = fe->fd;
/* Make sure no overflow here */ /* Make sure no overflow here */
BUG_ON(!e->subid); BUG_ON(!e->subid);
...@@ -166,7 +166,7 @@ static struct fd_id_entry *fd_id_generate_sub(struct fd_id_entry *e, ...@@ -166,7 +166,7 @@ static struct fd_id_entry *fd_id_generate_sub(struct fd_id_entry *e,
while (node) { while (node) {
struct fd_id_entry *this = rb_entry(node, struct fd_id_entry, subtree_node); struct fd_id_entry *this = rb_entry(node, struct fd_id_entry, subtree_node);
int ret = sys_kcmp(this->pid, pid, KCMP_FILE, this->fd, (int)fe->addr); int ret = sys_kcmp(this->pid, pid, KCMP_FILE, this->fd, fe->fd);
parent = *new; parent = *new;
if (ret < 0) if (ret < 0)
......
...@@ -161,8 +161,8 @@ static int collect_fd(int pid, struct fdinfo_entry *e) ...@@ -161,8 +161,8 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
struct fdinfo_list_entry *l, *le = &fdinfo_list[nr_fdinfo_list]; struct fdinfo_list_entry *l, *le = &fdinfo_list[nr_fdinfo_list];
struct file_desc *fdesc; struct file_desc *fdesc;
pr_info("Collect fdinfo pid=%d fd=%ld id=%16x\n", pr_info("Collect fdinfo pid=%d fd=%d id=%16x\n",
pid, e->addr, e->id); pid, e->fd, e->id);
nr_fdinfo_list++; nr_fdinfo_list++;
if ((nr_fdinfo_list) * sizeof(struct fdinfo_list_entry) >= 4096) { if ((nr_fdinfo_list) * sizeof(struct fdinfo_list_entry) >= 4096) {
...@@ -171,12 +171,12 @@ static int collect_fd(int pid, struct fdinfo_entry *e) ...@@ -171,12 +171,12 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
} }
le->pid = pid; le->pid = pid;
le->fd = e->addr; le->fd = e->fd;
futex_init(&le->real_pid); futex_init(&le->real_pid);
fdesc = find_file_desc(e); fdesc = find_file_desc(e);
if (fdesc == NULL) { if (fdesc == NULL) {
pr_err("No file for fd %d id %d\n", (int)e->addr, e->id); pr_err("No file for fd %d id %d\n", e->fd, e->id);
return -1; return -1;
} }
...@@ -248,10 +248,10 @@ int open_reg_by_id(u32 id) ...@@ -248,10 +248,10 @@ int open_reg_by_id(u32 id)
} }
static void transport_name_gen(struct sockaddr_un *addr, int *len, static void transport_name_gen(struct sockaddr_un *addr, int *len,
int pid, long fd) int pid, int fd)
{ {
addr->sun_family = AF_UNIX; addr->sun_family = AF_UNIX;
snprintf(addr->sun_path, UNIX_PATH_MAX, "x/crtools-fd-%d-%ld", pid, fd); snprintf(addr->sun_path, UNIX_PATH_MAX, "x/crtools-fd-%d-%d", pid, fd);
*len = SUN_LEN(addr); *len = SUN_LEN(addr);
*addr->sun_path = '\0'; *addr->sun_path = '\0';
} }
...@@ -274,7 +274,7 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe, struct file_desc ...@@ -274,7 +274,7 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe, struct file_desc
fle = file_master(d); fle = file_master(d);
if (fle->pid == pid) { if (fle->pid == pid) {
if (fle->fd == fe->addr) { if (fle->fd == fe->fd) {
/* file master */ /* file master */
if (!should_open_transport(fe, d)) if (!should_open_transport(fe, d))
return 0; return 0;
...@@ -282,12 +282,12 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe, struct file_desc ...@@ -282,12 +282,12 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe, struct file_desc
return 0; return 0;
} }
transport_name_gen(&saddr, &sun_len, getpid(), fe->addr); transport_name_gen(&saddr, &sun_len, getpid(), fe->fd);
pr_info("\t%d: Create transport fd for %lx\n", pid, fe->addr); pr_info("\t%d: Create transport fd for %d\n", pid, fe->fd);
list_for_each_entry(fle, &d->fd_info_head, list) list_for_each_entry(fle, &d->fd_info_head, list)
if ((fle->pid == pid) && (fle->fd == fe->addr)) if ((fle->pid == pid) && (fle->fd == fe->fd))
break; break;
BUG_ON(&d->fd_info_head == &fle->list); BUG_ON(&d->fd_info_head == &fle->list);
...@@ -303,7 +303,7 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe, struct file_desc ...@@ -303,7 +303,7 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe, struct file_desc
return -1; return -1;
} }
ret = reopen_fd_as((int)fe->addr, sock); ret = reopen_fd_as(fe->fd, sock);
if (ret < 0) if (ret < 0)
return -1; return -1;
...@@ -334,14 +334,14 @@ static int open_fd(int pid, struct fdinfo_entry *fe, ...@@ -334,14 +334,14 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
fle = file_master(d); fle = file_master(d);
if ((fle->pid != pid) || (fe->addr != fle->fd)) if ((fle->pid != pid) || (fe->fd != fle->fd))
return 0; return 0;
tmp = d->ops->open(d); tmp = d->ops->open(d);
if (tmp < 0) if (tmp < 0)
return -1; return -1;
if (reopen_fd_as((int)fe->addr, tmp)) if (reopen_fd_as(fe->fd, tmp))
return -1; return -1;
sock = socket(PF_UNIX, SOCK_DGRAM, 0); sock = socket(PF_UNIX, SOCK_DGRAM, 0);
...@@ -350,13 +350,12 @@ static int open_fd(int pid, struct fdinfo_entry *fe, ...@@ -350,13 +350,12 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
return -1; return -1;
} }
pr_info("\t%d: Create fd for %lx\n", pid, fe->addr); pr_info("\t%d: Create fd for %d\n", pid, fe->fd);
list_for_each_entry(fle, &d->fd_info_head, list) { list_for_each_entry(fle, &d->fd_info_head, list) {
if (pid == fle->pid) { if (pid == fle->pid) {
pr_info("\t\tGoing to dup %d into %d\n", pr_info("\t\tGoing to dup %d into %d\n", fe->fd, fle->fd);
(int)fe->addr, fle->fd); if (fe->fd == fle->fd)
if (fe->addr == fle->fd)
continue; continue;
if (move_img_fd(&sock, fle->fd)) if (move_img_fd(&sock, fle->fd))
...@@ -364,16 +363,16 @@ static int open_fd(int pid, struct fdinfo_entry *fe, ...@@ -364,16 +363,16 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
if (move_img_fd(fdinfo_fd, fle->fd)) if (move_img_fd(fdinfo_fd, fle->fd))
return -1; return -1;
if (dup2(fe->addr, fle->fd) != fle->fd) { if (dup2(fe->fd, fle->fd) != fle->fd) {
pr_perror("Can't dup local fd %d -> %d", pr_perror("Can't dup local fd %d -> %d",
(int)fe->addr, fle->fd); fe->fd, fle->fd);
return -1; return -1;
} }
continue; continue;
} }
if (send_fd_to_peer(fe->addr, fle, sock)) { if (send_fd_to_peer(fe->fd, fle, sock)) {
pr_perror("Can't send file descriptor"); pr_perror("Can't send file descriptor");
return -1; return -1;
} }
...@@ -394,16 +393,16 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d) ...@@ -394,16 +393,16 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
if (fle->pid == pid) if (fle->pid == pid)
return 0; return 0;
pr_info("\t%d: Receive fd for %lx\n", pid, fe->addr); pr_info("\t%d: Receive fd for %d\n", pid, fe->fd);
tmp = recv_fd(fe->addr); tmp = recv_fd(fe->fd);
if (tmp < 0) { if (tmp < 0) {
pr_err("Can't get fd %d\n", tmp); pr_err("Can't get fd %d\n", tmp);
return -1; return -1;
} }
close(fe->addr); close(fe->fd);
return reopen_fd_as((int)fe->addr, tmp); return reopen_fd_as(fe->fd, tmp);
} }
static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int state) static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int state)
...@@ -413,10 +412,10 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta ...@@ -413,10 +412,10 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta
struct file_desc *fdesc; struct file_desc *fdesc;
fdesc = find_file_desc(fe); fdesc = find_file_desc(fe);
if (move_img_fd(fdinfo_fd, (int)fe->addr)) if (move_img_fd(fdinfo_fd, fe->fd))
return -1; return -1;
pr_info("\t%d: Got fd for %lx\n", pid, fe->addr); pr_info("\t%d: Got fd for %d\n", pid, fe->fd);
switch (state) { switch (state) {
case FD_STATE_PREP: case FD_STATE_PREP:
......
...@@ -56,7 +56,7 @@ struct reg_file_entry { ...@@ -56,7 +56,7 @@ struct reg_file_entry {
} __packed; } __packed;
struct fdinfo_entry { struct fdinfo_entry {
u64 addr; u32 fd;
u8 type; u8 type;
u32 id; u32 id;
} __packed; } __packed;
......
...@@ -304,7 +304,7 @@ static int dump_one_inet(struct socket_desc *_sk, int fd, ...@@ -304,7 +304,7 @@ static int dump_one_inet(struct socket_desc *_sk, int fd,
if (!can_dump_inet_sk(sk)) if (!can_dump_inet_sk(sk))
goto err; goto err;
fe.addr = fd; fe.fd = fd;
fe.type = FDINFO_INETSK; fe.type = FDINFO_INETSK;
fe.id = sk->sd.ino; fe.id = sk->sd.ino;
...@@ -375,7 +375,7 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd, int lfd, ...@@ -375,7 +375,7 @@ static int dump_one_unix(const struct socket_desc *_sk, int fd, int lfd,
if (!can_dump_unix_sk(sk)) if (!can_dump_unix_sk(sk))
goto err; goto err;
fe.addr = fd; fe.fd = fd;
fe.type = FDINFO_UNIXSK; fe.type = FDINFO_UNIXSK;
fe.id = sk->sd.ino; fe.id = sk->sd.ino;
......
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