#include <afs/param.h>
#include <afs/stds.h>
-#ifndef DJGPP
#include <windows.h>
-#endif /* !DJGPP */
#include <string.h>
#include <malloc.h>
#include <osi.h>
+#include "afsd.h"
#include <rx/rx.h>
-#ifndef DJGPP
-#include <rx/rxkad.h>
-#else
#include <rx/rxkad.h>
-#endif
-
-#include "afsd.h"
+#include <afs/unified_afs.h>
+#include <WINNT/afsreg.h>
osi_rwlock_t cm_connLock;
-long RDRtimeout = CM_CONN_DEFAULTRDRTIMEOUT;
-long ConnDeadtimeout = CM_CONN_CONNDEADTIME;
-long HardDeadtimeout = CM_CONN_HARDDEADTIME;
+DWORD RDRtimeout = CM_CONN_DEFAULTRDRTIMEOUT;
+unsigned short ConnDeadtimeout = CM_CONN_CONNDEADTIME;
+unsigned short HardDeadtimeout = CM_CONN_HARDDEADTIME;
#define LANMAN_WKS_PARAM_KEY "SYSTEM\\CurrentControlSet\\Services\\lanmanworkstation\\parameters"
#define LANMAN_WKS_SESSION_TIMEOUT "SessTimeout"
void cm_PutConn(cm_conn_t *connp)
{
lock_ObtainWrite(&cm_connLock);
- osi_assert(connp->refCount-- > 0);
+ osi_assertx(connp->refCount-- > 0, "cm_conn_t refcount 0");
lock_ReleaseWrite(&cm_connLock);
}
void cm_InitConn(void)
{
- static osi_once_t once;
- long code;
- DWORD sessTimeout;
- HKEY parmKey;
+ static osi_once_t once;
+ long code;
+ DWORD dwValue;
+ DWORD dummyLen;
+ HKEY parmKey;
if (osi_Once(&once)) {
- lock_InitializeRWLock(&cm_connLock, "connection global lock");
+ lock_InitializeRWLock(&cm_connLock, "connection global lock");
/* keisa - read timeout value for lanmanworkstation service.
* jaltman - as per
* I believe that the default should not be short. Instead, we should wait until
* RX times out before reporting a timeout to the SMB client.
*/
- code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LANMAN_WKS_PARAM_KEY,
- 0, KEY_QUERY_VALUE, &parmKey);
- if (code == ERROR_SUCCESS)
+ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LANMAN_WKS_PARAM_KEY,
+ 0, KEY_QUERY_VALUE, &parmKey);
+ if (code == ERROR_SUCCESS)
{
- DWORD dummyLen = sizeof(sessTimeout);
- code = RegQueryValueEx(parmKey, LANMAN_WKS_SESSION_TIMEOUT, NULL, NULL,
- (BYTE *) &sessTimeout, &dummyLen);
- if (code == ERROR_SUCCESS)
- {
- afsi_log("lanmanworkstation : SessTimeout %d", sessTimeout);
- RDRtimeout = sessTimeout;
- if ( ConnDeadtimeout < RDRtimeout + 15 ) {
- ConnDeadtimeout = RDRtimeout + 15;
- afsi_log("ConnDeadTimeout increased to %d", ConnDeadtimeout);
- }
- if ( HardDeadtimeout < 2 * ConnDeadtimeout ) {
- HardDeadtimeout = 2 * ConnDeadtimeout;
- afsi_log("HardDeadTimeout increased to %d", HardDeadtimeout);
- }
- }
+ dummyLen = sizeof(DWORD);
+ code = RegQueryValueEx(parmKey, LANMAN_WKS_SESSION_TIMEOUT, NULL, NULL,
+ (BYTE *) &dwValue, &dummyLen);
+ if (code == ERROR_SUCCESS)
+ RDRtimeout = dwValue;
+ RegCloseKey(parmKey);
}
- osi_EndOnce(&once);
+ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
+ 0, KEY_QUERY_VALUE, &parmKey);
+ if (code == ERROR_SUCCESS) {
+ dummyLen = sizeof(DWORD);
+ code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
+ (BYTE *) &dwValue, &dummyLen);
+ if (code == ERROR_SUCCESS)
+ ConnDeadtimeout = (unsigned short)dwValue;
+
+ dummyLen = sizeof(DWORD);
+ code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
+ (BYTE *) &dwValue, &dummyLen);
+ if (code == ERROR_SUCCESS)
+ HardDeadtimeout = (unsigned short)dwValue;
+ afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
+ RegCloseKey(parmKey);
+ }
+
+ afsi_log("lanmanworkstation : SessTimeout %u", RDRtimeout);
+ if (ConnDeadtimeout == 0)
+ ConnDeadtimeout = (unsigned short) (RDRtimeout / 2);
+ afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
+ if (HardDeadtimeout == 0)
+ HardDeadtimeout = (unsigned short) RDRtimeout;
+ afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
+
+ osi_EndOnce(&once);
}
}
void cm_InitReq(cm_req_t *reqp)
{
memset((char *)reqp, 0, sizeof(cm_req_t));
-#ifndef DJGPP
- reqp->startTime = GetCurrentTime();
-#else
- gettimeofday(&reqp->startTime, NULL);
-#endif
+ reqp->startTime = GetTickCount();
}
static long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp,
if (!fidp) {
*serversppp = NULL;
- return 0;
+ return CM_ERROR_INVAL;
}
- cellp = cm_FindCellByID(fidp->cell);
- if (!cellp) return CM_ERROR_NOSUCHCELL;
+ cellp = cm_FindCellByID(fidp->cell, 0);
+ if (!cellp)
+ return CM_ERROR_NOSUCHCELL;
- code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp, &volp);
- if (code) return code;
+ code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp, CM_GETVOL_FLAG_CREATE, &volp);
+ if (code)
+ return code;
*serversppp = cm_GetVolServers(volp, fidp->volume);
* and if we're going to retry, determine whether failover is appropriate,
* and whether timed backoff is appropriate.
*
- * If the error code is from cm_Conn() or friends, it will be a CM_ERROR code.
+ * If the error code is from cm_ConnFromFID() or friends, it will be a CM_ERROR code.
* Otherwise it will be an RPC code. This may be a UNIX code (e.g. EDQUOT), or
* it may be an RX code, or it may be a special code (e.g. VNOVOL), or it may
* be a security code (e.g. RXKADEXPIRED).
*
- * If the error code is from cm_Conn() or friends, connp will be NULL.
+ * If the error code is from cm_ConnFromFID() or friends, connp will be NULL.
*
* For VLDB calls, fidp will be NULL.
*
cm_serverRef_t * serversp,
cm_callbackRequest_t *cbrp, long errorCode)
{
- cm_server_t *serverp = 0;
- cm_serverRef_t **serverspp = 0;
+ cm_server_t *serverp = NULL;
+ cm_serverRef_t **serverspp = NULL;
cm_serverRef_t *tsrp;
+ cm_cell_t *cellp = NULL;
cm_ucell_t *ucellp;
+ cm_volume_t * volp = NULL;
+ cm_vol_state_t *statep = NULL;
int retry = 0;
int free_svr_list = 0;
int dead_session;
long timeUsed, timeLeft;
-
- osi_Log2(afsd_logp, "cm_Analyze connp 0x%x, code 0x%x",
- (long) connp, errorCode);
+ long code;
+ char addr[16];
+ int forcing_new = 0;
+
+ osi_Log2(afsd_logp, "cm_Analyze connp 0x%p, code 0x%x",
+ connp, errorCode);
/* no locking required, since connp->serverp never changes after
* creation */
lock_ReleaseWrite(&cm_callbackLock);
}
- /* If not allowed to retry, don't */
- if (reqp->flags & CM_REQ_NORETRY)
- goto out;
-
- /* if timeout - check that it did not exceed the SMB timeout
+ /* if timeout - check that it did not exceed the HardDead timeout
* and retry */
/* timeleft - get if from reqp the same way as cmXonnByMServers does */
-#ifndef DJGPP
- timeUsed = (GetCurrentTime() - reqp->startTime) / 1000;
-#else
- gettimeofday(&now, NULL);
- timeUsed = sub_time(now, reqp->startTime) / 1000;
-#endif
+ timeUsed = (GetTickCount() - reqp->startTime) / 1000;
/* leave 5 seconds margin for sleep */
- timeLeft = RDRtimeout - timeUsed;
+ timeLeft = HardDeadtimeout - timeUsed;
+
+ /* get a pointer to the cell */
+ if (errorCode) {
+ if (cellp == NULL && serverp)
+ cellp = serverp->cellp;
+ if (cellp == NULL && serversp) {
+ struct cm_serverRef * refp;
+ for ( refp=serversp ; cellp == NULL && refp != NULL; refp=refp->next) {
+ if ( refp->server )
+ cellp = refp->server->cellp;
+ }
+ }
+ if (cellp == NULL && fidp) {
+ cellp = cm_FindCellByID(fidp->cell, 0);
+ }
+ }
if (errorCode == CM_ERROR_TIMEDOUT) {
if (timeLeft > 5 ) {
thrd_Sleep(3000);
- cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, NULL);
+ cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, cellp);
+ retry = 1;
+ }
+ }
+
+ else if (errorCode == UAEWOULDBLOCK || errorCode == EWOULDBLOCK ||
+ errorCode == UAEAGAIN || errorCode == EAGAIN) {
+ osi_Log0(afsd_logp, "cm_Analyze passed EWOULDBLOCK or EAGAIN.");
+ if (timeLeft > 5 ) {
+ thrd_Sleep(1000);
retry = 1;
}
- }
+ }
/* if there is nosuchvolume, then we have a situation in which a
* previously known volume no longer has a set of servers
* until the timeout period expires.
*/
else if (errorCode == CM_ERROR_NOSUCHVOLUME) {
+ osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_NOSUCHVOLUME.");
if (timeLeft > 7) {
- osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_NOSUCHVOLUME.");
thrd_Sleep(5000);
retry = 1;
}
}
+ else if (errorCode == CM_ERROR_ALLDOWN) {
+ osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLDOWN.");
+ /* Servers marked DOWN will be restored by the background daemon
+ * thread as they become available.
+ */
+ }
+
else if (errorCode == CM_ERROR_ALLOFFLINE) {
- if (timeLeft > 7) {
- osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE.");
+ osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE.");
+ /* Volume instances marked offline will be restored by the
+ * background daemon thread as they become available
+ */
+ if (timeLeft > 7 && fidp) {
thrd_Sleep(5000);
- /* cm_ForceUpdateVolume marks all servers as non_busy */
- /* No it doesn't and it won't do anything if all of the
- * the servers are marked as DOWN. So clear the DOWN
- * flag and reset the busy state as well.
- */
- if (!serversp) {
- cm_GetServerList(fidp, userp, reqp, &serverspp);
- serversp = *serverspp;
- free_svr_list = 1;
- }
- if (serversp) {
- lock_ObtainWrite(&cm_serverLock);
- for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
- tsrp->server->flags &= ~CM_SERVERFLAG_DOWN;
- if (tsrp->status == busy)
- tsrp->status = not_busy;
- }
- lock_ReleaseWrite(&cm_serverLock);
- if (free_svr_list) {
- cm_FreeServerList(&serversp);
- *serverspp = serversp;
+
+ code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp,
+ CM_GETVOL_FLAG_NO_LRU_UPDATE,
+ &volp);
+ if (code == 0) {
+ if (fidp->volume == volp->rw.ID)
+ statep = &volp->rw;
+ else if (fidp->volume == volp->ro.ID)
+ statep = &volp->ro;
+ else if (fidp->volume == volp->bk.ID)
+ statep = &volp->bk;
+
+ if (statep->state != vl_offline && statep->state != vl_unknown) {
+ retry = 1;
+ } else {
+ if (cm_CheckOfflineVolume(volp, statep->ID))
+ retry = 1;
}
- retry = 1;
+
+ cm_PutVolume(volp);
}
-
- if (fidp != NULL) /* Not a VLDB call */
- cm_ForceUpdateVolume(fidp, userp, reqp);
}
}
-
- /* if all servers are busy, mark them non-busy and start over */
else if (errorCode == CM_ERROR_ALLBUSY) {
+ /* Volumes that are busy cannot be determined to be non-busy
+ * without actually attempting to access them.
+ */
+ osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY.");
if (timeLeft > 7) {
+
thrd_Sleep(5000);
- if (!serversp) {
- cm_GetServerList(fidp, userp, reqp, &serverspp);
- serversp = *serverspp;
- free_svr_list = 1;
- }
- lock_ObtainWrite(&cm_serverLock);
- for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
- if (tsrp->status == busy)
- tsrp->status = not_busy;
- }
- lock_ReleaseWrite(&cm_serverLock);
- if (free_svr_list) {
- cm_FreeServerList(&serversp);
- *serverspp = serversp;
+
+ if (fidp) { /* File Server query */
+ code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp,
+ CM_GETVOL_FLAG_NO_LRU_UPDATE,
+ &volp);
+ if (code == 0) {
+ if (fidp->volume == volp->rw.ID)
+ statep = &volp->rw;
+ else if (fidp->volume == volp->ro.ID)
+ statep = &volp->ro;
+ else if (fidp->volume == volp->bk.ID)
+ statep = &volp->bk;
+
+ if (statep->state != vl_offline &&
+ statep->state != vl_busy &&
+ statep->state != vl_unknown) {
+ retry = 1;
+ } else {
+ if (!serversp) {
+ code = cm_GetServerList(fidp, userp, reqp, &serverspp);
+ if (code == 0) {
+ serversp = *serverspp;
+ free_svr_list = 1;
+ }
+ }
+ lock_ObtainWrite(&cm_serverLock);
+ for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
+ if (tsrp->status == srv_busy) {
+ tsrp->status = srv_not_busy;
+ }
+ }
+ lock_ReleaseWrite(&cm_serverLock);
+ if (free_svr_list) {
+ cm_FreeServerList(&serversp, 0);
+ *serverspp = serversp;
+ }
+
+ cm_UpdateVolumeStatus(volp, statep->ID);
+ retry = 1;
+ }
+
+ cm_PutVolume(volp);
+ }
+ } else { /* VL Server query */
+ if (serversp) {
+ lock_ObtainWrite(&cm_serverLock);
+ for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
+ if (tsrp->status == srv_busy) {
+ tsrp->status = srv_not_busy;
+ }
+ }
+ lock_ReleaseWrite(&cm_serverLock);
+ retry = 1;
+ }
}
- retry = 1;
}
}
/* special codes: VBUSY and VRESTARTING */
else if (errorCode == VBUSY || errorCode == VRESTARTING) {
- if (!serversp) {
- cm_GetServerList(fidp, userp, reqp, &serverspp);
- serversp = *serverspp;
- free_svr_list = 1;
+ if (!serversp && fidp) {
+ code = cm_GetServerList(fidp, userp, reqp, &serverspp);
+ if (code == 0) {
+ serversp = *serverspp;
+ free_svr_list = 1;
+ }
}
lock_ObtainWrite(&cm_serverLock);
for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
- if (tsrp->server == serverp
- && tsrp->status == not_busy) {
- tsrp->status = busy;
+ if (tsrp->server == serverp && tsrp->status == srv_not_busy) {
+ tsrp->status = srv_busy;
+ if (fidp) { /* File Server query */
+ code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp,
+ CM_GETVOL_FLAG_NO_LRU_UPDATE,
+ &volp);
+ if (code == 0) {
+ if (fidp->volume == volp->rw.ID)
+ statep = &volp->rw;
+ else if (fidp->volume == volp->ro.ID)
+ statep = &volp->ro;
+ else if (fidp->volume == volp->bk.ID)
+ statep = &volp->bk;
+ }
+ }
break;
}
}
lock_ReleaseWrite(&cm_serverLock);
+
+ if (statep) {
+ cm_UpdateVolumeStatus(volp, statep->ID);
+ cm_PutVolume(volp);
+ }
+
if (free_svr_list) {
- cm_FreeServerList(&serversp);
+ cm_FreeServerList(&serversp, 0);
*serverspp = serversp;
}
retry = 1;
}
/* special codes: missing volumes */
- else if (errorCode == VNOVOL || errorCode == VMOVED || errorCode == VOFFLINE
- || errorCode == VSALVAGE || errorCode == VNOSERVICE)
+ else if (errorCode == VNOVOL || errorCode == VMOVED || errorCode == VOFFLINE ||
+ errorCode == VSALVAGE || errorCode == VNOSERVICE || errorCode == VIO)
{
- /* Log server being offline for this volume */
- osi_Log4(afsd_logp, "cm_Analyze found server %d.%d.%d.%d marked offline for a volume",
- ((serverp->addr.sin_addr.s_addr & 0xff)),
- ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
- ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
- ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
- /* Create Event Log message */
- {
- HANDLE h;
- char *ptbuf[1];
- char s[100];
- h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
- sprintf(s, "cm_Analyze: Server %d.%d.%d.%d reported volume %d as missing.",
- ((serverp->addr.sin_addr.s_addr & 0xff)),
- ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
- ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
- ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24),
- fidp->volume);
- ptbuf[0] = s;
- ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1009, NULL,
- 1, 0, ptbuf, NULL);
- DeregisterEventSource(h);
+ char addr[16];
+ char *format;
+ DWORD msgID;
+ switch ( errorCode ) {
+ case VNOVOL:
+ msgID = MSG_SERVER_REPORTS_VNOVOL;
+ format = "Server %s reported volume %d as not attached.";
+ break;
+ case VMOVED:
+ msgID = MSG_SERVER_REPORTS_VMOVED;
+ format = "Server %s reported volume %d as moved.";
+ break;
+ case VOFFLINE:
+ msgID = MSG_SERVER_REPORTS_VOFFLINE;
+ format = "Server %s reported volume %d as offline.";
+ break;
+ case VSALVAGE:
+ msgID = MSG_SERVER_REPORTS_VSALVAGE;
+ format = "Server %s reported volume %d as needs salvage.";
+ break;
+ case VNOSERVICE:
+ msgID = MSG_SERVER_REPORTS_VNOSERVICE;
+ format = "Server %s reported volume %d as not in service.";
+ break;
+ case VIO:
+ msgID = MSG_SERVER_REPORTS_VIO;
+ format = "Server %s reported volume %d as temporarily unaccessible.";
+ break;
+ }
+
+ if (serverp && fidp) {
+ /* Log server being offline for this volume */
+ sprintf(addr, "%d.%d.%d.%d",
+ ((serverp->addr.sin_addr.s_addr & 0xff)),
+ ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
+ ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
+ ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
+
+ osi_Log2(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume);
+ LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume);
}
/* Mark server offline for this volume */
- if (!serversp) {
- cm_GetServerList(fidp, userp, reqp, &serverspp);
- serversp = *serverspp;
- free_svr_list = 1;
+ if (!serversp && fidp) {
+ code = cm_GetServerList(fidp, userp, reqp, &serverspp);
+ if (code == 0) {
+ serversp = *serverspp;
+ free_svr_list = 1;
+ }
}
+
+ lock_ObtainWrite(&cm_serverLock);
for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
- if (tsrp->server == serverp)
- tsrp->status = offline;
+ if (tsrp->server == serverp) {
+ /* REDIRECT */
+ if (errorCode == VMOVED) {
+ tsrp->status = srv_deleted;
+ } else {
+ tsrp->status = srv_offline;
+ }
+
+ if (fidp) { /* File Server query */
+ code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp,
+ CM_GETVOL_FLAG_NO_LRU_UPDATE,
+ &volp);
+ if (code == 0) {
+ if (fidp->volume == volp->rw.ID)
+ statep = &volp->rw;
+ else if (fidp->volume == volp->ro.ID)
+ statep = &volp->ro;
+ else if (fidp->volume == volp->bk.ID)
+ statep = &volp->bk;
+ }
+ }
+ }
}
+ lock_ReleaseWrite(&cm_serverLock);
+
+ if (fidp && errorCode == VMOVED)
+ cm_ForceUpdateVolume(fidp, userp, reqp);
+
+ if (statep) {
+ cm_UpdateVolumeStatus(volp, statep->ID);
+ cm_PutVolume(volp);
+ }
+
if (free_svr_list) {
- cm_FreeServerList(&serversp);
+ cm_FreeServerList(&serversp, 0);
*serverspp = serversp;
}
if ( timeLeft > 2 )
retry = 1;
+ } else if ( errorCode == VNOVNODE ) {
+ if ( fidp ) {
+ cm_scache_t * scp;
+ osi_Log4(afsd_logp, "cm_Analyze passed VNOVNODE cell %u vol %u vn %u uniq %u.",
+ fidp->cell, fidp->volume, fidp->vnode, fidp->unique);
+
+ scp = cm_FindSCache(fidp);
+ if (scp) {
+ cm_scache_t *pscp = NULL;
+
+ if (scp->fileType != CM_SCACHETYPE_DIRECTORY)
+ pscp = cm_FindSCacheParent(scp);
+
+
+ lock_ObtainMutex(&scp->mx);
+ lock_ObtainWrite(&cm_scacheLock);
+ cm_RemoveSCacheFromHashTable(scp);
+ lock_ReleaseWrite(&cm_scacheLock);
+ cm_LockMarkSCacheLost(scp);
+ scp->flags |= CM_SCACHEFLAG_DELETED;
+ lock_ReleaseMutex(&scp->mx);
+ cm_ReleaseSCache(scp);
+
+ if (pscp) {
+ if (cm_HaveCallback(pscp)) {
+ lock_ObtainMutex(&pscp->mx);
+ cm_DiscardSCache(pscp);
+ lock_ReleaseMutex(&pscp->mx);
+ }
+ cm_ReleaseSCache(pscp);
+ }
+ }
+ } else {
+ osi_Log0(afsd_logp, "cm_Analyze passed VNOVNODE unknown fid.");
+ }
}
/* RX codes */
* this is to prevent the SMB session from timing out
* In addition, we log an event to the event log
*/
-#ifndef DJGPP
- HANDLE h;
- char *ptbuf[1];
- char s[100];
- h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
- sprintf(s, "cm_Analyze: HardDeadTime exceeded.");
- ptbuf[0] = s;
- ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1009, NULL,
- 1, 0, ptbuf, NULL);
- DeregisterEventSource(h);
-#endif /* !DJGPP */
+
+ /* Log server being offline for this volume */
+ sprintf(addr, "%d.%d.%d.%d",
+ ((serverp->addr.sin_addr.s_addr & 0xff)),
+ ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
+ ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
+ ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
+
+ LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_HARD_DEAD_TIME_EXCEEDED, addr);
retry = 0;
- osi_Log0(afsd_logp, "cm_Analyze: hardDeadTime exceeded");
+ osi_Log1(afsd_logp, "cm_Analyze: hardDeadTime exceeded addr[%s]",
+ osi_LogSaveString(afsd_logp,addr));
}
else if (errorCode >= -64 && errorCode < 0) {
/* mark server as down */
lock_ObtainMutex(&serverp->mx);
- serverp->flags |= CM_SERVERFLAG_DOWN;
+ if (reqp->flags & CM_REQ_NEW_CONN_FORCED) {
+ if (!(serverp->flags & CM_SERVERFLAG_DOWN)) {
+ serverp->flags |= CM_SERVERFLAG_DOWN;
+ serverp->downTime = time(NULL);
+ }
+ } else {
+ reqp->flags |= CM_REQ_NEW_CONN_FORCED;
+ forcing_new = 1;
+ }
lock_ReleaseMutex(&serverp->mx);
+ cm_ForceNewConnections(serverp);
if ( timeLeft > 2 )
retry = 1;
}
- else if (errorCode == RXKADEXPIRED ||
- errorCode == RXKADBADTICKET) {
+ else if (errorCode == RXKADEXPIRED) {
if (!dead_session) {
lock_ObtainMutex(&userp->mx);
ucellp = cm_GetUCell(userp, serverp->cellp);
if ( timeLeft > 2 )
retry = 1;
}
+ } else if (errorCode == VICECONNBAD || errorCode == VICETOKENDEAD) {
+ cm_ForceNewConnections(serverp);
+ if ( timeLeft > 2 )
+ retry = 1;
} else {
if (errorCode) {
char * s = "unknown error";
switch ( errorCode ) {
case RXKADINCONSISTENCY: s = "RXKADINCONSISTENCY"; break;
- case RXKADPACKETSHORT : s = "RXKADPACKETSHORT "; break;
- case RXKADLEVELFAIL : s = "RXKADLEVELFAIL "; break;
- case RXKADTICKETLEN : s = "RXKADTICKETLEN "; break;
+ case RXKADPACKETSHORT : s = "RXKADPACKETSHORT"; break;
+ case RXKADLEVELFAIL : s = "RXKADLEVELFAIL"; break;
+ case RXKADTICKETLEN : s = "RXKADTICKETLEN"; break;
case RXKADOUTOFSEQUENCE: s = "RXKADOUTOFSEQUENCE"; break;
- case RXKADNOAUTH : s = "RXKADNOAUTH "; break;
- case RXKADBADKEY : s = "RXKADBADKEY "; break;
- case RXKADBADTICKET : s = "RXKADBADTICKET "; break;
- case RXKADUNKNOWNKEY : s = "RXKADUNKNOWNKEY "; break;
- case RXKADEXPIRED : s = "RXKADEXPIRED "; break;
- case RXKADSEALEDINCON : s = "RXKADSEALEDINCON "; break;
- case RXKADDATALEN : s = "RXKADDATALEN "; break;
- case RXKADILLEGALLEVEL : s = "RXKADILLEGALLEVEL "; break;
+ case RXKADNOAUTH : s = "RXKADNOAUTH"; break;
+ case RXKADBADKEY : s = "RXKADBADKEY"; break;
+ case RXKADBADTICKET : s = "RXKADBADTICKET"; break;
+ case RXKADUNKNOWNKEY : s = "RXKADUNKNOWNKEY"; break;
+ case RXKADEXPIRED : s = "RXKADEXPIRED"; break;
+ case RXKADSEALEDINCON : s = "RXKADSEALEDINCON"; break;
+ case RXKADDATALEN : s = "RXKADDATALEN"; break;
+ case RXKADILLEGALLEVEL : s = "RXKADILLEGALLEVEL"; break;
+ case VSALVAGE : s = "VSALVAGE"; break;
+ case VNOVNODE : s = "VNOVNODE"; break;
+ case VNOVOL : s = "VNOVOL"; break;
+ case VVOLEXISTS : s = "VVOLEXISTS"; break;
+ case VNOSERVICE : s = "VNOSERVICE"; break;
+ case VOFFLINE : s = "VOFFLINE"; break;
+ case VONLINE : s = "VONLINE"; break;
+ case VDISKFULL : s = "VDISKFULL"; break;
+ case VOVERQUOTA : s = "VOVERQUOTA"; break;
+ case VBUSY : s = "VBUSY"; break;
+ case VMOVED : s = "VMOVED"; break;
+ case VIO : s = "VIO"; break;
+ case VRESTRICTED : s = "VRESTRICTED"; break;
+ case VRESTARTING : s = "VRESTARTING"; break;
+ case VREADONLY : s = "VREADONLY"; break;
+ case EAGAIN : s = "EAGAIN"; break;
+ case UAEAGAIN : s = "UAEAGAIN"; break;
+ case EINVAL : s = "EINVAL"; break;
+ case UAEINVAL : s = "UAEINVAL"; break;
+ case EACCES : s = "EACCES"; break;
+ case UAEACCES : s = "UAEACCES"; break;
+ case ENOENT : s = "ENOENT"; break;
+ case UAENOENT : s = "UAENOENT"; break;
+ case VICECONNBAD : s = "VICECONNBAD"; break;
+ case VICETOKENDEAD : s = "VICETOKENDEAD"; break;
+ case WSAEWOULDBLOCK : s = "WSAEWOULDBLOCK"; break;
+ case UAEWOULDBLOCK : s = "UAEWOULDBLOCK"; break;
+ case CM_ERROR_NOSUCHCELL : s = "CM_ERROR_NOSUCHCELL"; break;
+ case CM_ERROR_NOSUCHVOLUME : s = "CM_ERROR_NOSUCHVOLUME"; break;
+ case CM_ERROR_TIMEDOUT : s = "CM_ERROR_TIMEDOUT"; break;
+ case CM_ERROR_RETRY : s = "CM_ERROR_RETRY"; break;
+ case CM_ERROR_NOACCESS : s = "CM_ERROR_NOACCESS"; break;
+ case CM_ERROR_NOSUCHFILE : s = "CM_ERROR_NOSUCHFILE"; break;
+ case CM_ERROR_STOPNOW : s = "CM_ERROR_STOPNOW"; break;
+ case CM_ERROR_TOOBIG : s = "CM_ERROR_TOOBIG"; break;
+ case CM_ERROR_INVAL : s = "CM_ERROR_INVAL"; break;
+ case CM_ERROR_BADFD : s = "CM_ERROR_BADFD"; break;
+ case CM_ERROR_BADFDOP : s = "CM_ERROR_BADFDOP"; break;
+ case CM_ERROR_EXISTS : s = "CM_ERROR_EXISTS"; break;
+ case CM_ERROR_CROSSDEVLINK : s = "CM_ERROR_CROSSDEVLINK"; break;
+ case CM_ERROR_BADOP : s = "CM_ERROR_BADOP"; break;
+ case CM_ERROR_BADPASSWORD : s = "CM_ERROR_BADPASSWORD"; break;
+ case CM_ERROR_NOTDIR : s = "CM_ERROR_NOTDIR"; break;
+ case CM_ERROR_ISDIR : s = "CM_ERROR_ISDIR"; break;
+ case CM_ERROR_READONLY : s = "CM_ERROR_READONLY"; break;
+ case CM_ERROR_WOULDBLOCK : s = "CM_ERROR_WOULDBLOCK"; break;
+ case CM_ERROR_QUOTA : s = "CM_ERROR_QUOTA"; break;
+ case CM_ERROR_SPACE : s = "CM_ERROR_SPACE"; break;
+ case CM_ERROR_BADSHARENAME : s = "CM_ERROR_BADSHARENAME"; break;
+ case CM_ERROR_BADTID : s = "CM_ERROR_BADTID"; break;
+ case CM_ERROR_UNKNOWN : s = "CM_ERROR_UNKNOWN"; break;
+ case CM_ERROR_NOMORETOKENS : s = "CM_ERROR_NOMORETOKENS"; break;
+ case CM_ERROR_NOTEMPTY : s = "CM_ERROR_NOTEMPTY"; break;
+ case CM_ERROR_USESTD : s = "CM_ERROR_USESTD"; break;
+ case CM_ERROR_REMOTECONN : s = "CM_ERROR_REMOTECONN"; break;
+ case CM_ERROR_ATSYS : s = "CM_ERROR_ATSYS"; break;
+ case CM_ERROR_NOSUCHPATH : s = "CM_ERROR_NOSUCHPATH"; break;
+ case CM_ERROR_CLOCKSKEW : s = "CM_ERROR_CLOCKSKEW"; break;
+ case CM_ERROR_BADSMB : s = "CM_ERROR_BADSMB"; break;
+ case CM_ERROR_ALLBUSY : s = "CM_ERROR_ALLBUSY"; break;
+ case CM_ERROR_NOFILES : s = "CM_ERROR_NOFILES"; break;
+ case CM_ERROR_PARTIALWRITE : s = "CM_ERROR_PARTIALWRITE"; break;
+ case CM_ERROR_NOIPC : s = "CM_ERROR_NOIPC"; break;
+ case CM_ERROR_BADNTFILENAME : s = "CM_ERROR_BADNTFILENAME"; break;
+ case CM_ERROR_BUFFERTOOSMALL : s = "CM_ERROR_BUFFERTOOSMALL"; break;
+ case CM_ERROR_RENAME_IDENTICAL : s = "CM_ERROR_RENAME_IDENTICAL"; break;
+ case CM_ERROR_ALLOFFLINE : s = "CM_ERROR_ALLOFFLINE"; break;
+ case CM_ERROR_AMBIGUOUS_FILENAME: s = "CM_ERROR_AMBIGUOUS_FILENAME"; break;
+ case CM_ERROR_BADLOGONTYPE : s = "CM_ERROR_BADLOGONTYPE"; break;
+ case CM_ERROR_GSSCONTINUE : s = "CM_ERROR_GSSCONTINUE"; break;
+ case CM_ERROR_TIDIPC : s = "CM_ERROR_TIDIPC"; break;
+ case CM_ERROR_TOO_MANY_SYMLINKS : s = "CM_ERROR_TOO_MANY_SYMLINKS"; break;
+ case CM_ERROR_PATH_NOT_COVERED : s = "CM_ERROR_PATH_NOT_COVERED"; break;
+ case CM_ERROR_LOCK_CONFLICT : s = "CM_ERROR_LOCK_CONFLICT"; break;
+ case CM_ERROR_SHARING_VIOLATION : s = "CM_ERROR_SHARING_VIOLATION"; break;
+ case CM_ERROR_ALLDOWN : s = "CM_ERROR_ALLDOWN"; break;
+ case CM_ERROR_TOOFEWBUFS : s = "CM_ERROR_TOOFEWBUFS"; break;
+ case CM_ERROR_TOOMANYBUFS : s = "CM_ERROR_TOOMANYBUFS"; break;
}
osi_Log2(afsd_logp, "cm_Analyze: ignoring error code 0x%x (%s)",
errorCode, s);
+ retry = 0;
}
}
- if (retry && dead_session)
+ /* If not allowed to retry, don't */
+ if (!forcing_new && (reqp->flags & CM_REQ_NORETRY))
+ retry = 0;
+ else if (retry && dead_session)
retry = 0;
out:
cm_serverRef_t *tsrp;
cm_server_t *tsp;
long firstError = 0;
- int someBusy = 0, someOffline = 0, allBusy = 1, allDown = 1;
+ int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
long timeUsed, timeLeft, hardTimeLeft;
-#ifdef DJGPP
- struct timeval now;
-#endif /* DJGPP */
*connpp = NULL;
-#ifndef DJGPP
- timeUsed = (GetCurrentTime() - reqp->startTime) / 1000;
-#else
- gettimeofday(&now, NULL);
- timeUsed = sub_time(now, reqp->startTime) / 1000;
-#endif
+ if (serversp == NULL) {
+ osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", CM_ERROR_ALLDOWN);
+ return CM_ERROR_ALLDOWN;
+ }
+
+ timeUsed = (GetTickCount() - reqp->startTime) / 1000;
/* leave 5 seconds margin of safety */
timeLeft = ConnDeadtimeout - timeUsed - 5;
cm_GetServerNoLock(tsp);
lock_ReleaseWrite(&cm_serverLock);
if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
- if (tsrp->status == busy) {
- allDown = 0;
+ allDown = 0;
+ if (tsrp->status == srv_deleted) {
+ /* skip this entry. no longer valid. */;
+ } else if (tsrp->status == srv_busy) {
+ allOffline = 0;
someBusy = 1;
- } else if (tsrp->status == offline) {
- someOffline = 1;
+ } else if (tsrp->status == srv_offline) {
+ allBusy = 0;
+ someOffline = 1;
} else {
- allDown = 0;
+ allOffline = 0;
allBusy = 0;
code = cm_ConnByServer(tsp, usersp, connpp);
if (code == 0) { /* cm_CBS only returns 0 */
lock_ObtainWrite(&cm_serverLock);
cm_PutServerNoLock(tsp);
}
-
lock_ReleaseWrite(&cm_serverLock);
+
if (firstError == 0) {
- if (serversp == NULL)
- firstError = CM_ERROR_NOSUCHVOLUME;
- else if (allDown)
- firstError = CM_ERROR_ALLOFFLINE;
+ if (allDown)
+ firstError = CM_ERROR_ALLDOWN;
else if (allBusy)
firstError = CM_ERROR_ALLBUSY;
+ else if (allOffline || (someBusy && someOffline))
+ firstError = CM_ERROR_ALLOFFLINE;
else {
osi_Log0(afsd_logp, "cm_ConnByMServers returning impossible error TIMEDOUT");
firstError = CM_ERROR_TIMEDOUT;
serviceID = 52;
}
else {
- osi_assert(serverp->type == CM_SERVER_FILE);
+ osi_assertx(serverp->type == CM_SERVER_FILE, "incorrect server type");
port = htons(7000);
serviceID = 1;
}
tcp->cryptlevel = rxkad_clear;
secObjp = rxnull_NewClientSecurityObject();
}
- osi_assert(secObjp != NULL);
+ osi_assertx(secObjp != NULL, "null rx_securityClass");
tcp->callp = rx_NewConnection(serverp->addr.sin_addr.s_addr,
port,
serviceID,
cm_conn_t *tcp;
cm_ucell_t *ucellp;
+ *connpp = NULL;
+
lock_ObtainMutex(&userp->mx);
lock_ObtainWrite(&cm_connLock);
for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
tcp->refCount = 1;
lock_ReleaseMutex(&tcp->mx);
} else {
- if ((tcp->ucgen < ucellp->gen) ||
+ if ((tcp->flags & CM_CONN_FLAG_FORCE_NEW) ||
+ (tcp->ucgen < ucellp->gen) ||
(tcp->cryptlevel != (cryptall ? (ucellp->flags & CM_UCELLFLAG_RXKAD ? rxkad_crypt : rxkad_clear) : rxkad_clear)))
{
if (tcp->ucgen < ucellp->gen)
else
osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to crypt change");
lock_ObtainMutex(&tcp->mx);
+ tcp->flags &= ~CM_CONN_FLAG_FORCE_NEW;
rx_DestroyConnection(tcp->callp);
cm_NewRXConnection(tcp, ucellp, serverp);
lock_ReleaseMutex(&tcp->mx);
lock_ReleaseMutex(&userp->mx);
/* return this pointer to our caller */
- osi_Log1(afsd_logp, "cm_ConnByServer returning conn 0x%x", (long) tcp);
+ osi_Log1(afsd_logp, "cm_ConnByServer returning conn 0x%p", tcp);
*connpp = tcp;
return 0;
}
-long cm_Conn(struct cm_fid *fidp, struct cm_user *userp, cm_req_t *reqp,
- cm_conn_t **connpp)
+long cm_ServerAvailable(struct cm_fid *fidp, struct cm_user *userp)
{
long code;
+ cm_req_t req;
+ cm_serverRef_t **serverspp;
+ cm_serverRef_t *tsrp;
+ cm_server_t *tsp;
+ int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
+
+ cm_InitReq(&req);
+
+ code = cm_GetServerList(fidp, userp, &req, &serverspp);
+ if (code)
+ return 0;
+
+ lock_ObtainWrite(&cm_serverLock);
+ for (tsrp = *serverspp; tsrp; tsrp=tsrp->next) {
+ tsp = tsrp->server;
+ cm_GetServerNoLock(tsp);
+ if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
+ allDown = 0;
+ if (tsrp->status == srv_busy) {
+ allOffline = 0;
+ someBusy = 1;
+ } else if (tsrp->status == srv_offline) {
+ allBusy = 0;
+ someOffline = 1;
+ } else {
+ allOffline = 0;
+ allBusy = 0;
+ }
+ }
+ cm_PutServerNoLock(tsp);
+ }
+ lock_ReleaseWrite(&cm_serverLock);
+ cm_FreeServerList(serverspp, 0);
+
+ if (allDown)
+ return 0;
+ else if (allBusy)
+ return 0;
+ else if (allOffline || (someBusy && someOffline))
+ return 0;
+ else
+ return 1;
+}
+/*
+ * The returned cm_conn_t ** object is released in the subsequent call
+ * to cm_Analyze().
+ */
+long cm_ConnFromFID(struct cm_fid *fidp, struct cm_user *userp, cm_req_t *reqp,
+ cm_conn_t **connpp)
+{
+ long code;
cm_serverRef_t **serverspp;
+ *connpp = NULL;
+
code = cm_GetServerList(fidp, userp, reqp, &serverspp);
if (code) {
- *connpp = NULL;
return code;
}
code = cm_ConnByMServers(*serverspp, userp, reqp, connpp);
- cm_FreeServerList(serverspp);
+ cm_FreeServerList(serverspp, 0);
return code;
}
-extern struct rx_connection *
+
+long cm_ConnFromVolume(struct cm_volume *volp, unsigned long volid, struct cm_user *userp, cm_req_t *reqp,
+ cm_conn_t **connpp)
+{
+ long code;
+ cm_serverRef_t **serverspp;
+
+ *connpp = NULL;
+
+ serverspp = cm_GetVolServers(volp, volid);
+
+ code = cm_ConnByMServers(*serverspp, userp, reqp, connpp);
+ cm_FreeServerList(serverspp, 0);
+ return code;
+}
+
+
+extern struct rx_connection *
cm_GetRxConn(cm_conn_t *connp)
{
struct rx_connection * rxconn;
return rxconn;
}
+void cm_ForceNewConnections(cm_server_t *serverp)
+{
+ cm_conn_t *tcp;
+
+ lock_ObtainWrite(&cm_connLock);
+ for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
+ lock_ObtainMutex(&tcp->mx);
+ tcp->flags |= CM_CONN_FLAG_FORCE_NEW;
+ lock_ReleaseMutex(&tcp->mx);
+ }
+ lock_ReleaseWrite(&cm_connLock);
+}