custom message req & reply types for ds

This commit is contained in:
Ben Gras 2014-07-26 13:54:02 +02:00 committed by Lionel Sambuc
parent c727357664
commit 5d0e31dbb3
4 changed files with 76 additions and 58 deletions

View file

@ -502,16 +502,6 @@
#define DS_RETRIEVE_LABEL (DS_RQ_BASE + 6) /* retrieve label's name */ #define DS_RETRIEVE_LABEL (DS_RQ_BASE + 6) /* retrieve label's name */
#define DS_GETSYSINFO (DS_RQ_BASE + 7) /* get system information */ #define DS_GETSYSINFO (DS_RQ_BASE + 7) /* get system information */
/* DS field names */
# define DS_KEY_GRANT m2_i1 /* key for the data */
# define DS_KEY_LEN m2_s1 /* length of key incl. '\0' */
# define DS_FLAGS m2_i2 /* flags provided by caller */
# define DS_VAL m2_l1 /* data (u32, char *, etc.) */
# define DS_VAL_LEN m2_l2 /* data length */
# define DS_NR_SNAPSHOT m2_i3 /* number of snapshot */
# define DS_OWNER m2_i3 /* owner */
/*===========================================================================* /*===========================================================================*
* Messages used between PM and VFS * * Messages used between PM and VFS *
*===========================================================================*/ *===========================================================================*/

View file

