Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 1 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2 | *------------------------------------------------------------------ |
| 3 | * svmdb.h - shared VM database |
| 4 | * |
| 5 | * Copyright (c) 2009 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #ifndef __included_svmdb_h__ |
| 21 | #define __included_svmdb_h__ |
| 22 | |
| 23 | #include "svm.h" |
| 24 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 25 | typedef enum |
| 26 | { |
| 27 | SVMDB_ACTION_ILLEGAL = 0, |
| 28 | SVMDB_ACTION_GET, /* not clear why anyone would care */ |
| 29 | SVMDB_ACTION_SET, |
| 30 | SVMDB_ACTION_UNSET, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | } svmdb_action_t; |
| 32 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 33 | typedef struct |
| 34 | { |
| 35 | int pid; |
| 36 | int signum; |
| 37 | u32 action:4; |
| 38 | u32 opaque:28; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | } svmdb_notify_t; |
| 40 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 41 | typedef struct |
| 42 | { |
| 43 | u8 *value; |
| 44 | svmdb_notify_t *notifications; |
| 45 | u32 elsize; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | } svmdb_value_t; |
| 47 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 48 | typedef enum |
| 49 | { |
| 50 | SVMDB_NAMESPACE_STRING = 0, |
| 51 | SVMDB_NAMESPACE_VEC, |
| 52 | SVMDB_N_NAMESPACES, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | } svmdb_namespace_t; |
| 54 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 55 | typedef struct |
| 56 | { |
| 57 | uword version; |
| 58 | /* pool of values */ |
| 59 | svmdb_value_t *values; |
| 60 | uword *namespaces[SVMDB_N_NAMESPACES]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | } svmdb_shm_hdr_t; |
| 62 | |
| 63 | #define SVMDB_SHM_VERSION 2 |
| 64 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 65 | typedef struct |
| 66 | { |
| 67 | int flags; |
| 68 | int pid; |
| 69 | svm_region_t *db_rp; |
| 70 | svmdb_shm_hdr_t *shm; |
| 71 | } svmdb_client_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 73 | typedef struct |
| 74 | { |
| 75 | int add_del; |
| 76 | svmdb_namespace_t nspace; |
| 77 | char *var; |
| 78 | u32 elsize; |
| 79 | int signum; |
| 80 | u32 action:4; |
| 81 | u32 opaque:28; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | } svmdb_notification_args_t; |
| 83 | |
Dave Barach | 98cfc1a | 2016-07-18 14:23:36 -0400 | [diff] [blame] | 84 | typedef struct |
| 85 | { |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 86 | const char *root_path; |
Dave Barach | 98cfc1a | 2016-07-18 14:23:36 -0400 | [diff] [blame] | 87 | uword size; |
| 88 | u32 uid; |
| 89 | u32 gid; |
| 90 | } svmdb_map_args_t; |
| 91 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 92 | /* |
| 93 | * Must be a reasonable number, several mb smaller than |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | * SVM_GLOBAL_REGION_SIZE, or no donut for you... |
| 95 | */ |
| 96 | #define SVMDB_DEFAULT_SIZE (4<<20) |
| 97 | |
Dave Barach | 98cfc1a | 2016-07-18 14:23:36 -0400 | [diff] [blame] | 98 | svmdb_client_t *svmdb_map (svmdb_map_args_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 100 | void svmdb_unmap (svmdb_client_t * client); |
| 101 | void svmdb_local_unset_string_variable (svmdb_client_t * client, char *var); |
| 102 | void svmdb_local_set_string_variable (svmdb_client_t * client, |
| 103 | char *var, char *val); |
| 104 | char *svmdb_local_get_string_variable (svmdb_client_t * client, char *var); |
| 105 | void *svmdb_local_get_variable_reference (svmdb_client_t * client, |
| 106 | svmdb_namespace_t ns, char *var); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 108 | void svmdb_local_dump_strings (svmdb_client_t * client); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 110 | void svmdb_local_unset_vec_variable (svmdb_client_t * client, char *var); |
| 111 | void svmdb_local_set_vec_variable (svmdb_client_t * client, |
| 112 | char *var, void *val, u32 elsize); |
| 113 | void *svmdb_local_get_vec_variable (svmdb_client_t * client, char *var, |
| 114 | u32 elsize); |
| 115 | void svmdb_local_dump_vecs (svmdb_client_t * client); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 117 | int svmdb_local_add_del_notification (svmdb_client_t * client, |
| 118 | svmdb_notification_args_t * args); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 120 | void *svmdb_local_find_or_add_vec_variable (svmdb_client_t * client, |
| 121 | char *var, u32 nbytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | |
Dave Barach | 23a7412 | 2016-11-24 16:34:20 -0500 | [diff] [blame] | 123 | int svmdb_local_serialize_strings (svmdb_client_t * client, char *filename); |
| 124 | int svmdb_local_unserialize_strings (svmdb_client_t * client, char *filename); |
| 125 | |
| 126 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | #endif /* __included_svmdb_h__ */ |
Dave Barach | 8a7fb0c | 2016-07-08 14:44:23 -0400 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * fd.io coding-style-patch-verification: ON |
| 131 | * |
| 132 | * Local Variables: |
| 133 | * eval: (c-set-style "gnu") |
| 134 | * End: |
| 135 | */ |