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
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 */
41 #else /* defined(UKERNEL) */
43 #endif /* defined(UKERNEL) */
45 /*! \name ubik_trans types */
46 #define UBIK_READTRANS 0
47 #define UBIK_WRITETRANS 1
50 /*! \name ubik_lock types */
53 #if !defined(UBIK_PAUSE)
55 #endif /* UBIK_PAUSE */
58 /*! \name ubik client flags */
59 #define UPUBIKONLY 1 /*!< only check servers presumed functional */
62 /*! \name RX services types */
63 #define VOTE_SERVICE_ID 50
64 #define DISK_SERVICE_ID 51
65 #define USER_SERVICE_ID 52 /*!< Since most applications use same port! */
68 #define UBIK_MAGIC 0x354545
70 /*! \name global ubik parameters */
71 #define MAXSERVERS 20 /*!< max number of servers */
74 /*! version comparison macro */
75 #define vcmp(a,b) ((a).epoch == (b).epoch? ((a).counter - (b).counter) : ((a).epoch - (b).epoch))
77 /*! \name ubik_client state bits */
78 #define CFLastFailed 1 /*!< last call failed to this guy (to detect down hosts) */
81 #ifdef AFS_PTHREAD_ENV
89 * \brief per-client structure for ubik
92 short initializationState; /*!< ubik client init state */
93 short states[MAXSERVERS]; /*!< state bits */
94 struct rx_connection *conns[MAXSERVERS];
96 #ifdef AFS_PTHREAD_ENV
101 #ifdef AFS_PTHREAD_ENV
102 #define LOCK_UBIK_CLIENT(client) assert(pthread_mutex_lock(&client->cm)==0)
103 #define UNLOCK_UBIK_CLIENT(client) assert(pthread_mutex_unlock(&client->cm)==0)
105 #define LOCK_UBIK_CLIENT(client)
106 #define UNLOCK_UBIK_CLIENT(client)
109 #define ubik_GetRPCConn(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->conns[aindex])
110 #define ubik_GetRPCHost(astr,aindex) ((aindex) >= MAXSERVERS? 0 : (astr)->hosts[aindex])
113 * \brief ubik header file structure
116 afs_int32 magic; /*!< magic number */
117 short pad1; /*!< some 0-initd padding */
118 short size; /*!< header allocation size */
119 struct ubik_version version; /*!< the version for this file */
123 * \brief representation of a ubik transaction
126 struct ubik_dbase *dbase; /*!< corresponding database */
127 struct ubik_trans *next; /*!< in the list */
128 afs_int32 locktype; /*!< transaction lock */
129 struct ubik_trunc *activeTruncs; /*!< queued truncates */
130 struct ubik_tid tid; /*!< transaction id of this trans (if write trans.) */
131 afs_int32 minCommitTime; /*!< time before which this trans can't commit */
132 afs_int32 seekFile; /*!< seek ptr: file number */
133 afs_int32 seekPos; /*!< seek ptr: offset therein */
134 short flags; /*!< trans flag bits */
135 char type; /*!< type of trans */
136 iovec_wrt iovec_info;
137 iovec_buf iovec_data;
141 * \brief representation of a truncation operation
144 struct ubik_trunc *next;
145 afs_int32 file; /*!< file to truncate */
146 afs_int32 length; /*!< new size */
155 #include "afs/lock.h"
156 #else /* defined(UKERNEL) */
157 #include <lock.h> /* just to make sure we've got this */
158 #endif /* defined(UKERNEL) */
161 * \brief representation of a ubik database.
163 * Contains info on low-level disk access routines
164 * for use by disk transaction module.
167 char *pathName; /*!< root name for dbase */
168 struct ubik_trans *activeTrans; /*!< active transaction list */
169 struct ubik_version version; /*!< version number */
171 struct afs_lock versionLock; /*!< lock on version number */
172 #else /* defined(UKERNEL) */
173 struct Lock versionLock; /*!< lock on version number */
174 #endif /* defined(UKERNEL) */
175 afs_int32 tidCounter; /*!< last RW or RO trans tid counter */
176 afs_int32 writeTidCounter; /*!< last write trans tid counter */
177 afs_int32 flags; /*!< flags */
178 /* physio procedures */
179 int (*read) (struct ubik_dbase * adbase, afs_int32 afile, void *abuffer,
180 afs_int32 apos, afs_int32 alength);
181 int (*write) (struct ubik_dbase * adbase, afs_int32 afile, void *abuffer,
182 afs_int32 apos, afs_int32 alength);
183 int (*truncate) (struct ubik_dbase * adbase, afs_int32 afile,
185 int (*sync) (struct ubik_dbase * adbase, afs_int32 afile);
186 int (*stat) (struct ubik_dbase * adbase, afs_int32 afid,
187 struct ubik_stat * astat);
188 void (*open) (struct ubik_dbase * adbase, afs_int32 afid);
189 int (*setlabel) (struct ubik_dbase * adbase, afs_int32 afile, struct ubik_version * aversion); /*!< set the version label */
190 int (*getlabel) (struct ubik_dbase * adbase, afs_int32 afile, struct ubik_version * aversion); /*!< retrieve the version label */
191 int (*getnfiles) (struct ubik_dbase * adbase); /*!< find out number of files */
192 short readers; /*!< number of current read transactions */
193 struct ubik_version cachedVersion; /*!< version of caller's cached data */
194 #ifdef AFS_PTHREAD_ENV
195 pthread_cond_t version_cond; /*!< condition variable to manage changes to version */
196 pthread_cond_t flags_cond; /*!< condition variable to manage changes to flags */
197 pthread_mutex_t version_mutex;
198 pthread_mutex_t flags_mutex;
202 /*! \name procedures for automatically authenticating ubik connections */
203 extern int (*ubik_CRXSecurityProc) (void *, struct rx_securityClass **,
205 extern void *ubik_CRXSecurityRock;
206 extern int (*ubik_SRXSecurityProc) (void *, struct rx_securityClass **,
208 extern void *ubik_SRXSecurityRock;
209 extern int (*ubik_CheckRXSecurityProc) (void *, struct rx_call *);
210 extern void *ubik_CheckRXSecurityRock;
213 /****************INTERNALS BELOW ****************/
215 #ifdef UBIK_INTERNALS
216 /*! \name some ubik parameters */
217 #define UBIK_PAGESIZE 1024 /*!< fits in current r packet */
218 #define UBIK_LOGPAGESIZE 10 /*!< base 2 log thereof */
219 #define NBUFFERS 20 /*!< number of 1K buffers */
220 #define HDRSIZE 64 /*!< bytes of header per dbfile */
223 /*! \name ubik_dbase flags */
224 #define DBWRITING 1 /*!< are any write trans. in progress */
225 #if defined(UBIK_PAUSE)
226 #define DBVOTING 2 /*!< the beacon task is polling */
227 #endif /* UBIK_PAUSE */
230 /*!\name ubik trans flags */
231 #define TRDONE 1 /*!< commit or abort done */
232 #define TRABORT 2 /*!< if #TRDONE, tells if aborted */
233 #define TRREADANY 4 /*!< read any data available in trans */
234 #if defined(UBIK_PAUSE)
235 #define TRSETLOCK 8 /*!< SetLock is using trans */
236 #define TRSTALE 16 /*!< udisk_end during getLock */
237 #endif /* UBIK_PAUSE */
240 /*! \name ubik_lock flags */
244 /*! \name ubik system database numbers */
248 /*! \name define log opcodes */
249 #define LOGNEW 100 /*!< start transaction */
250 #define LOGEND 101 /*!< commit (good) end transaction */
251 #define LOGABORT 102 /*!< abort (fail) transaction */
252 #define LOGDATA 103 /*!< data */
253 #define LOGTRUNCATE 104 /*!< truncate operation */
257 * \name timer constants
258 * time constant for replication algorithms: the R time period is 20 seconds. Both
259 * #SMALLTIME and #BIGTIME must be larger than #RPCTIMEOUT+max(#RPCTIMEOUT, #POLLTIME),
260 * so that timeouts do not prevent us from getting through to our servers in time.
262 * We use multi-R to time out multiple down hosts concurrently.
263 * The only other restrictions: #BIGTIME > #SMALLTIME and
264 * #BIGTIME-#SMALLTIME > #MAXSKEW (the clock skew).
268 #define RPCTIMEOUT 20
274 * \brief the per-server state, used by the sync site to keep track of its charges
277 struct ubik_server *next; /*!< next ptr */
278 afs_uint32 addr[UBIK_MAX_INTERFACE_ADDR]; /*!< network order, addr[0] is primary */
279 afs_int32 lastVoteTime; /*!< last time yes vote received */
280 afs_int32 lastBeaconSent; /*!< last time beacon attempted */
281 struct ubik_version version; /*!< version, only used during recovery */
282 struct rx_connection *vote_rxcid; /*!< cid to use to contact dude for votes */
283 struct rx_connection *disk_rxcid; /*!< cid to use to contact dude for disk reqs */
284 char lastVote; /*!< true if last vote was yes */
285 char up; /*!< is it up? */
286 char beaconSinceDown; /*!< did beacon get through since last crash? */
287 char currentDB; /*!< is dbase up-to-date */
288 char magic; /*!< the one whose vote counts twice */
289 char isClone; /*!< is only a clone, doesn't vote */
292 /*! \name hold and release functions on a database */
293 #define DBHOLD(a) ObtainWriteLock(&((a)->versionLock))
294 #define DBRELE(a) ReleaseWriteLock(&((a)->versionLock))
299 /*!name list of all servers in the system */
300 extern struct ubik_server *ubik_servers;
301 extern char amIClone;
304 /*! \name network port info */
305 extern short ubik_callPortal;
308 /*! \name urecovery state bits for sync site */
309 #define UBIK_RECSYNCSITE 1 /* am sync site */
310 #define UBIK_RECFOUNDDB 2 /* found acceptable dbase from quorum */
311 #define UBIK_RECHAVEDB 4 /* fetched best dbase */
312 #define UBIK_RECLABELDB 8 /* relabelled dbase */
313 #define UBIK_RECSENTDB 0x10 /* sent best db to *everyone* */
314 #define UBIK_RECSBETTER UBIK_RECLABELDB /* last state */
317 extern afs_int32 ubik_quorum; /* min hosts in quorum */
318 extern struct ubik_dbase *ubik_dbase; /* the database handled by this server */
319 extern afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR]; /* this host addr, in net order */
320 extern int ubik_amSyncSite; /* sleep on this waiting to be sync site */
321 extern struct ubik_stats { /* random stats */
324 extern afs_int32 ubik_epochTime; /* time when this site started */
325 extern afs_int32 urecovery_state; /* sync site recovery process state */
326 extern struct ubik_trans *ubik_currentTrans; /* current trans */
327 extern struct ubik_version ubik_dbVersion; /* sync site's dbase version */
328 extern afs_int32 ubik_debugFlag; /* ubik debug flag */
329 extern int ubikPrimaryAddrOnly; /* use only primary address */
331 /* this extern gives the sync site's db version, with epoch of 0 if none yet */
334 extern int uphys_close(register int afd);
335 extern int uphys_stat(struct ubik_dbase *adbase, afs_int32 afid,
336 struct ubik_stat *astat);
337 extern int uphys_read(register struct ubik_dbase *adbase, afs_int32 afile,
338 register void *abuffer, afs_int32 apos,
340 extern int uphys_write(register struct ubik_dbase *adbase, afs_int32 afile,
341 register void *abuffer, afs_int32 apos,
343 extern int uphys_truncate(register struct ubik_dbase *adbase, afs_int32 afile,
345 extern int uphys_getnfiles(register struct ubik_dbase *adbase);
346 extern int uphys_getlabel(register struct ubik_dbase *adbase, afs_int32 afile,
347 struct ubik_version *aversion);
348 extern int uphys_setlabel(register struct ubik_dbase *adbase, afs_int32 afile,
349 struct ubik_version *aversion);
350 extern int uphys_sync(register struct ubik_dbase *adbase, afs_int32 afile);
351 extern void uphys_invalidate(register struct ubik_dbase *adbase,
354 /*! \name recovery.c */
355 extern int urecovery_ResetState(void);
356 extern int urecovery_LostServer(void);
357 extern int urecovery_AllBetter(register struct ubik_dbase *adbase,
359 extern int urecovery_AbortAll(struct ubik_dbase *adbase);
360 extern int urecovery_CheckTid(register struct ubik_tid *atid);
361 extern int urecovery_Initialize(register struct ubik_dbase *adbase);
362 extern void *urecovery_Interact(void *);
363 extern int DoProbe(struct ubik_server *server);
367 extern afs_int32 ContactQuorum_NoArguments(afs_int32 (*proc)
368 (struct rx_connection *,
370 struct ubik_trans *atrans,
373 extern afs_int32 ContactQuorum_DISK_Lock(struct ubik_trans *atrans,
375 afs_int32 file, afs_int32 position,
376 afs_int32 length, afs_int32 type);
378 extern afs_int32 ContactQuorum_DISK_Write(struct ubik_trans *atrans,
380 afs_int32 file, afs_int32 position,
383 extern afs_int32 ContactQuorum_DISK_Truncate(struct ubik_trans *atrans,
385 afs_int32 file, afs_int32 length);
387 extern afs_int32 ContactQuorum_DISK_WriteV(struct ubik_trans *atrans,
389 iovec_wrt * io_vector,
390 iovec_buf *io_buffer);
392 extern afs_int32 ContactQuorum_DISK_SetVersion(struct ubik_trans *atrans,
394 ubik_version *OldVersion,
395 ubik_version *NewVersion);
397 extern void panic(char *format, ...);
399 extern afs_uint32 ubikGetPrimaryInterfaceAddr(afs_uint32 addr);
402 /*! \name beacon.c */
404 extern void ubeacon_Debug(struct ubik_debug *aparm);
405 extern int ubeacon_AmSyncSite(void);
406 extern int ubeacon_InitServerListByInfo(afs_int32 ame,
407 struct afsconf_cell *info,
409 extern int ubeacon_InitServerList(afs_int32 ame, afs_int32 aservers[]);
410 extern void *ubeacon_Interact(void *);
414 extern void udisk_Debug(struct ubik_debug *aparm);
415 extern int udisk_Invalidate(struct ubik_dbase *adbase, afs_int32 afid);
416 extern int udisk_read(struct ubik_trans *atrans, afs_int32 afile,
417 void *abuffer, afs_int32 apos, afs_int32 alen);
418 extern int udisk_truncate(struct ubik_trans *atrans, afs_int32 afile,
420 extern int udisk_write(struct ubik_trans *atrans, afs_int32 afile,
421 void *abuffer, afs_int32 apos, afs_int32 alen);
422 extern int udisk_begin(struct ubik_dbase *adbase, int atype,
423 struct ubik_trans **atrans);
424 extern int udisk_commit(struct ubik_trans *atrans);
425 extern int udisk_abort(struct ubik_trans *atrans);
426 extern int udisk_end(struct ubik_trans *atrans);
430 extern int ulock_getLock(struct ubik_trans *atrans, int atype, int await);
431 extern void ulock_relLock(struct ubik_trans *atrans);
432 extern void ulock_Debug(struct ubik_debug *aparm);
436 extern int uvote_ShouldIRun(void);
437 extern afs_int32 uvote_GetSyncSite(void);
438 extern int uvote_Init(void);
439 extern void ubik_vprint(const char *format, va_list ap);
440 extern void ubik_print(const char *format, ...);
441 extern void ubik_dprint(const char *format, ...);
442 extern void ubik_dprint_25(const char *format, ...);
445 #endif /* UBIK_INTERNALS */
447 extern afs_int32 ubik_nBuffers;
450 * \name Public function prototypes
455 extern int ubik_ServerInitByInfo(afs_int32 myHost, short myPort,
456 struct afsconf_cell *info, char clones[],
457 char *pathName, struct ubik_dbase **dbase);
458 extern int ubik_ServerInit(afs_int32 myHost, short myPort,
459 afs_int32 serverList[],
460 char *pathName, struct ubik_dbase **dbase);
461 extern int ubik_BeginTrans(register struct ubik_dbase *dbase,
462 afs_int32 transMode, struct ubik_trans **transPtr);
463 extern int ubik_BeginTransReadAny(register struct ubik_dbase *dbase,
465 struct ubik_trans **transPtr);
466 extern int ubik_AbortTrans(register struct ubik_trans *transPtr);
468 extern int ubik_EndTrans(register struct ubik_trans *transPtr);
469 extern int ubik_Read(register struct ubik_trans *transPtr, void *buffer,
471 extern int ubik_Flush(struct ubik_trans *transPtr);
472 extern int ubik_Write(register struct ubik_trans *transPtr, void *buffer,
474 extern int ubik_Seek(register struct ubik_trans *transPtr, afs_int32 fileid,
476 extern int ubik_Tell(register struct ubik_trans *transPtr, afs_int32 * fileid,
477 afs_int32 * position);
478 extern int ubik_Truncate(register struct ubik_trans *transPtr,
480 extern int ubik_SetLock(struct ubik_trans *atrans, afs_int32 apos,
481 afs_int32 alen, int atype);
482 extern int ubik_WaitVersion(register struct ubik_dbase *adatabase,
483 register struct ubik_version *aversion);
484 extern int ubik_GetVersion(register struct ubik_trans *atrans,
485 register struct ubik_version *avers);
486 extern int ubik_CacheUpdate(register struct ubik_trans *atrans);
489 /*! \name ubikclient.c */
491 extern int ubik_ParseClientList(int argc, char **argv, afs_int32 * aothers);
492 extern unsigned int afs_random(void);
493 extern int ubik_ClientInit(register struct rx_connection **serverconns,
494 struct ubik_client **aclient);
495 extern afs_int32 ubik_ClientDestroy(struct ubik_client *aclient);
496 extern struct rx_connection *ubik_RefreshConn(struct rx_connection *tc);
497 #ifdef UBIK_LEGACY_CALLITER
498 extern afs_int32 ubik_CallIter(int (*aproc) (), struct ubik_client *aclient,
499 afs_int32 aflags, int *apos, long p1, long p2,
500 long p3, long p4, long p5, long p6, long p7,
501 long p8, long p9, long p10, long p11, long p12,
502 long p13, long p14, long p15, long p16);
507 /* \name ubikcmd.c */
508 extern int ubik_ParseServerList(int argc, char **argv, afs_int32 *ahost,
514 struct rx_securityClass;
515 extern afs_int32 ugen_ClientInit(int noAuthFlag, const char *confDir,
516 char *cellName, afs_int32 sauth,
517 struct ubik_client **uclientp,
518 int (*secproc) (struct rx_securityClass *sc,
521 afs_int32 gen_rxkad_level,
522 afs_int32 maxservers, char *serviceid,
523 afs_int32 deadtime, afs_uint32 server,
524 afs_uint32 port, afs_int32 usrvid);