summaryrefslogtreecommitdiff
path: root/src/machine/operation.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-29 20:32:56 +0200
committerLennart Poettering <lennart@poettering.net>2016-05-02 11:17:06 +0200
commit795c5d31affeb3b3edbf673940cc0f16afebc7a8 (patch)
treeffd79868bad763f8bfa094f7a4b6c0e824333bb5 /src/machine/operation.c
parent5d2036b5f3506bd0ff07042aee8d69c26db32298 (diff)
machined: rework copy-from/copy-to operation to use generic Operation object
With this all potentially slow operations are done out-of-process, asynchronously, using the same "Operation" object.
Diffstat (limited to 'src/machine/operation.c')
-rw-r--r--src/machine/operation.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/machine/operation.c b/src/machine/operation.c
index e8564c29f7..e6ddc41a55 100644
--- a/src/machine/operation.c
+++ b/src/machine/operation.c
@@ -66,15 +66,20 @@ fail:
return 0;
}
-int operation_new(Manager *m, pid_t child, sd_bus_message *message, int errno_fd) {
+int operation_new(Manager *manager, Machine *machine, pid_t child, sd_bus_message *message, int errno_fd) {
Operation *o;
int r;
+ assert(manager);
+ assert(child > 1);
+ assert(message);
+ assert(errno_fd >= 0);
+
o = new0(Operation, 1);
if (!o)
return -ENOMEM;
- r = sd_event_add_child(m->event, &o->event_source, child, WEXITED, operation_done, o);
+ r = sd_event_add_child(manager->event, &o->event_source, child, WEXITED, operation_done, o);
if (r < 0) {
free(o);
return r;
@@ -84,9 +89,14 @@ int operation_new(Manager *m, pid_t child, sd_bus_message *message, int errno_fd
o->message = sd_bus_message_ref(message);
o->errno_fd = errno_fd;
- LIST_PREPEND(operations, m->operations, o);
- m->n_operations++;
- o->manager = m;
+ LIST_PREPEND(operations, manager->operations, o);
+ manager->n_operations++;
+ o->manager = manager;
+
+ if (machine) {
+ LIST_PREPEND(operations_by_machine, machine->operations, o);
+ o->machine = machine;
+ }
log_debug("Started new operation " PID_FMT ".", child);
@@ -113,6 +123,9 @@ Operation *operation_free(Operation *o) {
o->manager->n_operations--;
}
+ if (o->machine)
+ LIST_REMOVE(operations_by_machine, o->machine->operations, o);
+
free(o);
return NULL;
}