petitboot
6 years agodiscover/boot: Download resources in parallel
Jeremy Kerr [Thu, 26 Sep 2013 05:51:10 +0000 (13:51 +0800)]
discover/boot: Download resources in parallel

Now that we can download asynchronously, we can download boot resources
in parallel. This also means we don't need a state machine; we're either
not done (loads are still pending) or done.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Add struct load_url_result and load_task
Jeremy Kerr [Tue, 24 Sep 2013 03:03:11 +0000 (11:03 +0800)]
discover: Add struct load_url_result and load_task

Currently, load_url and load_url_async return a filename parameter and a
tempfile flag (indicating whether the file needs to be cleaned after
use).

Instead, encapsulate this data in a struct load_url_result, which the
caller (and async callbacks) can read the status, filename and clean
parameters.

For internal use in load_url and helpers, we add a struct load_task to
hold a pointer to the load_url_result and async data.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Don't depend on tftp failure for type detection
Jeremy Kerr [Wed, 25 Sep 2013 06:23:39 +0000 (14:23 +0800)]
discover: Don't depend on tftp failure for type detection

Rather than always trying both TFTP client types, do a runtime detection
on first invocation. This can be fixed at build-time with
--with-tftp=TYPE.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Store clean_* in the boot task
Jeremy Kerr [Tue, 24 Sep 2013 03:04:25 +0000 (11:04 +0800)]
discover/boot: Store clean_* in the boot task

... otherwise we won't clean up local files from earlier boot stages.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Check for failed loads in boot()
Jeremy Kerr [Tue, 24 Sep 2013 02:58:16 +0000 (10:58 +0800)]
discover/boot: Check for failed loads in boot()

Use the status argument to the URL load callback to check for load
failures.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: load_url_async callback should take an int status
Jeremy Kerr [Tue, 24 Sep 2013 02:39:03 +0000 (10:39 +0800)]
discover: load_url_async callback should take an int status

We don't need a pointer here, just the status value.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Implement asynchronous boot() process
Neelesh Gupta [Thu, 12 Sep 2013 14:26:32 +0000 (19:56 +0530)]
discover/boot: Implement asynchronous boot() process

The current boot process handled by boot() function is implemented such
that it blocks on the boot resources being downloaded which blocks
the discover process until the download completes. This patch
re-implements the boot() function using callback mechanism and
asynchronous notifications so that boot() returns to continue the
discover process while the download is in progress.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
6 years agodiscover: Add an asynchronous version of load_url
Neelesh Gupta [Thu, 12 Sep 2013 14:26:54 +0000 (19:56 +0530)]
discover: Add an asynchronous version of load_url

A new load_url_async() function handles retrieving the resources by
forking an external process which currently blocks the parent waiting
for the process to complete. This patch modifies the load_*() functions
to handle it asynchronously by providing the exit callback and returning
without waiting for the child process to exit.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
6 years agodiscover/grub2: Reimplement default options
Jeremy Kerr [Wed, 25 Sep 2013 00:37:50 +0000 (08:37 +0800)]
discover/grub2: Reimplement default options

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Check for devices with duplicate serial properties
Jeremy Kerr [Tue, 24 Sep 2013 09:31:50 +0000 (17:31 +0800)]
discover: Check for devices with duplicate serial properties

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>
6 years agopb-udhcpc: use plain kernel names for dhcp events
Jeremy Kerr [Tue, 24 Sep 2013 09:01:58 +0000 (17:01 +0800)]
pb-udhcpc: use plain kernel names for dhcp events

No need to prefix with /net/

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Fix uninitialised op variable
Jeremy Kerr [Tue, 24 Sep 2013 08:11:43 +0000 (16:11 +0800)]
discover/grub2: Fix uninitialised op variable

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Add test-grub2-single-line-if test
Jeremy Kerr [Tue, 24 Sep 2013 06:16:38 +0000 (14:16 +0800)]
test/parser: Add test-grub2-single-line-if test

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Support var=value assignments
Jeremy Kerr [Tue, 24 Sep 2013 06:15:59 +0000 (14:15 +0800)]
discover/grub2: Support var=value assignments

