machine.h revision f00c31213a2e521680c2381ef231f05e30c874a7
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner#pragma once
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner/***
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner This file is part of systemd.
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner Copyright 2013 Lennart Poettering
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner systemd is free software; you can redistribute it and/or modify it
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner under the terms of the GNU Lesser General Public License as published by
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner the Free Software Foundation; either version 2.1 of the License, or
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner (at your option) any later version.
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner systemd is distributed in the hope that it will be useful, but
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner WITHOUT ANY WARRANTY; without even the implied warranty of
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner Lesser General Public License for more details.
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner You should have received a copy of the GNU Lesser General Public License
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner along with systemd; If not, see <http://www.gnu.org/licenses/>.
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner***/
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknertypedef struct Machine Machine;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknertypedef enum KillWho KillWho;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner#include "list.h"
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner#include "util.h"
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner#include "machined.h"
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknertypedef enum MachineState {
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MACHINE_OPENING, /* Machine is being registered */
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MACHINE_RUNNING, /* Machine is running */
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MACHINE_CLOSING, /* Machine is terminating */
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner _MACHINE_STATE_MAX,
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner _MACHINE_STATE_INVALID = -1
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner} MachineState;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknertypedef enum MachineClass {
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MACHINE_CONTAINER,
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MACHINE_VM,
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner _MACHINE_CLASS_MAX,
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner _MACHINE_CLASS_INVALID = -1
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner} MachineClass;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerenum KillWho {
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner KILL_LEADER,
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner KILL_ALL,
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner _KILL_WHO_MAX,
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner _KILL_WHO_INVALID = -1
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner};
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerstruct Machine {
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner Manager *manager;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner char *name;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner sd_id128_t id;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MachineState state;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner MachineClass class;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner char *state_file;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner char *service;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner char *root_directory;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner char *scope;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner char *scope_job;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner pid_t leader;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner dual_timestamp timestamp;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner bool in_gc_queue:1;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner bool started:1;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner sd_bus_message *create_message;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner LIST_FIELDS(Machine, gc_queue);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner};
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens ElknerMachine* machine_new(Manager *manager, const char *name);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknervoid machine_free(Machine *m);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerbool machine_check_gc(Machine *m, bool drop_not_started);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknervoid machine_add_to_gc_queue(Machine *m);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_stop(Machine *m);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_save(Machine *m);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_load(Machine *m);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_kill(Machine *m, KillWho who, int signo);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens ElknerMachineState machine_get_state(Machine *u);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerextern const sd_bus_vtable machine_vtable[];
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerchar *machine_bus_path(Machine *s);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_send_signal(Machine *m, bool new_machine);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerint machine_send_create_reply(Machine *m, sd_bus_error *error);
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerconst char* machine_class_to_string(MachineClass t) _const_;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens ElknerMachineClass machine_class_from_string(const char *s) _pure_;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerconst char* machine_state_to_string(MachineState t) _const_;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens ElknerMachineState machine_state_from_string(const char *s) _pure_;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elknerconst char *kill_who_to_string(KillWho k) _const_;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens ElknerKillWho kill_who_from_string(const char *s) _pure_;
1d92f18454c8f1ddbb762659f72afb518b53c85fJens Elkner