[Settings] Implement simple_settings backed with extensible DHCP options

pull/1/head
Michael Brown 2008-03-22 00:24:50 +00:00
parent a462c96ffc
commit e5cea13e51
4 changed files with 72 additions and 26 deletions

View File

@ -79,23 +79,36 @@ static inline char * setting_tag_name ( unsigned int tag ) {
****************************************************************************** ******************************************************************************
*/ */
// Dummy routine just for testing /**
* Store value of simple setting
*
* @v options DHCP option block
* @v tag Setting tag number
* @v data Setting data, or NULL to clear setting
* @v len Length of setting data
* @ret rc Return status code
*/
int simple_settings_store ( struct settings *settings, unsigned int tag, int simple_settings_store ( struct settings *settings, unsigned int tag,
const void *data, size_t len ) { const void *data, size_t len ) {
DBGC ( settings, "Settings %p: store %s to:\n", struct simple_settings *simple =
settings, setting_tag_name ( tag ) ); container_of ( settings, struct simple_settings, settings );
DBGC_HD ( settings, data, len ); return dhcpopt_extensible_store ( &simple->dhcpopts, tag, data, len );
return 0;
} }
// Dummy routine just for testing /**
* Fetch value of simple setting
*
* @v options DHCP option block
* @v tag Setting tag number
* @v data Buffer to fill with setting data
* @v len Length of buffer
* @ret len Length of setting data, or negative error
*/
int simple_settings_fetch ( struct settings *settings, unsigned int tag, int simple_settings_fetch ( struct settings *settings, unsigned int tag,
void *data, size_t len ) { void *data, size_t len ) {
( void ) settings; struct simple_settings *simple =
( void ) tag; container_of ( settings, struct simple_settings, settings );
( void ) data; return dhcpopt_fetch ( &simple->dhcpopts, tag, data, len );
( void ) len;
return -ENOENT;
} }
/** Simple settings operations */ /** Simple settings operations */
@ -104,15 +117,22 @@ struct settings_operations simple_settings_operations = {
.fetch = simple_settings_fetch, .fetch = simple_settings_fetch,
}; };
/** Root settings block */ /** Root simple settings block */
struct settings settings_root = { struct simple_settings simple_settings_root = {
.settings = {
.refcnt = NULL, .refcnt = NULL,
.name = "", .name = "",
.siblings = LIST_HEAD_INIT ( settings_root.siblings ), .siblings =
.children = LIST_HEAD_INIT ( settings_root.children ), LIST_HEAD_INIT ( simple_settings_root.settings.siblings ),
.children =
LIST_HEAD_INIT ( simple_settings_root.settings.children ),
.op = &simple_settings_operations, .op = &simple_settings_operations,
},
}; };
/** Root settings block */
#define settings_root simple_settings_root.settings
/** /**
* Apply all settings * Apply all settings
* *

View File

@ -245,7 +245,7 @@ struct net_device {
struct net_device_stats stats; struct net_device_stats stats;
/** Configuration settings applicable to this device */ /** Configuration settings applicable to this device */
struct settings settings; struct simple_settings settings;
/** Driver private data */ /** Driver private data */
void *priv; void *priv;
@ -349,7 +349,7 @@ netdev_priv ( struct net_device *netdev ) {
*/ */
static inline __attribute__ (( always_inline )) struct settings * static inline __attribute__ (( always_inline )) struct settings *
netdev_settings ( struct net_device *netdev ) { netdev_settings ( struct net_device *netdev ) {
return &netdev->settings; return &netdev->settings.settings;
} }
extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ); extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );

View File

@ -11,6 +11,7 @@
#include <gpxe/tables.h> #include <gpxe/tables.h>
#include <gpxe/list.h> #include <gpxe/list.h>
#include <gpxe/refcnt.h> #include <gpxe/refcnt.h>
#include <gpxe/dhcpopts.h>
struct settings; struct settings;
struct in_addr; struct in_addr;
@ -138,12 +139,23 @@ struct settings_applicator {
#define __settings_applicator \ #define __settings_applicator \
__table ( struct settings_applicator, settings_applicators, 01 ) __table ( struct settings_applicator, settings_applicators, 01 )
/**
* A simple settings block
*
*/
struct simple_settings {
/** Settings block */
struct settings settings;
/** DHCP options */
struct dhcp_options dhcpopts;
};
extern struct settings_operations simple_settings_operations;
extern int simple_settings_store ( struct settings *settings, unsigned int tag, extern int simple_settings_store ( struct settings *settings, unsigned int tag,
const void *data, size_t len ); const void *data, size_t len );
extern int simple_settings_fetch ( struct settings *settings, unsigned int tag, extern int simple_settings_fetch ( struct settings *settings, unsigned int tag,
void *data, size_t len ); void *data, size_t len );
extern struct settings_operations simple_settings_operations;
extern int register_settings ( struct settings *settings, extern int register_settings ( struct settings *settings,
struct settings *parent ); struct settings *parent );
extern void unregister_settings ( struct settings *settings ); extern void unregister_settings ( struct settings *settings );
@ -205,6 +217,20 @@ static inline void settings_init ( struct settings *settings,
settings->name = name; settings->name = name;
} }
/**
* Initialise a settings block
*
* @v simple Simple settings block
* @v refcnt Containing object reference counter, or NULL
* @v name Settings block name
*/
static inline void simple_settings_init ( struct simple_settings *simple,
struct refcnt *refcnt,
const char *name ) {
settings_init ( &simple->settings, &simple_settings_operations,
refcnt, name );
}
/** /**
* Delete setting * Delete setting
* *

View File

@ -39,8 +39,8 @@
*/ */
static int netdev_store ( struct settings *settings, unsigned int tag, static int netdev_store ( struct settings *settings, unsigned int tag,
const void *data, size_t len ) { const void *data, size_t len ) {
struct net_device *netdev = struct net_device *netdev = container_of ( settings, struct net_device,
container_of ( settings, struct net_device, settings ); settings.settings );
switch ( tag ) { switch ( tag ) {
case DHCP_EB_MAC: case DHCP_EB_MAC:
@ -64,8 +64,8 @@ static int netdev_store ( struct settings *settings, unsigned int tag,
*/ */
static int netdev_fetch ( struct settings *settings, unsigned int tag, static int netdev_fetch ( struct settings *settings, unsigned int tag,
void *data, size_t len ) { void *data, size_t len ) {
struct net_device *netdev = struct net_device *netdev = container_of ( settings, struct net_device,
container_of ( settings, struct net_device, settings ); settings.settings );
switch ( tag ) { switch ( tag ) {
case DHCP_EB_MAC: case DHCP_EB_MAC: