[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 10/11] servmgr: Auf Root-Dateisystem warten



+ servmgr: Anstatt davon auszugehen, dass das Root-Dateisystem bereit
  ist, sobald alle Multiboot-Services geladen sind, lassen wir dem
  Dateisystem jetzt ein bisschen Zeit, um aufzutauchen. Mit Probing
  läuft die Erstellung des Symlinks im Hintergrund, während der
  Storagetreiber sich schon als Service registriert hat.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/servmgr/lang/lang_en.c |  3 +++
 src/modules/servmgr/lang/resstr.h  |  1 +
 src/modules/servmgr/main.c         | 46 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)

diff --git a/src/modules/servmgr/lang/lang_en.c b/src/modules/servmgr/lang/lang_en.c
index 390ce0e..82b6997 100644
--- a/src/modules/servmgr/lang/lang_en.c
+++ b/src/modules/servmgr/lang/lang_en.c
@@ -47,6 +47,9 @@ static const struct tms_strings dict[] = {
     &__tms_main_not_running,
     "service '%s' is not running!\n",
 
+    &__tms_main_no_root,
+    "servmgr: timeout while waiting for root filesystem\n",
+
     &__tms_service_not_found,
     "servmgr: service not found: '%s'\n",
 
diff --git a/src/modules/servmgr/lang/resstr.h b/src/modules/servmgr/lang/resstr.h
index 9664fed..91cfc84 100644
--- a/src/modules/servmgr/lang/resstr.h
+++ b/src/modules/servmgr/lang/resstr.h
@@ -34,6 +34,7 @@ extern void* __tms_config_dir_open;
 
 extern void* __tms_main_usage;
 extern void* __tms_main_not_running;
+extern void* __tms_main_no_root;
 
 extern void* __tms_service_not_found;
 extern void* __tms_service_dependency;
diff --git a/src/modules/servmgr/main.c b/src/modules/servmgr/main.c
index 09d17fd..86c70d4 100644
--- a/src/modules/servmgr/main.c
+++ b/src/modules/servmgr/main.c
@@ -38,6 +38,7 @@
 #include <collections.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <string.h>
 #include <init.h>
 #include <rpc.h>
 
@@ -122,6 +123,44 @@ static bool wait_startup_services(void)
 }
 
 /**
+ * Auf Root-Dateisystem warten
+ *
+ * @return true wenn das Dateisystem da ist, false sonst.
+ */
+static bool wait_root_dir(void)
+{
+    uint64_t timeout = get_tick_count() + 5000000;
+    lio_resource_t res;
+    lio_stream_t s;
+
+    while (timeout > get_tick_count()) {
+        res = lio_resource(root_dir, false);
+        if (res >= 0) {
+            goto found;
+        }
+
+        // Das System nicht mit Dauerpolling verstopfen
+        timer_register(do_nothing, 50000);
+        wait_for_rpc();
+    }
+    return false;
+
+found:
+    s = lio_open(res, LIO_SYMLINK | LIO_READ);
+    if (s >= 0) {
+        char buf[1024];
+        int ret;
+        ret = lio_read(s, sizeof(buf), buf);
+        if (ret > 0) {
+            root_dir = strdup(buf);
+            chdir(root_dir);
+        }
+        lio_close(s);
+    }
+    return true;
+}
+
+/**
  * Startup-Services anzeigen, die nicht gestartet wurden.
  */
 static void failed_startup_services(void)
@@ -163,6 +202,13 @@ int main(int argc, char* argv[])
         return EXIT_FAILURE;
     }
 
+    // Auf Rootdateisystem warten
+    if (!wait_root_dir()) {
+        printf(TMS(no_root, "servmgr: Timeout beim Warten auf das "
+                            "Rootdateisystem\n"));
+        return EXIT_FAILURE;
+    }
+
     // Konfiguration einlesen
     if (config_read()) {
         config_done = true;
-- 
2.1.4