Release 4.11 fs/coda/psdev.c
/*
* An implementation of a loadable kernel mode driver providing
* multiple kernel/user space bidirectional communications links.
*
* Author: Alan Cox <alan@lxorguk.ukuu.org.uk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Adapted to become the Linux 2.0 Coda pseudo device
* Peter Braam <braam@maths.ox.ac.uk>
* Michael Callahan <mjc@emmy.smith.edu>
*
* Changes for Linux 2.1
* Copyright (c) 1997 Carnegie-Mellon University
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/time.h>
#include <linux/sched/signal.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/fcntl.h>
#include <linux/delay.h>
#include <linux/skbuff.h>
#include <linux/proc_fs.h>
#include <linux/vmalloc.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/poll.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/device.h>
#include <linux/pid_namespace.h>
#include <asm/io.h>
#include <asm/poll.h>
#include <linux/uaccess.h>
#include <linux/coda.h>
#include <linux/coda_psdev.h>
#include "coda_linux.h"
#include "coda_int.h"
/* statistics */
int coda_hard;
/* allows signals during upcalls */
unsigned long coda_timeout = 30;
/* .. secs, then signals will dequeue */
struct venus_comm coda_comms[MAX_CODADEVS];
static struct class *coda_psdev_class;
/*
* Device operations
*/
static unsigned int coda_psdev_poll(struct file *file, poll_table * wait)
{
struct venus_comm *vcp = (struct venus_comm *) file->private_data;
unsigned int mask = POLLOUT | POLLWRNORM;
poll_wait(file, &vcp->vc_waitq, wait);
mutex_lock(&vcp->vc_mutex);
if (!list_empty(&vcp->vc_pending))
mask |= POLLIN | POLLRDNORM;
mutex_unlock(&vcp->vc_mutex);
return mask;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 70 | 81.40% | 5 | 83.33% |
Yoshihisa Abe | 16 | 18.60% | 1 | 16.67% |
Total | 86 | 100.00% | 6 | 100.00% |
static long coda_psdev_ioctl(struct file * filp, unsigned int cmd, unsigned long arg)
{
unsigned int data;
switch(cmd) {
case CIOC_KERNEL_VERSION:
data = CODA_KERNEL_VERSION;
return put_user(data, (int __user *) arg);
default:
return -ENOTTY;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 55 | 96.49% | 1 | 33.33% |
Arnd Bergmann | 1 | 1.75% | 1 | 33.33% |
Al Viro | 1 | 1.75% | 1 | 33.33% |
Total | 57 | 100.00% | 3 | 100.00% |
/*
* Receive a message written by Venus to the psdev
*/
static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
size_t nbytes, loff_t *off)
{
struct venus_comm *vcp = (struct venus_comm *) file->private_data;
struct upc_req *req = NULL;
struct upc_req *tmp;
struct list_head *lh;
struct coda_in_hdr hdr;
ssize_t retval = 0, count = 0;
int error;
/* Peek at the opcode, uniquefier */
if (copy_from_user(&hdr, buf, 2 * sizeof(u_long)))
return -EFAULT;
if (DOWNCALL(hdr.opcode)) {
union outputArgs *dcbuf;
int size = sizeof(*dcbuf);
if ( nbytes < sizeof(struct coda_out_hdr) ) {
pr_warn("coda_downcall opc %d uniq %d, not enough!\n",
hdr.opcode, hdr.unique);
count = nbytes;
goto out;
}
if ( nbytes > size ) {
pr_warn("downcall opc %d, uniq %d, too much!",
hdr.opcode, hdr.unique);
nbytes = size;
}
CODA_ALLOC(dcbuf, union outputArgs *, nbytes);
if (copy_from_user(dcbuf, buf, nbytes)) {
CODA_FREE(dcbuf, nbytes);
retval = -EFAULT;
goto out;
}
/* what downcall errors does Venus handle ? */
error = coda_downcall(vcp, hdr.opcode, dcbuf);
CODA_FREE(dcbuf, nbytes);
if (error) {
pr_warn("%s: coda_downcall error: %d\n",
__func__, error);
retval = error;
goto out;
}
count = nbytes;
goto out;
}
/* Look for the message on the processing queue. */
mutex_lock(&vcp->vc_mutex);
list_for_each(lh, &vcp->vc_processing) {
tmp = list_entry(lh, struct upc_req , uc_chain);
if (tmp->uc_unique == hdr.unique) {
req = tmp;
list_del(&req->uc_chain);
break;
}
}
mutex_unlock(&vcp->vc_mutex);
if (!req) {
pr_warn("%s: msg (%d, %d) not found\n",
__func__, hdr.opcode, hdr.unique);
retval = -ESRCH;
goto out;
}
/* move data into response buffer. */
if (req->uc_outSize < nbytes) {
pr_warn("%s: too much cnt: %d, cnt: %ld, opc: %d, uniq: %d.\n",
__func__, req->uc_outSize, (long)nbytes,
hdr.opcode, hdr.unique);
nbytes = req->uc_outSize; /* don't have more space! */
}
if (copy_from_user(req->uc_data, buf, nbytes)) {
req->uc_flags |= CODA_REQ_ABORT;
wake_up(&req->uc_sleep);
retval = -EFAULT;
goto out;
}
/* adjust outsize. is this useful ?? */
req->uc_outSize = nbytes;
req->uc_flags |= CODA_REQ_WRITE;
count = nbytes;
/* Convert filedescriptor into a file handle */
if (req->uc_opcode == CODA_OPEN_BY_FD) {
struct coda_open_by_fd_out *outp =
(struct coda_open_by_fd_out *)req->uc_data;
if (!outp->oh.result)
outp->fh = fget(outp->fd);
}
wake_up(&req->uc_sleep);
out:
return(count ? count : retval);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 429 | 83.14% | 6 | 33.33% |
Linus Torvalds | 43 | 8.33% | 2 | 11.11% |
Yoshihisa Abe | 16 | 3.10% | 2 | 11.11% |
Fabian Frederick | 15 | 2.91% | 3 | 16.67% |
Jan Harkes | 11 | 2.13% | 3 | 16.67% |
Al Viro | 1 | 0.19% | 1 | 5.56% |
Jens Axboe | 1 | 0.19% | 1 | 5.56% |
Total | 516 | 100.00% | 18 | 100.00% |
/*
* Read a message from the kernel to Venus
*/
static ssize_t coda_psdev_read(struct file * file, char __user * buf,
size_t nbytes, loff_t *off)
{
DECLARE_WAITQUEUE(wait, current);
struct venus_comm *vcp = (struct venus_comm *) file->private_data;
struct upc_req *req;
ssize_t retval = 0, count = 0;
if (nbytes == 0)
return 0;
mutex_lock(&vcp->vc_mutex);
add_wait_queue(&vcp->vc_waitq, &wait);
set_current_state(TASK_INTERRUPTIBLE);
while (list_empty(&vcp->vc_pending)) {
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
}
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
mutex_unlock(&vcp->vc_mutex);
schedule();
mutex_lock(&vcp->vc_mutex);
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&vcp->vc_waitq, &wait);
if (retval)
goto out;
req = list_entry(vcp->vc_pending.next, struct upc_req,uc_chain);
list_del(&req->uc_chain);
/* Move the input args into userspace */
count = req->uc_inSize;
if (nbytes < req->uc_inSize) {
pr_warn("%s: Venus read %ld bytes of %d in message\n",
__func__, (long)nbytes, req->uc_inSize);
count = nbytes;
}
if (copy_to_user(buf, req->uc_data, count))
retval = -EFAULT;
/* If request was not a signal, enqueue and don't free */
if (!(req->uc_flags & CODA_REQ_ASYNC)) {
req->uc_flags |= CODA_REQ_READ;
list_add_tail(&(req->uc_chain), &vcp->vc_processing);
goto out;
}
CODA_FREE(req->uc_data, sizeof(struct coda_in_hdr));
kfree(req);
out:
mutex_unlock(&vcp->vc_mutex);
return (count ? count : retval);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 285 | 86.36% | 6 | 42.86% |
Yoshihisa Abe | 30 | 9.09% | 1 | 7.14% |
Linus Torvalds | 5 | 1.52% | 1 | 7.14% |
Fabian Frederick | 4 | 1.21% | 2 | 14.29% |
Jens Axboe | 2 | 0.61% | 1 | 7.14% |
Akinobu Mita | 2 | 0.61% | 1 | 7.14% |
Al Viro | 1 | 0.30% | 1 | 7.14% |
Jan Harkes | 1 | 0.30% | 1 | 7.14% |
Total | 330 | 100.00% | 14 | 100.00% |
static int coda_psdev_open(struct inode * inode, struct file * file)
{
struct venus_comm *vcp;
int idx, err;
if (task_active_pid_ns(current) != &init_pid_ns)
return -EINVAL;
if (current_user_ns() != &init_user_ns)
return -EINVAL;
idx = iminor(inode);
if (idx < 0 || idx >= MAX_CODADEVS)
return -ENODEV;
err = -EBUSY;
vcp = &coda_comms[idx];
mutex_lock(&vcp->vc_mutex);
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;
}
mutex_unlock(&vcp->vc_mutex);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 102 | 61.82% | 6 | 46.15% |
Eric W. Biedermann | 26 | 15.76% | 2 | 15.38% |
Jan Harkes | 19 | 11.52% | 1 | 7.69% |
Yoshihisa Abe | 15 | 9.09% | 1 | 7.69% |
Al Viro | 2 | 1.21% | 2 | 15.38% |
Linus Torvalds | 1 | 0.61% | 1 | 7.69% |
Total | 165 | 100.00% | 13 | 100.00% |
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;
if (!vcp || !vcp->vc_inuse ) {
pr_warn("%s: Not open.\n", __func__);
return -1;
}
mutex_lock(&vcp->vc_mutex);
/* 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 & CODA_REQ_ASYNC) {
CODA_FREE(req->uc_data, sizeof(struct coda_in_hdr));
kfree(req);
continue;
}
req->uc_flags |= CODA_REQ_ABORT;
wake_up(&req->uc_sleep);
}
list_for_each_entry_safe(req, tmp, &vcp->vc_processing, uc_chain) {
list_del(&req->uc_chain);
req->uc_flags |= CODA_REQ_ABORT;
wake_up(&req->uc_sleep);
}
file->private_data = NULL;
vcp->vc_inuse--;
mutex_unlock(&vcp->vc_mutex);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 121 | 63.68% | 7 | 46.67% |
Jan Harkes | 48 | 25.26% | 4 | 26.67% |
Yoshihisa Abe | 14 | 7.37% | 1 | 6.67% |
Fabian Frederick | 4 | 2.11% | 2 | 13.33% |
Jens Axboe | 3 | 1.58% | 1 | 6.67% |
Total | 190 | 100.00% | 15 | 100.00% |
static const struct file_operations coda_psdev_fops = {
.owner = THIS_MODULE,
.read = coda_psdev_read,
.write = coda_psdev_write,
.poll = coda_psdev_poll,
.unlocked_ioctl = coda_psdev_ioctl,
.open = coda_psdev_open,
.release = coda_psdev_release,
.llseek = noop_llseek,
};
static int init_coda_psdev(void)
{
int i, err = 0;
if (register_chrdev(CODA_PSDEV_MAJOR, "coda", &coda_psdev_fops)) {
pr_err("%s: unable to get major %d\n",
__func__, CODA_PSDEV_MAJOR);
return -EIO;
}
coda_psdev_class = class_create(THIS_MODULE, "coda");
if (IS_ERR(coda_psdev_class)) {
err = PTR_ERR(coda_psdev_class);
goto out_chrdev;
}
for (i = 0; i < MAX_CODADEVS; i++) {
mutex_init(&(&coda_comms[i])->vc_mutex);
device_create(coda_psdev_class, NULL,
MKDEV(CODA_PSDEV_MAJOR, i), NULL, "cfs%d", i);
}
coda_sysctl_init();
goto out;
out_chrdev:
unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
out:
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hanna V. Linder | 60 | 43.17% | 1 | 7.14% |
Linus Torvalds (pre-git) | 33 | 23.74% | 3 | 21.43% |
Yoshihisa Abe | 16 | 11.51% | 1 | 7.14% |
Al Viro | 16 | 11.51% | 1 | 7.14% |
Greg Kroah-Hartman | 7 | 5.04% | 5 | 35.71% |
Fabian Frederick | 4 | 2.88% | 2 | 14.29% |
Jan Harkes | 3 | 2.16% | 1 | 7.14% |
Total | 139 | 100.00% | 14 | 100.00% |
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");
MODULE_VERSION("6.6");
static int __init init_coda(void)
{
int status;
int i;
status = coda_init_inodecache();
if (status)
goto out2;
status = init_coda_psdev();
if ( status ) {
pr_warn("Problem (%d) in init_coda_psdev\n", status);
goto out1;
}
status = register_filesystem(&coda_fs_type);
if (status) {
pr_warn("failed to register filesystem!\n");
goto out;
}
return 0;
out:
for (i = 0; i < MAX_CODADEVS; i++)
device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
class_destroy(coda_psdev_class);
unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
coda_sysctl_clean();
out1:
coda_destroy_inodecache();
out2:
return status;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 46 | 36.80% | 3 | 23.08% |
Linus Torvalds | 41 | 32.80% | 2 | 15.38% |
Al Viro | 16 | 12.80% | 1 | 7.69% |
Hanna V. Linder | 13 | 10.40% | 1 | 7.69% |
Greg Kroah-Hartman | 4 | 3.20% | 2 | 15.38% |
Fabian Frederick | 3 | 2.40% | 2 | 15.38% |
Jan Harkes | 1 | 0.80% | 1 | 7.69% |
Kay Sievers | 1 | 0.80% | 1 | 7.69% |
Total | 125 | 100.00% | 13 | 100.00% |
static void __exit exit_coda(void)
{
int err, i;
err = unregister_filesystem(&coda_fs_type);
if (err != 0)
pr_warn("failed to unregister filesystem\n");
for (i = 0; i < MAX_CODADEVS; i++)
device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
class_destroy(coda_psdev_class);
unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
coda_sysctl_clean();
coda_destroy_inodecache();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 37 | 48.68% | 3 | 25.00% |
Al Viro | 15 | 19.74% | 1 | 8.33% |
Hanna V. Linder | 13 | 17.11% | 1 | 8.33% |
Greg Kroah-Hartman | 4 | 5.26% | 2 | 16.67% |
Linus Torvalds | 3 | 3.95% | 1 | 8.33% |
Fabian Frederick | 2 | 2.63% | 2 | 16.67% |
Jan Harkes | 1 | 1.32% | 1 | 8.33% |
Kay Sievers | 1 | 1.32% | 1 | 8.33% |
Total | 76 | 100.00% | 12 | 100.00% |
module_init(init_coda);
module_exit(exit_coda);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Linus Torvalds (pre-git) | 1306 | 69.47% | 17 | 27.42% |
Yoshihisa Abe | 108 | 5.74% | 2 | 3.23% |
Linus Torvalds | 102 | 5.43% | 5 | 8.06% |
Jan Harkes | 100 | 5.32% | 8 | 12.90% |
Hanna V. Linder | 94 | 5.00% | 2 | 3.23% |
Al Viro | 54 | 2.87% | 5 | 8.06% |
Fabian Frederick | 33 | 1.76% | 4 | 6.45% |
Eric W. Biedermann | 29 | 1.54% | 2 | 3.23% |
Greg Kroah-Hartman | 16 | 0.85% | 5 | 8.06% |
Luca Tettamanti | 14 | 0.74% | 1 | 1.61% |
Arnd Bergmann | 7 | 0.37% | 2 | 3.23% |
Jens Axboe | 6 | 0.32% | 1 | 1.61% |
Alexey Dobriyan | 2 | 0.11% | 1 | 1.61% |
Kay Sievers | 2 | 0.11% | 1 | 1.61% |
Akinobu Mita | 2 | 0.11% | 1 | 1.61% |
Arjan van de Ven | 1 | 0.05% | 1 | 1.61% |
Ingo Molnar | 1 | 0.05% | 1 | 1.61% |
Alan Cox | 1 | 0.05% | 1 | 1.61% |
Dave Jones | 1 | 0.05% | 1 | 1.61% |
Adrian Bunk | 1 | 0.05% | 1 | 1.61% |
Total | 1880 | 100.00% | 62 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.