Commit bac56b11 authored by Pavel Emelyanov's avatar Pavel Emelyanov

sockets: Remove statfs and 2nd stat from dump process

The statfs is not required, we now check for fd being a socket with S_IFSOCK.
The 2nd stat is just not needed, the caller provides stat info.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 250d0764
......@@ -33,6 +33,7 @@
#include "proc_parse.h"
#include "parasite.h"
#include "parasite-syscall.h"
#include "files.h"
#ifndef CONFIG_X86_64
# error No x86-32 support yet
......@@ -125,16 +126,6 @@ static int collect_fds(pid_t pid, int *fd, int *nr_fd)
return 0;
}
struct fd_parms {
unsigned long fd_name;
unsigned long pos;
unsigned int flags;
unsigned int type;
struct stat stat;
u32 id;
pid_t pid;
};
static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
{
char fd_str[128];
......@@ -360,7 +351,7 @@ static int dump_one_fd(pid_t pid, int fd, int lfd,
}
if (S_ISSOCK(p.stat.st_mode))
return dump_socket(pid, fd, cr_fdset, sk_queue);
return dump_socket(&p, lfd, cr_fdset, sk_queue);
if (S_ISCHR(p.stat.st_mode) &&
(major(p.stat.st_rdev) == TTY_MAJOR ||
......
......@@ -7,6 +7,16 @@
#include "list.h"
#include "image.h"
struct fd_parms {
unsigned long fd_name;
unsigned long pos;
unsigned int flags;
unsigned int type;
struct stat stat;
u32 id;
pid_t pid;
};
enum fdinfo_states {
FD_STATE_PREP, /* Create unix sockets */
FD_STATE_CREATE, /* Create and send fd */
......
......@@ -22,8 +22,9 @@ struct sk_queue {
};
struct cr_fdset;
extern int dump_socket(pid_t pid, int fd, const struct cr_fdset *cr_fdset,
struct sk_queue *queue);
struct fd_parms;
extern int dump_socket(struct fd_parms *p, int lfd,
const struct cr_fdset *cr_fdset, struct sk_queue *queue);
extern int collect_sockets(void);
extern int prepare_sockets(int pid);
......
......@@ -22,6 +22,7 @@
#include "crtools.h"
#include "util.h"
#include "inet_diag.h"
#include "files.h"
static char buf[4096];
......@@ -381,7 +382,7 @@ err:
return -1;
}
int dump_socket(pid_t pid, int fd, const struct cr_fdset *cr_fdset,
int dump_socket(struct fd_parms *p, int lfd, const struct cr_fdset *cr_fdset,
struct sk_queue *queue)
{
struct socket_desc *sk;
......@@ -389,25 +390,7 @@ int dump_socket(pid_t pid, int fd, const struct cr_fdset *cr_fdset,
struct stat st;
char path[64];
/*
* Sockets are tricky, we can't open it but can
* do stats over and check for sokets magic.
*/
snprintf(buf, sizeof(buf), "/proc/%d/fd/%d", pid, fd);
if (statfs(buf, &fst)) {
pr_perror("Can't statfs %s", buf);
return -1;
}
if (stat(buf, &st)) {
pr_perror("Can't stat %s", buf);
return -1;
}
if (fst.f_type != SOCKFS_MAGIC)
return 1; /* not a socket, proceed with caller error */
sk = lookup_socket(st.st_ino);
sk = lookup_socket(p->stat.st_ino);
if (!sk) {
pr_err("Uncollected socket %ld\n", st.st_ino);
return -1;
......@@ -415,9 +398,9 @@ int dump_socket(pid_t pid, int fd, const struct cr_fdset *cr_fdset,
switch (sk->family) {
case AF_UNIX:
return dump_one_unix(sk, fd, cr_fdset, queue);
return dump_one_unix(sk, p->fd_name, cr_fdset, queue);
case AF_INET:
return dump_one_inet(sk, fd, cr_fdset, queue);
return dump_one_inet(sk, p->fd_name, cr_fdset, queue);
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