Преглед изворни кода

[init] Remove concept of "shutdown exit flags"

Remove the concept of shutdown exit flags, and replace it with a
counter used to keep track of exposed interfaces that require devices
to remain active.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown пре 13 година
родитељ
комит
962cada830

+ 3
- 3
src/arch/i386/drivers/net/undionly.c Прегледај датотеку

@@ -114,13 +114,13 @@ struct root_device undi_root_device __root_device = {
114 114
 /**
115 115
  * Prepare for exit
116 116
  *
117
- * @v flags		Shutdown flags
117
+ * @v booting		System is shutting down for OS boot
118 118
  */
119
-static void undionly_shutdown ( int flags ) {
119
+static void undionly_shutdown ( int booting ) {
120 120
 	/* If we are shutting down to boot an OS, clear the "keep PXE
121 121
 	 * stack" flag.
122 122
 	 */
123
-	if ( flags & SHUTDOWN_BOOT )
123
+	if ( booting )
124 124
 		preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
125 125
 }
126 126
 

+ 1
- 1
src/arch/i386/image/bzimage.c Прегледај датотеку

@@ -477,7 +477,7 @@ static int bzimage_exec ( struct image *image ) {
477 477
 	bzimage_update_header ( image, &bzimg, bzimg.rm_kernel );
478 478
 
479 479
 	/* Prepare for exiting */
480
-	shutdown ( SHUTDOWN_BOOT );
480
+	shutdown_boot();
481 481
 
482 482
 	DBGC ( image, "bzImage %p jumping to RM kernel at %04x:0000 "
483 483
 	       "(stack %04x:%04zx)\n", image, ( bzimg.rm_kernel_seg + 0x20 ),

+ 1
- 1
src/arch/i386/image/elfboot.c Прегледај датотеку

@@ -48,7 +48,7 @@ static int elfboot_exec ( struct image *image ) {
48 48
 	/* An ELF image has no callback interface, so we need to shut
49 49
 	 * down before invoking it.
50 50
 	 */
51
-	shutdown ( SHUTDOWN_BOOT );
51
+	shutdown_boot();
52 52
 
53 53
 	/* Jump to OS with flat physical addressing */
54 54
 	DBGC ( image, "ELF %p starting execution at %lx\n", image, entry );

+ 1
- 1
src/arch/i386/image/multiboot.c Прегледај датотеку

@@ -278,7 +278,7 @@ static int multiboot_exec ( struct image *image ) {
278 278
 	/* Multiboot images may not return and have no callback
279 279
 	 * interface, so shut everything down prior to booting the OS.
280 280
 	 */
281
-	shutdown ( SHUTDOWN_BOOT );
281
+	shutdown_boot();
282 282
 
283 283
 	/* Build memory map after unhiding bootloader memory regions as part of
284 284
 	 * shutting everything down.

+ 1
- 1
src/arch/i386/image/nbi.c Прегледај датотеку

@@ -406,7 +406,7 @@ static int nbi_exec ( struct image *image ) {
406 406
 	/* Shut down now if NBI image will not return */
407 407
 	may_return = NBI_PROGRAM_RETURNS ( imgheader.flags );
408 408
 	if ( ! may_return )
409
-		shutdown ( SHUTDOWN_BOOT );
409
+		shutdown_boot();
410 410
 
411 411
 	/* Execute NBI image */
412 412
 	if ( NBI_LINEAR_EXEC_ADDR ( imgheader.flags ) ) {

+ 6
- 2
src/arch/i386/interface/pcbios/int13.c Прегледај датотеку

@@ -1209,8 +1209,10 @@ static int int13_hook ( struct uri *uri, unsigned int drive ) {
1209 1209
 	       int13->cylinders, int13->heads, int13->sectors_per_track );
1210 1210
 
1211 1211
 	/* Hook INT 13 vector if not already hooked */
1212
-	if ( list_empty ( &int13s ) )
1212
+	if ( list_empty ( &int13s ) ) {
1213 1213
 		int13_hook_vector();
1214
+		devices_get();
1215
+	}
1214 1216
 
1215 1217
 	/* Add to list of emulated drives */
1216 1218
 	list_add ( &int13->list, &int13s );
@@ -1277,8 +1279,10 @@ static void int13_unhook ( unsigned int drive ) {
1277 1279
 	DBGC ( int13, "INT13 drive %02x unregistered\n", int13->drive );
1278 1280
 
1279 1281
 	/* Unhook INT 13 vector if no more drives */
1280
-	if ( list_empty ( &int13s ) )
1282
+	if ( list_empty ( &int13s ) ) {
1283
+		devices_put();
1281 1284
 		int13_unhook_vector();
1285
+	}
1282 1286
 
1283 1287
 	/* Drop list's reference to drive */
1284 1288
 	ref_put ( &int13->refcnt );

+ 2
- 0
src/arch/i386/interface/pxe/pxe_call.c Прегледај датотеку

@@ -448,6 +448,7 @@ void pxe_activate ( struct net_device *netdev ) {
448 448
 	if ( ! int_1a_hooked ) {
449 449
 		hook_bios_interrupt ( 0x1a, ( unsigned int ) pxe_int_1a,
450 450
 				      &pxe_int_1a_vector );
451
+		devices_get();
451 452
 		int_1a_hooked = 1;
452 453
 	}
453 454
 
@@ -475,6 +476,7 @@ int pxe_deactivate ( void ) {
475 476
 			      strerror ( rc ) );
476 477
 			return rc;
477 478
 		}
479
+		devices_put();
478 480
 		int_1a_hooked = 0;
479 481
 	}
480 482
 

+ 1
- 1
src/arch/i386/interface/pxe/pxe_preboot.c Прегледај датотеку

@@ -290,7 +290,7 @@ PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
290 290
 	pxe_deactivate();
291 291
 
292 292
 	/* Prepare for unload */
293
-	shutdown ( SHUTDOWN_BOOT );
293
+	shutdown_boot();
294 294
 
295 295
 	/* Check to see if we still have any hooked interrupts */
296 296
 	if ( hooked_bios_interrupts != 0 ) {

+ 2
- 2
src/arch/i386/interface/syslinux/comboot_call.c Прегледај датотеку

@@ -531,7 +531,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
531 531
 			break;
532 532
 
533 533
 		/* Perform final cleanup */
534
-		shutdown ( SHUTDOWN_BOOT );
534
+		shutdown_boot();
535 535
 
536 536
 		/* Perform sequence of copies */
537 537
 		shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
@@ -608,7 +608,7 @@ static __asmcall void int22 ( struct i386_all_regs *ix86 ) {
608 608
 			break;
609 609
 
610 610
 		/* Perform final cleanup */
611
-		shutdown ( SHUTDOWN_BOOT );
611
+		shutdown_boot();
612 612
 
613 613
 		/* Perform sequence of copies */
614 614
 		shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );

+ 5
- 2
src/core/device.c Прегледај датотеку

@@ -35,6 +35,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
35 35
 /** Registered root devices */
36 36
 static LIST_HEAD ( devices );
37 37
 
38
+/** Device removal inhibition counter */
39
+int device_keep_count = 0;
40
+
38 41
 /**
39 42
  * Probe a root device
40 43
  *
@@ -87,11 +90,11 @@ static void probe_devices ( void ) {
87 90
  * Remove all devices
88 91
  *
89 92
  */
90
-static void remove_devices ( int flags ) {
93
+static void remove_devices ( int booting __unused ) {
91 94
 	struct root_device *rootdev;
92 95
 	struct root_device *tmp;
93 96
 
94
-	if ( flags & SHUTDOWN_KEEP_DEVICES ) {
97
+	if ( device_keep_count != 0 ) {
95 98
 		DBG ( "Refusing to remove devices on shutdown\n" );
96 99
 		return;
97 100
 	}

+ 1
- 1
src/core/main.c Прегледај датотеку

@@ -85,7 +85,7 @@ __asmcall int main ( void ) {
85 85
 			shell();
86 86
 	}
87 87
 
88
-	shutdown ( SHUTDOWN_EXIT | shutdown_exit_flags );
88
+	shutdown_exit();
89 89
 
90 90
 	return 0;
91 91
 }

+ 3
- 3
src/drivers/net/efi/snponly.c Прегледај датотеку

@@ -114,13 +114,13 @@ struct root_device snp_root_device __root_device = {
114 114
 /**
115 115
  * Prepare for exit
116 116
  *
117
- * @v flags		Shutdown flags
117
+ * @v booting		System is shutting down for OS boot
118 118
  */
119
-static void snponly_shutdown ( int flags ) {
119
+static void snponly_shutdown ( int booting ) {
120 120
 	/* If we are shutting down to boot an OS, make sure the SNP does not
121 121
 	 * stay active.
122 122
 	 */
123
-	if ( flags & SHUTDOWN_BOOT )
123
+	if ( booting )
124 124
 		snponly_dev.removal_state = EfiSimpleNetworkStopped;
125 125
 }
126 126
 

+ 1
- 1
src/image/efi_image.c Прегледај датотеку

@@ -39,7 +39,7 @@ static EFI_EVENT efi_shutdown_event;
39 39
  */
40 40
 static EFIAPI void efi_shutdown_hook ( EFI_EVENT event __unused,
41 41
 				       void *context __unused ) {
42
-	shutdown ( SHUTDOWN_BOOT );
42
+	shutdown_boot();
43 43
 }
44 44
 
45 45
 /**

+ 18
- 0
src/include/ipxe/device.h Прегледај датотеку

@@ -112,6 +112,24 @@ struct root_driver {
112 112
 /** Declare a root device */
113 113
 #define __root_device __table_entry ( ROOT_DEVICES, 01 )
114 114
 
115
+extern int device_keep_count;
116
+
117
+/**
118
+ * Prevent devices from being removed on shutdown
119
+ *
120
+ */
121
+static inline void devices_get ( void ) {
122
+	device_keep_count++;
123
+}
124
+
125
+/**
126
+ * Allow devices to be removed on shutdown
127
+ *
128
+ */
129
+static inline void devices_put ( void ) {
130
+	device_keep_count--;
131
+}
132
+
115 133
 extern struct device * identify_device ( struct interface *intf );
116 134
 #define identify_device_TYPE( object_type ) \
117 135
 	typeof ( struct device * ( object_type ) )

+ 18
- 12
src/include/ipxe/init.h Прегледај датотеку

@@ -32,16 +32,6 @@ struct init_fn {
32 32
 
33 33
 /** @} */
34 34
 
35
-/** Shutdown flags */
36
-enum shutdown_flags {
37
-	/** Shutdown is in order to exit (return to iPXE's caller) */
38
-	SHUTDOWN_EXIT = 0x0001,
39
-	/** Shutdown is in order to boot an OS */
40
-	SHUTDOWN_BOOT = 0x0002,
41
-	/** Do not remove devices */
42
-	SHUTDOWN_KEEP_DEVICES = 0x0004,
43
-};
44
-
45 35
 /**
46 36
  * A startup/shutdown function
47 37
  *
@@ -50,7 +40,7 @@ enum shutdown_flags {
50 40
  */
51 41
 struct startup_fn {
52 42
 	void ( * startup ) ( void );
53
-	void ( * shutdown ) ( int flags );
43
+	void ( * shutdown ) ( int booting );
54 44
 };
55 45
 
56 46
 /** Startup/shutdown function table */
@@ -76,6 +66,22 @@ struct startup_fn {
76 66
 
77 67
 extern void initialise ( void );
78 68
 extern void startup ( void );
79
-extern void shutdown ( int flags );
69
+extern void shutdown ( int booting );
70
+
71
+/**
72
+ * Shut down system for OS boot
73
+ *
74
+ */
75
+static inline void shutdown_boot ( void ) {
76
+	shutdown ( 1 );
77
+}
78
+
79
+/**
80
+ * Shut down system for exit back to firmware
81
+ *
82
+ */
83
+static inline void shutdown_exit ( void ) {
84
+	shutdown ( 0 );
85
+}
80 86
 
81 87
 #endif /* _IPXE_INIT_H */

+ 0
- 2
src/include/usr/autoboot.h Прегледај датотеку

@@ -12,8 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
12 12
 #include <ipxe/in.h>
13 13
 struct net_device;
14 14
 
15
-extern int shutdown_exit_flags;
16
-
17 15
 extern int netboot ( struct net_device *netdev );
18 16
 extern int autoboot ( void );
19 17
 extern int boot_next_server_and_filename ( struct in_addr next_server,

+ 0
- 4
src/usr/autoboot.c Прегледај датотеку

@@ -40,9 +40,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
40 40
  *
41 41
  */
42 42
 
43
-/** Shutdown flags for exit */
44
-int shutdown_exit_flags = 0;
45
-
46 43
 /**
47 44
  * Perform PXE menu boot when PXE stack is not available
48 45
  */
@@ -193,7 +190,6 @@ int boot_root_path ( const char *root_path ) {
193 190
 	if ( fetch_intz_setting ( NULL, &keep_san_setting ) != 0 ) {
194 191
 		printf ( "Preserving connection to SAN device %#02x\n",
195 192
 			 drive );
196
-		shutdown_exit_flags |= SHUTDOWN_KEEP_DEVICES;
197 193
 		goto err_keep_san;
198 194
 	}
199 195
 

Loading…
Откажи
Сачувај