Selaa lähdekoodia

[interface] Provide the ability to shut down multiple interfaces

Shutting down (and optionally restarting) multiple interfaces is
fraught with problems if there are loops in the interface connectivity
(e.g. the HTTP content-decoded and transfer-decoded interfaces, which
will generally loop back to each other).  Various workarounds
currently exist across the codebase, generally involving preceding
calls to intf_nullify() to avoid problems due to known loops.

Provide intfs_shutdown() and intfs_restart() to allow all of an
object's interfaces to be shut down (or restarted) in a single call,
without having to worry about potential external loops.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 vuotta sitten
vanhempi
commit
23b788e5cd
2 muutettua tiedostoa jossa 74 lisäystä ja 0 poistoa
  1. 69
    0
      src/core/interface.c
  2. 5
    0
      src/include/ipxe/interface.h

+ 69
- 0
src/core/interface.c Näytä tiedosto

290
 	intf_unplug ( &tmp );
290
 	intf_unplug ( &tmp );
291
 }
291
 }
292
 
292
 
293
+/**
294
+ * Shut down multiple object interfaces
295
+ *
296
+ * @v intfs		Object interfaces
297
+ * @v rc		Reason for close
298
+ */
299
+void intfs_vshutdown ( va_list intfs, int rc ) {
300
+	struct interface *intf;
301
+	va_list tmp;
302
+
303
+	/* Nullify all interfaces to avoid potential loops */
304
+	va_copy ( tmp, intfs );
305
+	while ( ( intf = va_arg ( tmp, struct interface * ) ) )
306
+		intf_nullify ( intf );
307
+	va_end ( tmp );
308
+
309
+	/* Shut down all interfaces */
310
+	while ( ( intf = va_arg ( intfs, struct interface * ) ) )
311
+		intf_shutdown ( intf, rc );
312
+}
313
+
314
+/**
315
+ * Shut down multiple object interfaces
316
+ *
317
+ * @v rc		Reason for close
318
+ * @v ...		Object interfaces
319
+ */
320
+void intfs_shutdown ( int rc, ... ) {
321
+	va_list intfs;
322
+
323
+	va_start ( intfs, rc );
324
+	intfs_vshutdown ( intfs, rc );
325
+	va_end ( intfs );
326
+}
327
+
293
 /**
328
 /**
294
  * Shut down and restart an object interface
329
  * Shut down and restart an object interface
295
  *
330
  *
316
 	intf_reinit ( intf );
351
 	intf_reinit ( intf );
317
 }
352
 }
318
 
353
 
354
+/**
355
+ * Shut down and restart multiple object interfaces
356
+ *
357
+ * @v intfs		Object interfaces
358
+ * @v rc		Reason for close
359
+ */
360
+void intfs_vrestart ( va_list intfs, int rc ) {
361
+	struct interface *intf;
362
+	va_list tmp;
363
+
364
+	/* Shut down all interfaces */
365
+	va_copy ( tmp, intfs );
366
+	intfs_vshutdown ( tmp, rc );
367
+	va_end ( tmp );
368
+
369
+	/* Reinitialise all interfaces */
370
+	while ( ( intf = va_arg ( intfs, struct interface * ) ) )
371
+		intf_reinit ( intf );
372
+}
373
+
374
+/**
375
+ * Shut down and restart multiple object interfaces
376
+ *
377
+ * @v rc		Reason for close
378
+ * @v ...		Object interfaces
379
+ */
380
+void intfs_restart ( int rc, ... ) {
381
+	va_list intfs;
382
+
383
+	va_start ( intfs, rc );
384
+	intfs_vrestart ( intfs, rc );
385
+	va_end ( intfs );
386
+}
387
+
319
 /**
388
 /**
320
  * Poke an object interface
389
  * Poke an object interface
321
  *
390
  *

+ 5
- 0
src/include/ipxe/interface.h Näytä tiedosto

10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
10
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
 
11
 
12
 #include <stddef.h>
12
 #include <stddef.h>
13
+#include <stdarg.h>
13
 #include <ipxe/refcnt.h>
14
 #include <ipxe/refcnt.h>
14
 
15
 
15
 /** An object interface operation */
16
 /** An object interface operation */
148
 	typeof ( void ( object_type, int rc ) )
149
 	typeof ( void ( object_type, int rc ) )
149
 
150
 
150
 extern void intf_shutdown ( struct interface *intf, int rc );
151
 extern void intf_shutdown ( struct interface *intf, int rc );
152
+extern void intfs_vshutdown ( va_list intfs, int rc );
153
+extern void intfs_shutdown ( int rc, ... ) __attribute__ (( sentinel ));
151
 extern void intf_restart ( struct interface *intf, int rc );
154
 extern void intf_restart ( struct interface *intf, int rc );
155
+extern void intfs_vrestart ( va_list intfs, int rc );
156
+extern void intfs_restart ( int rc, ... ) __attribute__ (( sentinel ));
152
 
157
 
153
 extern void intf_poke ( struct interface *intf,
158
 extern void intf_poke ( struct interface *intf,
154
 			void ( type ) ( struct interface *intf ) );
159
 			void ( type ) ( struct interface *intf ) );

Loading…
Peruuta
Tallenna