fs-getcache-show-more-20060615
[openafs.git] / src / afs / afs_pioctl.c
index c1cd5e1..2c4599b 100644 (file)
@@ -71,6 +71,7 @@ DECL_PIOCTL(PGetCellStatus);
 DECL_PIOCTL(PSetCellStatus);
 DECL_PIOCTL(PFlushVolumeData);
 DECL_PIOCTL(PGetVnodeXStatus);
+DECL_PIOCTL(PGetVnodeXStatus2);
 DECL_PIOCTL(PSetSysName);
 DECL_PIOCTL(PSetSPrefs);
 DECL_PIOCTL(PSetSPrefs33);
@@ -183,6 +184,7 @@ static int (*(VpioctlSw[])) () = {
        PPrefetchFromTape,      /* 66 -- MR-AFS: prefetch file from tape */
        PResidencyCmd,          /* 67 -- MR-AFS: generic commnd interface */
        PBogus,                 /* 68 -- arla: fetch stats */
+       PGetVnodeXStatus2,      /* 69 - get caller access and some vcache status */
 };
 
 static int (*(CpioctlSw[])) () = {
@@ -195,7 +197,7 @@ static int (*(CpioctlSw[])) () = {
 #define PSetClientContext 99   /*  Special pioctl to setup caller's creds  */
 int afs_nobody = NFS_NOBODY;
 
-#if (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) || defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV))
+#if (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) || defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)) || defined(NEED_IOCTL32)
 static void
 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
 {
@@ -260,25 +262,33 @@ copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
     }
 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
 
-#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV)
+#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
     struct afs_ioctl32 dst32;
 
-#ifdef AFS_SPARC64_LINUX24_ENV
+#ifdef AFS_SPARC64_LINUX26_ENV
+    if (test_thread_flag(TIF_32BIT))
+#elif AFS_SPARC64_LINUX24_ENV
     if (current->thread.flags & SPARC_FLAG_32BIT)
 #elif defined(AFS_SPARC64_LINUX20_ENV)
     if (current->tss.flags & SPARC_FLAG_32BIT)
+
+#elif defined(AFS_AMD64_LINUX26_ENV)
+    if (test_thread_flag(TIF_IA32))
 #elif defined(AFS_AMD64_LINUX20_ENV)
     if (current->thread.flags & THREAD_IA32)
-#elif defined(AFS_PPC64_LINUX20_ENV)
-#ifdef AFS_PPC64_LINUX26_ENV
+
+#elif defined(AFS_PPC64_LINUX26_ENV)
     if (current->thread_info->flags & _TIF_32BIT)
-#else /*Linux 2.6 */
+#elif defined(AFS_PPC64_LINUX20_ENV)
     if (current->thread.flags & PPC_FLAG_32BIT)
-#endif
+
+#elif defined(AFS_S390X_LINUX26_ENV)
+    if (test_thread_flag(TIF_31BIT))
 #elif defined(AFS_S390X_LINUX20_ENV)
     if (current->thread.flags & S390_FLAG_31BIT)
+
 #else
-#error Not done for this linux type
+#error pioctl32 not done for this linux
 #endif
     {
        AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
@@ -420,7 +430,7 @@ afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
    interface call.
    */
 /* AFS_HPUX102 and up uses VNODE ioctl instead */
-#ifndef AFS_HPUX102_ENV
+#if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
 #if !defined(AFS_SGI_ENV)
 #ifdef AFS_AIX32_ENV
 #ifdef AFS_AIX51_ENV
@@ -522,16 +532,16 @@ afs_xioctl(void)
     register int ioctlDone = 0, code = 0;
 
     AFS_STATCNT(afs_xioctl);
-#if defined(AFS_XBSD_ENV)
+#if defined(AFS_DARWIN_ENV)
+    if ((code = fdgetf(p, uap->fd, &fd)))
+       return code;
+#elif defined(AFS_XBSD_ENV)
     fdp = p->p_fd;
     if ((u_int) uap->fd >= fdp->fd_nfiles
        || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
        return EBADF;
     if ((fd->f_flag & (FREAD | FWRITE)) == 0)
        return EBADF;
-#elif defined(AFS_DARWIN_ENV)
-    if ((code = fdgetf(p, uap->fd, &fd)))
-       return code;
 #elif defined(AFS_LINUX22_ENV)
     ua.com = com;
     ua.arg = arg;
@@ -591,21 +601,13 @@ afs_xioctl(void)
 #endif
 #endif /* AFS_LINUX22_ENV */
        if (tvc && IsAfsVnode(AFSTOV(tvc))) {
-#ifdef AFS_DEC_ENV
-           tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
-           if (!tvc) {         /* shouldn't happen with held gnodes */
-               u.u_error = ENOENT;
-               return;
-           }
-#endif
            /* This is an AFS vnode */
            if (((uap->com >> 8) & 0xff) == 'V') {
                register struct afs_ioctl *datap;
                AFS_GLOCK();
                datap =
                    (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
-               AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
-                          sizeof(struct afs_ioctl), code);
+               code=copyin_afs_ioctl((char *)uap->arg, datap);
                if (code) {
                    osi_FreeSmallSpace(datap);
                    AFS_GUNLOCK();
@@ -815,9 +817,15 @@ afs_pioctl(p, args, retval)
     } *uap = (struct a *)args;
 
     AFS_STATCNT(afs_pioctl);
+#ifdef AFS_DARWIN80_ENV
+    return (afs_syscall_pioctl
+           (uap->path, uap->cmd, uap->cmarg, uap->follow,
+            kauth_cred_get()));
+#else
     return (afs_syscall_pioctl
            (uap->path, uap->cmd, uap->cmarg, uap->follow,
             p->p_cred->pc_ucred));
+#endif
 }
 
 #endif
@@ -854,9 +862,6 @@ afs_syscall_pioctl(path, com, cmarg, follow)
     struct AFS_UCRED *foreigncreds = NULL;
     register afs_int32 code = 0;
     struct vnode *vp = NULL;
-#ifdef AFS_DEC_ENV
-    struct vnode *gp;
-#endif
 #ifdef AFS_AIX41_ENV
     struct ucred *credp = crref();     /* don't free until done! */
 #endif
@@ -950,11 +955,11 @@ afs_syscall_pioctl(path, com, cmarg, follow)
                       foreigncreds ? foreigncreds : credp);
 #else
 #ifdef AFS_LINUX22_ENV
-       code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
+       code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
        if (!code)
            vp = (struct vnode *)dp->d_inode;
 #else
-       code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
+       code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
 #endif /* AFS_LINUX22_ENV */
 #endif /* AFS_AIX41_ENV */
        AFS_GLOCK();
@@ -968,20 +973,22 @@ afs_syscall_pioctl(path, com, cmarg, follow)
     } else
        vp = NULL;
 
+#if defined(AFS_SUN510_ENV)
+    if (vp && !IsAfsVnode(vp)) {
+       struct vnode *realvp;
+       
+       if (VOP_REALVP(vp, &realvp) == 0) {
+           struct vnode *oldvp = vp;
+           
+           VN_HOLD(realvp);
+           vp = realvp;
+           AFS_RELE(oldvp);
+       }
+    }
+#endif
     /* now make the call if we were passed no file, or were passed an AFS file */
     if (!vp || IsAfsVnode(vp)) {
-#if defined(AFS_DEC_ENV)
-       /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
-        * So, we must test in this part of the code.  Also, must arrange to
-        * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
-        * we hold gnodes, whose references hold our vcache entries.
-        */
-       if (vp) {
-           gp = vp;            /* remember for "put" */
-           vp = (struct vnode *)afs_gntovn(vp);        /* get vcache from gp */
-       } else
-           gp = NULL;
-#elif defined(AFS_SUN5_ENV)
+#if defined(AFS_SUN5_ENV)
        code = afs_HandlePioctl(vp, com, &data, follow, &credp);
 #elif defined(AFS_AIX41_ENV)
        {
@@ -1020,12 +1027,6 @@ afs_syscall_pioctl(path, com, cmarg, follow)
 #else
        code = EINVAL;          /* not in /afs */
 #endif
-#ifdef AFS_DEC_ENV
-       if (vp) {
-           GRELE(vp);
-           vp = NULL;
-       }
-#endif
     }
 
   rescred:
@@ -1154,6 +1155,7 @@ afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
        } else {
            osi_FreeLargeSpace(inData);
        }
+       afs_PutFakeStat(&fakestate);
        return ENOMEM;
     }
     outSize = 0;
@@ -1203,7 +1205,7 @@ DECL_PIOCTL(PSetAcl)
     AFS_STATCNT(PSetAcl);
     if (!avc)
        return EINVAL;
-    if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
+    if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
        return EINVAL;
 
     acl.AFSOpaque_val = ain;
@@ -1470,8 +1472,10 @@ DECL_PIOCTL(PSetTokens)
 #else
        struct proc *p = curproc;       /* XXX */
 #endif
+#ifndef AFS_DARWIN80_ENV
        uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
                p->p_pid, p->p_comm);
+#endif
        if (!setpag(p, acred, -1, &pag, 1)) {
 #else
 #ifdef AFS_OSF_ENV
@@ -1675,7 +1679,7 @@ DECL_PIOCTL(PFlush)
     AFS_STATCNT(PFlush);
     if (!avc)
        return EINVAL;
-#if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
+#ifdef AFS_BOZONLOCK_ENV
     afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
     ObtainWriteLock(&avc->lock, 225);
@@ -1686,13 +1690,12 @@ DECL_PIOCTL(PFlush)
     /* now find the disk cache entries */
     afs_TryToSmush(avc, *acred, 1);
     osi_dnlc_purgedp(avc);
-    afs_symhint_inval(avc);
     if (avc->linkData && !(avc->states & CCore)) {
        afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
        avc->linkData = NULL;
     }
     ReleaseWriteLock(&avc->lock);
-#if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
+#ifdef AFS_BOZONLOCK_ENV
     afs_BozonUnlock(&avc->pvnLock, avc);
 #endif
     return 0;
@@ -1942,12 +1945,12 @@ DECL_PIOCTL(PCheckServers)
        pcheck = (struct chservinfo *)ain;
        if (pcheck->tinterval >= 0) {
            cp = aout;
-           memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
+           memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
            *aoutSize = sizeof(afs_int32);
            if (pcheck->tinterval > 0) {
                if (!afs_osi_suser(*acred))
                    return EACCES;
-               PROBE_INTERVAL = pcheck->tinterval;
+               afs_probe_interval = pcheck->tinterval;
            }
            return 0;
        }
@@ -2172,11 +2175,51 @@ DECL_PIOCTL(PSetCacheSize)
 DECL_PIOCTL(PGetCacheSize)
 {
     afs_int32 results[MAXGCSTATS];
-
+    afs_int32 flags;
+    register struct dcache * tdc;
+    int i, size;
+    
     AFS_STATCNT(PGetCacheSize);
+
+    if (sizeof(afs_int32) == ainSize){
+       memcpy((char *)&flags, ain, sizeof(afs_int32));
+    } else if (0 == ainSize){ 
+       flags = 0;
+    } else {
+       return EINVAL;
+    }
+    
     memset((char *)results, 0, sizeof(results));
     results[0] = afs_cacheBlocks;
     results[1] = afs_blocksUsed;
+    results[2] = afs_cacheFiles;
+    
+    if (1 == flags){
+        for (i = 0; i < afs_cacheFiles; i++) {
+           if (afs_indexFlags[i] & IFFree) results[3]++;
+       }
+    } else if (2 == flags){
+        for (i = 0; i < afs_cacheFiles; i++) {
+           if (afs_indexFlags[i] & IFFree) results[3]++;
+           if (afs_indexFlags[i] & IFEverUsed) results[4]++;
+           if (afs_indexFlags[i] & IFDataMod) results[5]++;
+           if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
+           if (afs_indexFlags[i] & IFAnyPages) results[7]++;
+           if (afs_indexFlags[i] & IFDiscarded) results[8]++;
+
+           tdc = afs_indexTable[i];
+           if (tdc){
+               results[9]++;
+               size = tdc->validPos;
+               if ( 0 < size && size < (1<<12) ) results[10]++;
+               else if (size < (1<<14) ) results[11]++;
+               else if (size < (1<<16) ) results[12]++;
+               else if (size < (1<<18) ) results[13]++;
+               else if (size < (1<<20) ) results[14]++;
+               else if (size >= (1<<20) ) results[15]++;
+           }
+        }
+    }
     memcpy(aout, (char *)results, sizeof(results));
     *aoutSize = sizeof(results);
     return 0;
@@ -2545,6 +2588,10 @@ DECL_PIOCTL(PFlushVolumeData)
     register struct vcache *tvc;
     register struct volume *tv;
     afs_int32 cell, volume;
+    struct afs_q *tq, *uq;
+#ifdef AFS_DARWIN80_ENV
+    vnode_t vp;
+#endif
 
     AFS_STATCNT(PFlushVolumeData);
     if (!avc)
@@ -2559,21 +2606,48 @@ DECL_PIOCTL(PFlushVolumeData)
      * Clear stat'd flag from all vnodes from this volume; this will invalidate all
      * the vcaches associated with the volume.
      */
+ loop:
     ObtainReadLock(&afs_xvcache);
-    for (i = 0; i < VCSIZE; i++) {
-       for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
+    i = VCHashV(&avc->fid);
+    for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
+           uq = QPrev(tq);
+           tvc = QTOVH(tq);
            if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
-#if    defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV)  || defined(AFS_SUN5_ENV)  || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
+               if (tvc->states & CVInit) {
+                   ReleaseReadLock(&afs_xvcache);
+                   afs_osi_Sleep(&tvc->states);
+                   goto loop;
+               }
+#ifdef AFS_DARWIN80_ENV
+               if (tvc->states & CDeadVnode) {
+                   ReleaseReadLock(&afs_xvcache);
+                   afs_osi_Sleep(&tvc->states);
+                   goto loop;
+               }
+#endif
+#if    defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV)  || defined(AFS_SUN5_ENV)  || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
                VN_HOLD(AFSTOV(tvc));
 #else
+#ifdef AFS_DARWIN80_ENV
+               vp = AFSTOV(tvc);
+               if (vnode_get(vp))
+                   continue;
+               if (vnode_ref(vp)) {
+                   AFS_GUNLOCK();
+                   vnode_put(vp);
+                   AFS_GLOCK();
+                   continue;
+               }
+#else
 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
                osi_vnhold(tvc, 0);
 #else
-               VREFCOUNT_INC(tvc);
+               VREFCOUNT_INC(tvc); /* AIX, apparently */
+#endif
 #endif
 #endif
                ReleaseReadLock(&afs_xvcache);
-#if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
+#ifdef AFS_BOZONLOCK_ENV
                afs_BozonLock(&tvc->pvnLock, tvc);      /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
                ObtainWriteLock(&tvc->lock, 232);
@@ -2586,15 +2660,18 @@ DECL_PIOCTL(PFlushVolumeData)
                    osi_dnlc_purgedp(tvc);
                afs_TryToSmush(tvc, *acred, 1);
                ReleaseWriteLock(&tvc->lock);
-#if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
+#ifdef AFS_BOZONLOCK_ENV
                afs_BozonUnlock(&tvc->pvnLock, tvc);
 #endif
+#ifdef AFS_DARWIN80_ENV
+               vnode_put(AFSTOV(tvc));
+#endif
                ObtainReadLock(&afs_xvcache);
+               uq = QPrev(tq);
                /* our tvc ptr is still good until now */
                AFS_FAST_RELE(tvc);
            }
        }
-    }
     ReleaseReadLock(&afs_xvcache);
 
 
@@ -2661,6 +2738,8 @@ DECL_PIOCTL(PGetVnodeXStatus)
        mode = PRSFS_READ;
     if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
        return EACCES;
+
+    memset(&stat, 0, sizeof(struct vcxstat));
     stat.fid = avc->fid;
     hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
     stat.lock = avc->lock;
@@ -2691,6 +2770,36 @@ DECL_PIOCTL(PGetVnodeXStatus)
 }
 
 
