]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE14-fssync-unix-socket-handling-fixes-20070623
authorMarcus Watts <mdw@umich.edu>
Sat, 23 Jun 2007 14:46:53 +0000 (14:46 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sat, 23 Jun 2007 14:46:53 +0000 (14:46 +0000)
FIXES 63743

make unix domain socket behavior better

src/vol/fssync.c
src/vol/fssync.h
src/vol/volume.c
src/vol/volume.h

index 9655600e5450e98b74c6df1fa3876efe7fc1c9cb..68a6445b31315175b9b7f504fddbc4dc95c043d8 100644 (file)
@@ -162,7 +162,7 @@ extern int LogLevel;
 struct Lock FSYNC_handler_lock;
 
 int
-FSYNC_clientInit(void)
+FSYNC_clientInit(int f)
 {
 #ifdef USE_UNIX_SOCKETS
     struct sockaddr_un addr;
@@ -178,6 +178,10 @@ FSYNC_clientInit(void)
        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))
@@ -206,6 +210,7 @@ FSYNC_askfs(VolumeId volume, char *partName, int com, int reason)
     byte response;
     struct command command;
     int n;
+    int retrycount = 8;
     command.volume = volume;
     command.command = com;
     command.reason = reason;
@@ -213,38 +218,42 @@ FSYNC_askfs(VolumeId volume, char *partName, int com, int 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:
@@ -338,13 +347,6 @@ FSYNC_sync()
     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. */
@@ -366,6 +368,15 @@ FSYNC_sync()
        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);
index af5ab02c7105e2d7ab31e633b6e622c9826a180f..201df6cba638f49a3bf3717f28e1695b7a12bc6b 100644 (file)
@@ -46,6 +46,6 @@
 
 /* Prototypes from fssync.c */
 void FSYNC_clientFinis(void);
-int FSYNC_clientInit(void);
+int FSYNC_clientInit(int);
 void FSYNC_fsInit(void);
 int FSYNC_askfs(VolumeId volume, char *partName, int com, int reason);
index 5ecc94c36f965e3e21daa513e0b98e59a2347532..ea07fda2c07c7ad2b54fbdf79226cff71bac607c 100644 (file)
@@ -379,9 +379,11 @@ VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes,
     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;
@@ -457,17 +459,17 @@ VConnectFS(void)
 {
     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;
@@ -700,7 +702,7 @@ VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode)
     int isbusy = 0;
     *ec = 0;
     if (programType == volumeUtility) {
-       assert(VInit == 3);
+       assert(VInit == 3 || VConnectFS_r(1));
        VLockPartition_r(partition);
     }
     if (programType == fileServer) {
index 68fc0f98c4040583d04151bedd2ab955a6247a71..b5205a0f93bfd2ec43ed4dce957fa36027192f1c 100644 (file)
@@ -419,7 +419,7 @@ extern void VPutVolume_r(Volume *);
 extern void VOffline(Volume * vp, char *message);
 extern void VOffline_r(Volume * vp, char *message);
 extern int VConnectFS(void);
-extern int VConnectFS_r(void);
+extern int VConnectFS_r(int);
 extern Volume *VAttachVolume(Error * ec, VolumeId volumeId, int mode);
 extern Volume *VAttachVolume_r(Error * ec, VolumeId volumeId, int mode);
 extern Volume *VCreateVolume(Error * ec, char *partname, VolId volumeId,