aix vnode hold simplification
[openafs.git] / src / afs / afs_callback.c
index 2deab40..f13436a 100644 (file)
@@ -16,8 +16,6 @@
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include "afs/sysincludes.h"   /*Standard vendor system headers */
 #include "afsincludes.h"       /*AFS-based standard headers */
@@ -59,7 +57,16 @@ static struct ltable {
     "afs_xosi", (char *)&afs_xosi},
 #endif
     {
-    "afs_xsrvAddr", (char *)&afs_xsrvAddr}
+      "afs_xsrvAddr", (char *)&afs_xsrvAddr},
+    {
+      "afs_xvreclaim", (char *)&afs_xvreclaim},
+    { "afsdb_client_lock", (char *)&afsdb_client_lock},
+    { "afsdb_req_lock", (char *)&afsdb_req_lock},
+#ifdef AFS_DISCON_ENV
+    { "afs_discon_lock", (char *)&afs_discon_lock},
+    { "afs_disconDirtyLock", (char *)&afs_disconDirtyLock},
+    { "afs_discon_vc_dirty", (char *)&afs_xvcdirty},
+#endif
 };
 unsigned long lastCallBack_vnode;
 unsigned int lastCallBack_dv;
@@ -125,33 +132,33 @@ SRXAFSCB_GetCE(struct rx_call *a_call, afs_int32 a_index,
      * Copy out the located entry.
      */
     a_result->addr = afs_data_pointer_to_int32(tvc);
-    a_result->cell = tvc->fid.Cell;
-    a_result->netFid.Volume = tvc->fid.Fid.Volume;
-    a_result->netFid.Vnode = tvc->fid.Fid.Vnode;
-    a_result->netFid.Unique = tvc->fid.Fid.Unique;
+    a_result->cell = tvc->f.fid.Cell;
+    a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
+    a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
+    a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
     a_result->lock.waitStates = tvc->lock.wait_states;
     a_result->lock.exclLocked = tvc->lock.excl_locked;
     a_result->lock.readersReading = tvc->lock.readers_reading;
     a_result->lock.numWaiting = tvc->lock.num_waiting;
 #if defined(INSTRUMENT_LOCKS)
-    a_result->lock.pid_last_reader = tvc->lock.pid_last_reader;
-    a_result->lock.pid_writer = tvc->lock.pid_writer;
+    a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
+    a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
     a_result->lock.src_indicator = tvc->lock.src_indicator;
 #else
     /* On osf20 , the vcache does not maintain these three fields */
     a_result->lock.pid_last_reader = 0;
     a_result->lock.pid_writer = 0;
     a_result->lock.src_indicator = 0;
-#endif /* AFS_OSF20_ENV */
+#endif /* INSTRUMENT_LOCKS */
 #ifdef AFS_64BIT_CLIENT
-    a_result->Length = (afs_int32) tvc->m.Length & 0xffffffff;
+    a_result->Length = (afs_int32) tvc->f.m.Length & 0xffffffff;
 #else /* AFS_64BIT_CLIENT */
-    a_result->Length = tvc->m.Length;
+    a_result->Length = tvc->f.m.Length;
 #endif /* AFS_64BIT_CLIENT */
-    a_result->DataVersion = hgetlo(tvc->m.DataVersion);
+    a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
     a_result->callback = afs_data_pointer_to_int32(tvc->callback);     /* XXXX Now a pointer; change it XXXX */
     a_result->cbExpires = tvc->cbExpires;
-    if (tvc->states & CVInit) {
+    if (tvc->f.states & CVInit) {
         a_result->refCount = 1;
     } else {
 #ifdef AFS_DARWIN80_ENV
@@ -163,7 +170,7 @@ SRXAFSCB_GetCE(struct rx_call *a_call, afs_int32 a_index,
     a_result->opens = tvc->opens;
     a_result->writers = tvc->execsOrWriters;
     a_result->mvstat = tvc->mvstat;
-    a_result->states = tvc->states;
+    a_result->states = tvc->f.states;
     code = 0;
 
     /*
@@ -211,34 +218,34 @@ SRXAFSCB_GetCE64(struct rx_call *a_call, afs_int32 a_index,
      * Copy out the located entry.
      */
     a_result->addr = afs_data_pointer_to_int32(tvc);
-    a_result->cell = tvc->fid.Cell;
-    a_result->netFid.Volume = tvc->fid.Fid.Volume;
-    a_result->netFid.Vnode = tvc->fid.Fid.Vnode;
-    a_result->netFid.Unique = tvc->fid.Fid.Unique;
+    a_result->cell = tvc->f.fid.Cell;
+    a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
+    a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
+    a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
     a_result->lock.waitStates = tvc->lock.wait_states;
     a_result->lock.exclLocked = tvc->lock.excl_locked;
     a_result->lock.readersReading = tvc->lock.readers_reading;
     a_result->lock.numWaiting = tvc->lock.num_waiting;
 #if defined(INSTRUMENT_LOCKS)
-    a_result->lock.pid_last_reader = tvc->lock.pid_last_reader;
-    a_result->lock.pid_writer = tvc->lock.pid_writer;
+    a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
+    a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
     a_result->lock.src_indicator = tvc->lock.src_indicator;
 #else
     /* On osf20 , the vcache does not maintain these three fields */
     a_result->lock.pid_last_reader = 0;
     a_result->lock.pid_writer = 0;
     a_result->lock.src_indicator = 0;
-#endif /* AFS_OSF20_ENV */
+#endif /* INSTRUMENT_LOCKS */
 #if !defined(AFS_64BIT_ENV) 
     a_result->Length.high = 0;
-    a_result->Length.low = tvc->m.Length;
+    a_result->Length.low = tvc->f.m.Length;
 #else
-    a_result->Length = tvc->m.Length;
+    a_result->Length = tvc->f.m.Length;
 #endif
-    a_result->DataVersion = hgetlo(tvc->m.DataVersion);
+    a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
     a_result->callback = afs_data_pointer_to_int32(tvc->callback);     /* XXXX Now a pointer; change it XXXX */
     a_result->cbExpires = tvc->cbExpires;
-    if (tvc->states & CVInit) {
+    if (tvc->f.states & CVInit) {
         a_result->refCount = 1;
     } else {
 #ifdef AFS_DARWIN80_ENV
@@ -250,7 +257,7 @@ SRXAFSCB_GetCE64(struct rx_call *a_call, afs_int32 a_index,
     a_result->opens = tvc->opens;
     a_result->writers = tvc->execsOrWriters;
     a_result->mvstat = tvc->mvstat;
-    a_result->states = tvc->states;
+    a_result->states = tvc->f.states;
     code = 0;
 
     /*
@@ -305,11 +312,35 @@ SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index,
 
     AFS_STATCNT(SRXAFSCB_GetLock);
     nentries = sizeof(ltable) / sizeof(struct ltable);
-    if (a_index < 0 || a_index >= nentries) {
+    if (a_index < 0 || a_index >= nentries+afs_cellindex) {
        /*
         * Past EOF
         */
        code = 1;
+    } else if (a_index >= nentries) {
+       struct cell *tc = afs_GetCellByIndex(a_index-nentries, 0);
+       strcpy(a_result->name, tc->cellName);
+       a_result->lock.waitStates =
+           ((struct afs_lock *)&(tc->lock))->wait_states;
+       a_result->lock.exclLocked =
+           ((struct afs_lock *)&(tc->lock))->excl_locked;
+       a_result->lock.readersReading =
+           ((struct afs_lock *)&(tc->lock))->readers_reading;
+       a_result->lock.numWaiting =
+           ((struct afs_lock *)&(tc->lock))->num_waiting;
+#ifdef INSTRUMENT_LOCKS
+       a_result->lock.pid_last_reader =
+           MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_last_reader);
+       a_result->lock.pid_writer =
+           MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_writer);
+       a_result->lock.src_indicator =
+           ((struct afs_lock *)&(tc->lock))->src_indicator;
+#else
+       a_result->lock.pid_last_reader = 0;
+       a_result->lock.pid_writer = 0;
+       a_result->lock.src_indicator = 0;
+#endif
+       code = 0;
     } else {
        /*
         * Found it - copy out its contents.
@@ -326,9 +357,9 @@ SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index,
            ((struct afs_lock *)(tl->addr))->num_waiting;
 #ifdef INSTRUMENT_LOCKS
        a_result->lock.pid_last_reader =
-           ((struct afs_lock *)(tl->addr))->pid_last_reader;
+           MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_last_reader);
        a_result->lock.pid_writer =
-           ((struct afs_lock *)(tl->addr))->pid_writer;
+           MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_writer);
        a_result->lock.src_indicator =
            ((struct afs_lock *)(tl->addr))->src_indicator;
 #else
@@ -382,6 +413,9 @@ ClearCallBack(register struct rx_connection *a_conn,
     register int i;
     struct VenusFid localFid;
     struct volume *tv;
+#ifdef AFS_DARWIN80_ENV
+    vnode_t vp;
+#endif
 
     AFS_STATCNT(ClearCallBack);
 
@@ -405,38 +439,81 @@ ClearCallBack(register struct rx_connection *a_conn,
             * Clear callback for the whole volume.  Zip through the
             * hash chain, nullifying entries whose volume ID matches.
             */
+loop1:
+               ObtainReadLock(&afs_xvcache);
                i = VCHashV(&localFid);
                for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
                    uq = QPrev(tq);
                    tvc = QTOVH(tq);      
-                   if (tvc->fid.Fid.Volume == a_fid->Volume) {
+                   if (tvc->f.fid.Fid.Volume == a_fid->Volume) {
                        tvc->callback = NULL;
                        if (!localFid.Cell)
-                           localFid.Cell = tvc->fid.Cell;
+                           localFid.Cell = tvc->f.fid.Cell;
                        tvc->dchint = NULL;     /* invalidate hints */
+                       if (tvc->f.states & CVInit) {
+                           ReleaseReadLock(&afs_xvcache);
+                           afs_osi_Sleep(&tvc->f.states);
+                           goto loop1;
+                       }
+#if     defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)  || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
+                       VN_HOLD(AFSTOV(tvc));
+#else
+#ifdef AFS_DARWIN80_ENV
+                       if (tvc->f.states & CDeadVnode) {
+                           if (!(tvc->f.states & CBulkFetching)) {
+                               ReleaseReadLock(&afs_xvcache);
+                               afs_osi_Sleep(&tvc->f.states);
+                               goto loop1;
+                           }
+                       }
+                       vp = AFSTOV(tvc);
+                       if (vnode_get(vp))
+                           continue;
+                       if (vnode_ref(vp)) {
+                           AFS_GUNLOCK();
+                           vnode_put(vp);
+                           AFS_GLOCK();
+                           continue;
+                       }
+                       if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
+                           AFS_GUNLOCK();
+                           vnode_recycle(AFSTOV(tvc));
+                           AFS_GLOCK();
+                       }
+#else
+                       AFS_FAST_HOLD(tvc);
+#endif
+#endif
+                       ReleaseReadLock(&afs_xvcache);
                        ObtainWriteLock(&afs_xcbhash, 449);
                        afs_DequeueCallback(tvc);
-                       tvc->states &= ~(CStatd | CUnique | CBulkFetching);
+                       tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
                        afs_allCBs++;
-                       if (tvc->fid.Fid.Vnode & 1)
+                       if (tvc->f.fid.Fid.Vnode & 1)
                            afs_oddCBs++;
                        else
                            afs_evenCBs++;
                        ReleaseWriteLock(&afs_xcbhash);
-                       if (!(tvc->states & CVInit) &&
-                           (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
+                       if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
                            osi_dnlc_purgedp(tvc);
                        afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
                                   ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
-                                  tvc->states, ICL_TYPE_INT32,
+                                  tvc->f.states, ICL_TYPE_INT32,
                                   a_fid->Volume);
-                   } else if ((tvc->states & CMValid)
+#ifdef AFS_DARWIN80_ENV
+                       vnode_put(AFSTOV(tvc));
+#endif
+                       ObtainReadLock(&afs_xvcache);
+                       uq = QPrev(tq);
+                       AFS_FAST_RELE(tvc);
+                   } else if ((tvc->f.states & CMValid)
                               && (tvc->mvid->Fid.Volume == a_fid->Volume)) {
-                       tvc->states &= ~CMValid;
+                       tvc->f.states &= ~CMValid;
                        if (!localFid.Cell)
                            localFid.Cell = tvc->mvid->Cell;
                    }
                }
+               ReleaseReadLock(&afs_xvcache);
 
            /*
             * XXXX Don't hold any locks here XXXX
@@ -452,35 +529,80 @@ ClearCallBack(register struct rx_connection *a_conn,
            /*
             * Clear callbacks just for the one file.
             */
+           struct vcache *uvc;
            afs_allCBs++;
            if (a_fid->Vnode & 1)
                afs_oddCBs++;   /*Could do this on volume basis, too */
            else
                afs_evenCBs++;  /*A particular fid was specified */
+loop2:
+           ObtainReadLock(&afs_xvcache);
            i = VCHash(&localFid);
-           for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
-               if (tvc->fid.Fid.Vnode == a_fid->Vnode
-                   && tvc->fid.Fid.Volume == a_fid->Volume
-                   && tvc->fid.Fid.Unique == a_fid->Unique) {
+           for (tvc = afs_vhashT[i]; tvc; tvc = uvc) {
+               uvc = tvc->hnext;
+               if (tvc->f.fid.Fid.Vnode == a_fid->Vnode
+                   && tvc->f.fid.Fid.Volume == a_fid->Volume
+                   && tvc->f.fid.Fid.Unique == a_fid->Unique) {
                    tvc->callback = NULL;
                    tvc->dchint = NULL; /* invalidate hints */
+                   if (tvc->f.states & CVInit) {
+                       ReleaseReadLock(&afs_xvcache);
+                       afs_osi_Sleep(&tvc->f.states);
+                       goto loop2;
+                   }
+#if     defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)  || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
+                   VN_HOLD(AFSTOV(tvc));
+#else
+#ifdef AFS_DARWIN80_ENV
+                   if (tvc->f.states & CDeadVnode) {
+                       if (!(tvc->f.states & CBulkFetching)) {
+                           ReleaseReadLock(&afs_xvcache);
+                           afs_osi_Sleep(&tvc->f.states);
+                           goto loop2;
+                       }
+                   }
+                   vp = AFSTOV(tvc);
+                   if (vnode_get(vp))
+                       continue;
+                   if (vnode_ref(vp)) {
+                       AFS_GUNLOCK();
+                       vnode_put(vp);
+                       AFS_GLOCK();
+                       continue;
+                   }
+                   if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
+                       AFS_GUNLOCK();
+                       vnode_recycle(AFSTOV(tvc));
+                       AFS_GLOCK();
+                   }
+#else
+                   AFS_FAST_HOLD(tvc);
+#endif
+#endif
+                   ReleaseReadLock(&afs_xvcache);
                    ObtainWriteLock(&afs_xcbhash, 450);
                    afs_DequeueCallback(tvc);
-                   tvc->states &= ~(CStatd | CUnique | CBulkFetching);
+                   tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
                    ReleaseWriteLock(&afs_xcbhash);
-                   if (!(tvc->states & CVInit) &&
-                       (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
+                   if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
                        osi_dnlc_purgedp(tvc);
                    afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
                               ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
-                              tvc->states, ICL_TYPE_LONG, 0);
+                              tvc->f.states, ICL_TYPE_LONG, 0);
 #ifdef CBDEBUG
                    lastCallBack_vnode = afid->Vnode;
                    lastCallBack_dv = tvc->mstat.DataVersion.low;
                    osi_GetuTime(&lastCallBack_time);
 #endif /* CBDEBUG */
+#ifdef AFS_DARWIN80_ENV
+                   vnode_put(AFSTOV(tvc));
+#endif
+                   ObtainReadLock(&afs_xvcache);
+                   uvc = tvc->hnext;
+                   AFS_FAST_RELE(tvc);
                }
            }                   /*Walk through hash table */
+           ReleaseReadLock(&afs_xvcache);
        }                       /*Clear callbacks for one file */
     }
 
@@ -645,7 +767,7 @@ SRXAFSCB_InitCallBackState(struct rx_call *a_call)
                        ObtainWriteLock(&afs_xcbhash, 451);
                        afs_DequeueCallback(tvc);
                        tvc->callback = NULL;
-                       tvc->states &= ~(CStatd | CUnique | CBulkFetching);
+                       tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
                        ReleaseWriteLock(&afs_xcbhash);
                    }
                }
@@ -660,7 +782,7 @@ SRXAFSCB_InitCallBackState(struct rx_call *a_call)
 
            for (i = 0; i < NVOLS; i++)
                for (tv = afs_volumes[i]; tv; tv = tv->next) {
-                   for (j = 0; j < MAXHOSTS; j++)
+                   for (j = 0; j < AFS_MAXHOSTS; j++)
                        if (tv->serverHost[j] == ts)
                            afs_ResetVolumeInfo(tv);
                }
@@ -890,7 +1012,7 @@ afs_RXCallBackServer(void)
     /*
      * Donate this process to Rx.
      */
-    rx_ServerProc();
+    rx_ServerProc(NULL);
     return (0);
 
 }                              /*afs_RXCallBackServer */
