SOLARIS: Avoid uninitialized caller_context_t
[openafs.git] / src / afs / SOLARIS / osi_file.c
index 3139e01..4a4f79e 100644 (file)
@@ -10,8 +10,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 */
@@ -20,7 +18,6 @@ RCSID
 
 
 int afs_osicred_initialized = 0;
-struct AFS_UCRED afs_osi_cred;
 afs_lock_t afs_xosi;           /* lock is for tvattr */
 extern struct osi_dev cacheDev;
 extern struct vfs *afs_cacheVfsp;
@@ -45,11 +42,7 @@ afs_InitDualFSCacheOps(struct vnode *vp)
     int code;
     static int inited = 0;
     struct vfs *vfsp;
-#ifdef AFS_SUN56_ENV
     struct statvfs64 vfst;
-#else /* AFS_SUN56_ENV */
-    struct statvfs vfst;
-#endif /* AFS_SUN56_ENV */
 
     if (inited)
        return;
@@ -86,7 +79,11 @@ VnodeToIno(vnode_t * vp)
     struct vattr vattr;
 
     vattr.va_mask = AT_FSID | AT_NODEID;       /* quick return using this mask. */
-    code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
+#ifdef AFS_SUN511_ENV
+    code = VOP_GETATTR(vp, &vattr, 0, afs_osi_credp, NULL);
+#else
+    code = VOP_GETATTR(vp, &vattr, 0, afs_osi_credp);
+#endif
     if (code) {
        osi_Panic("VnodeToIno");
     }
@@ -101,7 +98,11 @@ VnodeToDev(vnode_t * vp)
 
     vattr.va_mask = AT_FSID | AT_NODEID;       /* quick return using this mask. */
     AFS_GUNLOCK();
-    code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
+#ifdef AFS_SUN511_ENV
+    code = VOP_GETATTR(vp, &vattr, 0, afs_osi_credp, NULL);
+#else
+    code = VOP_GETATTR(vp, &vattr, 0, afs_osi_credp);
+#endif
     AFS_GLOCK();
     if (code) {
        osi_Panic("VnodeToDev");
@@ -119,28 +120,32 @@ VnodeToSize(vnode_t * vp)
      * We lock xosi in osi_Stat, so we probably should
      * lock it here too - RWH.
      */
-    MObtainWriteLock(&afs_xosi, 578);
+    ObtainWriteLock(&afs_xosi, 578);
     vattr.va_mask = AT_SIZE;
     AFS_GUNLOCK();
-    code = VOP_GETATTR(vp, &vattr, 0, &afs_osi_cred);
+#ifdef AFS_SUN511_ENV
+    code = VOP_GETATTR(vp, &vattr, 0, afs_osi_credp, NULL);
+#else
+    code = VOP_GETATTR(vp, &vattr, 0, afs_osi_credp);
+#endif
     AFS_GLOCK();
     if (code) {
        osi_Panic("VnodeToSize");
     }
-    MReleaseWriteLock(&afs_xosi);
+    ReleaseWriteLock(&afs_xosi);
     return (afs_int32) (vattr.va_size);
 }
 
 void *
