mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 22:35:33 +00:00
proc_parse: parse fdinfo to get pos and flags
We are going to parse fdinfo for getting mnt_id, so we can take there pos and flags and don't call fcntl and lseek for that. Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
d36e07aabe
commit
8bcffef6b9
14
files.c
14
files.c
@@ -34,6 +34,7 @@
|
|||||||
#include "tun.h"
|
#include "tun.h"
|
||||||
#include "fdset.h"
|
#include "fdset.h"
|
||||||
#include "fs-magic.h"
|
#include "fs-magic.h"
|
||||||
|
#include "proc_parse.h"
|
||||||
|
|
||||||
#include "parasite.h"
|
#include "parasite.h"
|
||||||
#include "parasite-syscall.h"
|
#include "parasite-syscall.h"
|
||||||
@@ -204,6 +205,7 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct statfs fsbuf;
|
struct statfs fsbuf;
|
||||||
|
struct fdinfo_common fdinfo;
|
||||||
|
|
||||||
if (fstat(lfd, &p->stat) < 0) {
|
if (fstat(lfd, &p->stat) < 0) {
|
||||||
pr_perror("Can't stat fd %d", lfd);
|
pr_perror("Can't stat fd %d", lfd);
|
||||||
@@ -215,16 +217,14 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parse_fdinfo(lfd, FD_TYPES__UND, NULL, &fdinfo))
|
||||||
|
return -1;
|
||||||
|
|
||||||
p->fs_type = fsbuf.f_type;
|
p->fs_type = fsbuf.f_type;
|
||||||
p->ctl = ctl;
|
p->ctl = ctl;
|
||||||
p->fd = fd;
|
p->fd = fd;
|
||||||
p->pos = lseek(lfd, 0, SEEK_CUR);
|
p->pos = fdinfo.pos;
|
||||||
ret = fcntl(lfd, F_GETFL);
|
p->flags = fdinfo.flags;
|
||||||
if (ret == -1) {
|
|
||||||
pr_perror("Unable to get fd %d flags", lfd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
p->flags = ret;
|
|
||||||
p->pid = ctl->pid.real;
|
p->pid = ctl->pid.real;
|
||||||
p->fd_flags = opts->flags;
|
p->fd_flags = opts->flags;
|
||||||
|
|
||||||
|
@@ -153,6 +153,11 @@ union fdinfo_entries {
|
|||||||
FanotifyMarkEntry ffy;
|
FanotifyMarkEntry ffy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct fdinfo_common {
|
||||||
|
off64_t pos;
|
||||||
|
int flags;
|
||||||
|
};
|
||||||
|
|
||||||
extern int parse_fdinfo(int fd, int type,
|
extern int parse_fdinfo(int fd, int type,
|
||||||
int (*cb)(union fdinfo_entries *e, void *arg), void *arg);
|
int (*cb)(union fdinfo_entries *e, void *arg), void *arg);
|
||||||
extern int parse_fdinfo_pid(int pid, int fd, int type,
|
extern int parse_fdinfo_pid(int pid, int fd, int type,
|
||||||
|
22
proc_parse.c
22
proc_parse.c
@@ -1020,7 +1020,27 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type,
|
|||||||
while (fgets(str, sizeof(str), f)) {
|
while (fgets(str, sizeof(str), f)) {
|
||||||
union fdinfo_entries entry;
|
union fdinfo_entries entry;
|
||||||
|
|
||||||
if (fdinfo_field(str, "pos") || fdinfo_field(str, "counter"))
|
if (fdinfo_field(str, "pos") ||
|
||||||
|
fdinfo_field(str, "flags")) {
|
||||||
|
unsigned long long val;
|
||||||
|
struct fdinfo_common *fdinfo = arg;
|
||||||
|
|
||||||
|
if (type != FD_TYPES__UND)
|
||||||
|
continue;
|
||||||
|
ret = sscanf(str, "%*s %lli", &val);
|
||||||
|
if (ret != 1)
|
||||||
|
goto parse_err;
|
||||||
|
|
||||||
|
if (fdinfo_field(str, "pos"))
|
||||||
|
fdinfo->pos = val;
|
||||||
|
else if (fdinfo_field(str, "flags"))
|
||||||
|
fdinfo->flags = val;
|
||||||
|
|
||||||
|
entry_met = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == FD_TYPES__UND)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (fdinfo_field(str, "eventfd-count")) {
|
if (fdinfo_field(str, "eventfd-count")) {
|
||||||
|
Reference in New Issue
Block a user