blob: c5f59bbdd82900aa7c1999ddeea3c209f6d96b6a [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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
25typedef 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
32typedef struct {
33 int pid;
34 int signum;
35 u32 action:4;
36 u32 opaque:28;
37} svmdb_notify_t;
38
39typedef struct {
40 u8 *value;
41 svmdb_notify_t *notifications;
42 u32 elsize;
43} svmdb_value_t;
44
45typedef enum {
46 SVMDB_NAMESPACE_STRING=0,
47 SVMDB_NAMESPACE_VEC,
48 SVMDB_N_NAMESPACES,
49} svmdb_namespace_t;
50
51typedef 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
60typedef struct {
61 int flags;
62 int pid;
63 svm_region_t *db_rp;
64 svmdb_shm_hdr_t *shm;
65} svmdb_client_t;
66
67typedef 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
83svmdb_client_t *svmdb_map (void);
84
85svmdb_client_t *svmdb_map_size (uword size);
86
87svmdb_client_t *svmdb_map_chroot (char *root_path);
88
89svmdb_client_t *svmdb_map_chroot_size (char *root_path, uword size);
90
91void svmdb_unmap (svmdb_client_t *client);
92void svmdb_local_unset_string_variable (svmdb_client_t *client, char *var);
93void svmdb_local_set_string_variable (svmdb_client_t *client,
94 char *var, char *val);
95char *svmdb_local_get_string_variable (svmdb_client_t *client, char *var);
96void *svmdb_local_get_variable_reference (svmdb_client_t *client,
97 svmdb_namespace_t ns,
98 char *var);
99
100void svmdb_local_dump_strings (svmdb_client_t *client);
101
102void svmdb_local_unset_vec_variable (svmdb_client_t *client, char *var);
103void svmdb_local_set_vec_variable (svmdb_client_t *client,
104 char *var, void *val, u32 elsize);
105void *svmdb_local_get_vec_variable (svmdb_client_t *client, char *var,
106 u32 elsize);
107void svmdb_local_dump_vecs (svmdb_client_t *client);
108
109int svmdb_local_add_del_notification (svmdb_client_t *client,
110 svmdb_notification_args_t *args);
111
112void *svmdb_local_find_or_add_vec_variable (svmdb_client_t *client,
113 char *var, u32 nbytes);
114
115#endif /* __included_svmdb_h__ */