Ver código fonte

[settings] Apply settings block name in register_settings()

Pass the settings block name as a parameter to register_settings(),
rather than defining it with settings_init() (and then possibly
changing it by directly manipulating settings->name).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 anos atrás
pai
commit
67b45186a5

+ 2
- 3
src/core/nvo.c Ver arquivo

@@ -204,8 +204,7 @@ void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
204 204
 		struct nvo_fragment *fragments, struct refcnt *refcnt ) {
205 205
 	nvo->nvs = nvs;
206 206
 	nvo->fragments = fragments;
207
-	settings_init ( &nvo->settings, &nvo_settings_operations, refcnt,
208
-			"nvo", 0 );
207
+	settings_init ( &nvo->settings, &nvo_settings_operations, refcnt, 0 );
209 208
 }
210 209
 
211 210
 /**
@@ -250,7 +249,7 @@ int register_nvo ( struct nvo_block *nvo, struct settings *parent ) {
250 249
 
251 250
 	/* Verify and register options */
252 251
 	nvo_init_dhcpopts ( nvo );
253
-	if ( ( rc = register_settings ( &nvo->settings, parent ) ) != 0 )
252
+	if ( ( rc = register_settings ( &nvo->settings, parent, "nvo" ) ) != 0 )
254 253
 		goto err_register;
255 254
 
256 255
 	DBGC ( nvo, "NVO %p registered\n", nvo );

+ 8
- 3
src/core/settings.c Ver arquivo

@@ -281,9 +281,9 @@ static struct settings * autovivify_child_settings ( struct settings *parent,
281 281
 		return NULL;
282 282
 	}
283 283
 	memcpy ( new_child->name, name, sizeof ( new_child->name ) );
284
-	generic_settings_init ( &new_child->generic, NULL, new_child->name );
284
+	generic_settings_init ( &new_child->generic, NULL );
285 285
 	settings = &new_child->generic.settings;
286
-	register_settings ( settings, parent );
286
+	register_settings ( settings, parent, new_child->name );
287 287
 	return settings;
288 288
 }
289 289
 
