summaryrefslogtreecommitdiffstats
path: root/discover/device-handler.c
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2016-07-26 15:45:37 +1000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2016-08-08 13:52:50 +1000
commit83a587b79e9a5a5279f1c7a26918fc8c08523a7f (patch)
tree353a9aff1c1207d3dcb44832606cbc5088218d42 /discover/device-handler.c
parent297d2f0cc9c0a233fadf42dacc08708ad3909f77 (diff)
downloadtalos-petitboot-83a587b79e9a5a5279f1c7a26918fc8c08523a7f.tar.gz
talos-petitboot-83a587b79e9a5a5279f1c7a26918fc8c08523a7f.zip
discover: Add 'sync' user event
Add a user event named 'sync' that causes the discover server to merge the devicemapper snapshots of mounted devices. This is particularly useful as a debug aid (for example, when copying logs to a USB device), as the server will otherwise only sync changes to mounted devices in response to parser actions. The command can be called as pb-event sync@device to sync a particular device, or as pb-event sync@all to sync all devices with snapshots. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r--discover/device-handler.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index 682a4e9..c31fcea 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -1581,6 +1581,41 @@ void device_release_write(struct discover_device *dev, bool release)
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(
@@ -1628,4 +1663,10 @@ void device_release_write(struct discover_device *dev __attribute__((unused)),
{
}
+void device_sync_snapshots(
+ struct device_handler *handler __attribute__((unused)),
+ const char *device __attribute__((unused)))
+{
+}
+
#endif
OpenPOWER on IntegriCloud