Browse Source

[Command] Add "sanboot" command.

tags/v0.9.4
Michael Brown 16 years ago
parent
commit
b08a6f5300
5 changed files with 74 additions and 1 deletions
  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 View File

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

+ 3
- 0
src/core/config.c View File

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

+ 68
- 0
src/hci/commands/sanboot_cmd.c View File

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 View File

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

+ 1
- 1
src/usr/autoboot.c View File

108
  * @v root_path		Root path
108
  * @v root_path		Root path
109
  * @ret rc		Return status code
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
 	/* Quick hack */
113
 	/* Quick hack */
114
 	if ( strncmp ( root_path, "iscsi:", 6 ) == 0 ) {
114
 	if ( strncmp ( root_path, "iscsi:", 6 ) == 0 ) {

Loading…
Cancel
Save