libafs: ensure one nat ping connection per srvAddr
authorDerrick Brashear <shadow@dementix.org>
Mon, 13 Feb 2012 03:45:59 +0000 (22:45 -0500)
committerDerrick Brashear <shadow@dementix.org>
Wed, 22 Feb 2012 20:49:58 +0000 (12:49 -0800)
track the natping conn with the srvAddr, ensuring exactly one.

Change-Id: I2e424a71d398563f9d0ec3ca77b83320cbef4ea1
Reviewed-on: http://gerrit.openafs.org/6706
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

src/afs/afs.h
src/afs/afs_conn.c
src/afs/afs_server.c

index 9a396a4..dd45066 100644 (file)
@@ -440,6 +440,7 @@ struct srvAddr {
     struct srvAddr *next_sa;   /* another interface on same host */
     struct server *server;     /* back to parent */
     struct sa_conn_vector *conns;   /* All user connections to this server */
+    struct afs_conn *natping;
     afs_int32 sa_ip;           /* Host addr in network byte order */
     u_short sa_iprank;         /* indiv ip address priority */
     u_short sa_portal;         /* port addr in network byte order */
index 0bfb526..09d7d8f 100644 (file)
@@ -134,7 +134,7 @@ release_conns_user_server(struct unixuser *xu, struct server *xs)
     int cix, glocked;
     struct srvAddr *sa;
     struct afs_conn *tc;
-    struct sa_conn_vector *tcv, **lcv;
+    struct sa_conn_vector *tcv, **lcv, *tcvn;
     for (sa = (xs)->addr; sa; sa = sa->next_sa) {
         lcv = &sa->conns;
         for (tcv = *lcv; tcv; lcv = &tcv->next, tcv = *lcv) {
@@ -149,6 +149,23 @@ release_conns_user_server(struct unixuser *xu, struct server *xs)
                     if (tc->activated) {
                         rx_SetConnSecondsUntilNatPing(tc->id, 0);
                         rx_DestroyConnection(tc->id);
+                       /* find another eligible connection */
+                       if (sa->natping == tc) {
+                           int cin;
+                           struct afs_conn *tcn;
+                           for (tcvn = sa->conns; tcvn; tcvn = tcvn->next) {
+                               if (tcvn == tcv)
+                                   continue;
+                               for(cin = 0; cin < CVEC_LEN; ++cin) {
+                                   tcn = &(tcvn->cvec[cin]);
+                                   if (tcn->activated) {
+                                       rx_SetConnSecondsUntilNatPing(tcn->id, 20);
+                                       sa->natping = tcn;
+                                       break;
+                                   }
+                               }
+                           }
+                       }
                     }
                 }
                 if (glocked)
@@ -180,6 +197,8 @@ release_conns_vector(struct sa_conn_vector *xcv)
             if (tc->activated) {
                 rx_SetConnSecondsUntilNatPing(tc->id, 0);
                 rx_DestroyConnection(tc->id);
+               if (tcv->srvr->natping == tc)
+                   tcv->srvr->natping = NULL;
             }
         }
         if (glocked)
@@ -450,6 +469,8 @@ afs_ConnBySA(struct srvAddr *sap, unsigned short aport, afs_int32 acell,
        UpgradeSToWLock(&afs_xconn, 38);
        csec = (struct rx_securityClass *)0;
        if (tc->id) {
+           if (sap->natping == tc)
+               sap->natping = NULL;
            if (glocked)
                 AFS_GUNLOCK();
             rx_SetConnSecondsUntilNatPing(tc->id, 0);
@@ -485,16 +506,12 @@ afs_ConnBySA(struct srvAddr *sap, unsigned short aport, afs_int32 acell,
            rx_SetConnIdleDeadTime(tc->id, afs_rx_idledead);
 
        /*
-        * Only do this for the base connection, not per-user.
-        * Will need to be revisited if/when CB gets security.
+        * Only do this for one connection
         */
-       if ((isec == 0) && (service != 52) && !(tu->states & UTokensBad) &&
-           (tu->viceId == UNDEFVID) && (isrep == 0)
-#ifndef UKERNEL /* ukernel runs as just one uid anyway */
-           && (tu->uid == 0)
-#endif
-           )
+       if ((service != 52) && (sap->natping == NULL)) {
+           sap->natping = tc;
            rx_SetConnSecondsUntilNatPing(tc->id, 20);
+       }
 
        tc->forceConnectFS = 0; /* apparently we're appropriately connected now */
        if (csec)
index 44f0f4e..f774ae2 100644 (file)
@@ -1888,6 +1888,7 @@ afs_RemoveAllConns(void)
                 if (sa->conns) {
                     afs_ReleaseConns(sa->conns);
                     sa->conns = NULL;
+                   sa->natping = NULL;
                 }
             }
         }