-osi_VxfsOpen(afs_int32 ainode)
+osi_VxfsOpen(afs_dcache_id_t *ainode)
 {
     struct vnode *vp;
-    register struct osi_file *afile = NULL;
+    struct osi_file *afile = NULL;
     afs_int32 code = 0;
     int dummy;
-    afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
+    afile = osi_AllocSmallSpace(sizeof(struct osi_file));
     AFS_GUNLOCK();
-    code = (*vxfs_vx_vp_byino) (afs_cacheVfsp, &vp, (unsigned int)ainode);
+    code = (*vxfs_vx_vp_byino) (afs_cacheVfsp, &vp, (unsigned int)ainode->ufs);
     AFS_GLOCK();
     if (code) {
        osi_FreeSmallSpace(afile);
@@ -150,51 +155,86 @@ osi_VxfsOpen(afs_int32 ainode)
     afile->size = VnodeToSize(afile->vnode);
     afile->offset = 0;
     afile->proc = (int (*)())0;
-    afile->inum = ainode;      /* for hint validity checking */
     return (void *)afile;
 }
 #endif /* AFS_HAVE_VXFS */
 
-#if defined(AFS_SUN57_64BIT_ENV)
-void *
-osi_UfsOpen(ino_t ainode)
-#else
 void *
-osi_UfsOpen(afs_int32 ainode)
-#endif
+osi_UfsOpen(afs_dcache_id_t *ainode)
 {
+#ifdef AFS_CACHE_VNODE_PATH
+    struct vnode *vp;
+#else
     struct inode *ip;
-    register struct osi_file *afile = NULL;
+#endif
+    struct osi_file *afile = NULL;
     afs_int32 code = 0;
     int dummy;
-    afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
+#ifdef AFS_CACHE_VNODE_PATH
+    char namebuf[1024];
+    struct pathname lookpn;
+#endif
+    struct osi_stat tstat;
+    afile = osi_AllocSmallSpace(sizeof(struct osi_file));
     AFS_GUNLOCK();
+
+/*
+ * AFS_CACHE_VNODE_PATH can be used with any file system, including ZFS or tmpfs.
+ * The ainode is not an inode number but a path.
+ */
+#ifdef AFS_CACHE_VNODE_PATH
+       /* Can not use vn_open or lookupname, they use user's CRED() 
+        * We need to run as root So must use low level lookuppnvp
+        * assume fname starts with /
+        */
+
+       code = pn_get_buf(ainode->ufs, AFS_UIOSYS, &lookpn, namebuf, sizeof(namebuf));
+    if (code != 0) 
+        osi_Panic("UfsOpen: pn_get_buf failed %ld %s", code, ainode->ufs);
+       VN_HOLD(rootdir); /* released in loopuppnvp */
+       code = lookuppnvp(&lookpn, NULL, FOLLOW, NULL, &vp, 
+           rootdir, rootdir, afs_osi_credp);
+    if (code != 0)  
+        osi_Panic("UfsOpen: lookuppnvp failed %ld %s", code, ainode->ufs);
+       
+#ifdef AFS_SUN511_ENV
+    code = VOP_OPEN(&vp, FREAD|FWRITE, afs_osi_credp, NULL);
+#else
+    code = VOP_OPEN(&vp, FREAD|FWRITE, afs_osi_credp);
+#endif
+
+    if (code != 0)
+        osi_Panic("UfsOpen: VOP_OPEN failed %ld %s", code, ainode->ufs);
+
+#else
     code =
-       igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip,
+       igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, ainode->ufs, &ip,
                  CRED(), &dummy);
+#endif
     AFS_GLOCK();
     if (code) {
        osi_FreeSmallSpace(afile);
-       osi_Panic("UfsOpen: igetinode failed");
+       osi_Panic("UfsOpen: igetinode failed %ld %s", code, ainode->ufs);
     }
+#ifdef AFS_CACHE_VNODE_PATH
+    afile->vnode = vp;
+    code = afs_osi_Stat(afile, &tstat);
+    afile->size = tstat.size;
+#else
     afile->vnode = ITOV(ip);
     afile->size = VTOI(afile->vnode)->i_size;
+#endif
     afile->offset = 0;
     afile->proc = (int (*)())0;
-    afile->inum = ainode;      /* for hint validity checking */
     return (void *)afile;
 }
 
 /**
   * In Solaris 7 we use 64 bit inode numbers
   */
-#if defined(AFS_SUN57_64BIT_ENV)
 void *
-osi_UFSOpen(ino_t ainode)
-#else
-void *
-osi_UFSOpen(afs_int32 ainode)
-#endif
+osi_UFSOpen(afs_dcache_id_t *ainode)
 {
     extern int cacheDiskType;
     AFS_STATCNT(osi_UFSOpen);
@@ -202,9 +242,7 @@ osi_UFSOpen(afs_int32 ainode)
        osi_Panic("UFSOpen called for non-UFS cache\n");
     }
     if (!afs_osicred_initialized) {
-       /* valid for alpha_osf, SunOS, Ultrix */
-       memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
-       crhold(&afs_osi_cred);  /* don't let it evaporate, since it is static */
+       afs_osi_credp = kcred;
        afs_osicred_initialized = 1;
     }
 #ifdef AFS_HAVE_VXFS
@@ -215,28 +253,32 @@ osi_UFSOpen(afs_int32 ainode)
 }
 
 int
-afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
+afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct vattr tvattr;
     AFS_STATCNT(osi_Stat);
-    MObtainWriteLock(&afs_xosi, 320);
+    ObtainWriteLock(&afs_xosi, 320);
     /* Ufs doesn't seem to care about the flags so we pass 0 for now */
     tvattr.va_mask = AT_ALL;
     AFS_GUNLOCK();
-    code = VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred);
+#ifdef AFS_SUN511_ENV 
+    code = VOP_GETATTR(afile->vnode, &tvattr, 0, afs_osi_credp, NULL);
+#else
+    code = VOP_GETATTR(afile->vnode, &tvattr, 0, afs_osi_credp);
+#endif
     AFS_GLOCK();
     if (code == 0) {
        astat->size = tvattr.va_size;
        astat->mtime = tvattr.va_mtime.tv_sec;
        astat->atime = tvattr.va_atime.tv_sec;
     }
