Commit bd238fb4 authored by Latchesar Ionkov's avatar Latchesar Ionkov Committed by Eric Van Hensbergen

9p: Reorganization of 9p file system code

This patchset moves non-filesystem interfaces of v9fs from fs/9p to net/9p.
It moves the transport, packet marshalling and connection layers to net/9p
leaving only the VFS related files in fs/9p.  This work is being done in
preparation for in-kernel 9p servers as well as alternate 9p clients (other
than VFS).
Signed-off-by: default avatarLatchesar Ionkov <lucho@ionkov.net>
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent 8d9107e8
/*
* linux/fs/9p/9p.h
*
* 9P protocol definitions.
*
* Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
/* Message Types */
enum {
TVERSION = 100,
RVERSION,
TAUTH = 102,
RAUTH,
TATTACH = 104,
RATTACH,
TERROR = 106,
RERROR,
TFLUSH = 108,
RFLUSH,
TWALK = 110,
RWALK,
TOPEN = 112,
ROPEN,
TCREATE = 114,
RCREATE,
TREAD = 116,
RREAD,
TWRITE = 118,
RWRITE,
TCLUNK = 120,
RCLUNK,
TREMOVE = 122,
RREMOVE,
TSTAT = 124,
RSTAT,
TWSTAT = 126,
RWSTAT,
};
/* modes */
enum {
V9FS_OREAD = 0x00,
V9FS_OWRITE = 0x01,
V9FS_ORDWR = 0x02,
V9FS_OEXEC = 0x03,
V9FS_OEXCL = 0x04,
V9FS_OTRUNC = 0x10,
V9FS_OREXEC = 0x20,
V9FS_ORCLOSE = 0x40,
V9FS_OAPPEND = 0x80,
};
/* permissions */
enum {
V9FS_DMDIR = 0x80000000,
V9FS_DMAPPEND = 0x40000000,
V9FS_DMEXCL = 0x20000000,
V9FS_DMMOUNT = 0x10000000,
V9FS_DMAUTH = 0x08000000,
V9FS_DMTMP = 0x04000000,
V9FS_DMSYMLINK = 0x02000000,
V9FS_DMLINK = 0x01000000,
/* 9P2000.u extensions */
V9FS_DMDEVICE = 0x00800000,
V9FS_DMNAMEDPIPE = 0x00200000,
V9FS_DMSOCKET = 0x00100000,
V9FS_DMSETUID = 0x00080000,
V9FS_DMSETGID = 0x00040000,
};
/* qid.types */
enum {
V9FS_QTDIR = 0x80,
V9FS_QTAPPEND = 0x40,
V9FS_QTEXCL = 0x20,
V9FS_QTMOUNT = 0x10,
V9FS_QTAUTH = 0x08,
V9FS_QTTMP = 0x04,
V9FS_QTSYMLINK = 0x02,
V9FS_QTLINK = 0x01,
V9FS_QTFILE = 0x00,
};
#define V9FS_NOTAG (u16)(~0)
#define V9FS_NOFID (u32)(~0)
#define V9FS_MAXWELEM 16
/* ample room for Twrite/Rread header (iounit) */
#define V9FS_IOHDRSZ 24
struct v9fs_str {
u16 len;
char *str;
};
/* qids are the unique ID for a file (like an inode */
struct v9fs_qid {
u8 type;
u32 version;
u64 path;
};
/* Plan 9 file metadata (stat) structure */
struct v9fs_stat {
u16 size;
u16 type;
u32 dev;
struct v9fs_qid qid;
u32 mode;
u32 atime;
u32 mtime;
u64 length;
struct v9fs_str name;
struct v9fs_str uid;
struct v9fs_str gid;
struct v9fs_str muid;
struct v9fs_str extension; /* 9p2000.u extensions */
u32 n_uid; /* 9p2000.u extensions */
u32 n_gid; /* 9p2000.u extensions */
u32 n_muid; /* 9p2000.u extensions */
};
/* file metadata (stat) structure used to create Twstat message
The is similar to v9fs_stat, but the strings don't point to
the same memory block and should be freed separately
*/
struct v9fs_wstat {
u16 size;
u16 type;
u32 dev;
struct v9fs_qid qid;
u32 mode;
u32 atime;
u32 mtime;
u64 length;
char *name;
char *uid;
char *gid;
char *muid;
char *extension; /* 9p2000.u extensions */
u32 n_uid; /* 9p2000.u extensions */
u32 n_gid; /* 9p2000.u extensions */
u32 n_muid; /* 9p2000.u extensions */
};
/* Structures for Protocol Operations */
struct Tversion {
u32 msize;
struct v9fs_str version;
};
struct Rversion {
u32 msize;
struct v9fs_str version;
};
struct Tauth {
u32 afid;
struct v9fs_str uname;
struct v9fs_str aname;
};
struct Rauth {
struct v9fs_qid qid;
};
struct Rerror {
struct v9fs_str error;
u32 errno; /* 9p2000.u extension */
};
struct Tflush {
u16 oldtag;
};
struct Rflush {
};
struct Tattach {
u32 fid;
u32 afid;
struct v9fs_str uname;
struct v9fs_str aname;
};
struct Rattach {
struct v9fs_qid qid;
};
struct Twalk {
u32 fid;
u32 newfid;
u16 nwname;
struct v9fs_str wnames[16];
};
struct Rwalk {
u16 nwqid;
struct v9fs_qid wqids[16];
};
struct Topen {
u32 fid;
u8 mode;
};
struct Ropen {
struct v9fs_qid qid;
u32 iounit;
};
struct Tcreate {
u32 fid;
struct v9fs_str name;
u32 perm;
u8 mode;
struct v9fs_str extension;
};
struct Rcreate {
struct v9fs_qid qid;
u32 iounit;
};
struct Tread {
u32 fid;
u64 offset;
u32 count;
};
struct Rread {
u32 count;
u8 *data;
};
struct Twrite {
u32 fid;
u64 offset;
u32 count;
u8 *data;
};
struct Rwrite {
u32 count;
};
struct Tclunk {
u32 fid;
};
struct Rclunk {
};
struct Tremove {
u32 fid;
};
struct Rremove {
};
struct Tstat {
u32 fid;
};
struct Rstat {
struct v9fs_stat stat;
};
struct Twstat {
u32 fid;
struct v9fs_stat stat;
};
struct Rwstat {
};
/*
* fcall is the primary packet structure
*
*/
struct v9fs_fcall {
u32 size;
u8 id;
u16 tag;
void *sdata;
union {
struct Tversion tversion;
struct Rversion rversion;
struct Tauth tauth;
struct Rauth rauth;
struct Rerror rerror;
struct Tflush tflush;
struct Rflush rflush;
struct Tattach tattach;
struct Rattach rattach;
struct Twalk twalk;
struct Rwalk rwalk;
struct Topen topen;
struct Ropen ropen;
struct Tcreate tcreate;
struct Rcreate rcreate;
struct Tread tread;
struct Rread rread;
struct Twrite twrite;
struct Rwrite rwrite;
struct Tclunk tclunk;
struct Rclunk rclunk;
struct Tremove tremove;
struct Rremove rremove;
struct Tstat tstat;
struct Rstat rstat;
struct Twstat twstat;
struct Rwstat rwstat;
} params;
};
#define PRINT_FCALL_ERROR(s, fcall) dprintk(DEBUG_ERROR, "%s: %.*s\n", s, \
fcall?fcall->params.rerror.error.len:0, \
fcall?fcall->params.rerror.error.str:"");
int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
char *version, struct v9fs_fcall **rcall);
int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
u32 fid, u32 afid, struct v9fs_fcall **rcall);
int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid);
int v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid,
struct v9fs_fcall **rcall);
int v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
struct v9fs_wstat *wstat, struct v9fs_fcall **rcall);
int v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
char *name, struct v9fs_fcall **rcall);
int v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
struct v9fs_fcall **rcall);
int v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
struct v9fs_fcall **rcall);
int v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
u32 perm, u8 mode, char *extension, struct v9fs_fcall **rcall);
int v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid,
u64 offset, u32 count, struct v9fs_fcall **rcall);
int v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
u32 count, const char __user * data,
struct v9fs_fcall **rcall);
int v9fs_printfcall(char *, int, struct v9fs_fcall *, int);
obj-$(CONFIG_9P_FS) := 9p.o obj-$(CONFIG_9P_FS) := 9p.o
9p-objs := \ 9p-objs := \
trans_fd.o \
mux.o \
fcall.o \
conv.o \
vfs_super.o \ vfs_super.o \
vfs_inode.o \ vfs_inode.o \
vfs_addr.o \ vfs_addr.o \
vfs_file.o \ vfs_file.o \
vfs_dir.o \ vfs_dir.o \
vfs_dentry.o \ vfs_dentry.o \
error.o \
v9fs.o \ v9fs.o \
fid.o \ fid.o \
fcprint.o
/*
* linux/fs/9p/debug.h - V9FS Debug Definitions
*
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
#define DEBUG_ERROR (1<<0)
#define DEBUG_CURRENT (1<<1)
#define DEBUG_9P (1<<2)
#define DEBUG_VFS (1<<3)
#define DEBUG_CONV (1<<4)
#define DEBUG_MUX (1<<5)
#define DEBUG_TRANS (1<<6)
#define DEBUG_SLABS (1<<7)
#define DEBUG_FCALL (1<<8)
#define DEBUG_DUMP_PKT 0
extern int v9fs_debug_level;
#define dprintk(level, format, arg...) \
do { \
if((v9fs_debug_level & level)==level) \
printk(KERN_NOTICE "-- %s (%d): " \
format , __FUNCTION__, current->pid , ## arg); \
} while(0)
#define eprintk(level, format, arg...) \
do { \
printk(level "v9fs: %s (%d): " \
format , __FUNCTION__, current->pid , ## arg); \
} while(0)
#if DEBUG_DUMP_PKT
static inline void dump_data(const unsigned char *data, unsigned int datalen)
{
int i, n;
char buf[5*8];
n = 0;
i = 0;
while (i < datalen) {
n += snprintf(buf+n, sizeof(buf)-n, "%02x", data[i++]);
if (i%4 == 0)
n += snprintf(buf+n, sizeof(buf)-n, " ");
if (i%16 == 0) {
dprintk(DEBUG_ERROR, "%s\n", buf);
n = 0;
}
}
dprintk(DEBUG_ERROR, "%s\n", buf);
}
#else /* DEBUG_DUMP_PKT */
static inline void dump_data(const unsigned char *data, unsigned int datalen)
{
}
#endif /* DEBUG_DUMP_PKT */
/*
* linux/fs/9p/fcall.c
*
* This file contains functions to perform synchronous 9P calls
*
* Copyright (C) 2004 by Latchesar Ionkov <lucho@ionkov.net>
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/idr.h>
#include "debug.h"
#include "v9fs.h"
#include "9p.h"
#include "conv.h"
#include "mux.h"
/**
* v9fs_t_version - negotiate protocol parameters with sever
* @v9ses: 9P2000 session information
* @msize: requested max size packet
* @version: requested version.extension string
* @fcall: pointer to response fcall pointer
*
*/
int
v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
char *version, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc;
dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version);
tc = v9fs_create_tversion(msize, version);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_attach - mount the server
* @v9ses: 9P2000 session information
* @uname: user name doing the attach
* @aname: remote name being attached to
* @fid: mount fid to attatch to root node
* @afid: authentication fid (in this case result key)
* @fcall: pointer to response fcall pointer
*
*/
int
v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
u32 fid, u32 afid, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall* tc;
dprintk(DEBUG_9P, "uname '%s' aname '%s' fid %d afid %d\n", uname,
aname, fid, afid);
tc = v9fs_create_tattach(fid, afid, uname, aname);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc,
struct v9fs_fcall *rc, int err)
{
int fid, id;
struct v9fs_session_info *v9ses;
id = 0;
fid = tc->params.tclunk.fid;
if (rc)
id = rc->id;
kfree(tc);
kfree(rc);
if (id == RCLUNK) {
v9ses = a;
v9fs_put_idpool(fid, &v9ses->fidpool);
}
}
/**
* v9fs_t_clunk - release a fid (finish a transaction)
* @v9ses: 9P2000 session information
* @fid: fid to release
* @fcall: pointer to response fcall pointer
*
*/
int
v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid)
{
int ret;
struct v9fs_fcall *tc, *rc;
dprintk(DEBUG_9P, "fid %d\n", fid);
rc = NULL;
tc = v9fs_create_tclunk(fid);
if (!IS_ERR(tc))
ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
else
ret = PTR_ERR(tc);
if (ret)
dprintk(DEBUG_ERROR, "failed fid %d err %d\n", fid, ret);
v9fs_t_clunk_cb(v9ses, tc, rc, ret);
return ret;
}
#if 0
/**
* v9fs_v9fs_t_flush - flush a pending transaction
* @v9ses: 9P2000 session information
* @tag: tag to release
*
*/
int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag)
{
int ret;
struct v9fs_fcall *tc;
dprintk(DEBUG_9P, "oldtag %d\n", oldtag);
tc = v9fs_create_tflush(oldtag);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, NULL);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
#endif
/**
* v9fs_t_stat - read a file's meta-data
* @v9ses: 9P2000 session information
* @fid: fid pointing to file or directory to get info about
* @fcall: pointer to response fcall
*
*/
int
v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc;
dprintk(DEBUG_9P, "fid %d\n", fid);
ret = -ENOMEM;
tc = v9fs_create_tstat(fid);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_wstat - write a file's meta-data
* @v9ses: 9P2000 session information
* @fid: fid pointing to file or directory to write info about
* @stat: metadata
* @fcall: pointer to response fcall
*
*/
int
v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
struct v9fs_wstat *wstat, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc;
dprintk(DEBUG_9P, "fid %d\n", fid);
tc = v9fs_create_twstat(fid, wstat, v9ses->extended);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_walk - walk a fid to a new file or directory
* @v9ses: 9P2000 session information
* @fid: fid to walk
* @newfid: new fid (for clone operations)
* @name: path to walk fid to
* @fcall: pointer to response fcall
*
*/
/* TODO: support multiple walk */
int
v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
char *name, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc;
int nwname;
dprintk(DEBUG_9P, "fid %d newfid %d wname '%s'\n", fid, newfid, name);
if (name)
nwname = 1;
else
nwname = 0;
tc = v9fs_create_twalk(fid, newfid, nwname, &name);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_open - open a file
*
* @v9ses - 9P2000 session information
* @fid - fid to open
* @mode - mode to open file (R, RW, etc)
* @fcall - pointer to response fcall
*
*/
int
v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc;
dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);
tc = v9fs_create_topen(fid, mode);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_remove - remove a file or directory
* @v9ses: 9P2000 session information
* @fid: fid to remove
* @fcall: pointer to response fcall
*
*/
int
v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc;
dprintk(DEBUG_9P, "fid %d\n", fid);
tc = v9fs_create_tremove(fid);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_create - create a file or directory
* @v9ses: 9P2000 session information
* @fid: fid to create
* @name: name of the file or directory to create
* @perm: permissions to create with
* @mode: mode to open file (R, RW, etc)
* @fcall: pointer to response fcall
*
*/
int
v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name, u32 perm,
u8 mode, char *extension, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc;
dprintk(DEBUG_9P, "fid %d name '%s' perm %x mode %d\n",
fid, name, perm, mode);
tc = v9fs_create_tcreate(fid, name, perm, mode, extension,
v9ses->extended);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, rcp);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_read - read data
* @v9ses: 9P2000 session information
* @fid: fid to read from
* @offset: offset to start read at
* @count: how many bytes to read
* @fcall: pointer to response fcall (with data)
*
*/
int
v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
u32 count, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc, *rc;
dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
(long long unsigned) offset, count);
tc = v9fs_create_tread(fid, offset, count);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
if (!ret)
ret = rc->params.rread.count;
if (rcp)
*rcp = rc;
else
kfree(rc);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
/**
* v9fs_t_write - write data
* @v9ses: 9P2000 session information
* @fid: fid to write to
* @offset: offset to start write at
* @count: how many bytes to write
* @fcall: pointer to response fcall
*
*/
int
v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid, u64 offset, u32 count,
const char __user *data, struct v9fs_fcall **rcp)
{
int ret;
struct v9fs_fcall *tc, *rc;
dprintk(DEBUG_9P, "fid %d offset 0x%llux count 0x%x\n", fid,
(long long unsigned) offset, count);
tc = v9fs_create_twrite(fid, offset, count, data);
if (!IS_ERR(tc)) {
ret = v9fs_mux_rpc(v9ses->mux, tc, &rc);
if (!ret)
ret = rc->params.rwrite.count;
if (rcp)
*rcp = rc;
else
kfree(rc);
kfree(tc);
} else
ret = PTR_ERR(tc);
return ret;
}
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <asm/semaphore.h> #include <asm/semaphore.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
#include "debug.h"
#include "v9fs.h" #include "v9fs.h"
#include "9p.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "fid.h" #include "fid.h"
...@@ -40,67 +40,29 @@ ...@@ -40,67 +40,29 @@
* *
*/ */
int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry) int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
{ {
struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; struct v9fs_dentry *dent;
dprintk(DEBUG_9P, "fid %d (%p) dentry %s (%p)\n", fid->fid, fid,
dentry->d_iname, dentry);
if (dentry->d_fsdata == NULL) {
dentry->d_fsdata =
kmalloc(sizeof(struct list_head), GFP_KERNEL);
if (dentry->d_fsdata == NULL) {
dprintk(DEBUG_ERROR, "Out of memory\n");
return -ENOMEM;
}
fid_list = (struct list_head *)dentry->d_fsdata;
INIT_LIST_HEAD(fid_list); /* Initialize list head */
}
fid->uid = current->uid; P9_DPRINTK(P9_DEBUG_VFS, "fid %d dentry %s\n",
list_add(&fid->list, fid_list); fid->fid, dentry->d_iname);
return 0;
}
/** dent = dentry->d_fsdata;
* v9fs_fid_create - allocate a FID structure if (!dent) {
* @dentry - dentry to link newly created fid to dent = kmalloc(sizeof(struct v9fs_dentry), GFP_KERNEL);
* if (!dent)
*/ return -ENOMEM;
struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *v9ses, int fid)
{
struct v9fs_fid *new;
dprintk(DEBUG_9P, "fid create fid %d\n", fid); spin_lock_init(&dent->lock);
new = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL); INIT_LIST_HEAD(&dent->fidlist);
if (new == NULL) { dentry->d_fsdata = dent;
dprintk(DEBUG_ERROR, "Out of Memory\n");
return ERR_PTR(-ENOMEM);
} }
new->fid = fid; spin_lock(&dent->lock);
new->v9ses = v9ses; list_add(&fid->dlist, &dent->fidlist);
new->fidopen = 0; spin_unlock(&dent->lock);
new->fidclunked = 0;
new->iounit = 0;
new->rdir_pos = 0;
new->rdir_fcall = NULL;
init_MUTEX(&new->lock);
INIT_LIST_HEAD(&new->list);
return new;
}
/**
* v9fs_fid_destroy - deallocate a FID structure
* @fid: fid to destroy
*
*/
void v9fs_fid_destroy(struct v9fs_fid *fid) return 0;
{
list_del(&fid->list);
kfree(fid);
} }
/** /**
...@@ -114,30 +76,42 @@ void v9fs_fid_destroy(struct v9fs_fid *fid) ...@@ -114,30 +76,42 @@ void v9fs_fid_destroy(struct v9fs_fid *fid)
* *
*/ */
struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry) struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
{ {
struct list_head *fid_list = (struct list_head *)dentry->d_fsdata; struct v9fs_dentry *dent;
struct v9fs_fid *return_fid = NULL; struct p9_fid *fid;
dprintk(DEBUG_9P, " dentry: %s (%p)\n", dentry->d_iname, dentry); P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
dent = dentry->d_fsdata;
if (fid_list) if (dent)
return_fid = list_entry(fid_list->next, struct v9fs_fid, list); fid = list_entry(dent->fidlist.next, struct p9_fid, dlist);
else
fid = ERR_PTR(-EBADF);
P9_DPRINTK(P9_DEBUG_VFS, " fid: %p\n", fid);
return fid;
}
if (!return_fid) { struct p9_fid *v9fs_fid_lookup_remove(struct dentry *dentry)
dprintk(DEBUG_ERROR, "Couldn't find a fid in dentry\n"); {
return_fid = ERR_PTR(-EBADF); struct p9_fid *fid;
struct v9fs_dentry *dent;
dent = dentry->d_fsdata;
fid = v9fs_fid_lookup(dentry);
if (!IS_ERR(fid)) {
spin_lock(&dent->lock);
list_del(&fid->dlist);
spin_unlock(&dent->lock);
} }
if(down_interruptible(&return_fid->lock)) return fid;
return ERR_PTR(-EINTR);
return return_fid;
} }
/** /**
* v9fs_fid_clone - lookup the fid for a dentry, clone a private copy and * v9fs_fid_clone - lookup the fid for a dentry, clone a private copy and
* release it * release it
* @dentry: dentry to look for fid in * @dentry: dentry to look for fid in
* *
* find a fid in the dentry and then clone to a new private fid * find a fid in the dentry and then clone to a new private fid
...@@ -146,49 +120,15 @@ struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry) ...@@ -146,49 +120,15 @@ struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry)
* *
*/ */
struct v9fs_fid *v9fs_fid_clone(struct dentry *dentry) struct p9_fid *v9fs_fid_clone(struct dentry *dentry)
{ {
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); struct p9_fid *ofid, *fid;
struct v9fs_fid *base_fid, *new_fid = ERR_PTR(-EBADF);
struct v9fs_fcall *fcall = NULL;
int fid, err;
base_fid = v9fs_fid_lookup(dentry);
if(IS_ERR(base_fid))
return base_fid;
if(base_fid) { /* clone fid */
fid = v9fs_get_idpool(&v9ses->fidpool);
if (fid < 0) {
eprintk(KERN_WARNING, "newfid fails!\n");
new_fid = ERR_PTR(-ENOSPC);
goto Release_Fid;
}
err = v9fs_t_walk(v9ses, base_fid->fid, fid, NULL, &fcall);
if (err < 0) {
dprintk(DEBUG_ERROR, "clone walk didn't work\n");
v9fs_put_idpool(fid, &v9ses->fidpool);
new_fid = ERR_PTR(err);
goto Free_Fcall;
}
new_fid = v9fs_fid_create(v9ses, fid);
if (new_fid == NULL) {
dprintk(DEBUG_ERROR, "out of memory\n");
new_fid = ERR_PTR(-ENOMEM);
}
Free_Fcall:
kfree(fcall);
}
Release_Fid: P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
up(&base_fid->lock); ofid = v9fs_fid_lookup(dentry);
return new_fid; if (IS_ERR(ofid))
} return ofid;
void v9fs_fid_clunk(struct v9fs_session_info *v9ses, struct v9fs_fid *fid) fid = p9_client_walk(ofid, 0, NULL, 1);
{ return fid;
v9fs_t_clunk(v9ses, fid->fid);
v9fs_fid_destroy(fid);
} }
...@@ -22,41 +22,12 @@ ...@@ -22,41 +22,12 @@
#include <linux/list.h> #include <linux/list.h>
#define FID_OP 0 struct v9fs_dentry {
#define FID_WALK 1 spinlock_t lock; /* protect fidlist */
#define FID_CREATE 2 struct list_head fidlist;
struct v9fs_fid {
struct list_head list; /* list of fids associated with a dentry */
struct list_head active; /* XXX - debug */
struct semaphore lock;
u32 fid;
unsigned char fidopen; /* set when fid is opened */
unsigned char fidclunked; /* set when fid has already been clunked */
struct v9fs_qid qid;
u32 iounit;
/* readdir stuff */
int rdir_fpos;
loff_t rdir_pos;
struct v9fs_fcall *rdir_fcall;
/* management stuff */
uid_t uid; /* user associated with this fid */
/* private data */
struct file *filp; /* backpointer to File struct for open files */
struct v9fs_session_info *v9ses; /* session info for this FID */
}; };
struct v9fs_fid *v9fs_fid_lookup(struct dentry *dentry); struct p9_fid *v9fs_fid_lookup(struct dentry *dentry);
struct v9fs_fid *v9fs_fid_get_created(struct dentry *); struct p9_fid *v9fs_fid_lookup_remove(struct dentry *dentry);
void v9fs_fid_destroy(struct v9fs_fid *fid); struct p9_fid *v9fs_fid_clone(struct dentry *dentry);
struct v9fs_fid *v9fs_fid_create(struct v9fs_session_info *, int fid); int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid);
int v9fs_fid_insert(struct v9fs_fid *fid, struct dentry *dentry);
struct v9fs_fid *v9fs_fid_clone(struct dentry *dentry);
void v9fs_fid_clunk(struct v9fs_session_info *v9ses, struct v9fs_fid *fid);
This diff is collapsed.
...@@ -21,16 +21,6 @@ ...@@ -21,16 +21,6 @@
* *
*/ */
/*
* Idpool structure provides lock and id management
*
*/
struct v9fs_idpool {
struct semaphore lock;
struct idr pool;
};
/* /*
* Session structure provides information for an opened session * Session structure provides information for an opened session
* *
...@@ -54,15 +44,7 @@ struct v9fs_session_info { ...@@ -54,15 +44,7 @@ struct v9fs_session_info {
unsigned int uid; /* default uid/muid for legacy support */ unsigned int uid; /* default uid/muid for legacy support */
unsigned int gid; /* default gid for legacy support */ unsigned int gid; /* default gid for legacy support */
/* book keeping */ struct p9_client *clnt; /* 9p client */
struct v9fs_idpool fidpool; /* The FID pool for file descriptors */
struct v9fs_transport *transport;
struct v9fs_mux_data *mux;
int inprogress; /* session in progress => true */
int shutdown; /* session shutting down. no more attaches. */
unsigned char session_hung;
struct dentry *debugfs_dir; struct dentry *debugfs_dir;
}; };
...@@ -71,6 +53,7 @@ enum { ...@@ -71,6 +53,7 @@ enum {
PROTO_TCP, PROTO_TCP,
PROTO_UNIX, PROTO_UNIX,
PROTO_FD, PROTO_FD,
PROTO_PCI,
}; };
/* possible values of ->cache */ /* possible values of ->cache */
...@@ -82,12 +65,9 @@ enum { ...@@ -82,12 +65,9 @@ enum {
extern struct dentry *v9fs_debugfs_root; extern struct dentry *v9fs_debugfs_root;
int v9fs_session_init(struct v9fs_session_info *, const char *, char *); struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,
struct v9fs_session_info *v9fs_inode2v9ses(struct inode *); char *);
void v9fs_session_close(struct v9fs_session_info *v9ses); void v9fs_session_close(struct v9fs_session_info *v9ses);
int v9fs_get_idpool(struct v9fs_idpool *p);
void v9fs_put_idpool(int id, struct v9fs_idpool *p);
int v9fs_check_idpool(int id, struct v9fs_idpool *p);
void v9fs_session_cancel(struct v9fs_session_info *v9ses); void v9fs_session_cancel(struct v9fs_session_info *v9ses);
#define V9FS_MAGIC 0x01021997 #define V9FS_MAGIC 0x01021997
...@@ -97,3 +77,7 @@ void v9fs_session_cancel(struct v9fs_session_info *v9ses); ...@@ -97,3 +77,7 @@ void v9fs_session_cancel(struct v9fs_session_info *v9ses);
#define V9FS_DEFUSER "nobody" #define V9FS_DEFUSER "nobody"
#define V9FS_DEFANAME "" #define V9FS_DEFANAME ""
static inline struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
{
return (inode->i_sb->s_fs_info);
}
...@@ -45,10 +45,10 @@ extern struct dentry_operations v9fs_dentry_operations; ...@@ -45,10 +45,10 @@ extern struct dentry_operations v9fs_dentry_operations;
extern struct dentry_operations v9fs_cached_dentry_operations; extern struct dentry_operations v9fs_cached_dentry_operations;
struct inode *v9fs_get_inode(struct super_block *sb, int mode); struct inode *v9fs_get_inode(struct super_block *sb, int mode);
ino_t v9fs_qid2ino(struct v9fs_qid *qid); ino_t v9fs_qid2ino(struct p9_qid *qid);
void v9fs_stat2inode(struct v9fs_stat *, struct inode *, struct super_block *); void v9fs_stat2inode(struct p9_stat *, struct inode *, struct super_block *);
int v9fs_dir_release(struct inode *inode, struct file *filp); int v9fs_dir_release(struct inode *inode, struct file *filp);
int v9fs_file_open(struct inode *inode, struct file *file); int v9fs_file_open(struct inode *inode, struct file *file);
void v9fs_inode2stat(struct inode *inode, struct v9fs_stat *stat); void v9fs_inode2stat(struct inode *inode, struct p9_stat *stat);
void v9fs_dentry_release(struct dentry *); void v9fs_dentry_release(struct dentry *);
int v9fs_uflags2omode(int uflags); int v9fs_uflags2omode(int uflags);
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
#include "debug.h"
#include "v9fs.h" #include "v9fs.h"
#include "9p.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "fid.h" #include "fid.h"
...@@ -50,55 +50,26 @@ ...@@ -50,55 +50,26 @@
static int v9fs_vfs_readpage(struct file *filp, struct page *page) static int v9fs_vfs_readpage(struct file *filp, struct page *page)
{ {
char *buffer = NULL; int retval;
int retval = -EIO; loff_t offset;
loff_t offset = page_offset(page); char *buffer;
int count = PAGE_CACHE_SIZE; struct p9_fid *fid;
struct inode *inode = filp->f_path.dentry->d_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
int rsize = v9ses->maxdata - V9FS_IOHDRSZ;
struct v9fs_fid *v9f = filp->private_data;
struct v9fs_fcall *fcall = NULL;
int fid = v9f->fid;
int total = 0;
int result = 0;
dprintk(DEBUG_VFS, "\n");
P9_DPRINTK(P9_DEBUG_VFS, "\n");
fid = filp->private_data;
buffer = kmap(page); buffer = kmap(page);
do { offset = page_offset(page);
if (count < rsize)
rsize = count;
result = v9fs_t_read(v9ses, fid, offset, rsize, &fcall);
if (result < 0) {
printk(KERN_ERR "v9fs_t_read returned %d\n",
result);
kfree(fcall);
goto UnmapAndUnlock;
} else
offset += result;
memcpy(buffer, fcall->params.rread.data, result);
count -= result;
buffer += result;
total += result;
kfree(fcall);
if (result < rsize) retval = p9_client_readn(fid, buffer, offset, PAGE_CACHE_SIZE);
break; if (retval < 0)
} while (count); goto done;
memset(buffer, 0, count); memset(buffer + retval, 0, PAGE_CACHE_SIZE - retval);
flush_dcache_page(page); flush_dcache_page(page);
SetPageUptodate(page); SetPageUptodate(page);
retval = 0; retval = 0;
UnmapAndUnlock: done:
kunmap(page); kunmap(page);
unlock_page(page); unlock_page(page);
return retval; return retval;
......
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
#include <linux/namei.h> #include <linux/namei.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
#include "debug.h"
#include "v9fs.h" #include "v9fs.h"
#include "9p.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "fid.h" #include "fid.h"
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
static int v9fs_dentry_delete(struct dentry *dentry) static int v9fs_dentry_delete(struct dentry *dentry)
{ {
dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
return 1; return 1;
} }
...@@ -69,7 +69,7 @@ static int v9fs_dentry_delete(struct dentry *dentry) ...@@ -69,7 +69,7 @@ static int v9fs_dentry_delete(struct dentry *dentry)
static int v9fs_cached_dentry_delete(struct dentry *dentry) static int v9fs_cached_dentry_delete(struct dentry *dentry)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
if(!inode) if(!inode)
return 1; return 1;
...@@ -85,26 +85,19 @@ static int v9fs_cached_dentry_delete(struct dentry *dentry) ...@@ -85,26 +85,19 @@ static int v9fs_cached_dentry_delete(struct dentry *dentry)
void v9fs_dentry_release(struct dentry *dentry) void v9fs_dentry_release(struct dentry *dentry)
{ {
int err; struct v9fs_dentry *dent;
struct p9_fid *temp, *current_fid;
dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
if (dentry->d_fsdata != NULL) { dent = dentry->d_fsdata;
struct list_head *fid_list = dentry->d_fsdata; if (dent) {
struct v9fs_fid *temp = NULL; list_for_each_entry_safe(current_fid, temp, &dent->fidlist,
struct v9fs_fid *current_fid = NULL; dlist) {
p9_client_clunk(current_fid);
list_for_each_entry_safe(current_fid, temp, fid_list, list) {
err = v9fs_t_clunk(current_fid->v9ses, current_fid->fid);
if (err < 0)
dprintk(DEBUG_ERROR, "clunk failed: %d name %s\n",
err, dentry->d_iname);
v9fs_fid_destroy(current_fid);
} }
kfree(dentry->d_fsdata); /* free the list_head */ kfree(dent);
dentry->d_fsdata = NULL;
} }
} }
......
...@@ -32,11 +32,10 @@ ...@@ -32,11 +32,10 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/inet.h> #include <linux/inet.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
#include "debug.h"
#include "v9fs.h" #include "v9fs.h"
#include "9p.h"
#include "conv.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "fid.h" #include "fid.h"
...@@ -46,14 +45,14 @@ ...@@ -46,14 +45,14 @@
* *
*/ */
static inline int dt_type(struct v9fs_stat *mistat) static inline int dt_type(struct p9_stat *mistat)
{ {
unsigned long perm = mistat->mode; unsigned long perm = mistat->mode;
int rettype = DT_REG; int rettype = DT_REG;
if (perm & V9FS_DMDIR) if (perm & P9_DMDIR)
rettype = DT_DIR; rettype = DT_DIR;
if (perm & V9FS_DMSYMLINK) if (perm & P9_DMSYMLINK)
rettype = DT_LNK; rettype = DT_LNK;
return rettype; return rettype;
...@@ -69,106 +68,36 @@ static inline int dt_type(struct v9fs_stat *mistat) ...@@ -69,106 +68,36 @@ static inline int dt_type(struct v9fs_stat *mistat)
static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
{ {
struct v9fs_fcall *fcall = NULL; int over;
struct inode *inode = filp->f_path.dentry->d_inode; struct p9_fid *fid;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct v9fs_session_info *v9ses;
struct v9fs_fid *file = filp->private_data; struct inode *inode;
unsigned int i, n, s; struct p9_stat *st;
int fid = -1;
int ret = 0; P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
struct v9fs_stat stat; inode = filp->f_path.dentry->d_inode;
int over = 0; v9ses = v9fs_inode2v9ses(inode);
fid = filp->private_data;
dprintk(DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); while ((st = p9_client_dirread(fid, filp->f_pos)) != NULL) {
if (IS_ERR(st))
fid = file->fid; return PTR_ERR(st);
if (file->rdir_fcall && (filp->f_pos != file->rdir_pos)) { over = filldir(dirent, st->name.str, st->name.len, filp->f_pos,
kfree(file->rdir_fcall); v9fs_qid2ino(&st->qid), dt_type(st));
file->rdir_fcall = NULL;
} if (over)
if (file->rdir_fcall) {
n = file->rdir_fcall->params.rread.count;
i = file->rdir_fpos;
while (i < n) {
s = v9fs_deserialize_stat(
file->rdir_fcall->params.rread.data + i,
n - i, &stat, v9ses->extended);
if (s == 0) {
dprintk(DEBUG_ERROR,
"error while deserializing stat\n");
ret = -EIO;
goto FreeStructs;
}
over = filldir(dirent, stat.name.str, stat.name.len,
filp->f_pos, v9fs_qid2ino(&stat.qid),
dt_type(&stat));
if (over) {
file->rdir_fpos = i;
file->rdir_pos = filp->f_pos;
break;
}
i += s;
filp->f_pos += s;
}
if (!over) {
kfree(file->rdir_fcall);
file->rdir_fcall = NULL;
}
}
while (!over) {
ret = v9fs_t_read(v9ses, fid, filp->f_pos,
v9ses->maxdata-V9FS_IOHDRSZ, &fcall);
if (ret < 0) {
dprintk(DEBUG_ERROR, "error while reading: %d: %p\n",
ret, fcall);
goto FreeStructs;
} else if (ret == 0)
break; break;
n = ret; filp->f_pos += st->size;
i = 0; kfree(st);
while (i < n) { st = NULL;
s = v9fs_deserialize_stat(fcall->params.rread.data + i,
n - i, &stat, v9ses->extended);
if (s == 0) {
dprintk(DEBUG_ERROR,
"error while deserializing stat\n");
return -EIO;
}
over = filldir(dirent, stat.name.str, stat.name.len,
filp->f_pos, v9fs_qid2ino(&stat.qid),
dt_type(&stat));
if (over) {
file->rdir_fcall = fcall;
file->rdir_fpos = i;
file->rdir_pos = filp->f_pos;
fcall = NULL;
break;
}
i += s;
filp->f_pos += s;
}
kfree(fcall);
} }
FreeStructs: kfree(st);
kfree(fcall); return 0;
return ret;
} }
/** /**
* v9fs_dir_release - close a directory * v9fs_dir_release - close a directory
* @inode: inode of the directory * @inode: inode of the directory
...@@ -178,29 +107,13 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -178,29 +107,13 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
int v9fs_dir_release(struct inode *inode, struct file *filp) int v9fs_dir_release(struct inode *inode, struct file *filp)
{ {
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct p9_fid *fid;
struct v9fs_fid *fid = filp->private_data;
int fidnum = -1;
dprintk(DEBUG_VFS, "inode: %p filp: %p fid: %d\n", inode, filp,
fid->fid);
fidnum = fid->fid;
fid = filp->private_data;
P9_DPRINTK(P9_DEBUG_VFS,
"inode: %p filp: %p fid: %d\n", inode, filp, fid->fid);
filemap_write_and_wait(inode->i_mapping); filemap_write_and_wait(inode->i_mapping);
p9_client_clunk(fid);
if (fidnum >= 0) {
dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen,
fid->fid);
if (v9fs_t_clunk(v9ses, fidnum))
dprintk(DEBUG_ERROR, "clunk failed\n");
kfree(fid->rdir_fcall);
kfree(fid);
filp->private_data = NULL;
}
return 0; return 0;
} }
......
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
#include <linux/list.h> #include <linux/list.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
#include "debug.h"
#include "v9fs.h" #include "v9fs.h"
#include "9p.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "fid.h" #include "fid.h"
...@@ -52,48 +52,36 @@ static const struct file_operations v9fs_cached_file_operations; ...@@ -52,48 +52,36 @@ static const struct file_operations v9fs_cached_file_operations;
int v9fs_file_open(struct inode *inode, struct file *file) int v9fs_file_open(struct inode *inode, struct file *file)
{ {
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
struct v9fs_fid *vfid;
struct v9fs_fcall *fcall = NULL;
int omode;
int err; int err;
struct v9fs_session_info *v9ses;
struct p9_fid *fid;
int omode;
dprintk(DEBUG_VFS, "inode: %p file: %p \n", inode, file); P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p \n", inode, file);
v9ses = v9fs_inode2v9ses(inode);
vfid = v9fs_fid_clone(file->f_path.dentry);
if (IS_ERR(vfid))
return PTR_ERR(vfid);
omode = v9fs_uflags2omode(file->f_flags); omode = v9fs_uflags2omode(file->f_flags);
err = v9fs_t_open(v9ses, vfid->fid, omode, &fcall); fid = file->private_data;
if (!fid) {
fid = v9fs_fid_clone(file->f_path.dentry);
if (IS_ERR(fid))
return PTR_ERR(fid);
err = p9_client_open(fid, omode);
if (err < 0) { if (err < 0) {
PRINT_FCALL_ERROR("open failed", fcall); p9_client_clunk(fid);
goto Clunk_Fid; return err;
}
} }
file->private_data = vfid; file->private_data = fid;
vfid->fidopen = 1; if ((fid->qid.version) && (v9ses->cache)) {
vfid->fidclunked = 0; P9_DPRINTK(P9_DEBUG_VFS, "cached");
vfid->iounit = fcall->params.ropen.iounit;
vfid->rdir_pos = 0;
vfid->rdir_fcall = NULL;
vfid->filp = file;
kfree(fcall);
if((vfid->qid.version) && (v9ses->cache)) {
dprintk(DEBUG_VFS, "cached");
/* enable cached file options */ /* enable cached file options */
if(file->f_op == &v9fs_file_operations) if(file->f_op == &v9fs_file_operations)
file->f_op = &v9fs_cached_file_operations; file->f_op = &v9fs_cached_file_operations;
} }
return 0; return 0;
Clunk_Fid:
v9fs_fid_clunk(v9ses, vfid);
kfree(fcall);
return err;
} }
/** /**
...@@ -110,7 +98,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl) ...@@ -110,7 +98,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
int res = 0; int res = 0;
struct inode *inode = filp->f_path.dentry->d_inode; struct inode *inode = filp->f_path.dentry->d_inode;
dprintk(DEBUG_VFS, "filp: %p lock: %p\n", filp, fl); P9_DPRINTK(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
/* No mandatory locks */ /* No mandatory locks */
if ((inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) if ((inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
...@@ -136,55 +124,16 @@ static ssize_t ...@@ -136,55 +124,16 @@ static ssize_t
v9fs_file_read(struct file *filp, char __user * data, size_t count, v9fs_file_read(struct file *filp, char __user * data, size_t count,
loff_t * offset) loff_t * offset)
{ {
struct inode *inode = filp->f_path.dentry->d_inode; int ret;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct p9_fid *fid;
struct v9fs_fid *v9f = filp->private_data;
struct v9fs_fcall *fcall = NULL;
int fid = v9f->fid;
int rsize = 0;
int result = 0;
int total = 0;
int n;
dprintk(DEBUG_VFS, "\n");
rsize = v9ses->maxdata - V9FS_IOHDRSZ;
if (v9f->iounit != 0 && rsize > v9f->iounit)
rsize = v9f->iounit;
do {
if (count < rsize)
rsize = count;
result = v9fs_t_read(v9ses, fid, *offset, rsize, &fcall); P9_DPRINTK(P9_DEBUG_VFS, "\n");
fid = filp->private_data;
ret = p9_client_uread(fid, data, *offset, count);
if (ret > 0)
*offset += ret;
if (result < 0) { return ret;
printk(KERN_ERR "9P2000: v9fs_t_read returned %d\n",
result);
kfree(fcall);
return total;
} else
*offset += result;
n = copy_to_user(data, fcall->params.rread.data, result);
if (n) {
dprintk(DEBUG_ERROR, "Problem copying to user %d\n", n);
kfree(fcall);
return -EFAULT;
}
count -= result;
data += result;
total += result;
kfree(fcall);
if (result < rsize)
break;
} while (count);
return total;
} }
/** /**
...@@ -200,50 +149,19 @@ static ssize_t ...@@ -200,50 +149,19 @@ static ssize_t
v9fs_file_write(struct file *filp, const char __user * data, v9fs_file_write(struct file *filp, const char __user * data,
size_t count, loff_t * offset) size_t count, loff_t * offset)
{ {
struct inode *inode = filp->f_path.dentry->d_inode; int ret;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct p9_fid *fid;
struct v9fs_fid *v9fid = filp->private_data;
struct v9fs_fcall *fcall;
int fid = v9fid->fid;
int result = -EIO;
int rsize = 0;
int total = 0;
dprintk(DEBUG_VFS, "data %p count %d offset %x\n", data, (int)count,
(int)*offset);
rsize = v9ses->maxdata - V9FS_IOHDRSZ;
if (v9fid->iounit != 0 && rsize > v9fid->iounit)
rsize = v9fid->iounit;
do {
if (count < rsize)
rsize = count;
result = v9fs_t_write(v9ses, fid, *offset, rsize, data, &fcall); P9_DPRINTK(P9_DEBUG_VFS, "data %p count %d offset %x\n", data,
if (result < 0) { (int)count, (int)*offset);
PRINT_FCALL_ERROR("error while writing", fcall);
kfree(fcall);
return result;
} else
*offset += result;
kfree(fcall);
fcall = NULL;
if (result != rsize) {
eprintk(KERN_ERR,
"short write: v9fs_t_write returned %d\n",
result);
break;
}
count -= result; fid = filp->private_data;
data += result; ret = p9_client_uwrite(fid, data, *offset, count);
total += result; if (ret > 0)
} while (count); *offset += ret;
invalidate_inode_pages2(inode->i_mapping); invalidate_inode_pages2(filp->f_path.dentry->d_inode->i_mapping);
return total; return ret;
} }
static const struct file_operations v9fs_cached_file_operations = { static const struct file_operations v9fs_cached_file_operations = {
......
This diff is collapsed.
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
#include "debug.h"
#include "v9fs.h" #include "v9fs.h"
#include "9p.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "fid.h" #include "fid.h"
...@@ -107,41 +107,48 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, ...@@ -107,41 +107,48 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
struct vfsmount *mnt) struct vfsmount *mnt)
{ {
struct super_block *sb = NULL; struct super_block *sb = NULL;
struct v9fs_fcall *fcall = NULL;
struct inode *inode = NULL; struct inode *inode = NULL;
struct dentry *root = NULL; struct dentry *root = NULL;
struct v9fs_session_info *v9ses = NULL; struct v9fs_session_info *v9ses = NULL;
struct v9fs_fid *root_fid = NULL; struct p9_stat *st = NULL;
int mode = S_IRWXUGO | S_ISVTX; int mode = S_IRWXUGO | S_ISVTX;
uid_t uid = current->fsuid; uid_t uid = current->fsuid;
gid_t gid = current->fsgid; gid_t gid = current->fsgid;
int stat_result = 0; struct p9_fid *fid;
int newfid = 0;
int retval = 0; int retval = 0;
dprintk(DEBUG_VFS, " \n"); P9_DPRINTK(P9_DEBUG_VFS, " \n");
v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL); v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL);
if (!v9ses) if (!v9ses)
return -ENOMEM; return -ENOMEM;
if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) { fid = v9fs_session_init(v9ses, dev_name, data);
dprintk(DEBUG_ERROR, "problem initiating session\n"); if (IS_ERR(fid)) {
retval = newfid; retval = PTR_ERR(fid);
goto out_free_session; fid = NULL;
kfree(v9ses);
v9ses = NULL;
goto error;
}
st = p9_client_stat(fid);
if (IS_ERR(st)) {
retval = PTR_ERR(st);
goto error;
} }
sb = sget(fs_type, NULL, v9fs_set_super, v9ses); sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
if (IS_ERR(sb)) { if (IS_ERR(sb)) {
retval = PTR_ERR(sb); retval = PTR_ERR(sb);
goto out_close_session; goto error;
} }
v9fs_fill_super(sb, v9ses, flags); v9fs_fill_super(sb, v9ses, flags);
inode = v9fs_get_inode(sb, S_IFDIR | mode); inode = v9fs_get_inode(sb, S_IFDIR | mode);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
retval = PTR_ERR(inode); retval = PTR_ERR(inode);
goto put_back_sb; goto error;
} }
inode->i_uid = uid; inode->i_uid = uid;
...@@ -150,54 +157,30 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, ...@@ -150,54 +157,30 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
root = d_alloc_root(inode); root = d_alloc_root(inode);
if (!root) { if (!root) {
retval = -ENOMEM; retval = -ENOMEM;
goto put_back_sb; goto error;
} }
sb->s_root = root; sb->s_root = root;
root->d_inode->i_ino = v9fs_qid2ino(&st->qid);
v9fs_stat2inode(st, root->d_inode, sb);
v9fs_fid_add(root, fid);
stat_result = v9fs_t_stat(v9ses, newfid, &fcall); return simple_set_mnt(mnt, sb);
if (stat_result < 0) {
dprintk(DEBUG_ERROR, "stat error\n");
v9fs_t_clunk(v9ses, newfid);
} else {
/* Setup the Root Inode */
root_fid = v9fs_fid_create(v9ses, newfid);
if (root_fid == NULL) {
retval = -ENOMEM;
goto put_back_sb;
}
retval = v9fs_fid_insert(root_fid, root);
if (retval < 0) {
kfree(fcall);
goto put_back_sb;
}
root_fid->qid = fcall->params.rstat.stat.qid;
root->d_inode->i_ino =
v9fs_qid2ino(&fcall->params.rstat.stat.qid);
v9fs_stat2inode(&fcall->params.rstat.stat, root->d_inode, sb);
}
kfree(fcall); error:
if (fid)
p9_client_clunk(fid);
if (stat_result < 0) { if (v9ses) {
retval = stat_result; v9fs_session_close(v9ses);
goto put_back_sb; kfree(v9ses);
} }
return simple_set_mnt(mnt, sb); if (sb) {
up_write(&sb->s_umount);
out_close_session: deactivate_super(sb);
v9fs_session_close(v9ses); }
out_free_session:
kfree(v9ses);
return retval;
put_back_sb:
/* deactivate_super calls v9fs_kill_super which will frees the rest */
up_write(&sb->s_umount);
deactivate_super(sb);
return retval; return retval;
} }
...@@ -211,7 +194,7 @@ static void v9fs_kill_super(struct super_block *s) ...@@ -211,7 +194,7 @@ static void v9fs_kill_super(struct super_block *s)
{ {
struct v9fs_session_info *v9ses = s->s_fs_info; struct v9fs_session_info *v9ses = s->s_fs_info;
dprintk(DEBUG_VFS, " %p\n", s); P9_DPRINTK(P9_DEBUG_VFS, " %p\n", s);
v9fs_dentry_release(s->s_root); /* clunk root */ v9fs_dentry_release(s->s_root); /* clunk root */
...@@ -219,7 +202,7 @@ static void v9fs_kill_super(struct super_block *s) ...@@ -219,7 +202,7 @@ static void v9fs_kill_super(struct super_block *s)
v9fs_session_close(v9ses); v9fs_session_close(v9ses);
kfree(v9ses); kfree(v9ses);
dprintk(DEBUG_VFS, "exiting kill_super\n"); P9_DPRINTK(P9_DEBUG_VFS, "exiting kill_super\n");
} }
/** /**
......
...@@ -2048,7 +2048,7 @@ config AFS_DEBUG ...@@ -2048,7 +2048,7 @@ config AFS_DEBUG
config 9P_FS config 9P_FS
tristate "Plan 9 Resource Sharing Support (9P2000) (Experimental)" tristate "Plan 9 Resource Sharing Support (9P2000) (Experimental)"
depends on INET && EXPERIMENTAL depends on INET && NET_9P && EXPERIMENTAL
help help
If you say Y here, you will get experimental support for If you say Y here, you will get experimental support for
Plan 9 resource sharing via the 9P2000 protocol. Plan 9 resource sharing via the 9P2000 protocol.
......
/*
* include/net/9p/9p.h
*
* 9P protocol definitions.
*
* Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
#ifndef NET_9P_H
#define NET_9P_H
#ifdef CONFIG_NET_9P_DEBUG
#define P9_DEBUG_ERROR (1<<0)
#define P9_DEBUG_9P (1<<2)
#define P9_DEBUG_VFS (1<<3)
#define P9_DEBUG_CONV (1<<4)
#define P9_DEBUG_MUX (1<<5)
#define P9_DEBUG_TRANS (1<<6)
#define P9_DEBUG_SLABS (1<<7)
#define P9_DEBUG_FCALL (1<<8)
extern unsigned int p9_debug_level;
#define P9_DPRINTK(level, format, arg...) \
do { \
if ((p9_debug_level & level) == level) \
printk(KERN_NOTICE "-- %s (%d): " \
format , __FUNCTION__, current->pid , ## arg); \
} while (0)
#define PRINT_FCALL_ERROR(s, fcall) P9_DPRINTK(P9_DEBUG_ERROR, \
"%s: %.*s\n", s, fcall?fcall->params.rerror.error.len:0, \
fcall?fcall->params.rerror.error.str:"");
#else
#define P9_DPRINTK(level, format, arg...) do { } while (0)
#define PRINT_FCALL_ERROR(s, fcall) do { } while (0)
#endif
#define P9_EPRINTK(level, format, arg...) \
do { \
printk(level "9p: %s (%d): " \
format , __FUNCTION__, current->pid , ## arg); \
} while (0)
/* Message Types */
enum {
P9_TVERSION = 100,
P9_RVERSION,
P9_TAUTH = 102,
P9_RAUTH,
P9_TATTACH = 104,
P9_RATTACH,
P9_TERROR = 106,
P9_RERROR,
P9_TFLUSH = 108,
P9_RFLUSH,
P9_TWALK = 110,
P9_RWALK,
P9_TOPEN = 112,
P9_ROPEN,
P9_TCREATE = 114,
P9_RCREATE,
P9_TREAD = 116,
P9_RREAD,
P9_TWRITE = 118,
P9_RWRITE,
P9_TCLUNK = 120,
P9_RCLUNK,
P9_TREMOVE = 122,
P9_RREMOVE,
P9_TSTAT = 124,
P9_RSTAT,
P9_TWSTAT = 126,
P9_RWSTAT,
};
/* open modes */
enum {
P9_OREAD = 0x00,
P9_OWRITE = 0x01,
P9_ORDWR = 0x02,
P9_OEXEC = 0x03,
P9_OEXCL = 0x04,
P9_OTRUNC = 0x10,
P9_OREXEC = 0x20,
P9_ORCLOSE = 0x40,
P9_OAPPEND = 0x80,
};
/* permissions */
enum {
P9_DMDIR = 0x80000000,
P9_DMAPPEND = 0x40000000,
P9_DMEXCL = 0x20000000,
P9_DMMOUNT = 0x10000000,
P9_DMAUTH = 0x08000000,
P9_DMTMP = 0x04000000,
P9_DMSYMLINK = 0x02000000,
P9_DMLINK = 0x01000000,
/* 9P2000.u extensions */
P9_DMDEVICE = 0x00800000,
P9_DMNAMEDPIPE = 0x00200000,
P9_DMSOCKET = 0x00100000,
P9_DMSETUID = 0x00080000,
P9_DMSETGID = 0x00040000,
};
/* qid.types */
enum {
P9_QTDIR = 0x80,
P9_QTAPPEND = 0x40,
P9_QTEXCL = 0x20,
P9_QTMOUNT = 0x10,
P9_QTAUTH = 0x08,
P9_QTTMP = 0x04,
P9_QTSYMLINK = 0x02,
P9_QTLINK = 0x01,
P9_QTFILE = 0x00,
};
#define P9_NOTAG (u16)(~0)
#define P9_NOFID (u32)(~0)
#define P9_MAXWELEM 16
/* ample room for Twrite/Rread header */
#define P9_IOHDRSZ 24
struct p9_str {
u16 len;
char *str;
};
/* qids are the unique ID for a file (like an inode */
struct p9_qid {
u8 type;
u32 version;
u64 path;
};
/* Plan 9 file metadata (stat) structure */
struct p9_stat {
u16 size;
u16 type;
u32 dev;
struct p9_qid qid;
u32 mode;
u32 atime;
u32 mtime;
u64 length;
struct p9_str name;
struct p9_str uid;
struct p9_str gid;
struct p9_str muid;
struct p9_str extension; /* 9p2000.u extensions */
u32 n_uid; /* 9p2000.u extensions */
u32 n_gid; /* 9p2000.u extensions */
u32 n_muid; /* 9p2000.u extensions */
};
/* file metadata (stat) structure used to create Twstat message
The is similar to p9_stat, but the strings don't point to
the same memory block and should be freed separately
*/
struct p9_wstat {
u16 size;
u16 type;
u32 dev;
struct p9_qid qid;
u32 mode;
u32 atime;
u32 mtime;
u64 length;
char *name;
char *uid;
char *gid;
char *muid;
char *extension; /* 9p2000.u extensions */
u32 n_uid; /* 9p2000.u extensions */
u32 n_gid; /* 9p2000.u extensions */
u32 n_muid; /* 9p2000.u extensions */
};
/* Structures for Protocol Operations */
struct p9_tversion {
u32 msize;
struct p9_str version;
};
struct p9_rversion {
u32 msize;
struct p9_str version;
};
struct p9_tauth {
u32 afid;
struct p9_str uname;
struct p9_str aname;
};
struct p9_rauth {
struct p9_qid qid;
};
struct p9_rerror {
struct p9_str error;
u32 errno; /* 9p2000.u extension */
};
struct p9_tflush {
u16 oldtag;
};
struct p9_rflush {
};
struct p9_tattach {
u32 fid;
u32 afid;
struct p9_str uname;
struct p9_str aname;
};
struct p9_rattach {
struct p9_qid qid;
};
struct p9_twalk {
u32 fid;
u32 newfid;
u16 nwname;
struct p9_str wnames[16];
};
struct p9_rwalk {
u16 nwqid;
struct p9_qid wqids[16];
};
struct p9_topen {
u32 fid;
u8 mode;
};
struct p9_ropen {
struct p9_qid qid;
u32 iounit;
};
struct p9_tcreate {
u32 fid;
struct p9_str name;
u32 perm;
u8 mode;
struct p9_str extension;
};
struct p9_rcreate {
struct p9_qid qid;
u32 iounit;
};
struct p9_tread {
u32 fid;
u64 offset;
u32 count;
};
struct p9_rread {
u32 count;
u8 *data;
};
struct p9_twrite {
u32 fid;
u64 offset;
u32 count;
u8 *data;
};
struct p9_rwrite {
u32 count;
};
struct p9_tclunk {
u32 fid;
};
struct p9_rclunk {
};
struct p9_tremove {
u32 fid;
};
struct p9_rremove {
};
struct p9_tstat {
u32 fid;
};
struct p9_rstat {
struct p9_stat stat;
};
struct p9_twstat {
u32 fid;
struct p9_stat stat;
};
struct p9_rwstat {
};
/*
* fcall is the primary packet structure
*
*/
struct p9_fcall {
u32 size;
u8 id;
u16 tag;
void *sdata;
union {
struct p9_tversion tversion;
struct p9_rversion rversion;
struct p9_tauth tauth;
struct p9_rauth rauth;
struct p9_rerror rerror;
struct p9_tflush tflush;
struct p9_rflush rflush;
struct p9_tattach tattach;
struct p9_rattach rattach;
struct p9_twalk twalk;
struct p9_rwalk rwalk;
struct p9_topen topen;
struct p9_ropen ropen;
struct p9_tcreate tcreate;
struct p9_rcreate rcreate;
struct p9_tread tread;
struct p9_rread rread;
struct p9_twrite twrite;
struct p9_rwrite rwrite;
struct p9_tclunk tclunk;
struct p9_rclunk rclunk;
struct p9_tremove tremove;
struct p9_rremove rremove;
struct p9_tstat tstat;
struct p9_rstat rstat;
struct p9_twstat twstat;
struct p9_rwstat rwstat;
} params;
};
struct p9_idpool;
int p9_deserialize_stat(void *buf, u32 buflen, struct p9_stat *stat,
int dotu);
int p9_deserialize_fcall(void *buf, u32 buflen, struct p9_fcall *fc, int dotu);
void p9_set_tag(struct p9_fcall *fc, u16 tag);
struct p9_fcall *p9_create_tversion(u32 msize, char *version);
struct p9_fcall *p9_create_tattach(u32 fid, u32 afid, char *uname,
char *aname);
struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname);
struct p9_fcall *p9_create_tflush(u16 oldtag);
struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname,
char **wnames);
struct p9_fcall *p9_create_topen(u32 fid, u8 mode);
struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode,
char *extension, int dotu);
struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count);
struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count,
const char *data);
struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count,
const char __user *data);
struct p9_fcall *p9_create_tclunk(u32 fid);
struct p9_fcall *p9_create_tremove(u32 fid);
struct p9_fcall *p9_create_tstat(u32 fid);
struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat,
int dotu);
int p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int dotu);
int p9_errstr2errno(char *errstr, int len);
struct p9_idpool *p9_idpool_create(void);
void p9_idpool_destroy(struct p9_idpool *);
int p9_idpool_get(struct p9_idpool *p);
void p9_idpool_put(int id, struct p9_idpool *p);
int p9_idpool_check(int id, struct p9_idpool *p);
int p9_error_init(void);
int p9_errstr2errno(char *, int);
int __init p9_sysctl_register(void);
void __exit p9_sysctl_unregister(void);
#endif /* NET_9P_H */
/*
* include/net/9p/client.h
*
* 9P Client Definitions
*
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
#ifndef NET_9P_CLIENT_H
#define NET_9P_CLIENT_H
struct p9_client {
spinlock_t lock; /* protect client structure */
int msize;
unsigned char dotu;
struct p9_transport *trans;
struct p9_conn *conn;
struct p9_idpool *fidpool;
struct list_head fidlist;
};
struct p9_fid {
struct p9_client *clnt;
u32 fid;
int mode;
struct p9_qid qid;
u32 iounit;
uid_t uid;
void *aux;
int rdir_fpos;
int rdir_pos;
struct p9_fcall *rdir_fcall;
struct list_head flist;
struct list_head dlist; /* list of all fids attached to a dentry */
};
struct p9_client *p9_client_create(struct p9_transport *trans, int msize,
int dotu);
void p9_client_destroy(struct p9_client *clnt);
void p9_client_disconnect(struct p9_client *clnt);
struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
char *uname, char *aname);
struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname, char *aname);
struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
int clone);
int p9_client_open(struct p9_fid *fid, int mode);
int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
char *extension);
int p9_client_clunk(struct p9_fid *fid);
int p9_client_remove(struct p9_fid *fid);
int p9_client_read(struct p9_fid *fid, char *data, u64 offset, u32 count);
int p9_client_readn(struct p9_fid *fid, char *data, u64 offset, u32 count);
int p9_client_write(struct p9_fid *fid, char *data, u64 offset, u32 count);
int p9_client_uread(struct p9_fid *fid, char __user *data, u64 offset,
u32 count);
int p9_client_uwrite(struct p9_fid *fid, const char __user *data, u64 offset,
u32 count);
struct p9_stat *p9_client_stat(struct p9_fid *fid);
int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst);
struct p9_stat *p9_client_dirread(struct p9_fid *fid, u64 offset);
#endif /* NET_9P_CLIENT_H */
/* /*
* linux/fs/9p/mux.h * include/net/9p/conn.h
* *
* Multiplexer Definitions * Connection Definitions
* *
* Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
...@@ -23,33 +23,35 @@ ...@@ -23,33 +23,35 @@
* *
*/ */
struct v9fs_mux_data; #ifndef NET_9P_CONN_H
struct v9fs_req; #define NET_9P_CONN_H
#undef P9_NONBLOCK
struct p9_conn;
struct p9_req;
/** /**
* v9fs_mux_req_callback - callback function that is called when the * p9_mux_req_callback - callback function that is called when the
* response of a request is received. The callback is called from * response of a request is received. The callback is called from
* a workqueue and shouldn't block. * a workqueue and shouldn't block.
* *
* @req - request
* @a - the pointer that was specified when the request was send to be * @a - the pointer that was specified when the request was send to be
* passed to the callback * passed to the callback
* @tc - request call
* @rc - response call
* @err - error code (non-zero if error occured)
*/ */
typedef void (*v9fs_mux_req_callback)(struct v9fs_req *req, void *a); typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a);
int v9fs_mux_global_init(void); struct p9_conn *p9_conn_create(struct p9_transport *trans, int msize,
void v9fs_mux_global_exit(void); unsigned char *dotu);
void p9_conn_destroy(struct p9_conn *);
int p9_conn_rpc(struct p9_conn *m, struct p9_fcall *tc, struct p9_fcall **rc);
struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, #ifdef P9_NONBLOCK
unsigned char *extended); int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc,
void v9fs_mux_destroy(struct v9fs_mux_data *); p9_conn_req_callback cb, void *a);
#endif /* P9_NONBLOCK */
int v9fs_mux_send(struct v9fs_mux_data *m, struct v9fs_fcall *tc); void p9_conn_cancel(struct p9_conn *m, int err);
struct v9fs_fcall *v9fs_mux_recv(struct v9fs_mux_data *m);
int v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, struct v9fs_fcall **rc);
void v9fs_mux_flush(struct v9fs_mux_data *m, int sendflush); #endif /* NET_9P_CONN_H */
void v9fs_mux_cancel(struct v9fs_mux_data *m, int err);
int v9fs_errstr2errno(char *errstr, int len);
/* /*
* linux/fs/9p/transport.h * include/net/9p/transport.h
* *
* Transport Definition * Transport Definition
* *
...@@ -23,23 +23,27 @@ ...@@ -23,23 +23,27 @@
* *
*/ */
enum v9fs_transport_status { #ifndef NET_9P_TRANSPORT_H
#define NET_9P_TRANSPORT_H
enum p9_transport_status {
Connected, Connected,
Disconnected, Disconnected,
Hung, Hung,
}; };
struct v9fs_transport { struct p9_transport {
enum v9fs_transport_status status; enum p9_transport_status status;
void *priv; void *priv;
int (*init) (struct v9fs_session_info *, const char *, char *); int (*write) (struct p9_transport *, void *, int);
int (*write) (struct v9fs_transport *, void *, int); int (*read) (struct p9_transport *, void *, int);
int (*read) (struct v9fs_transport *, void *, int); void (*close) (struct p9_transport *);
void (*close) (struct v9fs_transport *); unsigned int (*poll)(struct p9_transport *, struct poll_table_struct *);
unsigned int (*poll)(struct v9fs_transport *, struct poll_table_struct *);
}; };
extern struct v9fs_transport v9fs_trans_tcp; struct p9_transport *p9_trans_create_tcp(const char *addr, int port);
extern struct v9fs_transport v9fs_trans_unix; struct p9_transport *p9_trans_create_unix(const char *addr);
extern struct v9fs_transport v9fs_trans_fd; struct p9_transport *p9_trans_create_fd(int rfd, int wfd);
#endif /* NET_9P_TRANSPORT_H */
#
# 9P protocol configuration
#
menuconfig NET_9P
depends on NET && EXPERIMENTAL
tristate "Plan 9 Resource Sharing Support (9P2000) (Experimental)"
help
If you say Y here, you will get experimental support for
Plan 9 resource sharing via the 9P2000 protocol.
See <http://v9fs.sf.net> for more information.
If unsure, say N.
config NET_9P_DEBUG
bool "Debug information"
depends on NET_9P
help
Say Y if you want the 9P subsistem to log debug information.
obj-$(CONFIG_NET_9P) := 9p.o
9p-objs := \
mod.o \
trans_fd.o \
mux.o \
client.o \
conv.o \
error.o \
fcprint.o \
util.o \
9p-$(CONFIG_SYSCTL) += sysctl.o
This diff is collapsed.
This diff is collapsed.
/* /*
* linux/fs/9p/error.h * linux/fs/9p/error.c
* *
* Huge Nasty Error Table * Error string handling
* *
* Plan 9 uses error strings, Unix uses error numbers. This table tries to * Plan 9 uses error strings, Unix uses error numbers. These functions
* match UNIX strings and Plan 9 strings to unix error numbers. It is used * try to help manage that and provide for dynamically adding error
* to preload the dynamic error table which can also track user-specific error * mappings.
* strings.
* *
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
...@@ -28,8 +27,11 @@ ...@@ -28,8 +27,11 @@
* *
*/ */
#include <linux/module.h>
#include <linux/list.h>
#include <linux/jhash.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <asm/errno.h> #include <net/9p/9p.h>
struct errormap { struct errormap {
char *name; char *name;
...@@ -174,4 +176,65 @@ static struct errormap errmap[] = { ...@@ -174,4 +176,65 @@ static struct errormap errmap[] = {
{NULL, -1} {NULL, -1}
}; };
extern int v9fs_error_init(void); /**
* p9_error_init - preload
* @errstr: error string
*
*/
int p9_error_init(void)
{
struct errormap *c;
int bucket;
/* initialize hash table */
for (bucket = 0; bucket < ERRHASHSZ; bucket++)
INIT_HLIST_HEAD(&hash_errmap[bucket]);
/* load initial error map into hash table */
for (c = errmap; c->name != NULL; c++) {
c->namelen = strlen(c->name);
bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ;
INIT_HLIST_NODE(&c->list);
hlist_add_head(&c->list, &hash_errmap[bucket]);
}
return 1;
}
EXPORT_SYMBOL(p9_error_init);
/**
* errstr2errno - convert error string to error number
* @errstr: error string
*
*/
int p9_errstr2errno(char *errstr, int len)
{
int errno;
struct hlist_node *p;
struct errormap *c;
int bucket;
errno = 0;
p = NULL;
c = NULL;
bucket = jhash(errstr, len, 0) % ERRHASHSZ;
hlist_for_each_entry(c, p, &hash_errmap[bucket], list) {
if (c->namelen == len && !memcmp(c->name, errstr, len)) {
errno = c->val;
break;
}
}
if (errno == 0) {
/* TODO: if error isn't found, add it dynamically */
errstr[len] = 0;
printk(KERN_ERR "%s: errstr :%s: not found\n", __FUNCTION__,
errstr);
errno = 1;
}
return -errno;
}
EXPORT_SYMBOL(p9_errstr2errno);
This diff is collapsed.
/* /*
* linux/fs/9p/error.c * net/9p/9p.c
* *
* Error string handling * 9P entry point
*
* Plan 9 uses error strings, Unix uses error numbers. These functions
* try to help manage that and provide for dynamically adding error
* mappings.
* *
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
* *
...@@ -28,66 +25,61 @@ ...@@ -28,66 +25,61 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h>
#include <net/9p/9p.h>
#include <linux/list.h> #ifdef CONFIG_NET_9P_DEBUG
#include <linux/jhash.h> unsigned int p9_debug_level = 0; /* feature-rific global debug level */
EXPORT_SYMBOL(p9_debug_level);
module_param_named(debug, p9_debug_level, uint, 0);
MODULE_PARM_DESC(debug, "9P debugging level");
#endif
#include "debug.h" extern int p9_mux_global_init(void);
#include "error.h" extern void p9_mux_global_exit(void);
extern int p9_sysctl_register(void);
extern void p9_sysctl_unregister(void);
/** /**
* v9fs_error_init - preload * v9fs_init - Initialize module
* @errstr: error string
* *
*/ */
static int __init init_p9(void)
int v9fs_error_init(void)
{ {
struct errormap *c; int ret;
int bucket;
/* initialize hash table */ p9_error_init();
for (bucket = 0; bucket < ERRHASHSZ; bucket++) printk(KERN_INFO "Installing 9P2000 support\n");
INIT_HLIST_HEAD(&hash_errmap[bucket]); ret = p9_mux_global_init();
if (ret) {
printk(KERN_WARNING "9p: starting mux failed\n");
return ret;
}
/* load initial error map into hash table */ ret = p9_sysctl_register();
for (c = errmap; c->name != NULL; c++) { if (ret) {
c->namelen = strlen(c->name); printk(KERN_WARNING "9p: registering sysctl failed\n");
bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ; return ret;
INIT_HLIST_NODE(&c->list);
hlist_add_head(&c->list, &hash_errmap[bucket]);
} }
return 1; return ret;
} }
/** /**
* errstr2errno - convert error string to error number * v9fs_init - shutdown module
* @errstr: error string
* *
*/ */
int v9fs_errstr2errno(char *errstr, int len) static void __exit exit_p9(void)
{ {
int errno = 0; p9_sysctl_unregister();
struct hlist_node *p = NULL; p9_mux_global_exit();
struct errormap *c = NULL; }
int bucket = jhash(errstr, len, 0) % ERRHASHSZ;
hlist_for_each_entry(c, p, &hash_errmap[bucket], list) {
if (c->namelen==len && !memcmp(c->name, errstr, len)) {
errno = c->val;
break;
}
}
if (errno == 0) { module_init(init_p9)
/* TODO: if error isn't found, add it dynamically */ module_exit(exit_p9)
errstr[len] = 0;
printk(KERN_ERR "%s: errstr :%s: not found\n", __FUNCTION__,
errstr);
errno = 1;
}
return -errno; MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
} MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
MODULE_LICENSE("GPL");
This diff is collapsed.
/* /*
* linux/fs/9p/conv.h * net/9p/sysctl.c
* *
* 9P protocol conversion definitions. * 9P sysctl interface
* *
* Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net> * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 * it under the terms of the GNU General Public License version 2
...@@ -24,27 +22,65 @@ ...@@ -24,27 +22,65 @@
* *
*/ */
int v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat, #include <linux/kernel.h>
int extended); #include <linux/mm.h>
int v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall, #include <linux/sysctl.h>
int extended); #include <linux/init.h>
#include <net/9p/9p.h>
void v9fs_set_tag(struct v9fs_fcall *fc, u16 tag);
enum {
struct v9fs_fcall *v9fs_create_tversion(u32 msize, char *version); P9_SYSCTL_NET = 487,
struct v9fs_fcall *v9fs_create_tattach(u32 fid, u32 afid, char *uname, P9_SYSCTL_DEBUG = 1,
char *aname); };
struct v9fs_fcall *v9fs_create_tflush(u16 oldtag);
struct v9fs_fcall *v9fs_create_twalk(u32 fid, u32 newfid, u16 nwname, static ctl_table p9_table[] = {
char **wnames); #ifdef CONFIG_NET_9P_DEBUG
struct v9fs_fcall *v9fs_create_topen(u32 fid, u8 mode); {
struct v9fs_fcall *v9fs_create_tcreate(u32 fid, char *name, u32 perm, u8 mode, .ctl_name = P9_SYSCTL_DEBUG,
char *extension, int extended); .procname = "debug",
struct v9fs_fcall *v9fs_create_tread(u32 fid, u64 offset, u32 count); .data = &p9_debug_level,
struct v9fs_fcall *v9fs_create_twrite(u32 fid, u64 offset, u32 count, .maxlen = sizeof(int),
const char __user *data); .mode = 0644,
struct v9fs_fcall *v9fs_create_tclunk(u32 fid); .proc_handler = &proc_dointvec
struct v9fs_fcall *v9fs_create_tremove(u32 fid); },
struct v9fs_fcall *v9fs_create_tstat(u32 fid); #endif
struct v9fs_fcall *v9fs_create_twstat(u32 fid, struct v9fs_wstat *wstat, { .ctl_name = 0 },
int extended); };
static ctl_table p9_net_table[] = {
{
.ctl_name = P9_SYSCTL_NET,
.procname = "9p",
.maxlen = 0,
.mode = 0555,
.child = p9_table,
},
{ .ctl_name = 0 },
};
static ctl_table p9_ctl_table[] = {
{
.ctl_name = CTL_NET,
.procname = "net",
.maxlen = 0,
.mode = 0555,
.child = p9_net_table,
},
{ .ctl_name = 0 },
};
static struct ctl_table_header *p9_table_header;
int __init p9_sysctl_register(void)
{
p9_table_header = register_sysctl_table(p9_ctl_table);
if (!p9_table_header)
return -ENOMEM;
return 0;
}
void __exit p9_sysctl_unregister(void)
{
unregister_sysctl_table(p9_table_header);
}
This diff is collapsed.
/*
* net/9p/util.c
*
* This file contains some helper functions
*
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/parser.h>
#include <linux/idr.h>
#include <net/9p/9p.h>
struct p9_idpool {
struct semaphore lock;
struct idr pool;
};
struct p9_idpool *p9_idpool_create(void)
{
struct p9_idpool *p;
p = kmalloc(sizeof(struct p9_idpool), GFP_KERNEL);
if (!p)
return ERR_PTR(-ENOMEM);
init_MUTEX(&p->lock);
idr_init(&p->pool);
return p;
}
EXPORT_SYMBOL(p9_idpool_create);
void p9_idpool_destroy(struct p9_idpool *p)
{
idr_destroy(&p->pool);
kfree(p);
}
EXPORT_SYMBOL(p9_idpool_destroy);
/**
* p9_idpool_get - allocate numeric id from pool
* @p - pool to allocate from
*
* XXX - This seems to be an awful generic function, should it be in idr.c with
* the lock included in struct idr?
*/
int p9_idpool_get(struct p9_idpool *p)
{
int i = 0;
int error;
retry:
if (idr_pre_get(&p->pool, GFP_KERNEL) == 0)
return 0;
if (down_interruptible(&p->lock) == -EINTR) {
P9_EPRINTK(KERN_WARNING, "Interrupted while locking\n");
return -1;
}
/* no need to store exactly p, we just need something non-null */
error = idr_get_new(&p->pool, p, &i);
up(&p->lock);
if (error == -EAGAIN)
goto retry;
else if (error)
return -1;
return i;
}
EXPORT_SYMBOL(p9_idpool_get);
/**
* p9_idpool_put - release numeric id from pool
* @p - pool to allocate from
*
* XXX - This seems to be an awful generic function, should it be in idr.c with
* the lock included in struct idr?
*/
void p9_idpool_put(int id, struct p9_idpool *p)
{
if (down_interruptible(&p->lock) == -EINTR) {
P9_EPRINTK(KERN_WARNING, "Interrupted while locking\n");
return;
}
idr_remove(&p->pool, id);
up(&p->lock);
}
EXPORT_SYMBOL(p9_idpool_put);
/**
* p9_idpool_check - check if the specified id is available
* @id - id to check
* @p - pool
*/
int p9_idpool_check(int id, struct p9_idpool *p)
{
return idr_find(&p->pool, id) != NULL;
}
EXPORT_SYMBOL(p9_idpool_check);
...@@ -227,6 +227,7 @@ source "net/ieee80211/Kconfig" ...@@ -227,6 +227,7 @@ source "net/ieee80211/Kconfig"
endmenu endmenu
source "net/rfkill/Kconfig" source "net/rfkill/Kconfig"
source "net/9p/Kconfig"
endif # if NET endif # if NET
endmenu # Networking endmenu # Networking
......
...@@ -51,6 +51,7 @@ obj-$(CONFIG_TIPC) += tipc/ ...@@ -51,6 +51,7 @@ obj-$(CONFIG_TIPC) += tipc/
obj-$(CONFIG_NETLABEL) += netlabel/ obj-$(CONFIG_NETLABEL) += netlabel/
obj-$(CONFIG_IUCV) += iucv/ obj-$(CONFIG_IUCV) += iucv/
obj-$(CONFIG_RFKILL) += rfkill/ obj-$(CONFIG_RFKILL) += rfkill/
obj-$(CONFIG_NET_9P) += 9p/
ifeq ($(CONFIG_NET),y) ifeq ($(CONFIG_NET),y)
obj-$(CONFIG_SYSCTL) += sysctl_net.o obj-$(CONFIG_SYSCTL) += sysctl_net.o
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment