#include <afsconfig.h>
#include <afs/param.h>
+#include <afs/procmgmt.h>
+#include <roken.h>
-#include <sys/types.h>
-#include <stdio.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#include <time.h>
-#else
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <sys/time.h>
-#endif
-#include <errno.h>
-#include <afs/afs_assert.h>
-#include <signal.h>
-#include <string.h>
-
+#include <stddef.h>
-#include <rx/xdr.h>
+#include <afs/opr.h>
+#include <opr/lock.h>
#include <afs/afsint.h>
+#include <rx/rx_queue.h>
+
#include "nfs.h"
#include <afs/errors.h>
#include "salvsync.h"
-#include "lwp.h"
#include "lock.h"
#include <afs/afssyscalls.h>
#include "ihandle.h"
#include "partition.h"
#include "common.h"
#include <rx/rx_queue.h>
-#include <afs/procmgmt.h>
-
-#if !defined(offsetof)
-#include <stddef.h>
-#endif
#ifdef USE_UNIX_SOCKETS
#include <afs/afsutil.h>
static afs_int32 SALVSYNC_com_Link(SALVSYNC_command * com, SALVSYNC_response * res);
-extern int LogLevel;
extern int VInit;
extern pthread_mutex_t vol_salvsync_mutex;
static struct QueueHead SalvageHashTable[VSHASH_SIZE];
static struct SalvageQueueNode *
-LookupNode(afs_uint32 vid, char * partName,
+LookupNode(VolumeId vid, char * partName,
struct SalvageQueueNode ** parent)
{
struct rx_queue *qp, *nqp;
- struct SalvageQueueNode *vsp;
+ struct SalvageQueueNode *vsp = NULL;
int idx = VSHASH(vid);
for (queue_Scan(&SalvageHashTable[idx], qp, nqp, rx_queue)) {
SalvageHashTable[idx].len++;
}
-#if 0
-static void
-DeleteNodeFromHash(struct SalvageQueueNode * node)
-{
- int idx = VSHASH(node->command.sop.volume);
-
- if (queue_IsNotOnQueue(&node->hash_chain)) {
- return;
- }
-
- queue_Remove(&node->hash_chain);
- SalvageHashTable[idx].len--;
-}
-#endif
-
void
SALVSYNC_salvInit(void)
{
}
/* start the salvsync thread */
- osi_Assert(pthread_attr_init(&tattr) == 0);
- osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
- osi_Assert(pthread_create(&tid, &tattr, SALVSYNC_syncThread, NULL) == 0);
+ opr_Verify(pthread_attr_init(&tattr) == 0);
+ opr_Verify(pthread_attr_setdetachstate(&tattr,
+ PTHREAD_CREATE_DETACHED) == 0);
+ opr_Verify(pthread_create(&tid, &tattr, SALVSYNC_syncThread, NULL) == 0);
}
static void
/* when we fork, the child needs to close the salvsync server sockets,
* otherwise, it may get salvsync requests, instead of the parent
* salvageserver */
- osi_Assert(pthread_atfork(NULL, NULL, CleanFDs) == 0);
+ opr_Verify(pthread_atfork(NULL, NULL, CleanFDs) == 0);
SYNC_getAddr(&state->endpoint, &state->addr);
SYNC_cleanupSock(state);
state->fd = SYNC_getSock(&state->endpoint);
code = SYNC_bindSock(state);
- osi_Assert(!code);
+ opr_Assert(!code);
InitHandler();
AcceptOn();
for (;;) {
int maxfd;
+ struct timeval s_timeout;
GetHandler(&SALVSYNC_readfds, &maxfd);
+ s_timeout.tv_sec = SYNC_SELECT_TIMEOUT;
+ s_timeout.tv_usec = 0;
/* Note: check for >= 1 below is essential since IOMGR_select
* doesn't have exactly same semantics as select.
*/
- if (select(maxfd + 1, &SALVSYNC_readfds, NULL, NULL, NULL) >= 1)
+ if (select(maxfd + 1, &SALVSYNC_readfds, NULL, NULL, &s_timeout) >= 1)
CallHandler(&SALVSYNC_readfds);
}
- return NULL;
+ AFS_UNREACHED(return(NULL));
}
static void
osi_Panic("SALVSYNC_newconnection: accept failed, errno==%d\n", errno);
} else if (!AddHandler(fd, SALVSYNC_com)) {
AcceptOff();
- osi_Assert(AddHandler(fd, SALVSYNC_com));
+ opr_Verify(AddHandler(fd, SALVSYNC_com));
}
}
SALVSYNC_Drop(osi_socket fd)
{
RemoveHandler(fd);
-#ifdef AFS_NT40_ENV
- closesocket(fd);
-#else
- close(fd);
-#endif
+ rk_closesocket(fd);
AcceptOn();
}
AcceptOn(void)
{
if (AcceptHandler == -1) {
- osi_Assert(AddHandler(salvsync_server_state.fd, SALVSYNC_newconnection));
+ opr_Verify(AddHandler(salvsync_server_state.fd,
+ SALVSYNC_newconnection));
AcceptHandler = FindHandler(salvsync_server_state.fd);
}
}
AcceptOff(void)
{
if (AcceptHandler != -1) {
- osi_Assert(RemoveHandler(salvsync_server_state.fd));
+ opr_Verify(RemoveHandler(salvsync_server_state.fd));
AcceptHandler = -1;
}
}
}
ReleaseReadLock(&SALVSYNC_handler_lock); /* just in case */
osi_Panic("Failed to find handler\n");
- return -1; /* satisfy compiler */
+ AFS_UNREACHED(return -1);
}
static int
return i;
}
osi_Panic("Failed to find handler\n");
- return -1; /* satisfy compiler */
+ AFS_UNREACHED(return -1);
}
static int
int code = 0;
struct SalvageQueueNode * node;
- *node_out = node = (struct SalvageQueueNode *)
- malloc(sizeof(struct SalvageQueueNode));
+ *node_out = node = calloc(1, sizeof(struct SalvageQueueNode));
if (node == NULL) {
code = 1;
goto done;
}
- memset(node, 0, sizeof(struct SalvageQueueNode));
node->type = SALVSYNC_VOLGROUP_PARENT;
node->state = SALVSYNC_STATE_UNKNOWN;
switch (clone->state) {
case SALVSYNC_STATE_QUEUED:
DeleteFromSalvageQueue(clone);
-
+ AFS_FALLTHROUGH;
case SALVSYNC_STATE_SALVAGING:
switch (parent->state) {
case SALVSYNC_STATE_UNKNOWN:
}
}
-#if 0
-static struct SalvageQueueNode *
-LookupPendingCommand(SALVSYNC_command_hdr * qry)
-{
- struct SalvageQueueNode * np, * nnp;
-
- for (queue_Scan(&pendingQueue, np, nnp, SalvageQueueNode)) {
- if ((np->command.sop.volume == qry->volume) &&
- !strncmp(np->command.sop.partName, qry->partName,
- sizeof(qry->partName)))
- break;
- }
-
- if (queue_IsEnd(&pendingQueue, np))
- np = NULL;
- return np;
-}
-#endif
-
static struct SalvageQueueNode *
LookupPendingCommandByPid(int pid)
{
afs_int32 id;
afs_uint32 prio;
- osi_Assert(queue_IsOnQueue(node));
+ opr_Assert(queue_IsOnQueue(node));
prio = node->command.sop.prio;
id = node->partition_id;
osi_Panic("Node not found\n");
have_node:
- osi_Assert(node != NULL);
+ opr_Assert(node != NULL);
node->pid = 0;
partition_salvaging[node->partition_id]++;
DeleteFromSalvageQueue(node);
{
struct SalvageQueueNode * node;
char partName[16];
- afs_uint32 volids[VOLMAXTYPES+1];
+ VolumeId volids[VOLMAXTYPES+1];
unsigned int idx;
memset(volids, 0, sizeof(volids));