+DECL_PIOCTL(PGetVnodeXStatus2)
+{
+    register afs_int32 code;
+    struct vcxstat2 stat;
+    afs_int32 mode;
+
+    if (!avc)
+        return EINVAL;
+    code = afs_VerifyVCache(avc, areq);
+    if (code)
+        return code;
+    if (vType(avc) == VDIR)
+        mode = PRSFS_LOOKUP;
+    else
+        mode = PRSFS_READ;
+    if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
+        return EACCES;
+
+    memset(&stat, 0, sizeof(struct vcxstat2));
+
+    stat.cbExpires = avc->cbExpires;
+    stat.anyAccess = avc->anyAccess;
+    stat.mvstat = avc->mvstat;
+    stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
+
+    memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
+    *aoutSize = sizeof(struct vcxstat2);
+    return 0;
+}
+
 /* We require root for local sysname changes, but not for remote */
 /* (since we don't really believe remote uids anyway) */
  /* outname[] shouldn't really be needed- this is left as an excercise */
@@ -2703,7 +2812,7 @@ DECL_PIOCTL(PSetSysName)
     register struct unixuser *au;
     register afs_int32 pag, error;
     int t, count, num = 0;
-    char **sysnamelist[MAXSYSNAME];
+    char **sysnamelist[MAXNUMSYSNAMES];
 
     AFS_STATCNT(PSetSysName);
     if (!afs_globalVFS) {
@@ -3346,6 +3455,9 @@ HandleClientContext(struct afs_ioctl *ablob, int *com,
        uid = afs_nobody;       /* NFS_NOBODY == -2 */
     }
     newcred = crget();
+#if defined(AFS_LINUX26_ENV)
+    newcred->cr_group_info = groups_alloc(0);
+#endif
 #ifdef AFS_AIX41_ENV
     setuerror(0);
 #endif
@@ -3367,7 +3479,7 @@ HandleClientContext(struct afs_ioctl *ablob, int *com,
        newcred->cr_groups[i] = NOGROUP;
 #endif
 #endif
-#if    !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
+#if    !defined(AFS_OSF_ENV) 
     afs_nfsclient_init();      /* before looking for exporter, ensure one exists */
 #endif
     if (!(exporter = exporter_find(exporter_type))) {
@@ -3533,7 +3645,7 @@ DECL_PIOCTL(PFlushMount)
        code = EINVAL;
        goto out;
     }
-#if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
+#ifdef AFS_BOZONLOCK_ENV
     afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
     ObtainWriteLock(&tvc->lock, 649);
@@ -3544,13 +3656,12 @@ DECL_PIOCTL(PFlushMount)
     /* now find the disk cache entries */
     afs_TryToSmush(tvc, *acred, 1);
     osi_dnlc_purgedp(tvc);
-    afs_symhint_inval(tvc);
     if (tvc->linkData && !(tvc->states & CCore)) {
        afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
        tvc->linkData = NULL;
     }
     ReleaseWriteLock(&tvc->lock);
-#if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
+#ifdef AFS_BOZONLOCK_ENV
     afs_BozonUnlock(&tvc->pvnLock, tvc);
 #endif
     afs_PutVCache(tvc);