Переглянути джерело

[block] Add dummy SAN device

Add a dummy SAN device which allows the "sanhook" command to be tested
even when no SAN booting capability is present on the platform.  This
allows substantial portions of the SAN boot code to be run in Linux
under Valgrind.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 роки тому
джерело
коміт
c212597336

+ 115
- 0
src/core/dummy_sanboot.c Переглянути файл

@@ -0,0 +1,115 @@
1
+/*
2
+ * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ *
19
+ * You can also choose to distribute this program under the terms of
20
+ * the Unmodified Binary Distribution Licence (as given in the file
21
+ * COPYING.UBDL), provided that you have satisfied its requirements.
22
+ */
23
+
24
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
+
26
+/** @file
27
+ *
28
+ * Dummy SAN device
29
+ *
30
+ */
31
+
32
+#include <errno.h>
33
+#include <ipxe/sanboot.h>
34
+
35
+/**
36
+ * Hook dummy SAN device
37
+ *
38
+ * @v uri		URI
39
+ * @v drive		Drive number
40
+ * @ret drive		Drive number, or negative error
41
+ */
42
+static int dummy_san_hook ( struct uri *uri, unsigned int drive ) {
43
+	struct san_device *sandev;
44
+	int rc;
45
+
46
+	/* Allocate SAN device */
47
+	sandev = alloc_sandev ( uri, 0 );
48
+	if ( ! sandev ) {
49
+		rc = -ENOMEM;
50
+		goto err_alloc;
51
+	}
52
+	sandev->drive = drive;
53
+
54
+	/* Register SAN device */
55
+	if ( ( rc = register_sandev ( sandev ) ) != 0 ) {
56
+		DBGC ( sandev, "SAN %#02x could not register: %s\n",
57
+		       sandev->drive, strerror ( rc ) );
58
+		goto err_register;
59
+	}
60
+
61
+	return drive;
62
+
63
+	unregister_sandev ( sandev );
64
+ err_register:
65
+	sandev_put ( sandev );
66
+ err_alloc:
67
+	return rc;
68
+}
69
+
70
+/**
71
+ * Unhook dummy SAN device
72
+ *
73
+ * @v drive		Drive number
74
+ */
75
+static void dummy_san_unhook ( unsigned int drive ) {
76
+	struct san_device *sandev;
77
+
78
+	/* Find drive */
79
+	sandev = sandev_find ( drive );
80
+	if ( ! sandev ) {
81
+		DBG ( "SAN %#02x does not exist\n", drive );
82
+		return;
83
+	}
84
+
85
+	/* Unregister SAN device */
86
+	unregister_sandev ( sandev );
87
+
88
+	/* Drop reference to drive */
89
+	sandev_put ( sandev );
90
+}
91
+
92
+/**
93
+ * Boot from dummy SAN device
94
+ *
95
+ * @v drive		Drive number
96
+ */
97
+static int dummy_san_boot ( unsigned int drive __unused ) {
98
+
99
+	return -EOPNOTSUPP;
100
+}
101
+
102
+/**
103
+ * Describe dummy SAN device
104
+ *
105
+ * @v drive		Drive number
106
+ */
107
+static int dummy_san_describe ( unsigned int drive __unused ) {
108
+
109
+	return 0;
110
+}
111
+
112
+PROVIDE_SANBOOT ( dummy, san_hook, dummy_san_hook );
113
+PROVIDE_SANBOOT ( dummy, san_unhook, dummy_san_unhook );
114
+PROVIDE_SANBOOT ( dummy, san_boot, dummy_san_boot );
115
+PROVIDE_SANBOOT ( dummy, san_describe, dummy_san_describe );

+ 18
- 0
src/include/ipxe/dummy_sanboot.h Переглянути файл

@@ -0,0 +1,18 @@
1
+#ifndef _IPXE_DUMMY_SANBOOT_H
2
+#define _IPXE_DUMMY_SANBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * Dummy SAN device
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#ifdef SANBOOT_DUMMY
13
+#define SANBOOT_PREFIX_dummy
14
+#else
15
+#define SANBOOT_PREFIX_dummy __dummy_
16
+#endif
17
+
18
+#endif /* _IPXE_DUMMY_SANBOOT_H */

+ 1
- 0
src/include/ipxe/errfile.h Переглянути файл

@@ -73,6 +73,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
73 73
 #define ERRFILE_pixbuf		       ( ERRFILE_CORE | 0x00210000 )
74 74
 #define ERRFILE_efi_block	       ( ERRFILE_CORE | 0x00220000 )
75 75
 #define ERRFILE_sanboot		       ( ERRFILE_CORE | 0x00230000 )
76
+#define ERRFILE_dummy_sanboot	       ( ERRFILE_CORE | 0x00240000 )
76 77
 
77 78
 #define ERRFILE_eisa		     ( ERRFILE_DRIVER | 0x00000000 )
78 79
 #define ERRFILE_isa		     ( ERRFILE_DRIVER | 0x00010000 )

+ 1
- 0
src/include/ipxe/sanboot.h Переглянути файл

@@ -90,6 +90,7 @@ struct san_device {
90 90
 
91 91
 /* Include all architecture-independent sanboot API headers */
92 92
 #include <ipxe/null_sanboot.h>
93
+#include <ipxe/dummy_sanboot.h>
93 94
 #include <ipxe/efi/efi_block.h>
94 95
 
95 96
 /* Include all architecture-dependent sanboot API headers */

Завантаження…
Відмінити
Зберегти