@@ -422,9 +422,11 @@ static void reprioritise_settings ( struct settings *settings ) {
422 422
  *
423 423
  * @v settings		Settings block
424 424
  * @v parent		Parent settings block, or NULL
425
+ * @v name		Settings block name
425 426
  * @ret rc		Return status code
426 427
  */
427
-int register_settings ( struct settings *settings, struct settings *parent ) {
428
+int register_settings ( struct settings *settings, struct settings *parent,
429
+			const char *name ) {
428 430
 	struct settings *old_settings;
429 431
 
430 432
 	/* NULL parent => add to settings root */
@@ -432,6 +434,9 @@ int register_settings ( struct settings *settings, struct settings *parent ) {
432 434
 	if ( parent == NULL )
433 435
 		parent = &settings_root;
434 436
 
437
+	/* Apply settings block name */
438
+	settings->name = name;
439
+
435 440
 	/* Remove any existing settings with the same name */
436 441
 	if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
437 442
 		unregister_settings ( old_settings );

+ 2
- 2
src/drivers/net/phantom/phantom.c Ver arquivo

@@ -2061,7 +2061,7 @@ static int phantom_probe ( struct pci_device *pci,
2061 2061
 	assert ( phantom->port < PHN_MAX_NUM_PORTS );
2062 2062
 	settings_init ( &phantom->settings,
2063 2063
 			&phantom_settings_operations,
2064
-			&netdev->refcnt, "clp", PHN_CLP_TAG_MAGIC );
2064
+			&netdev->refcnt, PHN_CLP_TAG_MAGIC );
2065 2065
 
2066 2066
 	/* Fix up PCI device */
2067 2067
 	adjust_pci_device ( pci );
@@ -2111,7 +2111,7 @@ static int phantom_probe ( struct pci_device *pci,
2111 2111
 	/* Register settings blocks */
2112 2112
 	parent_settings = netdev_settings ( netdev );
2113 2113
 	if ( ( rc = register_settings ( &phantom->settings,
2114
-					parent_settings ) ) != 0 ) {
2114
+					parent_settings, "clp" ) ) != 0 ) {
2115 2115
 		DBGC ( phantom, "Phantom %p could not register settings: "
2116 2116
 		       "%s\n", phantom, strerror ( rc ) );
2117 2117
 		goto err_register_settings;

+ 1
- 2
src/include/ipxe/netdevice.h Ver arquivo

@@ -489,8 +489,7 @@ netdev_settings ( struct net_device *netdev ) {
489 489
  */
490 490
 static inline __attribute__ (( always_inline )) void
491 491
 netdev_settings_init ( struct net_device *netdev ) {
492
-	generic_settings_init ( &netdev->settings,
493
-				&netdev->refcnt, netdev->name );
492
+	generic_settings_init ( &netdev->settings, &netdev->refcnt );
494 493
 	netdev->settings.settings.op = &netdev_settings_operations;
495 494
 }
496 495
 

+ 3
- 8
src/include/ipxe/settings.h Ver arquivo

@@ -178,7 +178,7 @@ extern int generic_settings_fetch ( struct settings *settings,
178 178
 extern void generic_settings_clear ( struct settings *settings );
179 179
 
180 180
 extern int register_settings ( struct settings *settings,
181
-			       struct settings *parent );
181
+			       struct settings *parent, const char *name );
182 182
 extern void unregister_settings ( struct settings *settings );
183 183
 
184 184
 extern int store_setting ( struct settings *settings, struct setting *setting,
@@ -252,19 +252,16 @@ extern struct setting user_class_setting __setting;
252 252
  * @v settings		Settings block
253 253
  * @v op		Settings block operations
254 254
  * @v refcnt		Containing object reference counter, or NULL
255
- * @v name		Settings block name
256 255
  * @v tag_magic		Tag magic
257 256
  */
258 257
 static inline void settings_init ( struct settings *settings,
259 258
 				   struct settings_operations *op,
260 259
 				   struct refcnt *refcnt,
261
-				   const char *name,
262 260
 				   unsigned int tag_magic ) {
263 261
 	INIT_LIST_HEAD ( &settings->siblings );
264 262
 	INIT_LIST_HEAD ( &settings->children );
265 263
 	settings->op = op;
266 264
 	settings->refcnt = refcnt;
267
-	settings->name = name;
268 265
 	settings->tag_magic = tag_magic;
269 266
 }
270 267
 
@@ -273,13 +270,11 @@ static inline void settings_init ( struct settings *settings,
273 270
  *
274 271
  * @v generics		Generic settings block
275 272
  * @v refcnt		Containing object reference counter, or NULL
276
- * @v name		Settings block name
277 273
  */
278 274
 static inline void generic_settings_init ( struct generic_settings *generics,
279
-					   struct refcnt *refcnt,
280
-					   const char *name ) {
275
+					   struct refcnt *refcnt ) {
281 276
 	settings_init ( &generics->settings, &generic_settings_operations,
282
-			refcnt, name, 0 );
277
+			refcnt, 0 );
283 278
 	INIT_LIST_HEAD ( &generics->list );
284 279
 }
285 280
 

+ 2
- 2
src/interface/smbios/smbios_settings.c Ver arquivo

@@ -125,7 +125,6 @@ static struct settings_operations smbios_settings_operations = {
125 125
 /** SMBIOS settings */
126 126
 static struct settings smbios_settings = {
127 127
 	.refcnt = NULL,
128
-	.name = "smbios",
129 128
 	.tag_magic = SMBIOS_EMPTY_TAG,
130 129
 	.siblings = LIST_HEAD_INIT ( smbios_settings.siblings ),
131 130
 	.children = LIST_HEAD_INIT ( smbios_settings.children ),
@@ -136,7 +135,8 @@ static struct settings smbios_settings = {
136 135
 static void smbios_init ( void ) {
137 136
 	int rc;
138 137
 
139
-	if ( ( rc = register_settings ( &smbios_settings, NULL ) ) != 0 ) {
138
+	if ( ( rc = register_settings ( &smbios_settings, NULL,
139
+					"smbios" ) ) != 0 ) {
140 140
 		DBG ( "SMBIOS could not register settings: %s\n",
141 141
 		      strerror ( rc ) );
142 142
 		return;

+ 2
- 1
src/net/cachedhcp.c Ver arquivo

@@ -66,7 +66,8 @@ void store_cached_dhcpack ( userptr_t data, size_t len ) {
66 66
 	 * device, which is usually what we want.
67 67
 	 */
68 68
 	parent = netdev_settings ( last_opened_netdev() );
69
-	if ( ( rc = register_settings ( &dhcppkt->settings, parent ) ) != 0 )
69
+	if ( ( rc = register_settings ( &dhcppkt->settings, parent,
70
+					DHCP_SETTINGS_NAME ) ) != 0 )
70 71
 		DBG ( "DHCP could not register cached settings: %s\n",
71 72
 		      strerror ( rc ) );
72 73
 

+ 1
- 2
src/net/dhcppkt.c Ver arquivo

@@ -279,6 +279,5 @@ void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data,
279 279
 	dhcppkt->len = ( offsetof ( struct dhcphdr, options ) +
280 280
 			 dhcppkt->options.len );
281 281
 	settings_init ( &dhcppkt->settings,
282
-			&dhcppkt_settings_operations, &dhcppkt->refcnt,
283
-			DHCP_SETTINGS_NAME, 0 );
282
+			&dhcppkt_settings_operations, &dhcppkt->refcnt, 0 );
284 283
 }

+ 1
- 1
src/net/netdevice.c Ver arquivo

@@ -422,7 +422,7 @@ int register_netdev ( struct net_device *netdev ) {
422 422
 
423 423
 	/* Register per-netdev configuration settings */
424 424
 	if ( ( rc = register_settings ( netdev_settings ( netdev ),
425
-					NULL ) ) != 0 ) {
425
+					NULL, netdev->name ) ) != 0 ) {
426 426
 		DBGC ( netdev, "NETDEV %s could not register settings: %s\n",
427 427
 		       netdev->name, strerror ( rc ) );
428 428
 		goto err_register_settings;

+ 8
- 8
src/net/udp/dhcp.c Ver arquivo

@@ -553,7 +553,8 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp,
553 553
 	/* Register settings */
554 554
 	parent = netdev_settings ( dhcp->netdev );
555 555
 	settings = &dhcppkt->settings;
556
-	if ( ( rc = register_settings ( settings, parent ) ) != 0 ) {
556
+	if ( ( rc = register_settings ( settings, parent,
557
+					DHCP_SETTINGS_NAME ) ) != 0 ) {
557 558
 		DBGC ( dhcp, "DHCP %p could not register settings: %s\n",
558 559
 		       dhcp, strerror ( rc ) );
559 560
 		dhcp_finished ( dhcp, rc );
@@ -568,9 +569,8 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp,
568 569
 			 * without performing a ProxyDHCPREQUEST
569 570
 			 */
570 571
 			settings = &dhcp->proxy_offer->settings;
571
-			settings->name = PROXYDHCP_SETTINGS_NAME;
572
-			if ( ( rc = register_settings ( settings,
573
-							NULL ) ) != 0 ) {
572
+			if ( ( rc = register_settings ( settings, NULL,
573
+					   PROXYDHCP_SETTINGS_NAME ) ) != 0 ) {
574 574
 				DBGC ( dhcp, "DHCP %p could not register "
575 575
 				       "proxy settings: %s\n",
576 576
 				       dhcp, strerror ( rc ) );
@@ -670,8 +670,8 @@ static void dhcp_proxy_rx ( struct dhcp_session *dhcp,
670 670
 		return;
671 671
 
672 672
 	/* Register settings */
673
-	settings->name = PROXYDHCP_SETTINGS_NAME;
674
-	if ( ( rc = register_settings ( settings, NULL ) ) != 0 ) {
673
+	if ( ( rc = register_settings ( settings, NULL,
674
+					PROXYDHCP_SETTINGS_NAME ) ) != 0 ) {
675 675
 		DBGC ( dhcp, "DHCP %p could not register proxy settings: %s\n",
676 676
 		       dhcp, strerror ( rc ) );
677 677
 		dhcp_finished ( dhcp, rc );
@@ -809,8 +809,8 @@ static void dhcp_pxebs_rx ( struct dhcp_session *dhcp,
809 809
 		return;
810 810
 
811 811
 	/* Register settings */
812
-	dhcppkt->settings.name = PXEBS_SETTINGS_NAME;
813
-	if ( ( rc = register_settings ( &dhcppkt->settings, NULL ) ) != 0 ) {
812
+	if ( ( rc = register_settings ( &dhcppkt->settings, NULL,
813
+					PXEBS_SETTINGS_NAME ) ) != 0 ) {
814 814
 		DBGC ( dhcp, "DHCP %p could not register settings: %s\n",
815 815
 		       dhcp, strerror ( rc ) );
816 816
 		dhcp_finished ( dhcp, rc );

Carregando…
Cancelar
Salvar