@@ -1510,7 +1632,7 @@ SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call,
 {
     int i;
     int code = 0;
-    afs_int32 *dataBuffP;
+    afs_uint32 *dataBuffP;
     afs_int32 dataBytes;
 
     RX_AFS_GLOCK();
@@ -1532,17 +1654,17 @@ SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call,
 
     RX_AFS_GUNLOCK();
 
-    dataBytes = 1 * sizeof(afs_int32);
-    dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
-    dataBuffP[0] = CAPABILITY_ERRORTRANS;
-    capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
+    dataBytes = 1 * sizeof(afs_uint32);
+    dataBuffP = (afs_uint32 *) afs_osi_Alloc(dataBytes);
+    dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
+    capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
     capabilities->Capabilities_val = dataBuffP;
 
     return code;
 }
 
 
-#ifdef AFS_LINUX24_ENV
+#if 0 && defined(AFS_LINUX24_ENV)
 extern struct vcache *afs_globalVp;
 
 int recurse_dcache_parent(parent, a_index, addr, inode, flags, time, fileName)
@@ -1604,17 +1726,12 @@ resume:
 }
 #endif
 
-int SRXAFSCB_GetDE(a_call, a_index, addr, inode, flags, time, fileName)
-    struct rx_call *a_call;
-    afs_int32 a_index;
-    afs_int32 *addr;
-    afs_int32 *inode;
-    afs_int32 *flags;
-    afs_int32 *time;
-    char ** fileName;
+int SRXAFSCB_GetDE(struct rx_call *a_call, afs_int32 a_index, afs_int32 *addr,
+                  afs_int32 *inode, afs_int32 *flags, afs_int32 *time,
+                  char ** fileName)
 { /*SRXAFSCB_GetDE*/
     int code = 0;                              /*Return code*/
-#ifdef AFS_LINUX24_ENV
+#if 0 && defined(AFS_LINUX24_ENV)
     register int i;                    /*Loop variable*/
     register struct vcache *tvc = afs_globalVp;
     struct dentry *dentry;