ia64/linux-2.6.18-xen.hg

annotate fs/nfsctl.c @ 524:7f8b544237bf

netfront: Allow netfront in domain 0.

This is useful if your physical network device is in a utility domain.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 15 15:18:58 2008 +0100 (2008-04-15)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * fs/nfsctl.c
ian@0 3 *
ian@0 4 * This should eventually move to userland.
ian@0 5 *
ian@0 6 */
ian@0 7 #include <linux/types.h>
ian@0 8 #include <linux/file.h>
ian@0 9 #include <linux/fs.h>
ian@0 10 #include <linux/sunrpc/svc.h>
ian@0 11 #include <linux/nfsd/nfsd.h>
ian@0 12 #include <linux/nfsd/syscall.h>
ian@0 13 #include <linux/linkage.h>
ian@0 14 #include <linux/namei.h>
ian@0 15 #include <linux/mount.h>
ian@0 16 #include <linux/syscalls.h>
ian@0 17 #include <asm/uaccess.h>
ian@0 18
ian@0 19 /*
ian@0 20 * open a file on nfsd fs
ian@0 21 */
ian@0 22
ian@0 23 static struct file *do_open(char *name, int flags)
ian@0 24 {
ian@0 25 struct nameidata nd;
ian@0 26 int error;
ian@0 27
ian@0 28 nd.mnt = do_kern_mount("nfsd", 0, "nfsd", NULL);
ian@0 29
ian@0 30 if (IS_ERR(nd.mnt))
ian@0 31 return (struct file *)nd.mnt;
ian@0 32
ian@0 33 nd.dentry = dget(nd.mnt->mnt_root);
ian@0 34 nd.last_type = LAST_ROOT;
ian@0 35 nd.flags = 0;
ian@0 36 nd.depth = 0;
ian@0 37
ian@0 38 error = path_walk(name, &nd);
ian@0 39 if (error)
ian@0 40 return ERR_PTR(error);
ian@0 41
ian@0 42 if (flags == O_RDWR)
ian@0 43 error = may_open(&nd,MAY_READ|MAY_WRITE,FMODE_READ|FMODE_WRITE);
ian@0 44 else
ian@0 45 error = may_open(&nd, MAY_WRITE, FMODE_WRITE);
ian@0 46
ian@0 47 if (!error)
ian@0 48 return dentry_open(nd.dentry, nd.mnt, flags);
ian@0 49
ian@0 50 path_release(&nd);
ian@0 51 return ERR_PTR(error);
ian@0 52 }
ian@0 53
ian@0 54 static struct {
ian@0 55 char *name; int wsize; int rsize;
ian@0 56 } map[] = {
ian@0 57 [NFSCTL_SVC] = {
ian@0 58 .name = ".svc",
ian@0 59 .wsize = sizeof(struct nfsctl_svc)
ian@0 60 },
ian@0 61 [NFSCTL_ADDCLIENT] = {
ian@0 62 .name = ".add",
ian@0 63 .wsize = sizeof(struct nfsctl_client)
ian@0 64 },
ian@0 65 [NFSCTL_DELCLIENT] = {
ian@0 66 .name = ".del",
ian@0 67 .wsize = sizeof(struct nfsctl_client)
ian@0 68 },
ian@0 69 [NFSCTL_EXPORT] = {
ian@0 70 .name = ".export",
ian@0 71 .wsize = sizeof(struct nfsctl_export)
ian@0 72 },
ian@0 73 [NFSCTL_UNEXPORT] = {
ian@0 74 .name = ".unexport",
ian@0 75 .wsize = sizeof(struct nfsctl_export)
ian@0 76 },
ian@0 77 [NFSCTL_GETFD] = {
ian@0 78 .name = ".getfd",
ian@0 79 .wsize = sizeof(struct nfsctl_fdparm),
ian@0 80 .rsize = NFS_FHSIZE
ian@0 81 },
ian@0 82 [NFSCTL_GETFS] = {
ian@0 83 .name = ".getfs",
ian@0 84 .wsize = sizeof(struct nfsctl_fsparm),
ian@0 85 .rsize = sizeof(struct knfsd_fh)
ian@0 86 },
ian@0 87 };
ian@0 88
ian@0 89 long
ian@0 90 asmlinkage sys_nfsservctl(int cmd, struct nfsctl_arg __user *arg, void __user *res)
ian@0 91 {
ian@0 92 struct file *file;
ian@0 93 void __user *p = &arg->u;
ian@0 94 int version;
ian@0 95 int err;
ian@0 96
ian@0 97 if (copy_from_user(&version, &arg->ca_version, sizeof(int)))
ian@0 98 return -EFAULT;
ian@0 99
ian@0 100 if (version != NFSCTL_VERSION)
ian@0 101 return -EINVAL;
ian@0 102
ian@0 103 if (cmd < 0 || cmd >= ARRAY_SIZE(map) || !map[cmd].name)
ian@0 104 return -EINVAL;
ian@0 105
ian@0 106 file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);
ian@0 107 if (IS_ERR(file))
ian@0 108 return PTR_ERR(file);
ian@0 109 err = file->f_op->write(file, p, map[cmd].wsize, &file->f_pos);
ian@0 110 if (err >= 0 && map[cmd].rsize)
ian@0 111 err = file->f_op->read(file, res, map[cmd].rsize, &file->f_pos);
ian@0 112 if (err >= 0)
ian@0 113 err = 0;
ian@0 114 fput(file);
ian@0 115 return err;
ian@0 116 }