dev->mounted = true;
}
+void device_sync_snapshots(struct device_handler *handler, const char *device)
+{
+ struct discover_device *dev = NULL;
+ unsigned int i;
+
+ if (device) {
+ /* Find matching device and sync */
+ dev = device_lookup_by_name(handler, device);
+ if (!dev) {
+ pb_log("%s: device name '%s' unrecognised\n",
+ __func__, device);
+ return;
+ }
+ if (dev->ramdisk)
+ device_release_write(dev, true);
+ else
+ pb_log("%s has no snapshot to merge, skipping\n",
+ dev->device->id);
+ return;
+ }
+
+ /* Otherwise sync all relevant devices */
+ for (i = 0; i < handler->n_devices; i++) {
+ dev = handler->devices[i];
+ if (dev->device->type != DEVICE_TYPE_DISK &&
+ dev->device->type != DEVICE_TYPE_USB)
+ continue;
+ if (dev->ramdisk)
+ device_release_write(dev, true);
+ else
+ pb_log("%s has no snapshot to merge, skipping\n",
+ dev->device->id);
+ }
+}
+
#else
void device_handler_discover_context_commit(
{
}
+void device_sync_snapshots(
+ struct device_handler *handler __attribute__((unused)),
+ const char *device __attribute__((unused)))
+{
+}
+
#endif
int device_request_write(struct discover_device *dev, bool *release);
void device_release_write(struct discover_device *dev, bool release);
+void device_sync_snapshots(struct device_handler *handler, const char *device);
#endif /* _DEVICE_HANDLER_H */
*action = EVENT_ACTION_DHCP;
else if (streq(buf, "boot"))
*action = EVENT_ACTION_BOOT;
+ else if (streq(buf, "sync"))
+ *action = EVENT_ACTION_SYNC;
else {
pb_log("%s: unknown action: %s\n", __func__, buf);
return -1;
EVENT_ACTION_CONF,
EVENT_ACTION_DHCP,
EVENT_ACTION_BOOT,
+ EVENT_ACTION_SYNC,
EVENT_ACTION_MAX,
};
return "dhcp";
case EVENT_ACTION_BOOT:
return "boot";
+ case EVENT_ACTION_SYNC:
+ return "sync";
default:
break;
}
return 0;
}
+static int user_event_sync(struct user_event *uev, struct event *event)
+{
+ struct device_handler *handler = uev->handler;
+
+ if (strncasecmp(event->device, "all", strlen("all")) != 0)
+ device_sync_snapshots(handler, event->device);
+ else
+ device_sync_snapshots(handler, NULL);
+
+ return 0;
+}
+
static void user_event_handle_message(struct user_event *uev, char *buf,
int len)
{
case EVENT_ACTION_BOOT:
result = user_event_boot(uev, event);
break;
+ case EVENT_ACTION_SYNC:
+ result = user_event_sync(uev, event);
+ break;
default:
break;
}
" Events can be read from stdin, or provided on the command line.\n"
" User events must have the following format:\n"
"\n"
-" (add|remove|boot)@device-id [name=value] [image=value] [args=value]\n"
+" (add|remove|boot|sync)@device-id [name=value] [image=value] [args=value]\n"
"\n"
" When read from stdin, components are separated by NUL chars\n"
"\n"