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 #include <afsconfig.h>
11 #include <afs/param.h>
17 #ifdef AFS_PTHREAD_ENV
18 # include <opr/lock.h>
20 # include <opr/lockstub.h>
24 #include <afs/afsutil.h>
25 #include <afs/cellconfig.h>
28 #define UBIK_INTERNALS
33 * This module is responsible for determining when the system has
34 * recovered to the point that it can handle new transactions. It
35 * replays logs, polls to determine the current dbase after a crash,
36 * and distributes the new database to the others.
38 * The sync site associates a version number with each database. It
39 * broadcasts the version associated with its current dbase in every
40 * one of its beacon messages. When the sync site send a dbase to a
41 * server, it also sends the db's version. A non-sync site server can
42 * tell if it has the right dbase version by simply comparing the
43 * version from the beacon message \p uvote_dbVersion with the version
44 * associated with the database \p ubik_dbase->version. The sync site
45 * itself simply has one counter to keep track of all of this (again
46 * \p ubik_dbase->version).
48 * sync site: routine called when the sync site loses its quorum; this
49 * procedure is called "up" from the beacon package. It resyncs the
50 * dbase and nudges the recovery daemon to try to propagate out the
51 * changes. It also resets the recovery daemon's state, since
52 * recovery must potentially find a new dbase to propagate out. This
53 * routine should not do anything with variables used by non-sync site
58 * if this flag is set, then ubik will use only the primary address
59 * (the address specified in the CellServDB) to contact other
60 * ubik servers. Ubik recovery will not try opening connections
61 * to the alternate interface addresses.
63 int ubikPrimaryAddrOnly
;
66 urecovery_ResetState(void)
75 * routine called when a non-sync site server goes down; restarts recovery
76 * process to send missing server the new db when it comes back up for
77 * non-sync site servers.
79 * \note This routine should not do anything with variables used by non-sync site servers.
82 urecovery_LostServer(struct ubik_server
*ts
)
84 ubeacon_ReinitServer(ts
);
89 * return true iff we have a current database (called by both sync
90 * sites and non-sync sites) How do we determine this? If we're the
91 * sync site, we wait until recovery has finished fetching and
92 * re-labelling its dbase (it may still be trying to propagate it out
93 * to everyone else; that's THEIR problem). If we're not the sync
94 * site, then we must have a dbase labelled with the right version,
95 * and we must have a currently-good sync site.
98 urecovery_AllBetter(struct ubik_dbase
*adbase
, int areadAny
)
102 ViceLog(25, ("allbetter checking\n"));
107 if (ubik_dbase
->version
.epoch
> 1)
108 rcode
= 1; /* Happy with any good version of database */
111 /* Check if we're sync site and we've got the right data */
112 else if (ubeacon_AmSyncSite() && (urecovery_state
& UBIK_RECHAVEDB
)) {
116 /* next, check if we're aux site, and we've ever been sent the
117 * right data (note that if a dbase update fails, we won't think
118 * that the sync site is still the sync site, 'cause it won't talk
119 * to us until a timeout period has gone by. When we recover, we
120 * leave this clear until we get a new dbase */
121 else if (uvote_HaveSyncAndVersion(ubik_dbase
->version
)) {
125 ViceLog(25, ("allbetter: returning %d\n", rcode
));
130 * \brief abort all transactions on this database
133 urecovery_AbortAll(struct ubik_dbase
*adbase
)
135 struct ubik_trans
*tt
;
136 for (tt
= adbase
->activeTrans
; tt
; tt
= tt
->next
) {
143 * \brief this routine aborts the current remote transaction, if any, if the tid is wrong
146 urecovery_CheckTid(struct ubik_tid
*atid
, int abortalways
)
148 if (ubik_currentTrans
) {
149 /* there is remote write trans, see if we match, see if this
150 * is a new transaction */
151 if (atid
->epoch
!= ubik_currentTrans
->tid
.epoch
152 || atid
->counter
> ubik_currentTrans
->tid
.counter
|| abortalways
) {
153 /* don't match, abort it */
154 /* If the thread is not waiting for lock - ok to end it */
155 if (ubik_currentTrans
->locktype
!= LOCKWAIT
) {
156 udisk_end(ubik_currentTrans
);
158 ubik_currentTrans
= (struct ubik_trans
*)0;
167 * log format is defined here, and implicitly in disk.c
169 * 4 byte opcode, followed by parameters, each 4 bytes long. All integers
170 * are in logged in network standard byte order, in case we want to move logs
171 * from machine-to-machine someday.
173 * Begin transaction: opcode \n
174 * Commit transaction: opcode, version (8 bytes) \n
175 * Truncate file: opcode, file number, length \n
176 * Abort transaction: opcode \n
177 * Write data: opcode, file, position, length, <length> data bytes \n
179 * A very simple routine, it just replays the log. Note that this is a new-value only log, which
180 * implies that no uncommitted data is written to the dbase: one writes data to the log, including
181 * the commit record, then we allow data to be written through to the dbase. In our particular
182 * implementation, once a transaction is done, we write out the pages to the database, so that
183 * our buffer package doesn't have to know about stable and uncommitted data in the memory buffers:
184 * any changed data while there is an uncommitted write transaction can be zapped during an
185 * abort and the remaining dbase on the disk is exactly the right dbase, without having to read
189 ReplayLog(struct ubik_dbase
*adbase
)
192 afs_int32 code
, tpos
;
194 afs_int32 len
, thisSize
, tfile
, filePos
;
196 afs_int32 syncFile
= -1;
197 afs_int32 data
[1024];
199 /* read the lock twice, once to see whether we have a transaction to deal
200 * with that committed, (theoretically, we should support more than one
201 * trans in the log at once, but not yet), and once replaying the
205 /* for now, assume that all ops in log pertain to one transaction; see if there's a commit */
208 (*adbase
->read
) (adbase
, LOGFILE
, (char *)&opcode
, tpos
,
210 if (code
!= sizeof(afs_int32
))
212 opcode
= ntohl(opcode
);
213 if (opcode
== LOGNEW
) {
214 /* handle begin trans */
215 tpos
+= sizeof(afs_int32
);
216 } else if (opcode
== LOGABORT
)
218 else if (opcode
== LOGEND
) {
221 } else if (opcode
== LOGTRUNCATE
) {
224 (*adbase
->read
) (adbase
, LOGFILE
, (char *)buffer
, tpos
,
225 2 * sizeof(afs_int32
));
226 if (code
!= 2 * sizeof(afs_int32
))
227 break; /* premature eof or io error */
228 tpos
+= 2 * sizeof(afs_int32
);
229 } else if (opcode
== LOGDATA
) {
232 (*adbase
->read
) (adbase
, LOGFILE
, (char *)buffer
, tpos
,
233 3 * sizeof(afs_int32
));
234 if (code
!= 3 * sizeof(afs_int32
))
236 /* otherwise, skip over the data bytes, too */
237 tpos
+= ntohl(buffer
[2]) + 3 * sizeof(afs_int32
);
239 ViceLog(0, ("corrupt log opcode (%d) at position %d\n", opcode
,
241 break; /* corrupt log! */
245 /* actually do the replay; log should go all the way through the commit record, since
246 * we just read it above. */
252 (*adbase
->read
) (adbase
, LOGFILE
, (char *)&opcode
, tpos
,
254 if (code
!= sizeof(afs_int32
))
256 opcode
= ntohl(opcode
);
257 if (opcode
== LOGNEW
) {
258 /* handle begin trans */
259 tpos
+= sizeof(afs_int32
);
260 } else if (opcode
== LOGABORT
)
261 panic("log abort\n");
262 else if (opcode
== LOGEND
) {
263 struct ubik_version version
;
266 (*adbase
->read
) (adbase
, LOGFILE
, (char *)buffer
, tpos
,
267 2 * sizeof(afs_int32
));
268 if (code
!= 2 * sizeof(afs_int32
))
270 version
.epoch
= ntohl(buffer
[0]);
271 version
.counter
= ntohl(buffer
[1]);
272 code
= (*adbase
->setlabel
) (adbase
, 0, &version
);
275 ViceLog(0, ("Successfully replayed log for interrupted "
276 "transaction; db version is now %ld.%ld\n",
277 (long) version
.epoch
, (long) version
.counter
));
279 break; /* all done now */
280 } else if (opcode
== LOGTRUNCATE
) {
283 (*adbase
->read
) (adbase
, LOGFILE
, (char *)buffer
, tpos
,
284 2 * sizeof(afs_int32
));
285 if (code
!= 2 * sizeof(afs_int32
))
286 break; /* premature eof or io error */
287 tpos
+= 2 * sizeof(afs_int32
);
289 (*adbase
->truncate
) (adbase
, ntohl(buffer
[0]),
293 } else if (opcode
== LOGDATA
) {
296 (*adbase
->read
) (adbase
, LOGFILE
, (char *)buffer
, tpos
,
297 3 * sizeof(afs_int32
));
298 if (code
!= 3 * sizeof(afs_int32
))
300 tpos
+= 3 * sizeof(afs_int32
);
301 /* otherwise, skip over the data bytes, too */
302 len
= ntohl(buffer
[2]); /* total number of bytes to copy */
303 filePos
= ntohl(buffer
[1]);
304 tfile
= ntohl(buffer
[0]);
305 /* try to minimize file syncs */
306 if (syncFile
!= tfile
) {
308 code
= (*adbase
->sync
) (adbase
, syncFile
);
316 thisSize
= (len
> sizeof(data
) ? sizeof(data
) : len
);
317 /* copy sizeof(data) buffer bytes at a time */
319 (*adbase
->read
) (adbase
, LOGFILE
, (char *)data
, tpos
,
321 if (code
!= thisSize
)
324 (*adbase
->write
) (adbase
, tfile
, (char *)data
, filePos
,
326 if (code
!= thisSize
)
333 ViceLog(0, ("corrupt log opcode (%d) at position %d\n",
335 break; /* corrupt log! */
340 code
= (*adbase
->sync
) (adbase
, syncFile
);
344 ViceLog(0, ("Log read error on pass 2\n"));
349 /* now truncate the log, we're done with it */
350 code
= (*adbase
->truncate
) (adbase
, LOGFILE
, 0);
355 * Called at initialization to figure out version of the dbase we really have.
357 * This routine is called after replaying the log; it reads the restored labels.
360 InitializeDB(struct ubik_dbase
*adbase
)
364 code
= (*adbase
->getlabel
) (adbase
, 0, &adbase
->version
);
366 /* try setting the label to a new value */
368 adbase
->version
.epoch
= 1; /* value for newly-initialized db */
369 adbase
->version
.counter
= 1;
370 code
= (*adbase
->setlabel
) (adbase
, 0, &adbase
->version
);
372 /* failed, try to set it back */
373 adbase
->version
.epoch
= 0;
374 adbase
->version
.counter
= 0;
375 (*adbase
->setlabel
) (adbase
, 0, &adbase
->version
);
377 #ifdef AFS_PTHREAD_ENV
378 opr_cv_broadcast(&adbase
->version_cond
);
380 LWP_NoYieldSignal(&adbase
->version
);
388 * \brief initialize the local ubik_dbase
390 * We replay the logs and then read the resulting file to figure out what version we've really got.
393 urecovery_Initialize(struct ubik_dbase
*adbase
)
398 code
= ReplayLog(adbase
);
401 code
= InitializeDB(adbase
);
408 * \brief Main interaction loop for the recovery manager
410 * The recovery light-weight process only runs when you're the
411 * synchronization site. It performs the following tasks, if and only
412 * if the prerequisite tasks have been performed successfully (it
413 * keeps track of which ones have been performed in its bit map,
414 * \p urecovery_state).
416 * First, it is responsible for probing that all servers are up. This
417 * is the only operation that must be performed even if this is not
418 * yet the sync site, since otherwise this site may not notice that
419 * enough other machines are running to even elect this guy to be the
422 * After that, the recovery process does nothing until the beacon and
423 * voting modules manage to get this site elected sync site.
425 * After becoming sync site, recovery first attempts to find the best
426 * database available in the network (it must do this in order to
427 * ensure finding the latest committed data). After finding the right
428 * database, it must fetch this dbase to the sync site.
430 * After fetching the dbase, it relabels it with a new version number,
431 * to ensure that everyone recognizes this dbase as the most recent
434 * One the dbase has been relabelled, this machine can start handling
435 * requests. However, the recovery module still has one more task:
436 * propagating the dbase out to everyone who is up in the network.
439 urecovery_Interact(void *dummy
)
442 struct ubik_server
*bestServer
= NULL
;
443 struct ubik_server
*ts
;
444 int dbok
, doingRPC
, now
;
445 afs_int32 lastProbeTime
;
446 /* if we're the sync site, the best db version we've found yet */
447 static struct ubik_version bestDBVersion
;
448 struct ubik_version tversion
;
450 int length
, tlen
, offset
, file
, nbytes
;
451 struct rx_call
*rxcall
;
453 struct ubik_stat ubikstat
;
454 struct in_addr inAddr
;
460 afs_pthread_setname_self("recovery");
462 /* otherwise, begin interaction */
466 /* Run through this loop every 4 seconds */
469 #ifdef AFS_PTHREAD_ENV
470 select(0, 0, 0, 0, &tv
);
472 IOMGR_Select(0, 0, 0, 0, &tv
);
475 ViceLog(5, ("recovery running in state %x\n", urecovery_state
));
477 /* Every 30 seconds, check all the down servers and mark them
478 * as up if they respond. When a server comes up or found to
479 * not be current, then re-find the the best database and
482 if ((now
= FT_ApproxTime()) > 30 + lastProbeTime
) {
484 for (ts
= ubik_servers
, doingRPC
= 0; ts
; ts
= ts
->next
) {
495 urecovery_state
&= ~UBIK_RECFOUNDDB
;
502 urecovery_state
&= ~UBIK_RECFOUNDDB
;
508 now
= FT_ApproxTime();
512 /* Mark whether we are the sync site */
514 if (!ubeacon_AmSyncSite()) {
515 urecovery_state
&= ~UBIK_RECSYNCSITE
;
517 continue; /* nothing to do */
519 urecovery_state
|= UBIK_RECSYNCSITE
;
521 /* If a server has just come up or if we have not found the
522 * most current database, then go find the most current db.
524 if (!(urecovery_state
& UBIK_RECFOUNDDB
)) {
527 bestServer
= (struct ubik_server
*)0;
528 bestDBVersion
.epoch
= 0;
529 bestDBVersion
.counter
= 0;
530 for (ts
= ubik_servers
; ts
; ts
= ts
->next
) {
534 continue; /* don't bother with these guys */
540 code
= DISK_GetVersion(ts
->disk_rxcid
, &ts
->version
);
544 /* perhaps this is the best version */
545 if (vcmp(ts
->version
, bestDBVersion
) > 0) {
546 /* new best version */
547 bestDBVersion
= ts
->version
;
555 if (okcalls
+ 1 >= ubik_quorum
) {
556 /* If we've asked a majority of sites about their db version,
557 * then we can say with confidence that we've found the best db
558 * version. If we haven't contacted most sites (because
559 * GetVersion failed or because we already know the server is
560 * down), then we don't really know if we know about the best
561 * db version. So we can only proceed in here if 'okcalls'
562 * indicates we managed to contact a majority of sites. */
564 /* take into consideration our version. Remember if we,
565 * the sync site, have the best version. Also note that
566 * we may need to send the best version out.
568 if (vcmp(ubik_dbase
->version
, bestDBVersion
) >= 0) {
569 bestDBVersion
= ubik_dbase
->version
;
570 bestServer
= (struct ubik_server
*)0;
571 urecovery_state
|= UBIK_RECHAVEDB
;
573 /* Clear the flag only when we know we have to retrieve
574 * the db. Because urecovery_AllBetter() looks at it.
576 urecovery_state
&= ~UBIK_RECHAVEDB
;
578 urecovery_state
|= UBIK_RECFOUNDDB
;
579 urecovery_state
&= ~UBIK_RECSENTDB
;
582 if (!(urecovery_state
& UBIK_RECFOUNDDB
)) {
584 continue; /* not ready */
587 /* If we, the sync site, do not have the best db version, then
588 * go and get it from the server that does.
590 if ((urecovery_state
& UBIK_RECHAVEDB
) || !bestServer
) {
591 urecovery_state
|= UBIK_RECHAVEDB
;
593 /* we don't have the best version; we should fetch it. */
594 urecovery_AbortAll(ubik_dbase
);
596 /* Rx code to do the Bulk fetch */
600 rxcall
= rx_NewCall(bestServer
->disk_rxcid
);
602 ViceLog(0, ("Ubik: Synchronize database via DISK_GetFile to server %s\n",
603 afs_inet_ntoa_r(bestServer
->addr
[0], hoststr
)));
606 code
= StartDISK_GetFile(rxcall
, file
);
608 ViceLog(5, ("StartDiskGetFile failed=%d\n", code
));
611 nbytes
= rx_Read(rxcall
, (char *)&length
, sizeof(afs_int32
));
612 length
= ntohl(length
);
613 if (nbytes
!= sizeof(afs_int32
)) {
614 ViceLog(5, ("Rx-read length error=%d\n", BULK_ERROR
));
619 /* give invalid label during file transit */
622 code
= (*ubik_dbase
->setlabel
) (ubik_dbase
, file
, &tversion
);
625 ViceLog(5, ("setlabel io error=%d\n", code
));
628 snprintf(pbuffer
, sizeof(pbuffer
), "%s.DB%s%d.TMP",
629 ubik_dbase
->pathName
, (file
<0)?"SYS":"",
630 (file
<0)?-file
:file
);
631 fd
= open(pbuffer
, O_CREAT
| O_RDWR
| O_TRUNC
, 0600);
636 code
= lseek(fd
, HDRSIZE
, 0);
637 if (code
!= HDRSIZE
) {
644 tlen
= (length
> sizeof(tbuffer
) ? sizeof(tbuffer
) : length
);
645 #ifndef AFS_PTHREAD_ENV
649 nbytes
= rx_Read(rxcall
, tbuffer
, tlen
);
650 if (nbytes
!= tlen
) {
651 ViceLog(5, ("Rx-read bulk error=%d\n", BULK_ERROR
));
656 nbytes
= write(fd
, tbuffer
, tlen
);
658 if (nbytes
!= tlen
) {
669 code
= EndDISK_GetFile(rxcall
, &tversion
);
671 code
= rx_EndCall(rxcall
, code
);
673 /* we got a new file, set up its header */
674 urecovery_state
|= UBIK_RECHAVEDB
;
676 memcpy(&ubik_dbase
->version
, &tversion
,
677 sizeof(struct ubik_version
));
678 snprintf(tbuffer
, sizeof(tbuffer
), "%s.DB%s%d",
679 ubik_dbase
->pathName
, (file
<0)?"SYS":"",
680 (file
<0)?-file
:file
);
682 snprintf(pbuffer
, sizeof(pbuffer
), "%s.DB%s%d.OLD",
683 ubik_dbase
->pathName
, (file
<0)?"SYS":"",
684 (file
<0)?-file
:file
);
685 code
= unlink(pbuffer
);
687 code
= rename(tbuffer
, pbuffer
);
688 snprintf(pbuffer
, sizeof(pbuffer
), "%s.DB%s%d.TMP",
689 ubik_dbase
->pathName
, (file
<0)?"SYS":"",
690 (file
<0)?-file
:file
);
693 code
= rename(pbuffer
, tbuffer
);
695 (*ubik_dbase
->open
) (ubik_dbase
, file
);
696 /* after data is good, sync disk with correct label */
698 (*ubik_dbase
->setlabel
) (ubik_dbase
, 0,
699 &ubik_dbase
->version
);
703 snprintf(pbuffer
, sizeof(pbuffer
), "%s.DB%s%d.OLD",
704 ubik_dbase
->pathName
, (file
<0)?"SYS":"",
705 (file
<0)?-file
:file
);
712 * We will effectively invalidate the old data forever now.
713 * Unclear if we *should* but we do.
716 ubik_dbase
->version
.epoch
= 0;
717 ubik_dbase
->version
.counter
= 0;
719 ViceLog(0, ("Ubik: Synchronize database failed (error = %d)\n",
722 ViceLog(0, ("Ubik: Synchronize database completed\n"));
723 urecovery_state
|= UBIK_RECHAVEDB
;
725 udisk_Invalidate(ubik_dbase
, 0); /* data has changed */
726 #ifdef AFS_PTHREAD_ENV
727 opr_cv_broadcast(&ubik_dbase
->version_cond
);
729 LWP_NoYieldSignal(&ubik_dbase
->version
);
732 if (!(urecovery_state
& UBIK_RECHAVEDB
)) {
734 continue; /* not ready */
737 /* If the database was newly initialized, then when we establish quorum, write
738 * a new label. This allows urecovery_AllBetter() to allow access for reads.
739 * Setting it to 2 also allows another site to come along with a newer
740 * database and overwrite this one.
742 if (ubik_dbase
->version
.epoch
== 1) {
743 urecovery_AbortAll(ubik_dbase
);
745 ubik_dbase
->version
.epoch
= 2;
746 ubik_dbase
->version
.counter
= 1;
748 (*ubik_dbase
->setlabel
) (ubik_dbase
, 0, &ubik_dbase
->version
);
750 udisk_Invalidate(ubik_dbase
, 0); /* data may have changed */
751 #ifdef AFS_PTHREAD_ENV
752 opr_cv_broadcast(&ubik_dbase
->version_cond
);
754 LWP_NoYieldSignal(&ubik_dbase
->version
);
758 /* Check the other sites and send the database to them if they
759 * do not have the current db.
761 if (!(urecovery_state
& UBIK_RECSENTDB
)) {
762 /* now propagate out new version to everyone else */
763 dbok
= 1; /* start off assuming they all worked */
766 * Check if a write transaction is in progress. We can't send the
767 * db when a write is in progress here because the db would be
768 * obsolete as soon as it goes there. Also, ops after the begin
769 * trans would reach the recepient and wouldn't find a transaction
770 * pending there. Frankly, I don't think it's possible to get past
771 * the write-lock above if there is a write transaction in progress,
772 * but then, it won't hurt to check, will it?
774 if (ubik_dbase
->flags
& DBWRITING
) {
777 long cur_usec
= 50000;
778 while ((ubik_dbase
->flags
& DBWRITING
) && (safety
< 500)) {
780 /* sleep for a little while */
782 tv
.tv_usec
= cur_usec
;
783 #ifdef AFS_PTHREAD_ENV
784 select(0, 0, 0, 0, &tv
);
786 IOMGR_Select(0, 0, 0, 0, &tv
);
794 for (ts
= ubik_servers
; ts
; ts
= ts
->next
) {
796 inAddr
.s_addr
= ts
->addr
[0];
801 ViceLog(5, ("recovery cannot send version to %s\n",
802 afs_inet_ntoa_r(inAddr
.s_addr
, hoststr
)));
807 ViceLog(5, ("recovery sending version to %s\n",
808 afs_inet_ntoa_r(inAddr
.s_addr
, hoststr
)));
809 if (vcmp(ts
->version
, ubik_dbase
->version
) != 0) {
810 ViceLog(5, ("recovery stating local database\n"));
812 /* Rx code to do the Bulk Store */
813 code
= (*ubik_dbase
->stat
) (ubik_dbase
, 0, &ubikstat
);
815 length
= ubikstat
.size
;
818 rxcall
= rx_NewCall(ts
->disk_rxcid
);
821 StartDISK_SendFile(rxcall
, file
, length
,
822 &ubik_dbase
->version
);
824 ViceLog(5, ("StartDiskSendFile failed=%d\n",
831 sizeof(tbuffer
) ? sizeof(tbuffer
) : length
);
833 (*ubik_dbase
->read
) (ubik_dbase
, file
,
834 tbuffer
, offset
, tlen
);
835 if (nbytes
!= tlen
) {
837 ViceLog(5, ("Local disk read error=%d\n", code
));
840 nbytes
= rx_Write(rxcall
, tbuffer
, tlen
);
841 if (nbytes
!= tlen
) {
843 ViceLog(5, ("Rx-write bulk error=%d\n", code
));
849 code
= EndDISK_SendFile(rxcall
);
851 code
= rx_EndCall(rxcall
, code
);
854 /* we set a new file, process its header */
855 ts
->version
= ubik_dbase
->version
;
860 /* mark file up to date */
865 urecovery_state
|= UBIK_RECSENTDB
;
869 AFS_UNREACHED(return(NULL
));
873 * \brief send a Probe to all the network address of this server
875 * \return 0 if success, else return 1
878 DoProbe(struct ubik_server
*server
)
880 struct rx_connection
*conns
[UBIK_MAX_INTERFACE_ADDR
];
881 struct rx_connection
*connSuccess
= 0;
882 int i
, nconns
, success_i
= -1;
888 for (i
= 0; (i
< UBIK_MAX_INTERFACE_ADDR
) && (addr
= server
->addr
[i
]);
891 rx_NewConnection(addr
, ubik_callPortal
, DISK_SERVICE_ID
,
892 addr_globals
.ubikSecClass
, addr_globals
.ubikSecIndex
);
894 /* user requirement to use only the primary interface */
895 if (ubikPrimaryAddrOnly
) {
902 opr_Assert(nconns
); /* at least one interface address for this server */
904 multi_Rx(conns
, nconns
) {
906 if (!multi_error
) { /* first success */
913 if (success_i
>= 0) {
915 addr
= server
->addr
[success_i
]; /* successful interface addr */
917 if (server
->disk_rxcid
) /* destroy existing conn */
918 rx_DestroyConnection(server
->disk_rxcid
);
919 if (server
->vote_rxcid
)
920 rx_DestroyConnection(server
->vote_rxcid
);
922 /* make new connections */
923 server
->disk_rxcid
= conns
[success_i
];
924 server
->vote_rxcid
= rx_NewConnection(addr
, ubik_callPortal
,
925 VOTE_SERVICE_ID
, addr_globals
.ubikSecClass
,
926 addr_globals
.ubikSecIndex
);
928 connSuccess
= conns
[success_i
];
929 strcpy(buffer
, afs_inet_ntoa_r(server
->addr
[0], hoststr
));
931 ViceLog(0, ("ubik:server %s is back up: will be contacted through %s\n",
932 buffer
, afs_inet_ntoa_r(addr
, hoststr
)));
936 /* Destroy all connections except the one on which we succeeded */
937 for (i
= 0; i
< nconns
; i
++)
938 if (conns
[i
] != connSuccess
)
939 rx_DestroyConnection(conns
[i
]);
942 ViceLog(5, ("ubik:server %s still down\n",
943 afs_inet_ntoa_r(server
->addr
[0], hoststr
)));
946 return 0; /* success */
948 return 1; /* failure */