2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* fs/nfsctl.c
|
|
|
|
*
|
|
|
|
* This should eventually move to userland.
|
|
|
|
*
|
|
|
|
*/
|
2006-01-19 09:44:07 +08:00
|
|
|
#include <linux/types.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/nfsd/syscall.h>
|
2008-11-20 03:46:46 +08:00
|
|
|
#include <linux/cred.h>
|
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/syscalls.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open a file on nfsd fs
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct file *do_open(char *name, int flags)
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
2007-07-19 16:48:21 +08:00
|
|
|
struct vfsmount *mnt;
|
2005-04-17 06:20:36 +08:00
|
|
|
int error;
|
|
|
|
|
2007-07-19 16:48:21 +08:00
|
|
|
mnt = do_kern_mount("nfsd", 0, "nfsd", NULL);
|
|
|
|
if (IS_ERR(mnt))
|
|
|
|
return (struct file *)mnt;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-19 16:48:21 +08:00
|
|
|
error = vfs_path_lookup(mnt->mnt_root, mnt, name, 0, &nd);
|
|
|
|
mntput(mnt); /* drop do_kern_mount reference */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (error)
|
|
|
|
return ERR_PTR(error);
|
|
|
|
|
|
|
|
if (flags == O_RDWR)
|
2008-10-24 15:58:10 +08:00
|
|
|
error = may_open(&nd.path, MAY_READ|MAY_WRITE,
|
|
|
|
FMODE_READ|FMODE_WRITE);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-10-24 15:58:10 +08:00
|
|
|
error = may_open(&nd.path, MAY_WRITE, FMODE_WRITE);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!error)
|
2008-11-14 07:39:22 +08:00
|
|
|
return dentry_open(nd.path.dentry, nd.path.mnt, flags,
|
|
|
|
current_cred());
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-15 11:34:35 +08:00
|
|
|
path_put(&nd.path);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ERR_PTR(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
char *name; int wsize; int rsize;
|
|
|
|
} map[] = {
|
|
|
|
[NFSCTL_SVC] = {
|
|
|
|
.name = ".svc",
|
|
|
|
.wsize = sizeof(struct nfsctl_svc)
|
|
|
|
},
|
|
|
|
[NFSCTL_ADDCLIENT] = {
|
|
|
|
.name = ".add",
|
|
|
|
.wsize = sizeof(struct nfsctl_client)
|
|
|
|
},
|
|
|
|
[NFSCTL_DELCLIENT] = {
|
|
|
|
.name = ".del",
|
|
|
|
.wsize = sizeof(struct nfsctl_client)
|
|
|
|
},
|
|
|
|
[NFSCTL_EXPORT] = {
|
|
|
|
.name = ".export",
|
|
|
|
.wsize = sizeof(struct nfsctl_export)
|
|
|
|
},
|
|
|
|
[NFSCTL_UNEXPORT] = {
|
|
|
|
.name = ".unexport",
|
|
|
|
.wsize = sizeof(struct nfsctl_export)
|
|
|
|
},
|
|
|
|
[NFSCTL_GETFD] = {
|
|
|
|
.name = ".getfd",
|
|
|
|
.wsize = sizeof(struct nfsctl_fdparm),
|
|
|
|
.rsize = NFS_FHSIZE
|
|
|
|
},
|
|
|
|
[NFSCTL_GETFS] = {
|
|
|
|
.name = ".getfs",
|
|
|
|
.wsize = sizeof(struct nfsctl_fsparm),
|
|
|
|
.rsize = sizeof(struct knfsd_fh)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2009-01-14 21:14:29 +08:00
|
|
|
SYSCALL_DEFINE3(nfsservctl, int, cmd, struct nfsctl_arg __user *, arg,
|
|
|
|
void __user *, res)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct file *file;
|
|
|
|
void __user *p = &arg->u;
|
|
|
|
int version;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (copy_from_user(&version, &arg->ca_version, sizeof(int)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2006-03-17 15:04:02 +08:00
|
|
|
if (version != NFSCTL_VERSION)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2006-03-24 19:15:34 +08:00
|
|
|
if (cmd < 0 || cmd >= ARRAY_SIZE(map) || !map[cmd].name)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);
|
|
|
|
if (IS_ERR(file))
|
|
|
|
return PTR_ERR(file);
|
|
|
|
err = file->f_op->write(file, p, map[cmd].wsize, &file->f_pos);
|
|
|
|
if (err >= 0 && map[cmd].rsize)
|
|
|
|
err = file->f_op->read(file, res, map[cmd].rsize, &file->f_pos);
|
|
|
|
if (err >= 0)
|
|
|
|
err = 0;
|
|
|
|
fput(file);
|
|
|
|
return err;
|
|
|
|
}
|