mirror of
https://github.com/ipxe/ipxe
synced 2025-12-21 20:40:25 +03:00
[peerdist] Allow for the use of a hosted cache server
Allow a PeerDist hosted cache server to be specified via the
${peerhost} setting, e.g.:
# Use 192.168.0.1 as hosted cache server
set peerhost 192.168.0.1
Note that this simply treats the hosted cache server as a permanently
discovered peer for all segments.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -37,6 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||||||
#include <ipxe/netdevice.h>
|
#include <ipxe/netdevice.h>
|
||||||
#include <ipxe/timer.h>
|
#include <ipxe/timer.h>
|
||||||
#include <ipxe/fault.h>
|
#include <ipxe/fault.h>
|
||||||
|
#include <ipxe/settings.h>
|
||||||
#include <ipxe/pccrd.h>
|
#include <ipxe/pccrd.h>
|
||||||
#include <ipxe/peerdisc.h>
|
#include <ipxe/peerdisc.h>
|
||||||
|
|
||||||
@@ -72,6 +73,9 @@ static LIST_HEAD ( peerdisc_segments );
|
|||||||
*/
|
*/
|
||||||
unsigned int peerdisc_timeout_secs = PEERDISC_DEFAULT_TIMEOUT_SECS;
|
unsigned int peerdisc_timeout_secs = PEERDISC_DEFAULT_TIMEOUT_SECS;
|
||||||
|
|
||||||
|
/** Hosted cache server */
|
||||||
|
static char *peerhost;
|
||||||
|
|
||||||
static struct peerdisc_segment * peerdisc_find ( const char *id );
|
static struct peerdisc_segment * peerdisc_find ( const char *id );
|
||||||
static int peerdisc_discovered ( struct peerdisc_segment *segment,
|
static int peerdisc_discovered ( struct peerdisc_segment *segment,
|
||||||
const char *location );
|
const char *location );
|
||||||
@@ -442,6 +446,7 @@ static struct peerdisc_segment * peerdisc_create ( const char *id ) {
|
|||||||
char *uuid_copy;
|
char *uuid_copy;
|
||||||
char *id_copy;
|
char *id_copy;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* Generate a random message UUID. This does not require high
|
/* Generate a random message UUID. This does not require high
|
||||||
* quality randomness.
|
* quality randomness.
|
||||||
@@ -458,7 +463,7 @@ static struct peerdisc_segment * peerdisc_create ( const char *id ) {
|
|||||||
/* Allocate and initialise structure */
|
/* Allocate and initialise structure */
|
||||||
segment = zalloc ( sizeof ( *segment ) + id_len + uuid_len );
|
segment = zalloc ( sizeof ( *segment ) + id_len + uuid_len );
|
||||||
if ( ! segment )
|
if ( ! segment )
|
||||||
return NULL;
|
goto err_alloc;
|
||||||
id_copy = ( ( ( void * ) segment ) + sizeof ( *segment ) );
|
id_copy = ( ( ( void * ) segment ) + sizeof ( *segment ) );
|
||||||
memcpy ( id_copy, id, id_len );
|
memcpy ( id_copy, id, id_len );
|
||||||
uuid_copy = ( ( ( void * ) id_copy ) + id_len );
|
uuid_copy = ( ( ( void * ) id_copy ) + id_len );
|
||||||
@@ -469,14 +474,30 @@ static struct peerdisc_segment * peerdisc_create ( const char *id ) {
|
|||||||
INIT_LIST_HEAD ( &segment->peers );
|
INIT_LIST_HEAD ( &segment->peers );
|
||||||
INIT_LIST_HEAD ( &segment->clients );
|
INIT_LIST_HEAD ( &segment->clients );
|
||||||
timer_init ( &segment->timer, peerdisc_expired, &segment->refcnt );
|
timer_init ( &segment->timer, peerdisc_expired, &segment->refcnt );
|
||||||
DBGC2 ( segment, "PEERDISC %p discovering %s\n", segment, segment->id );
|
|
||||||
|
|
||||||
/* Start discovery timer */
|
/* Add hosted cache server or initiate discovery */
|
||||||
start_timer_nodelay ( &segment->timer );
|
if ( peerhost ) {
|
||||||
|
|
||||||
|
/* Add hosted cache server to list of peers */
|
||||||
|
if ( ( rc = peerdisc_discovered ( segment, peerhost ) ) != 0 )
|
||||||
|
goto err_peerhost;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* Start discovery timer */
|
||||||
|
start_timer_nodelay ( &segment->timer );
|
||||||
|
DBGC2 ( segment, "PEERDISC %p discovering %s\n",
|
||||||
|
segment, segment->id );
|
||||||
|
}
|
||||||
|
|
||||||
/* Add to list of segments, transfer reference to list, and return */
|
/* Add to list of segments, transfer reference to list, and return */
|
||||||
list_add_tail ( &segment->list, &peerdisc_segments );
|
list_add_tail ( &segment->list, &peerdisc_segments );
|
||||||
return segment;
|
return segment;
|
||||||
|
|
||||||
|
err_peerhost:
|
||||||
|
ref_put ( &segment->refcnt );
|
||||||
|
err_alloc:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -579,3 +600,43 @@ void peerdisc_close ( struct peerdisc_client *peerdisc ) {
|
|||||||
if ( list_empty ( &peerdisc_segments ) )
|
if ( list_empty ( &peerdisc_segments ) )
|
||||||
peerdisc_socket_close ( 0 );
|
peerdisc_socket_close ( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
*
|
||||||
|
* Settings
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** PeerDist hosted cache server setting */
|
||||||
|
const struct setting peerhost_setting __setting ( SETTING_MISC, peerhost ) = {
|
||||||
|
.name = "peerhost",
|
||||||
|
.description = "PeerDist hosted cache",
|
||||||
|
.type = &setting_type_string,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply PeerDist discovery settings
|
||||||
|
*
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
static int apply_peerdisc_settings ( void ) {
|
||||||
|
|
||||||
|
/* Free any existing hosted cache server */
|
||||||
|
free ( peerhost );
|
||||||
|
peerhost = NULL;
|
||||||
|
|
||||||
|
/* Fetch hosted cache server */
|
||||||
|
fetch_string_setting_copy ( NULL, &peerhost_setting, &peerhost );
|
||||||
|
if ( peerhost ) {
|
||||||
|
DBGC ( &peerhost, "PEERDISC using hosted cache %s\n",
|
||||||
|
peerhost );
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PeerDist discovery settings applicator */
|
||||||
|
struct settings_applicator peerdisc_applicator __settings_applicator = {
|
||||||
|
.apply = apply_peerdisc_settings,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user