-    MReleaseWriteLock(&afs_xosi);
+    ReleaseWriteLock(&afs_xosi);
     return code;
 }
 
 int
-osi_UFSClose(register struct osi_file *afile)
+osi_UFSClose(struct osi_file *afile)
 {
     AFS_STATCNT(osi_Close);
     if (afile->vnode) {
@@ -248,11 +290,11 @@ osi_UFSClose(register struct osi_file *afile)
 }
 
 int
-osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
+osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
 {
-    struct AFS_UCRED *oldCred;
+    afs_ucred_t *oldCred;
     struct vattr tvattr;
-    register afs_int32 code;
+    afs_int32 code;
     struct osi_stat tstat;
     AFS_STATCNT(osi_Truncate);
 
@@ -263,7 +305,7 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
     code = afs_osi_Stat(afile, &tstat);
     if (code || tstat.size <= asize)
        return code;
-    MObtainWriteLock(&afs_xosi, 321);
+    ObtainWriteLock(&afs_xosi, 321);
     tvattr.va_mask = AT_SIZE;
     tvattr.va_size = asize;
     /*
@@ -271,16 +313,12 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
      */
     AFS_GUNLOCK();
 #ifdef AFS_SUN510_ENV
-    {
-       caller_context_t ct;
-
-       code = VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, &ct);
-    }
+    code = VOP_SETATTR(afile->vnode, &tvattr, 0, afs_osi_credp, NULL);
 #else
-    code = VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred);
+    code = VOP_SETATTR(afile->vnode, &tvattr, 0, afs_osi_credp);
 #endif
     AFS_GLOCK();
-    MReleaseWriteLock(&afs_xosi);
+    ReleaseWriteLock(&afs_xosi);
     return code;
 }
 
@@ -288,29 +326,27 @@ void
 osi_DisableAtimes(struct vnode *avp)
 {
     if (afs_CacheFSType == AFS_SUN_UFS_CACHE) {
+#ifndef AFS_CACHE_VNODE_PATH 
        struct inode *ip = VTOI(avp);
        rw_enter(&ip->i_contents, RW_READER);
        mutex_enter(&ip->i_tlock);
        ip->i_flag &= ~IACC;
        mutex_exit(&ip->i_tlock);
        rw_exit(&ip->i_contents);
+#endif
     }
 }
 
 
 /* Generic read interface */
 int
-afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
+afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
             afs_int32 asize)
 {
-    struct AFS_UCRED *oldCred;
-#if defined(AFS_SUN57_ENV)
+    afs_ucred_t *oldCred;
     ssize_t resid;
-#else
-    int resid;
-#endif
-    register afs_int32 code;
-    register afs_int32 cnt1 = 0;
+    afs_int32 code;
+    afs_int32 cnt1 = 0;
     AFS_STATCNT(osi_Read);
 
     /**
@@ -321,7 +357,7 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
        if (!afs_shuttingdown)
            osi_Panic("osi_Read called with null param");
        else
-           return EIO;
+           return -EIO;
     }
 
     if (offset != -1)
@@ -329,7 +365,7 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
     AFS_GUNLOCK();
     code =
        gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
-                AFS_UIOSYS, 0, 0, &afs_osi_cred, &resid);
+                AFS_UIOSYS, 0, 0, afs_osi_credp, &resid);
     AFS_GLOCK();
     if (code == 0) {
        code = asize - resid;
@@ -338,23 +374,21 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
     } else {
        afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
                   ICL_TYPE_INT32, code);
-       code = -1;
+       if (code > 0) {
+           code = -code;
+       }
     }
     return code;
 }
 
 /* Generic write interface */
 int
-afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
+afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
              afs_int32 asize)
 {
-    struct AFS_UCRED *oldCred;
-#if defined(AFS_SUN57_ENV)
+    afs_ucred_t *oldCred;
     ssize_t resid;
-#else
-    int resid;
-#endif
-    register afs_int32 code;
+    afs_int32 code;
     AFS_STATCNT(osi_Write);
     if (!afile)
        osi_Panic("afs_osi_Write called with null param");
@@ -363,14 +397,16 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
     AFS_GUNLOCK();
     code =
        gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
-                afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, &afs_osi_cred,
+                afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, afs_osi_credp,
                 &resid);
     AFS_GLOCK();
     if (code == 0) {
        code = asize - resid;
        afile->offset += code;
     } else {
-       code = -1;
+       if (code > 0) {
+           code = -code;
+       }
     }
     if (afile->proc) {
        (*afile->proc) (afile, code);
@@ -383,7 +419,7 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
     This routine written from the RT NFS port strategy routine.
     It has been generalized a bit, but should still be pretty clear. */
 int
-afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
+afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
 {
     afs_int32 returnCode;