From patchwork Wed Jul 27 05:37:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 653095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rzkKg5243z9t1V for ; Wed, 27 Jul 2016 15:37:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b=jq7oV6Sc; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rzkKg2Tj5zDrFf for ; Wed, 27 Jul 2016 15:37:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b=jq7oV6Sc; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mendozajonas.com (mendozajonas.com [188.166.185.233]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rzkKY6KlMzDqYk for ; Wed, 27 Jul 2016 15:37:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b=jq7oV6Sc; dkim-atps=neutral Received: from skellige.ozlabs.ibm.com (unknown [122.99.82.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: sam@mendozajonas.com) by mendozajonas.com (Postfix) with ESMTPSA id E5310140053; Wed, 27 Jul 2016 13:37:49 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1469597870; bh=oupUbkuQxmE98UHyGWT9wlgON932TjKwd9ufGGPC2pg=; h=From:To:Cc:Subject:Date:From; b=jq7oV6ScBsqQo5yMBnqPTugn3L6uPJ61XZ7kdrPUIMGyq2sLwIWCzbobs0MTvkJV+ itpikLoDRTCfGYyedYfVXUegmdSZyWf3xe3UQTW/42IBkq2GmPa5sbqqWzM7aH2SAa wN/GXdgqvpa2Rsg/V64cH53QnWwy42ZTAyHanykw= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH] discover: Add 'sync' user event Date: Wed, 27 Jul 2016 15:37:39 +1000 Message-Id: <20160727053739.31169-1-sam@mendozajonas.com> X-Mailer: git-send-email 2.9.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" 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 --- discover/device-handler.c | 41 +++++++++++++++++++++++++++++++++++++++++ discover/device-handler.h | 1 + discover/event.c | 2 ++ discover/event.h | 1 + discover/user-event.c | 15 +++++++++++++++ utils/pb-event.c | 2 +- 6 files changed, 61 insertions(+), 1 deletion(-) 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 diff --git a/discover/device-handler.h b/discover/device-handler.h index 6b1a757..b6f9fd5 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -142,5 +142,6 @@ void device_handler_reinit(struct device_handler *handler); 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 */ diff --git a/discover/event.c b/discover/event.c index 8b3a1ab..242ae81 100644 --- a/discover/event.c +++ b/discover/event.c @@ -55,6 +55,8 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action, *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; diff --git a/discover/event.h b/discover/event.h index 35c0767..a603615 100644 --- a/discover/event.h +++ b/discover/event.h @@ -14,6 +14,7 @@ enum event_action { EVENT_ACTION_CONF, EVENT_ACTION_DHCP, EVENT_ACTION_BOOT, + EVENT_ACTION_SYNC, EVENT_ACTION_MAX, }; diff --git a/discover/user-event.c b/discover/user-event.c index 15d9c87..76a75d9 100644 --- a/discover/user-event.c +++ b/discover/user-event.c @@ -464,6 +464,18 @@ static int user_event_boot(struct user_event *uev, struct event *event) 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) { @@ -499,6 +511,9 @@ static void user_event_handle_message(struct user_event *uev, char *buf, case EVENT_ACTION_BOOT: result = user_event_boot(uev, event); break; + case EVENT_ACTION_SYNC: + result = user_event_sync(uev, event); + break; default: break; } diff --git a/utils/pb-event.c b/utils/pb-event.c index 572eb16..10bf4f5 100644 --- a/utils/pb-event.c +++ b/utils/pb-event.c @@ -55,7 +55,7 @@ static void print_usage(void) " 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"