#include "../h/smp_lock.h"
#endif
+#ifdef pgoff2loff
+#define pageoff(pp) pgoff2loff((pp)->index)
+#else
+#define pageoff(pp) pp->offset
+#endif
+
extern struct vcache *afs_globalVp;
extern struct dentry_operations *afs_dops;
static int afs_linux_readdir(struct file *fp,
void *dirbuf, filldir_t filldir)
{
+ extern struct DirEntry * afs_dir_GetBlob();
struct vcache *avc = (struct vcache*)FILE_INODE(fp);
struct vrequest treq;
register struct dcache *tdc;
len = strlen(de->name);
/* filldir returns -EINVAL when the buffer is full. */
- /* code = (*filldir)(dirbuf, de->name, len, offset, ino); */
- code = (*filldir)(dirbuf, de->name, len, offset, ino, DT_DIR);
+#ifdef AFS_LINUX24_ENV
+ {
+ unsigned int type=DT_UNKNOWN;
+ struct VenusFid afid;
+ struct vcache *tvc;
+ int vtype;
+ afid.Cell=avc->fid.Cell;
+ afid.Fid.Volume=avc->fid.Fid.Volume;
+ afid.Fid.Vnode=ntohl(de->fid.vnode);
+ afid.Fid.Unique=ntohl(de->fid.vunique);
+ if ((avc->states & CForeign) == 0 &&
+ (ntohl(de->fid.vnode) & 1)) {
+ type=DT_DIR;
+ } else if ((tvc=afs_FindVCache(&afid,0,0,0,0))) {
+ if (tvc->mvstat) {
+ type=DT_DIR;
+ } else if (((tvc->states) & (CStatd|CTruth))) {
+ /* CTruth will be set if the object has
+ *ever* been statd */
+ vtype=vType(tvc);
+ if (vtype == VDIR)
+ type=DT_DIR;
+ else if (vtype == VREG)
+ type=DT_REG;
+ /* Don't do this until we're sure it can't be a mtpt */
+ /* else if (vtype == VLNK)
+ type=DT_LNK; */
+ /* what other types does AFS support? */
+ }
+ }
+ code = (*filldir)(dirbuf, de->name, len, offset, ino, type);
+ }
+#else
+ code = (*filldir)(dirbuf, de->name, len, offset, ino);
+#endif
DRelease(de, 0);
if (code)
break;
}
/* Not allowed to directly read a directory. */
-int afs_linux_dir_read(struct file *fp, char *buf, size_t count, loff_t *ppos)
+ssize_t afs_linux_dir_read(struct file *fp, char *buf, size_t count, loff_t *ppos)
{
return -EISDIR;
}
lock_kernel();
#endif
- /* If it's a negative dentry, then there's nothing to do. */
- if (!vcp) {
-#ifdef AFS_LINUX24_ENV
- unlock_kernel();
-#endif
- AFS_GUNLOCK();
- return 0;
- }
-
/* Make this a fast path (no crref), since it's called so often. */
if (vcp->states & CStatd) {
if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
cred_t *credp;
struct vrequest treq;
struct vcache *vcp = (struct vcache*)dp->d_inode;
+ struct vcache *dvcp = (struct vcache*)dp->d_parent->d_inode;
+
AFS_GLOCK();
#ifdef AFS_LINUX24_ENV
lock_kernel();
#endif
- /* If it's a negative dentry, then there's nothing to do. */
- if (!vcp) {
-#ifdef AFS_LINUX24_ENV
- unlock_kernel();
-#endif
- AFS_GUNLOCK();
- return 0;
- }
-
/* Make this a fast path (no crref), since it's called so often. */
- if (vcp->states & CStatd) {
- if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
- check_bad_parent(dp); /* check and correct mvid */
- vcache2inode(vcp);
-#ifdef AFS_LINUX24_ENV
- unlock_kernel();
-#endif
- AFS_GUNLOCK();
- return 0;
+ if ((dvcp->states & CStatd)) {
+ if (dp->d_time != hgetlo(dvcp->m.DataVersion))
+ goto out_bad;
+ goto out_valid;
}
-
credp = crref();
code = afs_InitReq(&treq, credp);
if (!code)
- code = afs_VerifyVCache(vcp, &treq);
+ code = afs_VerifyVCache(dvcp, &treq);
+ crfree(credp);
+ if (code)
+ goto out_bad;
+ if (dp->d_time != hgetlo(dvcp->m.DataVersion))
+ goto out_bad;
+out_valid:
+ if (vcp) {
+ if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
+ check_bad_parent(dp); /* check and correct mvid */
+ /*vcache2inode(vcp);*/
+ }
#ifdef AFS_LINUX24_ENV
unlock_kernel();
#endif
AFS_GUNLOCK();
- crfree(credp);
return 1;
+
+out_bad:
+ /* d_drop(dp); Let cached_lookup do this so shrink_dcache_parent
+ is called */
+#ifdef AFS_LINUX24_ENV
+ unlock_kernel();
+#endif
+ AFS_GUNLOCK();
+ return 0;
}
/* afs_dentry_iput */
static void afs_dentry_iput(struct dentry *dp, struct inode *ip)
{
-#if defined(AFS_LINUX24_ENV)
- if (atomic_read(&ip->i_count) == 0 || atomic_read(&ip->i_count) & 0xffff0000) {
-#else
- if (ip->i_count == 0 || ip->i_count & 0xffff0000) {
-#endif
- osi_Panic("Bad refCount %d on inode 0x%x\n",
-#if defined(AFS_LINUX24_ENV)
- atomic_read(&ip->i_count), ip);
-#else
- ip->i_count, ip);
-#endif
- }
-#if defined(AFS_LINUX24_ENV)
- atomic_dec(&ip->i_count);
- if (!atomic_read(&ip->i_count)) {
-#else
- ip->i_count --;
- if (!ip->i_count) {
-#endif
- afs_delete_inode(ip);
- }
+ osi_iput(ip);
}
#if defined(AFS_LINUX24_ENV)
#endif
dp->d_op = afs_dops;
+ /* This DV is probably wrong, unfortunately, Perhaps we should
+ VerifyVCache the directory */
+ dp->d_time=hgetlo(((struct vcache *)dip)->m.DataVersion);
d_instantiate(dp, ip);
}
ip->i_op = &afs_symlink_iops;
#endif
}
+ /* directory ought to be stat'd here.... */
+ dp->d_time=hgetlo(((struct vcache *)dip)->m.DataVersion);
dp->d_op = afs_dops;
d_add(dp, (struct inode*)vcp);
AFS_GUNLOCK();
if (!code) {
d_delete(dp);
- if (putback)
+ if (putback) {
+ /* This DV is probably wrong, unfortunately, Perhaps we should
+ VerifyVCache the directory */
+ dp->d_time=hgetlo(((struct vcache *)dip)->m.DataVersion);
d_add(dp, NULL); /* means definitely does _not_ exist */
}
+ }
crfree(credp);
return -code;
}
tvcp->v.v_fop = &afs_dir_fops;
#endif
dp->d_op = afs_dops;
+ /* This DV is probably wrong, unfortunately, Perhaps we should
+ VerifyVCache the directory */
+ dp->d_time=hgetlo(((struct vcache *)dip)->m.DataVersion);
d_instantiate(dp, (struct inode*)tvcp);
}
AFS_GUNLOCK();
AFS_GLOCK();
code = afs_rmdir((struct vcache*)dip, name, credp);
- /* Linux likes to see ENOTDIR returned from an rmdir() syscall
+ /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
* that failed because a directory is not empty. So, we map
- * EEXIST to ENOTDIR on linux.
+ * EEXIST to ENOTEMPTY on linux.
*/
if (code == EEXIST) {
- code = ENOTDIR;
+ code = ENOTEMPTY;
}
if (!code) {
newname, credp);
AFS_GUNLOCK();
- if (!code)
+ if (!code) {
+ /* update time so it doesn't expire immediately */
+ /* This DV is probably wrong, unfortunately, Perhaps we should
+ VerifyVCache the directory */
+ newdp->d_time=hgetlo(((struct vcache *)newdp->d_parent->d_inode)->m.DataVersion);
d_move(olddp, newdp);
+ }
crfree(credp);
return -code;
{
int code = 0;
char *name;
+ struct dentry *res;
AFS_GLOCK();
name = osi_Alloc(PATH_MAX+1);
{
int code;
cred_t *credp = crref();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ char *address;
+ loff_t offset = pp->index << PAGE_CACHE_SHIFT;
+#else
ulong address = afs_linux_page_address(pp);
+ loff_t offset = pageoff(pp);
+#endif
uio_t tuio;
struct iovec iovec;
struct inode *ip = FILE_INODE(fp);
ICL_TYPE_POINTER, pp,
ICL_TYPE_INT32, cnt,
ICL_TYPE_INT32, 99999); /* not a possible code value */
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ address = kmap(pp);
+ ClearPageError(pp);
+
+ lock_kernel();
+#else
atomic_add(1, &pp->count);
set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
clear_bit(PG_error, &pp->flags);
+#endif
-#if defined(AFS_LINUX24_ENV)
- setup_uio(&tuio, &iovec, (char*)address, pp->index << PAGE_CACHE_SHIFT,
- PAGESIZE, UIO_READ, AFS_UIOSYS);
-#else
- setup_uio(&tuio, &iovec, (char*)address, pp->offset, PAGESIZE,
+ setup_uio(&tuio, &iovec, (char*)address, offset, PAGESIZE,
UIO_READ, AFS_UIOSYS);
-#endif
-#ifdef AFS_LINUX24_ENV
- lock_kernel();
-#endif
code = afs_rdwr((struct vcache*)ip, &tuio, UIO_READ, 0, credp);
-#ifdef AFS_LINUX24_ENV
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
unlock_kernel();
#endif
if (tuio.uio_resid) /* zero remainder of page */
memset((void*)(address+(PAGESIZE-tuio.uio_resid)), 0,
tuio.uio_resid);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ flush_dcache_page(pp);
+ SetPageUptodate(pp);
+#else
set_bit(PG_uptodate, &pp->flags);
+#endif
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
+ kunmap(pp);
+ UnlockPage(pp);
+#else
clear_bit(PG_locked, &pp->flags);
wake_up(&pp->wait);
free_page(address);
+#endif
crfree(credp);
afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
return -code;
}
-#ifdef NOTUSED
-/* afs_linux_writepage - is this used anywhere? swap files via nfs? */
-int afs_linux_writepage(struct inode *ip, struct page *) { return -EINVAL };
+#if defined(AFS_LINUX24_ENV)
+int afs_linux_writepage(struct page *pp)
+{
+ struct address_space *mapping = pp->mapping;
+ struct inode *inode;
+ unsigned long end_index;
+ unsigned offset = PAGE_CACHE_SIZE;
+ long status;
+
+ inode = (struct inode *) mapping->host;
+ end_index = inode->i_size >> PAGE_CACHE_SHIFT;
+
+ /* easy case */
+ if (pp->index < end_index)
+ goto do_it;
+ /* things got complicated... */
+ offset = inode->i_size & (PAGE_CACHE_SIZE-1);
+ /* OK, are we completely out? */
+ if (pp->index >= end_index+1 || !offset)
+ return -EIO;
+do_it:
+ AFS_GLOCK();
+ status = afs_linux_writepage_sync(inode, pp, 0, offset);
+ AFS_GUNLOCK();
+ SetPageUptodate(pp);
+ UnlockPage(pp);
+ if (status == offset)
+ return 0;
+ else
+ return status;
+}
+#endif
+#ifdef NOTUSED
/* afs_linux_bmap - supports generic_readpage, but we roll our own. */
int afs_linux_bmap(struct inode *ip, int) { return -EINVAL; }
int afs_linux_smap(struct inode *ip, int) { return -EINVAL; }
#endif
+#if defined(AFS_LINUX24_ENV)
+int afs_linux_writepage_sync(struct inode *ip, struct page *pp,
+ unsigned long offset,
+ unsigned int count)
+{
+ struct vcache *vcp = (struct vcache *) ip;
+ char *buffer;
+ loff_t base;
+ int code = 0;
+ cred_t *credp;
+ uio_t tuio;
+ struct iovec iovec;
+ int f_flags = 0;
+
+ buffer = kmap(pp) + offset;
+ base = (pp->index << PAGE_CACHE_SHIFT) + offset;
+
+ credp = crref();
+ afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
+ ICL_TYPE_POINTER, pp,
+ ICL_TYPE_INT32, atomic_read(&pp->count),
+ ICL_TYPE_INT32, 99999);
+ setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
+
+ code = afs_write(vcp, &tuio, f_flags, credp, 0);
+
+ vcache2inode(vcp);
+
+ code = code ? -code : count - tuio.uio_resid;
+ afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
+ ICL_TYPE_POINTER, pp,
+ ICL_TYPE_INT32, atomic_read(&pp->count),
+ ICL_TYPE_INT32, code);
+
+ crfree(credp);
+ kunmap(pp);
+
+ return code;
+}
+
+static int
+afs_linux_updatepage(struct file *file, struct page *page,
+ unsigned long offset, unsigned int count)
+{
+ struct dentry *dentry = file->f_dentry;
+
+ return afs_linux_writepage_sync(dentry->d_inode, page, offset, count);
+}
+#else
/* afs_linux_updatepage
* What one would have thought was writepage - write dirty page to file.
* Called from generic_file_write. buffer is still in user space. pagep
credp = crref();
AFS_GLOCK();
-#ifdef AFS_LINUX24_ENV
- lock_kernel();
-#endif
afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
ICL_TYPE_POINTER, pp,
ICL_TYPE_INT32, atomic_read(&pp->count),
ICL_TYPE_INT32, 99999);
-#if defined(AFS_LINUX24_ENV)
- setup_uio(&tuio, &iovec, page_addr + offset,
- (pp->index << PAGE_CACHE_SHIFT) + offset, count,
- UIO_WRITE, AFS_UIOSYS);
-#else
setup_uio(&tuio, &iovec, page_addr + offset, pp->offset + offset, count,
UIO_WRITE, AFS_UIOSYS);
-#endif
code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
ICL_TYPE_INT32, atomic_read(&pp->count),
ICL_TYPE_INT32, code);
-#ifdef AFS_LINUX24_ENV
- unlock_kernel();
-#endif
AFS_GUNLOCK();
crfree(credp);
clear_bit(PG_locked, &pp->flags);
return code;
}
+#endif
#if defined(AFS_LINUX24_ENV)
static int afs_linux_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to)
{
- long status;
- loff_t pos = ((loff_t)page->index<<PAGE_CACHE_SHIFT) + to;
+ int code;
- status = afs_linux_updatepage(file, page, offset, to-offset, 1);
+ AFS_GLOCK();
+ lock_kernel();
+ code = afs_linux_updatepage(file, page, offset, to-offset);
+ unlock_kernel();
+ AFS_GUNLOCK();
kunmap(page);
- return status;
+ return code;
}
static int afs_linux_prepare_write(struct file *file, struct page *page,
};
struct address_space_operations afs_file_aops = {
readpage: afs_linux_readpage,
+ writepage: afs_linux_writepage,
commit_write: afs_linux_commit_write,
prepare_write: afs_linux_prepare_write,
};
AFS_GLOCK();
lock_kernel();
code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
- unlock_kernel();
- AFS_GUNLOCK();
if (code<0)
goto fail;
p[code] = '\0'; /* null terminate? */
+ unlock_kernel();
+ AFS_GUNLOCK();
+
SetPageUptodate(page);
kunmap(page);
UnlockPage(page);
return 0;
fail:
+ unlock_kernel();
+ AFS_GUNLOCK();
+
SetPageError(page);
kunmap(page);
UnlockPage(page);