-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
criu: Add pidfd support #2259
base: criu-dev
Are you sure you want to change the base?
criu: Add pidfd support #2259
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ enum { | |
CR_FD_PIPES, | ||
CR_FD_TTY_FILES, | ||
CR_FD_MEMFD_FILE, | ||
CR_FD_PIDFD, | ||
|
||
CR_FD_AUTOFS, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ | |
#define BPFMAP_FILE_MAGIC 0x57506142 /* Alapayevsk */ | ||
#define BPFMAP_DATA_MAGIC 0x64324033 /* Arkhangelsk */ | ||
#define APPARMOR_MAGIC 0x59423047 /* Nikolskoye */ | ||
#define PIDFD_MAGIC 0x59423447 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we tend to use location coordinates of a city as a magic number. For example, Nikolskoye is a city with the following coordinates (from Wikipedia) 59°42'N 30°47'E -> 0x59423047. |
||
|
||
#define IFADDR_MAGIC RAW_IMAGE_MAGIC | ||
#define ROUTE_MAGIC RAW_IMAGE_MAGIC | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef __CR_PIDFD_H__ | ||
#define __CR_PIDFD_H__ | ||
|
||
#include <sys/stat.h> | ||
#include "images/pidfd.pb-c.h" | ||
#include <sys/syscall.h> | ||
#include <unistd.h> | ||
|
||
struct fd_parms; | ||
|
||
extern const struct fdtype_ops pidfd_dump_ops; | ||
extern struct collect_image_info pidfd_cinfo; | ||
extern int is_pidfd_link(char *link); | ||
|
||
static inline int pidfd_open(pid_t pid, unsigned int flags) | ||
{ | ||
return syscall(__NR_pidfd_open, pid, flags); | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ enum { | |
PB_SK_QUEUES, | ||
PB_IPCNS_MSG, | ||
PB_IPCNS_MSG_ENT, | ||
PB_PIDFD, | ||
|
||
PB_MAX, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "pidfd.h" | ||
#include "util.h" | ||
|
||
#include "fdinfo.h" | ||
#include "files.h" | ||
#include "imgset.h" | ||
#include "protobuf.h" | ||
#include "fdinfo.pb-c.h" | ||
|
||
int is_pidfd_link(char *link) | ||
{ | ||
return is_anon_link_type(link, "[pidfd]"); | ||
} | ||
|
||
static int dump_one_pidfd(int lfd, u32 id, const struct fd_parms *p) | ||
{ | ||
PidfdEntry tfe = PIDFD_ENTRY__INIT; | ||
FileEntry fe = FILE_ENTRY__INIT; | ||
|
||
if (parse_fdinfo(lfd, FD_TYPES__PIDFD, &tfe)) | ||
return -1; | ||
|
||
tfe.id = id; | ||
tfe.flags = p->flags; | ||
tfe.inode = p->stat.st_ino; | ||
tfe.mnt_id = p->mnt_id; | ||
tfe.fown = (FownEntry *)&p->fown; | ||
|
||
fe.type = FD_TYPES__PIDFD; | ||
fe.id = tfe.id; | ||
fe.pidfd = &tfe; | ||
|
||
return pb_write_one(img_from_set(glob_imgset, CR_FD_FILES), &fe, PB_FILE); | ||
} | ||
|
||
const struct fdtype_ops pidfd_dump_ops = { | ||
.type = FD_TYPES__PIDFD, | ||
.dump = dump_one_pidfd, | ||
}; | ||
|
||
struct pidfd_info { | ||
PidfdEntry *pidfde; | ||
struct file_desc d; | ||
}; | ||
|
||
static int open_pidfd_fd(struct file_desc *d, int *new_fd) | ||
{ | ||
int fd = -1; | ||
struct pidfd_info *info = container_of(d, struct pidfd_info, d); | ||
PidfdEntry *pidfde = info->pidfde; | ||
|
||
pr_info("Creating new pidfd %" PRId64 "\n", pidfde->pid); | ||
fd = pidfd_open(pidfde->pid, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a task linked to fd can be dead and pidfd_open will fail in this case. |
||
if (fd < 0) { | ||
pr_perror("Cannot create pidfd %" PRId64, pidfde->pid); | ||
return -1; | ||
} | ||
|
||
*new_fd = fd; | ||
return 0; | ||
} | ||
|
||
static struct file_desc_ops pidfd_desc_ops = { | ||
.type = FD_TYPES__PIDFD, | ||
.open = open_pidfd_fd, | ||
}; | ||
|
||
static int collect_one_pidfd(void *o, ProtobufCMessage *msg, struct cr_img *i) | ||
{ | ||
struct pidfd_info *info = o; | ||
|
||
info->pidfde = pb_msg(msg, PidfdEntry); | ||
return file_desc_add(&info->d, info->pidfde->id, &pidfd_desc_ops); | ||
} | ||
|
||
struct collect_image_info pidfd_cinfo = { | ||
.fd_type = CR_FD_PIDFD, | ||
.pb_type = PB_PIDFD, | ||
.priv_size = sizeof(struct pidfd_info), | ||
.collect = collect_one_pidfd, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
syntax = "proto2"; | ||
|
||
import "fown.proto"; | ||
|
||
message pidfd_entry { | ||
required uint32 id = 1; | ||
required uint64 pos = 2; | ||
required uint32 flags = 3; | ||
required uint32 mnt_id = 4; | ||
required uint64 inode = 5; | ||
required int64 pid = 6; | ||
required int64 nspid = 7; | ||
required fown_entry fown = 8; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks unnecessary.