X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fsysinfo.c;h=219369a0d5456f5bda27fed2ba7a534a4db7b64b;hp=19dac57f02fb26757948605f716a2e94ba44550a;hb=53aa247c013afcab0dd003fbb7bd056bebcb23e8;hpb=bc4114e2235163bd88456c25cc0a908d86151f93 diff --git a/discover/sysinfo.c b/discover/sysinfo.c index 19dac57..219369a 100644 --- a/discover/sysinfo.c +++ b/discover/sysinfo.c @@ -2,8 +2,10 @@ #include #include +#include #include "discover-server.h" +#include "platform.h" #include "sysinfo.h" static struct system_info *sysinfo; @@ -15,12 +17,14 @@ const struct system_info *system_info_get(void) } void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr, - const char *name) + const char *name, bool link) { struct interface_info *if_info; unsigned int i; for (i = 0; i < sysinfo->n_interfaces; i++) { + bool changed = false; + if_info = sysinfo->interfaces[i]; if (if_info->hwaddr_size != hwaddr_size) @@ -29,10 +33,22 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr, if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size)) continue; - /* update the name and we're done */ - talloc_free(if_info->name); - if_info->name = talloc_strdup(if_info, name); - discover_server_notify_system_info(server, sysinfo); + /* Found an existing interface. Notify clients on any name or + * link changes */ + if (strcmp(if_info->name, name)) { + talloc_free(if_info->name); + if_info->name = talloc_strdup(if_info, name); + changed = true; + } + + if (if_info->link != link) { + if_info->link = link; + changed = true; + } + + if (changed) + discover_server_notify_system_info(server, sysinfo); + return; } @@ -40,6 +56,7 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr, if_info->hwaddr_size = hwaddr_size; if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size); if_info->name = talloc_strdup(if_info, name); + if_info->link = link; sysinfo->n_interfaces++; sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces, @@ -50,15 +67,43 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr, discover_server_notify_system_info(server, sysinfo); } -static void system_info_set_identifier(struct system_info *info - __attribute__((unused))) +void system_info_register_blockdev(const char *name, const char *uuid, + const char *mountpoint) { - /* todo: call helpers to set type & id */ + struct blockdev_info *bd_info; + unsigned int i; + + for (i = 0; i < sysinfo->n_blockdevs; i++) { + bd_info = sysinfo->blockdevs[i]; + + if (strcmp(bd_info->name, name)) + continue; + + /* update the mountpoint and UUID, and we're done */ + talloc_free(bd_info->mountpoint); + bd_info->uuid = talloc_strdup(bd_info, uuid); + bd_info->mountpoint = talloc_strdup(bd_info, mountpoint); + discover_server_notify_system_info(server, sysinfo); + return; + } + + bd_info = talloc_zero(sysinfo, struct blockdev_info); + bd_info->name = talloc_strdup(bd_info, name); + bd_info->uuid = talloc_strdup(bd_info, uuid); + bd_info->mountpoint = talloc_strdup(bd_info, mountpoint); + + sysinfo->n_blockdevs++; + sysinfo->blockdevs = talloc_realloc(sysinfo, sysinfo->blockdevs, + struct blockdev_info *, + sysinfo->n_blockdevs); + sysinfo->blockdevs[sysinfo->n_blockdevs - 1] = bd_info; + + discover_server_notify_system_info(server, sysinfo); } void system_info_init(struct discover_server *s) { - sysinfo = talloc_zero(server, struct system_info); server = s; - system_info_set_identifier(sysinfo); + sysinfo = talloc_zero(server, struct system_info); + platform_get_sysinfo(sysinfo); }