void cm_QueueBKGRequest(cm_scache_t *scp, cm_bkgProc_t *procp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4, cm_user_t *userp) { cm_bkgRequest_t *rp; rp = malloc(sizeof(*rp)); memset(rp, 0, sizeof(*rp)); cm_HoldSCache(scp); rp->scp = scp; cm_HoldUser(userp); rp->userp = userp; rp->procp = procp; rp->p1 = p1; rp->p2 = p2; rp->p3 = p3; rp->p4 = p4; lock_ObtainWrite(&cm_daemonLock); cm_bkgQueueCount++; osi_QAdd((osi_queue_t **) &cm_bkgListp, &rp->q); if (!cm_bkgListEndp) cm_bkgListEndp = rp; lock_ReleaseWrite(&cm_daemonLock); osi_Wakeup((LONG_PTR) &cm_bkgListp); }
void cm_DaemonShutdown(void) { int i; DWORD code; daemon_ShutdownFlag = 1; /* wait for shutdown */ for ( i=0; i<cm_nDaemons; i++) { osi_Wakeup((LONG_PTR) &cm_bkgListpp[i]); if (cm_BkgDaemon_ShutdownEvent[i]) code = thrd_WaitForSingleObject_Event(cm_BkgDaemon_ShutdownEvent[i], INFINITE); } if (cm_Daemon_ShutdownEvent) code = thrd_WaitForSingleObject_Event(cm_Daemon_ShutdownEvent, INFINITE); if (cm_LockDaemon_ShutdownEvent) code = thrd_WaitForSingleObject_Event(cm_LockDaemon_ShutdownEvent, INFINITE); #if 0 /* * Do not waste precious time waiting for the ipaddr daemon to shutdown. * When it does it means we have lost our network connection and we need * it during cache shutdown in order to notify the file servers that this * client is giving up all callbacks. */ if (cm_IPAddrDaemon_ShutdownEvent) code = thrd_WaitForSingleObject_Event(cm_IPAddrDaemon_ShutdownEvent, INFINITE); #endif }
void cm_QueueBKGRequest(cm_scache_t *scp, cm_bkgProc_t *procp, afs_uint32 p1, afs_uint32 p2, afs_uint32 p3, afs_uint32 p4, cm_user_t *userp, cm_req_t *reqp) { cm_bkgRequest_t *rp, *rpq; afs_uint32 daemonID; int duplicate = 0; rp = malloc(sizeof(*rp)); memset(rp, 0, sizeof(*rp)); cm_HoldSCache(scp); rp->scp = scp; cm_HoldUser(userp); rp->userp = userp; rp->procp = procp; rp->p1 = p1; rp->p2 = p2; rp->p3 = p3; rp->p4 = p4; rp->req = *reqp; /* Use separate queues for fetch and store operations */ daemonID = scp->fid.hash % (cm_nDaemons/2) * 2; if (procp == cm_BkgStore) daemonID++; lock_ObtainWrite(&cm_daemonLockp[daemonID]); /* Check to see if this is a duplicate request */ for (rpq = cm_bkgListpp[daemonID]; rpq; rpq = (cm_bkgRequest_t *) osi_QNext(&rpq->q)) { if ( rpq->p1 == p1 && rpq->p3 == p3 && rpq->procp == procp && rpq->p2 == p2 && rpq->p4 == p4 && rpq->scp == scp && rpq->userp == userp) { /* found a duplicate; update request with latest info */ duplicate = 1; break; } } if (!duplicate) { cm_bkgQueueCountp[daemonID]++; osi_QAddH((osi_queue_t **) &cm_bkgListpp[daemonID], (osi_queue_t **)&cm_bkgListEndpp[daemonID], &rp->q); } lock_ReleaseWrite(&cm_daemonLockp[daemonID]); if (duplicate) { cm_ReleaseSCache(scp); cm_ReleaseUser(userp); free(rp); } else { osi_Wakeup((LONG_PTR) &cm_bkgListpp[daemonID]); } }
/*! \brief End an RPC operation \see smb_RPC_BeginOp() */ afs_int32 smb_RPC_EndOp(smb_rpc_t * rpcp) { lock_ObtainMutex(&rpcp->fidp->mx); osi_assertx(rpcp->fidp->flags & SMB_FID_RPC_INCALL, "RPC_EndOp() call without RPC_BeginOp()"); rpcp->fidp->flags &= ~SMB_FID_RPC_INCALL; lock_ReleaseMutex(&rpcp->fidp->mx); osi_Wakeup((LONG_PTR) rpcp); return 0; }
void cm_DaemonShutdown(void) { int i; DWORD code; daemon_ShutdownFlag = 1; osi_Wakeup((LONG_PTR) &cm_bkgListp); /* wait for shutdown */ if (cm_Daemon_ShutdownEvent) code = thrd_WaitForSingleObject_Event(cm_Daemon_ShutdownEvent, INFINITE); for ( i=0; i<cm_nDaemons; i++) { if (cm_BkgDaemon_ShutdownEvent[i]) code = thrd_WaitForSingleObject_Event(cm_BkgDaemon_ShutdownEvent[i], INFINITE); } if (cm_IPAddrDaemon_ShutdownEvent) code = thrd_WaitForSingleObject_Event(cm_IPAddrDaemon_ShutdownEvent, INFINITE); }
int fsprobe_Init(int a_numServers, struct sockaddr_in *a_socketArray, int a_ProbeFreqInSecs, int (*a_ProbeHandler)(void), int a_debug) { /*fsprobe_Init */ static char rn[] = "fsprobe_Init"; /*Routine name */ register afs_int32 code; /*Return value */ static struct rx_securityClass *CBsecobj; /*Callback security object */ struct rx_securityClass *secobj; /*Client security object */ struct rx_service *rxsrv_afsserver; /*Server for AFS */ int arg_errfound; /*Argument error found? */ int curr_srv; /*Current server idx */ struct fsprobe_ConnectionInfo *curr_conn; /*Ptr to current conn */ char *hostNameFound; /*Ptr to returned host name */ int conn_err; /*Connection error? */ int PortToUse; /*Callback port to use */ /* * If we've already been called, snicker at the bozo, gently * remind him of his doubtful heritage, and return success. */ if (fsprobe_initflag) { fprintf(stderr, "[%s] Called multiple times!\n", rn); return (0); } else fsprobe_initflag = 1; /* * Check the parameters for bogosities. */ arg_errfound = 0; if (a_numServers <= 0) { fprintf(stderr, "[%s] Illegal number of servers: %d\n", rn, a_numServers); arg_errfound = 1; } if (a_socketArray == (struct sockaddr_in *)0) { fprintf(stderr, "[%s] Null server socket array argument\n", rn); arg_errfound = 1; } if (a_ProbeFreqInSecs <= 0) { fprintf(stderr, "[%s] Illegal probe frequency: %d\n", rn, a_ProbeFreqInSecs); arg_errfound = 1; } if (a_ProbeHandler == (int (*)())0) { fprintf(stderr, "[%s] Null probe handler function argument\n", rn); arg_errfound = 1; } if (arg_errfound) return (-1); /* * Record our passed-in info. */ fsprobe_debug = a_debug; fsprobe_numServers = a_numServers; fsprobe_Handler = a_ProbeHandler; fsprobe_ProbeFreqInSecs = a_ProbeFreqInSecs; /* * Get ready in case we have to do a cleanup - basically, zero * everything out. */ fsprobe_CleanupInit(); /* * Allocate the necessary data structures and initialize everything * else. */ fsprobe_ConnInfo = (struct fsprobe_ConnectionInfo *) malloc(a_numServers * sizeof(struct fsprobe_ConnectionInfo)); if (fsprobe_ConnInfo == (struct fsprobe_ConnectionInfo *)0) { fprintf(stderr, "[%s] Can't allocate %d connection info structs (%"AFS_SIZET_FMT" bytes)\n", rn, a_numServers, (a_numServers * sizeof(struct fsprobe_ConnectionInfo))); return (-1); /*No cleanup needs to be done yet */ } #if 0 else fprintf(stderr, "[%s] fsprobe_ConnInfo allocated (%d bytes)\n", rn, a_numServers * sizeof(struct fsprobe_ConnectionInfo)); #endif /* 0 */ fsprobe_statsBytes = a_numServers * sizeof(struct ProbeViceStatistics); fsprobe_Results.stats = (struct ProbeViceStatistics *) malloc(fsprobe_statsBytes); if (fsprobe_Results.stats == NULL) { fprintf(stderr, "[%s] Can't allocate %d statistics structs (%d bytes)\n", rn, a_numServers, fsprobe_statsBytes); fsprobe_Cleanup(1); /*Delete already-malloc'ed areas */ return (-1); } else if (fsprobe_debug) fprintf(stderr, "[%s] fsprobe_Results.stats allocated (%d bytes)\n", rn, fsprobe_statsBytes); fsprobe_probeOKBytes = a_numServers * sizeof(int); fsprobe_Results.probeOK = (int *)malloc(fsprobe_probeOKBytes); if (fsprobe_Results.probeOK == (int *)0) { fprintf(stderr, "[%s] Can't allocate %d probeOK array entries (%d bytes)\n", rn, a_numServers, fsprobe_probeOKBytes); fsprobe_Cleanup(1); /*Delete already-malloc'ed areas */ return (-1); } else if (fsprobe_debug) fprintf(stderr, "[%s] fsprobe_Results.probeOK allocated (%d bytes)\n", rn, fsprobe_probeOKBytes); fsprobe_Results.probeNum = 0; fsprobe_Results.probeTime = 0; memset(fsprobe_Results.stats, 0, (a_numServers * sizeof(struct ProbeViceStatistics))); /* * Initialize the Rx subsystem, just in case nobody's done it. */ if (fsprobe_debug) fprintf(stderr, "[%s] Initializing Rx\n", rn); PortToUse = FSPROBE_CBPORT; do { code = rx_Init(htons(PortToUse)); if (code) { if (code == RX_ADDRINUSE) { if (fsprobe_debug) fprintf(stderr, "[%s] Callback port %d in use, advancing\n", rn, PortToUse); PortToUse++; } else { fprintf(stderr, "[%s] Fatal error in rx_Init()\n", rn); return (-1); } } } while (code); if (fsprobe_debug) fprintf(stderr, "[%s] Rx initialized on port %d\n", rn, PortToUse); /* * Create a null Rx server security object, to be used by the * Callback listener. */ CBsecobj = rxnull_NewServerSecurityObject(); if (CBsecobj == (struct rx_securityClass *)0) { fprintf(stderr, "[%s] Can't create null security object for the callback listener.\n", rn); fsprobe_Cleanup(1); /*Delete already-malloc'ed areas */ return (-1); } if (fsprobe_debug) fprintf(stderr, "[%s] Callback server security object created\n", rn); /* * Create a null Rx client security object, to be used by the * probe LWP. */ secobj = rxnull_NewClientSecurityObject(); if (secobj == (struct rx_securityClass *)0) { fprintf(stderr, "[%s] Can't create client security object for probe LWP.\n", rn); fsprobe_Cleanup(1); /*Delete already-malloc'ed areas */ return (-1); } if (fsprobe_debug) fprintf(stderr, "[%s] Probe LWP client security object created\n", rn); curr_conn = fsprobe_ConnInfo; conn_err = 0; for (curr_srv = 0; curr_srv < a_numServers; curr_srv++) { /* * Copy in the socket info for the current server, resolve its * printable name if possible. */ if (fsprobe_debug) { fprintf(stderr, "[%s] Copying in the following socket info:\n", rn); fprintf(stderr, "[%s] IP addr 0x%x, port %d\n", rn, (a_socketArray + curr_srv)->sin_addr.s_addr, (a_socketArray + curr_srv)->sin_port); } memcpy(&(curr_conn->skt), a_socketArray + curr_srv, sizeof(struct sockaddr_in)); hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr); if (hostNameFound == NULL) { fprintf(stderr, "[%s] Can't map Internet address %u to a string name\n", rn, curr_conn->skt.sin_addr.s_addr); curr_conn->hostName[0] = '\0'; } else { strcpy(curr_conn->hostName, hostNameFound); if (fsprobe_debug) fprintf(stderr, "[%s] Host name for server index %d is %s\n", rn, curr_srv, curr_conn->hostName); } /* * Make an Rx connection to the current server. */ if (fsprobe_debug) fprintf(stderr, "[%s] Connecting to srv idx %d, IP addr 0x%x, port %d, service 1\n", rn, curr_srv, curr_conn->skt.sin_addr.s_addr, curr_conn->skt.sin_port); curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr, /*Server addr */ curr_conn->skt.sin_port, /*Server port */ 1, /*AFS service num */ secobj, /*Security object */ 0); /*Number of above */ if (curr_conn->rxconn == (struct rx_connection *)0) { fprintf(stderr, "[%s] Can't create Rx connection to server %s (%u)\n", rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr); conn_err = 1; } if (fsprobe_debug) fprintf(stderr, "[%s] New connection at %p\n", rn, curr_conn->rxconn); /* * Make an Rx connection to the current volume server. */ if (fsprobe_debug) fprintf(stderr, "[%s] Connecting to srv idx %d, IP addr 0x%x, port %d, service 1\n", rn, curr_srv, curr_conn->skt.sin_addr.s_addr, htons(7005)); curr_conn->rxVolconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr, /*Server addr */ htons(AFSCONF_VOLUMEPORT), /*Volume Server port */ VOLSERVICE_ID, /*AFS service num */ secobj, /*Security object */ 0); /*Number of above */ if (curr_conn->rxVolconn == (struct rx_connection *)0) { fprintf(stderr, "[%s] Can't create Rx connection to volume server %s (%u)\n", rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr); conn_err = 1; } else { int i, cnt; memset(&curr_conn->partList, 0, sizeof(struct partList)); curr_conn->partCnt = 0; i = XListPartitions(curr_conn->rxVolconn, &curr_conn->partList, &cnt); if (!i) { curr_conn->partCnt = cnt; } } if (fsprobe_debug) fprintf(stderr, "[%s] New connection at %p\n", rn, curr_conn->rxVolconn); /* * Bump the current fsprobe connection to set up. */ curr_conn++; } /*for curr_srv */ /* * Create the AFS callback service (listener). */ if (fsprobe_debug) fprintf(stderr, "[%s] Creating AFS callback listener\n", rn); rxsrv_afsserver = rx_NewService(0, /*Use default port */ 1, /*Service ID */ "afs", /*Service name */ &CBsecobj, /*Ptr to security object(s) */ 1, /*Number of security objects */ RXAFSCB_ExecuteRequest); /*Dispatcher */ if (rxsrv_afsserver == (struct rx_service *)0) { fprintf(stderr, "[%s] Can't create callback Rx service/listener\n", rn); fsprobe_Cleanup(1); /*Delete already-malloc'ed areas */ return (-1); } if (fsprobe_debug) fprintf(stderr, "[%s] Callback listener created\n", rn); /* * Start up the AFS callback service. */ if (fsprobe_debug) fprintf(stderr, "[%s] Starting up callback listener.\n", rn); rx_StartServer(0 /*Don't donate yourself to LWP pool */ ); /* * Start up the probe LWP. */ if (fsprobe_debug) fprintf(stderr, "[%s] Creating the probe LWP\n", rn); code = LWP_CreateProcess(fsprobe_LWP, /*Function to start up */ LWP_STACK_SIZE, /*Stack size in bytes */ 1, /*Priority */ (void *)0, /*Parameters */ "fsprobe Worker", /*Name to use */ &probeLWP_ID); /*Returned LWP process ID */ if (code) { fprintf(stderr, "[%s] Can't create fsprobe LWP! Error is %d\n", rn, code); fsprobe_Cleanup(1); /*Delete already-malloc'ed areas */ return (code); } if (fsprobe_debug) fprintf(stderr, "[%s] Probe LWP process structure located at %p\n", rn, probeLWP_ID); #if 0 /* * Do I need to do this? */ if (fsprobe_debug) fprintf(stderr, "[%s] Calling osi_Wakeup()\n", rn); osi_Wakeup(&rxsrv_afsserver); /*Wake up anyone waiting for it */ #endif /* 0 */ /* * Return the final results. */ if (conn_err) return (-2); else return (0); } /*fsprobe_Init */
void cm_PingServer(cm_server_t *tsp) { long code; int wasDown = 0; cm_conn_t *connp; struct rx_connection * rxconnp; Capabilities caps = {0, 0}; char hoststr[16]; cm_req_t req; lock_ObtainMutex(&tsp->mx); if (InterlockedIncrement(&tsp->pingCount) > 1) { tsp->waitCount++; osi_SleepM((LONG_PTR)tsp, &tsp->mx); lock_ObtainMutex(&tsp->mx); InterlockedDecrement(&tsp->pingCount); if (--tsp->waitCount > 0) osi_Wakeup((LONG_PTR)tsp); lock_ReleaseMutex(&tsp->mx); return; } wasDown = tsp->flags & CM_SERVERFLAG_DOWN; afs_inet_ntoa_r(tsp->addr.sin_addr.S_un.S_addr, hoststr); lock_ReleaseMutex(&tsp->mx); if (cm_noIPAddr > 0) code = cm_ConnByServer(tsp, cm_rootUserp, FALSE, &connp); else code = RX_CALL_DEAD; /* No network */ if (code == 0) { /* now call the appropriate ping call. Drop the timeout if * the server is known to be down, so that we don't waste a * lot of time retiming out down servers. */ osi_Log4(afsd_logp, "cm_PingServer server %s (%s) was %s with caps 0x%x", osi_LogSaveString(afsd_logp, hoststr), tsp->type == CM_SERVER_VLDB ? "vldb" : "file", wasDown ? "down" : "up", tsp->capabilities); rxconnp = cm_GetRxConn(connp); if (wasDown) rx_SetConnHardDeadTime(rxconnp, 10); if (tsp->type == CM_SERVER_VLDB) { code = VL_ProbeServer(rxconnp); } else { /* file server */ code = RXAFS_GetCapabilities(rxconnp, &caps); } if (wasDown) rx_SetConnHardDeadTime(rxconnp, HardDeadtimeout); rx_PutConnection(rxconnp); cm_PutConn(connp); } /* got an unauthenticated connection to this server */ lock_ObtainMutex(&tsp->mx); if (code >= 0 || code == RXGEN_OPCODE) { /* mark server as up */ _InterlockedAnd(&tsp->flags, ~CM_SERVERFLAG_DOWN); tsp->downTime = 0; /* we currently handle 32-bits of capabilities */ if (code != RXGEN_OPCODE && caps.Capabilities_len > 0) { tsp->capabilities = caps.Capabilities_val[0]; xdr_free((xdrproc_t) xdr_Capabilities, &caps); caps.Capabilities_len = 0; caps.Capabilities_val = 0; } else { tsp->capabilities = 0; } osi_Log3(afsd_logp, "cm_PingServer server %s (%s) is up with caps 0x%x", osi_LogSaveString(afsd_logp, hoststr), tsp->type == CM_SERVER_VLDB ? "vldb" : "file", tsp->capabilities); /* Now update the volume status if necessary */ if (wasDown) { cm_server_vols_t * tsrvp; cm_volume_t * volp; int i; for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) { for (i=0; i<NUM_SERVER_VOLS; i++) { if (tsrvp->ids[i] != 0) { cm_InitReq(&req); lock_ReleaseMutex(&tsp->mx); code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp, &req, CM_GETVOL_FLAG_NO_LRU_UPDATE, &volp); lock_ObtainMutex(&tsp->mx); if (code == 0) { cm_UpdateVolumeStatus(volp, tsrvp->ids[i]); cm_PutVolume(volp); } } } } cm_RankServer(tsp); } } else { cm_MarkServerDown(tsp, code, wasDown); osi_Log3(afsd_logp, "cm_PingServer server %s (%s) is down with caps 0x%x", osi_LogSaveString(afsd_logp, hoststr), tsp->type == CM_SERVER_VLDB ? "vldb" : "file", tsp->capabilities); } InterlockedDecrement(&tsp->pingCount); if (tsp->waitCount > 0) osi_Wakeup((LONG_PTR)tsp); lock_ReleaseMutex(&tsp->mx); }