Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
struct device *devices;
int n_devices;
struct device *devices;
int n_devices;
+
+ struct list contexts;
};
struct discover_context {
};
struct discover_context {
-static struct list contexts;
static struct boot_option options[] = {
{
static struct boot_option options[] = {
{
-static struct discover_context *find_context(const char *id)
+static struct discover_context *find_context(struct device_handler *handler,
+ const char *id)
{
struct discover_context *ctx;
{
struct discover_context *ctx;
- list_for_each_entry(&contexts, ctx, list) {
+ list_for_each_entry(&handler->contexts, ctx, list) {
if (!strcmp(ctx->id, id))
return ctx;
}
if (!strcmp(ctx->id, id))
return ctx;
}
int rc;
/* create our context */
int rc;
/* create our context */
- ctx = talloc(NULL, struct discover_context);
+ ctx = talloc(handler, struct discover_context);
ctx->event = event;
ctx->mount_path = NULL;
ctx->links = NULL;
ctx->event = event;
ctx->mount_path = NULL;
ctx->links = NULL;
- list_add(&contexts, &ctx->list);
+ list_add(&handler->contexts, &ctx->list);
talloc_set_destructor(ctx, destroy_context);
talloc_set_destructor(ctx, destroy_context);
{
struct discover_context *ctx;
{
struct discover_context *ctx;
- ctx = find_context(event->device);
+ ctx = find_context(handler, event->device);
handler->devices = NULL;
handler->n_devices = 0;
handler->devices = NULL;
handler->n_devices = 0;
+ list_init(&handler->contexts);
/* set up our mount point base */
mkdir_recursive(mount_base());
/* set up our mount point base */
mkdir_recursive(mount_base());
-void device_handler_destroy(struct device_handler *devices)
+void device_handler_destroy(struct device_handler *handler)
- struct discover_context *ctx, *n;
-
- talloc_free(devices);
-
- list_for_each_entry_safe(&contexts, ctx, n, list)
- talloc_free(ctx);
&pos->member != &(list)->head; \
pos = list_entry(pos->member.next, typeof(*pos), member))
&pos->member != &(list)->head; \
pos = list_entry(pos->member.next, typeof(*pos), member))
-#define list_for_each_entry_safe(list, pos, n, member) \
- for (pos = list_entry((list)->head.next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != &(list)->head; \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
-
-
void list_init(struct list *list);
void list_add(struct list *list, struct list_item *item);
void list_init(struct list *list);
void list_add(struct list *list, struct list_item *item);