summaryrefslogtreecommitdiffstats
path: root/src/server/net.c
diff options
context:
space:
mode:
authorSimon Rettberg2025-10-10 18:13:16 +0200
committerSimon Rettberg2025-10-24 09:20:46 +0200
commite1a3ce5f67d243ab4075405b5ef15457ddfbce2b (patch)
tree133a0e3536077a412d46fad76a7f5ff099a49169 /src/server/net.c
parentFixes to iSCSI DNBD3 proxy uplink handling. (diff)
downloaddnbd3-e1a3ce5f67d243ab4075405b5ef15457ddfbce2b.tar.gz
dnbd3-e1a3ce5f67d243ab4075405b5ef15457ddfbce2b.tar.xz
dnbd3-e1a3ce5f67d243ab4075405b5ef15457ddfbce2b.zip
WIP
Diffstat (limited to 'src/server/net.c')
-rw-r--r--src/server/net.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/server/net.c b/src/server/net.c
index af31f4a..41caa96 100644
--- a/src/server/net.c
+++ b/src/server/net.c
@@ -152,10 +152,24 @@ void net_init()
mutex_init( &_clients_lock, LOCK_CLIENT_LIST );
}
+void initClientStruct(dnbd3_client_t *client)
+{
+ mutex_init( &client->lock, LOCK_CLIENT );
+ mutex_init( &client->sendMutex, LOCK_CLIENT_SEND );
+
+ mutex_lock( &client->lock );
+ host_to_string( &client->host, client->hostName, HOSTNAMELEN );
+ client->hostName[HOSTNAMELEN-1] = '\0';
+ mutex_unlock( &client->lock );
+ client->bytesSent = 0;
+ client->relayedCount = 0;
+}
+
void* net_handleNewConnection(void *clientPtr)
{
dnbd3_client_t * const client = (dnbd3_client_t *)clientPtr;
dnbd3_request_t request;
+ dnbd3_cache_map_t *cache = NULL;
client->thread = pthread_self();
// Await data from client. Since this is a fresh connection, we expect data right away
@@ -178,8 +192,16 @@ void* net_handleNewConnection(void *clientPtr)
if ( ((char*)&request)[0] == 'G' || ((char*)&request)[0] == 'P' ) {
// Close enough...
rpc_sendStatsJson( client->sock, &client->host, &request, ret );
+ } else if ( true /* check opcode ... */ ) {
+ initClientStruct( client );
+ if ( !addToList( client ) ) {
+ freeClientStruct( client );
+ logadd( LOG_WARNING, "Could not add new iSCSI client to list when connecting" );
+ } else {
+ iscsi_connection_handle( client, &request, ret );
+ goto exit_client_cleanup;
+ }
} else {
- iscsi_connection_handle( client, &request, ret );
logadd( LOG_DEBUG1, "Magic in client handshake incorrect" );
}
goto fail_preadd;
@@ -192,26 +214,17 @@ void* net_handleNewConnection(void *clientPtr)
}
} while (0);
// Fully init client struct
- mutex_init( &client->lock, LOCK_CLIENT );
- mutex_init( &client->sendMutex, LOCK_CLIENT_SEND );
-
- mutex_lock( &client->lock );
- host_to_string( &client->host, client->hostName, HOSTNAMELEN );
- client->hostName[HOSTNAMELEN-1] = '\0';
- mutex_unlock( &client->lock );
- client->bytesSent = 0;
- client->relayedCount = 0;
+ initClientStruct( client );
if ( !addToList( client ) ) {
freeClientStruct( client );
- logadd( LOG_WARNING, "Could not add new client to list when connecting" );
- return NULL;
+ logadd( LOG_WARNING, "Could not add new DNBD3 client to list when connecting" );
+ goto fail_preadd;
}
dnbd3_reply_t reply;
dnbd3_image_t *image = NULL;
- dnbd3_cache_map_t *cache = NULL;
int image_file = -1;
int num;
@@ -518,11 +531,11 @@ exit_client_cleanup: ;
removeFromList( client );
totalBytesSent += client->bytesSent;
// Access time, but only if client didn't just probe
- if ( image != NULL && client->bytesSent > DNBD3_BLOCK_SIZE * 10 ) {
- mutex_lock( &image->lock );
- timing_get( &image->atime );
- image->accessed = true;
- mutex_unlock( &image->lock );
+ if ( client->image != NULL && client->bytesSent > DNBD3_BLOCK_SIZE * 10 ) {
+ mutex_lock( &client->image->lock );
+ timing_get( &client->image->atime );
+ client->image->accessed = true;
+ mutex_unlock( &client->image->lock );
}
if ( cache != NULL ) {
ref_put( &cache->reference );
@@ -688,7 +701,7 @@ static dnbd3_client_t* freeClientStruct(dnbd3_client_t *client)
dnbd3_uplink_t *uplink = ref_get_uplink( &client->image->uplinkref );
if ( uplink != NULL ) {
if ( client->relayedCount != 0 ) {
- uplink_removeEntry( uplink, client, &uplinkCallback );
+ uplink_removeEntry( uplink, client );
}
ref_put( &uplink->reference );
}