path: root/discover/device-handler.c
Commit message (Collapse)AuthorAgeFilesLines
* Various fixups and checks to make scan-build happySamuel Mendoza-Jonas2019-05-301-1/+1
| | | | Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Recognise and open LUKS encrypted partitionsSamuel Mendoza-Jonas2019-03-261-1/+147
| | | | | | | | | | | | | | Handle devices encrypted with LUKS and call cryptsetup to open them if a client sends the associated password. If a new device has the "crypto_LUKS" filesystem type it is marked as a LUKS device and sent to clients but further discovery is not performed. Once a client sends the device's password cryptsetup is called to open it. The opened device will appear separately, so the source device is "forgotten" at this point and then the newly opened device is treated as a normal partition. On destruction the device is "closed" with cryptsetup so that discovery can start from the beginning. Signed-off-by: Samuel Mendoza-Jonas <>
* ui/ncurses: Keep track of the default boot optionSamuel Mendoza-Jonas2018-12-031-0/+4
| | | | | | | | | Keep track of the default boot option, and prefix its display name with a '(*)' to point it out to the user. This avoids having to authenticate with pb-discover even if only booting the default option. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Prevent normal users changing boot targetSamuel Mendoza-Jonas2018-12-031-1/+13
| | | | Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Display warning if saving config failsSamuel Mendoza-Jonas2018-11-291-1/+4
| | | | Signed-off-by: Samuel Mendoza-Jonas <>
* ui/ncurses: Reset console options on bootSamuel Mendoza-Jonas2018-11-161-0/+1
| | | | | | | | | | | | | | | The ncurses UI sets a few console options at startup that are needed for ncurses to work properly. These aren't reset however and can lead to quirks like the cursor being invisible after kexecing to the next kernel. The UI process doesn't have time to reset these when it is killed by kexec, so instead add a 'boot_active' field to status updates. This is set by boot.c's update handler so the UI can assume it is about to boot if it receives a status update with this field, and resets the console options. If the boot is cancelled for any reason the status update will reflect that and the console options are restored. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Restore autoboot setting on requerySamuel Mendoza-Jonas2018-08-281-1/+9
| | | | | | | | | | | | | | | | When a device requery is triggered we cancel any default boot option on the device. This also disables autoboot which we don't want; any boot options found after the requery will not be able to autoboot. To avoid this restore the existing autoboot setting after checking for default options. This prevents a particular corner case where a default boot option has been selected for boot but one of its boot files has stalled or is taking more time to download than the requery timeout and the requery accidentally cancels autoboot preventing Petitboot from trying to boot again. Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Let 'boot' user-event boot by nameSamuel Mendoza-Jonas2018-08-281-0/+22
| | | | | | | | | If a 'name' parameter is used for a boot user event, search existing boot options for one that matches that name on the given device. This allows a pb-event user to boot based on name rather than having to specify the exact boot arguments. Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Add some debug print messagesGeoff Levand2018-08-071-0/+1
| | | | | | | | To aid in debugging print some additinal discover messages to the log. Signed-off-by: Geoff Levand <> Signed-off-by: Samuel Mendoza-Jonas <>
* lib/log: Switch to pb_log_fnGeoff Levand2018-08-071-4/+4
| | | | | | | | The only functional change should be an additional '/n' to a few log messagees that seemed to be missing it. Signed-off-by: Geoff Levand <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Support IPv6 addressesSamuel Mendoza-Jonas2018-07-101-17/+34
| | | | | | | Support handling IPv6 addresses from user events and call the udhcpc6 client in addition to the udhcpc client. Signed-off-by: Samuel Mendoza-Jonas <>
* ui/ncurses: Implement F10-F12 for autoboot device controlJeremy Kerr2018-07-101-0/+25
| | | | | | | | | | | | | Add a few mappings to specify temporary autoboot settings: F10: Only autoboot from disk F11: Only autoboot from USB devices F12: Only autoboot from network These use the new code to prevent cancelling autoboot. Signed-off-by: Jeremy Kerr <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover/handler: Implement temporary autoboot messagesJeremy Kerr2018-07-101-6/+57
| | | | | | | | Handle incoming requests for temporary autoboot settings. Signed-off-by: Jeremy Kerr <> [indenting fixup] Signed-off-by: Samuel Mendoza-Jonas <>
* discover/handler: Split autoboot matching into a new functionJeremy Kerr2018-07-101-10/+17
| | | | | | | | A future change will want to match autoboot option settings, so abstract this into its own function. Signed-off-by: Jeremy Kerr <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: implement a periodic requery for network devicesJeremy Kerr2018-07-091-4/+128
| | | | | | | | | | | | | | | | | | If we boot a machine before external (network) dependencies are properly configured, it will have tried once to download configuration, and possibly failed due to that configuration not being present. This change introduces a periodic requery of network resources. After a timeout, petitboot will either re-acquire its DHCP lease (causing any downloads to be re-processed, possibly with different parameters from the new lease), or re-download a statically defined URL. This timeout defaults to five minutes (similar to pxelinux), and is configurable by DHCP option 211, "reboot time". Signed-off-by: Jeremy Kerr <> [added test stub] Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Rescan SCSI devices on reinitSamuel Mendoza-Jonas2018-06-121-0/+3
| | | | | | | Explicitly rescan SCSI devices on reinit rather than just remounting them in case a device did not init properly on boot. Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Fix bad check of version stringJoel Stanley2018-03-071-2/+1
| | | | | | | | | | | | | | | | | | | Clang says this: discover/device-handler.c:1564:27: warning: size argument in 'strncmp' call is a comparison [-Wmemsize-comparison] strlen(opt->version) == 0)) { ~~~~~~~~~~~~~~~~~~~~~^~~~ discover/device-handler.c:1563:5: note: did you mean to compare the result of 'strncmp' instead? strncmp(opt->version, tmp->version, ^ It looks like it's correct. However, we can go one better and drop the pointless strncmp(foo, bar, strlen(bar)), as this is equivalent to strcmp(foo, bar). Signed-off-by: Joel Stanley <> Reviewed-by: Cyril Bur <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Treat empty boot order as 'boot any'Samuel Mendoza-Jonas2018-02-121-0/+3
| | | | | | | | It is possible to have autoboot enabled with an empty boot order. Currently this acts as if autoboot is disabled, but it likely makes more sense to the user for this to behave as "autoboot any device". Signed-off-by: Samuel Mendoza-Jonas <>
* printf: Fix format type warningsGeoff Levand2018-01-101-1/+2
| | | | | | | | | Fixes build warnings like these when building 32 bit programs: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument has type ‘uint64_t’ Signed-off-by: Geoff Levand <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover/pxe-parser: Fix relative parsing for manual config filesSamuel Mendoza-Jonas2017-12-121-1/+1
| | | | | | | | | | | | Manually specified config files are asynchronously downloaded by device_handler_process_url() before being parsed. This overwrites the 'pxeconffile' parameter, causing the parser to create relative paths relative to the downloaded file's path, not the original remote path. Work around this by setting 'pxeconffile-local' instead to differentiate between the original config file's location and the local copy. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Fallback to device if snapshot fails to mountv1.6.1Samuel Mendoza-Jonas2017-10-121-3/+14
| | | | | | | | | In the event that a snapshot fails to mount, destroy it and fall back to the actual source device. While this loses the protection afforded by a snapshot it avoids users being greeted with an empty boot menu and unable to continue booting. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Disable safe mode warning on reinitSamuel Mendoza-Jonas2017-08-231-0/+10
| | | | | | | | | | | If a user pressed "Rescan Devices" in safe mode the reinit would complete successfully, but the big warning that safe mode is active would remain. On reinit clear the safe_mode flag properly. This has no functional change aside from clearing the UI warning - the IPMI override remains active until cleared or a successful boot occurs. Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Update env vars at init and suppress LVM warningsSamuel Mendoza-Jonas2017-08-221-0/+20
| | | | | | | | | | | Environment variables are not platform-specific so move set_proxy_variables to device-handler and call it at handler init. At the same time set LVM_SUPPRESS_FD_WARNINGS to ignore the "file descriptor leaked" warnings when calling LVM-utilities, since we must keep some file descriptors open in lib/process. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Be ready for user events earlierSamuel Mendoza-Jonas2017-08-151-4/+4
| | | | | | | | Actions performed in network and udev init may result in pb-event callbacks (such as from udhcpc or pb-plugin), so make sure the user event interface is set up beforehand. Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Handle plugin install requestSamuel Mendoza-Jonas2017-08-151-0/+56
| | | | | | | | | Handle "_PLUGIN_INSTALL" requests from clients. Calling the pb-plugin script from pb-discover ensures different clients don't trip over each other. Successfully installed plugins are automatically communicated back to clients once pb-plugin sends a 'plugin' user event. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Scan devices for pluginsSamuel Mendoza-Jonas2017-08-151-0/+18
| | | | Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Handle and track plugin_optionsSamuel Mendoza-Jonas2017-08-151-0/+64
| | | | | | | | | | Track plugin_options in the device_handler. Plugins can be added with device_handler_add_plugin_option() and accessed via device_handler_get_plugin(). Extend discover_server to support the new 'add' and 'remove' pb-protocol actions and advertise new plugins to connecting clients. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Mention booting device in timeout statusSamuel Mendoza-Jonas2017-07-131-1/+2
| | | | Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Wait for net interfaces to be marked readySamuel Mendoza-Jonas2017-07-111-6/+6
| | | | | | | | | | | | | | | | | | | | | | | If pb-discover is started before udev has settled there is a race between Petitboot configuring interfaces and udev renaming them. If an interface is set "up" the name change will fail and interfaces can be inconsistently named, eg: Device: (*) eth0 [0c:c4:7a:f4:1c:50, link up] ( ) enP1p9s0f1 [0c:c4:7a:f4:1c:51, link down] ( ) enP1p9s0f2 [0c:c4:7a:f4:1c:52, link down] ( ) enP1p9s0f3 [0c:c4:7a:f4:1c:53, link down] Add "net" devices to the udev filter and wait for them to be announced by udev before configuring them. udev_enumerate_add_match_is_initialized() ensures that by the time an interface appears via udev its name will be consistent. This also swaps the network and udev init order, but since interfaces now will not be configured until after udev is ready this should not have a user-visible effect. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Allow process_url request to be pendingSamuel Mendoza-Jonas2017-07-111-34/+73
| | | | | | | device_handler_process_url() fails immediately if no network is available. For individual files queue the load task for later instead. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/paths: Add network jobs to queueSamuel Mendoza-Jonas2017-07-111-0/+3
| | | | | | | | | Load tasks that start before the network is available will fail. Rather than just fail these tasks, add them to a queue that is processed once the network is ready. This helps users who try to request files early in setup, as well as very early running load tasks. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/sysinfo: Add system_info_reinit()Samuel Mendoza-Jonas2017-07-111-0/+2
| | | | | | | | Currently over reinit events the system info is not affected. However network and block device information can change over reinit, so clear this information. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Include makedev() from sysmacros.hSamuel Mendoza-Jonas2017-06-201-0/+1
| | | | | | | | | | | | | | | | Include sys/sysmacros.h explicitly in response to the following error message: ../discover/device-handler.c:1001:13: warning: In the GNU C Library, "makedev" is defined by <sys/sysmacros.h>. For historical compatibility, it is currently defined by <sys/types.h> as well, but we plan to remove this soon. To use "makedev", include <sys/sysmacros.h> directly. If you did not intend to use a system-defined macro "makedev", you should undefine it after including <sys/types.h>. id = makedev(1, handler->n_ramdisks); ^~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Track both configured and current autoboot settingsSamuel Mendoza-Jonas2017-03-151-1/+1
| | | | | | | | | | | | | | | If autoboot is enabled but later disabled or cancelled by, for example, an IPMI override then the nc-config screen will set the autoboot widget as disabled. If the user then makes and saves a change in nc-config, autoboot will also be saved as disabled. This accidental change is particularly awkward if the user is attempting to remove an IPMI override. Instead only ever change the autoboot setting if the user explicitly changes it. Use a new helper function 'config_autoboot_active()' to determine the current autoboot status where needed. Signed-off-by: Samuel Mendoza-Jonas <>
* process: Cancel all asynchronous jobs on reinitv1.4.1Samuel Mendoza-Jonas2017-01-311-0/+3
| | | | | | | | | | | If an asynchronous job is running over a reinit, the process can return and run its callback function after the reinit. This becomes a problem if the callback function accesses pointers that were only valid before the reinit (eg. device structs). If a reinit is requested explicitly stop all active asynchronous jobs and clear their callback functions before the reinit. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Cancel pending boot on reinitSamuel Mendoza-Jonas2017-01-311-0/+6
| | | | | | | | | | When a reinit is requested device_handler_cancel_default() is called, however as the name suggests this only cancels the boot task if it is the result of a default boot option. We also want to cancel a boot task if it was executed manually because it may have outstanding asynchronous transfers running, so explicitly cancel it during reinit. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Process queue after device addedSamuel Mendoza-Jonas2017-01-311-2/+1
| | | | | | | | | | | | In device_handler_discover() we process the unresolved boot options queue first. However the discover_device in question has not yet been added to handler->devices so when a parser tries to search for a matching device it will fail. The discover_device will be added to the handler if it has not already in device_handler_discover_context_commit() so move the call to process_boot_option_queue() after it. Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Maintain a backlog of status updatesSamuel Mendoza-Jonas2016-12-201-0/+2
| | | | | | | | | Add status updates to a persistent list in the discover_server struct, and send each client the backlog on connect. This avoids clients missing useful messages from early init. Clients will only show this in the backlog screen to avoid flooding the client's status line. Signed-off-by: Samuel Mendoza-Jonas <>
* discover/device-handler: Add aggregated download progress updatesSamuel Mendoza-Jonas2016-12-201-0/+117
| | | | | | | | | | | | | | 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 <>
* discover/status: Be more specific about DHCP event status messageJeremy Kerr2016-12-201-1/+2
| | | | | Signed-off-by: Jeremy Kerr <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover/status: remove completion messagesJeremy Kerr2016-12-201-4/+0
| | | | | | | | | The completion messages are unconditional, so don't really indicate anything. In fact, the dhcp completion status is misleading, as we may still be processing the context through pxe callbacks. Signed-off-by: Jeremy Kerr <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: add handler reference to struct discover_contextJeremy Kerr2016-12-201-1/+7
| | | | | | | | | | | | | 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 <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Use device_handler_status_dev_* for device-specific statusJeremy Kerr2016-12-201-27/+12
| | | | | Signed-off-by: Jeremy Kerr <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Add device-specific status reporting functionsJeremy Kerr2016-12-201-0/+32
| | | | | | | | | 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 <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: use helpers for status reportingJeremy Kerr2016-12-201-41/+11
| | | | | | | | Now that we have helpers for simpler status reporting, use those instead of constructing a struct status everywhere. Signed-off-by: Jeremy Kerr <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Add helpers for status reportingJeremy Kerr2016-12-201-0/+33
| | | | | | | | | 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 <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: separate status-reporting function from boot() callbackJeremy Kerr2016-12-201-12/+16
| | | | | | | | | | | | 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 <> Signed-off-by: Samuel Mendoza-Jonas <>
* types: Remove detail and progress from struct statusJeremy Kerr2016-12-201-8/+0
| | | | | | | Nothing used these, and the serialisation was buggy anyway. Signed-off-by: Jeremy Kerr <> Signed-off-by: Samuel Mendoza-Jonas <>
* types: shorten boot_status definitionsJeremy Kerr2016-12-201-15/+15
| | | | | | | | | | | 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 <> Signed-off-by: Samuel Mendoza-Jonas <>
* discover: Pass UUID to discover_device_create()Samuel Mendoza-Jonas2016-09-081-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <>
OpenPOWER on IntegriCloud