We want to allow assignments outside of the 'set' builtin.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Allow double-quotes in embedded config
Jeremy Kerr [Tue, 24 Sep 2013 06:09:06 +0000 (14:09 +0800)]
test/parser: Allow double-quotes in embedded config

We need to escape any double-quotes.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add true & false builtins
Jeremy Kerr [Tue, 24 Sep 2013 06:08:46 +0000 (14:08 +0800)]
discover/grub2: Add true & false builtins

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Allow checks for NULL boot_args
Jeremy Kerr [Tue, 24 Sep 2013 06:01:43 +0000 (14:01 +0800)]
test/parser: Allow checks for NULL boot_args

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Add variable expansion in Ubuntu conf file test
Jeremy Kerr [Tue, 24 Sep 2013 06:00:24 +0000 (14:00 +0800)]
test/parser: Add variable expansion in Ubuntu conf file test

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2/lexer: Require 1+ spaces for a TOKEN_DELIM
Jeremy Kerr [Tue, 24 Sep 2013 05:59:43 +0000 (13:59 +0800)]
discover/grub2/lexer: Require 1+ spaces for a TOKEN_DELIM

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add linux16 command
Jeremy Kerr [Tue, 24 Sep 2013 05:59:24 +0000 (13:59 +0800)]
discover/grub2: Add linux16 command

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Allow both delimiters and EOLs after a "then" reserved word
Jeremy Kerr [Tue, 24 Sep 2013 05:55:57 +0000 (13:55 +0800)]
discover/grub2: Allow both delimiters and EOLs after a "then" reserved word

Putting an if-statement on one line should be possible:

 if true; then echo "true"; else echo "false"; fi

To do this, we'll need to allow both EOLs and TOKEN_DELIM after then and
else.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Fix spacing in grub2-f18-ppc64 test
Jeremy Kerr [Tue, 24 Sep 2013 05:17:02 +0000 (13:17 +0800)]
test/parser: Fix spacing in grub2-f18-ppc64 test

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement test builtin
Jeremy Kerr [Tue, 17 Sep 2013 13:54:38 +0000 (21:54 +0800)]
discover/grub2: Implement test builtin

A faily simple implementation now, and could do with some testing...

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add nops for unnecessary builtins
Jeremy Kerr [Tue, 17 Sep 2013 07:09:41 +0000 (15:09 +0800)]
discover/grub2: Add nops for unnecessary builtins

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement statement_block_execute
Jeremy Kerr [Tue, 17 Sep 2013 07:04:19 +0000 (15:04 +0800)]
discover/grub2: Implement statement_block_execute

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: unknown commands should fail
Jeremy Kerr [Tue, 17 Sep 2013 06:51:23 +0000 (14:51 +0800)]
discover/grub2: unknown commands should fail

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Populate option ids
Jeremy Kerr [Tue, 17 Sep 2013 06:51:02 +0000 (14:51 +0800)]
discover/grub2: Populate option ids

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Allow EOF as a statement terminator
Jeremy Kerr [Tue, 17 Sep 2013 06:38:42 +0000 (14:38 +0800)]
discover/grub2: Allow EOF as a statement terminator

Files may not have a trailing newline.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add print_token
Jeremy Kerr [Tue, 17 Sep 2013 06:38:06 +0000 (14:38 +0800)]
discover/grub2: Add print_token

For better trace output.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: fix comment handling
Jeremy Kerr [Tue, 17 Sep 2013 06:36:43 +0000 (14:36 +0800)]
discover/grub2: fix comment handling

Remove '#' from the list of word chars. Also, don't need the '$' char in
the comment regex

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement 'elif'
Jeremy Kerr [Tue, 17 Sep 2013 06:35:38 +0000 (14:35 +0800)]
discover/grub2: Implement 'elif'

Rather than just having one conditional in an if statement, we use a
list of conditionals instead. This allows us to implement elif.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Create 'conditional' statements
Jeremy Kerr [Tue, 17 Sep 2013 05:02:05 +0000 (13:02 +0800)]
discover/grub2: Create 'conditional' statements

Rather than holding the condition and conditional-statements in struct
grub2_statment_if, create a new conditional type that contains these. We
can then use this to implement elif statements.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Allow empty statements
Jeremy Kerr [Tue, 17 Sep 2013 03:29:27 +0000 (11:29 +0800)]
discover/grub2: Allow empty statements

