[3/6] ext: Add more helpers to mess with external resources.

Submitted by Pavel Emelianov on Sept. 20, 2016, 1:26 p.m.

Details

Message ID 57E13904.80807@virtuozzo.com
State Accepted
Series "Unify external resources in CLI"
Commit 13c28ece9aa23f95a2349494d85ccad4f2490a87
Headers show

Commit Message

Pavel Emelianov Sept. 20, 2016, 1:26 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/external.c         | 19 +++++++++++++++++++
 criu/include/external.h | 15 +++++++++++++++
 2 files changed, 34 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/external.c b/criu/external.c
index bb7ef06..f3459df 100644
--- a/criu/external.c
+++ b/criu/external.c
@@ -40,3 +40,22 @@  char *external_lookup_by_key(char *key)
 	return NULL;
 }
 
+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;
+}
diff --git a/criu/include/external.h b/criu/include/external.h
index d343732..98e4258 100644
--- a/criu/include/external.h
+++ b/criu/include/external.h
@@ -8,4 +8,19 @@  struct external {
 extern int add_external(char *key);
 extern bool external_lookup_id(char *id);
 extern char *external_lookup_by_key(char *id);
+extern int external_for_each_type(char *type, int (*cb)(struct external *, void *), void *arg);
+
+static inline char *external_val(struct external *e)
+{
+	char *aux;
+
+	aux = strchr(e->id, '[');
+	if (aux) {
+		aux = strchr(aux + 1, ']');
+		if (aux && aux[1] == ':')
+			return aux + 2;
+	}
+
+	return NULL;
+}
 #endif