]> git.ozlabs.org Git - petitboot/blob - discover/device-handler.h
discover/event: Ensure event struct exists for async callers
[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 #include <types/types.h>
8
9 struct device_handler;
10 struct discover_device;
11 struct discover_server;
12 struct boot_option;
13 struct boot_command;
14 struct event;
15 struct device;
16 struct waitset;
17 struct config;
18
19 struct discover_device {
20         struct device           *device;
21
22         char                    **links;
23         int                     n_links;
24
25         const char              *uuid;
26         const char              *label;
27
28         char                    *mount_path;
29         char                    *root_path;
30         const char              *device_path;
31         struct ramdisk_device   *ramdisk;
32         bool                    mounted;
33         bool                    mounted_rw;
34         bool                    unmount;
35
36         bool                    notified;
37
38         struct list             boot_options;
39         struct list             params;
40 };
41
42 struct discover_boot_option {
43         struct parser           *source;
44         struct discover_device  *device;
45         struct boot_option      *option;
46         struct list_item        list;
47
48         struct resource         *boot_image;
49         struct resource         *initrd;
50         struct resource         *dtb;
51         struct resource         *args_sig_file;
52         struct resource         *icon;
53 };
54
55
56 struct discover_context {
57         struct parser           *parser;
58         struct event            *event;
59         struct discover_device  *device;
60         struct list             boot_options;
61         struct pb_url           *conf_url;
62         struct network          *network;
63         void                    *test_data;
64 };
65
66 struct ramdisk_device {
67         const char      *path;
68         char            *snapshot;
69         char            *origin;
70         char            *base;
71         uint64_t        sectors;
72 };
73
74 struct device_handler *device_handler_init(struct discover_server *server,
75                 struct waitset *waitset, int dry_run);
76
77 void device_handler_destroy(struct device_handler *devices);
78
79 int device_handler_get_device_count(const struct device_handler *handler);
80 const struct discover_device *device_handler_get_device(
81         const struct device_handler *handler, unsigned int index);
82
83 struct discover_device *discover_device_create(struct device_handler *handler,
84                 const char *id);
85 void device_handler_add_device(struct device_handler *handler,
86                 struct discover_device *device);
87 void device_handler_add_ramdisk(struct device_handler *handler,
88                 const char *path);
89 struct ramdisk_device *device_handler_get_ramdisk(
90                 struct device_handler *handler);
91 void device_handler_release_ramdisk(struct discover_device *device);
92 int device_handler_discover(struct device_handler *handler,
93                 struct discover_device *dev);
94 int device_handler_dhcp(struct device_handler *handler,
95                 struct discover_device *dev, struct event *event);
96 int device_handler_conf(struct device_handler *handler,
97                 struct discover_device *dev, struct pb_url *url);
98 void device_handler_remove(struct device_handler *handler,
99                 struct discover_device *device);
100
101 void device_handler_boot_status(void *arg, struct boot_status *status);
102
103 struct discover_context *device_handler_discover_context_create(
104                 struct device_handler *handler,
105                 struct discover_device *device);
106 void device_handler_discover_context_commit(struct device_handler *handler,
107                 struct discover_context *ctx);
108
109 struct discover_boot_option *discover_boot_option_create(
110                 struct discover_context *ctx,
111                 struct discover_device *dev);
112 void discover_context_add_boot_option(struct discover_context *ctx,
113                 struct discover_boot_option *opt);
114
115 int device_handler_user_event(struct device_handler *handler,
116                                 struct event *event);
117
118 struct discover_device *device_lookup_by_name(struct device_handler *handler,
119                 const char *name);
120 struct discover_device *device_lookup_by_uuid(struct device_handler *handler,
121                 const char *uuid);
122 struct discover_device *device_lookup_by_label(struct device_handler *handler,
123                 const char *label);
124 struct discover_device *device_lookup_by_id(struct device_handler *handler,
125                 const char *id);
126 struct discover_device *device_lookup_by_serial(
127                 struct device_handler *device_handler,
128                 const char *serial);
129
130 void discover_device_set_param(struct discover_device *device,
131                 const char *name, const char *value);
132 const char *discover_device_get_param(struct discover_device *device,
133                 const char *name);
134
135 void device_handler_boot(struct device_handler *handler,
136                 struct boot_command *cmd);
137 void device_handler_cancel_default(struct device_handler *handler);
138 void device_handler_update_config(struct device_handler *handler,
139                 struct config *config);
140 void device_handler_process_url(struct device_handler *handler,
141                 const char *url, const char *mac, const char *ip);
142 void device_handler_reinit(struct device_handler *handler);
143
144 int device_request_write(struct discover_device *dev, bool *release);
145 void device_release_write(struct discover_device *dev, bool release);
146 void device_sync_snapshots(struct device_handler *handler, const char *device);
147
148 #endif /* _DEVICE_HANDLER_H */