discover: Fix dead code in udev_handle_cdrom_events()
The check against ddev->mounted to cause an eject action is logically
impossible. Change it so a cdrom_eject() is called properly.
Change the return value to 'true' for any action caused by
DISK_EJECT_REQUEST - no further action is appropriate in this case
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
- Abbreviate several translations of "Disk R/W".
- Do not expand 'DHCP' in pt_BR.
- Remove several extra space characters in French translations.
- Shorten some translations of "Boot Order", "DNS Servers".
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Jeremy Kerr [Wed, 30 Sep 2015 00:38:36 +0000 (08:38 +0800)]
discover/ipmi: Increase IPMI timeout to a reasonable value
We've seen some IPMI timeouts during testing - meaning that an IPMI
bootdev setting will be ignored. This can result in a machine booting
from an incorrect boot device, or missing a 'safe mode' indication, or
incorrectly proceeding past petitboot.
The firmware & kernel has its own timeout & retry mechanism, so we
already have a little error-recovery there; the timeout in petitboot is
to prevent an indefinite block if the kernel interface isn't behaving
correctly.
So, this change bumps the timeout to a value that suits BMCs we've seen
in the field (specifying a 2 second timeout, with one retry).
Jeremy Kerr [Tue, 29 Sep 2015 04:14:16 +0000 (12:14 +0800)]
discover/ipmi: Use advisory locking on ipmi device
The ipmi module is shared between pb-config and pb-discover. During
system initilisation, we're likely to have a few invocations of
pb-config running, as well as pb-discover starting.
We may have multiple potential concurrent accesses to the ipmi device
node. To avoid problems, this change introduces a fcntl lock on the
device node.
The nc-config screen now includes several select options with a FIELD
height greater than one, but config_screen_widget_focus() will only
scroll down enough to see the first line of text.
Update config_screen_widget_focus() to try and make as much of the
focussed widget visible as possible.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Several string translations used in select widgets are longer than the
maximum possible width of the widget. Rather than associating several
FIELDs with a select option, use a fold_text callback to pad out
substrings of the original string such that the ncurses O_WRAP option
properly wraps strings within the field.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
If we have a device-mapper snapshot available we can now guarantee
filesystem recovery will not write back to a read-only mounted disk.
Allow recovery on those devices with the notable exception of XFS which
may fail to mount if the filesystem is the opposite endian of Petitboot.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
ui/ncurses: Improve update handling in nested screens
Several screens in petitboot-nc require an update if a config or sysinfo
update is received. However if those screens exist but are not the
current screen they will incorrectly try to draw to the screen.
Where the currently active screen is a textscreen (eg. a help screen)
the update is delayed until after the screen is exited.
In the particular case of nc-config where the current screen can be an
nc-subset screen, the nc-subset screen is exited immediately so the
update can be performed, since the nc-subset screen depends on the
information in the previous screen.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
ui/ncurses: Change arrangement of boot order buttons
The buttons 'Add Device', 'Clear', and 'Clear & Boot Any' are short
enough to be positioned horizontally, but several localisations have
strings as long as all three buttons combined.
Instead arrange the buttons vertically and allow longer strings to
resize the width of the button to fit the whole string.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Jeremy Kerr [Wed, 2 Sep 2015 09:13:27 +0000 (17:13 +0800)]
pb-plugin: Implement plugin ABI versioning
If a future update to plugins is not compatbile with the installed
plugin infrastructure, we want to abort the scan / install process.
This change adds an ABI version to the script, as well as version (and
minimum-supported version) to the plugin metadata. This means we can
check before plugin execution.
Jeremy Kerr [Wed, 2 Sep 2015 07:41:38 +0000 (15:41 +0800)]
pb-plugin: Only require a fixed plugin extension, instead of full name
Currently, the `pb-plugin scan` code requires a fixed archive name at
the root of distributed media. This means that vendors need to have a
fixed name, and can only ship one plugin per device.
This change shifts the requirement to just a filename extension
(.pb-plugin) instead.
To handle this, we now look for any plugin with a .pb-plugin extension,
and so may find multiple plugins on a device.
Users may want to prioritise USB-attached storage devices differently to
other devices. Detect if a device is USB-attached and add a new device
type to identify it.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Commit 9781a370 ("Handle mblen return code when n is zero.") in glibc
changes the return value for when the number of bytes ('n') is zero.
Add an extra condition to detect if we've reached the end of the buffer.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Jeremy Kerr [Fri, 21 Aug 2015 05:12:19 +0000 (13:12 +0800)]
pb-plugin: Keep chroot persistent, and create wrapper scripts
Rather than having to 'pb-plugin run' multiple times, we want users to
be able to execute multiple plugin binaries with more accessible
command-line statements.
This change reverts to the previous 'install' (rather than 'run')
behaviour, and creates wrapper scripts to call into the chroot.
discover/udev: Additional checks in udev_handle_block_add
- Several filesystem types can appear that we won't be able to mount.
Instead of waiting to fail mounting them in device_handler_discover(),
skip processing them at all.
- Do not create dm-snapshots on top of raid arrays until we have a
reliable way of determining the sector count for a md raid device.
- Turn down the verbosity on skipping dm-devices.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover/devmapper: Disable libdm udev sync support
Certain userspace environments that Petitboot is packaged with include
a libdm built with udev sync support which hung with the previous approach.
Relying on udev to properly process dm device creation makes some
assumptions about the flavour of udev available - until that is certain
disable udev sync support and have device-mapper control device creation
itself.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Jeremy Kerr [Fri, 7 Aug 2015 04:14:42 +0000 (12:14 +0800)]
pb-plugin: Update to chroot-style plugins
This change uses a chroot for all plugins, so that plugins have complete
flexibility with their libraries, dependencies and configuration.
We remove the 'install' action, as we simply run the plugin once.
Running involves extracting the archive, setting up a root filesystem,
and running a chroot.
To simplify plugin discovery behaviour, we standardise the plugin file
to be at pb-plugin.conf of attached devices, and read the metadatafile
straight out of the archive.
Create a new Petitboot option 'petitboot,write?' that specifies whether
the system is allowed to mount devices read-write. The option can be
toggled by the user in the nc-config screen.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover: Mount snapshots for all eligible disk devices
Device-mapper snapshots are created for all disk devices prior to
being mounted. If explicit writes are made to the snapshot they are
merged back to the disk once write access is released.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover: Support creation of device-mapper devices
Add discover/dm-snapshot that allows the creation of device-mapper
snapshots that support merging changes back to disk.
Device-mapper snapshots are a CoW device backed by a ramdisk, mirroring
the contents of a source device. No changes are made to the original
disk unless an explicit merge action is performed. This guarantees
read-only mounting of host disks even when writes could implicitly
occur, eg. when performing recovering a journaled filesystem.
In the event that writing back to the disk is desired, such as when
updating grubenv, the changes made to the snapshot can be merged back to
the source disk.
This patch adds support but does not change functionality.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Jeremy Kerr [Fri, 26 Jun 2015 03:41:46 +0000 (11:41 +0800)]
discover: Fix raw string argument to talloc_asprintf_append
Current builds give a warning:
../discover/platform-powerpc.c: In function ‘update_bootdev_config’:
../discover/platform-powerpc.c:667:4: warning: format not a string
literal and no format arguments [-Wformat-security]
tmp = val = talloc_asprintf_append(val, boot_str);
^
ui/ncurses: Properly reposition cursor after menu update
The currently selected item in the main menu can be set to an item off
the visible portion of the menu after the additional or removal of a
boot option. Update the currently selected item and/or the current view
such that the item remains in the visible area.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Send a short message to the UI to inform the user a device is being
parsed for boot options. This helps slightly in environments when the UI
appears well before devices are available for parsing, giving the user
an indication that work is still being done.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover: Clear default-boot-device when invalidated
Update the clear_ipmi_bootdev functions to optionally invalidate the
next- or default-boot-device for their respective machines.
If a client invalidates the ipmi_bootdev in the config, invalidate the
respective bootdev.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Move petitboot to a more familiar 'boot-order' based autoboot system.
The discover server now reads multiple values from the petitboot,bootdev
parameter and adds them in order to config->autoboot_opts. Boot priority
is determined by the options' position in the list.
On the client, nc-config now recognises the new boot order, and allows
the user to add, remove, and reorder the devices in the list.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Changing the visual order of widgets will cause their associated fields to be
out of order relative to the widgetset field array. Rather than manually
resorting the array, use sorted navigation to move according to a field's
visual positon
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
The nc-subset screen is intended to be used as a sub-screen from the
current screen (eg. nc-config) which passes a pointer to a
nc_widget_subset struct. The nc-subset screen allows the user to select
an option from a list of 'inactive' options, before returning control
back to the current screen.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
The new nc_widget_subset is similar to nc_widget_select, but hides added
options until they are made active. This allows the widget to have
multiple options selected and ordered without cluttering the screen.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover: Add support for multiple bootdev arguments
To support multiple autoboot options while retaining backwards
compatability, interpret the petitboot,bootdev parameter as
optionally having several space-separated values.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Add the new autoboot_option struct, and helper functions for working
with device_type enums. device_type_name() returns exact strings as used
by platform code to read/write nvram params, so
device_type_display_name() is added for use in user-visible strings.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Joel Stanley [Thu, 30 Apr 2015 06:02:03 +0000 (16:02 +1000)]
discover: Set OS Boot sensor with 0xa9
If we don't set all the things, we only get an assertion event, without
the state being asserted.
Despite the IPMI spec suggesting we only needed to set 0x10, aka the
assertion bits, testing reveals we want to set all of the things to
cause the BMC to assert the state.
Tested-by: Nick Bofferding <bofferdn@us.ibm.com> Signed-off-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Joel Stanley [Thu, 30 Apr 2015 06:02:03 +0000 (16:02 +1000)]
discover: Set OS Boot sensor with 0xa9
If we don't set all the things, we only get an assertion event, without
the state being asserted.
Despite the IPMI spec suggesting we only needed to set 0x10, aka the
assertion bits, testing reveals we want to set all of the things to
cause the BMC to assert the state.
Tested-by: Nick Bofferding <bofferdn@us.ibm.com> Signed-off-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover: Mount with norecovery, avoid rw mount of XFS filesystems
Journaled filesytems may still write to their disk even if the disk is
mounted read only. Petitboot should avoid modifying any disks
automatically, and in mixed-endian systems this can also cause journal
operations to fail. Use the 'norecovery' option on filesystems that
support it to skip the journal replay.
Additionally, mounting an XFS filesystem as read-write in such a case
will cause the call to mount to hang indefinitely. Avoid this generally
by explicitly unmounting and (re)mounting when mounting read-write.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Udev may change the name of network interfaces if persistent interface
naming is used. It is important to recognise this since udev may re-use
the old name for a different interface.
If we receive an RTM_NEWLINK message for an existing interface, check if
the name has been updated.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
All current *_post() methods in ui/ncurses call redrawwin() and
wrefresh() together. wrefresh() updates any lines on the screen that
have been marked as changed or invalid. However redrawwin() marks the
entire screen as invalid unconditionally. We can reduce the amount of
data written to the screen by avoiding calls to redrawwin().
Screen transitions are the primary use case of redrawwin(), where the
whole screen must be invalidated to avoid stale data remaining on
screen. All other 'in-screen' updates such as changes to widgets or
changing focus do not require a call to redrawwin(). The most noticeable
performance improvement is in nc-menu, which makes an unnecssary call to
redrawwin() after every addition to the boot option menu.
eg. The number of bytes written to STDOUT in the main menu:
# Boot options | Before | After
--------------------------------
8 | 5488 | 1149
133 | 422454 | 4652
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
A boot option requires an image path at minimum. If an option is
created without an image, trying to edit the resulting user item causes
a segfault. Prevent the user from creating a boot option without at
least an image path.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Jeremy Kerr [Thu, 11 Dec 2014 08:38:21 +0000 (16:38 +0800)]
discover: Integrate ipmi bootdev settings into the priority system
Currently, we expose the boot device priorities through an array in
struct config, which will either be the default (network -> disk), or a
single device type specified by the IPMI code.
Rather than hide the implementation details in this array, we'd like to
expose the details of the machine configuration instead. This allows
user visibility of the real boot configuration (for example, if an IPMI
boot preference is set).
This change removes the priority array, and replaces it with the
ipmi_bootdev data (and a persistent flag). We update the
default-conflict-resolution code to reflect the priorities between IPMI
and UUID preferences.
Jeremy Kerr [Tue, 2 Dec 2014 07:04:38 +0000 (15:04 +0800)]
discover/powerpc: Separate ipmi bootdev handling into separate functions
We'd like to add a new backend to the bootdev storage, so move the
common bootdev-handling code into separate functions, moving
ipmi_bootdev_is_valid to ipmi.c.
Jeremy Kerr [Thu, 11 Dec 2014 01:42:58 +0000 (09:42 +0800)]
discover/grub2: Allow unset and invalid defaults
If the default environment variable is unset or invalid (i.e.,
references a non-existent boot option), then GRUB2 will fallback to the
first boot option present. This is preventing petitboot from autobooting
where no default is explicitly set, or is stale.
This change adds this fallback behaviour to petitboot. Because we don't
know if the first option will be a default at parse time (as no other
options matched the default env var), we need to keep options in a list,
and register them with the discover server once the parse is complete.
discover/pxe: Format IPAPPEND mac addresses correctly
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.
Jeremy Kerr [Mon, 1 Dec 2014 03:47:16 +0000 (11:47 +0800)]
discover/grub2: improve handling of word & delimiter tokens
Currently, the delimiter token handling is a little fragile: we try to
ignore non-inter-word delimiters in the lexer with a selective set of
regexes on the possible delimiter characters.
This means we don't need to handle potential delimiters in every grammar
rule, but there are other situations (not regex-able) where we may see
delimters, and this will cause a parse error.
Instead of relying on the regex behaviour, we have an 'inter_word' flag,
which is set when we see the first word token, and cleared when we see
an end-of-line token. We only emit TOKEN_DELIM when this flag is set.
This means that we only get the delim tokens when they're required -
when we're looking for word separators (becuase WORD DELIM WORD is
distinct from WORD WORD - eg "linux /vmlinux" and "x$var").
We add a few new tests for the "menuentry" and "if" syntax, with
different delimiter configurations.
Jeremy Kerr [Fri, 28 Nov 2014 03:42:06 +0000 (11:42 +0800)]
lib/fold: fix warning with -DDEBUG
When compiling the fold code with DEBUG defined, we get:
../lib/fold/fold.c: In function 'fold_text':
../lib/fold/fold.c:37:3: error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
assert(bytes >= 0);
^
We should be comparing with != (size_t)-1, not >= 0
Widgets running over the horizontal width of the pad will cause the
screen to blank. Expand the (non-viewable) size of the pad to prevent
blanking until shorter translations are available for nc-config.
Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>