Welcome to mirror list, hosted at ThFree Co, Russian Federation.

external.c « criu - github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbbcd17cbc95428544f1dbf22761405eadf001ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "common/err.h"
#include "common/list.h"
#include "cr_options.h"
#include "xmalloc.h"
#include "mount.h"
#include "external.h"
#include "util.h"

#include "net.h"

int add_external(char *key)
{
	struct external *ext;

	if (strstartswith(key, "mnt[]"))
		return ext_mount_parse_auto(key + 5);

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

	ext->id = xstrdup(key);
	if (!ext->id)
		goto err_id;

	if (strstartswith(key, "macvlan") && macvlan_ext_add(ext) < 0)
		goto err;

	list_add(&ext->node, &opts.external);

	return 0;
err:
	xfree(ext->id);
err_id:
	xfree(ext);
	return -1;
}

bool external_lookup_id(char *id)
{
	struct external *ext;

	list_for_each_entry(ext, &opts.external, node)
		if (!strcmp(ext->id, id))
			return true;
	return false;
}

void *external_lookup_data(char *key)
{
	struct external *ext;
	int len = strlen(key);

	list_for_each_entry(ext, &opts.external, node) {
		if (strncmp(ext->id, key, len))
			continue;

		return ext->data;
	}

	return ERR_PTR(-ENOENT);
}

char *external_lookup_by_key(char *key)
{
	struct external *ext;
	int len = strlen(key);

	list_for_each_entry(ext, &opts.external, node) {
		if (strncmp(ext->id, key, len))
			continue;
		if (ext->id[len] == ':')
			return ext->id + len + 1;
		else if (ext->id[len] == '\0')
			return NULL;
	}
	return ERR_PTR(-ENOENT);
}

int external_for_each_type(char *type, int (*cb)(struct external *, void *), void *arg)
{
	struct external *ext;
	int ln = strlen(type);
	int ret = 0;

	list_for_each_entry(ext, &opts.external, node) {
		if (strncmp(ext->id, type, ln))
			continue;
		if (ext->id[ln] != '[')
			continue;

		ret = cb(ext, arg);
		if (ret)
			break;
	}

	return ret;
}