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
10 #if !defined(lint) && !defined(LOCORE) && defined(RCS_HDRS)
15 /* these are now appended by the error table compiler */
17 /* ubik error codes */
18 #define UMINCODE 100000 /* lowest ubik error code */
19 #define UNOQUORUM 100000 /* no quorum elected */
20 #define UNOTSYNC 100001 /* not synchronization site (should work on sync site) */
21 #define UNHOSTS 100002 /* too many hosts */
22 #define UIOERROR 100003 /* I/O error writing dbase or log */
23 #define UINTERNAL 100004 /* mysterious internal error */
24 #define USYNC 100005 /* major synchronization error */
25 #define UNOENT 100006 /* file not found when processing dbase */
26 #define UBADLOCK 100007 /* bad lock range size (must be 1) */
27 #define UBADLOG 100008 /* read error reprocessing log */
28 #define UBADHOST 100009 /* problems with host name */
29 #define UBADTYPE 100010 /* bad operation for this transaction type */
30 #define UTWOENDS 100011 /* two commits or aborts done to transaction */
31 #define UDONE 100012 /* operation done after abort (or commmit) */
32 #define UNOSERVERS 100013 /* no servers appear to be up */
33 #define UEOF 100014 /* premature EOF */
34 #define ULOGIO 100015 /* error writing log file */
35 #define UMAXCODE 100100 /* largest ubik error code */
40 #include "../afsint/ubik_int.h"
41 #else /* defined(UKERNEL) */
43 #endif /* defined(UKERNEL) */
45 /* ubik_trans types */
46 #define UBIK_READTRANS 0
47 #define UBIK_WRITETRANS 1
54 /* ubik client flags */
55 #define UPUBIKONLY 1 /* only check servers presumed functional */
57 /* RX services types */
58 #define VOTE_SERVICE_ID 50
59 #define DISK_SERVICE_ID 51
60 #define USER_SERVICE_ID 52 /* Since most applications use same port! */
62 #define UBIK_MAGIC 0x354545
64 /* global ubik parameters */
65 #define MAXSERVERS 20 /* max number of servers */
67 /* version comparison macro */
68 #define vcmp(a,b) ((a).epoch == (b).epoch? ((a).counter - (b).counter) : ((a).epoch - (b).epoch))
70 /* ubik_client state bits */
71 #define CFLastFailed 1 /* last call failed to this guy (to detect down hosts) */
73 #ifdef AFS_PTHREAD_ENV
78 /* per-client structure for ubik */
80 short initializationState; /* ubik client init state */
81 short states[MAXSERVERS]; /* state bits */
82 struct rx_connection *conns[MAXSERVERS];
84 #ifdef AFS_PTHREAD_ENV
89 #ifdef AFS_PTHREAD_ENV
90 #define LOCK_UBIK_CLIENT(client) assert(pthread_mutex_lock(&client->cm)==0);
91 #define UNLOCK_UBIK_CLIENT(client) assert(pthread_mutex_unlock(&client->cm)==0);
93 #define LOCK_UBIK_CLIENT(client)
94 #define UNLOCK_UBIK_CLIENT(client)
97 #define ubik_GetRPCConn(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->conns[aindex])
98 #define ubik_GetRPCHost(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->hosts[aindex])
100 /* ubik transaction id representation */
102 afs_int32 epoch; /* time this server started */
103 afs_int32 counter; /* counter within epoch of transactions */
106 /* ubik version representation */
107 struct ubik_version {
108 afs_int32 epoch; /* time this server started */
109 afs_int32 counter; /* counter within epoch of transactions */
112 /* ubik header file structure */
114 afs_int32 magic; /* magic number */
115 short pad1; /* some 0-initd padding */
116 short size; /* header allocation size */
117 struct ubik_version version; /* the version for this file */
120 /* representation of a ubik transaction */
122 struct ubik_dbase *dbase; /* corresponding database */
123 struct ubik_trans *next; /* in the list */
124 afs_int32 locktype; /* transaction lock */
125 struct ubik_trunc *activeTruncs;/* queued truncates */
126 struct ubik_tid tid; /* transaction id of this trans (if write trans.) */
127 afs_int32 minCommitTime; /* time before which this trans can't commit */
128 afs_int32 seekFile; /* seek ptr: file number */
129 afs_int32 seekPos; /* seek ptr: offset therein */
130 short flags; /* trans flag bits */
131 char type; /* type of trans */
132 iovec_wrt iovec_info;
133 iovec_buf iovec_data;
136 /* representation of a truncation operation */
138 struct ubik_trunc *next;
139 afs_int32 file; /* file to truncate */
140 afs_int32 length; /* new size */
149 #include "../afs/lock.h"
150 #else /* defined(UKERNEL) */
151 #include <lock.h> /* just to make sure we've go this */
152 #endif /* defined(UKERNEL) */
154 /* representation of a ubik database. Contains info on low-level disk access routines
155 for use by disk transaction module.
158 char *pathName; /* root name for dbase */
159 struct ubik_trans *activeTrans; /* active transaction list */
160 struct ubik_version version; /* version number */
162 struct afs_lock versionLock; /* lock on version number */
163 #else /* defined(UKERNEL) */
164 struct Lock versionLock; /* lock on version number */
165 #endif /* defined(UKERNEL) */
166 afs_int32 tidCounter; /* last RW or RO trans tid counter */
167 afs_int32 writeTidCounter; /* last write trans tid counter */
168 afs_int32 flags; /* flags */
169 int (*read)(); /* physio procedures */
175 int (*setlabel)(); /* set the version label */
176 int (*getlabel)(); /* retrieve the version label */
177 int (*getnfiles)(); /* find out number of files */
178 short readers; /* number of current read transactions */
179 struct ubik_version cachedVersion; /* version of caller's cached data */
182 /* procedures for automatically authenticating ubik connections */
183 extern int (*ubik_CRXSecurityProc)();
184 extern char *ubik_CRXSecurityRock;
185 extern int (*ubik_SRXSecurityProc)();
186 extern char *ubik_SRXSecurityRock;
187 extern int (*ubik_CheckRXSecurityProc)();
188 extern char *ubik_CheckRXSecurityRock;
190 /****************INTERNALS BELOW ****************/
192 #ifdef UBIK_INTERNALS
193 /* some ubik parameters */
197 #define PAGESIZE 1024 /* fits in current r packet */
198 #define LOGPAGESIZE 10 /* base 2 log thereof */
199 #define NBUFFERS 20 /* number of 1K buffers */
200 #define HDRSIZE 64 /* bytes of header per dbfile */
202 /* ubik_dbase flags */
203 #define DBWRITING 1 /* are any write trans. in progress */
205 /* ubik trans flags */
206 #define TRDONE 1 /* commit or abort done */
207 #define TRABORT 2 /* if TRDONE, tells if aborted */
208 #define TRREADANY 4 /* read any data available in trans */
210 /* ubik_lock flags */
213 /* ubik system database numbers */
216 /* define log opcodes */
217 #define LOGNEW 100 /* start transaction */
218 #define LOGEND 101 /* commit (good) end transaction */
219 #define LOGABORT 102 /* abort (fail) transaction */
220 #define LOGDATA 103 /* data */
221 #define LOGTRUNCATE 104 /* truncate operation */
223 /* time constant for replication algorithms: the R time period is 20 seconds. Both SMALLTIME
224 and BIGTIME must be larger than RPCTIMEOUT+max(RPCTIMEOUT,POLLTIME),
225 so that timeouts do not prevent us from getting through to our servers in time.
227 We use multi-R to time out multiple down hosts concurrently.
228 The only other restrictions: BIGTIME > SMALLTIME and
229 BIGTIME-SMALLTIME > MAXSKEW (the clock skew).
233 #define RPCTIMEOUT 20
237 /* the per-server state, used by the sync site to keep track of its charges */
239 struct ubik_server *next; /* next ptr */
240 afs_uint32 addr[UBIK_MAX_INTERFACE_ADDR];/* network order, addr[0] is primary*/
241 afs_int32 lastVoteTime; /* last time yes vote received */
242 afs_int32 lastBeaconSent; /* last time beacon attempted */
243 struct ubik_version version; /* version, only used during recovery */
244 struct rx_connection *vote_rxcid; /* cid to use to contact dude for votes */
245 struct rx_connection *disk_rxcid; /* cid to use to contact dude for disk reqs */
246 char lastVote; /* true if last vote was yes */
247 char up; /* is it up? */
248 char beaconSinceDown; /* did beacon get through since last crash? */
249 char currentDB; /* is dbase up-to-date */
250 char magic; /* the one whose vote counts twice */
251 char isClone; /* is only a clone, doesn't vote */
254 /* hold and release functions on a database */
255 #define DBHOLD(a) ObtainWriteLock(&((a)->versionLock))
256 #define DBRELE(a) ReleaseWriteLock(&((a)->versionLock))
260 /* list of all servers in the system */
261 extern struct ubik_server *ubik_servers;
262 extern char amIClone;
264 /* network port info */
265 extern short ubik_callPortal;
267 /* urecovery state bits for sync site */
268 #define UBIK_RECSYNCSITE 1 /* am sync site */
269 #define UBIK_RECFOUNDDB 2 /* found acceptable dbase from quorum */
270 #define UBIK_RECHAVEDB 4 /* fetched best dbase */
271 #define UBIK_RECLABELDB 8 /* relabelled dbase */
272 #define UBIK_RECSENTDB 0x10 /* sent best db to *everyone* */
273 #define UBIK_RECSBETTER UBIK_RECLABELDB /* last state */
275 extern afs_int32 ubik_quorum; /* min hosts in quorum */
276 extern struct ubik_dbase *ubik_dbase; /* the database handled by this server */
277 extern afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR];/* this host addr, in net order */
278 extern int ubik_amSyncSite; /* sleep on this waiting to be sync site */
279 extern struct ubik_stats { /* random stats */
282 extern afs_int32 ubik_epochTime; /* time when this site started */
283 extern afs_int32 urecovery_state; /* sync site recovery process state */
284 extern struct ubik_trans *ubik_currentTrans; /* current trans */
285 extern struct ubik_version ubik_dbVersion; /* sync site's dbase version */
286 extern afs_int32 ubik_debugFlag; /* ubik debug flag */
287 extern int ubikPrimaryAddrOnly; /* use only primary address */
289 /* this extern gives the sync site's db version, with epoch of 0 if none yet */
291 extern int uphys_read();
292 extern int uphys_write();
293 extern int uphys_truncate();
294 extern int uphys_sync();
297 extern int uphys_open();
299 extern int uphys_stat();
300 extern int uphys_getlabel();
301 extern int uphys_setlabel();
302 extern int uphys_getnfiles();
303 extern int ubeacon_Interact();
304 extern int urecovery_Interact();
305 extern int sdisk_Interact();
306 extern int uvote_Interact();
307 extern int DISK_Abort();
308 extern int DISK_Begin();
309 extern int DISK_ReleaseLocks();
310 extern int DISK_Commit();
311 extern int DISK_Lock();
312 extern int DISK_Write();
313 extern int DISK_WriteV();
314 extern int DISK_Truncate();
315 extern int DISK_SetVersion();
316 #endif /* UBIK_INTERNALS */
318 extern afs_int32 ubik_nBuffers;
321 * Public function prototypes
324 extern int ubik_ParseClientList(
330 extern unsigned int afs_random(
334 extern int ubik_ClientInit(
335 register struct rx_connection **serverconns,
336 struct ubik_client **aclient
339 extern afs_int32 ubik_ClientDestroy(
340 struct ubik_client *aclient