Re-arrange the script/statements parse rules to allow empty statements.
We also move the EOL token out of the 'statement' definition, and use
it to separate 'statements'.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement submenu
Jeremy Kerr [Tue, 17 Sep 2013 03:14:18 +0000 (11:14 +0800)]
discover/grub2: Implement submenu

Just recurse into the submenu items, as we flatten everything into the
one menu.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add function support
Jeremy Kerr [Tue, 17 Sep 2013 01:36:11 +0000 (09:36 +0800)]
discover/grub2: Add function support

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Improve error handling
Jeremy Kerr [Tue, 17 Sep 2013 01:34:34 +0000 (09:34 +0800)]
discover/grub2: Improve error handling

Only run the script if the parse succeeded, and and improve the
error reporting by enabling verbose errors and line numbers.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement 'else' blocks
Jeremy Kerr [Mon, 16 Sep 2013 08:58:30 +0000 (16:58 +0800)]
discover/grub2: Implement 'else' blocks

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement 'search' command
Jeremy Kerr [Mon, 16 Sep 2013 08:53:22 +0000 (16:53 +0800)]
discover/grub2: Implement 'search' command

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement 'linux' & 'initrd' commands
Jeremy Kerr [Mon, 16 Sep 2013 08:47:17 +0000 (16:47 +0800)]
discover/grub2: Implement 'linux' & 'initrd' commands

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Function infrastructure improvements
Jeremy Kerr [Mon, 16 Sep 2013 08:26:46 +0000 (16:26 +0800)]
discover/grub2: Function infrastructure improvements

For user-defined functions, we'll need a data pointer to the function's
execution callback. Add this as a void *, and change references from
'command' to 'function'.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add option state in menuentry processing
Jeremy Kerr [Mon, 16 Sep 2013 08:02:09 +0000 (16:02 +0800)]
discover/grub2: Add option state in menuentry processing

This will allow menuentry-specific commands to populate boot option
data.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add a reference to the context from grub2_script
Jeremy Kerr [Mon, 16 Sep 2013 07:51:53 +0000 (15:51 +0800)]
discover/grub2: Add a reference to the context from grub2_script

We'll need the context to add boot options.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Hook up flex/bison parser to discover server
Jeremy Kerr [Mon, 16 Sep 2013 07:12:13 +0000 (15:12 +0800)]
discover/grub2: Hook up flex/bison parser to discover server

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Move parser-api definitions to parser.y
Jeremy Kerr [Mon, 16 Sep 2013 06:22:27 +0000 (14:22 +0800)]
discover/grub2: Move parser-api definitions to parser.y

No need for a separate file here.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement multiple-arv variable splitting
Jeremy Kerr [Mon, 16 Sep 2013 02:40:21 +0000 (10:40 +0800)]
discover/grub2: Implement multiple-arv variable splitting

If we expand a variable containing word-delimiter chars, we need to
create new argv items.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add initial command execution
Jeremy Kerr [Fri, 13 Sep 2013 08:33:58 +0000 (16:33 +0800)]
discover/grub2: Add initial command execution

.. with a simple 'set' command to update the environment

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add menuentry execution
Jeremy Kerr [Fri, 13 Sep 2013 07:30:58 +0000 (15:30 +0800)]
discover/grub2: Add menuentry execution

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Fix word append
Jeremy Kerr [Fri, 13 Sep 2013 07:25:33 +0000 (15:25 +0800)]
discover/grub2: Fix word append

The parser was setting word->next on the top-level word, resulting in
word chains of a maximum length of 2. Instead, use a last pointer to
always append to the last word.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Handle var tokens in lexer
Jeremy Kerr [Fri, 13 Sep 2013 06:50:19 +0000 (14:50 +0800)]
discover/grub2: Handle var tokens in lexer

Rather than post-processing to expand variables, use the lexer to
identify variable tokens as a type of grub2_word.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Remove debug printfs
Jeremy Kerr [Fri, 13 Sep 2013 05:45:58 +0000 (13:45 +0800)]
discover/grub2: Remove debug printfs

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Initial environment handling
Jeremy Kerr [Fri, 13 Sep 2013 05:40:40 +0000 (13:40 +0800)]
discover/grub2: Initial environment handling

