From 5d0e31dbb3512c463a6e519a7b964522fba3d14f Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Sat, 26 Jul 2014 13:54:02 +0200 Subject: [PATCH] custom message req & reply types for ds --- include/minix/com.h | 10 --------- include/minix/ipc.h | 24 ++++++++++++++++++++++ lib/libsys/ds.c | 50 ++++++++++++++++++++++----------------------- servers/ds/store.c | 50 ++++++++++++++++++++++++--------------------- 4 files changed, 76 insertions(+), 58 deletions(-) diff --git a/include/minix/com.h b/include/minix/com.h index 32e4d9df0..98eba5556 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -502,16 +502,6 @@ #define DS_RETRIEVE_LABEL (DS_RQ_BASE + 6) /* retrieve label's name */ #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 * *===========================================================================*/ diff --git a/include/minix/ipc.h b/include/minix/ipc.h index 97e6bfeae..a5c2151f7 100644 --- a/include/minix/ipc.h +++ b/include/minix/ipc.h @@ -1907,6 +1907,28 @@ typedef struct { } 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 { endpoint_t m_source; /* who sent the message */ int m_type; /* what kind of message is it */ @@ -2150,6 +2172,8 @@ typedef struct { mess_rs_init m_rs_init; mess_rs_update m_rs_update; 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_openclose m_vfs_lchardriver_openclose; diff --git a/lib/libsys/ds.c b/lib/libsys/ds.c index 38d914e88..7f665e9b0 100644 --- a/lib/libsys/ds.c +++ b/lib/libsys/ds.c @@ -24,8 +24,8 @@ static int do_invoke_ds(message *m, int type, const char *ds_name) if(!GRANT_VALID(g_key)) return ENOMEM; - m->DS_KEY_GRANT = g_key; - m->DS_KEY_LEN = len_key; + m->m_ds_req.key_grant = g_key; + m->m_ds_req.key_len = len_key; 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; memset(&m, 0, sizeof(m)); - m.DS_VAL = (u32_t) endpoint; - m.DS_FLAGS = DSF_TYPE_LABEL | flags; + m.m_ds_req.val_in.ep = endpoint; + m.m_ds_req.flags = DSF_TYPE_LABEL | flags; 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; memset(&m, 0, sizeof(m)); - m.DS_VAL = value; - m.DS_FLAGS = DSF_TYPE_U32 | flags; + m.m_ds_req.val_in.u32 = value; + m.m_ds_req.flags = DSF_TYPE_U32 | flags; 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; memset(&m, 0, sizeof(m)); - m.DS_VAL = gid; - m.DS_VAL_LEN = length; - m.DS_FLAGS = flags; + m.m_ds_req.val_in.grant = gid; + m.m_ds_req.val_len = length; + m.m_ds_req.flags = flags; r = do_invoke_ds(&m, DS_PUBLISH, ds_name); cpf_revoke(gid); @@ -95,7 +95,7 @@ int ds_retrieve_label_name(char *ds_name, endpoint_t endpoint) int r; 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); return r; } @@ -106,9 +106,9 @@ int ds_retrieve_label_endpt(const char *ds_name, endpoint_t *endpoint) int r; 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); - *endpoint = (endpoint_t) m.DS_VAL; + *endpoint = m.m_ds_reply.val_out.ep; return r; } @@ -118,9 +118,9 @@ int ds_retrieve_u32(const char *ds_name, u32_t *value) int r; 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); - *value = m.DS_VAL; + *value = m.m_ds_reply.val_out.u32; return r; } @@ -137,11 +137,11 @@ static int ds_retrieve_raw(const char *ds_name, char *vaddr, size_t *length, return ENOMEM; memset(&m, 0, sizeof(m)); - m.DS_VAL = gid; - m.DS_VAL_LEN = *length; - m.DS_FLAGS = flags; + m.m_ds_req.val_in.grant = gid; + m.m_ds_req.val_len = *length; + m.m_ds_req.flags = flags; r = do_invoke_ds(&m, DS_RETRIEVE, ds_name); - *length = m.DS_VAL_LEN; + *length = m.m_ds_reply.val_len; cpf_revoke(gid); return r; @@ -166,7 +166,7 @@ int ds_delete_u32(const char *ds_name) message 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); } @@ -175,7 +175,7 @@ int ds_delete_str(const char *ds_name) message 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); } @@ -184,7 +184,7 @@ int ds_delete_mem(const char *ds_name) message 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); } @@ -193,7 +193,7 @@ int ds_delete_label(const char *ds_name) message 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); } @@ -202,7 +202,7 @@ int ds_subscribe(const char *regexp, int flags) message m; memset(&m, 0, sizeof(m)); - m.DS_FLAGS = flags; + m.m_ds_req.flags = flags; 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)); r = do_invoke_ds(&m, DS_CHECK, ds_key); - if(type) *type = m.DS_FLAGS; - if(owner_e) *owner_e = m.DS_OWNER; + if(type) *type = m.m_ds_req.flags; + if(owner_e) *owner_e = m.m_ds_req.owner; return r; } diff --git a/servers/ds/store.c b/servers/ds/store.c index 3e1309e52..e6fb5e10c 100644 --- a/servers/ds/store.c +++ b/servers/ds/store.c @@ -146,16 +146,16 @@ static int get_key_name(const message *m_ptr, char *key_name) /* Get key name given an input message. */ int r; - if (m_ptr->DS_KEY_LEN > DS_MAX_KEYLEN || m_ptr->DS_KEY_LEN < 2) { - printf("DS: bogus key length (%d) from %d\n", m_ptr->DS_KEY_LEN, + 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->m_ds_req.key_len, m_ptr->m_source); return EINVAL; } /* Copy name from caller. */ r = sys_safecopyfrom(m_ptr->m_source, - (cp_grant_id_t) m_ptr->DS_KEY_GRANT, 0, - (vir_bytes) key_name, m_ptr->DS_KEY_LEN); + (cp_grant_id_t) m_ptr->m_ds_req.key_grant, 0, + (vir_bytes) key_name, m_ptr->m_ds_req.key_len); if(r != OK) { printf("DS: publish: copy failed from %d: %d\n", m_ptr->m_source, r); return r; @@ -275,7 +275,7 @@ int do_publish(message *m_ptr) struct data_store *dsp; char key_name[DS_MAX_KEYLEN]; char *source; - int flags = m_ptr->DS_FLAGS; + int flags = m_ptr->m_ds_req.flags; size_t length; int r; @@ -296,7 +296,7 @@ int do_publish(message *m_ptr) dsp = lookup_entry(key_name, flags & DSF_MASK_TYPE); /* If type is LABEL, also try to lookup the entry by num. */ 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) { /* The entry doesn't exist, allocate a new data slot. */ @@ -314,12 +314,14 @@ int do_publish(message *m_ptr) /* Store! */ switch(flags & DSF_MASK_TYPE) { case DSF_TYPE_U32: + dsp->u.u32 = m_ptr->m_ds_req.val_in.u32; + break; case DSF_TYPE_LABEL: - dsp->u.u32 = m_ptr->DS_VAL; + dsp->u.u32 = m_ptr->m_ds_req.val_in.ep; break; case DSF_TYPE_STR: 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. */ if(!(dsp->flags & DSF_IN_USE)) { if((dsp->u.mem.data = malloc(length)) == NULL) @@ -333,7 +335,7 @@ int do_publish(message *m_ptr) } /* 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); if(r != OK) { 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; 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; size_t length; int r; @@ -386,20 +388,22 @@ int do_retrieve(message *m_ptr) /* Copy the requested data. */ switch(type) { case DSF_TYPE_U32: + m_ptr->m_ds_reply.val_out.u32 = dsp->u.u32; + break; case DSF_TYPE_LABEL: - m_ptr->DS_VAL = dsp->u.u32; + m_ptr->m_ds_reply.val_out.ep = dsp->u.u32; break; case DSF_TYPE_STR: case DSF_TYPE_MEM: - length = MIN(m_ptr->DS_VAL_LEN, dsp->u.mem.length); - r = sys_safecopyto(m_ptr->m_source, (cp_grant_id_t) m_ptr->DS_VAL, 0, + length = MIN(m_ptr->m_ds_req.val_len, dsp->u.mem.length); + r = sys_safecopyto(m_ptr->m_source, m_ptr->m_ds_req.val_in.grant, 0, (vir_bytes) dsp->u.mem.data, length); if(r != OK) { printf("DS: retrieve: copy failed to %d: %d\n", m_ptr->m_source, r); return r; } - m_ptr->DS_VAL_LEN = length; + m_ptr->m_ds_reply.val_len = length; break; default: return EINVAL; @@ -417,12 +421,12 @@ int do_retrieve_label(const message *m_ptr) int r; /* 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; /* Copy the key name. */ 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); if(r != OK) { 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. */ if((subp = alloc_sub_slot()) == NULL) 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. */ return EEXIST; } @@ -476,7 +480,7 @@ int do_subscribe(message *m_ptr) } /* 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) type_set = DSF_MASK_TYPE; @@ -486,7 +490,7 @@ int do_subscribe(message *m_ptr) subp->old_subs[b] = 0; /* 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; for(i = 0; i < NR_DS_KEYS; i++) { if(!(ds_store[i].flags & DSF_IN_USE)) @@ -537,7 +541,7 @@ int do_check(message *m_ptr) /* Copy the key name. */ 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); if(r != OK) { 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. */ entry_owner_e = ds_getprocep(ds_store[i].owner); - m_ptr->DS_FLAGS = ds_store[i].flags & DSF_MASK_TYPE; - m_ptr->DS_OWNER = entry_owner_e; + m_ptr->m_ds_req.flags = ds_store[i].flags & DSF_MASK_TYPE; + m_ptr->m_ds_req.owner = entry_owner_e; /* Mark the entry as no longer updated for the subscriber. */ UNSET_BIT(subp->old_subs, i); @@ -564,7 +568,7 @@ int do_delete(message *m_ptr) char key_name[DS_MAX_KEYLEN]; char *source; 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; /* Lookup the source. */ -- 2.44.0