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, void *abuffer,
178 afs_int32 apos, afs_int32 alength);
179 int (*write) (struct ubik_dbase * adbase, afs_int32 afile, void *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 void (*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) (void *, struct rx_securityClass **,
203 extern void *ubik_CRXSecurityRock;
204 extern int (*ubik_SRXSecurityProc) (void *, struct rx_securityClass **,
206 extern void *ubik_SRXSecurityRock;
207 extern int (*ubik_CheckRXSecurityProc) (void *, struct rx_call *);
208 extern void *ubik_CheckRXSecurityRock;
211 /****************INTERNALS BELOW ****************/
213 #ifdef UBIK_INTERNALS
214 /*! \name some ubik parameters */
215 #define UBIK_PAGESIZE 1024 /*!< fits in current r packet */
216 #define UBIK_LOGPAGESIZE 10 /*!< base 2 log thereof */
217 #define NBUFFERS 20 /*!< number of 1K buffers */
218 #define HDRSIZE 64 /*!< bytes of header per dbfile */
221 /*! \name ubik_dbase flags */
222 #define DBWRITING 1 /*!< are any write trans. in progress */
223 #if defined(UBIK_PAUSE)
224 #define DBVOTING 2 /*!< the beacon task is polling */
225 #endif /* UBIK_PAUSE */
228 /*!\name ubik trans flags */
229 #define TRDONE 1 /*!< commit or abort done */
230 #define TRABORT 2 /*!< if #TRDONE, tells if aborted */
231 #define TRREADANY 4 /*!< read any data available in trans */
232 #if defined(UBIK_PAUSE)
233 #define TRSETLOCK 8 /*!< SetLock is using trans */
234 #define TRSTALE 16 /*!< udisk_end during getLock */
235 #endif /* UBIK_PAUSE */
238 /*! \name ubik_lock flags */
242 /*! \name ubik system database numbers */
246 /*! \name define log opcodes */
247 #define LOGNEW 100 /*!< start transaction */
248 #define LOGEND 101 /*!< commit (good) end transaction */
249 #define LOGABORT 102 /*!< abort (fail) transaction */
250 #define LOGDATA 103 /*!< data */
251 #define LOGTRUNCATE 104 /*!< truncate operation */
255 * \name timer constants
256 * time constant for replication algorithms: the R time period is 20 seconds. Both
257 * #SMALLTIME and #BIGTIME must be larger than #RPCTIMEOUT+max(#RPCTIMEOUT, #POLLTIME),
258 * so that timeouts do not prevent us from getting through to our servers in time.
260 * We use multi-R to time out multiple down hosts concurrently.
261 * The only other restrictions: #BIGTIME > #SMALLTIME and
262 * #BIGTIME-#SMALLTIME > #MAXSKEW (the clock skew).
266 #define RPCTIMEOUT 20
272 * \brief the per-server state, used by the sync site to keep track of its charges
275 struct ubik_server *next; /*!< next ptr */
276 afs_uint32 addr[UBIK_MAX_INTERFACE_ADDR]; /*!< network order, addr[0] is primary */
277 afs_int32 lastVoteTime; /*!< last time yes vote received */
278 afs_int32 lastBeaconSent; /*!< last time beacon attempted */
279 struct ubik_version version; /*!< version, only used during recovery */
280 struct rx_connection *vote_rxcid; /*!< cid to use to contact dude for votes */
281 struct rx_connection *disk_rxcid; /*!< cid to use to contact dude for disk reqs */
282 char lastVote; /*!< true if last vote was yes */
283 char up; /*!< is it up? */
284 char beaconSinceDown; /*!< did beacon get through since last crash? */
285 char currentDB; /*!< is dbase up-to-date */
286 char magic; /*!< the one whose vote counts twice */
287 char isClone; /*!< is only a clone, doesn't vote */
290 /*! \name hold and release functions on a database */
291 #define DBHOLD(a) ObtainWriteLock(&((a)->versionLock))
292 #define DBRELE(a) ReleaseWriteLock(&((a)->versionLock))
297 /*!name list of all servers in the system */
298 extern struct ubik_server *ubik_servers;
299 extern char amIClone;
302 /*! \name network port info */
303 extern short ubik_callPortal;
306 /*! \name urecovery state bits for sync site */
307 #define UBIK_RECSYNCSITE 1 /* am sync site */
308 #define UBIK_RECFOUNDDB 2 /* found acceptable dbase from quorum */
309 #define UBIK_RECHAVEDB 4 /* fetched best dbase */
310 #define UBIK_RECLABELDB 8 /* relabelled dbase */
311 #define UBIK_RECSENTDB 0x10 /* sent best db to *everyone* */
312 #define UBIK_RECSBETTER UBIK_RECLABELDB /* last state */
315 extern afs_int32 ubik_quorum; /* min hosts in quorum */
316 extern struct ubik_dbase *ubik_dbase; /* the database handled by this server */
317 extern afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR]; /* this host addr, in net order */
318 extern int ubik_amSyncSite; /* sleep on this waiting to be sync site */
319 extern struct ubik_stats { /* random stats */
322 extern afs_int32 ubik_epochTime; /* time when this site started */
323 extern afs_int32 urecovery_state; /* sync site recovery process state */
324 extern struct ubik_trans *ubik_currentTrans; /* current trans */
325 extern struct ubik_version ubik_dbVersion; /* sync site's dbase version */
326 extern afs_int32 ubik_debugFlag; /* ubik debug flag */
327 extern int ubikPrimaryAddrOnly; /* use only primary address */
329 /* this extern gives the sync site's db version, with epoch of 0 if none yet */
332 extern int uphys_close(register int afd);
333 extern int uphys_stat(struct ubik_dbase *adbase, afs_int32 afid,
334 struct ubik_stat *astat);
335 extern int uphys_read(register struct ubik_dbase *adbase, afs_int32 afile,
336 register void *abuffer, afs_int32 apos,
338 extern int uphys_write(register struct ubik_dbase *adbase, afs_int32 afile,
339 register void *abuffer, afs_int32 apos,
341 extern int uphys_truncate(register struct ubik_dbase *adbase, afs_int32 afile,
343 extern int uphys_getnfiles(register struct ubik_dbase *adbase);
344 extern int uphys_getlabel(register struct ubik_dbase *adbase, afs_int32 afile,
345 struct ubik_version *aversion);
346 extern int uphys_setlabel(register struct ubik_dbase *adbase, afs_int32 afile,
347 struct ubik_version *aversion);
348 extern int uphys_sync(register struct ubik_dbase *adbase, afs_int32 afile);
349 extern void uphys_invalidate(register struct ubik_dbase *adbase,
352 /*! \name recovery.c */
353 extern int urecovery_ResetState(void);
354 extern int urecovery_LostServer(void);
355 extern int urecovery_AllBetter(register struct ubik_dbase *adbase,
357 extern int urecovery_AbortAll(struct ubik_dbase *adbase);
358 extern int urecovery_CheckTid(register struct ubik_tid *atid);
359 extern int urecovery_Initialize(register struct ubik_dbase *adbase);
360 extern void *urecovery_Interact(void *);
361 extern int DoProbe(struct ubik_server *server);
365 extern afs_int32 ContactQuorum_NoArguments(afs_int32 (*proc)
366 (struct rx_connection *,
368 struct ubik_trans *atrans,
371 extern afs_int32 ContactQuorum_DISK_Lock(struct ubik_trans *atrans,
373 afs_int32 file, afs_int32 position,
374 afs_int32 length, afs_int32 type);
376 extern afs_int32 ContactQuorum_DISK_Write(struct ubik_trans *atrans,
378 afs_int32 file, afs_int32 position,
381 extern afs_int32 ContactQuorum_DISK_Truncate(struct ubik_trans *atrans,
383 afs_int32 file, afs_int32 length);
385 extern afs_int32 ContactQuorum_DISK_WriteV(struct ubik_trans *atrans,
387 iovec_wrt * io_vector,
388 iovec_buf *io_buffer);
390 extern afs_int32 ContactQuorum_DISK_SetVersion(struct ubik_trans *atrans,
392 ubik_version *OldVersion,
393 ubik_version *NewVersion);
395 extern void panic(char *format, ...);
397 extern afs_uint32 ubikGetPrimaryInterfaceAddr(afs_uint32 addr);
400 /*! \name beacon.c */
402 extern void ubeacon_Debug(struct ubik_debug *aparm);
403 extern int ubeacon_AmSyncSite(void);
404 extern int ubeacon_InitServerListByInfo(afs_int32 ame,
405 struct afsconf_cell *info,
407 extern int ubeacon_InitServerList(afs_int32 ame, afs_int32 aservers[]);
408 extern void *ubeacon_Interact(void *);
412 extern void udisk_Debug(struct ubik_debug *aparm);
413 extern int udisk_Invalidate(struct ubik_dbase *adbase, afs_int32 afid);
414 extern int udisk_read(struct ubik_trans *atrans, afs_int32 afile,
415 void *abuffer, afs_int32 apos, afs_int32 alen);
416 extern int udisk_truncate(struct ubik_trans *atrans, afs_int32 afile,
418 extern int udisk_write(struct ubik_trans *atrans, afs_int32 afile,
419 void *abuffer, afs_int32 apos, afs_int32 alen);
420 extern int udisk_begin(struct ubik_dbase *adbase, int atype,
421 struct ubik_trans **atrans);
422 extern int udisk_commit(struct ubik_trans *atrans);
423 extern int udisk_abort(struct ubik_trans *atrans);
424 extern int udisk_end(struct ubik_trans *atrans);
428 extern int ulock_getLock(struct ubik_trans *atrans, int atype, int await);
429 extern void ulock_relLock(struct ubik_trans *atrans);
430 extern void ulock_Debug(struct ubik_debug *aparm);
434 extern int uvote_ShouldIRun(void);
435 extern afs_int32 uvote_GetSyncSite(void);
436 extern int uvote_Init(void);
437 extern void ubik_vprint(const char *format, va_list ap);
438 extern void ubik_print(const char *format, ...);
439 extern void ubik_dprint(const char *format, ...);
442 /*! \name ubik_int.xg - rxgen really should prototype these for us ... */
443 extern int VOTE_ExecuteRequest(register struct rx_call *);
444 extern int DISK_ExecuteRequest(register struct rx_call *);
447 #endif /* UBIK_INTERNALS */
449 extern afs_int32 ubik_nBuffers;
452 * \name Public function prototypes
457 extern int ubik_ServerInitByInfo(afs_int32 myHost, short myPort,
458 struct afsconf_cell *info, char clones[],
459 char *pathName, struct ubik_dbase **dbase);
460 extern int ubik_ServerInit(afs_int32 myHost, short myPort,
461 afs_int32 serverList[],
462 char *pathName, struct ubik_dbase **dbase);
463 extern int ubik_BeginTrans(register struct ubik_dbase *dbase,
464 afs_int32 transMode, struct ubik_trans **transPtr);
465 extern int ubik_BeginTransReadAny(register struct ubik_dbase *dbase,
467 struct ubik_trans **transPtr);
468 extern int ubik_AbortTrans(register struct ubik_trans *transPtr);
470 extern int ubik_EndTrans(register struct ubik_trans *transPtr);
471 extern int ubik_Read(register struct ubik_trans *transPtr, void *buffer,
473 extern int ubik_Flush(struct ubik_trans *transPtr);
474 extern int ubik_Write(register struct ubik_trans *transPtr, void *buffer,
476 extern int ubik_Seek(register struct ubik_trans *transPtr, afs_int32 fileid,
478 extern int ubik_Tell(register struct ubik_trans *transPtr, afs_int32 * fileid,
479 afs_int32 * position);
480 extern int ubik_Truncate(register struct ubik_trans *transPtr,
482 extern int ubik_SetLock(struct ubik_trans *atrans, afs_int32 apos,
483 afs_int32 alen, int atype);
484 extern int ubik_WaitVersion(register struct ubik_dbase *adatabase,
485 register struct ubik_version *aversion);
486 extern int ubik_GetVersion(register struct ubik_trans *atrans,
487 register struct ubik_version *avers);
488 extern int ubik_CacheUpdate(register struct ubik_trans *atrans);
491 /*! \name ubikclient.c */
493 extern int ubik_ParseClientList(int argc, char **argv, afs_int32 * aothers);
494 extern unsigned int afs_random(void);
495 extern int ubik_ClientInit(register struct rx_connection **serverconns,
496 struct ubik_client **aclient);
497 extern afs_int32 ubik_ClientDestroy(struct ubik_client *aclient);
498 extern struct rx_connection *ubik_RefreshConn(struct rx_connection *tc);
499 #ifdef UBIK_LEGACY_CALLITER
500 extern afs_int32 ubik_CallIter(int (*aproc) (), struct ubik_client *aclient,
501 afs_int32 aflags, int *apos, long p1, long p2,
502 long p3, long p4, long p5, long p6, long p7,
503 long p8, long p9, long p10, long p11, long p12,
504 long p13, long p14, long p15, long p16);
509 /* \name ubikcmd.c */
510 extern int ubik_ParseServerList(int argc, char **argv, afs_int32 *ahost,
516 struct rx_securityClass;
517 extern afs_int32 ugen_ClientInit(int noAuthFlag, char *confDir, char *cellName,
519 struct ubik_client **uclientp,
520 int (*secproc) (struct rx_securityClass *sc,
523 afs_int32 gen_rxkad_level,
524 afs_int32 maxservers, char *serviceid,
525 afs_int32 deadtime, afs_uint32 server,
526 afs_uint32 port, afs_int32 usrvid);