소스 검색

[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>
tags/v1.20.1
Michael Brown 5 년 전
부모
커밋
a2d3bedf1f
1개의 변경된 파일65개의 추가작업 그리고 4개의 파일을 삭제
  1. 65
    4
      src/net/peerdisc.c

+ 65
- 4
src/net/peerdisc.c 파일 보기

@@ -37,6 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
37 37
 #include <ipxe/netdevice.h>
38 38
 #include <ipxe/timer.h>
39 39
 #include <ipxe/fault.h>
40
+#include <ipxe/settings.h>
40 41
 #include <ipxe/pccrd.h>
41 42
 #include <ipxe/peerdisc.h>
42 43
 
@@ -72,6 +73,9 @@ static LIST_HEAD ( peerdisc_segments );
72 73
  */
73 74
 unsigned int peerdisc_timeout_secs = PEERDISC_DEFAULT_TIMEOUT_SECS;
74 75
 
76
+/** Hosted cache server */
77
+static char *peerhost;
78
+
75 79
 static struct peerdisc_segment * peerdisc_find ( const char *id );
76 80
 static int peerdisc_discovered ( struct peerdisc_segment *segment,
77 81
 				 const char *location );
@@ -442,6 +446,7 @@ static struct peerdisc_segment * peerdisc_create ( const char *id ) {
442 446
 	char *uuid_copy;
443 447
 	char *id_copy;
444 448
 	unsigned int i;
449
+	int rc;
445 450
 
446 451
 	/* Generate a random message UUID.  This does not require high
447 452
 	 * quality randomness.
@@ -458,7 +463,7 @@ static struct peerdisc_segment * peerdisc_create ( const char *id ) {
458 463
 	/* Allocate and initialise structure */
459 464
 	segment = zalloc ( sizeof ( *segment ) + id_len + uuid_len );
460 465
 	if ( ! segment )
461
-		return NULL;
466
+		goto err_alloc;
462 467
 	id_copy = ( ( ( void * ) segment ) + sizeof ( *segment ) );
463 468
 	memcpy ( id_copy, id, id_len );
464 469
 	uuid_copy = ( ( ( void * ) id_copy ) + id_len );
@@ -469,14 +474,30 @@ static struct peerdisc_segment * peerdisc_create ( const char *id ) {
469 474
 	INIT_LIST_HEAD ( &segment->peers );
470 475
 	INIT_LIST_HEAD ( &segment->clients );
471 476
 	timer_init ( &segment->timer, peerdisc_expired, &segment->refcnt );
472
-	DBGC2 ( segment, "PEERDISC %p discovering %s\n", segment, segment->id );
473 477
 
474
-	/* Start discovery timer */
475
-	start_timer_nodelay ( &segment->timer );
478
+	/* Add hosted cache server or initiate discovery */
479
+	if ( peerhost ) {
480
+
481
+		/* Add hosted cache server to list of peers */
482
+		if ( ( rc = peerdisc_discovered ( segment, peerhost ) ) != 0 )
483
+			goto err_peerhost;
484
+
485
+	} else {
486
+
487
+		/* Start discovery timer */
488
+		start_timer_nodelay ( &segment->timer );
489
+		DBGC2 ( segment, "PEERDISC %p discovering %s\n",
490
+			segment, segment->id );
491
+	}
476 492
 
477 493
 	/* Add to list of segments, transfer reference to list, and return */
478 494
 	list_add_tail ( &segment->list, &peerdisc_segments );
479 495
 	return segment;
496
+
497
+ err_peerhost:
498
+	ref_put ( &segment->refcnt );
499
+ err_alloc:
500
+	return NULL;
480 501
 }
481 502
 
482 503
 /**
@@ -579,3 +600,43 @@ void peerdisc_close ( struct peerdisc_client *peerdisc ) {
579 600
 	if ( list_empty ( &peerdisc_segments ) )
580 601
 		peerdisc_socket_close ( 0 );
581 602
 }
603
+
604
+/******************************************************************************
605
+ *
606
+ * Settings
607
+ *
608
+ ******************************************************************************
609
+ */
610
+
611
+/** PeerDist hosted cache server setting */
612
+const struct setting peerhost_setting __setting ( SETTING_MISC, peerhost ) = {
613
+	.name = "peerhost",
614
+	.description = "PeerDist hosted cache",
615
+	.type = &setting_type_string,
616
+};
617
+
618
+/**
619
+ * Apply PeerDist discovery settings
620
+ *
621
+ * @ret rc		Return status code
622
+ */
623
+static int apply_peerdisc_settings ( void ) {
624
+
625
+	/* Free any existing hosted cache server */
626
+	free ( peerhost );
627
+	peerhost = NULL;
628
+
629
+	/* Fetch hosted cache server */
630
+	fetch_string_setting_copy ( NULL, &peerhost_setting, &peerhost );
631
+	if ( peerhost ) {
632
+		DBGC ( &peerhost, "PEERDISC using hosted cache %s\n",
633
+		       peerhost );
634
+	}
635
+
636
+	return 0;
637
+}
638
+
639
+/** PeerDist discovery settings applicator */
640
+struct settings_applicator peerdisc_applicator __settings_applicator = {
641
+	.apply = apply_peerdisc_settings,
642
+};

Loading…
취소
저장