2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-12-14 15:21:32 +00:00

An AoE session holds a persistent reference to a net device.

This commit is contained in:
Michael Brown 2007-01-04 03:21:45 +00:00
parent 35b5e5d3f5
commit b22d4405c0
2 changed files with 26 additions and 0 deletions

View File

@ -86,6 +86,9 @@ struct aoe_session {
/** Network device */
struct net_device *netdev;
/** Reference to network device */
struct reference netdev_ref;
/** Major number */
uint16_t major;
/** Minor number */

View File

@ -76,6 +76,12 @@ static int aoe_send_command ( struct aoe_session *aoe ) {
unsigned int count;
unsigned int data_out_len;
/* Fail immediately if we have no netdev to send on */
if ( ! aoe->netdev ) {
aoe_done ( aoe, -ENETUNREACH );
return -ENETUNREACH;
}
/* Calculate count and data_out_len for this subcommand */
count = command->cb.count.native;
if ( count > AOE_MAX_COUNT )
@ -259,6 +265,19 @@ struct net_protocol aoe_protocol __net_protocol = {
.rx = aoe_rx,
};
/**
* Forget reference to net_device
*
* @v ref Persistent reference
*/
static void aoe_forget_netdev ( struct reference *ref ) {
struct aoe_session *aoe
= container_of ( ref, struct aoe_session, netdev_ref );
aoe->netdev = NULL;
ref_del ( &aoe->netdev_ref );
}
/**
* Open AoE session
*
@ -269,6 +288,8 @@ void aoe_open ( struct aoe_session *aoe ) {
sizeof ( aoe->target ) );
aoe->tag = AOE_TAG_MAGIC;
aoe->timer.expired = aoe_timer_expired;
aoe->netdev_ref.forget = aoe_forget_netdev;
ref_add ( &aoe->netdev_ref, &aoe->netdev->references );
list_add ( &aoe->list, &aoe_sessions );
}
@ -278,6 +299,8 @@ void aoe_open ( struct aoe_session *aoe ) {
* @v aoe AoE session
*/
void aoe_close ( struct aoe_session *aoe ) {
if ( aoe->netdev )
ref_del ( &aoe->netdev_ref );
list_del ( &aoe->list );
}