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 */
39 #else /* defined(UKERNEL) */
41 #endif /* defined(UKERNEL) */
43 /*! \name ubik_trans types */
44 #define UBIK_READTRANS 0
45 #define UBIK_WRITETRANS 1
48 /*! \name ubik_lock types */
51 #if !defined(UBIK_PAUSE)
53 #endif /* UBIK_PAUSE */
56 /*! \name ubik client flags */
57 #define UPUBIKONLY 1 /*!< only check servers presumed functional */
60 /*! \name RX services types */
61 #define VOTE_SERVICE_ID 50
62 #define DISK_SERVICE_ID 51
63 #define USER_SERVICE_ID 52 /*!< Since most applications use same port! */
66 #define UBIK_MAGIC 0x354545
68 /*! \name global ubik parameters */
69 #define MAXSERVERS 20 /*!< max number of servers */
72 /*! version comparison macro */
73 #define vcmp(a,b) ((a).epoch == (b).epoch? ((a).counter - (b).counter) : ((a).epoch - (b).epoch))
75 /*! \name ubik_client state bits */
76 #define CFLastFailed 1 /*!< last call failed to this guy (to detect down hosts) */
79 #ifdef AFS_PTHREAD_ENV
87 * \brief per-client structure for ubik
90 short initializationState; /*!< ubik client init state */
91 short states[MAXSERVERS]; /*!< state bits */
92 struct rx_connection *conns[MAXSERVERS];
94 #ifdef AFS_PTHREAD_ENV
99 #ifdef AFS_PTHREAD_ENV
100 #define LOCK_UBIK_CLIENT(client) assert(pthread_mutex_lock(&client->cm)==0)
101 #define UNLOCK_UBIK_CLIENT(client) assert(pthread_mutex_unlock(&client->cm)==0)
103 #define LOCK_UBIK_CLIENT(client)
104 #define UNLOCK_UBIK_CLIENT(client)
107 #define ubik_GetRPCConn(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->conns[aindex])
108 #define ubik_GetRPCHost(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->hosts[aindex])
111 * \brief 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 */
121 * \brief representation of a ubik transaction
124 struct ubik_dbase *dbase; /*!< corresponding database */
125 struct ubik_trans *next; /*!< in the list */
126 afs_int32 locktype; /*!< transaction lock */
127 struct ubik_trunc *activeTruncs; /*!< queued truncates */
128 struct ubik_tid tid; /*!< transaction id of this trans (if write trans.) */
129 afs_int32 minCommitTime; /*!< time before which this trans can't commit */
130 afs_int32 seekFile; /*!< seek ptr: file number */
131 afs_int32 seekPos; /*!< seek ptr: offset therein */
132 short flags; /*!< trans flag bits */
133 char type; /*!< type of trans */
134 iovec_wrt iovec_info;
135 iovec_buf iovec_data;
139 * \brief representation of a truncation operation
142 struct ubik_trunc *next;
143 afs_int32 file; /*!< file to truncate */
144 afs_int32 length; /*!< new size */
153 #include "afs/lock.h"
154 #else /* defined(UKERNEL) */
155 #include <lock.h> /* just to make sure we've got this */
156 #endif /* defined(UKERNEL) */
159 * \brief representation of a ubik database.
161 * Contains info on low-level disk access routines
162 * for use by disk transaction module.
165 char *pathName; /*!< root name for dbase */
166 struct ubik_trans *activeTrans; /*!< active transaction list */
167 struct ubik_version version; /*!< version number */
169 struct afs_lock versionLock; /*!< lock on version number */
170 #else /* defined(UKERNEL) */
171 struct Lock versionLock; /*!< lock on version number */
172 #endif /* defined(UKERNEL) */
173 afs_int32 tidCounter; /*!< last RW or RO trans tid counter */
174 afs_int32 writeTidCounter; /*!< last write trans tid counter */
175 afs_int32 flags; /*!< flags */
176 /* physio procedures */
177 int (*read) (struct ubik_dbase * adbase, afs_int32 afile, char *abuffer,
178 afs_int32 apos, afs_int32 alength);
179 int (*write) (struct ubik_dbase * adbase, afs_int32 afile, char *abuffer,
180 afs_int32 apos, afs_int32 alength);
181 int (*truncate) (struct ubik_dbase * adbase, afs_int32 afile,
183 int (*sync) (struct ubik_dbase * adbase, afs_int32 afile);
184 int (*stat) (struct ubik_dbase * adbase, afs_int32 afid,
185 struct ubik_stat * astat);
186 int (*open) (struct ubik_dbase * adbase, afs_int32 afid);
187 int (*setlabel) (struct ubik_dbase * adbase, afs_int32 afile, struct ubik_version * aversion); /*!< set the version label */
188 int (*getlabel) (struct ubik_dbase * adbase, afs_int32 afile, struct ubik_version * aversion); /*!< retrieve the version label */
189 int (*getnfiles) (struct ubik_dbase * adbase); /*!< find out number of files */
190 short readers; /*!< number of current read transactions */
191 struct ubik_version cachedVersion; /*!< version of caller's cached data */
192 #ifdef AFS_PTHREAD_ENV
193 pthread_cond_t version_cond; /*!< condition variable to manage changes to version */
194 pthread_cond_t flags_cond; /*!< condition variable to manage changes to flags */
195 pthread_mutex_t version_mutex;
196 pthread_mutex_t flags_mutex;
200 /*! \name procedures for automatically authenticating ubik connections */
201 extern int (*ubik_CRXSecurityProc) ();
202 extern char *ubik_CRXSecurityRock;
203 extern int (*ubik_SRXSecurityProc) ();
204 extern char *ubik_SRXSecurityRock;
205 extern int (*ubik_CheckRXSecurityProc) ();
206 extern char *ubik_CheckRXSecurityRock;
209 /****************INTERNALS BELOW ****************/
211 #ifdef UBIK_INTERNALS
212 /*! \name some ubik parameters */
213 #define UBIK_PAGESIZE 1024 /*!< fits in current r packet */
214 #define UBIK_LOGPAGESIZE 10 /*!< base 2 log thereof */
215 #define NBUFFERS 20 /*!< number of 1K buffers */
216 #define HDRSIZE 64 /*!< bytes of header per dbfile */
219 /*! \name ubik_dbase flags */
220 #define DBWRITING 1 /*!< are any write trans. in progress */
221 #if defined(UBIK_PAUSE)
222 #define DBVOTING 2 /*!< the beacon task is polling */
223 #endif /* UBIK_PAUSE */
226 /*!\name ubik trans flags */
227 #define TRDONE 1 /*!< commit or abort done */
228 #define TRABORT 2 /*!< if #TRDONE, tells if aborted */
229 #define TRREADANY 4 /*!< read any data available in trans */
230 #if defined(UBIK_PAUSE)
231 #define TRSETLOCK 8 /*!< SetLock is using trans */
232 #define TRSTALE 16 /*!< udisk_end during getLock */
233 #endif /* UBIK_PAUSE */
236 /*! \name ubik_lock flags */
240 /*! \name ubik system database numbers */
244 /*! \name define log opcodes */
245 #define LOGNEW 100 /*!< start transaction */
246 #define LOGEND 101 /*!< commit (good) end transaction */
247 #define LOGABORT 102 /*!< abort (fail) transaction */
248 #define LOGDATA 103 /*!< data */
249 #define LOGTRUNCATE 104 /*!< truncate operation */
253 * \name timer constants
254 * time constant for replication algorithms: the R time period is 20 seconds. Both
255 * #SMALLTIME and #BIGTIME must be larger than #RPCTIMEOUT+max(#RPCTIMEOUT, #POLLTIME),
256 * so that timeouts do not prevent us from getting through to our servers in time.
258 * We use multi-R to time out multiple down hosts concurrently.
259 * The only other restrictions: #BIGTIME > #SMALLTIME and
260 * #BIGTIME-#SMALLTIME > #MAXSKEW (the clock skew).
264 #define RPCTIMEOUT 20
270 * \brief the per-server state, used by the sync site to keep track of its charges
273 struct ubik_server *next; /*!< next ptr */
274 afs_uint32 addr[UBIK_MAX_INTERFACE_ADDR]; /*!< network order, addr[0] is primary */
275 afs_int32 lastVoteTime; /*!< last time yes vote received */
276 afs_int32 lastBeaconSent; /*!< last time beacon attempted */
277 struct ubik_version version; /*!< version, only used during recovery */
278 struct rx_connection *vote_rxcid; /*!< cid to use to contact dude for votes */
279 struct rx_connection *disk_rxcid; /*!< cid to use to contact dude for disk reqs */
280 char lastVote; /*!< true if last vote was yes */
281 char up; /*!< is it up? */
282 char beaconSinceDown; /*!< did beacon get through since last crash? */
283 char currentDB; /*!< is dbase up-to-date */
284 char magic; /*!< the one whose vote counts twice */
285 char isClone; /*!< is only a clone, doesn't vote */
288 /*! \name hold and release functions on a database */
289 #define DBHOLD(a) ObtainWriteLock(&((a)->versionLock))
290 #define DBRELE(a) ReleaseWriteLock(&((a)->versionLock))
295 /*!name list of all servers in the system */
296 extern struct ubik_server *ubik_servers;
297 extern char amIClone;
300 /*! \name network port info */
301 extern short ubik_callPortal;
304 /*! \name urecovery state bits for sync site */
305 #define UBIK_RECSYNCSITE 1 /* am sync site */
306 #define UBIK_RECFOUNDDB 2 /* found acceptable dbase from quorum */
307 #define UBIK_RECHAVEDB 4 /* fetched best dbase */
308 #define UBIK_RECLABELDB 8 /* relabelled dbase */
309 #define UBIK_RECSENTDB 0x10 /* sent best db to *everyone* */
310 #define UBIK_RECSBETTER UBIK_RECLABELDB /* last state */
313 extern afs_int32 ubik_quorum; /* min hosts in quorum */
314 extern struct ubik_dbase *ubik_dbase; /* the database handled by this server */
315 extern afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR]; /* this host addr, in net order */
316 extern int ubik_amSyncSite; /* sleep on this waiting to be sync site */
317 extern struct ubik_stats { /* random stats */
320 extern afs_int32 ubik_epochTime; /* time when this site started */
321 extern afs_int32 urecovery_state; /* sync site recovery process state */
322 extern struct ubik_trans *ubik_currentTrans; /* current trans */
323 extern struct ubik_version ubik_dbVersion; /* sync site's dbase version */
324 extern afs_int32 ubik_debugFlag; /* ubik debug flag */
325 extern int ubikPrimaryAddrOnly; /* use only primary address */
327 /* this extern gives the sync site's db version, with epoch of 0 if none yet */
330 extern int uphys_close(register int afd);
331 extern int uphys_stat(struct ubik_dbase *adbase, afs_int32 afid,
332 struct ubik_stat *astat);
333 extern int uphys_read(register struct ubik_dbase *adbase, afs_int32 afile,
334 register char *abuffer, afs_int32 apos,
336 extern int uphys_write(register struct ubik_dbase *adbase, afs_int32 afile,
337 register char *abuffer, afs_int32 apos,
339 extern int uphys_truncate(register struct ubik_dbase *adbase, afs_int32 afile,
341 extern int uphys_getnfiles(register struct ubik_dbase *adbase);
342 extern int uphys_getlabel(register struct ubik_dbase *adbase, afs_int32 afile,
343 struct ubik_version *aversion);
344 extern int uphys_setlabel(register struct ubik_dbase *adbase, afs_int32 afile,
345 struct ubik_version *aversion);
346 extern int uphys_sync(register struct ubik_dbase *adbase, afs_int32 afile);
347 extern void uphys_invalidate(register struct ubik_dbase *adbase,
350 /*! \name recovery.c */
351 extern int urecovery_ResetState(void);
352 extern int urecovery_LostServer(void);
353 extern int urecovery_AllBetter(register struct ubik_dbase *adbase,
355 extern int urecovery_AbortAll(struct ubik_dbase *adbase);
356 extern int urecovery_CheckTid(register struct ubik_tid *atid);
357 extern int urecovery_Initialize(register struct ubik_dbase *adbase);
358 extern void *urecovery_Interact(void *);
359 extern int DoProbe(struct ubik_server *server);
362 extern void *ubeacon_Interact(void *);
363 extern int sdisk_Interact();
364 extern int uvote_Interact();
365 extern int DISK_Abort();
366 extern int DISK_Begin();
367 extern int DISK_ReleaseLocks();
368 extern int DISK_Commit();
369 extern int DISK_Lock();
370 extern int DISK_Write();
371 extern int DISK_WriteV();
372 extern int DISK_Truncate();
373 extern int DISK_SetVersion();
376 extern int udisk_abort(struct ubik_trans *atrans);
380 extern void ulock_relLock(struct ubik_trans *atrans);
383 #endif /* UBIK_INTERNALS */
385 extern afs_int32 ubik_nBuffers;
388 * \name Public function prototypes
391 extern int ubik_ParseClientList(int argc, char **argv, afs_int32 * aothers);
393 extern unsigned int afs_random(void
396 extern int ubik_ClientInit(register struct rx_connection **serverconns,
397 struct ubik_client **aclient);
399 extern afs_int32 ubik_ClientDestroy(struct ubik_client *aclient);
401 extern afs_int32 ubik_CallIter(int (*aproc) (), struct ubik_client *aclient,
402 afs_int32 aflags, int *apos, long p1, long p2,
403 long p3, long p4, long p5, long p6, long p7,
404 long p8, long p9, long p10, long p11, long p12,
405 long p13, long p14, long p15, long p16);
407 extern struct rx_connection *ubik_RefreshConn(struct rx_connection *tc);
411 extern int ubik_BeginTrans(register struct ubik_dbase *dbase,
412 afs_int32 transMode, struct ubik_trans **transPtr);
413 extern int ubik_EndTrans(register struct ubik_trans *transPtr);
417 extern afs_int32 ugen_ClientInit(int noAuthFlag, char *confDir, char *cellName,
419 struct ubik_client **uclientp,
420 int (*secproc) (), char *funcName,
421 afs_int32 gen_rxkad_level,
422 afs_int32 maxservers, char *serviceid,
423 afs_int32 deadtime, afs_uint32 server,
424 afs_uint32 port, afs_int32 usrvid);