Skip to content

Commit

Permalink
irmap: add --irmap-scan-path option
Browse files Browse the repository at this point in the history
This option allows users to specify their own irmap paths to scan in the event
that they don't have a path in one of the hard coded hints.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
Tycho Andersen authored and xemul committed Sep 21, 2015
1 parent d3be641 commit 4f2e4ab
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cr-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "action-scripts.h"
#include "security.h"
#include "sockets.h"
#include "irmap.h"

#include "setproctitle.h"

Expand Down Expand Up @@ -445,6 +446,13 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
if (req->has_ghost_limit)
opts.ghost_limit = req->ghost_limit;

if (req->n_irmap_scan_paths) {
for (i = 0; i < req->n_irmap_scan_paths; i++) {
if (irmap_scan_path_add(req->irmap_scan_paths[i]))
goto err;
}
}

return 0;

err:
Expand Down
9 changes: 9 additions & 0 deletions crtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "cpu.h"
#include "action-scripts.h"
#include "security.h"
#include "irmap.h"

#include "setproctitle.h"

Expand All @@ -56,6 +57,7 @@ void init_opts(void)
INIT_LIST_HEAD(&opts.ext_mounts);
INIT_LIST_HEAD(&opts.inherit_fds);
INIT_LIST_HEAD(&opts.new_cgroup_roots);
INIT_LIST_HEAD(&opts.irmap_scan_paths);

opts.cpu_cap = CPU_CAP_DEFAULT;
opts.manage_cgroups = CG_MODE_DEFAULT;
Expand Down Expand Up @@ -249,6 +251,7 @@ int main(int argc, char *argv[], char *envp[])
{ "enable-external-masters", no_argument, 0, 1067 },
{ "freeze-cgroup", required_argument, 0, 1068 },
{ "ghost-limit", required_argument, 0, 1069 },
{ "irmap-scan-path", required_argument, 0, 1070 },
{ },
};

Expand Down Expand Up @@ -487,6 +490,10 @@ int main(int argc, char *argv[], char *envp[])
case 1069:
opts.ghost_limit = parse_size(optarg);
break;
case 1070:
if (irmap_scan_path_add(optarg))
return -1;
break;
case 'M':
{
char *aux;
Expand Down Expand Up @@ -719,6 +726,8 @@ int main(int argc, char *argv[], char *envp[])
" -l|--" OPT_FILE_LOCKS " handle file locks, for safety, only used for container\n"
" -L|--libdir path to a plugin directory (by default " CR_PLUGIN_DEFAULT ")\n"
" --force-irmap force resolving names for inotify/fsnotify watches\n"
" --irmap-scan-path FILE\n"
" add a path the irmap hints to scan\n"
" -M|--ext-mount-map KEY:VALUE\n"
" add external mount mapping\n"
" -M|--ext-mount-map auto\n"
Expand Down
6 changes: 6 additions & 0 deletions include/cr_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ struct cg_root_opt {
*/
#define DEFAULT_GHOST_LIMIT (1 << 20)

struct irmap_path_opt {
struct list_head node;
char *path;
};

struct cr_options {
int final_state;
char *show_dump_file;
Expand Down Expand Up @@ -87,6 +92,7 @@ struct cr_options {
bool aufs; /* auto-deteced, not via cli */
bool overlayfs;
size_t ghost_limit;
struct list_head irmap_scan_paths;
};

extern struct cr_options opts;
Expand Down
1 change: 1 addition & 0 deletions include/irmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ int irmap_predump_run(void);
int check_open_handle(unsigned int s_dev, unsigned long i_ino,
struct _FhEntry *f_handle);
int irmap_load_cache(void);
int irmap_scan_path_add(char *path);
#endif
36 changes: 36 additions & 0 deletions irmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "image.h"
#include "stats.h"
#include "pstree.h"
#include "cr_options.h"

#include "protobuf.h"
#include "protobuf/fsnotify.pb-c.h"
Expand Down Expand Up @@ -229,6 +230,7 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino)
struct irmap *c, *h, **p;
char *path = NULL;
int hv;
struct irmap_path_opt *o;

s_dev = kdev_to_odev(s_dev);

Expand Down Expand Up @@ -260,6 +262,27 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino)
goto out;
}

