Skip to content

Commit

Permalink
[settings] Apply settings block name in register_settings()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcb30 committed Dec 1, 2010
1 parent de6a594 commit 67b4518
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 32 deletions.
5 changes: 2 additions & 3 deletions src/core/nvo.c
Expand Up @@ -204,8 +204,7 @@ void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
struct nvo_fragment *fragments, struct refcnt *refcnt ) {
nvo->nvs = nvs;
nvo->fragments = fragments;
settings_init ( &nvo->settings, &nvo_settings_operations, refcnt,
"nvo", 0 );
settings_init ( &nvo->settings, &nvo_settings_operations, refcnt, 0 );
}

/**
Expand Down Expand Up @@ -250,7 +249,7 @@ int register_nvo ( struct nvo_block *nvo, struct settings *parent ) {

/* Verify and register options */
nvo_init_dhcpopts ( nvo );
if ( ( rc = register_settings ( &nvo->settings, parent ) ) != 0 )
if ( ( rc = register_settings ( &nvo->settings, parent, "nvo" ) ) != 0 )
goto err_register;

DBGC ( nvo, "NVO %p registered\n", nvo );
Expand Down
11 changes: 8 additions & 3 deletions src/core/settings.c
Expand Up @@ -281,9 +281,9 @@ static struct settings * autovivify_child_settings ( struct settings *parent,
return NULL;
}
memcpy ( new_child->name, name, sizeof ( new_child->name ) );
generic_settings_init ( &new_child->generic, NULL, new_child->name );
generic_settings_init ( &new_child->generic, NULL );
settings = &new_child->generic.settings;
register_settings ( settings, parent );
register_settings ( settings, parent, new_child->name );
return settings;
}

