osi_UfsOpen(afs_int32 ainode)
#endif
{
+#ifdef AFS_CACHE_VNODE_PATH
+ struct vnode *vp;
+#else
struct inode *ip;
+#endif
register struct osi_file *afile = NULL;
afs_int32 code = 0;
+#ifdef AFS_CACHE_VNODE_PATH
int dummy;
+ char fname[1024];
+ char namebuf[1024];
+ struct pathname lookpn;
+#endif
+ struct osi_stat tstat;
afile = (struct osi_file *)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 signed index used to generate file names.
+ */
+#ifdef AFS_CACHE_VNODE_PATH
+ switch (ainode) {
+ case AFS_CACHE_CELLS_INODE:
+ snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CellItems");
+ break;
+ case AFS_CACHE_ITEMS_INODE:
+ snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "CacheItems");
+ break;
+ case AFS_CACHE_VOLUME_INODE:
+ snprintf(fname, 1024, "%s/%s", afs_cachebasedir, "VolumeItems");
+ break;
+ default:
+ dummy = ainode / afs_numfilesperdir;
+ snprintf(fname, 1024, "%s/D%d/V%d", afs_cachebasedir, dummy, ainode);
+ }
+
+ /* 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(fname, AFS_UIOSYS, &lookpn, namebuf, sizeof(namebuf));
+ if (code != 0)
+ osi_Panic("UfsOpen: pn_get_buf failed %ld %s %ld", code, fname, ainode);
+
+ VN_HOLD(rootdir); /* released in loopuppnvp */
+ code = lookuppnvp(&lookpn, NULL, FOLLOW, NULL, &vp,
+ rootdir, rootdir, &afs_osi_cred);
+ if (code != 0)
+ osi_Panic("UfsOpen: lookuppnvp failed %ld %s %ld", code, fname, ainode);
+
+#ifdef AFS_SUN511_ENV
+ code = VOP_OPEN(&vp, FREAD|FWRITE, &afs_osi_cred, NULL);
+#else
+ code = VOP_OPEN(&vp, FREAD|FWRITE, &afs_osi_cred);
+#endif
+
+ if (code != 0)
+ osi_Panic("UfsOpen: VOP_OPEN failed %ld %s %ld", code, fname, ainode);
+
+#else
code =
igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip,
CRED(), &dummy);
+#endif
AFS_GLOCK();
if (code) {
osi_FreeSmallSpace(afile);
- osi_Panic("UfsOpen: igetinode failed");
+ osi_Panic("UfsOpen: igetinode failed %ld %s %ld", code, fname, ainode);
}
+#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 */
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
}
}