Quellcode durchsuchen

[Command] Add "sanboot" command.

tags/v0.9.4
Michael Brown vor 16 Jahren
Ursprung
Commit
b08a6f5300
5 geänderte Dateien mit 74 neuen und 1 gelöschten Zeilen
  1. 1
    0
      src/config.h
  2. 3
    0
      src/core/config.c
  3. 68
    0
      src/hci/commands/sanboot_cmd.c
  4. 1
    0
      src/include/usr/autoboot.h
  5. 1
    1
      src/usr/autoboot.c

+ 1
- 0
src/config.h Datei anzeigen

@@ -125,6 +125,7 @@
125 125
 #define	ROUTE_CMD		/* Routing table management commands */
126 126
 #define IMAGE_CMD		/* Image management commands */
127 127
 #define DHCP_CMD		/* DHCP management commands */
128
+#define SANBOOT_CMD		/* SAN boot commands */
128 129
 
129 130
 /* @END general.h */ 
130 131
 

+ 3
- 0
src/core/config.c Datei anzeigen

@@ -175,6 +175,9 @@ REQUIRE_OBJECT ( image_cmd );
175 175
 #ifdef DHCP_CMD
176 176
 REQUIRE_OBJECT ( dhcp_cmd );
177 177
 #endif
178
+#ifdef SANBOOT_CMD
179
+REQUIRE_OBJECT ( sanboot_cmd );
180
+#endif
178 181
 
179 182
 /*
180 183
  * Drag in miscellaneous objects

+ 68
- 0
src/hci/commands/sanboot_cmd.c Datei anzeigen

@@ -0,0 +1,68 @@
1
+#include <stdio.h>
2
+#include <string.h>
3
+#include <getopt.h>
4
+#include <gpxe/command.h>
5
+#include <usr/autoboot.h>
6
+
7
+/**
8
+ * "sanboot" command syntax message
9
+ *
10
+ * @v argv		Argument list
11
+ */
12
+static void sanboot_syntax ( char **argv ) {
13
+	printf ( "Usage:\n"
14
+		 "  %s <root-path>\n"
15
+		 "\n"
16
+		 "Boot from SAN target\n",
17
+		 argv[0] );
18
+}
19
+
20
+/**
21
+ * The "sanboot" command
22
+ *
23
+ * @v argc		Argument count
24
+ * @v argv		Argument list
25
+ * @ret rc		Exit code
26
+ */
27
+static int sanboot_exec ( int argc, char **argv ) {
28
+	static struct option longopts[] = {
29
+		{ "help", 0, NULL, 'h' },
30
+		{ NULL, 0, NULL, 0 },
31
+	};
32
+	const char *root_path = NULL;
33
+	int c;
34
+	int rc;
35
+
36
+	/* Parse options */
37
+	while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
38
+		switch ( c ) {
39
+		case 'h':
40
+			/* Display help text */
41
+		default:
42
+			/* Unrecognised/invalid option */
43
+			sanboot_syntax ( argv );
44
+			return 1;
45
+		}
46
+	}
47
+
48
+	/* Need exactly one image name remaining after the options */
49
+	if ( optind != ( argc - 1 ) ) {
50
+		sanboot_syntax ( argv );
51
+		return 1;
52
+	}
53
+	root_path = argv[optind];
54
+
55
+	/* Boot from root path */
56
+	if ( ( rc = boot_root_path ( root_path ) ) != 0 ) {
57
+		printf ( "Could not boot from %s: %s\n",
58
+			 root_path, strerror ( rc ) );
59
+		return 1;
60
+	}
61
+
62
+	return 0;
63
+}
64
+
65
+struct command sanboot_command __command = {
66
+	.name = "sanboot",
67
+	.exec = sanboot_exec,
68
+};

+ 1
- 0
src/include/usr/autoboot.h Datei anzeigen

@@ -8,5 +8,6 @@
8 8
  */
9 9
 
10 10
 extern void autoboot ( void );
11
+extern int boot_root_path ( const char *root_path );
11 12
 
12 13
 #endif /* _USR_AUTOBOOT_H */

+ 1
- 1
src/usr/autoboot.c Datei anzeigen

@@ -108,7 +108,7 @@ static int boot_filename ( const char *filename ) {
108 108
  * @v root_path		Root path
109 109
  * @ret rc		Return status code
110 110
  */
111
-static int boot_root_path ( const char *root_path ) {
111
+int boot_root_path ( const char *root_path ) {
112 112
 
113 113
 	/* Quick hack */
114 114
 	if ( strncmp ( root_path, "iscsi:", 6 ) == 0 ) {

Laden…
Abbrechen
Speichern