2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
13 /* these are now appended by the error table compiler */
15 /* ubik error codes */
16 #define UMINCODE 100000 /* lowest ubik error code */
17 #define UNOQUORUM 100000 /* no quorum elected */
18 #define UNOTSYNC 100001 /* not synchronization site (should work on sync site) */
19 #define UNHOSTS 100002 /* too many hosts */
20 #define UIOERROR 100003 /* I/O error writing dbase or log */
21 #define UINTERNAL 100004 /* mysterious internal error */
22 #define USYNC 100005 /* major synchronization error */
23 #define UNOENT 100006 /* file not found when processing dbase */
24 #define UBADLOCK 100007 /* bad lock range size (must be 1) */
25 #define UBADLOG 100008 /* read error reprocessing log */
26 #define UBADHOST 100009 /* problems with host name */
27 #define UBADTYPE 100010 /* bad operation for this transaction type */
28 #define UTWOENDS 100011 /* two commits or aborts done to transaction */
29 #define UDONE 100012 /* operation done after abort (or commmit) */
30 #define UNOSERVERS 100013 /* no servers appear to be up */
31 #define UEOF 100014 /* premature EOF */
32 #define ULOGIO 100015 /* error writing log file */
33 #define UMAXCODE 100100 /* largest ubik error code */
38 #include "../afsint/ubik_int.h"
39 #else /* defined(UKERNEL) */
41 #endif /* defined(UKERNEL) */
43 /* ubik_trans types */
44 #define UBIK_READTRANS 0
45 #define UBIK_WRITETRANS 1
52 /* ubik client flags */
53 #define UPUBIKONLY 1 /* only check servers presumed functional */
55 /* RX services types */
56 #define VOTE_SERVICE_ID 50
57 #define DISK_SERVICE_ID 51
58 #define USER_SERVICE_ID 52 /* Since most applications use same port! */
60 #define UBIK_MAGIC 0x354545
62 /* global ubik parameters */
63 #define MAXSERVERS 20 /* max number of servers */
65 /* version comparison macro */
66 #define vcmp(a,b) ((a).epoch == (b).epoch? ((a).counter - (b).counter) : ((a).epoch - (b).epoch))
68 /* ubik_client state bits */
69 #define CFLastFailed 1 /* last call failed to this guy (to detect down hosts) */
71 #ifdef AFS_PTHREAD_ENV
76 /* per-client structure for ubik */
78 short initializationState; /* ubik client init state */
79 short states[MAXSERVERS]; /* state bits */
80 struct rx_connection *conns[MAXSERVERS];
82 #ifdef AFS_PTHREAD_ENV
87 #ifdef AFS_PTHREAD_ENV
88 #define LOCK_UBIK_CLIENT(client) assert(pthread_mutex_lock(&client->cm)==0);
89 #define UNLOCK_UBIK_CLIENT(client) assert(pthread_mutex_unlock(&client->cm)==0);
91 #define LOCK_UBIK_CLIENT(client)
92 #define UNLOCK_UBIK_CLIENT(client)
95 #define ubik_GetRPCConn(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->conns[aindex])
96 #define ubik_GetRPCHost(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->hosts[aindex])
98 /* ubik transaction id representation */
100 afs_int32 epoch; /* time this server started */
101 afs_int32 counter; /* counter within epoch of transactions */
104 /* ubik version representation */
105 struct ubik_version {
106 afs_int32 epoch; /* time this server started */
107 afs_int32 counter; /* counter within epoch of transactions */
110 /* ubik header file structure */
112 afs_int32 magic; /* magic number */
113 short pad1; /* some 0-initd padding */
114 short size; /* header allocation size */
115 struct ubik_version version; /* the version for this file */
118 /* representation of a ubik transaction */
120 struct ubik_dbase *dbase; /* corresponding database */
121 struct ubik_trans *next; /* in the list */
122 afs_int32 locktype; /* transaction lock */
123 struct ubik_trunc *activeTruncs;/* queued truncates */
124 struct ubik_tid tid; /* transaction id of this trans (if write trans.) */
125 afs_int32 minCommitTime; /* time before which this trans can't commit */
126 afs_int32 seekFile; /* seek ptr: file number */
127 afs_int32 seekPos; /* seek ptr: offset therein */
128 short flags; /* trans flag bits */
129 char type; /* type of trans */
130 iovec_wrt iovec_info;
131 iovec_buf iovec_data;
134 /* representation of a truncation operation */
136 struct ubik_trunc *next;
137 afs_int32 file; /* file to truncate */
138 afs_int32 length; /* new size */
147 #include "../afs/lock.h"
148 #else /* defined(UKERNEL) */
149 #include <lock.h> /* just to make sure we've go this */
150 #endif /* defined(UKERNEL) */
152 /* representation of a ubik database. Contains info on low-level disk access routines
153 for use by disk transaction module.
156 char *pathName; /* root name for dbase */
157 struct ubik_trans *activeTrans; /* active transaction list */
158 struct ubik_version version; /* version number */
160 struct afs_lock versionLock; /* lock on version number */
161 #else /* defined(UKERNEL) */
162 struct Lock versionLock; /* lock on version number */
163 #endif /* defined(UKERNEL) */
164 afs_int32 tidCounter; /* last RW or RO trans tid counter */
165 afs_int32 writeTidCounter; /* last write trans tid counter */
166 afs_int32 flags; /* flags */
167 int (*read)(); /* physio procedures */
173 int (*setlabel)(); /* set the version label */
174 int (*getlabel)(); /* retrieve the version label */
175 int (*getnfiles)(); /* find out number of files */
176 short readers; /* number of current read transactions */
177 struct ubik_version cachedVersion; /* version of caller's cached data */
180 /* procedures for automatically authenticating ubik connections */
181 extern int (*ubik_CRXSecurityProc)();
182 extern char *ubik_CRXSecurityRock;
183 extern int (*ubik_SRXSecurityProc)();
184 extern char *ubik_SRXSecurityRock;
185 extern int (*ubik_CheckRXSecurityProc)();
186 extern char *ubik_CheckRXSecurityRock;
188 /****************INTERNALS BELOW ****************/
190 #ifdef UBIK_INTERNALS
191 /* some ubik parameters */
195 #define PAGESIZE 1024 /* fits in current r packet */
196 #define LOGPAGESIZE 10 /* base 2 log thereof */
197 #define NBUFFERS 20 /* number of 1K buffers */
198 #define HDRSIZE 64 /* bytes of header per dbfile */
200 /* ubik_dbase flags */
201 #define DBWRITING 1 /* are any write trans. in progress */
203 /* ubik trans flags */
204 #define TRDONE 1 /* commit or abort done */
205 #define TRABORT 2 /* if TRDONE, tells if aborted */
206 #define TRREADANY 4 /* read any data available in trans */
208 /* ubik_lock flags */
211 /* ubik system database numbers */
214 /* define log opcodes */
215 #define LOGNEW 100 /* start transaction */
216 #define LOGEND 101 /* commit (good) end transaction */
217 #define LOGABORT 102 /* abort (fail) transaction */
218 #define LOGDATA 103 /* data */
219 #define LOGTRUNCATE 104 /* truncate operation */
221 /* time constant for replication algorithms: the R time period is 20 seconds. Both SMALLTIME
222 and BIGTIME must be larger than RPCTIMEOUT+max(RPCTIMEOUT,POLLTIME),
223 so that timeouts do not prevent us from getting through to our servers in time.
225 We use multi-R to time out multiple down hosts concurrently.
226 The only other restrictions: BIGTIME > SMALLTIME and
227 BIGTIME-SMALLTIME > MAXSKEW (the clock skew).
231 #define RPCTIMEOUT 20
235 /* the per-server state, used by the sync site to keep track of its charges */
237 struct ubik_server *next; /* next ptr */
238 afs_uint32 addr[UBIK_MAX_INTERFACE_ADDR];/* network order, addr[0] is primary*/
239 afs_int32 lastVoteTime; /* last time yes vote received */
240 afs_int32 lastBeaconSent; /* last time beacon attempted */
241 struct ubik_version version; /* version, only used during recovery */
242 struct rx_connection *vote_rxcid; /* cid to use to contact dude for votes */
243 struct rx_connection *disk_rxcid; /* cid to use to contact dude for disk reqs */
244 char lastVote; /* true if last vote was yes */
245 char up; /* is it up? */
246 char beaconSinceDown; /* did beacon get through since last crash? */
247 char currentDB; /* is dbase up-to-date */
248 char magic; /* the one whose vote counts twice */
249 char isClone; /* is only a clone, doesn't vote */
252 /* hold and release functions on a database */
253 #define DBHOLD(a) ObtainWriteLock(&((a)->versionLock))
254 #define DBRELE(a) ReleaseWriteLock(&((a)->versionLock))
258 /* list of all servers in the system */
259 extern struct ubik_server *ubik_servers;
260 extern char amIClone;
262 /* network port info */
263 extern short ubik_callPortal;
265 /* urecovery state bits for sync site */
266 #define UBIK_RECSYNCSITE 1 /* am sync site */
267 #define UBIK_RECFOUNDDB 2 /* found acceptable dbase from quorum */
268 #define UBIK_RECHAVEDB 4 /* fetched best dbase */
269 #define UBIK_RECLABELDB 8 /* relabelled dbase */
270 #define UBIK_RECSENTDB 0x10 /* sent best db to *everyone* */
271 #define UBIK_RECSBETTER UBIK_RECLABELDB /* last state */
273 extern afs_int32 ubik_quorum; /* min hosts in quorum */
274 extern struct ubik_dbase *ubik_dbase; /* the database handled by this server */
275 extern afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR];/* this host addr, in net order */
276 extern int ubik_amSyncSite; /* sleep on this waiting to be sync site */
277 extern struct ubik_stats { /* random stats */
280 extern afs_int32 ubik_epochTime; /* time when this site started */
281 extern afs_int32 urecovery_state; /* sync site recovery process state */
282 extern struct ubik_trans *ubik_currentTrans; /* current trans */
283 extern struct ubik_version ubik_dbVersion; /* sync site's dbase version */
284 extern afs_int32 ubik_debugFlag; /* ubik debug flag */
285 extern int ubikPrimaryAddrOnly; /* use only primary address */
287 /* this extern gives the sync site's db version, with epoch of 0 if none yet */
289 extern int uphys_read();
290 extern int uphys_write();
291 extern int uphys_truncate();
292 extern int uphys_sync();
295 extern int uphys_open();
297 extern int uphys_stat();
298 extern int uphys_getlabel();
299 extern int uphys_setlabel();
300 extern int uphys_getnfiles();
301 extern int ubeacon_Interact();
302 extern int urecovery_Interact();
303 extern int sdisk_Interact();
304 extern int uvote_Interact();
305 extern int DISK_Abort();
306 extern int DISK_Begin();
307 extern int DISK_ReleaseLocks();
308 extern int DISK_Commit();
309 extern int DISK_Lock();
310 extern int DISK_Write();
311 extern int DISK_WriteV();
312 extern int DISK_Truncate();
313 extern int DISK_SetVersion();
314 #endif /* UBIK_INTERNALS */
316 extern afs_int32 ubik_nBuffers;
319 * Public function prototypes
322 extern int ubik_ParseClientList(
328 extern unsigned int afs_random(
332 extern int ubik_ClientInit(
333 register struct rx_connection **serverconns,
334 struct ubik_client **aclient
337 extern afs_int32 ubik_ClientDestroy(
338 struct ubik_client *aclient