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