1/** 2 * \file 3 * \brief Monitor octopus client 4 * 5 * Cannot simply use octopus client library as monitor does not support THC 6 * calls. 7 */ 8 9/* 10 * Copyright (c) 2016, ETH Zurich. 11 * All rights reserved. 12 * 13 * This file is distributed under the terms in the attached LICENSE file. 14 * If you do not find this file, copies can be found by writing to: 15 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group. 16 */ 17 18#include <if/octopus_defs.h> 19#include <octopus/getset.h> // for oct_read TODO 20#include <octopus/trigger.h> // for NOP_TRIGGER 21#include "monitor.h" 22 23struct bind_state { 24 bool done; 25 errval_t err; 26}; 27 28static void error_handler(struct octopus_binding *b, errval_t err) 29{ 30 USER_PANIC_ERR(err, "asynchronous error in nameservice binding"); 31} 32 33static void bind_continuation(void *st_arg, errval_t err, 34 struct octopus_binding *b) 35{ 36 struct bind_state *st = st_arg; 37 38 if (err_is_ok(err)) { 39 b->error_handler = error_handler; 40 41 octopus_rpc_client_init(b); 42 set_octopus_binding(b); 43 } 44 45 st->err = err; 46 st->done = true; 47} 48 49errval_t octopus_client_bind(void) 50{ 51 errval_t err; 52 struct bind_state st = { .done = false }; 53 assert(name_serv_iref != 0); 54 err = octopus_bind(name_serv_iref, bind_continuation, &st, 55 get_default_waitset(), IDC_BIND_FLAG_RPC_CAP_TRANSFER); 56 while (!st.done) { 57 err = event_dispatch(get_default_waitset()); 58 if (err_is_fail(err)) { 59 DEBUG_ERR(err, "ev_disp in octopus_client_bind"); 60 } 61 } 62 63 return st.err; 64} 65 66errval_t octopus_set_bspkcb(void) 67{ 68 errval_t err, octerr; 69 70 const char *kcb_key = "kcb_id_0"; 71 const char *mapping = "kcb.0 { kcb_id: 0, barrelfish_id: 0, cap_key: 'kcb_id_0' }"; 72 73 struct capref bspkcb = { 74 .cnode = cnode_root, 75 .slot = ROOTCN_SLOT_BSPKCB, 76 }; 77 78 debug_printf("%s: storing cap\n", __FUNCTION__); 79 struct octopus_binding *orpc = get_octopus_binding(); 80 err = orpc->rpc_tx_vtbl.put_cap(orpc, kcb_key, bspkcb, &octerr); 81 if (err_is_fail(err)) { 82 DEBUG_ERR(err, "oct_put_capability(bspkcb)"); 83 return err; 84 } 85 if (err_is_fail(octerr)) { 86 DEBUG_ERR(octerr, "from octopus in oct_put_capability(bspkcb)"); 87 return err; 88 } 89 debug_printf("%s: setting mapping\n", __FUNCTION__); 90 err = orpc->rpc_tx_vtbl.set(orpc, mapping, SET_DEFAULT, NOP_TRIGGER, false, 91 NULL, NULL, &octerr); 92 if (err_is_fail(err)) { 93 DEBUG_ERR(err, "oct_set(\"kcb.0 { ... }\")"); 94 return err; 95 } 96 if (err_is_fail(octerr)) { 97 DEBUG_ERR(octerr, "from octopus oct_set(\"kcb.0 { ... }\")"); 98 return err; 99 } 100 101 return SYS_ERR_OK; 102} 103