OK, some pretty substantial rework here. I've merged the spl-file

stuff which only inclused the getf()/releasef() in to the vnode area
where it will only really be used.  These calls allow a user to
grab an open file struct given only the known open fd for a particular
user context.  ZFS makes use of these, but they're a bit tricky to
test from within the kernel since you already need the file open
and know the fd.  So we basically spook the system calls to setup
the environment we need for the splat test case and verify given
just the know fd we can get the file, create the needed vnode, and
then use the vnode interface as usual to read and write from it.

While I was hacking away I also noticed a NULL termination issue
in the second kobj test case so I fixed that too.  In fact, I fixed
a few other things as well but all for the best!



git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@51 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c
This commit is contained in:
behlendo
2008-03-18 23:20:30 +00:00
parent 5d86345d37
commit e4f1d29f89
14 changed files with 350 additions and 298 deletions
-1
View File
@@ -23,7 +23,6 @@ splat-objs += splat-rwlock.o
splat-objs += splat-time.o
splat-objs += splat-vnode.o
splat-objs += splat-kobj.o
splat-objs += splat-file.o
splatmodule := splat.ko
splatmoduledir := @kmoduledir@/kernel/lib/
-2
View File
@@ -593,7 +593,6 @@ splat_init(void)
SPLAT_SUBSYSTEM_INIT(time);
SPLAT_SUBSYSTEM_INIT(vnode);
SPLAT_SUBSYSTEM_INIT(kobj);
SPLAT_SUBSYSTEM_INIT(file);
dev = MKDEV(SPLAT_MAJOR, 0);
if ((rc = register_chrdev_region(dev, SPLAT_MINORS, "splatctl")))
@@ -655,7 +654,6 @@ splat_fini(void)
cdev_del(&splat_cdev);
unregister_chrdev_region(dev, SPLAT_MINORS);
SPLAT_SUBSYSTEM_FINI(file);
SPLAT_SUBSYSTEM_FINI(kobj);
SPLAT_SUBSYSTEM_FINI(vnode);
SPLAT_SUBSYSTEM_FINI(time);
-57
View File
@@ -1,57 +0,0 @@
#include "splat-internal.h"
#define SPLAT_SUBSYSTEM_FILE 0x0b00
#define SPLAT_FILE_NAME "file"
#define SPLAT_FILE_DESC "Kernel File Tests"
#define SPLAT_FILE_TEST1_ID 0x0b01
#define SPLAT_FILE_TEST1_NAME "getf"
#define SPLAT_FILE_TEST1_DESC "File getf/releasef Test"
static int
splat_file_test1(struct file *file, void *arg)
{
splat_vprint(file, SPLAT_FILE_TEST1_NAME, "WRITE A TEST, %d\n", 0);
return 0;
} /* splat_file_test1() */
splat_subsystem_t *
splat_file_init(void)
{
splat_subsystem_t *sub;
sub = kmalloc(sizeof(*sub), GFP_KERNEL);
if (sub == NULL)
return NULL;
memset(sub, 0, sizeof(*sub));
strncpy(sub->desc.name, SPLAT_FILE_NAME, SPLAT_NAME_SIZE);
strncpy(sub->desc.desc, SPLAT_FILE_DESC, SPLAT_DESC_SIZE);
INIT_LIST_HEAD(&sub->subsystem_list);
INIT_LIST_HEAD(&sub->test_list);
spin_lock_init(&sub->test_lock);
sub->desc.id = SPLAT_SUBSYSTEM_FILE;
SPLAT_TEST_INIT(sub, SPLAT_FILE_TEST1_NAME, SPLAT_FILE_TEST1_DESC,
SPLAT_FILE_TEST1_ID, splat_file_test1);
return sub;
} /* splat_file_init() */
void
splat_file_fini(splat_subsystem_t *sub)
{
ASSERT(sub);
SPLAT_TEST_FINI(sub, SPLAT_FILE_TEST1_ID);
kfree(sub);
} /* splat_file_fini() */
int
splat_file_id(void)
{
return SPLAT_SUBSYSTEM_FILE;
} /* splat_file_id() */
-3
View File
@@ -172,7 +172,6 @@ splat_subsystem_t * splat_thread_init(void);
splat_subsystem_t * splat_time_init(void);
splat_subsystem_t * splat_vnode_init(void);
splat_subsystem_t * splat_kobj_init(void);
splat_subsystem_t * splat_file_init(void);
void splat_condvar_fini(splat_subsystem_t *);
void splat_kmem_fini(splat_subsystem_t *);
@@ -184,7 +183,6 @@ void splat_thread_fini(splat_subsystem_t *);
void splat_time_fini(splat_subsystem_t *);
void splat_vnode_fini(splat_subsystem_t *);
void splat_kobj_fini(splat_subsystem_t *);
void splat_file_fini(splat_subsystem_t *);
int splat_condvar_id(void);
int splat_kmem_id(void);
@@ -196,6 +194,5 @@ int splat_thread_id(void);
int splat_time_id(void);
int splat_vnode_id(void);
int splat_kobj_id(void);
int splat_file_id(void);
#endif /* _SPLAT_INTERNAL_H */
+3 -2
View File
@@ -55,7 +55,7 @@ splat_kobj_test2(struct file *file, void *arg)
goto out;
}
buf = kmalloc(size, GFP_KERNEL);
buf = kmalloc(size + 1, GFP_KERNEL);
if (!buf) {
rc = -ENOMEM;
splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Failed to alloc "
@@ -63,6 +63,7 @@ splat_kobj_test2(struct file *file, void *arg)
goto out;
}
memset(buf, 0, size + 1);
rc = kobj_read_file(f, buf, size, 0);
if (rc < 0) {
splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Failed read of "
@@ -74,7 +75,7 @@ splat_kobj_test2(struct file *file, void *arg)
* isn't a perfect test since we didn't create the file however it is
* pretty unlikely there are garbage characters in your /etc/fstab */
if (size != (uint64_t)strlen(buf)) {
rc = EFBIG;
rc = -EFBIG;
splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Stat'ed size "
"(%lld) does not match number of bytes read "
"(%lld)\n", size, (uint64_t)strlen(buf));
+123 -2
View File
@@ -1,4 +1,5 @@
#include "splat-internal.h"
#include <linux/rcupdate.h>
#define SPLAT_SUBSYSTEM_VNODE 0x0900
#define SPLAT_VNODE_NAME "vnode"
@@ -28,6 +29,10 @@
#define SPLAT_VNODE_TEST6_NAME "vn_sync"
#define SPLAT_VNODE_TEST6_DESC "Vn_sync Test"
#define SPLAT_VNODE_TEST7_ID 0x0907
#define SPLAT_VNODE_TEST7_NAME "getf"
#define SPLAT_VNODE_TEST7_DESC "getf/releasef Test"
#define SPLAT_VNODE_TEST_FILE "/etc/fstab"
#define SPLAT_VNODE_TEST_FILE_AT "etc/fstab"
#define SPLAT_VNODE_TEST_FILE_RW "/tmp/spl.vnode.tmp"
@@ -130,7 +135,7 @@ splat_vnode_test3(struct file *file, void *arg)
}
if (strncmp(buf1, buf2, strlen(buf1))) {
rc = EINVAL;
rc = -EINVAL;
splat_vprint(file, SPLAT_VNODE_TEST3_NAME,
"Failed strncmp data written does not match "
"data read\nWrote: %sRead: %s\n", buf1, buf2);
@@ -315,7 +320,120 @@ out:
vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
return rc;
} /* splat_vnode_test4() */
} /* splat_vnode_test6() */
/* Basically a slightly modified version of sys_close() */
static int
fd_uninstall(int fd)
{
struct file *fp;
struct files_struct *files = current->files;
struct fdtable *fdt;
spin_lock(&files->file_lock);
fdt = files_fdtable(files);
if (fd >= fdt->max_fds)
goto out_unlock;
fp = fdt->fd[fd];
if (!fp)
goto out_unlock;
rcu_assign_pointer(fdt->fd[fd], NULL);
FD_CLR(fd, fdt->close_on_exec);
/* Dropping the lock here exposes a minor race but it allows me
* to use the existing kernel interfaces for this, and for a test
* case I think that's reasonable. */
spin_unlock(&files->file_lock);
put_unused_fd(fd);
out_unlock:
spin_unlock(&files->file_lock);
return -EBADF;
} /* fd_uninstall() */
static int
splat_vnode_test7(struct file *file, void *arg)
{
char buf1[32] = "SPL VNode Interface Test File\n";
char buf2[32] = "";
struct file *lfp;
file_t *fp;
int rc, fd;
/* Prep work needed to test getf/releasef */
fd = get_unused_fd();
if (fd < 0) {
splat_vprint(file, SPLAT_VNODE_TEST7_NAME,
"Failed to get unused fd (%d)\n", fd);
return fd;
}
lfp = filp_open(SPLAT_VNODE_TEST_FILE_RW, O_RDWR|O_CREAT|O_EXCL, 0644);
if (IS_ERR(lfp)) {
put_unused_fd(fd);
rc = PTR_ERR(lfp);
splat_vprint(file, SPLAT_VNODE_TEST7_NAME,
"Failed to filp_open: %s (%d)\n",
SPLAT_VNODE_TEST_FILE_RW, rc);
return rc;
}
/* Pair up the new fd and lfp in the current context, this allows
* getf to lookup the file struct simply by the known open fd */
fd_install(fd, lfp);
/* Actual getf()/releasef() test */
fp = vn_getf(fd);
if (fp == NULL) {
rc = -EINVAL;
splat_vprint(file, SPLAT_VNODE_TEST7_NAME,
"Failed to getf fd %d: (%d)\n", fd, rc);
goto out;
}
rc = vn_rdwr(UIO_WRITE, fp->f_vnode, buf1, strlen(buf1), 0,
UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
if (rc < 0) {
splat_vprint(file, SPLAT_VNODE_TEST7_NAME,
"Failed vn_rdwr write of test file: %s (%d)\n",
SPLAT_VNODE_TEST_FILE_RW, rc);
goto out;
}
rc = vn_rdwr(UIO_READ, fp->f_vnode, buf2, strlen(buf1), 0,
UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
if (rc < 0) {
splat_vprint(file, SPLAT_VNODE_TEST7_NAME,
"Failed vn_rdwr read of test file: %s (%d)\n",
SPLAT_VNODE_TEST_FILE_RW, rc);
goto out;
}
if (strncmp(buf1, buf2, strlen(buf1))) {
rc = -EINVAL;
splat_vprint(file, SPLAT_VNODE_TEST7_NAME,
"Failed strncmp data written does not match "
"data read\nWrote: %sRead: %s\n", buf1, buf2);
goto out;
}
rc = 0;
splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Wrote: %s", buf1);
splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Read: %s", buf2);
splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Successfully wrote and "
"read expected data pattern to test file: %s\n",
SPLAT_VNODE_TEST_FILE_RW);
out:
vn_releasef(fd);
fd_uninstall(fd);
filp_close(lfp, 0);
vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
return rc;
} /* splat_vnode_test7() */
splat_subsystem_t *
splat_vnode_init(void)
@@ -346,6 +464,8 @@ splat_vnode_init(void)
SPLAT_VNODE_TEST5_ID, splat_vnode_test5);
SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST6_NAME, SPLAT_VNODE_TEST6_DESC,
SPLAT_VNODE_TEST6_ID, splat_vnode_test6);
SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST7_NAME, SPLAT_VNODE_TEST7_DESC,
SPLAT_VNODE_TEST7_ID, splat_vnode_test7);
return sub;
} /* splat_vnode_init() */
@@ -355,6 +475,7 @@ splat_vnode_fini(splat_subsystem_t *sub)
{
ASSERT(sub);
SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST7_ID);
SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST6_ID);
SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST5_ID);
SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST4_ID);