Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | typedef enum { |
| 26 | SVMDB_ACTION_ILLEGAL=0, |
| 27 | SVMDB_ACTION_GET, /* not clear why anyone would care */ |
| 28 | SVMDB_ACTION_SET, |
| 29 | SVMDB_ACTION_UNSET, |
| 30 | } svmdb_action_t; |
| 31 | |
| 32 | typedef struct { |
| 33 | int pid; |
| 34 | int signum; |
| 35 | u32 action:4; |
| 36 | u32 opaque:28; |
| 37 | } svmdb_notify_t; |
| 38 | |
| 39 | typedef struct { |
| 40 | u8 *value; |
| 41 | svmdb_notify_t *notifications; |
| 42 | u32 elsize; |
| 43 | } svmdb_value_t; |
| 44 | |
| 45 | typedef enum { |
| 46 | SVMDB_NAMESPACE_STRING=0, |
| 47 | SVMDB_NAMESPACE_VEC, |
| 48 | SVMDB_N_NAMESPACES, |
| 49 | } svmdb_namespace_t; |
| 50 | |
| 51 | typedef struct { |
| 52 | uword version; |
| 53 | /* pool of values */ |
| 54 | svmdb_value_t *values; |
| 55 | uword *namespaces [SVMDB_N_NAMESPACES]; |
| 56 | } svmdb_shm_hdr_t; |
| 57 | |
| 58 | #define SVMDB_SHM_VERSION 2 |
| 59 | |
| 60 | typedef struct { |
| 61 | int flags; |
| 62 | int pid; |
| 63 | svm_region_t *db_rp; |
| 64 | svmdb_shm_hdr_t *shm; |
| 65 | } svmdb_client_t; |
| 66 | |
| 67 | typedef struct { |
| 68 | int add_del; |
| 69 | svmdb_namespace_t nspace; |
| 70 | char *var; |
| 71 | u32 elsize; |
| 72 | int signum; |
| 73 | u32 action:4; |
| 74 | u32 opaque:28; |
| 75 | } svmdb_notification_args_t; |
| 76 | |
| 77 | /* |
| 78 | * Must be a reasonable number, several mb smaller than |
| 79 | * SVM_GLOBAL_REGION_SIZE, or no donut for you... |
| 80 | */ |
| 81 | #define SVMDB_DEFAULT_SIZE (4<<20) |
| 82 | |
| 83 | svmdb_client_t *svmdb_map (void); |
| 84 | |
| 85 | svmdb_client_t *svmdb_map_size (uword size); |
| 86 | |
| 87 | svmdb_client_t *svmdb_map_chroot (char *root_path); |
| 88 | |
| 89 | svmdb_client_t *svmdb_map_chroot_size (char *root_path, uword size); |
| 90 | |
| 91 | void svmdb_unmap (svmdb_client_t *client); |
| 92 | void svmdb_local_unset_string_variable (svmdb_client_t *client, char *var); |
| 93 | void svmdb_local_set_string_variable (svmdb_client_t *client, |
| 94 | char *var, char *val); |
| 95 | char *svmdb_local_get_string_variable (svmdb_client_t *client, char *var); |
| 96 | void *svmdb_local_get_variable_reference (svmdb_client_t *client, |
| 97 | svmdb_namespace_t ns, |
| 98 | char *var); |
| 99 | |
| 100 | void svmdb_local_dump_strings (svmdb_client_t *client); |
| 101 | |
| 102 | void svmdb_local_unset_vec_variable (svmdb_client_t *client, char *var); |
| 103 | void svmdb_local_set_vec_variable (svmdb_client_t *client, |
| 104 | char *var, void *val, u32 elsize); |
| 105 | void *svmdb_local_get_vec_variable (svmdb_client_t *client, char *var, |
| 106 | u32 elsize); |
| 107 | void svmdb_local_dump_vecs (svmdb_client_t *client); |
| 108 | |
| 109 | int svmdb_local_add_del_notification (svmdb_client_t *client, |
| 110 | svmdb_notification_args_t *args); |
| 111 | |
| 112 | void *svmdb_local_find_or_add_vec_variable (svmdb_client_t *client, |
| 113 | char *var, u32 nbytes); |
| 114 | |
| 115 | #endif /* __included_svmdb_h__ */ |