A simple linked-list implementation of string pairs.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add initial execution code
Jeremy Kerr [Fri, 13 Sep 2013 03:53:46 +0000 (11:53 +0800)]
discover/grub2: Add initial execution code

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Fix statement reduce rule
Jeremy Kerr [Fri, 13 Sep 2013 02:09:24 +0000 (10:09 +0800)]
discover/grub2: Fix statement reduce rule

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add var expansion code
Jeremy Kerr [Thu, 12 Sep 2013 10:46:57 +0000 (18:46 +0800)]
discover/grub2: Add var expansion code

Still todo: splitting.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add initial script infrastructure
Jeremy Kerr [Thu, 12 Sep 2013 08:08:18 +0000 (16:08 +0800)]
discover/grub2: Add initial script infrastructure

Now that we can parse scripts, we want some infrastructure for
execution.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Use subclass-style structs for AST
Jeremy Kerr [Thu, 12 Sep 2013 07:54:36 +0000 (15:54 +0800)]
discover/grub2: Use subclass-style structs for AST

Use embedded 'struct grub2_statement' data to create a subclass-style
syntax tree of statements.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement statement blocks
Jeremy Kerr [Thu, 12 Sep 2013 07:03:05 +0000 (15:03 +0800)]
discover/grub2: Implement statement blocks

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement reduce rules
Jeremy Kerr [Wed, 11 Sep 2013 05:38:25 +0000 (13:38 +0800)]
discover/grub2: Implement reduce rules

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add structures & API for parser
Jeremy Kerr [Wed, 11 Sep 2013 02:47:37 +0000 (10:47 +0800)]
discover/grub2: Add structures & API for parser

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Implement parser
Jeremy Kerr [Tue, 10 Sep 2013 06:04:41 +0000 (14:04 +0800)]
discover/grub2: Implement parser

Add our simple parser to handle a grub2 script. Since we're not building
a parse tree at the moment (we have no reduce rules), we just have a
simple word-based %union for our tokens.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Initial grub2 lexer
Jeremy Kerr [Tue, 10 Sep 2013 03:01:55 +0000 (11:01 +0800)]
discover/grub2: Initial grub2 lexer

Add a simple flex lexer to tokenise our grub2 config files.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib: Add array-size header
Jeremy Kerr [Fri, 13 Sep 2013 08:00:51 +0000 (16:00 +0800)]
lib: Add array-size header

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Add booting status message
Jeremy Kerr [Mon, 23 Sep 2013 09:34:14 +0000 (17:34 +0800)]
discover/boot: Add booting status message

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Allow printf formatting in update_status
Jeremy Kerr [Mon, 23 Sep 2013 09:31:43 +0000 (17:31 +0800)]
discover/boot: Allow printf formatting in update_status

It'd be nice to include arbitrary format strings here, so do a
taloc_vasprintf in update_status.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Fix log message with no newline
Jeremy Kerr [Mon, 23 Sep 2013 09:11:10 +0000 (17:11 +0800)]
discover/boot: Fix log message with no newline

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: clear default_timeout waiter on timeout
Jeremy Kerr [Mon, 23 Sep 2013 09:01:15 +0000 (17:01 +0800)]
discover: clear default_timeout waiter on timeout

We don't want cancel_default to try to remove an already-removed waiter.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Don't register multiple boot_timeout waiters
Jeremy Kerr [Mon, 23 Sep 2013 08:27:17 +0000 (16:27 +0800)]
discover: Don't register multiple boot_timeout waiters

Rather than adding another timeout waiter, just override
handler->default_boot_option and extend the timeout a little.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: check for multiple default options
Jeremy Kerr [Fri, 20 Sep 2013 06:25:30 +0000 (14:25 +0800)]
test/parser: check for multiple default options

Update check_boot_option_count to check if a parser returned more than
one boot option with is_default set.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/pxe: Implement default options
Jeremy Kerr [Fri, 20 Sep 2013 06:21:43 +0000 (14:21 +0800)]
discover/pxe: Implement default options

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Implement device priorities
Jeremy Kerr [Thu, 19 Sep 2013 14:18:04 +0000 (22:18 +0800)]
discover: Implement device priorities

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: register network devices with the device handler
Jeremy Kerr [Thu, 19 Sep 2013 14:04:12 +0000 (22:04 +0800)]
discover: register network devices with the device handler

