+struct requery_data {
+ struct device_handler *handler;
+ struct discover_device *device;
+};
+
+static int device_handler_requery_timeout_fn(void *data)
+{
+ struct discover_boot_option *opt, *tmp;
+ struct requery_data *rqd = data;
+ struct device_handler *handler;
+ struct discover_device *device;
+ bool autoboot;
+
+ handler = rqd->handler;
+ device = rqd->device;
+
+ talloc_free(rqd);
+
+ /* network_requery_device may re-add a timeout, so clear the device
+ * waiter here, so we can potentially start a new one. */
+ device->requery_waiter = NULL;
+
+ /* We keep the device around, but get rid of the parsed boot
+ * options on that device. That involves delaring out the lists,
+ * and potentially cancelling a default.
+ */
+ list_for_each_entry_safe(&handler->unresolved_boot_options,
+ opt, tmp, list) {
+ if (opt->device != device)
+ continue;
+ list_remove(&opt->list);
+ talloc_free(opt);
+ }
+
+ /* Track whether autoboot was enabled, if we cancel a default option
+ * it will be switched off.
+ */
+ autoboot = handler->autoboot_enabled;
+
+ list_for_each_entry_safe(&device->boot_options, opt, tmp, list) {
+ if (opt == handler->default_boot_option) {
+ pb_log("Default option %s cancelled since device is being requeried\n",
+ opt->option->name);
+ device_handler_cancel_default(handler);
+ }
+ list_remove(&opt->list);
+ talloc_free(opt);
+ }
+
+ handler->autoboot_enabled = autoboot;
+
+ discover_server_notify_device_remove(handler->server, device->device);
+ device->notified = false;
+
+ network_requery_device(handler->network, device);
+
+ return 0;
+}
+
+/* Schedule a requery in timeout (seconds).
+ *
+ * Special values of timeout:
+ * 0: no requery
+ * -1: use default
+ */
+void device_handler_start_requery_timeout( struct device_handler *handler,
+ struct discover_device *dev, int timeout)
+{
+ struct requery_data *rqd;
+
+ if (dev->requery_waiter)
+ return;
+
+ if (timeout == -1)
+ timeout = default_rescan_timeout;
+ else if (timeout == 0)
+ return;
+
+ rqd = talloc(dev, struct requery_data);
+ rqd->handler = handler;
+ rqd->device = dev;
+
+ pb_debug("starting requery timeout for device %s, in %d sec\n",
+ dev->device->id, timeout);
+
+ dev->requery_waiter = waiter_register_timeout(handler->waitset,
+ timeout * 1000, device_handler_requery_timeout_fn, rqd);
+}
+
+static int event_requery_timeout(struct event *event)
+{
+ int timeout = -1;
+ unsigned long x;
+ const char *str;
+ char *endp;
+
+ if (!event)
+ return timeout;
+
+ str = event_get_param(event, "reboottime");
+ if (!str)
+ return timeout;
+
+ x = strtoul(str, &endp, 0);
+ if (endp != str)
+ timeout = x;
+
+ return timeout;
+}
+
+