summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2017-03-27 15:56:36 +0200
committerMichael Brown2017-03-27 15:57:40 +0200
commit539088a27b0c60ef4bc413a7042f8b9f3ad60e97 (patch)
tree4f88490652062db9599b3f555369c91c75526f40 /src/core
parent[block] Retry reopening indefinitely for multipath devices (diff)
downloadipxe-539088a27b0c60ef4bc413a7042f8b9f3ad60e97.tar.gz
ipxe-539088a27b0c60ef4bc413a7042f8b9f3ad60e97.tar.xz
ipxe-539088a27b0c60ef4bc413a7042f8b9f3ad60e97.zip
[block] Gracefully close SAN device if registration fails
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/sanboot.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/core/sanboot.c b/src/core/sanboot.c
index 8eb54b7c..7dbf03db 100644
--- a/src/core/sanboot.c
+++ b/src/core/sanboot.c
@@ -733,7 +733,8 @@ int register_sandev ( struct san_device *sandev ) {
/* Check that drive number is not in use */
if ( sandev_find ( sandev->drive ) != NULL ) {
DBGC ( sandev, "SAN %#02x is already in use\n", sandev->drive );
- return -EADDRINUSE;
+ rc = -EADDRINUSE;
+ goto err_in_use;
}
/* Check that device is capable of being opened (i.e. that all
@@ -741,22 +742,30 @@ int register_sandev ( struct san_device *sandev ) {
* working).
*/
if ( ( rc = sandev_reopen ( sandev ) ) != 0 )
- return rc;
+ goto err_reopen;
/* Read device capacity */
if ( ( rc = sandev_command ( sandev, sandev_command_read_capacity,
NULL ) ) != 0 )
- return rc;
+ goto err_capacity;
/* Configure as a CD-ROM, if applicable */
if ( ( rc = sandev_parse_iso9660 ( sandev ) ) != 0 )
- return rc;
+ goto err_iso9660;
/* Add to list of SAN devices */
list_add_tail ( &sandev->list, &san_devices );
DBGC ( sandev, "SAN %#02x registered\n", sandev->drive );
return 0;
+
+ list_del ( &sandev->list );
+ err_iso9660:
+ err_capacity:
+ err_reopen:
+ sandev_restart ( sandev, rc );
+ err_in_use:
+ return rc;
}
/**
@@ -769,11 +778,12 @@ void unregister_sandev ( struct san_device *sandev ) {
/* Sanity check */
assert ( ! timer_running ( &sandev->timer ) );
+ /* Remove from list of SAN devices */
+ list_del ( &sandev->list );
+
/* Shut down interfaces */
sandev_restart ( sandev, 0 );
- /* Remove from list of SAN devices */
- list_del ( &sandev->list );
DBGC ( sandev, "SAN %#02x unregistered\n", sandev->drive );
}