]>
Commit | Line | Data |
---|---|---|
e0edde6f | 1 | /* Copyright (c) 2011, 2012 Nicira, Inc. |
e317253b BP |
2 | * |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at: | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | #ifndef SERVER_H | |
17 | #define SERVER_H 1 | |
18 | ||
ee89ea7b | 19 | #include "openvswitch/hmap.h" |
b19bab5b | 20 | #include "openvswitch/list.h" |
ee89ea7b | 21 | #include "openvswitch/shash.h" |
64fada26 | 22 | #include "openvswitch/uuid.h" |
b4e8d170 BP |
23 | |
24 | struct ovsdb; | |
25 | struct ovsdb_server; | |
e317253b BP |
26 | |
27 | /* Abstract representation of an OVSDB client connection, not tied to any | |
28 | * particular network protocol. Protocol implementations | |
29 | * (e.g. jsonrpc-server.c) embed this in a larger data structure. */ | |
30 | struct ovsdb_session { | |
b4e8d170 | 31 | struct ovsdb_server *server; |
ca6ba700 | 32 | struct ovs_list completions;/* Completed triggers. */ |
da897f41 | 33 | struct hmap waiters; /* "ovsdb_lock_waiter *"s by lock name. */ |
e317253b BP |
34 | }; |
35 | ||
b4e8d170 | 36 | void ovsdb_session_init(struct ovsdb_session *, struct ovsdb_server *); |
e317253b BP |
37 | void ovsdb_session_destroy(struct ovsdb_session *); |
38 | ||
da897f41 BP |
39 | struct ovsdb_lock_waiter *ovsdb_session_get_lock_waiter( |
40 | const struct ovsdb_session *, const char *lock_name); | |
41 | ||
42 | /* A database lock. | |
43 | * | |
44 | * A lock always has one or more "lock waiters" kept on a list. The waiter at | |
45 | * the head of the list owns the lock. */ | |
46 | struct ovsdb_lock { | |
6e492d81 | 47 | struct hmap_node hmap_node; /* In ovsdb_server's "locks" hmap. */ |
da897f41 BP |
48 | struct ovsdb_server *server; /* The containing server. */ |
49 | char *name; /* Unique name. */ | |
ca6ba700 | 50 | struct ovs_list waiters; /* Contains "struct ovsdb_lock_waiter"s. */ |
da897f41 BP |
51 | }; |
52 | ||
53 | struct ovsdb_lock_waiter *ovsdb_lock_get_owner(const struct ovsdb_lock *); | |
54 | ||
55 | /* How to obtain a lock. */ | |
56 | enum ovsdb_lock_mode { | |
57 | OVSDB_LOCK_WAIT, /* By waiting for it to become available. */ | |
58 | OVSDB_LOCK_STEAL /* By stealing it from the owner. */ | |
59 | }; | |
60 | ||
61 | /* A session's request for a database lock. */ | |
62 | struct ovsdb_lock_waiter { | |
6e492d81 BP |
63 | struct hmap_node session_node; /* In ->session->locks's hmap. */ |
64 | struct ovsdb_lock *lock; /* The lock being waited for. */ | |
65 | ||
da897f41 BP |
66 | enum ovsdb_lock_mode mode; |
67 | char *lock_name; | |
68 | ||
da897f41 | 69 | struct ovsdb_session *session; |
ca6ba700 | 70 | struct ovs_list lock_node; /* In ->lock->waiters's list. */ |
da897f41 BP |
71 | }; |
72 | ||
73 | struct ovsdb_session *ovsdb_lock_waiter_remove(struct ovsdb_lock_waiter *); | |
74 | void ovsdb_lock_waiter_destroy(struct ovsdb_lock_waiter *); | |
75 | bool ovsdb_lock_waiter_is_owner(const struct ovsdb_lock_waiter *); | |
76 | ||
e317253b BP |
77 | /* Abstract representation of an OVSDB server not tied to any particular |
78 | * network protocol. Protocol implementations (e.g. jsonrpc-server.c) embed | |
79 | * this in a larger data structure. */ | |
80 | struct ovsdb_server { | |
b4e8d170 | 81 | struct shash dbs; /* Maps from a db name to a "struct ovsdb *". */ |
da897f41 | 82 | struct hmap locks; /* Contains "struct ovsdb_lock"s indexed by name. */ |
64fada26 AZ |
83 | struct uuid uuid; /* Server ID. Generated every time a server is |
84 | launched. */ | |
e317253b BP |
85 | }; |
86 | ||
b4e8d170 BP |
87 | void ovsdb_server_init(struct ovsdb_server *); |
88 | bool ovsdb_server_add_db(struct ovsdb_server *, struct ovsdb *); | |
0a3b723b | 89 | bool ovsdb_server_remove_db(struct ovsdb_server *, struct ovsdb *); |
e317253b BP |
90 | void ovsdb_server_destroy(struct ovsdb_server *); |
91 | ||
da897f41 BP |
92 | struct ovsdb_lock_waiter *ovsdb_server_lock(struct ovsdb_server *, |
93 | struct ovsdb_session *, | |
94 | const char *lock_name, | |
95 | enum ovsdb_lock_mode, | |
96 | struct ovsdb_session **victimp); | |
97 | ||
e317253b | 98 | #endif /* ovsdb/server.h */ |