@ -1907,6 +1907,28 @@ typedef struct {
} mess_rs_req; } mess_rs_req;
_ASSERT_MSG_SIZE(mess_rs_req); _ASSERT_MSG_SIZE(mess_rs_req);
typedef struct {
cp_grant_id_t key_grant;
int key_len;
int flags;
union ds_val {
cp_grant_id_t grant;
u32_t u32;
endpoint_t ep;
} val_in;
int val_len;
endpoint_t owner;
uint8_t padding[32];
} mess_ds_req;
_ASSERT_MSG_SIZE(mess_ds_req);
typedef struct {
union ds_val val_out;
int val_len;
uint8_t padding[48];
} mess_ds_reply;
_ASSERT_MSG_SIZE(mess_ds_reply);
typedef struct { typedef struct {
endpoint_t m_source; /* who sent the message */ endpoint_t m_source; /* who sent the message */
int m_type; /* what kind of message is it */ int m_type; /* what kind of message is it */
@ -2150,6 +2172,8 @@ typedef struct {
mess_rs_init m_rs_init; mess_rs_init m_rs_init;
mess_rs_update m_rs_update; mess_rs_update m_rs_update;
mess_rs_req m_rs_req; mess_rs_req m_rs_req;
mess_ds_req m_ds_req;
mess_ds_reply m_ds_reply;
mess_vfs_lchardriver_cancel m_vfs_lchardriver_cancel; mess_vfs_lchardriver_cancel m_vfs_lchardriver_cancel;
mess_vfs_lchardriver_openclose m_vfs_lchardriver_openclose; mess_vfs_lchardriver_openclose m_vfs_lchardriver_openclose;

View file

@ -24,8 +24,8 @@ static int do_invoke_ds(message *m, int type, const char *ds_name)
if(!GRANT_VALID(g_key)) if(!GRANT_VALID(g_key))
return ENOMEM; return ENOMEM;
m->DS_KEY_GRANT = g_key; m->m_ds_req.key_grant = g_key;
m->DS_KEY_LEN = len_key; m->m_ds_req.key_len = len_key;
r = _taskcall(DS_PROC_NR, type, m); r = _taskcall(DS_PROC_NR, type, m);
@ -38,8 +38,8 @@ int ds_publish_label(const char *ds_name, endpoint_t endpoint, int flags)
message m; message m;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_VAL = (u32_t) endpoint; m.m_ds_req.val_in.ep = endpoint;
m.DS_FLAGS = DSF_TYPE_LABEL | flags; m.m_ds_req.flags = DSF_TYPE_LABEL | flags;
return do_invoke_ds(&m, DS_PUBLISH, ds_name); return do_invoke_ds(&m, DS_PUBLISH, ds_name);
} }
@ -48,8 +48,8 @@ int ds_publish_u32(const char *ds_name, u32_t value, int flags)
message m; message m;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_VAL = value; m.m_ds_req.val_in.u32 = value;
m.DS_FLAGS = DSF_TYPE_U32 | flags; m.m_ds_req.flags = DSF_TYPE_U32 | flags;
return do_invoke_ds(&m, DS_PUBLISH, ds_name); return do_invoke_ds(&m, DS_PUBLISH, ds_name);
} }
@ -66,9 +66,9 @@ static int ds_publish_raw(const char *ds_name, void *vaddr, size_t length,
return ENOMEM; return ENOMEM;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_VAL = gid; m.m_ds_req.val_in.grant = gid;
m.DS_VAL_LEN = length; m.m_ds_req.val_len = length;
m.DS_FLAGS = flags; m.m_ds_req.flags = flags;
r = do_invoke_ds(&m, DS_PUBLISH, ds_name); r = do_invoke_ds(&m, DS_PUBLISH, ds_name);
cpf_revoke(gid); cpf_revoke(gid);
@ -95,7 +95,7 @@ int ds_retrieve_label_name(char *ds_name, endpoint_t endpoint)
int r; int r;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_VAL = (u32_t) endpoint; m.m_ds_req.val_in.ep = endpoint;
r = do_invoke_ds(&m, DS_RETRIEVE_LABEL, ds_name); r = do_invoke_ds(&m, DS_RETRIEVE_LABEL, ds_name);
return r; return r;
} }
@ -106,9 +106,9 @@ int ds_retrieve_label_endpt(const char *ds_name, endpoint_t *endpoint)
int r; int r;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_LABEL; m.m_ds_req.flags = DSF_TYPE_LABEL;
r = do_invoke_ds(&m, DS_RETRIEVE, ds_name); r = do_invoke_ds(&m, DS_RETRIEVE, ds_name);
*endpoint = (endpoint_t) m.DS_VAL; *endpoint = m.m_ds_reply.val_out.ep;
return r; return r;
} }
@ -118,9 +118,9 @@ int ds_retrieve_u32(const char *ds_name, u32_t *value)
int r; int r;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_U32; m.m_ds_req.flags = DSF_TYPE_U32;
r = do_invoke_ds(&m, DS_RETRIEVE, ds_name); r = do_invoke_ds(&m, DS_RETRIEVE, ds_name);
*value = m.DS_VAL; *value = m.m_ds_reply.val_out.u32;
return r; return r;
} }
@ -137,11 +137,11 @@ static int ds_retrieve_raw(const char *ds_name, char *vaddr, size_t *length,
return ENOMEM; return ENOMEM;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_VAL = gid; m.m_ds_req.val_in.grant = gid;
m.DS_VAL_LEN = *length; m.m_ds_req.val_len = *length;
m.DS_FLAGS = flags; m.m_ds_req.flags = flags;
r = do_invoke_ds(&m, DS_RETRIEVE, ds_name); r = do_invoke_ds(&m, DS_RETRIEVE, ds_name);
*length = m.DS_VAL_LEN; *length = m.m_ds_reply.val_len;
cpf_revoke(gid); cpf_revoke(gid);
return r; return r;
@ -166,7 +166,7 @@ int ds_delete_u32(const char *ds_name)
message m; message m;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_U32; m.m_ds_req.flags = DSF_TYPE_U32;
return do_invoke_ds(&m, DS_DELETE, ds_name); return do_invoke_ds(&m, DS_DELETE, ds_name);
} }
@ -175,7 +175,7 @@ int ds_delete_str(const char *ds_name)
message m; message m;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_STR; m.m_ds_req.flags = DSF_TYPE_STR;
return do_invoke_ds(&m, DS_DELETE, ds_name); return do_invoke_ds(&m, DS_DELETE, ds_name);
} }
@ -184,7 +184,7 @@ int ds_delete_mem(const char *ds_name)
message m; message m;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_MEM; m.m_ds_req.flags = DSF_TYPE_MEM;
return do_invoke_ds(&m, DS_DELETE, ds_name); return do_invoke_ds(&m, DS_DELETE, ds_name);
} }
@ -193,7 +193,7 @@ int ds_delete_label(const char *ds_name)
message m; message m;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_FLAGS = DSF_TYPE_LABEL; m.m_ds_req.flags = DSF_TYPE_LABEL;
return do_invoke_ds(&m, DS_DELETE, ds_name); return do_invoke_ds(&m, DS_DELETE, ds_name);
} }
@ -202,7 +202,7 @@ int ds_subscribe(const char *regexp, int flags)
message m; message m;
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.DS_FLAGS = flags; m.m_ds_req.flags = flags;
return do_invoke_ds(&m, DS_SUBSCRIBE, regexp); return do_invoke_ds(&m, DS_SUBSCRIBE, regexp);
} }
@ -213,7 +213,7 @@ int ds_check(char *ds_key, int *type, endpoint_t *owner_e)
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
r = do_invoke_ds(&m, DS_CHECK, ds_key); r = do_invoke_ds(&m, DS_CHECK, ds_key);
if(type) *type = m.DS_FLAGS; if(type) *type = m.m_ds_req.flags;
if(owner_e) *owner_e = m.DS_OWNER; if(owner_e) *owner_e = m.m_ds_req.owner;
return r; return r;
} }