Expand Down Expand Up @@ -422,16 +422,21 @@ static void reprioritise_settings ( struct settings *settings ) {
*
* @v settings Settings block
* @v parent Parent settings block, or NULL
* @v name Settings block name
* @ret rc Return status code
*/
int register_settings ( struct settings *settings, struct settings *parent ) {
int register_settings ( struct settings *settings, struct settings *parent,
const char *name ) {
struct settings *old_settings;

/* NULL parent => add to settings root */
assert ( settings != NULL );
if ( parent == NULL )
parent = &settings_root;

/* Apply settings block name */
settings->name = name;

/* Remove any existing settings with the same name */
if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
unregister_settings ( old_settings );
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/net/phantom/phantom.c
Expand Up @@ -2061,7 +2061,7 @@ static int phantom_probe ( struct pci_device *pci,
assert ( phantom->port < PHN_MAX_NUM_PORTS );
settings_init ( &phantom->settings,
&phantom_settings_operations,
&netdev->refcnt, "clp", PHN_CLP_TAG_MAGIC );
&netdev->refcnt, PHN_CLP_TAG_MAGIC );

/* Fix up PCI device */
adjust_pci_device ( pci );
Expand Down Expand Up @@ -2111,7 +2111,7 @@ static int phantom_probe ( struct pci_device *pci,
/* Register settings blocks */
parent_settings = netdev_settings ( netdev );
if ( ( rc = register_settings ( &phantom->settings,
parent_settings ) ) != 0 ) {
parent_settings, "clp" ) ) != 0 ) {
DBGC ( phantom, "Phantom %p could not register settings: "
"%s\n", phantom, strerror ( rc ) );
goto err_register_settings;
Expand Down
3 changes: 1 addition & 2 deletions src/include/ipxe/netdevice.h
Expand Up @@ -489,8 +489,7 @@ netdev_settings ( struct net_device *netdev ) {
*/
static inline __attribute__ (( always_inline )) void
netdev_settings_init ( struct net_device *netdev ) {
generic_settings_init ( &netdev->settings,
&netdev->refcnt, netdev->name );
generic_settings_init ( &netdev->settings, &netdev->refcnt );
netdev->settings.settings.op = &netdev_settings_operations;
}

Expand Down
11 changes: 3 additions & 8 deletions src/include/ipxe/settings.h
Expand Up @@ -178,7 +178,7 @@ extern int generic_settings_fetch ( struct settings *settings,
extern void generic_settings_clear ( struct settings *settings );

extern int register_settings ( struct settings *settings,
struct settings *parent );
struct settings *parent, const char *name );
extern void unregister_settings ( struct settings *settings );

extern int store_setting ( struct settings *settings, struct setting *setting,
Expand Down Expand Up @@ -252,19 +252,16 @@ extern struct setting user_class_setting __setting;
* @v settings Settings block
* @v op Settings block operations
* @v refcnt Containing object reference counter, or NULL
* @v name Settings block name
* @v tag_magic Tag magic
*/
static inline void settings_init ( struct settings *settings,
struct settings_operations *op,
struct refcnt *refcnt,
const char *name,
unsigned int tag_magic ) {
INIT_LIST_HEAD ( &settings->siblings );
INIT_LIST_HEAD ( &settings->children );
settings->op = op;
settings->refcnt = refcnt;
settings->name = name;
settings->tag_magic = tag_magic;
}

Expand All @@ -273,13 +270,11 @@ static inline void settings_init ( struct settings *settings,
*
* @v generics Generic settings block
* @v refcnt Containing object reference counter, or NULL
* @v name Settings block name
*/
static inline void generic_settings_init ( struct generic_settings *generics,
struct refcnt *refcnt,
const char *name ) {
struct refcnt *refcnt ) {
settings_init ( &generics->settings, &generic_settings_operations,
refcnt, name, 0 );
refcnt, 0 );
INIT_LIST_HEAD ( &generics->list );
}

Expand Down
4 changes: 2 additions & 2 deletions src/interface/smbios/smbios_settings.c
Expand Up @@ -125,7 +125,6 @@ static struct settings_operations smbios_settings_operations = {
/** SMBIOS settings */
static struct settings smbios_settings = {
.refcnt = NULL,
.name = "smbios",
.tag_magic = SMBIOS_EMPTY_TAG,
.siblings = LIST_HEAD_INIT ( smbios_settings.siblings ),
.children = LIST_HEAD_INIT ( smbios_settings.children ),
Expand All @@ -136,7 +135,8 @@ static struct settings smbios_settings = {
static void smbios_init ( void ) {
int rc;

if ( ( rc = register_settings ( &smbios_settings, NULL ) ) != 0 ) {
if ( ( rc = register_settings ( &smbios_settings, NULL,
"smbios" ) ) != 0 ) {
DBG ( "SMBIOS could not register settings: %s\n",
strerror ( rc ) );
return;
Expand Down
3 changes: 2 additions & 1 deletion src/net/cachedhcp.c
Expand Up @@ -66,7 +66,8 @@ void store_cached_dhcpack ( userptr_t data, size_t len ) {
* device, which is usually what we want.
*/
parent = netdev_settings ( last_opened_netdev() );
if ( ( rc = register_settings ( &dhcppkt->settings, parent ) ) != 0 )
if ( ( rc = register_settings ( &dhcppkt->settings, parent,
DHCP_SETTINGS_NAME ) ) != 0 )
DBG ( "DHCP could not register cached settings: %s\n",
strerror ( rc ) );

Expand Down
3 changes: 1 addition & 2 deletions src/net/dhcppkt.c
Expand Up @@ -279,6 +279,5 @@ void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data,
dhcppkt->len = ( offsetof ( struct dhcphdr, options ) +
dhcppkt->options.len );
settings_init ( &dhcppkt->settings,
&dhcppkt_settings_operations, &dhcppkt->refcnt,
DHCP_SETTINGS_NAME, 0 );
&dhcppkt_settings_operations, &dhcppkt->refcnt, 0 );
}
2 changes: 1 addition & 1 deletion src/net/netdevice.c
Expand Up @@ -422,7 +422,7 @@ int register_netdev ( struct net_device *netdev ) {

/* Register per-netdev configuration settings */
if ( ( rc = register_settings ( netdev_settings ( netdev ),
NULL ) ) != 0 ) {
NULL, netdev->name ) ) != 0 ) {
DBGC ( netdev, "NETDEV %s could not register settings: %s\n",
netdev->name, strerror ( rc ) );
goto err_register_settings;
Expand Down
16 changes: 8 additions & 8 deletions src/net/udp/dhcp.c
Expand Up @@ -553,7 +553,8 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp,
/* Register settings */
parent = netdev_settings ( dhcp->netdev );
settings = &dhcppkt->settings;
if ( ( rc = register_settings ( settings, parent ) ) != 0 ) {
if ( ( rc = register_settings ( settings, parent,
DHCP_SETTINGS_NAME ) ) != 0 ) {
DBGC ( dhcp, "DHCP %p could not register settings: %s\n",
dhcp, strerror ( rc ) );
dhcp_finished ( dhcp, rc );
Expand All @@ -568,9 +569,8 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp,
* without performing a ProxyDHCPREQUEST
*/
settings = &dhcp->proxy_offer->settings;
settings->name = PROXYDHCP_SETTINGS_NAME;
if ( ( rc = register_settings ( settings,
NULL ) ) != 0 ) {
if ( ( rc = register_settings ( settings, NULL,
PROXYDHCP_SETTINGS_NAME ) ) != 0 ) {
DBGC ( dhcp, "DHCP %p could not register "
"proxy settings: %s\n",
dhcp, strerror ( rc ) );
Expand Down Expand Up @@ -670,8 +670,8 @@ static void dhcp_proxy_rx ( struct dhcp_session *dhcp,
return;

/* Register settings */
settings->name = PROXYDHCP_SETTINGS_NAME;
if ( ( rc = register_settings ( settings, NULL ) ) != 0 ) {
if ( ( rc = register_settings ( settings, NULL,
PROXYDHCP_SETTINGS_NAME ) ) != 0 ) {
DBGC ( dhcp, "DHCP %p could not register proxy settings: %s\n",
dhcp, strerror ( rc ) );
dhcp_finished ( dhcp, rc );
Expand Down Expand Up @@ -809,8 +809,8 @@ static void dhcp_pxebs_rx ( struct dhcp_session *dhcp,
return;

/* Register settings */
dhcppkt->settings.name = PXEBS_SETTINGS_NAME;
if ( ( rc = register_settings ( &dhcppkt->settings, NULL ) ) != 0 ) {
if ( ( rc = register_settings ( &dhcppkt->settings, NULL,
PXEBS_SETTINGS_NAME ) ) != 0 ) {
DBGC ( dhcp, "DHCP %p could not register settings: %s\n",
dhcp, strerror ( rc ) );
dhcp_finished ( dhcp, rc );
Expand Down

0 comments on commit 67b4518

Please sign in to comment.