iscsiboot.c
Go to the documentation of this file.00001 #include <stdint.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include <errno.h>
00006 #include <gpxe/iscsi.h>
00007 #include <gpxe/netdevice.h>
00008 #include <gpxe/ibft.h>
00009 #include <gpxe/sanboot.h>
00010 #include <int13.h>
00011
00012 FILE_LICENCE ( GPL2_OR_LATER );
00013
00014 static int iscsiboot ( const char *root_path ) {
00015 struct scsi_device *scsi;
00016 struct int13_drive *drive;
00017 int rc;
00018
00019 scsi = zalloc ( sizeof ( *scsi ) );
00020 if ( ! scsi ) {
00021 rc = -ENOMEM;
00022 goto err_alloc_scsi;
00023 }
00024 drive = zalloc ( sizeof ( *drive ) );
00025 if ( ! drive ) {
00026 rc = -ENOMEM;
00027 goto err_alloc_drive;
00028 }
00029
00030 if ( ( rc = iscsi_attach ( scsi, root_path ) ) != 0 ) {
00031 printf ( "Could not attach iSCSI device: %s\n",
00032 strerror ( rc ) );
00033 goto err_attach;
00034 }
00035 if ( ( rc = init_scsidev ( scsi ) ) != 0 ) {
00036 printf ( "Could not initialise iSCSI device: %s\n",
00037 strerror ( rc ) );
00038 goto err_init;
00039 }
00040
00041 drive->blockdev = &scsi->blockdev;
00042
00043
00044 struct net_device *netdev = last_opened_netdev();
00045 struct iscsi_session *iscsi =
00046 container_of ( scsi->backend, struct iscsi_session, refcnt );
00047 ibft_fill_data ( netdev, iscsi );
00048
00049 register_int13_drive ( drive );
00050 printf ( "Registered as BIOS drive %#02x\n", drive->drive );
00051 printf ( "Booting from BIOS drive %#02x\n", drive->drive );
00052 rc = int13_boot ( drive->drive );
00053 printf ( "Boot failed\n" );
00054
00055
00056 if ( keep_san() )
00057 return rc;
00058
00059 printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
00060 unregister_int13_drive ( drive );
00061
00062 err_init:
00063 iscsi_detach ( scsi );
00064 err_attach:
00065 free ( drive );
00066 err_alloc_drive:
00067 free ( scsi );
00068 err_alloc_scsi:
00069 return rc;
00070 }
00071
00072 struct sanboot_protocol iscsi_sanboot_protocol __sanboot_protocol = {
00073 .prefix = "iscsi:",
00074 .boot = iscsiboot,
00075 };