diff options
Diffstat (limited to 'fs/coda')
-rw-r--r-- | fs/coda/cache.c | 7 | ||||
-rw-r--r-- | fs/coda/cnode.c | 7 | ||||
-rw-r--r-- | fs/coda/coda_int.h | 7 | ||||
-rw-r--r-- | fs/coda/dir.c | 286 | ||||
-rw-r--r-- | fs/coda/file.c | 17 | ||||
-rw-r--r-- | fs/coda/inode.c | 46 | ||||
-rw-r--r-- | fs/coda/psdev.c | 88 | ||||
-rw-r--r-- | fs/coda/symlink.c | 2 | ||||
-rw-r--r-- | fs/coda/sysctl.c | 228 | ||||
-rw-r--r-- | fs/coda/upcall.c | 454 |
10 files changed, 447 insertions, 695 deletions
diff --git a/fs/coda/cache.c b/fs/coda/cache.c index fcb88fa8d2f2..8a2370341c7a 100644 --- a/fs/coda/cache.c +++ b/fs/coda/cache.c @@ -43,17 +43,12 @@ void coda_cache_enter(struct inode *inode, int mask) void coda_cache_clear_inode(struct inode *inode) { struct coda_inode_info *cii = ITOC(inode); - cii->c_cached_perm = 0; + cii->c_cached_epoch = atomic_read(&permission_epoch) - 1; } /* remove all acl caches */ void coda_cache_clear_all(struct super_block *sb) { - struct coda_sb_info *sbi; - - sbi = coda_sbp(sb); - BUG_ON(!sbi); - atomic_inc(&permission_epoch); } diff --git a/fs/coda/cnode.c b/fs/coda/cnode.c index 28c872747f81..a7a780929eec 100644 --- a/fs/coda/cnode.c +++ b/fs/coda/cnode.c @@ -55,11 +55,6 @@ static int coda_set_inode(struct inode *inode, void *data) return 0; } -static int coda_fail_inode(struct inode *inode, void *data) -{ - return -1; -} - struct inode * coda_iget(struct super_block * sb, struct CodaFid * fid, struct coda_vattr * attr) { @@ -141,7 +136,7 @@ struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb) return NULL; } - inode = iget5_locked(sb, hash, coda_test_inode, coda_fail_inode, fid); + inode = ilookup5(sb, hash, coda_test_inode, fid); if ( !inode ) return NULL; diff --git a/fs/coda/coda_int.h b/fs/coda/coda_int.h index 9e6338fea514..8ccd5ed81d9c 100644 --- a/fs/coda/coda_int.h +++ b/fs/coda/coda_int.h @@ -1,12 +1,19 @@ #ifndef _CODA_INT_ #define _CODA_INT_ +struct dentry; + extern struct file_system_type coda_fs_type; +extern unsigned long coda_timeout; +extern int coda_hard; +extern int coda_fake_statfs; void coda_destroy_inodecache(void); int coda_init_inodecache(void); int coda_fsync(struct file *coda_file, struct dentry *coda_dentry, int datasync); +void coda_sysctl_init(void); +void coda_sysctl_clean(void); #endif /* _CODA_INT_ */ diff --git a/fs/coda/dir.c b/fs/coda/dir.c index 898a86dde8f5..04a3dd84c993 100644 --- a/fs/coda/dir.c +++ b/fs/coda/dir.c @@ -25,7 +25,6 @@ #include <linux/coda_psdev.h> #include <linux/coda_fs_i.h> #include <linux/coda_cache.h> -#include <linux/coda_proc.h> #include "coda_int.h" @@ -43,15 +42,15 @@ static int coda_rename(struct inode *old_inode, struct dentry *old_dentry, struct inode *new_inode, struct dentry *new_dentry); /* dir file-ops */ -static int coda_readdir(struct file *file, void *dirent, filldir_t filldir); +static int coda_readdir(struct file *file, void *buf, filldir_t filldir); /* dentry ops */ static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd); static int coda_dentry_delete(struct dentry *); /* support routines */ -static int coda_venus_readdir(struct file *filp, filldir_t filldir, - void *dirent, struct dentry *dir); +static int coda_venus_readdir(struct file *coda_file, void *buf, + filldir_t filldir); /* same as fs/bad_inode.c */ static int coda_return_EIO(void) @@ -97,58 +96,45 @@ const struct file_operations coda_dir_operations = { /* access routines: lookup, readlink, permission */ static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, struct nameidata *nd) { - struct inode *res_inode = NULL; + struct inode *inode = NULL; struct CodaFid resfid = { { 0, } }; - int dropme = 0; /* to indicate entry should not be cached */ int type = 0; int error = 0; const char *name = entry->d_name.name; size_t length = entry->d_name.len; - - if ( length > CODA_MAXNAMLEN ) { - printk("name too long: lookup, %s (%*s)\n", + + if (length > CODA_MAXNAMLEN) { + printk(KERN_ERR "name too long: lookup, %s (%*s)\n", coda_i2s(dir), (int)length, name); return ERR_PTR(-ENAMETOOLONG); } + /* control object, create inode on the fly */ + if (coda_isroot(dir) && coda_iscontrol(name, length)) { + error = coda_cnode_makectl(&inode, dir->i_sb); + type = CODA_NOCACHE; + goto exit; + } + lock_kernel(); - /* control object, create inode on the fly */ - if (coda_isroot(dir) && coda_iscontrol(name, length)) { - error = coda_cnode_makectl(&res_inode, dir->i_sb); - dropme = 1; - goto exit; - } - error = venus_lookup(dir->i_sb, coda_i2f(dir), - (const char *)name, length, &type, &resfid); + error = venus_lookup(dir->i_sb, coda_i2f(dir), name, length, + &type, &resfid); + if (!error) + error = coda_cnode_make(&inode, &resfid, dir->i_sb); - res_inode = NULL; - if (!error) { - if (type & CODA_NOCACHE) { - type &= (~CODA_NOCACHE); - dropme = 1; - } + unlock_kernel(); - error = coda_cnode_make(&res_inode, &resfid, dir->i_sb); - if (error) { - unlock_kernel(); - return ERR_PTR(error); - } - } else if (error != -ENOENT) { - unlock_kernel(); + if (error && error != -ENOENT) return ERR_PTR(error); - } exit: - entry->d_time = 0; entry->d_op = &coda_dentry_operations; - d_add(entry, res_inode); - if ( dropme ) { - d_drop(entry); - coda_flag_inode(res_inode, C_VATTR); - } - unlock_kernel(); - return NULL; + + if (inode && (type & CODA_NOCACHE)) + coda_flag_inode(inode, C_VATTR | C_PURGE); + + return d_splice_alias(inode, entry); } @@ -161,8 +147,6 @@ int coda_permission(struct inode *inode, int mask, struct nameidata *nd) lock_kernel(); - coda_vfs_stat.permission++; - if (coda_cache_check(inode, mask)) goto out; @@ -173,12 +157,11 @@ int coda_permission(struct inode *inode, int mask, struct nameidata *nd) out: unlock_kernel(); - - return error; + return error; } -static inline void coda_dir_changed(struct inode *dir, int link) +static inline void coda_dir_update_mtime(struct inode *dir) { #ifdef REQUERY_VENUS_FOR_MTIME /* invalidate the directory cnode's attributes so we refetch the @@ -186,12 +169,27 @@ static inline void coda_dir_changed(struct inode *dir, int link) coda_flag_inode(dir, C_VATTR); #else /* optimistically we can also act as if our nose bleeds. The - * granularity of the mtime is coarse anyways so we might actually be - * right most of the time. Note: we only do this for directories. */ + * granularity of the mtime is coarse anyways so we might actually be + * right most of the time. Note: we only do this for directories. */ dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; #endif - if (link) - dir->i_nlink += link; +} + +/* we have to wrap inc_nlink/drop_nlink because sometimes userspace uses a + * trick to fool GNU find's optimizations. If we can't be sure of the link + * (because of volume mount points) we set i_nlink to 1 which forces find + * to consider every child as a possible directory. We should also never + * see an increment or decrement for deleted directories where i_nlink == 0 */ +static inline void coda_dir_inc_nlink(struct inode *dir) +{ + if (dir->i_nlink >= 2) + inc_nlink(dir); +} + +static inline void coda_dir_drop_nlink(struct inode *dir) +{ + if (dir->i_nlink > 2) + drop_nlink(dir); } /* creation routines: create, mknod, mkdir, link, symlink */ @@ -205,7 +203,6 @@ static int coda_create(struct inode *dir, struct dentry *de, int mode, struct na struct coda_vattr attrs; lock_kernel(); - coda_vfs_stat.create++; if (coda_isroot(dir) && coda_iscontrol(name, length)) { unlock_kernel(); @@ -229,10 +226,10 @@ static int coda_create(struct inode *dir, struct dentry *de, int mode, struct na } /* invalidate the directory cnode's attributes */ - coda_dir_changed(dir, 0); + coda_dir_update_mtime(dir); unlock_kernel(); d_instantiate(de, inode); - return 0; + return 0; } static int coda_mkdir(struct inode *dir, struct dentry *de, int mode) @@ -245,7 +242,6 @@ static int coda_mkdir(struct inode *dir, struct dentry *de, int mode) struct CodaFid newfid; lock_kernel(); - coda_vfs_stat.mkdir++; if (coda_isroot(dir) && coda_iscontrol(name, len)) { unlock_kernel(); @@ -268,12 +264,13 @@ static int coda_mkdir(struct inode *dir, struct dentry *de, int mode) d_drop(de); return PTR_ERR(inode); } - + /* invalidate the directory cnode's attributes */ - coda_dir_changed(dir, 1); + coda_dir_inc_nlink(dir); + coda_dir_update_mtime(dir); unlock_kernel(); d_instantiate(de, inode); - return 0; + return 0; } /* try to make de an entry in dir_inodde linked to source_de */ @@ -286,7 +283,6 @@ static int coda_link(struct dentry *source_de, struct inode *dir_inode, int error; lock_kernel(); - coda_vfs_stat.link++; if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) { unlock_kernel(); @@ -296,16 +292,16 @@ static int coda_link(struct dentry *source_de, struct inode *dir_inode, error = venus_link(dir_inode->i_sb, coda_i2f(inode), coda_i2f(dir_inode), (const char *)name, len); - if (error) { + if (error) { d_drop(de); goto out; } - coda_dir_changed(dir_inode, 0); + coda_dir_update_mtime(dir_inode); atomic_inc(&inode->i_count); d_instantiate(de, inode); inc_nlink(inode); - + out: unlock_kernel(); return(error); @@ -318,10 +314,9 @@ static int coda_symlink(struct inode *dir_inode, struct dentry *de, const char *name = de->d_name.name; int len = de->d_name.len; int symlen; - int error=0; - + int error = 0; + lock_kernel(); - coda_vfs_stat.symlink++; if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) { unlock_kernel(); @@ -336,18 +331,18 @@ static int coda_symlink(struct inode *dir_inode, struct dentry *de, /* * This entry is now negative. Since we do not create - * an inode for the entry we have to drop it. + * an inode for the entry we have to drop it. */ d_drop(de); - error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len, + error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len, symname, symlen); /* mtime is no good anymore */ if ( !error ) - coda_dir_changed(dir_inode, 0); + coda_dir_update_mtime(dir_inode); unlock_kernel(); - return error; + return error; } /* destruction routines: unlink, rmdir */ @@ -358,79 +353,70 @@ int coda_unlink(struct inode *dir, struct dentry *de) int len = de->d_name.len; lock_kernel(); - coda_vfs_stat.unlink++; - error = venus_remove(dir->i_sb, coda_i2f(dir), name, len); - if ( error ) { + error = venus_remove(dir->i_sb, coda_i2f(dir), name, len); + if ( error ) { unlock_kernel(); - return error; - } + return error; + } - coda_dir_changed(dir, 0); + coda_dir_update_mtime(dir); drop_nlink(de->d_inode); unlock_kernel(); - - return 0; + return 0; } int coda_rmdir(struct inode *dir, struct dentry *de) { const char *name = de->d_name.name; int len = de->d_name.len; - int error; + int error; lock_kernel(); - coda_vfs_stat.rmdir++; - if (!d_unhashed(de)) { - unlock_kernel(); - return -EBUSY; - } error = venus_rmdir(dir->i_sb, coda_i2f(dir), name, len); + if (!error) { + /* VFS may delete the child */ + if (de->d_inode) + de->d_inode->i_nlink = 0; - if ( error ) { - unlock_kernel(); - return error; - } - - coda_dir_changed(dir, -1); - drop_nlink(de->d_inode); - d_delete(de); + /* fix the link count of the parent */ + coda_dir_drop_nlink(dir); + coda_dir_update_mtime(dir); + } unlock_kernel(); - - return 0; + return error; } /* rename */ -static int coda_rename(struct inode *old_dir, struct dentry *old_dentry, +static int coda_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) { - const char *old_name = old_dentry->d_name.name; - const char *new_name = new_dentry->d_name.name; + const char *old_name = old_dentry->d_name.name; + const char *new_name = new_dentry->d_name.name; int old_length = old_dentry->d_name.len; int new_length = new_dentry->d_name.len; - int link_adjust = 0; - int error; + int error; lock_kernel(); - coda_vfs_stat.rename++; - error = venus_rename(old_dir->i_sb, coda_i2f(old_dir), - coda_i2f(new_dir), old_length, new_length, + error = venus_rename(old_dir->i_sb, coda_i2f(old_dir), + coda_i2f(new_dir), old_length, new_length, (const char *) old_name, (const char *)new_name); - if ( !error ) { + if ( !error ) { if ( new_dentry->d_inode ) { - if ( S_ISDIR(new_dentry->d_inode->i_mode) ) - link_adjust = 1; - - coda_dir_changed(old_dir, -link_adjust); - coda_dir_changed(new_dir, link_adjust); + if ( S_ISDIR(new_dentry->d_inode->i_mode) ) { + coda_dir_drop_nlink(old_dir); + coda_dir_inc_nlink(new_dir); + } + coda_dir_update_mtime(old_dir); + coda_dir_update_mtime(new_dir); coda_flag_inode(new_dentry->d_inode, C_VATTR); } else { coda_flag_inode(old_dir, C_VATTR); coda_flag_inode(new_dir, C_VATTR); - } + } } unlock_kernel(); @@ -439,44 +425,41 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry, /* file operations for directories */ -int coda_readdir(struct file *coda_file, void *dirent, filldir_t filldir) +int coda_readdir(struct file *coda_file, void *buf, filldir_t filldir) { - struct dentry *coda_dentry = coda_file->f_path.dentry; struct coda_file_info *cfi; struct file *host_file; - struct inode *host_inode; int ret; cfi = CODA_FTOC(coda_file); BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); host_file = cfi->cfi_container; - coda_vfs_stat.readdir++; + if (!host_file->f_op) + return -ENOTDIR; - host_inode = host_file->f_path.dentry->d_inode; - mutex_lock(&host_inode->i_mutex); - host_file->f_pos = coda_file->f_pos; + if (host_file->f_op->readdir) + { + /* potemkin case: we were handed a directory inode. + * We can't use vfs_readdir because we have to keep the file + * position in sync between the coda_file and the host_file. + * and as such we need grab the inode mutex. */ + struct inode *host_inode = host_file->f_path.dentry->d_inode; - if (!host_file->f_op->readdir) { - /* Venus: we must read Venus dirents from the file */ - ret = coda_venus_readdir(host_file, filldir, dirent, coda_dentry); - } else { - /* potemkin case: we were handed a directory inode. */ - /* Yuk, we can't call vfs_readdir because we are already - * holding the inode semaphore. */ - ret = -ENOTDIR; - if (!host_file->f_op || !host_file->f_op->readdir) - goto out; + mutex_lock(&host_inode->i_mutex); + host_file->f_pos = coda_file->f_pos; ret = -ENOENT; if (!IS_DEADDIR(host_inode)) { - ret = host_file->f_op->readdir(host_file, dirent, filldir); + ret = host_file->f_op->readdir(host_file, buf, filldir); file_accessed(host_file); } + + coda_file->f_pos = host_file->f_pos; + mutex_unlock(&host_inode->i_mutex); } -out: - coda_file->f_pos = host_file->f_pos; - mutex_unlock(&host_inode->i_mutex); + else /* Venus: we must read Venus dirents from a file */ + ret = coda_venus_readdir(coda_file, buf, filldir); return ret; } @@ -501,57 +484,68 @@ static inline unsigned int CDT2DT(unsigned char cdt) } /* support routines */ -static int coda_venus_readdir(struct file *filp, filldir_t filldir, - void *dirent, struct dentry *dir) +static int coda_venus_readdir(struct file *coda_file, void *buf, + filldir_t filldir) { int result = 0; /* # of entries returned */ + struct coda_file_info *cfi; + struct coda_inode_info *cii; + struct file *host_file; + struct dentry *de; struct venus_dirent *vdir; unsigned long vdir_size = (unsigned long)(&((struct venus_dirent *)0)->d_name); unsigned int type; struct qstr name; ino_t ino; - int ret, i; + int ret; + + cfi = CODA_FTOC(coda_file); + BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); + host_file = cfi->cfi_container; + + de = coda_file->f_path.dentry; + cii = ITOC(de->d_inode); vdir = kmalloc(sizeof(*vdir), GFP_KERNEL); if (!vdir) return -ENOMEM; - i = filp->f_pos; - switch(i) { + switch (coda_file->f_pos) { case 0: - ret = filldir(dirent, ".", 1, 0, dir->d_inode->i_ino, DT_DIR); + ret = filldir(buf, ".", 1, 0, de->d_inode->i_ino, DT_DIR); if (ret < 0) break; result++; - filp->f_pos++; + coda_file->f_pos++; /* fallthrough */ case 1: - ret = filldir(dirent, "..", 2, 1, dir->d_parent->d_inode->i_ino, DT_DIR); + ret = filldir(buf, "..", 2, 1, de->d_parent->d_inode->i_ino, DT_DIR); if (ret < 0) break; result++; - filp->f_pos++; + coda_file->f_pos++; /* fallthrough */ default: while (1) { /* read entries from the directory file */ - ret = kernel_read(filp, filp->f_pos - 2, (char *)vdir, + ret = kernel_read(host_file, coda_file->f_pos - 2, (char *)vdir, sizeof(*vdir)); if (ret < 0) { - printk("coda_venus_readdir: read dir failed %d\n", ret); + printk(KERN_ERR "coda readdir: read dir %s failed %d\n", + coda_f2s(&cii->c_fid), ret); break; } if (ret == 0) break; /* end of directory file reached */ /* catch truncated reads */ if (ret < vdir_size || ret < vdir_size + vdir->d_namlen) { - printk("coda_venus_readdir: short read: %ld\n", - filp->f_path.dentry->d_inode->i_ino); + printk(KERN_ERR "coda readdir: short read on %s\n", + coda_f2s(&cii->c_fid)); ret = -EBADF; break; } /* validate whether the directory file actually makes sense */ if (vdir->d_reclen < vdir_size + vdir->d_namlen) { - printk("coda_venus_readdir: Invalid dir: %ld\n", - filp->f_path.dentry->d_inode->i_ino); + printk(KERN_ERR "coda readdir: invalid dir %s\n", + coda_f2s(&cii->c_fid)); ret = -EBADF; break; } @@ -570,21 +564,21 @@ static int coda_venus_readdir(struct file *filp, filldir_t filldir, * userspace doesn't have to worry about breaking * getcwd by having mismatched inode numbers for * internal volume mountpoints. */ - ino = find_inode_number(dir, &name); + ino = find_inode_number(de, &name); if (!ino) ino = vdir->d_fileno; type = CDT2DT(vdir->d_type); - ret = filldir(dirent, name.name, name.len, filp->f_pos, - ino, type); + ret = filldir(buf, name.name, name.len, + coda_file->f_pos, ino, type); /* failure means no space for filling in this round */ if (ret < 0) break; result++; } /* we'll always have progress because d_reclen is unsigned and * we've already established it is non-zero. */ - filp->f_pos += vdir->d_reclen; + coda_file->f_pos += vdir->d_reclen; + } } - } kfree(vdir); return result ? result : ret; } diff --git a/fs/coda/file.c b/fs/coda/file.c index 99dbe866816d..7594962604c2 100644 --- a/fs/coda/file.c +++ b/fs/coda/file.c @@ -22,7 +22,6 @@ #include <linux/coda_linux.h> #include <linux/coda_fs_i.h> #include <linux/coda_psdev.h> -#include <linux/coda_proc.h> #include "coda_int.h" @@ -134,8 +133,6 @@ int coda_open(struct inode *coda_inode, struct file *coda_file) unsigned short coda_flags = coda_flags_to_cflags(flags); struct coda_file_info *cfi; - coda_vfs_stat.open++; - cfi = kmalloc(sizeof(struct coda_file_info), GFP_KERNEL); if (!cfi) return -ENOMEM; @@ -143,8 +140,11 @@ int coda_open(struct inode *coda_inode, struct file *coda_file) lock_kernel(); error = venus_open(coda_inode->i_sb, coda_i2f(coda_inode), coda_flags, - &host_file); - if (error || !host_file) { + &host_file); + if (!host_file) + error = -EIO; + + if (error) { kfree(cfi); unlock_kernel(); return error; @@ -173,8 +173,6 @@ int coda_flush(struct file *coda_file, fl_owner_t id) lock_kernel(); - coda_vfs_stat.flush++; - /* last close semantics */ fcnt = file_count(coda_file); if (fcnt > 1) @@ -216,8 +214,7 @@ int coda_release(struct inode *coda_inode, struct file *coda_file) int err = 0; lock_kernel(); - coda_vfs_stat.release++; - + if (!use_coda_close) { err = venus_release(coda_inode->i_sb, coda_i2f(coda_inode), coda_flags); @@ -268,8 +265,6 @@ int coda_fsync(struct file *coda_file, struct dentry *coda_dentry, int datasync) BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); host_file = cfi->cfi_container; - coda_vfs_stat.fsync++; - if (host_file->f_op && host_file->f_op->fsync) { host_dentry = host_file->f_path.dentry; host_inode = host_dentry->d_inode; diff --git a/fs/coda/inode.c b/fs/coda/inode.c index dbff1bd4fb96..6771a4271e33 100644 --- a/fs/coda/inode.c +++ b/fs/coda/inode.c @@ -83,7 +83,7 @@ void coda_destroy_inodecache(void) static int coda_remount(struct super_block *sb, int *flags, char *data) { - *flags |= MS_NODIRATIME; + *flags |= MS_NOATIME; return 0; } @@ -141,11 +141,10 @@ static int get_device_index(struct coda_mount_data *data) static int coda_fill_super(struct super_block *sb, void *data, int silent) { - struct inode *root = NULL; - struct coda_sb_info *sbi = NULL; + struct inode *root = NULL; struct venus_comm *vc = NULL; struct CodaFid fid; - int error; + int error; int idx; idx = get_device_index((struct coda_mount_data *) data); @@ -167,21 +166,14 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent) return -EBUSY; } - sbi = kmalloc(sizeof(struct coda_sb_info), GFP_KERNEL); - if(!sbi) { - return -ENOMEM; - } - vc->vc_sb = sb; - sbi->sbi_vcomm = vc; - - sb->s_fs_info = sbi; - sb->s_flags |= MS_NODIRATIME; /* probably even noatime */ - sb->s_blocksize = 1024; /* XXXXX what do we put here?? */ - sb->s_blocksize_bits = 10; - sb->s_magic = CODA_SUPER_MAGIC; - sb->s_op = &coda_super_operations; + sb->s_fs_info = vc; + sb->s_flags |= MS_NOATIME; + sb->s_blocksize = 4096; /* XXXXX what do we put here?? */ + sb->s_blocksize_bits = 12; + sb->s_magic = CODA_SUPER_MAGIC; + sb->s_op = &coda_super_operations; /* get root fid from Venus: this needs the root inode */ error = venus_rootfid(sb, &fid); @@ -207,26 +199,20 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent) return 0; error: - if (sbi) { - kfree(sbi); - if(vc) - vc->vc_sb = NULL; - } if (root) - iput(root); + iput(root); + if (vc) + vc->vc_sb = NULL; - return -EINVAL; + return -EINVAL; } static void coda_put_super(struct super_block *sb) { - struct coda_sb_info *sbi; - - sbi = coda_sbp(sb); - sbi->sbi_vcomm->vc_sb = NULL; + coda_vcp(sb)->vc_sb = NULL; + sb->s_fs_info = NULL; printk("Coda: Bye bye.\n"); - kfree(sbi); } static void coda_clear_inode(struct inode *inode) @@ -296,7 +282,7 @@ static int coda_statfs(struct dentry *dentry, struct kstatfs *buf) /* and fill in the rest */ buf->f_type = CODA_SUPER_MAGIC; - buf->f_bsize = 1024; + buf->f_bsize = 4096; buf->f_namelen = CODA_MAXNAMLEN; return 0; diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c index 803aacf0d49c..dcc6aead70f5 100644 --- a/fs/coda/psdev.c +++ b/fs/coda/psdev.c @@ -45,12 +45,9 @@ #include <linux/coda_linux.h> #include <linux/coda_fs_i.h> #include <linux/coda_psdev.h> -#include <linux/coda_proc.h> #include "coda_int.h" -#define upc_free(r) kfree(r) - /* statistics */ int coda_hard; /* allows signals during upcalls */ unsigned long coda_timeout = 30; /* .. secs, then signals will dequeue */ @@ -195,7 +192,8 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf, if (req->uc_opcode == CODA_OPEN_BY_FD) { struct coda_open_by_fd_out *outp = (struct coda_open_by_fd_out *)req->uc_data; - outp->fh = fget(outp->fd); + if (!outp->oh.result) + outp->fh = fget(outp->fd); } wake_up(&req->uc_sleep); @@ -263,7 +261,7 @@ static ssize_t coda_psdev_read(struct file * file, char __user * buf, } CODA_FREE(req->uc_data, sizeof(struct coda_in_hdr)); - upc_free(req); + kfree(req); out: unlock_kernel(); return (count ? count : retval); @@ -271,71 +269,70 @@ out: static int coda_psdev_open(struct inode * inode, struct file * file) { - struct venus_comm *vcp; - int idx; + struct venus_comm *vcp; + int idx, err; - lock_kernel(); idx = iminor(inode); - if(idx >= MAX_CODADEVS) { - unlock_kernel(); + if (idx < 0 || idx >= MAX_CODADEVS) return -ENODEV; - } + lock_kernel(); + + err = -EBUSY; vcp = &coda_comms[idx]; - if(vcp->vc_inuse) { - unlock_kernel(); - return -EBUSY; - } - - if (!vcp->vc_inuse++) { + if (!vcp->vc_inuse) { + vcp->vc_inuse++; + INIT_LIST_HEAD(&vcp->vc_pending); INIT_LIST_HEAD(&vcp->vc_processing); init_waitqueue_head(&vcp->vc_waitq); vcp->vc_sb = NULL; vcp->vc_seq = 0; + + file->private_data = vcp; + err = 0; } - - file->private_data = vcp; unlock_kernel(); - return 0; + return err; } static int coda_psdev_release(struct inode * inode, struct file * file) { - struct venus_comm *vcp = (struct venus_comm *) file->private_data; - struct upc_req *req, *tmp; + struct venus_comm *vcp = (struct venus_comm *) file->private_data; + struct upc_req *req, *tmp; - lock_kernel(); - if ( !vcp->vc_inuse ) { - unlock_kernel(); + if (!vcp || !vcp->vc_inuse ) { printk("psdev_release: Not open.\n"); return -1; } - if (--vcp->vc_inuse) { - unlock_kernel(); - return 0; - } - - /* Wakeup clients so they can return. */ + lock_kernel(); + + /* Wakeup clients so they can return. */ list_for_each_entry_safe(req, tmp, &vcp->vc_pending, uc_chain) { + list_del(&req->uc_chain); + /* Async requests need to be freed here */ if (req->uc_flags & REQ_ASYNC) { CODA_FREE(req->uc_data, sizeof(struct coda_in_hdr)); - upc_free(req); + kfree(req); continue; } req->uc_flags |= REQ_ABORT; wake_up(&req->uc_sleep); - } - - list_for_each_entry(req, &vcp->vc_processing, uc_chain) { + } + + list_for_each_entry_safe(req, tmp, &vcp->vc_processing, uc_chain) { + list_del(&req->uc_chain); + req->uc_flags |= REQ_ABORT; - wake_up(&req->uc_sleep); - } + wake_up(&req->uc_sleep); + } + file->private_data = NULL; + vcp->vc_inuse--; unlock_kernel(); return 0; } @@ -376,21 +373,20 @@ out: return err; } - -MODULE_AUTHOR("Peter J. Braam <braam@cs.cmu.edu>"); +MODULE_AUTHOR("Jan Harkes, Peter J. Braam"); +MODULE_DESCRIPTION("Coda Distributed File System VFS interface"); +MODULE_ALIAS_CHARDEV_MAJOR(CODA_PSDEV_MAJOR); MODULE_LICENSE("GPL"); +#ifdef CONFIG_CODA_FS_OLD_API +MODULE_VERSION("5.3.21"); +#else +MODULE_VERSION("6.6"); +#endif static int __init init_coda(void) { int status; int i; - printk(KERN_INFO "Coda Kernel/Venus communications, " -#ifdef CONFIG_CODA_FS_OLD_API - "v5.3.20" -#else - "v6.0.0" -#endif - ", coda@cs.cmu.edu\n"); status = coda_init_inodecache(); if (status) diff --git a/fs/coda/symlink.c b/fs/coda/symlink.c index 76e00a65a75b..4513b7258458 100644 --- a/fs/coda/symlink.c +++ b/fs/coda/symlink.c @@ -20,7 +20,6 @@ #include <linux/coda_linux.h> #include <linux/coda_psdev.h> #include <linux/coda_fs_i.h> -#include <linux/coda_proc.h> static int coda_symlink_filler(struct file *file, struct page *page) { @@ -32,7 +31,6 @@ static int coda_symlink_filler(struct file *file, struct page *page) lock_kernel(); cii = ITOC(inode); - coda_vfs_stat.follow_link++; error = venus_readlink(inode->i_sb, &cii->c_fid, p, &len); unlock_kernel(); diff --git a/fs/coda/sysctl.c b/fs/coda/sysctl.c index c57a1fa7cf23..81b7771c6465 100644 --- a/fs/coda/sysctl.c +++ b/fs/coda/sysctl.c @@ -5,181 +5,14 @@ * * Carnegie Mellon encourages users to contribute improvements to * the Coda project. Contact Peter Braam (coda@cs.cmu.edu). - * - * CODA operation statistics - * (c) March, 1998 Zhanyong Wan <zhanyong.wan@yale.edu> - * */ -#include <linux/time.h> -#include <linux/mm.h> #include <linux/sysctl.h> -#include <linux/proc_fs.h> -#include <linux/seq_file.h> -#include <linux/slab.h> -#include <linux/stat.h> -#include <linux/ctype.h> -#include <linux/bitops.h> -#include <asm/uaccess.h> -#include <linux/utsname.h> -#include <linux/module.h> -#include <linux/coda.h> -#include <linux/coda_linux.h> -#include <linux/coda_fs_i.h> -#include <linux/coda_psdev.h> -#include <linux/coda_cache.h> -#include <linux/coda_proc.h> +#include "coda_int.h" static struct ctl_table_header *fs_table_header; -#define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */ -#define CODA_HARD 5 /* mount type "hard" or "soft" */ -#define CODA_VFS 6 /* vfs statistics */ -#define CODA_CACHE_INV 9 /* cache invalidation statistics */ -#define CODA_FAKE_STATFS 10 /* don't query venus for actual cache usage */ - -struct coda_vfs_stats coda_vfs_stat; -static struct coda_cache_inv_stats coda_cache_inv_stat; - -static void reset_coda_vfs_stats( void ) -{ - memset( &coda_vfs_stat, 0, sizeof( coda_vfs_stat ) ); -} - -static void reset_coda_cache_inv_stats( void ) -{ - memset( &coda_cache_inv_stat, 0, sizeof( coda_cache_inv_stat ) ); -} - -static int do_reset_coda_vfs_stats( ctl_table * table, int write, - struct file * filp, void __user * buffer, - size_t * lenp, loff_t * ppos ) -{ - if ( write ) { - reset_coda_vfs_stats(); - - *ppos += *lenp; - } else { - *lenp = 0; - } - - return 0; -} - -static int do_reset_coda_cache_inv_stats( ctl_table * table, int write, - struct file * filp, - void __user * buffer, - size_t * lenp, loff_t * ppos ) -{ - if ( write ) { - reset_coda_cache_inv_stats(); - - *ppos += *lenp; - } else { - *lenp = 0; - } - - return 0; -} - -static int proc_vfs_stats_show(struct seq_file *m, void *v) -{ - struct coda_vfs_stats * ps = & coda_vfs_stat; - - seq_printf(m, - "Coda VFS statistics\n" - "===================\n\n" - "File Operations:\n" - "\topen\t\t%9d\n" - "\tflush\t\t%9d\n" - "\trelease\t\t%9d\n" - "\tfsync\t\t%9d\n\n" - "Dir Operations:\n" - "\treaddir\t\t%9d\n\n" - "Inode Operations\n" - "\tcreate\t\t%9d\n" - "\tlookup\t\t%9d\n" - "\tlink\t\t%9d\n" - "\tunlink\t\t%9d\n" - "\tsymlink\t\t%9d\n" - "\tmkdir\t\t%9d\n" - "\trmdir\t\t%9d\n" - "\trename\t\t%9d\n" - "\tpermission\t%9d\n", - - /* file operations */ - ps->open, - ps->flush, - ps->release, - ps->fsync, - - /* dir operations */ - ps->readdir, - - /* inode operations */ - ps->create, - ps->lookup, - ps->link, - ps->unlink, - ps->symlink, - ps->mkdir, - ps->rmdir, - ps->rename, - ps->permission); - return 0; -} - -static int proc_cache_inv_stats_show(struct seq_file *m, void *v) -{ - struct coda_cache_inv_stats * ps = & coda_cache_inv_stat; - - seq_printf(m, - "Coda cache invalidation statistics\n" - "==================================\n\n" - "flush\t\t%9d\n" - "purge user\t%9d\n" - "zap_dir\t\t%9d\n" - "zap_file\t%9d\n" - "zap_vnode\t%9d\n" - "purge_fid\t%9d\n" - "replace\t\t%9d\n", - ps->flush, - ps->purge_user, - ps->zap_dir, - ps->zap_file, - ps->zap_vnode, - ps->purge_fid, - ps->replace ); - return 0; -} - -static int proc_vfs_stats_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_vfs_stats_show, NULL); -} - -static int proc_cache_inv_stats_open(struct inode *inode, struct file *file) -{ - return single_open(file, proc_cache_inv_stats_show, NULL); -} - -static const struct file_operations proc_vfs_stats_fops = { - .owner = THIS_MODULE, - .open = proc_vfs_stats_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static const struct file_operations proc_cache_inv_stats_fops = { - .owner = THIS_MODULE, - .open = proc_cache_inv_stats_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - static ctl_table coda_table[] = { { .ctl_name = CTL_UNNUMBERED, @@ -199,22 +32,6 @@ static ctl_table coda_table[] = { }, { .ctl_name = CTL_UNNUMBERED, - .procname = "vfs_stats", - .data = NULL, - .maxlen = 0, - .mode = 0644, - .proc_handler = &do_reset_coda_vfs_stats - }, - { - .ctl_name = CTL_UNNUMBERED, - .procname = "cache_inv_stats", - .data = NULL, - .maxlen = 0, - .mode = 0644, - .proc_handler = &do_reset_coda_cache_inv_stats - }, - { - .ctl_name = CTL_UNNUMBERED, .procname = "fake_statfs", .data = &coda_fake_statfs, .maxlen = sizeof(int), @@ -235,59 +52,20 @@ static ctl_table fs_table[] = { }; -#ifdef CONFIG_PROC_FS - -/* - target directory structure: - /proc/fs (see linux/fs/proc/root.c) - /proc/fs/coda - /proc/fs/coda/{vfs_stats, - -*/ - -static struct proc_dir_entry* proc_fs_coda; - -#endif - void coda_sysctl_init(void) { - reset_coda_vfs_stats(); - reset_coda_cache_inv_stats(); - -#ifdef CONFIG_PROC_FS - proc_fs_coda = proc_mkdir("coda", proc_root_fs); - if (proc_fs_coda) { - struct proc_dir_entry *pde; - - proc_fs_coda->owner = THIS_MODULE; - pde = create_proc_entry("vfs_stats", 0, proc_fs_coda); - if (pde) - pde->proc_fops = &proc_vfs_stats_fops; - pde = create_proc_entry("cache_inv_stats", 0, proc_fs_coda); - if (pde) - pde->proc_fops = &proc_cache_inv_stats_fops; - } -#endif - #ifdef CONFIG_SYSCTL if ( !fs_table_header ) fs_table_header = register_sysctl_table(fs_table); -#endif +#endif } -void coda_sysctl_clean(void) +void coda_sysctl_clean(void) { - #ifdef CONFIG_SYSCTL if ( fs_table_header ) { unregister_sysctl_table(fs_table_header); fs_table_header = NULL; } #endif - -#ifdef CONFIG_PROC_FS - remove_proc_entry("cache_inv_stats", proc_fs_coda); - remove_proc_entry("vfs_stats", proc_fs_coda); - remove_proc_entry("coda", proc_root_fs); -#endif } diff --git a/fs/coda/upcall.c b/fs/coda/upcall.c index 5faacdb1a479..e4e766e5557c 100644 --- a/fs/coda/upcall.c +++ b/fs/coda/upcall.c @@ -35,12 +35,10 @@ #include <linux/coda_psdev.h> #include <linux/coda_fs_i.h> #include <linux/coda_cache.h> -#include <linux/coda_proc.h> -#define upc_alloc() kmalloc(sizeof(struct upc_req), GFP_KERNEL) -#define upc_free(r) kfree(r) +#include "coda_int.h" -static int coda_upcall(struct coda_sb_info *mntinfo, int inSize, int *outSize, +static int coda_upcall(struct venus_comm *vc, int inSize, int *outSize, union inputArgs *buffer); static void *alloc_upcall(int opcode, int size) @@ -86,13 +84,9 @@ int venus_rootfid(struct super_block *sb, struct CodaFid *fidp) insize = SIZE(root); UPARG(CODA_ROOT); - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); - - if (error) { - printk("coda_get_rootfid: error %d\n", error); - } else { + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); + if (!error) *fidp = outp->coda_root.VFid; - } CODA_FREE(inp, insize); return error; @@ -109,9 +103,9 @@ int venus_getattr(struct super_block *sb, struct CodaFid *fid, UPARG(CODA_GETATTR); inp->coda_getattr.VFid = *fid; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); - - *attr = outp->coda_getattr.attr; + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); + if (!error) + *attr = outp->coda_getattr.attr; CODA_FREE(inp, insize); return error; @@ -130,7 +124,7 @@ int venus_setattr(struct super_block *sb, struct CodaFid *fid, inp->coda_setattr.VFid = *fid; inp->coda_setattr.attr = *vattr; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -156,10 +150,11 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid, memcpy((char *)(inp) + offset, name, length); *((char *)inp + offset + length) = '\0'; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); - - *resfid = outp->coda_lookup.VFid; - *type = outp->coda_lookup.vtype; + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); + if (!error) { + *resfid = outp->coda_lookup.VFid; + *type = outp->coda_lookup.vtype; + } CODA_FREE(inp, insize); return error; @@ -188,7 +183,7 @@ int venus_store(struct super_block *sb, struct CodaFid *fid, int flags, inp->coda_store.VFid = *fid; inp->coda_store.flags = flags; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -206,7 +201,7 @@ int venus_release(struct super_block *sb, struct CodaFid *fid, int flags) inp->coda_release.VFid = *fid; inp->coda_release.flags = flags; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -235,7 +230,7 @@ int venus_close(struct super_block *sb, struct CodaFid *fid, int flags, inp->coda_close.VFid = *fid; inp->coda_close.flags = flags; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -251,12 +246,12 @@ int venus_open(struct super_block *sb, struct CodaFid *fid, insize = SIZE(open_by_fd); UPARG(CODA_OPEN_BY_FD); - inp->coda_open.VFid = *fid; - inp->coda_open.flags = flags; + inp->coda_open_by_fd.VFid = *fid; + inp->coda_open_by_fd.flags = flags; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); - - *fh = outp->coda_open_by_fd.fh; + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); + if (!error) + *fh = outp->coda_open_by_fd.fh; CODA_FREE(inp, insize); return error; @@ -281,11 +276,12 @@ int venus_mkdir(struct super_block *sb, struct CodaFid *dirfid, /* Venus must get null terminated string */ memcpy((char *)(inp) + offset, name, length); *((char *)inp + offset + length) = '\0'; - - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); - *attrs = outp->coda_mkdir.attr; - *newfid = outp->coda_mkdir.VFid; + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); + if (!error) { + *attrs = outp->coda_mkdir.attr; + *newfid = outp->coda_mkdir.VFid; + } CODA_FREE(inp, insize); return error; @@ -323,7 +319,7 @@ int venus_rename(struct super_block *sb, struct CodaFid *old_fid, memcpy((char *)(inp) + offset, new_name, new_length); *((char *)inp + offset + new_length) = '\0'; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -351,11 +347,12 @@ int venus_create(struct super_block *sb, struct CodaFid *dirfid, /* Venus must get null terminated string */ memcpy((char *)(inp) + offset, name, length); *((char *)inp + offset + length) = '\0'; - - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); - *attrs = outp->coda_create.attr; - *newfid = outp->coda_create.VFid; + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); + if (!error) { + *attrs = outp->coda_create.attr; + *newfid = outp->coda_create.VFid; + } CODA_FREE(inp, insize); return error; @@ -377,8 +374,8 @@ int venus_rmdir(struct super_block *sb, struct CodaFid *dirfid, inp->coda_rmdir.name = offset; memcpy((char *)(inp) + offset, name, length); *((char *)inp + offset + length) = '\0'; - - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -399,8 +396,8 @@ int venus_remove(struct super_block *sb, struct CodaFid *dirfid, inp->coda_remove.name = offset; memcpy((char *)(inp) + offset, name, length); *((char *)inp + offset + length) = '\0'; - - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -420,19 +417,18 @@ int venus_readlink(struct super_block *sb, struct CodaFid *fid, UPARG(CODA_READLINK); inp->coda_readlink.VFid = *fid; - - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); - - if (! error) { - retlen = outp->coda_readlink.count; + + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); + if (!error) { + retlen = outp->coda_readlink.count; if ( retlen > *length ) - retlen = *length; + retlen = *length; *length = retlen; result = (char *)outp + (long)outp->coda_readlink.data; memcpy(buffer, result, retlen); *(buffer + retlen) = '\0'; } - + CODA_FREE(inp, insize); return error; } @@ -458,8 +454,8 @@ int venus_link(struct super_block *sb, struct CodaFid *fid, /* make sure strings are null terminated */ memcpy((char *)(inp) + offset, name, len); *((char *)inp + offset + len) = '\0'; - - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -494,7 +490,7 @@ int venus_symlink(struct super_block *sb, struct CodaFid *fid, memcpy((char *)(inp) + offset, name, len); *((char *)inp + offset + len) = '\0'; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -509,9 +505,9 @@ int venus_fsync(struct super_block *sb, struct CodaFid *fid) insize=SIZE(fsync); UPARG(CODA_FSYNC); - inp->coda_fsync.VFid = *fid; - error = coda_upcall(coda_sbp(sb), sizeof(union inputArgs), - &outsize, inp); + inp->coda_fsync.VFid = *fid; + error = coda_upcall(coda_vcp(sb), sizeof(union inputArgs), + &outsize, inp); CODA_FREE(inp, insize); return error; @@ -529,7 +525,7 @@ int venus_access(struct super_block *sb, struct CodaFid *fid, int mask) inp->coda_access.VFid = *fid; inp->coda_access.flags = mask; - error = coda_upcall(coda_sbp(sb), insize, &outsize, inp); + error = coda_upcall(coda_vcp(sb), insize, &outsize, inp); CODA_FREE(inp, insize); return error; @@ -578,9 +574,9 @@ int venus_pioctl(struct super_block *sb, struct CodaFid *fid, goto exit; } - error = coda_upcall(coda_sbp(sb), SIZE(ioctl) + data->vi.in_size, - &outsize, inp); - + error = coda_upcall(coda_vcp(sb), SIZE(ioctl) + data->vi.in_size, + &outsize, inp); + if (error) { printk("coda_pioctl: Venus returns: %d for %s\n", error, coda_f2s(fid)); @@ -620,16 +616,13 @@ int venus_statfs(struct dentry *dentry, struct kstatfs *sfs) insize = max_t(unsigned int, INSIZE(statfs), OUTSIZE(statfs)); UPARG(CODA_STATFS); - error = coda_upcall(coda_sbp(dentry->d_sb), insize, &outsize, inp); - - if (!error) { + error = coda_upcall(coda_vcp(dentry->d_sb), insize, &outsize, inp); + if (!error) { sfs->f_blocks = outp->coda_statfs.stat.f_blocks; sfs->f_bfree = outp->coda_statfs.stat.f_bfree; sfs->f_bavail = outp->coda_statfs.stat.f_bavail; sfs->f_files = outp->coda_statfs.stat.f_files; sfs->f_ffree = outp->coda_statfs.stat.f_ffree; - } else { - printk("coda_statfs: Venus returns: %d\n", error); } CODA_FREE(inp, insize); @@ -638,96 +631,129 @@ int venus_statfs(struct dentry *dentry, struct kstatfs *sfs) /* * coda_upcall and coda_downcall routines. - * */ +static void block_signals(sigset_t *old) +{ + spin_lock_irq(¤t->sighand->siglock); + *old = current->blocked; + + sigfillset(¤t->blocked); + sigdelset(¤t->blocked, SIGKILL); + sigdelset(¤t->blocked, SIGSTOP); + sigdelset(¤t->blocked, SIGINT); + + recalc_sigpending(); + spin_unlock_irq(¤t->sighand->siglock); +} + +static void unblock_signals(sigset_t *old) +{ + spin_lock_irq(¤t->sighand->siglock); + current->blocked = *old; + recalc_sigpending(); + spin_unlock_irq(¤t->sighand->siglock); +} + +/* Don't allow signals to interrupt the following upcalls before venus + * has seen them, + * - CODA_CLOSE or CODA_RELEASE upcall (to avoid reference count problems) + * - CODA_STORE (to avoid data loss) + */ +#define CODA_INTERRUPTIBLE(r) (!coda_hard && \ + (((r)->uc_opcode != CODA_CLOSE && \ + (r)->uc_opcode != CODA_STORE && \ + (r)->uc_opcode != CODA_RELEASE) || \ + (r)->uc_flags & REQ_READ)) -static inline void coda_waitfor_upcall(struct upc_req *vmp, - struct venus_comm *vcommp) +static inline void coda_waitfor_upcall(struct upc_req *req) { DECLARE_WAITQUEUE(wait, current); + unsigned long timeout = jiffies + coda_timeout * HZ; + sigset_t old; + int blocked; - vmp->uc_posttime = jiffies; + block_signals(&old); + blocked = 1; - add_wait_queue(&vmp->uc_sleep, &wait); + add_wait_queue(&req->uc_sleep, &wait); for (;;) { - if ( !coda_hard && vmp->uc_opcode != CODA_CLOSE ) + if (CODA_INTERRUPTIBLE(req)) set_current_state(TASK_INTERRUPTIBLE); else set_current_state(TASK_UNINTERRUPTIBLE); - /* venus died */ - if ( !vcommp->vc_inuse ) - break; - /* got a reply */ - if ( vmp->uc_flags & ( REQ_WRITE | REQ_ABORT ) ) + if (req->uc_flags & (REQ_WRITE | REQ_ABORT)) break; - if ( !coda_hard && vmp->uc_opcode != CODA_CLOSE && signal_pending(current) ) { - /* if this process really wants to die, let it go */ - if ( sigismember(&(current->pending.signal), SIGKILL) || - sigismember(&(current->pending.signal), SIGINT) ) - break; - /* signal is present: after timeout always return - really smart idea, probably useless ... */ - if ( jiffies - vmp->uc_posttime > coda_timeout * HZ ) - break; + if (blocked && time_after(jiffies, timeout) && + CODA_INTERRUPTIBLE(req)) + { + unblock_signals(&old); + blocked = 0; + } + + if (signal_pending(current)) { + list_del(&req->uc_chain); + break; } - schedule(); + + if (blocked) + schedule_timeout(HZ); + else + schedule(); } - remove_wait_queue(&vmp->uc_sleep, &wait); - set_current_state(TASK_RUNNING); + if (blocked) + unblock_signals(&old); - return; + remove_wait_queue(&req->uc_sleep, &wait); + set_current_state(TASK_RUNNING); } -/* - * coda_upcall will return an error in the case of +/* + * coda_upcall will return an error in the case of * failed communication with Venus _or_ will peek at Venus * reply and return Venus' error. * * As venus has 2 types of errors, normal errors (positive) and internal * errors (negative), normal errors are negated, while internal errors * are all mapped to -EINTR, while showing a nice warning message. (jh) - * */ -static int coda_upcall(struct coda_sb_info *sbi, - int inSize, int *outSize, - union inputArgs *buffer) +static int coda_upcall(struct venus_comm *vcp, + int inSize, int *outSize, + union inputArgs *buffer) { - struct venus_comm *vcommp; union outputArgs *out; - struct upc_req *req; + union inputArgs *sig_inputArgs; + struct upc_req *req, *sig_req; int error = 0; - vcommp = sbi->sbi_vcomm; - if ( !vcommp->vc_inuse ) { - printk("No pseudo device in upcall comms at %p\n", vcommp); - return -ENXIO; + if (!vcp->vc_inuse) { + printk(KERN_NOTICE "coda: Venus dead, not sending upcall\n"); + return -ENXIO; } /* Format the request message. */ - req = upc_alloc(); - if (!req) { - printk("Failed to allocate upc_req structure\n"); + req = kmalloc(sizeof(struct upc_req), GFP_KERNEL); + if (!req) return -ENOMEM; - } + req->uc_data = (void *)buffer; req->uc_flags = 0; req->uc_inSize = inSize; req->uc_outSize = *outSize ? *outSize : inSize; req->uc_opcode = ((union inputArgs *)buffer)->ih.opcode; - req->uc_unique = ++vcommp->vc_seq; + req->uc_unique = ++vcp->vc_seq; init_waitqueue_head(&req->uc_sleep); - + /* Fill in the common input args. */ ((union inputArgs *)buffer)->ih.unique = req->uc_unique; /* Append msg to pending queue and poke Venus. */ - list_add_tail(&(req->uc_chain), &vcommp->vc_pending); - - wake_up_interruptible(&vcommp->vc_waitq); + list_add_tail(&req->uc_chain, &vcp->vc_pending); + + wake_up_interruptible(&vcp->vc_waitq); /* We can be interrupted while we wait for Venus to process * our request. If the interrupt occurs before Venus has read * the request, we dequeue and return. If it occurs after the @@ -738,67 +764,60 @@ static int coda_upcall(struct coda_sb_info *sbi, * ENODEV. */ /* Go to sleep. Wake up on signals only after the timeout. */ - coda_waitfor_upcall(req, vcommp); + coda_waitfor_upcall(req); - if (vcommp->vc_inuse) { /* i.e. Venus is still alive */ - /* Op went through, interrupt or not... */ - if (req->uc_flags & REQ_WRITE) { + /* Op went through, interrupt or not... */ + if (req->uc_flags & REQ_WRITE) { out = (union outputArgs *)req->uc_data; /* here we map positive Venus errors to kernel errors */ error = -out->oh.result; *outSize = req->uc_outSize; goto exit; - } - if ( !(req->uc_flags & REQ_READ) && signal_pending(current)) { - /* Interrupted before venus read it. */ - list_del(&(req->uc_chain)); - /* perhaps the best way to convince the app to - give up? */ - error = -EINTR; + } + + error = -EINTR; + if ((req->uc_flags & REQ_ABORT) || !signal_pending(current)) { + printk(KERN_WARNING "coda: Unexpected interruption.\n"); goto exit; - } - if ( (req->uc_flags & REQ_READ) && signal_pending(current) ) { - /* interrupted after Venus did its read, send signal */ - union inputArgs *sig_inputArgs; - struct upc_req *sig_req; - - list_del(&(req->uc_chain)); - error = -ENOMEM; - sig_req = upc_alloc(); - if (!sig_req) goto exit; - - CODA_ALLOC((sig_req->uc_data), char *, sizeof(struct coda_in_hdr)); - if (!sig_req->uc_data) { - upc_free(sig_req); - goto exit; - } - - error = -EINTR; - sig_inputArgs = (union inputArgs *)sig_req->uc_data; - sig_inputArgs->ih.opcode = CODA_SIGNAL; - sig_inputArgs->ih.unique = req->uc_unique; - - sig_req->uc_flags = REQ_ASYNC; - sig_req->uc_opcode = sig_inputArgs->ih.opcode; - sig_req->uc_unique = sig_inputArgs->ih.unique; - sig_req->uc_inSize = sizeof(struct coda_in_hdr); - sig_req->uc_outSize = sizeof(struct coda_in_hdr); - - /* insert at head of queue! */ - list_add(&(sig_req->uc_chain), &vcommp->vc_pending); - wake_up_interruptible(&vcommp->vc_waitq); - } else { - printk("Coda: Strange interruption..\n"); - error = -EINTR; - } - } else { /* If venus died i.e. !VC_OPEN(vcommp) */ - printk("coda_upcall: Venus dead on (op,un) (%d.%d) flags %d\n", - req->uc_opcode, req->uc_unique, req->uc_flags); - error = -ENODEV; } - exit: - upc_free(req); + /* Interrupted before venus read it. */ + if (!(req->uc_flags & REQ_READ)) + goto exit; + + /* Venus saw the upcall, make sure we can send interrupt signal */ + if (!vcp->vc_inuse) { + printk(KERN_INFO "coda: Venus dead, not sending signal.\n"); + goto exit; + } + + error = -ENOMEM; + sig_req = kmalloc(sizeof(struct upc_req), GFP_KERNEL); + if (!sig_req) goto exit; + + CODA_ALLOC((sig_req->uc_data), char *, sizeof(struct coda_in_hdr)); + if (!sig_req->uc_data) { + kfree(sig_req); + goto exit; + } + + error = -EINTR; + sig_inputArgs = (union inputArgs *)sig_req->uc_data; + sig_inputArgs->ih.opcode = CODA_SIGNAL; + sig_inputArgs->ih.unique = req->uc_unique; + + sig_req->uc_flags = REQ_ASYNC; + sig_req->uc_opcode = sig_inputArgs->ih.opcode; + sig_req->uc_unique = sig_inputArgs->ih.unique; + sig_req->uc_inSize = sizeof(struct coda_in_hdr); + sig_req->uc_outSize = sizeof(struct coda_in_hdr); + + /* insert at head of queue! */ + list_add(&(sig_req->uc_chain), &vcp->vc_pending); + wake_up_interruptible(&vcp->vc_waitq); + +exit: + kfree(req); return error; } @@ -838,77 +857,66 @@ static int coda_upcall(struct coda_sb_info *sbi, int coda_downcall(int opcode, union outputArgs * out, struct super_block *sb) { + struct inode *inode = NULL; + struct CodaFid *fid, *newfid; + /* Handle invalidation requests. */ - if ( !sb || !sb->s_root || !sb->s_root->d_inode) - return 0; - - switch (opcode) { - - case CODA_FLUSH : { - coda_cache_clear_all(sb); - shrink_dcache_sb(sb); - coda_flag_inode(sb->s_root->d_inode, C_FLUSH); - return(0); - } - - case CODA_PURGEUSER : { - coda_cache_clear_all(sb); - return(0); - } - - case CODA_ZAPDIR : { - struct inode *inode; - struct CodaFid *fid = &out->coda_zapdir.CodaFid; - - inode = coda_fid_to_inode(fid, sb); - if (inode) { - coda_flag_inode_children(inode, C_PURGE); - coda_flag_inode(inode, C_VATTR); - iput(inode); - } - - return(0); - } - - case CODA_ZAPFILE : { - struct inode *inode; - struct CodaFid *fid = &out->coda_zapfile.CodaFid; - inode = coda_fid_to_inode(fid, sb); - if ( inode ) { - coda_flag_inode(inode, C_VATTR); - iput(inode); - } - return 0; - } - - case CODA_PURGEFID : { - struct inode *inode; - struct CodaFid *fid = &out->coda_purgefid.CodaFid; - inode = coda_fid_to_inode(fid, sb); - if ( inode ) { + if ( !sb || !sb->s_root) + return 0; + + switch (opcode) { + case CODA_FLUSH: + coda_cache_clear_all(sb); + shrink_dcache_sb(sb); + if (sb->s_root->d_inode) + coda_flag_inode(sb->s_root->d_inode, C_FLUSH); + break; + + case CODA_PURGEUSER: + coda_cache_clear_all(sb); + break; + + case CODA_ZAPDIR: + fid = &out->coda_zapdir.CodaFid; + inode = coda_fid_to_inode(fid, sb); + if (inode) { + coda_flag_inode_children(inode, C_PURGE); + coda_flag_inode(inode, C_VATTR); + } + break; + + case CODA_ZAPFILE: + fid = &out->coda_zapfile.CodaFid; + inode = coda_fid_to_inode(fid, sb); + if (inode) + coda_flag_inode(inode, C_VATTR); + break; + + case CODA_PURGEFID: + fid = &out->coda_purgefid.CodaFid; + inode = coda_fid_to_inode(fid, sb); + if (inode) { coda_flag_inode_children(inode, C_PURGE); /* catch the dentries later if some are still busy */ coda_flag_inode(inode, C_PURGE); d_prune_aliases(inode); - iput(inode); - } - return 0; - } - - case CODA_REPLACE : { - struct inode *inode; - struct CodaFid *oldfid = &out->coda_replace.OldFid; - struct CodaFid *newfid = &out->coda_replace.NewFid; - inode = coda_fid_to_inode(oldfid, sb); - if ( inode ) { - coda_replace_fid(inode, oldfid, newfid); - iput(inode); - } - return 0; - } - } - return 0; + } + break; + + case CODA_REPLACE: + fid = &out->coda_replace.OldFid; + newfid = &out->coda_replace.NewFid; + inode = coda_fid_to_inode(fid, sb); + if (inode) + coda_replace_fid(inode, fid, newfid); + break; + } + + if (inode) + iput(inode); + + return 0; } |