We'd like to correlate incoming network boot options with a device, so
register the interface with the device hander.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/network: Manage network->interfaces with {add,remove}_interface
Jeremy Kerr [Thu, 19 Sep 2013 13:55:06 +0000 (21:55 +0800)]
discover/network: Manage network->interfaces with {add,remove}_interface

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/network: ignore devices with zero MTU
Jeremy Kerr [Thu, 19 Sep 2013 13:48:32 +0000 (21:48 +0800)]
discover/network: ignore devices with zero MTU

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Remove unnecessary event passing
Jeremy Kerr [Thu, 19 Sep 2013 09:16:53 +0000 (17:16 +0800)]
discover: Remove unnecessary event passing

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>
6 years agodiscover/boot: Fix use-after-free in boot()
Jeremy Kerr [Thu, 19 Sep 2013 13:07:19 +0000 (21:07 +0800)]
discover/boot: Fix use-after-free in boot()

We need boot_task for kexec_reboot.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/pb-config: Initialise DNS server info
Jeremy Kerr [Thu, 19 Sep 2013 09:19:12 +0000 (17:19 +0800)]
lib/pb-config: Initialise DNS server info

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/log: Cleanup log API
Jeremy Kerr [Thu, 19 Sep 2013 04:18:56 +0000 (12:18 +0800)]
lib/log: Cleanup log API

Rather than exposing log internals (through always_flush and
set_stream), do all logging init through pb_log_init(). If pb_log_init()
hasn't been called, pb_log will drop messages.

Also, add a pb_debug() function, specifically for debugging information.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Consolidate device path, name and ID.
Jeremy Kerr [Wed, 18 Sep 2013 03:49:14 +0000 (11:49 +0800)]
discover: Consolidate device path, name and ID.

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>
6 years agodiscover: populate udev device types
Jeremy Kerr [Wed, 18 Sep 2013 03:44:41 +0000 (11:44 +0800)]
discover: populate udev device types

Now that we have device types, populate from the udev info.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotypes: Add device_type to struct device
Jeremy Kerr [Wed, 18 Sep 2013 03:03:17 +0000 (11:03 +0800)]
types: Add device_type to struct device

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/pb-config/powerpc-nvram: Add petitboot,timeout nvram property
Jeremy Kerr [Wed, 18 Sep 2013 01:06:02 +0000 (09:06 +0800)]
lib/pb-config/powerpc-nvram: Add petitboot,timeout nvram property

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/pb-config: Add autoboot timeout to configuration vars
Jeremy Kerr [Wed, 18 Sep 2013 00:54:05 +0000 (08:54 +0800)]
lib/pb-config: Add autoboot timeout to configuration vars

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agopb-udhcpc: Fix string returned from resolve_url
Jeremy Kerr [Fri, 6 Sep 2013 06:31:32 +0000 (14:31 +0800)]
pb-udhcpc: Fix string returned from resolve_url

In the 'as-is' case, we were echoing both URLs.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/pxe: check for a valid boot option before adding
Jeremy Kerr [Fri, 6 Sep 2013 03:46:56 +0000 (11:46 +0800)]
discover/pxe: check for a valid boot option before adding

If we didn't find any valid boot options in the pxe buffer, we'll call
discover_context_add_boot_option with a NULL boot option.

This change adds a check before we try to add the boot option, and a
test to verify this situation.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Allow both DEL and ^H to map to backspace
Jeremy Kerr [Mon, 2 Sep 2013 03:01:20 +0000 (13:01 +1000)]
ui/ncurses: Allow both DEL and ^H to map to backspace

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: add 'partition' directive overriding test for yaboot conf file
Neelesh Gupta [Thu, 29 Aug 2013 13:51:58 +0000 (19:21 +0530)]
test/parser: add 'partition' directive overriding test for yaboot conf file

Check the overriding of 'partition' directive from yaboot conf file for
'petitboot', then verify the device name on which the resource resides

Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/yaboot-parser: Handle 'partition=' directive override
Neelesh Gupta [Thu, 29 Aug 2013 13:51:32 +0000 (19:21 +0530)]
discover/yaboot-parser: Handle 'partition=' directive override

