iPXE
|
SAN booting. More...
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/timer.h>
#include <ipxe/process.h>
#include <ipxe/iso9660.h>
#include <ipxe/dhcp.h>
#include <ipxe/settings.h>
#include <ipxe/quiesce.h>
#include <ipxe/sanboot.h>
Go to the source code of this file.
Data Structures | |
struct | san_command_rw_params |
SAN device read/write command parameters. More... | |
union | san_command_params |
SAN device command parameters. More... | |
Macros | |
#define | SAN_DEFAULT_DRIVE 0x80 |
Default SAN drive number. More... | |
#define | SAN_COMMAND_TIMEOUT ( 15 * TICKS_PER_SEC ) |
Timeout for block device commands (in ticks) More... | |
#define | SAN_DEFAULT_RETRIES 10 |
Default number of times to retry commands. More... | |
#define | SAN_REOPEN_DELAY_SECS 5 |
Delay between reopening attempts. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
LIST_HEAD (san_devices) | |
List of SAN devices. More... | |
struct san_device * | sandev_find (unsigned int drive) |
Find SAN device by drive number. More... | |
static void | sandev_free (struct refcnt *refcnt) |
Free SAN device. More... | |
static void | sandev_command_close (struct san_device *sandev, int rc) |
Close SAN device command. More... | |
static void | sandev_command_capacity (struct san_device *sandev, struct block_device_capacity *capacity) |
Record SAN device capacity. More... | |
static void | sandev_command_expired (struct retry_timer *timer, int over __unused) |
Handle SAN device command timeout. More... | |
static int | sanpath_open (struct san_path *sanpath) |
Open SAN path. More... | |
static void | sanpath_close (struct san_path *sanpath, int rc) |
Close SAN path. More... | |
static void | sanpath_block_close (struct san_path *sanpath, int rc) |
Handle closure of underlying block device interface. More... | |
static size_t | sanpath_block_window (struct san_path *sanpath __unused) |
Check flow control window. More... | |
static void | sanpath_step (struct san_path *sanpath) |
SAN path process. More... | |
static void | sandev_restart (struct san_device *sandev, int rc) |
Restart SAN device interface. More... | |
int | sandev_reopen (struct san_device *sandev) |
(Re)open SAN device More... | |
static int | sandev_command_rw (struct san_device *sandev, const union san_command_params *params) |
Initiate SAN device read/write command. More... | |
static int | sandev_command_read_capacity (struct san_device *sandev, const union san_command_params *params __unused) |
Initiate SAN device read capacity command. More... | |
static int | sandev_command (struct san_device *sandev, int(*command)(struct san_device *sandev, const union san_command_params *params), const union san_command_params *params) |
Execute a single SAN device command and wait for completion. More... | |
int | sandev_reset (struct san_device *sandev) |
Reset SAN device. More... | |
static int | sandev_rw (struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer, int(*block_rw)(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len)) |
Read from or write to SAN device. More... | |
int | sandev_read (struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer) |
Read from SAN device. More... | |
int | sandev_write (struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer) |
Write to SAN device. More... | |
static int | sandev_describe (struct san_device *sandev) |
Describe SAN device. More... | |
static void | sandev_undescribe (struct san_device *sandev) |
Remove SAN device descriptors. More... | |
static int | sandev_parse_iso9660 (struct san_device *sandev) |
Configure SAN device as a CD-ROM, if applicable. More... | |
struct san_device * | alloc_sandev (struct uri **uris, unsigned int count, size_t priv_size) |
Allocate SAN device. More... | |
int | register_sandev (struct san_device *sandev, unsigned int drive, unsigned int flags) |
Register SAN device. More... | |
void | unregister_sandev (struct san_device *sandev) |
Unregister SAN device. More... | |
const struct setting san_drive_setting | __setting (SETTING_SANBOOT_EXTRA, san-drive) |
The "san-drive" setting. More... | |
unsigned int | san_default_drive (void) |
Get default SAN drive number. More... | |
static int | sandev_apply (void) |
Apply SAN boot settings. More... | |
Variables | |
static unsigned long | san_retries = SAN_DEFAULT_RETRIES |
Number of times to retry commands. More... | |
static struct interface_operation | sandev_command_op [] |
SAN device command interface operations. More... | |
static struct interface_descriptor | sandev_command_desc |
SAN device command interface descriptor. More... | |
static struct interface_operation | sanpath_block_op [] |
SAN path block interface operations. More... | |
static struct interface_descriptor | sanpath_block_desc |
SAN path block interface descriptor. More... | |
static struct process_descriptor | sanpath_process_desc |
SAN path process descriptor. More... | |
struct settings_applicator sandev_applicator | __settings_applicator |
Settings applicator. More... | |
SAN booting.
Definition in file sanboot.c.
#define SAN_DEFAULT_DRIVE 0x80 |
Default SAN drive number.
The drive number is a meaningful concept only in a BIOS environment, where it represents the INT13 drive number (0x80 for the first hard disk). We retain it in other environments to allow for a simple way for iPXE commands to refer to SAN drives.
#define SAN_COMMAND_TIMEOUT ( 15 * TICKS_PER_SEC ) |
Timeout for block device commands (in ticks)
Underlying devices should ideally never become totally stuck. However, if they do, then the blocking SAN APIs provide no means for the caller to cancel the operation, and the machine appears to hang. Use an overall timeout for all commands to avoid this problem and bounce timeout failures to the caller.
#define SAN_DEFAULT_RETRIES 10 |
Default number of times to retry commands.
We may need to retry commands. For example, the underlying connection may be closed by the SAN target due to an inactivity timeout, or the SAN target may return pointless "error" messages such as "SCSI power-on occurred".
#define SAN_REOPEN_DELAY_SECS 5 |
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
LIST_HEAD | ( | san_devices | ) |
List of SAN devices.
struct san_device* sandev_find | ( | unsigned int | drive | ) |
Find SAN device by drive number.
drive | Drive number |
sandev | SAN device, or NULL |
Definition at line 100 of file sanboot.c.
References drive, san_device::drive, san_device::list, list_for_each_entry, NULL, and san_devices.
Referenced by dummy_san_unhook(), efi_block_boot(), efi_block_unhook(), int13_unhook(), and register_sandev().
|
static |
Free SAN device.
refcnt | Reference count |
Definition at line 115 of file sanboot.c.
References san_device::active, assert(), container_of, san_path::desc, free, list_empty, NULL, san_device::opened, san_device::path, san_device::paths, san_device::timer, san_path::uri, and uri_put().
Referenced by alloc_sandev().
|
static |
Close SAN device command.
sandev | SAN device |
rc | Reason for close |
Definition at line 136 of file sanboot.c.
References san_device::command, san_device::command_rc, intf_restart(), rc, stop_timer(), and san_device::timer.
Referenced by sandev_command_expired(), sandev_restart(), and sanpath_close().
|
static |
Record SAN device capacity.
sandev | SAN device |
capacity | SAN device capacity |
Definition at line 154 of file sanboot.c.
References san_device::capacity, and memcpy().
|
static |
Handle SAN device command timeout.
retry | Retry timer |
Definition at line 177 of file sanboot.c.
References container_of, ETIMEDOUT, and sandev_command_close().
Referenced by alloc_sandev().
|
static |
Open SAN path.
sanpath | SAN path |
rc | Return status code |
Definition at line 191 of file sanboot.c.
References acpi_add(), acpi_del(), acpi_describe(), san_path::block, san_device::closed, DBGC, san_path::desc, san_device::drive, EINPROGRESS, san_device::flags, san_path::index, san_path::list, san_device::list, list_add_tail, list_check_contains_entry, list_del, san_device::opened, san_path::path_rc, san_path::process, process_add(), rc, SAN_NO_DESCRIBE, san_path::sandev, strerror(), san_path::uri, and xfer_open_uri().
Referenced by sandev_reopen().
|
static |
Close SAN path.
sanpath | SAN path |
rc | Reason for close |
Definition at line 233 of file sanboot.c.
References san_device::active, san_path::block, san_device::closed, san_device::command, intf_restart(), intfs_restart(), san_path::list, list_add_tail, list_del, NULL, san_path::path_rc, san_path::process, process_del(), rc, san_path::sandev, and sandev_command_close().
Referenced by sandev_restart(), sanpath_block_close(), and sanpath_step().
|
static |
Handle closure of underlying block device interface.
sanpath | SAN path |
rc | Reason for close |
Definition at line 262 of file sanboot.c.
References DBGC, san_device::drive, ENOTCONN, san_path::index, rc, san_path::sandev, sanpath_close(), and strerror().
Check flow control window.
sanpath | SAN path |
|
static |
SAN path process.
sanpath | SAN path |
Definition at line 294 of file sanboot.c.
References san_device::active, san_path::block, DBGC, san_device::drive, san_path::index, san_path::path_rc, san_path::sandev, sanpath_close(), and xfer_window().
|
static |
Restart SAN device interface.
sandev | SAN device |
rc | Reason for restart |
Definition at line 341 of file sanboot.c.
References san_device::active, san_path::list, list_first_entry, NULL, san_device::opened, rc, san_path::sandev, sandev_command_close(), and sanpath_close().
Referenced by register_sandev(), sandev_reopen(), and unregister_sandev().
int sandev_reopen | ( | struct san_device * | sandev | ) |
(Re)open SAN device
sandev | SAN device |
rc | Return status code |
This function will block until the device is available.
Definition at line 365 of file sanboot.c.
References san_device::active, assert(), san_device::closed, DBGC, san_device::drive, ECONNRESET, ENODEV, san_path::list, list_empty, list_first_entry, list_for_each_entry, NULL, san_device::opened, san_path::path_rc, rc, san_path::sandev, sandev_restart(), sanpath_open(), step(), strerror(), and unquiesce().
Referenced by int13_device_path_info(), register_sandev(), sandev_command(), and sandev_reset().
|
static |
Initiate SAN device read/write command.
sandev | SAN device |
params | Command parameters |
rc | Return status code |
Definition at line 443 of file sanboot.c.
References san_device::active, assert(), block_device_capacity::blksize, san_path::block, san_command_rw_params::block_rw, san_command_rw_params::buffer, san_device::capacity, san_device::command, san_command_rw_params::count, DBGC, san_device::drive, san_path::index, san_command_rw_params::lba, len, NULL, rc, san_command_params::rw, san_path::sandev, and strerror().
Referenced by sandev_rw().
|
static |
Initiate SAN device read capacity command.
sandev | SAN device |
params | Command parameters |
rc | Return status code |
Definition at line 472 of file sanboot.c.
References san_device::active, assert(), san_path::block, block_read_capacity(), san_device::command, DBGC, san_device::drive, san_path::index, NULL, rc, san_path::sandev, and strerror().
Referenced by register_sandev().
|
static |
Execute a single SAN device command and wait for completion.
sandev | SAN device |
command | Command |
params | Command parameters (if required) |
rc | Return status code |
Definition at line 500 of file sanboot.c.
References assert(), san_device::command_rc, san_device::paths, rc, SAN_COMMAND_TIMEOUT, SAN_REOPEN_DELAY_SECS, san_retries, san_path::sandev, sandev_needs_reopen(), sandev_reopen(), sleep_fixed(), start_timer_fixed(), step(), san_device::timer, and unquiesce().
Referenced by register_sandev(), and sandev_rw().
int sandev_reset | ( | struct san_device * | sandev | ) |
Reset SAN device.
sandev | SAN device |
rc | Return status code |
Definition at line 565 of file sanboot.c.
References DBGC, san_device::drive, rc, san_path::sandev, and sandev_reopen().
Referenced by efi_block_io_reset(), and int13_reset().
|
static |
Read from or write to SAN device.
sandev | SAN device |
lba | Starting logical block address |
count | Number of logical blocks |
buffer | Data buffer |
block_rw | Block read/write method |
rc | Return status code |
Definition at line 587 of file sanboot.c.
References block_device_capacity::blksize, san_device::blksize_shift, san_command_rw_params::block_rw, buffer, san_command_rw_params::buffer, san_device::capacity, count, san_command_rw_params::count, lba, san_command_rw_params::lba, block_device_capacity::max_count, rc, san_command_params::rw, sandev_command(), sandev_command_rw(), and userptr_add().
Referenced by efi_block_rw(), int13_extended_rw(), int13_rw_sectors(), sandev_read(), and sandev_write().
int sandev_read | ( | struct san_device * | sandev, |
uint64_t | lba, | ||
unsigned int | count, | ||
userptr_t | buffer | ||
) |
Read from SAN device.
sandev | SAN device |
lba | Starting logical block address |
count | Number of logical blocks |
buffer | Data buffer |
rc | Return status code |
Definition at line 636 of file sanboot.c.
References block_read(), buffer, count, lba, rc, and sandev_rw().
Referenced by efi_block_io_read(), int13_cdrom_read_boot_catalog(), int13_extended_read(), int13_guess_geometry_hdd(), int13_parse_eltorito(), int13_read_sectors(), and sandev_parse_iso9660().
int sandev_write | ( | struct san_device * | sandev, |
uint64_t | lba, | ||
unsigned int | count, | ||
userptr_t | buffer | ||
) |
Write to SAN device.
sandev | SAN device |
lba | Starting logical block address |
count | Number of logical blocks |
buffer | Data buffer |
rc | Return status code |
Definition at line 656 of file sanboot.c.
References block_write(), buffer, count, lba, quiesce(), rc, and sandev_rw().
Referenced by efi_block_io_write(), int13_extended_write(), and int13_write_sectors().
|
static |
Describe SAN device.
sandev | SAN device |
rc | Return status code |
Allow connections to progress until all existent path descriptors are complete.
Definition at line 684 of file sanboot.c.
References san_device::closed, acpi_model::complete, DBGC, san_path::desc, san_device::drive, san_path::index, acpi_descriptor::list, list_for_each_entry, acpi_descriptor::model, san_device::opened, rc, step(), and strerror().
Referenced by register_sandev().
|
static |
Remove SAN device descriptors.
sandev | SAN device |
Definition at line 727 of file sanboot.c.
References acpi_del(), san_path::desc, NULL, san_device::path, san_device::paths, and san_path::sandev.
Referenced by register_sandev(), and unregister_sandev().
|
static |
Configure SAN device as a CD-ROM, if applicable.
sandev | SAN device |
rc | Return status code |
Both BIOS and UEFI require SAN devices to be accessed with a block size of 2048. While we could require the user to configure the block size appropriately, this is non-trivial and would impose a substantial learning effort on the user. Instead, we check for the presence of the ISO9660 primary volume descriptor and, if found, then we force a block size of 2048 and map read/write requests appropriately.
Definition at line 755 of file sanboot.c.
References block_device_capacity::blksize, blksize, san_device::blksize_shift, bytes, san_device::capacity, count, DBGC, san_device::drive, ENOMEM, free, san_device::is_cdrom, ISO9660_BLKSIZE, ISO9660_ID, ISO9660_PRIMARY_LBA, ISO9660_TYPE_PRIMARY, lba, malloc(), memcmp(), primary, rc, sandev_read(), strerror(), iso9660_primary_descriptor_fixed::type, and virt_to_user().
Referenced by register_sandev().
struct san_device* alloc_sandev | ( | struct uri ** | uris, |
unsigned int | count, | ||
size_t | priv_size | ||
) |
Allocate SAN device.
uris | List of URIs |
count | Number of URIs |
priv_size | Size of private data |
sandev | SAN device, or NULL |
Definition at line 825 of file sanboot.c.
References san_path::block, san_device::closed, san_device::command, count, EINPROGRESS, san_path::index, INIT_LIST_HEAD, intf_init(), san_path::list, list_add_tail, NULL, san_device::opened, san_device::path, san_path::path_rc, san_device::paths, san_device::priv, san_path::process, process_init_stopped(), ref_init, san_device::refcnt, san_path::sandev, sandev_command_desc, sandev_command_expired(), sandev_free(), sanpath_block_desc, sanpath_process_desc, size, san_device::timer, san_path::uri, uri_get(), and zalloc().
Referenced by dummy_san_hook(), efi_block_hook(), and int13_hook().
int register_sandev | ( | struct san_device * | sandev, |
unsigned int | drive, | ||
unsigned int | flags | ||
) |
Register SAN device.
sandev | SAN device |
drive | Drive number |
flags | Flags |
rc | Return status code |
Definition at line 868 of file sanboot.c.
References DBGC, drive, san_device::drive, EADDRINUSE, flags, san_device::flags, san_device::list, list_add_tail, list_del, NULL, rc, san_devices, san_path::sandev, sandev_command(), sandev_command_read_capacity(), sandev_describe(), sandev_find(), sandev_parse_iso9660(), sandev_reopen(), sandev_restart(), and sandev_undescribe().
Referenced by dummy_san_hook(), efi_block_hook(), and int13_hook().
void unregister_sandev | ( | struct san_device * | sandev | ) |
Unregister SAN device.
sandev | SAN device |
Definition at line 925 of file sanboot.c.
References assert(), DBGC, san_device::drive, san_device::list, list_del, san_path::sandev, sandev_restart(), sandev_undescribe(), and san_device::timer.
Referenced by dummy_san_hook(), dummy_san_unhook(), efi_block_hook(), efi_block_unhook(), int13_hook(), and int13_unhook().
const struct setting san_retries_setting __setting | ( | SETTING_SANBOOT_EXTRA | , |
san- | drive | ||
) |
The "san-drive" setting.
The "san-retries" setting.
unsigned int san_default_drive | ( | void | ) |
Get default SAN drive number.
drive | Default drive number |
Definition at line 956 of file sanboot.c.
References drive, fetch_uint_setting(), NULL, and SAN_DEFAULT_DRIVE.
Referenced by netboot(), and sanboot_core_exec().
|
static |
Apply SAN boot settings.
rc | Return status code |
Definition at line 981 of file sanboot.c.
References fetch_uint_setting(), NULL, SAN_DEFAULT_RETRIES, and san_retries.
|
static |
Number of times to retry commands.
Definition at line 92 of file sanboot.c.
Referenced by sandev_apply(), and sandev_command().
|
static |
SAN device command interface operations.
|
static |
SAN device command interface descriptor.
Definition at line 169 of file sanboot.c.
Referenced by alloc_sandev().
|
static |
SAN path block interface operations.
|
static |
SAN path block interface descriptor.
Definition at line 328 of file sanboot.c.
Referenced by alloc_sandev().
|
static |
SAN path process descriptor.
Definition at line 332 of file sanboot.c.
Referenced by alloc_sandev().
struct settings_applicator sandev_applicator __settings_applicator |
Settings applicator.