Linux: drop GLOCK before calling dput
[openafs.git] / src / afs / afs_pioctl.c
index ff3e87d..0836b87 100644 (file)
@@ -568,8 +568,7 @@ kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
            if (((uap->com >> 8) & 0xff) == 'V') {
                struct afs_ioctl *datap;
                AFS_GLOCK();
-               datap =
-                   (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
+               datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
                code=copyin_afs_ioctl((char *)uap->arg, datap);
                if (code) {
                    osi_FreeSmallSpace(datap);
@@ -677,8 +676,7 @@ afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
            if (((uap->com >> 8) & 0xff) == 'V') {
                struct afs_ioctl *datap;
                AFS_GLOCK();
-               datap =
-                   (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
+               datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
                code=copyin_afs_ioctl((char *)uap->arg, datap);
                if (code) {
                    osi_FreeSmallSpace(datap);
@@ -874,7 +872,11 @@ afs_xioctl(afs_proc_t *p, const struct ioctl_args *uap, register_t *retval)
 
     if (!ioctlDone) {
 # if defined(AFS_FBSD_ENV)
+#  if (__FreeBSD_version >= 900044)
+       return sys_ioctl(td, uap);
+#  else
        return ioctl(td, uap);
+#  endif
 # elif defined(AFS_OBSD_ENV)
        code = sys_ioctl(p, uap, retval);
 # elif defined(AFS_NBSD_ENV)
@@ -1237,7 +1239,13 @@ afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
 #endif /* AFS_NEED_CLIENTCONTEXT */
     if (vp) {
 #ifdef AFS_LINUX22_ENV
+       /*
+        * Holding the global lock when calling dput can cause a deadlock
+        * when the kernel calls back into afs_dentry_iput
+        */
+       AFS_GUNLOCK();
        dput(dp);
+       AFS_GLOCK();
 #else
 #if defined(AFS_FBSD80_ENV)
     if (VOP_ISLOCKED(vp))
@@ -2145,7 +2153,7 @@ DECL_PIOCTL(PFlush)
     afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
     ObtainWriteLock(&avc->lock, 225);
-    afs_ResetVCache(avc, *acred);
+    afs_ResetVCache(avc, *acred, 0);
     ReleaseWriteLock(&avc->lock);
 #ifdef AFS_BOZONLOCK_ENV
     afs_BozonUnlock(&avc->pvnLock, avc);
@@ -3514,14 +3522,7 @@ DECL_PIOCTL(PFlushVolumeData)
                afs_BozonLock(&tvc->pvnLock, tvc);      /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
                ObtainWriteLock(&tvc->lock, 232);
-
-               ObtainWriteLock(&afs_xcbhash, 458);
-               afs_DequeueCallback(tvc);
-               tvc->f.states &= ~(CStatd | CDirty);
-               ReleaseWriteLock(&afs_xcbhash);
-               if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
-                   osi_dnlc_purgedp(tvc);
-               afs_TryToSmush(tvc, *acred, 1);
+               afs_ResetVCache(tvc, *acred, 1);
                ReleaseWriteLock(&tvc->lock);
 #ifdef AFS_BOZONLOCK_ENV
                afs_BozonUnlock(&tvc->pvnLock, tvc);
@@ -3542,16 +3543,21 @@ DECL_PIOCTL(PFlushVolumeData)
     for (i = 0; i < afs_cacheFiles; i++) {
        if (!(afs_indexFlags[i] & IFEverUsed))
            continue;           /* never had any data */
-       tdc = afs_GetDSlot(i, NULL);
+       tdc = afs_GetValidDSlot(i);
+       if (!tdc) {
+           continue;
+       }
        if (tdc->refCount <= 1) {    /* too high, in use by running sys call */
            ReleaseReadLock(&tdc->tlock);
            if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
-               if (!(afs_indexFlags[i] & IFDataMod)) {
+               if (!(afs_indexFlags[i] & (IFDataMod | IFFree | IFDiscarded))) {
                    /* if the file is modified, but has a ref cnt of only 1,
                     * then someone probably has the file open and is writing
                     * into it. Better to skip flushing such a file, it will be
                     * brought back immediately on the next write anyway.
                     *
+                    * Skip if already freed.
+                    *
                     * If we *must* flush, then this code has to be rearranged
                     * to call afs_storeAllSegments() first */
                    afs_FlushDCache(tdc);
@@ -3972,7 +3978,7 @@ afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
            afs_uint32 temp = sp->host.s_addr;
            srvr =
                afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
-                             WRITE_LOCK, (afsUUID *) 0, 0);
+                             WRITE_LOCK, (afsUUID *) 0, 0, NULL);
            srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
            afs_PutServer(srvr, WRITE_LOCK);
        }
@@ -4022,7 +4028,7 @@ DECL_PIOCTL(PSetSPrefs)
 
     ssp = (struct setspref *)ainPtr;
     if (ainSize < (sizeof(struct setspref)
-                  + sizeof(struct spref) * ssp->num_servers-1))
+                  + sizeof(struct spref) * (ssp->num_servers-1)))
        return EINVAL;
 
     afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
@@ -5174,7 +5180,7 @@ DECL_PIOCTL(PCallBackAddr)
        /* get a connection, even if host is down; bumps conn ref count */
        tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
        tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
-                         1 /*force */ , 1 /*create */ , SHARED_LOCK, &rxconn);
+                         1 /*force */ , 1 /*create */ , SHARED_LOCK, 0, &rxconn);
        afs_PutUser(tu, SHARED_LOCK);
        if (!tc)
            continue;
@@ -5380,7 +5386,7 @@ out:
 
 DECL_PIOCTL(PGetTokens2)
 {
-    struct cell *cell;
+    struct cell *cell = NULL;
     struct unixuser *tu = NULL;
     afs_int32 iterator;
     char *cellName = NULL;