]>
Commit | Line | Data |
---|---|---|
1 | /* Copyright (c) 2011, 2012 Nicira, Inc. | |
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 | ||
19 | #include "openvswitch/hmap.h" | |
20 | #include "openvswitch/list.h" | |
21 | #include "openvswitch/shash.h" | |
22 | ||
23 | struct ovsdb; | |
24 | struct ovsdb_server; | |
25 | ||
26 | /* Abstract representation of an OVSDB client connection, not tied to any | |
27 | * particular network protocol. Protocol implementations | |
28 | * (e.g. jsonrpc-server.c) embed this in a larger data structure. */ | |
29 | struct ovsdb_session { | |
30 | struct ovsdb_server *server; | |
31 | struct ovs_list completions;/* Completed triggers. */ | |
32 | struct hmap waiters; /* "ovsdb_lock_waiter *"s by lock name. */ | |
33 | }; | |
34 | ||
35 | void ovsdb_session_init(struct ovsdb_session *, struct ovsdb_server *); | |
36 | void ovsdb_session_destroy(struct ovsdb_session *); | |
37 | ||
38 | struct ovsdb_lock_waiter *ovsdb_session_get_lock_waiter( | |
39 | const struct ovsdb_session *, const char *lock_name); | |
40 | ||
41 | /* A database lock. | |
42 | * | |
43 | * A lock always has one or more "lock waiters" kept on a list. The waiter at | |
44 | * the head of the list owns the lock. */ | |
45 | struct ovsdb_lock { | |
46 | struct hmap_node hmap_node; /* In ovsdb_server's "locks" hmap. */ | |
47 | struct ovsdb_server *server; /* The containing server. */ | |
48 | char *name; /* Unique name. */ | |
49 | struct ovs_list waiters; /* Contains "struct ovsdb_lock_waiter"s. */ | |
50 | }; | |
51 | ||
52 | struct ovsdb_lock_waiter *ovsdb_lock_get_owner(const struct ovsdb_lock *); | |
53 | ||
54 | /* How to obtain a lock. */ | |
55 | enum ovsdb_lock_mode { | |
56 | OVSDB_LOCK_WAIT, /* By waiting for it to become available. */ | |
57 | OVSDB_LOCK_STEAL /* By stealing it from the owner. */ | |
58 | }; | |
59 | ||
60 | /* A session's request for a database lock. */ | |
61 | struct ovsdb_lock_waiter { | |
62 | struct hmap_node session_node; /* In ->session->locks's hmap. */ | |
63 | struct ovsdb_lock *lock; /* The lock being waited for. */ | |
64 | ||
65 | enum ovsdb_lock_mode mode; | |
66 | char *lock_name; | |
67 | ||
68 | struct ovsdb_session *session; | |
69 | struct ovs_list lock_node; /* In ->lock->waiters's list. */ | |
70 | }; | |
71 | ||
72 | struct ovsdb_session *ovsdb_lock_waiter_remove(struct ovsdb_lock_waiter *); | |
73 | void ovsdb_lock_waiter_destroy(struct ovsdb_lock_waiter *); | |
74 | bool ovsdb_lock_waiter_is_owner(const struct ovsdb_lock_waiter *); | |
75 | ||
76 | /* Abstract representation of an OVSDB server not tied to any particular | |
77 | * network protocol. Protocol implementations (e.g. jsonrpc-server.c) embed | |
78 | * this in a larger data structure. */ | |
79 | struct ovsdb_server { | |
80 | struct shash dbs; /* Maps from a db name to a "struct ovsdb *". */ | |
81 | struct hmap locks; /* Contains "struct ovsdb_lock"s indexed by name. */ | |
82 | }; | |
83 | ||
84 | void ovsdb_server_init(struct ovsdb_server *); | |
85 | bool ovsdb_server_add_db(struct ovsdb_server *, struct ovsdb *); | |
86 | bool ovsdb_server_remove_db(struct ovsdb_server *, struct ovsdb *); | |
87 | void ovsdb_server_destroy(struct ovsdb_server *); | |
88 | ||
89 | struct ovsdb_lock_waiter *ovsdb_server_lock(struct ovsdb_server *, | |
90 | struct ovsdb_session *, | |
91 | const char *lock_name, | |
92 | enum ovsdb_lock_mode, | |
93 | struct ovsdb_session **victimp); | |
94 | ||
95 | #endif /* ovsdb/server.h */ |