exec: Fix memory allocation when memory path isn't on hugetlbfs
[qemu/kevin.git] / qga / guest-agent-command-state.c
blob20b9b22224a5f4080b9a74770efbb20b0a34afe5
1 /*
2 * QEMU Guest Agent command state interfaces
4 * Copyright IBM Corp. 2011
6 * Authors:
7 * Michael Roth <mdroth@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include <glib.h>
14 #include "qga/guest-agent-core.h"
16 struct GACommandState {
17 GSList *groups;
20 typedef struct GACommandGroup {
21 void (*init)(void);
22 void (*cleanup)(void);
23 } GACommandGroup;
25 /* handle init/cleanup for stateful guest commands */
27 void ga_command_state_add(GACommandState *cs,
28 void (*init)(void),
29 void (*cleanup)(void))
31 GACommandGroup *cg = g_new0(GACommandGroup, 1);
32 cg->init = init;
33 cg->cleanup = cleanup;
34 cs->groups = g_slist_append(cs->groups, cg);
37 static void ga_command_group_init(gpointer opaque, gpointer unused)
39 GACommandGroup *cg = opaque;
41 g_assert(cg);
42 if (cg->init) {
43 cg->init();
47 void ga_command_state_init_all(GACommandState *cs)
49 g_assert(cs);
50 g_slist_foreach(cs->groups, ga_command_group_init, NULL);
53 static void ga_command_group_cleanup(gpointer opaque, gpointer unused)
55 GACommandGroup *cg = opaque;
57 g_assert(cg);
58 if (cg->cleanup) {
59 cg->cleanup();
63 void ga_command_state_cleanup_all(GACommandState *cs)
65 g_assert(cs);
66 g_slist_foreach(cs->groups, ga_command_group_cleanup, NULL);
69 GACommandState *ga_command_state_new(void)
71 GACommandState *cs = g_new0(GACommandState, 1);
72 cs->groups = NULL;
73 return cs;