Changes for nameservice. Use RPC client for NS functionality.
authorGerd Zellweger <zgerd@student.ethz.ch>
Wed, 22 Feb 2012 23:18:40 +0000 (00:18 +0100)
committerGerd Zellweger <zgerd@student.ethz.ch>
Wed, 22 Feb 2012 23:18:40 +0000 (00:18 +0100)
hake/ArchDefaults.hs
include/barrelfish/core_state.h
include/barrelfish/domain.h
lib/barrelfish/Hakefile
lib/barrelfish/domain.c
lib/barrelfish/init.c
lib/barrelfish/nameservice_client.c
lib/dist2/parser/read.c [moved from lib/dist2/client/read.c with 100% similarity]
lib/posixcompat/Hakefile
lib/posixcompat/semaphore.c

index 9d9ca8b..bf245cb 100644 (file)
@@ -79,8 +79,7 @@ ldCxxFlags arch =
 
 stdLibs arch = 
     [ In InstallTree arch "/lib/libbarrelfish.a",
-      In InstallTree arch "/lib/libdist2.a",
-      In InstallTree arch "/lib/libdist_parser.a",
+      In InstallTree arch "/lib/libdist_parser.a", -- dist_read() in nameservice_client.c
       In InstallTree arch "/errors/errno.o",
       In InstallTree arch "/lib/libc.a",
       In InstallTree arch "/lib/crtend.o" ,
index 58abc8b..52ae601 100644 (file)
@@ -81,7 +81,7 @@ struct slot_alloc_state {
 };
 
 struct terminal_state;
-struct nameservice_rpc_client;
+struct dist2_rpc_client;
 struct domain_state;
 struct spawn_state;
 struct monitor_binding;
@@ -95,7 +95,7 @@ struct core_state_generic {
     struct mem_rpc_client *mem_st;
     struct morecore_state morecore_state;
     struct ram_alloc_state ram_alloc_state;
-    struct nameservice_rpc_client *nameservice_rpc_client;
+    struct dist2_rpc_client *nameservice_rpc_client;
     struct spawn_rpc_client *spawn_rpc_clients[MAX_CPUS];
     struct terminal_state *terminal_state;
     struct domain_state *domain_state;
index 1e47360..20772ea 100644 (file)
@@ -18,7 +18,7 @@
 typedef void (*domain_spanned_callback_t)(void *arg, errval_t err);
 
 struct mem_rpc_client;
-struct nameservice_rpc_client;
+struct dist2_rpc_client;
 struct monitor_binding;
 struct monitor_blocking_rpc_client;
 struct waitset;
@@ -40,8 +40,8 @@ struct vspace *get_current_vspace(void);
 struct pmap *get_current_pmap(void);
 struct morecore_state *get_morecore_state(void);
 struct ram_alloc_state *get_ram_alloc_state(void);
-void set_nameservice_rpc_client(struct nameservice_rpc_client *st);
-struct nameservice_rpc_client *get_nameservice_rpc_client(void);
+void set_nameservice_rpc_client(struct dist2_rpc_client *st);
+struct dist2_rpc_client *get_nameservice_rpc_client(void);
 void set_spawn_rpc_client(coreid_t core, struct spawn_rpc_client *st);
 struct spawn_rpc_client *get_spawn_rpc_client(coreid_t core);
 struct terminal_state *get_terminal_state(void);
index 6a717ab..3cae7cd 100644 (file)
                     cFiles = arch_srcs arch ++ archfam_srcs (archFamily arch)
                              ++ common_srcs ++ idc_srcs,
                     assemblyFiles = arch_assembly (archFamily arch),
-                    flounderBindings = [ "mem", "nameservice", "serial",
+                    flounderBindings = [ "mem", "dist2", "serial",
                                          "interdisp", "spawn", "keyboard" ],
                     -- only makes sense to compile monitor binding for lmp
                     flounderExtraBindings = [ ("monitor", ["lmp"]),
                                              ("monitor_blocking", ["lmp", "rpcclient"]),
                                               ("mem", ["rpcclient"]),
-                                              ("nameservice", ["rpcclient"]),
+                                              ("dist2", ["rpcclient"]),
                                               ("spawn", ["rpcclient"]),
                                               ("serial", ["rpcclient"])],
                     addIncludes = [ "include", "include" ./. arch_dir ],
index b763347..a63c249 100644 (file)
@@ -1088,7 +1088,7 @@ struct skb_state *get_skb_state(void)
 /**
  * \brief Returns a pointer to the chips_context state on the dispatcher priv
  */
-struct nameservice_rpc_client *get_nameservice_rpc_client(void)
+struct dist2_rpc_client *get_nameservice_rpc_client(void)
 {
     dispatcher_handle_t handle = curdispatcher();
     struct dispatcher_generic* disp = get_dispatcher_generic(handle);
@@ -1098,7 +1098,7 @@ struct nameservice_rpc_client *get_nameservice_rpc_client(void)
 /**
  * \brief set the chips_context state on the dispatcher priv
  */
-void set_nameservice_rpc_client(struct nameservice_rpc_client *c)
+void set_nameservice_rpc_client(struct dist2_rpc_client *c)
 {
     dispatcher_handle_t handle = curdispatcher();
     struct dispatcher_generic* disp = get_dispatcher_generic(handle);
index 509df59..54504e5 100644 (file)
@@ -245,7 +245,7 @@ errval_t barrelfish_init_onthread(struct spawn_domain_params *params)
 #endif
 
     // try to connect to name service (may fail if we are the skb or ramfsd!)
-    err = dist_rpc_init();
+    err = nameservice_client_blocking_bind();
     if (err_is_fail(err)) {
         if (err_no(err) == LIB_ERR_GET_NAME_IREF) {
             // skip everything else if we don't have a nameservice
index 408a28f..842a566 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * \file
- * \brief Client for interacting with the name service (chips)
+ * \brief Client for interacting with the name service
  */
 
 /*
  * If you do not find this file, copies can be found by writing to:
  * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
  */
+#include <stdio.h>
 
 #include <barrelfish/barrelfish.h>
 #include <barrelfish/nameservice_client.h>
 
-#include <if/nameservice_defs.h>
-#include <if/nameservice_rpcclient_defs.h>
+#include <if/dist2_defs.h>
+#include <if/dist2_rpcclient_defs.h>
 #include <if/monitor_defs.h>
+#include <dist2/getset.h> // for dist_read TODO
+#include <dist2/trigger.h> // for NOP_TRIGGER
 
 /**
  * \brief Non-blocking name service lookup
  * \param iface Name of interface for which to query name server
  * \param retiref Returns pointer to IREF on success
  */
-#ifdef USE_CHIPS_NS
 errval_t nameservice_lookup(const char *iface, iref_t *retiref)
 {
-    nameservice_srvref_t ref;
     errval_t err;
 
-    struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+    struct dist2_rpc_client *r = get_nameservice_rpc_client();
     if (r == NULL) {
         return LIB_ERR_NAMESERVICE_NOT_BOUND;
     }
 
-    err = r->vtbl.get_service_reference(r, iface, &ref);
+    char* record = NULL;
+    dist2_trigger_id_t tid;
+    errval_t error_code;
+    err = r->vtbl.get(r, iface, NOP_TRIGGER, &record, &tid, &error_code);
     if (err_is_fail(err)) {
-        return err_push(err, CHIPS_ERR_GET_SERVICE_REFERENCE);
+        goto out;
     }
-
-    if (ref == 0) {
-        return CHIPS_ERR_UNKNOWN_NAME;
+    err = error_code;
+    if (err_is_fail(err)) {
+        if (err_no(err) == DIST2_ERR_NO_RECORD) {
+            err = err_push(err, LIB_ERR_NAMESERVICE_UNKNOWN_NAME);
+        }
+        goto out;
     }
 
-    err = r->vtbl.get_service(r, ref, retiref);
-    if (err_is_fail(err)) {
-        return err_push(err, CHIPS_ERR_GET_SERVICE_IREF);
+    uint64_t iref_number = 0;
+    err = dist_read(record, "_ { iref: %d }", &iref_number);
+    if (err_is_fail(err) || iref_number == 0) {
+        err = err_push(err, LIB_ERR_NAMESERVICE_INVALID_NAME);
+        goto out;
+    }
+    if (retiref != NULL) {
+        *retiref = iref_number;
     }
 
-    return SYS_ERR_OK;
+out:
+    free(record);
+    return err;
 }
 
 /**
@@ -61,34 +75,40 @@ errval_t nameservice_lookup(const char *iface, iref_t *retiref)
  */
 errval_t nameservice_blocking_lookup(const char *iface, iref_t *retiref)
 {
-    nameservice_srvref_t ref;
-    iref_t iref;
     errval_t err;
 
-    struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+    struct dist2_rpc_client *r = get_nameservice_rpc_client();
     if (r == NULL) {
         return LIB_ERR_NAMESERVICE_NOT_BOUND;
     }
 
-    err = r->vtbl.wait_for_service_reference(r, iface, &ref);
+    char* record = NULL;
+    errval_t error_code;
+    err = r->vtbl.wait_for(r, iface, &record, &error_code);
     if (err_is_fail(err)) {
-        return err_push(err, CHIPS_ERR_GET_SERVICE_REFERENCE);
+        goto out;
     }
-
-    if (ref == 0) {
-        return CHIPS_ERR_GET_SERVICE_REFERENCE;
+    err = error_code;
+    if (err_is_fail(err)) {
+        if (err_no(err) == DIST2_ERR_NO_RECORD) {
+            err = err_push(err, LIB_ERR_NAMESERVICE_UNKNOWN_NAME);
+        }
+        goto out;
     }
 
-    err = r->vtbl.get_service(r, ref, &iref);
+    uint64_t iref_number = 0;
+    err = dist_read(record, "_ { iref: %d }", &iref_number);
     if (err_is_fail(err)) {
-        return err_push(err, CHIPS_ERR_GET_SERVICE_IREF);
+        err = err_push(err, LIB_ERR_NAMESERVICE_INVALID_NAME);
+        goto out;
     }
-
     if (retiref != NULL) {
-        *retiref = iref;
+        *retiref = iref_number;
     }
 
-    return SYS_ERR_OK;
+out:
+    free(record);
+    return err;
 }
 
 /**
@@ -99,17 +119,37 @@ errval_t nameservice_blocking_lookup(const char *iface, iref_t *retiref)
  */
 errval_t nameservice_register(const char *iface, iref_t iref)
 {
-    nameservice_srvref_t ref;
+    errval_t err = SYS_ERR_OK;
 
-    struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+    struct dist2_rpc_client *r = get_nameservice_rpc_client();
     if (r == NULL) {
         return LIB_ERR_NAMESERVICE_NOT_BOUND;
     }
 
-    return r->vtbl.register_service(r, iref, iface, &ref);
+    // Format record
+    static const char* format = "%s { iref: %d }";
+    size_t len = snprintf(NULL, 0, format, iface, iref);
+    char* record = malloc(len+1);
+    if (record == NULL) {
+        return LIB_ERR_MALLOC_FAIL;
+    }
+    snprintf(record, len+1, format, iface, iref);
+
+    char* ret = NULL;
+    dist2_trigger_id_t tid;
+    errval_t error_code;
+    err = r->vtbl.set(r, record, 0, NOP_TRIGGER, 0, &ret, &tid, &error_code);
+    if (err_is_fail(err)) {
+        goto out;
+    }
+    err = error_code;
+
+out:
+    free(record);
+    return err;
 }
-#endif
 
+#ifdef NOT_YET_IMPLEMENTED
 /**
  * \brief Get a capability from the capability store.
  *
@@ -120,7 +160,7 @@ errval_t nameservice_register(const char *iface, iref_t iref)
 errval_t nameservice_get_capability(const char *key, struct capref *retcap)
 {
     errval_t reterr;
-    struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+    struct dist2_rpc_client *r = get_nameservice_rpc_client();
     if (r == NULL) {
        printf("nameservice not found\n");
         return LIB_ERR_NAMESERVICE_NOT_BOUND;
@@ -144,7 +184,7 @@ errval_t nameservice_get_capability(const char *key, struct capref *retcap)
 errval_t nameservice_put_capability(const char *key, struct capref cap)
 {
     errval_t reterr;
-    struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+    struct dist2_rpc_client *r = get_nameservice_rpc_client();
     if (r == NULL) {
         return LIB_ERR_NAMESERVICE_NOT_BOUND;
     }
@@ -156,11 +196,12 @@ errval_t nameservice_put_capability(const char *key, struct capref cap)
 
     return reterr;
 }
+#endif
 
 /* ----------------------- BIND/INIT CODE FOLLOWS ----------------------- */
 
 
-static void error_handler(struct nameservice_binding *b, errval_t err)
+static void error_handler(struct dist2_binding *b, errval_t err)
 {
     USER_PANIC_ERR(err, "asynchronous error in nameservice binding");
 }
@@ -171,17 +212,17 @@ struct bind_state {
 };
 
 static void bind_continuation(void *st_arg, errval_t err,
-                              struct nameservice_binding *b)
+                              struct dist2_binding *b)
 {
     struct bind_state *st = st_arg;
 
     if (err_is_ok(err)) {
         b->error_handler = error_handler;
 
-        struct nameservice_rpc_client *r;
-        r = malloc(sizeof(struct nameservice_rpc_client));
+        struct dist2_rpc_client *r;
+        r = malloc(sizeof(struct dist2_rpc_client));
         assert(r != NULL);
-        err = nameservice_rpc_client_init(r, b);
+        err = dist2_rpc_client_init(r, b);
         if (err_is_fail(err)) {
             free(r);
             USER_PANIC_ERR(err, "error in nameservice_rpc_client_init");
@@ -203,8 +244,8 @@ static void get_name_iref_reply(struct monitor_binding *mb, iref_t iref,
     if (iref == 0) {
         err = LIB_ERR_GET_NAME_IREF;
     } else {
-        err = nameservice_bind(iref, bind_continuation, st,
-                               get_default_waitset(), IDC_BIND_FLAG_RPC_CAP_TRANSFER);
+        err = dist2_bind(iref, bind_continuation, st,
+                get_default_waitset(), IDC_BIND_FLAG_RPC_CAP_TRANSFER);
     }
 
     if (err_is_fail(err)) {
@@ -243,3 +284,4 @@ errval_t nameservice_client_blocking_bind(void)
 
     return st.err;
 }
+
index 76a6d63..4a94c61 100644 (file)
@@ -24,8 +24,8 @@
                              "shm.c", "getpid.c", "ioctl.c", "fcntl.c",
                              "sockets.c", "select.c", "grp.c", "rename.c",
                             "remove.c", "time.c", "random.c", "inheritance.c" ],
-                  flounderDefs = [ "unixsock", "nameservice", "monitor" ],
+                  flounderDefs = [ "unixsock", "dist2", "monitor" ],
                  flounderBindings = [ "unixsock" ],
-                  flounderExtraBindings = [ ("nameservice", ["rpcclient"]) ]
+                  flounderExtraBindings = [ ("dist2", ["rpcclient"]) ]
                 }
 ]
index a940536..63b0f82 100644 (file)
@@ -15,8 +15,8 @@
 #include <string.h>
 #include "posixcompat.h"
 
-#include <if/nameservice_defs.h>
-#include <if/nameservice_rpcclient_defs.h>
+#include <if/dist2_defs.h>
+#include <if/dist2_rpcclient_defs.h>
 
 int sem_init(sem_t *sem, int pshared, unsigned int value)
 {
@@ -30,7 +30,7 @@ int sem_init(sem_t *sem, int pshared, unsigned int value)
 
                POSIXCOMPAT_DEBUG("%d: sem_init(%p, %d, %u)\n", disp_get_domain_id(), sem, pshared, value);
 
-        struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+        struct dist2_rpc_client *r = get_nameservice_rpc_client();
         assert(r != NULL);
 
         errval_t err, reterr;
@@ -67,7 +67,7 @@ int sem_wait(sem_t *sem)
     if(!sem->pshared) {
         thread_sem_wait(&sem->thread_sem);
     } else {
-        struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+        struct dist2_rpc_client *r = get_nameservice_rpc_client();
         assert(r != NULL);
 
         errval_t err;
@@ -92,7 +92,7 @@ int sem_trywait(sem_t *sem)
             return -1;
         }
     } else {
-        struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+        struct dist2_rpc_client *r = get_nameservice_rpc_client();
         assert(r != NULL);
 
         errval_t err;
@@ -126,7 +126,7 @@ int sem_post(sem_t *sem)
     if(!sem->pshared) {
         thread_sem_post(&sem->thread_sem);
     } else {
-        struct nameservice_rpc_client *r = get_nameservice_rpc_client();
+        struct dist2_rpc_client *r = get_nameservice_rpc_client();
         assert(r != NULL);
 
         errval_t err;