discover: Use platform code to read sysinfo type and identifier
authorJeremy Kerr <jk@ozlabs.org>
Wed, 23 Jul 2014 06:03:42 +0000 (14:03 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 5 Aug 2014 02:49:31 +0000 (10:49 +0800)
This change uses the platform-specific code to read the system type and
identifier, rather than the pb-sysinfo utility. We introduce a new
callback for struct platform:

  int (*get_sysinfo)(struct platform *, struct system_info *);

- which populates struct system_info with appropriate information.

This means that the system-specific code is kept in one place; rather
than having powerpc-specific device-tree-reading code in the pb-sysinfo
shell script.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/platform-powerpc.c
discover/platform.c
discover/platform.h
discover/sysinfo.c
utils/pb-sysinfo

index 24cc521c12c98c40f57c2fbec42400ee71f6f556..2ce69e76f892ace0f6b06bae728edb20d362f25f 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/fcntl.h>
 #include <sys/stat.h>
 
+#include <file/file.h>
 #include <talloc/talloc.h>
 #include <list/list.h>
 #include <log/log.h>
@@ -738,6 +739,23 @@ static int save_config(struct platform *p, struct config *config)
        return rc;
 }
 
+static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
+{
+       struct platform_powerpc *platform = p->platform_data;
+       int len, rc;
+       char *buf;
+
+       rc = read_file(platform, "/proc/device_tree/model", &buf, &len);
+       if (rc == 0)
+               sysinfo->type = talloc_steal(sysinfo, buf);
+
+       rc = read_file(platform, "/proc/device_tree/system-id", &buf, &len);
+       if (rc == 0)
+               sysinfo->identifier = talloc_steal(sysinfo, buf);
+
+       return 0;
+}
+
 static bool probe(struct platform *p, void *ctx)
 {
        struct platform_powerpc *platform;
@@ -759,12 +777,14 @@ static bool probe(struct platform *p, void *ctx)
        return true;
 }
 
+
 static struct platform platform_powerpc = {
        .name           = "powerpc",
        .dhcp_arch_id   = 0x000e,
        .probe          = probe,
        .load_config    = load_config,
        .save_config    = save_config,
+       .get_sysinfo    = get_sysinfo,
 };
 
 register_platform(platform_powerpc);
index 0dced1697f6458c8c4dc3291758da593f1fa47aa..65e9ed4acb4af5662b9a1a3006715226b9c9954d 100644 (file)
@@ -143,6 +143,13 @@ const struct platform *platform_get(void)
        return platform;
 }
 
+int platform_get_sysinfo(struct system_info *info)
+{
+       if (platform && platform->get_sysinfo)
+               return platform->get_sysinfo(platform, info);
+       return -1;
+}
+
 int config_set(struct config *newconfig)
 {
        int rc;
index a01ac7108ae562ae9cea3ecc7ed03b69357af6a4..0a1aa5e3015920cfb17e3c632b203467e82d05d1 100644 (file)
@@ -8,6 +8,7 @@ struct platform {
        bool            (*probe)(struct platform *, void *);
        int             (*load_config)(struct platform *, struct config *);
        int             (*save_config)(struct platform *, struct config *);
+       int             (*get_sysinfo)(struct platform *, struct system_info *);
        uint16_t        dhcp_arch_id;
        void            *platform_data;
 };
@@ -15,6 +16,7 @@ struct platform {
 int platform_init(void *ctx);
 int platform_fini(void);
 const struct platform *platform_get(void);
+int platform_get_sysinfo(struct system_info *info);
 
 /* configuration interface */
 const struct config *config_get(void);
index be4543832265a964ceea26124dbcdc1a8d85a2c9..219369a0d5456f5bda27fed2ba7a534a4db7b64b 100644 (file)
@@ -5,13 +5,12 @@
 #include <process/process.h>
 
 #include "discover-server.h"
+#include "platform.h"
 #include "sysinfo.h"
 
 static struct system_info *sysinfo;
 static struct discover_server *server;
 
-static const char *sysinfo_helper = PKG_LIBEXEC_DIR "/pb-sysinfo";
-
 const struct system_info *system_info_get(void)
 {
        return sysinfo;
@@ -102,41 +101,9 @@ void system_info_register_blockdev(const char *name, const char *uuid,
        discover_server_notify_system_info(server, sysinfo);
 }
 
-static void system_info_set_identifier(struct system_info *info)
-{
-       struct process *process;
-       int rc;
-       const char *argv[] = {
-               sysinfo_helper, NULL, NULL,
-       };
-
-       process = process_create(info);
-       process->path = sysinfo_helper;
-       process->argv = argv;
-       process->keep_stdout = true;
-
-       argv[1] = "--type";
-       rc = process_run_sync(process);
-
-       if (!rc) {
-               info->type = talloc_strndup(info, process->stdout_buf,
-                               process->stdout_len);
-       }
-
-       argv[1] = "--id";
-       rc = process_run_sync(process);
-
-       if (!rc) {
-               info->identifier = talloc_strndup(info, process->stdout_buf,
-                               process->stdout_len);
-       }
-
-       process_release(process);
-}
-
 void system_info_init(struct discover_server *s)
 {
        server = s;
        sysinfo = talloc_zero(server, struct system_info);
-       system_info_set_identifier(sysinfo);
+       platform_get_sysinfo(sysinfo);
 }
index 001535a46fac14934e7fc5be2a4ccf86317de9f8..7d6635cf0351c87f1d66429c0f8f26f8eb93c5ed 100755 (executable)
@@ -1,12 +1,6 @@
 #!/bin/sh
 
 case "$1" in
-'--type')
-       tr -d '\0' < /proc/device-tree/model
-       ;;
-'--id')
-       tr -d '\0' < /proc/device-tree/system-id
-       ;;
 '--debug-enabled')
        exec >/dev/null 2>&1
        nvram --print-config=petitboot,debug? | grep -q true && exit 0