[interface] Provide intf_insert() to insert a filter interface

Generalise the filter interface insertion logic from block_translate()
and expose as intf_insert(), allowing a filter interface to be
inserted on any existing interface.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2020-12-07 13:49:47 +00:00
parent cb0ba2f825
commit 09fe2bbd34
3 changed files with 20 additions and 3 deletions

View File

@@ -242,9 +242,7 @@ int block_translate ( struct interface *block, userptr_t buffer, size_t size ) {
} }
/* Attach to interfaces, mortalise self, and return */ /* Attach to interfaces, mortalise self, and return */
assert ( block->dest != &null_intf ); intf_insert ( block, &blktrans->block, &blktrans->xfer );
intf_plug_plug ( &blktrans->xfer, block->dest );
intf_plug_plug ( &blktrans->block, block );
ref_put ( &blktrans->refcnt ); ref_put ( &blktrans->refcnt );
DBGC2 ( blktrans, "BLKTRANS %p created", blktrans ); DBGC2 ( blktrans, "BLKTRANS %p created", blktrans );

View File

@@ -390,6 +390,23 @@ void intfs_restart ( int rc, ... ) {
va_end ( intfs ); va_end ( intfs );
} }
/**
* Insert a filter interface
*
* @v intf Object interface
* @v upper Upper end of filter
* @v lower Lower end of filter
*/
void intf_insert ( struct interface *intf, struct interface *upper,
struct interface *lower ) {
struct interface *dest = intf->dest;
intf_get ( dest );
intf_plug_plug ( intf, upper );
intf_plug_plug ( lower, dest );
intf_put ( dest );
}
/** /**
* Poke an object interface * Poke an object interface
* *

View File

@@ -169,6 +169,8 @@ extern void intfs_shutdown ( int rc, ... ) __attribute__ (( sentinel ));
extern void intf_restart ( struct interface *intf, int rc ); extern void intf_restart ( struct interface *intf, int rc );
extern void intfs_vrestart ( va_list intfs, int rc ); extern void intfs_vrestart ( va_list intfs, int rc );
extern void intfs_restart ( int rc, ... ) __attribute__ (( sentinel )); extern void intfs_restart ( int rc, ... ) __attribute__ (( sentinel ));
extern void intf_insert ( struct interface *intf, struct interface *upper,
struct interface *lower );
extern void intf_poke ( struct interface *intf, extern void intf_poke ( struct interface *intf,
void ( type ) ( struct interface *intf ) ); void ( type ) ( struct interface *intf ) );