summaryrefslogtreecommitdiffstats
path: root/discover/device-handler.h
Commit message (Collapse)AuthorAgeFilesLines
* discover/device-handler: Add aggregated download progress updatesSamuel Mendoza-Jonas2016-12-201-0/+6
| | | | | | | | | | | | | | Several processes run by Petitboot output progress information while running. Add device_handler_status_download() which process callers can call to register and update progress information (percentage and current size). A list of 'progress_info' structs holds this progress information, and on each call to device_handler_status_download() the information is combined and displayed as a single status update for readability. On completion device_handler_status_download_remove() is called to remove old progress information from the list. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: add handler reference to struct discover_contextJeremy Kerr2016-12-201-1/+3
| | | | | | | | | | | | | Since the device handler provides the status message functions, we need a pointer to it for device discovery (which we use a struct discover_context for). This change adds a 'handler' member to struct discover_context, to allow status reporting. Since we now have a handler, there's no need for the network pointer, so provide an accessor function instead. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: Add device-specific status reporting functionsJeremy Kerr2016-12-201-0/+4
| | | | | | | | | Most of our status reporting is against a specific device, so add status reporting functions that take a struct discover_device and use a stnadard prefix. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: Add helpers for status reportingJeremy Kerr2016-12-201-0/+4
| | | | | | | | | This change adds a couple of helpers for the status reporting API, allowing callers to provide just a set of printf-style arguments, rather than having to build up a struct status. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: separate status-reporting function from boot() callbackJeremy Kerr2016-12-201-1/+2
| | | | | | | | | | | | Currently, the device_discover_boot_status function is both used for internal status updates, as well as the callback passed to boot(). This change splits this into two functions; one for the latter and one for the former. The latter just has a void * for its first argument, to match the boot_status_fn type. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* types: shorten boot_status definitionsJeremy Kerr2016-12-201-1/+1
| | | | | | | | | | | struct boot_status is a bit misnamed; we report status on things that aren't just the boot status (eg, discovery). This change refactors struct boot_status into just struct status. We give the type enum a name, and shorten the enum values to suit. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: Pass UUID to discover_device_create()Samuel Mendoza-Jonas2016-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently discover_device_create() will search for existing discover devices by id to determine if a new device is required. However it is possible under some circumstances for distinct devices to have the same name. This is especially troublesome if the following network events are seen in network_handle_nlmsg(): - New interface, 'foo' with uuid x:x:x:x:x:x -> new discover device created with dev->device->id = 'foo' dev->uuid = x:x:x:x:x:x - New interface, 'foo' with uuid y:y:y:y:y:y -> existing device 'foo' found dev->uuid = y:y:y:y:y:y This can occur if an interface rename event arrives *after* an old name is reused, where temporarily Petitboot will see two distinct network interfaces with the same name. Now the two interfaces point to the same discover device, which can quickly result in a segfault if a 'remove' event occurs for one of the interfaces and the discover device is freed. To generally avoid this a 'uuid' parameter is added to discover_device_create(), which if present allows existing devices to be looked up by UUID rather than just their name. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: Deprecate 'conf' user eventSamuel Mendoza-Jonas2016-09-081-2/+0
| | | | | | | | | | | | The 'conf' user event is functionally very similar to the 'url' event, in that both events result in downloading a specified configuration file and passing it to iterate_parsers(). The 'url' event additionally allows downloading files from a directory path and is also accessed by the UI via pb-protocol, so remove the 'conf' event and associated functions in favour of 'url' and device_handler_process_url(). Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* Add support for GPG signature enforcement on bootedtpearson@raptorengineering.com2016-08-261-0/+1
| | | | | | | | | | | | | kernels and related blobs This can be used to implement a form of organization-controlled secure boot, whereby kernels may be loaded from a variety of sources but they will only boot if a valid signature file is found for each component, and only if the signature is listed in the /etc/pb-lockdown file. Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com> (Minor build fixes and gpgme.m4, comment on secure boot in gpg.c)
* discover: Add 'sync' user eventSamuel Mendoza-Jonas2016-08-081-0/+1
| | | | | | | | | | | | | | | | | | | | 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>
* discover/device-handler: Make boot_status() publicSamuel Mendoza-Jonas2016-06-281-0/+3
| | | | | | | | | Rename boot_status() to device_handler_boot_status() and make it accessible by files that include device-handler.h. This enables the boot status to be updated from additional callers, in particular within parser functions. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: Handle BTRFS root subvolumesSam Mendoza-Jonas2016-02-091-0/+1
| | | | | | | | | | | | | | | | | | During install some distributions[0] will create subvolumes when formatting the root filesystem with BTRFS. In particular this can mean that bootloader config files will appear (in the case of GRUB) under /var/petitboot/mnt/dev/$device/@/boot/grub/ rather than the expected /var/petitboot/mnt/dev/$device/boot/grub/ If this is the case, perform all file operations from the parser relative to this subvolume rather than the mount point. At the moment this only supports the trivial case where the subvolume name for root is blank (ie. '@'). [0] In particular, Ubuntu from at least 14.04 Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover: extend URL in UI to support auto-discoveryNishanth Aravamudan2015-12-181-1/+1
| | | | | | | | | | | | | The URL field currently only supports loading a particular file for static network configurations. But it makes sense in certain static network configurations to 'auto-discover' a file like petitboot does with DHCP -- based off the MAC address and IP. Extend device_handler_process_url to take those as parameters, and toggle off the URL ending in a '/' to indicate whether to 'auto-discover' or directly load the specified URL. Signed-off-by: Nishanth Aravamudan <nacc@linux.vnet.ibm.com> Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
* discover/devmapper: Use explicit 64-bit types for sector countsJeremy Kerr2015-09-301-1/+1
| | | | | | | | | We currently have a bug where the return value from get_block_sectors may overflow an unsigned int, so we create a snapshot that is too small. This change uses uint64_t types for the sector counts. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Keep track of available ramdisk devicesSamuel Mendoza-Jonas2015-08-061-0/+14
| | | | | | | | | | Store information on available ramdisk devices when they are recognised by udev, and add functions to 'reserve' and 'release' these devices. This will be used to associate device-mapper snapshots with a backing ramdisk in a following patch. Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
* discover/pxe: Format IPAPPEND mac addresses correctlySamuel Mendoza-Jonas2014-12-031-0/+1
| | | | | | | | | | | | | | | | | | | | | The SYSAPPEND/IPAPPEND option 2 in PXE configs requires the MAC address of the booting interface to be appended to the boot options. Previously we formatted this as "BOOTIF=01:02:03:04:05:06", but syslinux/pxelinux implementation use this format: "BOOTIF=01-01-02-03-04-05-06", where the leading '01' represents the hardware type. The relevant part of the pxelinux doc is at: http://www.syslinux.org/wiki/index.php/SYSLINUX#SYSAPPEND_bitmask Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Enable 'url' pb-eventsSamuel Mendoza-Jonas2014-07-281-0/+2
| | | | | | | | | | Adds a new option to pb-event; ./pb-event url@dev url=scheme://path/to/petitboot.conf Specifies a remote conf file to parse for boot options Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* protocol: expose discovery reinit over client/server protocolJeremy Kerr2014-04-021-0/+1
| | | | | | | Now that we can re-initialise the device handler, allow this to be triggered from UIs over the petitboot protocol. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Handle incoming configuration messagesJeremy Kerr2013-11-131-0/+3
| | | | | | | When the client sends us a PB_PROTOCOL_ACTION_CONFIG message, we want to update the current config. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Change parsers to explicitly request configuration filesNeelesh Gupta2013-11-061-14/+4
| | | | | | | | | | | | | | | | | | | Add a new function parser_request_url() to read the data from configuration files present remotely. We deprecate iterate_parser_files() and download_config() functions along with the 'filenames' and 'method' members of the 'parser' structure so that individual parsers would now require to request the configuration files data from the parser code and doesn't necessarily export the list of configuration files. Add the support to handle incoming DHCP event, done by passing all the relevant environment variables of the udhcpc to the discover code. Also, update the pxe parser code to populate the list of configuration file names as per PXELINUX convention of fallback names using mac and ip addresses of the booting machine. Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add device_{request,release}_writeJeremy Kerr2013-10-011-0/+4
| | | | | | | | Add a pair of functions to the parser API to allow write access to the underlying device. We'll use this in the GRUB2 parser to implement environment persistence. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add test_data member to struct discover_contextJeremy Kerr2013-10-011-0/+1
| | | | | | | | We have parsers passing discover_contexts around, which we want to hook into the test framework. Add a void * member, which the test code can use to reference the test. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Allow for already-mounted devicesJeremy Kerr2013-10-011-1/+3
| | | | | | | | | | | When we start the discover server, we may find that devices are already mounted. In this case, mount_device will fail, and we'll abort the parse. This change uses /proc/self/mounts to check if new devices are already mounted, and uses the existing mount point. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Check for devices with duplicate serial propertiesJeremy Kerr2013-09-241-0/+3
| | | | | | | | | If we have multipath devices present in the system, we'll end up with duplicate mounts, parse results and boot options. This change adds a check to see if we've encountered a device with this serial number previously. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Remove unnecessary event passingJeremy Kerr2013-09-191-6/+35
| | | | | | | | | | | | | | | Currently, we pass "events" between the udev, user-event and device-handler layers. These events all get sent through device_handler_event, then de-multiplexed to an appropriate handler, depending on their source. Instead, just export relevant device_handler functions, and have the (old) event sources call these functions directly. This also means we can include a lot more of the device hander code in the parser tests. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Consolidate device path, name and ID.Jeremy Kerr2013-09-191-2/+0
| | | | | | | | | | | | This change cleans up our usage of device path, names and IDs. Device ID is the kernel name for the device. We also expose this through lookup_by_name. Device path is the path to the dev node (ie, always starts with /dev/), and is only used for mounting. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib/pb-config: Add autoboot timeout to configuration varsJeremy Kerr2013-09-181-2/+0
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Add initial dtb supportGeoff Levand2013-06-241-0/+1
| | | | | | | Updates & fixes by Jeremy Kerr <jk@ozlabs.org>. Signed-off-by: Geoff Levand <geoff@infradead.org> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add "cancel default boot" messagesJeremy Kerr2013-06-241-0/+1
| | | | | | | Allow the default boot process to be cancelled, via a message with action PB_PROTOCOL_ACTION_CANCEL_DEFAULT. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: implement default bootingJeremy Kerr2013-06-241-1/+4
| | | | | | | When we see a boot option with is_default set, store it in the handler and register a timeout waiter. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add configuration events & DHCP handlerJeremy Kerr2013-04-291-0/+5
| | | | | | | | | | This change adds a new event type, EVENT_ACTION_CONF. These events supply a new configuration URL that petitiboot should download and parse. With this in place, we can receive DHCP configuration events. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add configuration methodsJeremy Kerr2013-04-291-0/+6
| | | | | | | | | | | | We'd like to be able to download petitboot configurations from other sources (not just local files), but we'll need some way to indicate to the parsers that a chunk of config data is from a specific source. This change adds "configuration methods". At present, we have only one: CONF_METHOD_LOCAL_FILE. For any incoming configuration data, we only run parsers that have registered themselves with that configuration method. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Handle unresolved resourcesJeremy Kerr2013-04-291-0/+2
| | | | | | | | | | | | This change adds an unresolved resource queue - any unresolved resources discovered by parsers are added to this queue rather than being reported to the clients. When we discover a new device, we try to resolve any resources in the queue against the new device. If resolution succeeds, we can send the option to clients. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Change parsers to emit resources rather than filenamesJeremy Kerr2013-04-291-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | This change switches the parsers over to populate the resources in discover_boot_option, rather than the string parameters in boot_option. To do this, we need a few things: * Add struct resources to discover_boot_option for the boot_image, initrd and icon data. * Have the parsers populate the resources, rather than the strings. Currently, parsers can all use the devpath resource type. * Add a resolve_resource callback to parsers; this is how the device handler will attempt to resolve resources. * Change load_file to load_url, as we should be only accessing (resolved) resources by URLs. This then allows us to remove the mount map, and associated lookup code, as well as the UUID and label links to devices. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Introduce a container type for boot optionsJeremy Kerr2013-04-291-2/+14
| | | | | | | | | This change introduces a new type, struct discover_boot_option. Like struct discover_device adds discover-specific data to struct device, struct discover_boot_option allows the discover server to store more than just the boot option strings for a boot option. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add device lookup functionsJeremy Kerr2013-04-291-0/+11
| | | | | | | | | | | | Add a few functions to find devices by various attributes: * device_lookup_by_name * device_lookup_by_path * device_lookup_by_uuid * device_lookup_by_label * device_lookup_by_id Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add uuid and label parameters to persistent device dataJeremy Kerr2013-04-291-0/+3
| | | | | | | | | | | | | | | | Rather than depending on the event (which is only available during inital discovery) for UUID and label parameters, this change adds uuid and label members to struct discover_device. This means that the label and UUID are available during the device's lifetime, not just during initial discovery. We can also just pass the device to some of the device handling code, rather than the discover context. Also, fix an issue where we don't use the raw label/uuid (instead of the encoded one) in setup_device_links. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Separate temporary and permanent device dataJeremy Kerr2013-04-161-9/+19
| | | | | | | | | | | At present, we keep both permanent (eg links/n_links) and temporary (event) data in struct discover_context. This change makes discover_context a temporary structure, just used during actual device discovery. Once discovery is complete, the permanent data (discover_device) is "committed" to the device handler. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Move --dry-run option to discover serverJeremy Kerr2013-04-151-1/+2
| | | | | | | Now that the server does the booting, we should move the --dry-run argument to the server. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Implement device handler boot pathJeremy Kerr2013-04-151-0/+4
| | | | | | | | | | This change adds a funtion, device_handler_boot, which processes the boot command message from the discover server. We add a new file, discover/boot.c (and a corresponding header) with a skeleton for the final kexec code. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Make udev_event a generic eventGeoff Levand2009-06-301-4/+3
| | | | | | | | | | The struct udev_event can be used as a generic event, so rename it struct event and move it from udev.h into a new file event.h. Also, rename the emums UDEV_ACTION_ADD and UDEV_ACTION_REMOVE to ACTION_UDEV_ADD and ACTION_UDEV_REMOVE. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Add discover device reportGeoff Levand2009-06-301-2/+3
| | | | | | | | | | Fillout the missing discover code that reports current devices. Replaces device_handler_get_current_devices() with two new accessor routines device_handler_get_device_count() and device_handler_get_device(). Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Make device instance constantGeoff Levand2009-02-011-1/+1
| | | | | | | Make the instance of devices read-only. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Hook up parsers to device discoveryJeremy Kerr2009-01-021-0/+14
| | | | | | | | Iterate the parsers from the device handler on an add event. Initial change to just the kboot parser. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Create device-handler for managing registered devicesJeremy Kerr2008-12-151-0/+19
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
OpenPOWER on IntegriCloud