struct Lock FSYNC_handler_lock;
int
-FSYNC_clientInit(void)
+FSYNC_clientInit(int f)
{
#ifdef USE_UNIX_SOCKETS
struct sockaddr_un addr;
FS_sd = getport(&addr);
if (connect(FS_sd, (struct sockaddr *)&addr, sizeof(addr)) >= 0)
return 1;
+ if (!f) {
+ FSYNC_clientFinis();
+ return 0;
+ }
if (!*timeout)
break;
if (!(*timeout & 1))
byte response;
struct command command;
int n;
+ int retrycount = 8;
command.volume = volume;
command.command = com;
command.reason = reason;
strcpy(command.partName, partName);
else
command.partName[0] = 0;
- assert(FS_sd != -1);
VFSYNC_LOCK;
#ifdef AFS_NT40_ENV
- if (send(FS_sd, (char *)&command, sizeof(command), 0) != sizeof(command)) {
- printf("FSYNC_askfs: write to file server failed\n");
+#define FS_SEND(fd,cmd) send(fd, (char*)&(cmd), sizeof(cmd), 0)
+#define FS_RECV(fd,resp) recv(fd, &(resp), 1, 0)
+#define FS_PERROR(m) fprintf(stderr,"%s\n", m)
+#define FS_INTERRUPTED(n) ((n) && WSAEINTR == WSAGetLastError())
+#else
+#define FS_SEND(fd,cmd) write(fd,&(cmd), sizeof (cmd))
+#define FS_RECV(fd,resp) read(fd, &(resp), 1)
+#define FS_PERROR(m) perror(m)
+#define FS_INTERRUPTED(n) (n && errno == EINTR)
+#endif
+ for (;;) {
+ if (FS_sd != -1) {
+ if (FS_SEND(FS_sd, command) == sizeof(command)) break;
+ FS_PERROR("FSYNC_askfs: write to file server failed");
+ }
+ if (--retrycount > 0) {
+ FSYNC_clientFinis();
+ if (FSYNC_clientInit(1)) continue;
+ }
response = FSYNC_DENIED;
goto done;
}
- while ((n = recv(FS_sd, &response, 1, 0)) != 1) {
- if (n == 0 || WSAEINTR != WSAGetLastError()) {
- printf("FSYNC_askfs: No response from file server\n");
- response = FSYNC_DENIED;
- goto done;
- }
- }
-#else
- if (write(FS_sd, &command, sizeof(command)) != sizeof(command)) {
- printf("FSYNC_askfs: write to file server failed\n");
+ for (;;) {
+ errno = 0;
+ n = FS_RECV(FS_sd, response);
+ if (n == 1) break;
+ if (FS_INTERRUPTED(n)) continue;
+ fprintf(stderr,"FSYNC_askfs: No response from file server\n");
response = FSYNC_DENIED;
goto done;
}
- while ((n = read(FS_sd, &response, 1)) != 1) {
- if (n == 0 || errno != EINTR) {
- printf("FSYNC_askfs: No response from file server\n");
- response = FSYNC_DENIED;
- goto done;
- }
- }
-#endif
if (response == 0) {
- printf
- ("FSYNC_askfs: negative response from file server; volume %u, command %d\n",
+ fprintf(stderr,
+ "FSYNC_askfs: negative response from file server; volume %u, command %d\n",
command.volume, (int)command.command);
}
done:
Log("Set thread id %d for FSYNC_sync\n", tid);
#endif /* AFS_PTHREAD_ENV */
-#ifdef USE_UNIX_SOCKETS
- strcompose(tbuffer, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH, "/",
- "fssync.sock", NULL);
- /* ignore errors */
- remove(tbuffer);
-#endif /* USE_UNIX_SOCKETS */
-
while (!VInit) {
/* Let somebody else run until level > 0. That doesn't mean that
* all volumes have been attached. */
if ((code =
bind(AcceptSd, (struct sockaddr *)&addr, sizeof(addr))) == 0)
break;
+#ifdef USE_UNIX_SOCKETS
+ code = errno;
+ if (remove(addr.sun_path) == 0) {
+ Log("FSYNC_sync: bind failed with (%d), removed bogus %s\n",
+ code, addr.sun_path);
+ continue;
+ }
+ errno = code;
+#endif
Log("FSYNC_sync: bind failed with (%d), will sleep and retry\n",
errno);
sleep(5);
VInit = 2; /* Initialized, and all volumes have been attached */
if (programType == volumeUtility && connect) {
if (!VConnectFS()) {
- Log("Unable to connect to file server; aborted\n");
+ Log("Unable to connect to file server; will retry at need\n");
+#if 0
Lock_Destroy(&FSYNC_handler_lock);
exit(1);
+#endif
}
}
return 0;
{
int retVal;
VOL_LOCK;
- retVal = VConnectFS_r();
+ retVal = VConnectFS_r(0);
VOL_UNLOCK;
return retVal;
}
int
-VConnectFS_r(void)
+VConnectFS_r(int f)
{
int rc;
assert(VInit == 2 && programType == volumeUtility);
- rc = FSYNC_clientInit();
+ rc = FSYNC_clientInit(f);
if (rc)
VInit = 3;
return rc;
int isbusy = 0;
*ec = 0;
if (programType == volumeUtility) {
- assert(VInit == 3);
+ assert(VInit == 3 || VConnectFS_r(1));
VLockPartition_r(partition);
}
if (programType == fileServer) {