View file

@ -146,16 +146,16 @@ static int get_key_name(const message *m_ptr, char *key_name)
/* Get key name given an input message. */ /* Get key name given an input message. */
int r; int r;
if (m_ptr->DS_KEY_LEN > DS_MAX_KEYLEN || m_ptr->DS_KEY_LEN < 2) { if (m_ptr->m_ds_req.key_len > DS_MAX_KEYLEN || m_ptr->m_ds_req.key_len < 2) {
printf("DS: bogus key length (%d) from %d\n", m_ptr->DS_KEY_LEN, printf("DS: bogus key length (%d) from %d\n", m_ptr->m_ds_req.key_len,
m_ptr->m_source); m_ptr->m_source);
return EINVAL; return EINVAL;
} }
/* Copy name from caller. */ /* Copy name from caller. */
r = sys_safecopyfrom(m_ptr->m_source, r = sys_safecopyfrom(m_ptr->m_source,
(cp_grant_id_t) m_ptr->DS_KEY_GRANT, 0, (cp_grant_id_t) m_ptr->m_ds_req.key_grant, 0,
(vir_bytes) key_name, m_ptr->DS_KEY_LEN); (vir_bytes) key_name, m_ptr->m_ds_req.key_len);
if(r != OK) { if(r != OK) {
printf("DS: publish: copy failed from %d: %d\n", m_ptr->m_source, r); printf("DS: publish: copy failed from %d: %d\n", m_ptr->m_source, r);
return r; return r;
@ -275,7 +275,7 @@ int do_publish(message *m_ptr)
struct data_store *dsp; struct data_store *dsp;
char key_name[DS_MAX_KEYLEN]; char key_name[DS_MAX_KEYLEN];
char *source; char *source;
int flags = m_ptr->DS_FLAGS; int flags = m_ptr->m_ds_req.flags;
size_t length; size_t length;
int r; int r;
@ -296,7 +296,7 @@ int do_publish(message *m_ptr)
dsp = lookup_entry(key_name, flags & DSF_MASK_TYPE); dsp = lookup_entry(key_name, flags & DSF_MASK_TYPE);
/* If type is LABEL, also try to lookup the entry by num. */ /* If type is LABEL, also try to lookup the entry by num. */
if((flags & DSF_TYPE_LABEL) && (dsp == NULL)) if((flags & DSF_TYPE_LABEL) && (dsp == NULL))
dsp = lookup_label_entry(m_ptr->DS_VAL); dsp = lookup_label_entry(m_ptr->m_ds_req.val_in.ep);
if(dsp == NULL) { if(dsp == NULL) {
/* The entry doesn't exist, allocate a new data slot. */ /* The entry doesn't exist, allocate a new data slot. */
@ -314,12 +314,14 @@ int do_publish(message *m_ptr)
/* Store! */ /* Store! */
switch(flags & DSF_MASK_TYPE) { switch(flags & DSF_MASK_TYPE) {
case DSF_TYPE_U32: case DSF_TYPE_U32:
dsp->u.u32 = m_ptr->m_ds_req.val_in.u32;
break;
case DSF_TYPE_LABEL: case DSF_TYPE_LABEL:
dsp->u.u32 = m_ptr->DS_VAL; dsp->u.u32 = m_ptr->m_ds_req.val_in.ep;
break; break;
case DSF_TYPE_STR: case DSF_TYPE_STR:
case DSF_TYPE_MEM: case DSF_TYPE_MEM:
length = m_ptr->DS_VAL_LEN; length = m_ptr->m_ds_req.val_len;
/* Allocate a new data buffer if necessary. */ /* Allocate a new data buffer if necessary. */
if(!(dsp->flags & DSF_IN_USE)) { if(!(dsp->flags & DSF_IN_USE)) {
if((dsp->u.mem.data = malloc(length)) == NULL) if((dsp->u.mem.data = malloc(length)) == NULL)
@ -333,7 +335,7 @@ int do_publish(message *m_ptr)
} }
/* Copy the memory range. */ /* Copy the memory range. */
r = sys_safecopyfrom(m_ptr->m_source, (cp_grant_id_t) m_ptr->DS_VAL, r = sys_safecopyfrom(m_ptr->m_source, m_ptr->m_ds_req.val_in.grant,
0, (vir_bytes) dsp->u.mem.data, length); 0, (vir_bytes) dsp->u.mem.data, length);
if(r != OK) { if(r != OK) {
printf("DS: publish: memory map/copy failed from %d: %d\n", printf("DS: publish: memory map/copy failed from %d: %d\n",
@ -368,7 +370,7 @@ int do_retrieve(message *m_ptr)
{ {
struct data_store *dsp; struct data_store *dsp;
char key_name[DS_MAX_KEYLEN]; char key_name[DS_MAX_KEYLEN];
int flags = m_ptr->DS_FLAGS; int flags = m_ptr->m_ds_req.flags;
int type = flags & DSF_MASK_TYPE; int type = flags & DSF_MASK_TYPE;
size_t length; size_t length;
int r; int r;
@ -386,20 +388,22 @@ int do_retrieve(message *m_ptr)
/* Copy the requested data. */ /* Copy the requested data. */
switch(type) { switch(type) {
case DSF_TYPE_U32: case DSF_TYPE_U32:
m_ptr->m_ds_reply.val_out.u32 = dsp->u.u32;
break;
case DSF_TYPE_LABEL: case DSF_TYPE_LABEL:
m_ptr->DS_VAL = dsp->u.u32; m_ptr->m_ds_reply.val_out.ep = dsp->u.u32;
break; break;
case DSF_TYPE_STR: case DSF_TYPE_STR:
case DSF_TYPE_MEM: case DSF_TYPE_MEM:
length = MIN(m_ptr->DS_VAL_LEN, dsp->u.mem.length); length = MIN(m_ptr->m_ds_req.val_len, dsp->u.mem.length);
r = sys_safecopyto(m_ptr->m_source, (cp_grant_id_t) m_ptr->DS_VAL, 0, r = sys_safecopyto(m_ptr->m_source, m_ptr->m_ds_req.val_in.grant, 0,
(vir_bytes) dsp->u.mem.data, length); (vir_bytes) dsp->u.mem.data, length);
if(r != OK) { if(r != OK) {
printf("DS: retrieve: copy failed to %d: %d\n", printf("DS: retrieve: copy failed to %d: %d\n",
m_ptr->m_source, r); m_ptr->m_source, r);
return r; return r;
} }
m_ptr->DS_VAL_LEN = length; m_ptr->m_ds_reply.val_len = length;
break; break;
default: default:
return EINVAL; return EINVAL;
@ -417,12 +421,12 @@ int do_retrieve_label(const message *m_ptr)
int r; int r;
/* Lookup the label entry. */ /* Lookup the label entry. */
if((dsp = lookup_label_entry(m_ptr->DS_VAL)) == NULL) if((dsp = lookup_label_entry(m_ptr->m_ds_req.val_in.ep)) == NULL)
return ESRCH; return ESRCH;
/* Copy the key name. */ /* Copy the key name. */
r = sys_safecopyto(m_ptr->m_source, r = sys_safecopyto(m_ptr->m_source,
(cp_grant_id_t) m_ptr->DS_KEY_GRANT, (vir_bytes) 0, (cp_grant_id_t) m_ptr->m_ds_req.key_grant, (vir_bytes) 0,
(vir_bytes) dsp->key, strlen(dsp->key) + 1); (vir_bytes) dsp->key, strlen(dsp->key) + 1);
if(r != OK) { if(r != OK) {
printf("DS: copy failed from %d: %d\n", m_ptr->m_source, r); printf("DS: copy failed from %d: %d\n", m_ptr->m_source, r);
@ -454,7 +458,7 @@ int do_subscribe(message *m_ptr)
/* The subscription doesn't exist, allocate a new one. */ /* The subscription doesn't exist, allocate a new one. */
if((subp = alloc_sub_slot()) == NULL) if((subp = alloc_sub_slot()) == NULL)
return EAGAIN; return EAGAIN;
} else if(!(m_ptr->DS_FLAGS & DSF_OVERWRITE)) { } else if(!(m_ptr->m_ds_req.flags & DSF_OVERWRITE)) {
/* The subscription exists but we can't overwrite, return error. */ /* The subscription exists but we can't overwrite, return error. */
return EEXIST; return EEXIST;
} }
@ -476,7 +480,7 @@ int do_subscribe(message *m_ptr)
} }
/* If type_set = 0, then subscribe all types. */ /* If type_set = 0, then subscribe all types. */
type_set = m_ptr->DS_FLAGS & DSF_MASK_TYPE; type_set = m_ptr->m_ds_req.flags & DSF_MASK_TYPE;
if(type_set == 0) if(type_set == 0)
type_set = DSF_MASK_TYPE; type_set = DSF_MASK_TYPE;
@ -486,7 +490,7 @@ int do_subscribe(message *m_ptr)
subp->old_subs[b] = 0; subp->old_subs[b] = 0;
/* See if caller requested an instant initial list. */ /* See if caller requested an instant initial list. */
if(m_ptr->DS_FLAGS & DSF_INITIAL) { if(m_ptr->m_ds_req.flags & DSF_INITIAL) {
int i, match_found = FALSE; int i, match_found = FALSE;
for(i = 0; i < NR_DS_KEYS; i++) { for(i = 0; i < NR_DS_KEYS; i++) {
if(!(ds_store[i].flags & DSF_IN_USE)) if(!(ds_store[i].flags & DSF_IN_USE))
@ -537,7 +541,7 @@ int do_check(message *m_ptr)
/* Copy the key name. */ /* Copy the key name. */
r = sys_safecopyto(m_ptr->m_source, r = sys_safecopyto(m_ptr->m_source,
(cp_grant_id_t) m_ptr->DS_KEY_GRANT, (vir_bytes) 0, (cp_grant_id_t) m_ptr->m_ds_req.key_grant, (vir_bytes) 0,
(vir_bytes) ds_store[i].key, strlen(ds_store[i].key) + 1); (vir_bytes) ds_store[i].key, strlen(ds_store[i].key) + 1);
if(r != OK) { if(r != OK) {
printf("DS: check: copy failed from %d: %d\n", m_ptr->m_source, r); printf("DS: check: copy failed from %d: %d\n", m_ptr->m_source, r);
@ -546,8 +550,8 @@ int do_check(message *m_ptr)
/* Copy the type and the owner of the original entry. */ /* Copy the type and the owner of the original entry. */
entry_owner_e = ds_getprocep(ds_store[i].owner); entry_owner_e = ds_getprocep(ds_store[i].owner);
m_ptr->DS_FLAGS = ds_store[i].flags & DSF_MASK_TYPE; m_ptr->m_ds_req.flags = ds_store[i].flags & DSF_MASK_TYPE;
m_ptr->DS_OWNER = entry_owner_e; m_ptr->m_ds_req.owner = entry_owner_e;
/* Mark the entry as no longer updated for the subscriber. */ /* Mark the entry as no longer updated for the subscriber. */
UNSET_BIT(subp->old_subs, i); UNSET_BIT(subp->old_subs, i);
@ -564,7 +568,7 @@ int do_delete(message *m_ptr)
char key_name[DS_MAX_KEYLEN]; char key_name[DS_MAX_KEYLEN];
char *source; char *source;
char *label; char *label;
int type = m_ptr->DS_FLAGS & DSF_MASK_TYPE; int type = m_ptr->m_ds_req.flags & DSF_MASK_TYPE;
int i, r; int i, r;
/* Lookup the source. */ /* Lookup the source. */