/* Let's scan any user provided paths first; since the user told us
* about them, hopefully they're more interesting than our hints.
*/
list_for_each_entry(o, &opts.irmap_scan_paths, node) {
struct irmap *ir;

ir = xzalloc(sizeof(*ir));
if (!ir)
goto out;

ir->nr_kids = -1;
ir->path = o->path;

c = irmap_scan(ir, s_dev, i_ino);
if (c) {
pr_debug("\tScanned %s\n", c->path);
path = c->path;
goto out;
}
}

for (h = hints; h->path; h++) {
pr_debug("Scanning %s hint\n", h->path);
c = irmap_scan(h, s_dev, i_ino);
Expand Down Expand Up @@ -457,3 +480,16 @@ int irmap_load_cache(void)
close_image(img);
return ret;
}

int irmap_scan_path_add(char *path)
{
struct irmap_path_opt *o;

o = xmalloc(sizeof(*o));
if (!o)
return -1;

o->path = path;
list_add(&o->node, &opts.irmap_scan_paths);
return 0;
}
39 changes: 39 additions & 0 deletions lib/criu.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,40 @@ int criu_local_add_skip_mnt(criu_opts *opts, char *mnt)
return -ENOMEM;
}

int criu_local_add_irmap_path(criu_opts *opts, char *path)
{
int nr;
char *my_path;
char **m;

if (!opts)
return -1;

my_path = strdup(path);
if (!my_path)
goto err;

nr = opts->rpc->n_irmap_scan_paths + 1;
m = realloc(opts->rpc->irmap_scan_paths, nr * sizeof(*m));
if (!m)
goto err;

m[nr - 1] = my_path;

opts->rpc->n_irmap_scan_paths = nr;
opts->rpc->irmap_scan_paths = m;

return 0;

err:
if (my_path)
free(my_path);
if (m)
free(m);

return -ENOMEM;
}

int criu_add_skip_mnt(char *mnt)
{
return criu_local_add_skip_mnt(global_opts, mnt);
Expand All @@ -685,6 +719,11 @@ void criu_set_ghost_limit(unsigned int limit)
criu_local_set_ghost_limit(global_opts, limit);
}

int criu_add_irmap_path(char *path)
{
return criu_local_add_irmap_path(global_opts, path);
}

static CriuResp *recv_resp(int socket_fd)
{
unsigned char *buf;
Expand Down
2 changes: 2 additions & 0 deletions lib/criu.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ int criu_add_cg_root(char *ctrl, char *path);
int criu_add_enable_fs(char *fs);
int criu_add_skip_mnt(char *mnt);
void criu_set_ghost_limit(unsigned int limit);
int criu_add_irmap_path(char *path);

/*
* The criu_notify_arg_t na argument is an opaque
Expand Down Expand Up @@ -189,6 +190,7 @@ int criu_local_add_cg_root(criu_opts *opts, char *ctrl, char *path);
int criu_local_add_enable_fs(criu_opts *opts, char *fs);
int criu_local_add_skip_mnt(criu_opts *opts, char *mnt);
void criu_local_set_ghost_limit(criu_opts *opts, unsigned int limit);
int criu_local_add_irmap_path(criu_opts *opts, char *path);

void criu_local_set_notify_cb(criu_opts *opts, int (*cb)(char *action, criu_notify_arg_t na));

Expand Down
1 change: 1 addition & 0 deletions protobuf/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ message criu_opts {

optional criu_cg_mode manage_cgroups_mode = 34;
optional uint32 ghost_limit = 35 [default = 0x100000];
repeated string irmap_scan_paths = 36;
}

message criu_dump_resp {
Expand Down

0 comments on commit 4f2e4ab

Please sign in to comment.