In a yaboot conf file, we may see a device= directive that actually
specifies a partition (eg, sda1) rather than the underlying block device
(sda). If we then encounter a partition= directive, we don't handle the
resolution of the partition correctly, as we simply append the
partition number to the device= string.

This change implements a smarter handling of the partition= directive,
where we strip away any partition information from the device=
parameter first.

Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest: add 'partition=directive' test for yaboot conf file
Neelesh Gupta [Tue, 27 Aug 2013 09:04:51 +0000 (14:34 +0530)]
test: add 'partition=directive' test for yaboot conf file

Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/lib: Implement process_init change in testcases
Jeremy Kerr [Thu, 29 Aug 2013 03:52:28 +0000 (13:52 +1000)]
test/lib: Implement process_init change in testcases

We need to provide the dry_run argument.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: handle EINTR from waitpid
Jeremy Kerr [Tue, 20 Aug 2013 02:30:57 +0000 (10:30 +0800)]
lib/process: handle EINTR from waitpid

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: Add dry_run argument to process_init
Jeremy Kerr [Tue, 20 Aug 2013 02:14:22 +0000 (10:14 +0800)]
lib/process: Add dry_run argument to process_init

Implement dry-run behaviour on the discover server by passing a bool to
process_init. UIs don't need to support dry runs.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: replace pb_run_cmd
Jeremy Kerr [Tue, 13 Aug 2013 05:03:53 +0000 (13:03 +0800)]
lib/process: replace pb_run_cmd

This change replaces the pb_run_cmd() function with proper usage of the
process API.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: replace pb_run_cmd_pipe
Jeremy Kerr [Mon, 12 Aug 2013 08:39:36 +0000 (16:39 +0800)]
lib/process: replace pb_run_cmd_pipe

Replace pb_run_cmd_pipe with process_create / process_run_sync.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/lib: add process tests
Jeremy Kerr [Wed, 14 Aug 2013 07:05:56 +0000 (15:05 +0800)]
test/lib: add process tests

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/waiter: handle -EINTR
Jeremy Kerr [Mon, 19 Aug 2013 03:58:23 +0000 (11:58 +0800)]
lib/waiter: handle -EINTR

Now that we're handing non-fatal signals (i.e., SIGCHLD in the process
lib), we need to gracefully handle -EINTR from poll().

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: Add process helpers
Jeremy Kerr [Mon, 12 Aug 2013 07:57:41 +0000 (15:57 +0800)]
lib/process: Add process helpers

We've grown-out of pb_run_cmd a little, as we have a number of different
process types:

   boot():
    - kexec: short-running process, run synchronously
    - boot hooks: short-running, run sync, need exit code & stdout

   network init:
    - interface configuration: short running, run sync
    - udhcp processes are long running, we may want completion, but
      doesn't block other actions

   downloads:
    - potentially long-running, block parse progress

   config nvram:
    - read: short running, can block, need stdout
    - write: short running, can block

We'd like to introduce proper asynchronous processes, to allow config &
boot-option downloads without blocking the discover server.

This change introduces a new type for processes, 'struct process'. These
structures are created with process_create, and run with
process_run_sync or process_run_async. The latter reports completion
through a callback member of struct process.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest: Add --enable-test-valgrind
Jeremy Kerr [Mon, 19 Aug 2013 03:08:56 +0000 (11:08 +0800)]
test: Add --enable-test-valgrind

Add an --enable-test-valgrind argument to configure, to run all tests
under valgrind, configured to fail on leaked memory

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/lib: Use talloc in list test
Jeremy Kerr [Mon, 19 Aug 2013 03:08:36 +0000 (11:08 +0800)]
test/lib: Use talloc in list test

.. so we can free at exit

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/lib: build with -DEBUG
Jeremy Kerr [Fri, 12 Jul 2013 06:25:07 +0000 (14:25 +0800)]
test/lib: build with -DEBUG

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: talloc struct boot_task
Jeremy Kerr [Tue, 13 Aug 2013 03:23:57 +0000 (11:23 +0800)]
discover/boot: talloc struct boot_task

Rather than using the stack for struct boot_task, talloc one instead.
This gives us a short-lived context (active for the boot() process
only), and we don't need to use the externally-provided context
directly.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>