]> git.ozlabs.org Git - petitboot/blob - discover/device-handler.h
discover: Don't free clients on write failure
[petitboot] / discover / device-handler.h
1 #ifndef _DEVICE_HANDLER_H
2 #define _DEVICE_HANDLER_H
3
4 #include <stdbool.h>
5
6 #include <list/list.h>
7
8 struct device_handler;
9 struct discover_device;
10 struct discover_server;
11 struct boot_option;
12 struct boot_command;
13 struct event;
14 struct device;
15 struct waitset;
16
17 enum conf_method {
18         CONF_METHOD_LOCAL_FILE, /* discover by looking at local files on this
19                                    block device */
20
21         CONF_METHOD_DHCP,       /* configuration from a DHCP response */
22
23         CONF_METHOD_UNKNOWN = -1,
24 };
25
26
27 struct discover_device {
28         struct device           *device;
29
30         char                    **links;
31         int                     n_links;
32
33         const char              *uuid;
34         const char              *label;
35
36         char                    *mount_path;
37         const char              *device_path;
38         bool                    mounted;
39         bool                    mounted_rw;
40         bool                    unmount;
41
42         bool                    notified;
43
44         struct list             boot_options;
45         struct list             params;
46 };
47
48 struct discover_boot_option {
49         struct parser           *source;
50         struct discover_device  *device;
51         struct boot_option      *option;
52         struct list_item        list;
53
54         struct resource         *boot_image;
55         struct resource         *initrd;
56         struct resource         *dtb;
57         struct resource         *icon;
58 };
59
60
61 struct discover_context {
62         struct parser           *parser;
63         struct event            *event;
64         struct discover_device  *device;
65         struct list             boot_options;
66         struct pb_url           *conf_url;
67         enum conf_method        method;
68         void                    *test_data;
69 };
70
71 struct device_handler *device_handler_init(struct discover_server *server,
72                 struct waitset *waitset, int dry_run);
73
74 void device_handler_destroy(struct device_handler *devices);
75
76 int device_handler_get_device_count(const struct device_handler *handler);
77 const struct discover_device *device_handler_get_device(
78         const struct device_handler *handler, unsigned int index);
79
80 struct discover_device *discover_device_create(struct device_handler *handler,
81                 const char *id);
82 void device_handler_add_device(struct device_handler *handler,
83                 struct discover_device *device);
84 int device_handler_discover(struct device_handler *handler,
85                 struct discover_device *dev, enum conf_method method);
86 int device_handler_conf(struct device_handler *handler,
87                 struct discover_device *dev, struct pb_url *url,
88                 enum conf_method method);
89 void device_handler_remove(struct device_handler *handler,
90                 struct discover_device *device);
91
92 struct discover_context *device_handler_discover_context_create(
93                 struct device_handler *handler,
94                 struct discover_device *device);
95 void device_handler_discover_context_commit(struct device_handler *handler,
96                 struct discover_context *ctx);
97
98 struct discover_boot_option *discover_boot_option_create(
99                 struct discover_context *ctx,
100                 struct discover_device *dev);
101 void discover_context_add_boot_option(struct discover_context *ctx,
102                 struct discover_boot_option *opt);
103
104 int device_handler_user_event(struct device_handler *handler,
105                                 struct event *event);
106
107 struct discover_device *device_lookup_by_name(struct device_handler *handler,
108                 const char *name);
109 struct discover_device *device_lookup_by_uuid(struct device_handler *handler,
110                 const char *uuid);
111 struct discover_device *device_lookup_by_label(struct device_handler *handler,
112                 const char *label);
113 struct discover_device *device_lookup_by_id(struct device_handler *handler,
114                 const char *id);
115 struct discover_device *device_lookup_by_serial(
116                 struct device_handler *device_handler,
117                 const char *serial);
118
119 void discover_device_set_param(struct discover_device *device,
120                 const char *name, const char *value);
121 const char *discover_device_get_param(struct discover_device *device,
122                 const char *name);
123
124 void device_handler_boot(struct device_handler *handler,
125                 struct boot_command *cmd);
126 void device_handler_cancel_default(struct device_handler *handler);
127
128 int device_request_write(struct discover_device *dev, bool *release);
129 void device_release_write(struct discover_device *dev, bool release);
130
131 #endif /* _DEVICE_HANDLER_H */