Jeremy Kerr [Wed, 2 Apr 2014 06:33:38 +0000 (14:33 +0800)]
discover: add reinit path
Currently, changes to settings doesn't take effect while the discover
server is running. This means we need to reboot for any changes (eg, to
network settings) to take effect.
This change introduces a reinit path. Triggered by a configuration
update, this will cause the device handler to drop all of its devices
(and boot options), and restart the discovery process from the device
sources.
Jeremy Kerr [Wed, 2 Apr 2014 06:08:26 +0000 (14:08 +0800)]
discover: move device sources to the device handler
Currently, the pb-discover main() function initialises the device
handler and the device sources.
We want to eventually be able to re-init the device sources, which will
be initiated by the handler. In this case, the handler will need
references to the sources.
This change moves the creation of the device sources to be internal to
the handler. This way, the device handler gets a reference to
everything, without having to pass pointers around in main().
We also remove the _destroy functions, as we handle everything through
talloc destructors, as all sources are parented to the handler. We also
change user_event_init and udev_init to take the handler as the first
('context') argument, to make them consistent with network_init.
Jeremy Kerr [Tue, 1 Apr 2014 08:30:27 +0000 (16:30 +0800)]
discover/udev: don't propagate non-fatal errors from udev_process
Currently, we have a bug where non-zero return codes from
udev_handle_dev_* cause the udev worker from deregistering from the
waiter poll loop. This is becasue udev_process is propagating these
errors, causing the deregistration.
This change stops propagation of non-fatal errors, so we don't
deregister.
Jeremy Kerr [Thu, 13 Mar 2014 02:07:12 +0000 (10:07 +0800)]
discover: Use ID_FS_TYPE property for filesystem type detection
Currently, we don't hand any -t option to mount, as we expect the mount
binary to do autodetection of the filesystem type for us.
Turns out this isn't great with busybox mount, (which we're likely to be
using in petitboot builds), which implements "autodetection" by trying
the mount() syscall with every fs type in /proc/filesystems, until one
succeeds.
We expect a lot of the mount calls to fail, as we currently try to mount
everything (and abort discovery on devices that don't mount), including
non-filesystem partitions. On a test machine with 560 block devices, and
37 entries in /proc/partitions, this results in around 20,000 calls to
mount().
A better way would be to pass a -t option to mount. It turns out that
udev uses libblkid to probe the filesystem type, which is available in
the ID_FS_TYPE property. This change only attempts to mount filesystems
with this property, and passes an explicit fstype to the mount binary.
Jeremy Kerr [Fri, 7 Mar 2014 05:46:49 +0000 (13:46 +0800)]
discover/udev: Register udev monitor before enumerating devices
Currently, we enumerate udev devices before setting up our monitor. This
means that we may lose devices that udev discovers after we start the
enumeration, but before the monitor is registered.
This change enables the monitor before enumeration, so we don't lose
devices. We add a filter to the enumeration code to only parse
completely initialised devices.
This means we may need to handle change events as the main source of
device notifications. We keep the existing CDROM event handler, but
check for new devices and handle those as an add.
Jeremy Kerr [Fri, 7 Mar 2014 01:05:00 +0000 (09:05 +0800)]
discover: don't retry mount without ro option
Currently, if the read-only mount fails during device discovery, we
retry without the '-o ro' option. This was originally due to the
read-only mount failing when a device was already mounted elsewhere.
Since we check for exsiting mounts now, we can drop this retry.
Jeremy Kerr [Thu, 27 Feb 2014 03:39:41 +0000 (11:39 +0800)]
discover/pxe: Fix prefix autodetection when bootfile is in the root dir
Currently, if the bootfile doesn't contain a directory, the path we use
for config file resolution will use the bootfile as the first component
of path.
Jeremy Kerr [Thu, 27 Feb 2014 02:33:13 +0000 (10:33 +0800)]
discover/pxe: Add pxelinux.cfg/ directory to autodiscovered pxe paths
The pxelinux project will perform autodiscovery by looking for files
under the pxelinux.cfg/ prefix (in addition to any pxepathprefix from
DHCP option 210)
This change unifies petitboot's behaviour with pxelinux.
Jeremy Kerr [Thu, 20 Feb 2014 01:22:58 +0000 (09:22 +0800)]
lib/process: Don't abort stdout reads on EINTR
If our read() of the process stdout pipe fails with EINTR (eg, if we
receive a SIGCHLD because the process exited), then
process_read_stdout_once will return a non-zero exit code, and we'll
abort any further stdout collection.
Instead, we should check for EINTR, and allow the reads to continue.
This change normalises the return value from process_read_stdout_once to
return positive on success, negative on failure, and zero on competion.
We use a positive return value for the non-error EINTR case.
Also, add a pb_log if the read fails for non-EINTR reasons.
Jeremy Kerr [Thu, 30 Jan 2014 08:59:56 +0000 (16:59 +0800)]
platforms/powerpc: Add support for OPAL sysparams
PowerPC OPAL firmware's sysparam interface allows us to read the boot
device set over IPMI. This change implements support for IPMI bootdev
selection over the sysparams interface, using the new boot_priority
infrastructure.
Jeremy Kerr [Thu, 30 Jan 2014 08:19:20 +0000 (16:19 +0800)]
discover: Make boot_priorities more flexible
Rather than rely on the ordering of the boot_priorities array to define
which device types have a higher "default boot" priority, this change
introduces a slightly more flexible way of priority lookups, by adding a
separate priority field to struct boot_priority.
This means we can have an unordered array, change priorities without
re-writing the array, and implementing a disable mechanism.
Jeremy Kerr [Wed, 29 Jan 2014 05:28:06 +0000 (13:28 +0800)]
pb-config: Move config storage modules to "platform" modules in discover code
There's no need to include the config storage code in lib/ as only the
discover server should be using it.
This change moves the config-storage code to discover/, with the
platform-specific parts moved to a 'struct platform'. Each platform has
a probe function, which is called during init. The first probe function
to return a platform is used.
At present we only have the one platform, but it's now non-intrusive to
add others.
We keep an array of platform pointers in a separate ("platforms")
section, to allow the test module to drop-in its own test "platform".
Jeremy Kerr [Tue, 28 Jan 2014 05:01:19 +0000 (13:01 +0800)]
lib/pb-config: Add config_copy
At the moment, UIs have the config_set_defaults function to estabilish
an initial configuration when performing an update.
Rather than using the defaults, this change provides a config_copy()
function, so that the updated configuration can be initialised from the
current config.
With this in place, the UI/server-common pb-config module can be reduced
to just the one function.
Jeremy Kerr [Fri, 24 Jan 2014 06:40:46 +0000 (14:40 +0800)]
discover/grub2: Add support for for-loops
GRUB2 syntax allows for for-loops; this change adds supoprt in the
parser grammar and script execution code to implement them. In the
execution code, we simply update the for-loop variable and re-execute
the body statements.
In order to implement for-loops, we may need to evaluate the same chunk
of script more than once, and perform that evaluation in a different
context (particularly, with different environment variables).
Currently, the process_expansion code destroys the result of the
parse-tree (ie, the token list) when performing expansions. This means
that we can only perform the expansions once.
This change preserves the token list while creating the argv array. This
means that we can expand the list multiple times.
Jeremy Kerr [Fri, 24 Jan 2014 06:39:37 +0000 (14:39 +0800)]
discover: Add support for checking directories in parser API
This change adds a function to the parser API:
int parser_check_dir(struct discover_context *ctx,
struct discover_device *dev, const char *dirname)
- which allows parsers to check for the presence of a directory (path of
'dirname') on the device ('dev'). We use this in the GRUB2 parser to
implement the `test -d` check.
Jeremy Kerr [Tue, 21 Jan 2014 00:27:48 +0000 (08:27 +0800)]
discover/paths: Check process exit status when loading URLs
Currently, we may report incorrect success when loading a URL, as we
only check the return value of process_run_sync() (and not the process
exit status itself) in load_process_to_local_file.
Jeremy Kerr [Mon, 20 Jan 2014 00:58:49 +0000 (08:58 +0800)]
utils/pb-udhcpc: Unify references to DHCP bootfile parameter
udhcpc may pass the bootfile parameter as either $bootfile or
$boot_file, depending on whether the option is present in the BOOTP
header, or as a DHCP vendor option. We have code in pb-udhcpc to unify
this to $bootfile, but we only use the unified value in one of the user
events.
This change uses the correct value of bootfile, and fixes the check to
conditionally generate the explicit add event. We also need to update
the user-event code to use the right event parameter name.
Jeremy Kerr [Mon, 20 Jan 2014 00:51:11 +0000 (08:51 +0800)]
utils/pb-udhcpc: Fix incorrect reference to $interface
We have a typo in the udhcpc hook, where we're not referncing the
interface variable correctly. This means we'll get the same device
identifier for all netboot options.
Jeremy Kerr [Fri, 17 Jan 2014 07:51:54 +0000 (15:51 +0800)]
discover: Support DHCP "pathprefix" configuration option
This change implements support for the DHCP "pathprefix" option. We use
the following logic:
- If pathprefix is present and a full URL, we base the config file
location on pathprefix + conffile
- If pathprefix is present but not a full URL, we use it as the path
component of the URL, and pick up the host from other parameters in
the DHCP response
- If no pathprefix is present, we determine the configuration prefix
from the DHCP bootfile parameter.
Jeremy Kerr [Fri, 17 Jan 2014 08:36:41 +0000 (16:36 +0800)]
test/parser: Check for full URLs in parser tests
At present, we only match the 'file' portion of a URL in the parser
tests, so we "serve" a file if just the filename (but not the scheme,
hostname or path) matches the file we set with test_read_conf_embedded.
This change introduces test_read_conf_embedded_url, which we can use to
specify a full URL. In this case, the fake parser_request_file matches
the entire URL before returning the file data.
Jeremy Kerr [Fri, 17 Jan 2014 06:50:54 +0000 (14:50 +0800)]
discover: Don't rely on ctx->conf_url side-effect in user_event_parse_conf_url
Currently, user_event_parse_conf_url sets dc->conf_url if it detects we
have a full URL (rather than a base URL). This is a little too subtle,
so replace it with an explicit output parameter.
Ben Stoltz [Wed, 15 Jan 2014 23:10:25 +0000 (15:10 -0800)]
discover/grub: Use --id values for default option detection
Fix Petitboot's grub.cfg parser to handle --id=label argument to
menuentry, and use it (in preference to the option name) when looking
for a default option.
Jeremy Kerr [Thu, 16 Jan 2014 01:13:20 +0000 (09:13 +0800)]
discover: Bring down configured interfaces on discover server exit.
We want to down the interfaces that we brought up, so hook up the
network_shutdown function to the discover exit path. Also, we only want
to down interfaces that we've configured, and exclude lo.
Jeremy Kerr [Tue, 14 Jan 2014 07:44:10 +0000 (15:44 +0800)]
lib/process: Add add_stderr flag to process module
For some process execution functions, we'd like to capture stderr as
well as stdout. Currently, we unconditionally redirect subprocess stderr
to the petitboot log file.
This change adds an add_stderr flag to struct process, which indicates
to the process library that we want stderr as well as stdout. If this is
specified, the subprocess' stderr is captured to stdout_buf.
Jeremy Kerr [Tue, 14 Jan 2014 02:56:41 +0000 (10:56 +0800)]
discover/yaboot: Clear globals_done when we see an image definition
Currently, we have a bug where a 'known_name' that appears before an
image section will cause globals_done to be set, and we don't see any
further global variables.
This change sets globals_done only once we see an image section.
Jeremy Kerr [Mon, 23 Dec 2013 08:42:21 +0000 (16:42 +0800)]
config/powerpc: Always call update_network_config
Currently, we have a bug when setting the default network configuration
(ie, no devices have any specific config), as we won't call
update_network_config to clear out the value of the petitboot,network
parameter.
This change always invokes update_network_config, regardless of the
number of interfaces configured. This ensures we clear out the
petitboot,network param, which is then synced to nvram if the param has
changed.
We'd like to do some validation of the system configuration parameters,
so add a few validation types to the widget code. We currently need
integer, ipv4 address and multiple ipv4 address types. These are
implemented as small wrappers around the ncurses form validator code.
Jeremy Kerr [Mon, 16 Dec 2013 02:49:29 +0000 (10:49 +0800)]
sysinfo: Add interface link status to sysinfo data
This changes adds a 'link' parameter to the interface information sent
in sysinfo messages. The discover network code populates this from the
incoming netlink messages.
Jeremy Kerr [Thu, 5 Dec 2013 06:32:28 +0000 (14:32 +0800)]
discover/boot: Fix condition for updating boot params
In commit 823958fb, we change to use struct process, but left in the
check for rc == BOOT_HOOK_EXIT_UPDATE. We actually want to check
process->exit_status here, not rc.
Jeremy Kerr [Tue, 3 Dec 2013 07:14:53 +0000 (15:14 +0800)]
discover/grub2: Fixes for bison 3.x
YYLEX_PARAM is removed in bison 3.0, so we need to pass the scanner
param directly through yyparse (rather than referencing
parser->scanner). Unfortunately, we don't have the lexer header
available at the time we declare yyparse, so we need to pass a void *
here.
Jeremy Kerr [Fri, 29 Nov 2013 02:47:10 +0000 (10:47 +0800)]
discover: Fix CDROM handling
Currently, we don't handle CDROM devices well; we'll try to mount on
boot, and not detect any media changes. Also, the default rules shipping
with udev will put the CDROM tray into a locked state, blocking eject
from working.
This change adds a set of cdrom utility functions, which the udev code
can use to properly initialise cdrom devices and handle eject and media
change requests.
In an upcoming change, we'll populate $prefix (which is used to locate
the environment file) based on the location of the config file, so these
paths will need to be consistent.