Commit d2a9a8de authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs:
  9p: fix a race condition bug in umount which caused a segfault
  9p: re-enable mount time debug option
  9p: cache meta-data when cache=loose
  net/9p: set error to EREMOTEIO if trans->write returns zero
  net/9p: change net/9p module name to 9pnet
  9p: Reorganization of 9p file system code
parents 2d896c78 0af8887e
/*
* 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);
...@@ -29,16 +29,12 @@ ...@@ -29,16 +29,12 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/parser.h> #include <linux/parser.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <net/9p/9p.h>
#include "debug.h" #include <net/9p/transport.h>
#include <net/9p/conn.h>
#include <net/9p/client.h>
#include "v9fs.h" #include "v9fs.h"
#include "9p.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "transport.h"
#include "mux.h"
/* TODO: sysfs or debugfs interface */
int v9fs_debug_level = 0; /* feature-rific global debug level */
/* /*
* Option Parsing (code inspired by NFS code) * Option Parsing (code inspired by NFS code)
...@@ -47,12 +43,12 @@ int v9fs_debug_level = 0; /* feature-rific global debug level */ ...@@ -47,12 +43,12 @@ int v9fs_debug_level = 0; /* feature-rific global debug level */
enum { enum {
/* Options that take integer arguments */ /* Options that take integer arguments */
Opt_port, Opt_msize, Opt_uid, Opt_gid, Opt_afid, Opt_debug, Opt_debug, Opt_port, Opt_msize, Opt_uid, Opt_gid, Opt_afid,
Opt_rfdno, Opt_wfdno, Opt_rfdno, Opt_wfdno,
/* String options */ /* String options */
Opt_uname, Opt_remotename, Opt_uname, Opt_remotename,
/* Options that take no arguments */ /* Options that take no arguments */
Opt_legacy, Opt_nodevmap, Opt_unix, Opt_tcp, Opt_fd, Opt_legacy, Opt_nodevmap, Opt_unix, Opt_tcp, Opt_fd, Opt_pci,
/* Cache options */ /* Cache options */
Opt_cache_loose, Opt_cache_loose,
/* Error token */ /* Error token */
...@@ -60,6 +56,7 @@ enum { ...@@ -60,6 +56,7 @@ enum {
}; };
static match_table_t tokens = { static match_table_t tokens = {
{Opt_debug, "debug=%x"},
{Opt_port, "port=%u"}, {Opt_port, "port=%u"},
{Opt_msize, "msize=%u"}, {Opt_msize, "msize=%u"},
{Opt_uid, "uid=%u"}, {Opt_uid, "uid=%u"},
...@@ -67,12 +64,14 @@ static match_table_t tokens = { ...@@ -67,12 +64,14 @@ static match_table_t tokens = {
{Opt_afid, "afid=%u"}, {Opt_afid, "afid=%u"},
{Opt_rfdno, "rfdno=%u"}, {Opt_rfdno, "rfdno=%u"},
{Opt_wfdno, "wfdno=%u"}, {Opt_wfdno, "wfdno=%u"},
{Opt_debug, "debug=%x"},
{Opt_uname, "uname=%s"}, {Opt_uname, "uname=%s"},
{Opt_remotename, "aname=%s"}, {Opt_remotename, "aname=%s"},
{Opt_unix, "proto=unix"}, {Opt_unix, "proto=unix"},
{Opt_tcp, "proto=tcp"}, {Opt_tcp, "proto=tcp"},
{Opt_fd, "proto=fd"}, {Opt_fd, "proto=fd"},
#ifdef CONFIG_PCI_9P
{Opt_pci, "proto=pci"},
#endif
{Opt_tcp, "tcp"}, {Opt_tcp, "tcp"},
{Opt_unix, "unix"}, {Opt_unix, "unix"},
{Opt_fd, "fd"}, {Opt_fd, "fd"},
...@@ -83,6 +82,8 @@ static match_table_t tokens = { ...@@ -83,6 +82,8 @@ static match_table_t tokens = {
{Opt_err, NULL} {Opt_err, NULL}
}; };
extern struct p9_transport *p9pci_trans_create(void);
/* /*
* Parse option string. * Parse option string.
*/ */
...@@ -122,12 +123,16 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses) ...@@ -122,12 +123,16 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
token = match_token(p, tokens, args); token = match_token(p, tokens, args);
if (token < Opt_uname) { if (token < Opt_uname) {
if ((ret = match_int(&args[0], &option)) < 0) { if ((ret = match_int(&args[0], &option)) < 0) {
dprintk(DEBUG_ERROR, P9_DPRINTK(P9_DEBUG_ERROR,
"integer field, but no integer?\n"); "integer field, but no integer?\n");
continue; continue;
} }
} }
switch (token) { switch (token) {
case Opt_debug:
v9ses->debug = option;
p9_debug_level = option;
break;
case Opt_port: case Opt_port:
v9ses->port = option; v9ses->port = option;
break; break;
...@@ -149,15 +154,15 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses) ...@@ -149,15 +154,15 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
case Opt_wfdno: case Opt_wfdno:
v9ses->wfdno = option; v9ses->wfdno = option;
break; break;
case Opt_debug:
v9ses->debug = option;
break;
case Opt_tcp: case Opt_tcp:
v9ses->proto = PROTO_TCP; v9ses->proto = PROTO_TCP;
break; break;
case Opt_unix: case Opt_unix:
v9ses->proto = PROTO_UNIX; v9ses->proto = PROTO_UNIX;
break; break;
case Opt_pci:
v9ses->proto = PROTO_PCI;
break;
case Opt_fd: case Opt_fd:
v9ses->proto = PROTO_FD; v9ses->proto = PROTO_FD;
break; break;
...@@ -182,82 +187,6 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses) ...@@ -182,82 +187,6 @@ static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
} }
} }
/**
* v9fs_inode2v9ses - safely extract v9fs session info from super block
* @inode: inode to extract information from
*
* Paranoid function to extract v9ses information from superblock,
* if anything is missing it will report an error.
*
*/
struct v9fs_session_info *v9fs_inode2v9ses(struct inode *inode)
{
return (inode->i_sb->s_fs_info);
}
/**
* v9fs_get_idpool - 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 v9fs_get_idpool(struct v9fs_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) {
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;
}
/**
* v9fs_put_idpool - 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 v9fs_put_idpool(int id, struct v9fs_idpool *p)
{
if (down_interruptible(&p->lock) == -EINTR) {
eprintk(KERN_WARNING, "Interrupted while locking\n");
return;
}
idr_remove(&p->pool, id);
up(&p->lock);
}
/**
* v9fs_check_idpool - check if the specified id is available
* @id - id to check
* @p - pool
*/
int v9fs_check_idpool(int id, struct v9fs_idpool *p)
{
return idr_find(&p->pool, id) != NULL;
}
/** /**
* v9fs_session_init - initialize session * v9fs_session_init - initialize session
* @v9ses: session information structure * @v9ses: session information structure
...@@ -266,25 +195,21 @@ int v9fs_check_idpool(int id, struct v9fs_idpool *p) ...@@ -266,25 +195,21 @@ int v9fs_check_idpool(int id, struct v9fs_idpool *p)
* *
*/ */
int struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
v9fs_session_init(struct v9fs_session_info *v9ses,
const char *dev_name, char *data) const char *dev_name, char *data)
{ {
struct v9fs_fcall *fcall = NULL;
struct v9fs_transport *trans_proto;
int n = 0;
int newfid = -1;
int retval = -EINVAL; int retval = -EINVAL;
struct v9fs_str *version; struct p9_transport *trans;
struct p9_fid *fid;
v9ses->name = __getname(); v9ses->name = __getname();
if (!v9ses->name) if (!v9ses->name)
return -ENOMEM; return ERR_PTR(-ENOMEM);
v9ses->remotename = __getname(); v9ses->remotename = __getname();
if (!v9ses->remotename) { if (!v9ses->remotename) {
__putname(v9ses->name); __putname(v9ses->name);
return -ENOMEM; return ERR_PTR(-ENOMEM);
} }
strcpy(v9ses->name, V9FS_DEFUSER); strcpy(v9ses->name, V9FS_DEFUSER);
...@@ -292,130 +217,60 @@ v9fs_session_init(struct v9fs_session_info *v9ses, ...@@ -292,130 +217,60 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
v9fs_parse_options(data, v9ses); v9fs_parse_options(data, v9ses);
/* set global debug level */
v9fs_debug_level = v9ses->debug;
/* id pools that are session-dependent: fids and tags */
idr_init(&v9ses->fidpool.pool);
init_MUTEX(&v9ses->fidpool.lock);
switch (v9ses->proto) { switch (v9ses->proto) {
case PROTO_TCP: case PROTO_TCP:
trans_proto = &v9fs_trans_tcp; trans = p9_trans_create_tcp(dev_name, v9ses->port);
break; break;
case PROTO_UNIX: case PROTO_UNIX:
trans_proto = &v9fs_trans_unix; trans = p9_trans_create_unix(dev_name);
*v9ses->remotename = 0; *v9ses->remotename = 0;
break; break;
case PROTO_FD: case PROTO_FD:
trans_proto = &v9fs_trans_fd; trans = p9_trans_create_fd(v9ses->rfdno, v9ses->wfdno);
*v9ses->remotename = 0; *v9ses->remotename = 0;
break; break;
#ifdef CONFIG_PCI_9P
case PROTO_PCI:
trans = p9pci_trans_create();
*v9ses->remotename = 0;
break;
#endif
default: default:
printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto); printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto);
retval = -ENOPROTOOPT; retval = -ENOPROTOOPT;
goto SessCleanUp; goto error;
}; };
v9ses->transport = kmalloc(sizeof(*v9ses->transport), GFP_KERNEL); if (IS_ERR(trans)) {
if (!v9ses->transport) { retval = PTR_ERR(trans);
retval = -ENOMEM; trans = NULL;
goto SessCleanUp; goto error;
} }
memmove(v9ses->transport, trans_proto, sizeof(*v9ses->transport)); v9ses->clnt = p9_client_create(trans, v9ses->maxdata + P9_IOHDRSZ,
v9ses->extended);
if ((retval = v9ses->transport->init(v9ses, dev_name, data)) < 0) { if (IS_ERR(v9ses->clnt)) {
eprintk(KERN_ERR, "problem initializing transport\n"); retval = PTR_ERR(v9ses->clnt);
goto SessCleanUp; v9ses->clnt = NULL;
P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
goto error;
} }
v9ses->inprogress = 0; fid = p9_client_attach(v9ses->clnt, NULL, v9ses->name,
v9ses->shutdown = 0; v9ses->remotename);
v9ses->session_hung = 0; if (IS_ERR(fid)) {
retval = PTR_ERR(fid);
v9ses->mux = v9fs_mux_init(v9ses->transport, v9ses->maxdata + V9FS_IOHDRSZ, fid = NULL;
&v9ses->extended); P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
goto error;
if (IS_ERR(v9ses->mux)) {
retval = PTR_ERR(v9ses->mux);
v9ses->mux = NULL;
dprintk(DEBUG_ERROR, "problem initializing mux\n");
goto SessCleanUp;
} }
if (v9ses->afid == ~0) { return fid;
if (v9ses->extended)
retval =
v9fs_t_version(v9ses, v9ses->maxdata, "9P2000.u",
&fcall);
else
retval = v9fs_t_version(v9ses, v9ses->maxdata, "9P2000",
&fcall);
if (retval < 0) {
dprintk(DEBUG_ERROR, "v9fs_t_version failed\n");
goto FreeFcall;
}
version = &fcall->params.rversion.version;
if (version->len==8 && !memcmp(version->str, "9P2000.u", 8)) {
dprintk(DEBUG_9P, "9P2000 UNIX extensions enabled\n");
v9ses->extended = 1;
} else if (version->len==6 && !memcmp(version->str, "9P2000", 6)) {
dprintk(DEBUG_9P, "9P2000 legacy mode enabled\n");
v9ses->extended = 0;
} else {
retval = -EREMOTEIO;
goto FreeFcall;
}
n = fcall->params.rversion.msize; error:
kfree(fcall);
if (n < v9ses->maxdata)
v9ses->maxdata = n;
}
newfid = v9fs_get_idpool(&v9ses->fidpool);
if (newfid < 0) {
eprintk(KERN_WARNING, "couldn't allocate FID\n");
retval = -ENOMEM;
goto SessCleanUp;
}
/* it is a little bit ugly, but we have to prevent newfid */
/* being the same as afid, so if it is, get a new fid */
if (v9ses->afid != ~0 && newfid == v9ses->afid) {
newfid = v9fs_get_idpool(&v9ses->fidpool);
if (newfid < 0) {
eprintk(KERN_WARNING, "couldn't allocate FID\n");
retval = -ENOMEM;
goto SessCleanUp;
}
}
if ((retval =
v9fs_t_attach(v9ses, v9ses->name, v9ses->remotename, newfid,
v9ses->afid, NULL))
< 0) {
dprintk(DEBUG_ERROR, "cannot attach\n");
goto SessCleanUp;
}
if (v9ses->afid != ~0) {
dprintk(DEBUG_ERROR, "afid not equal to ~0\n");
if (v9fs_t_clunk(v9ses, v9ses->afid))
dprintk(DEBUG_ERROR, "clunk failed\n");
}
return newfid;
FreeFcall:
kfree(fcall);
SessCleanUp:
v9fs_session_close(v9ses); v9fs_session_close(v9ses);
return retval; return ERR_PTR(retval);
} }
/** /**
...@@ -426,15 +281,9 @@ v9fs_session_init(struct v9fs_session_info *v9ses, ...@@ -426,15 +281,9 @@ v9fs_session_init(struct v9fs_session_info *v9ses,
void v9fs_session_close(struct v9fs_session_info *v9ses) void v9fs_session_close(struct v9fs_session_info *v9ses)
{ {
if (v9ses->mux) { if (v9ses->clnt) {
v9fs_mux_destroy(v9ses->mux); p9_client_destroy(v9ses->clnt);
v9ses->mux = NULL; v9ses->clnt = NULL;
}
if (v9ses->transport) {
v9ses->transport->close(v9ses->transport);
kfree(v9ses->transport);
v9ses->transport = NULL;
} }
__putname(v9ses->name); __putname(v9ses->name);
...@@ -446,9 +295,8 @@ void v9fs_session_close(struct v9fs_session_info *v9ses) ...@@ -446,9 +295,8 @@ void v9fs_session_close(struct v9fs_session_info *v9ses)
* and cancel all pending requests. * and cancel all pending requests.
*/ */
void v9fs_session_cancel(struct v9fs_session_info *v9ses) { void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
dprintk(DEBUG_ERROR, "cancel session %p\n", v9ses); P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
v9ses->transport->status = Disconnected; p9_client_disconnect(v9ses->clnt);
v9fs_mux_cancel(v9ses->mux, -EIO);
} }
extern int v9fs_error_init(void); extern int v9fs_error_init(void);
...@@ -460,24 +308,9 @@ extern int v9fs_error_init(void); ...@@ -460,24 +308,9 @@ extern int v9fs_error_init(void);
static int __init init_v9fs(void) static int __init init_v9fs(void)
{ {
int ret;
v9fs_error_init();
printk(KERN_INFO "Installing v9fs 9p2000 file system support\n"); printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
ret = v9fs_mux_global_init(); return register_filesystem(&v9fs_fs_type);
if (ret) {
printk(KERN_WARNING "v9fs: starting mux failed\n");
return ret;
}
ret = register_filesystem(&v9fs_fs_type);
if (ret) {
printk(KERN_WARNING "v9fs: registering file system failed\n");
v9fs_mux_global_exit();
}
return ret;
} }
/** /**
...@@ -487,13 +320,13 @@ static int __init init_v9fs(void) ...@@ -487,13 +320,13 @@ static int __init init_v9fs(void)
static void __exit exit_v9fs(void) static void __exit exit_v9fs(void)
{ {
v9fs_mux_global_exit();
unregister_filesystem(&v9fs_fs_type); unregister_filesystem(&v9fs_fs_type);
} }
module_init(init_v9fs) module_init(init_v9fs)
module_exit(exit_v9fs) module_exit(exit_v9fs)
MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>"); MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>"); MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -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,40 @@ static const struct file_operations v9fs_cached_file_operations; ...@@ -52,48 +52,40 @@ 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 (err < 0) { if (!fid) {
PRINT_FCALL_ERROR("open failed", fcall); fid = v9fs_fid_clone(file->f_path.dentry);
goto Clunk_Fid; if (IS_ERR(fid))
return PTR_ERR(fid);
err = p9_client_open(fid, omode);
if (err < 0) {
p9_client_clunk(fid);
return err;
}
if (omode & P9_OTRUNC) {
inode->i_size = 0;
inode->i_blocks = 0;
}
} }
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 +102,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl) ...@@ -110,7 +102,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 +128,16 @@ static ssize_t ...@@ -136,55 +128,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 +153,25 @@ static ssize_t ...@@ -200,50 +153,25 @@ 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)
{ {
int ret;
struct p9_fid *fid;
struct inode *inode = filp->f_path.dentry->d_inode; struct inode *inode = filp->f_path.dentry->d_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
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); fid = filp->private_data;
fcall = NULL; ret = p9_client_uwrite(fid, data, *offset, count);
if (ret > 0)
*offset += ret;
if (result != rsize) { if (*offset > inode->i_size) {
eprintk(KERN_ERR, inode->i_size = *offset;
"short write: v9fs_t_write returned %d\n", inode->i_blocks = (inode->i_size + 512 - 1) >> 9;
result); }
break;
}
count -= result;
data += result;
total += result;
} while (count);
invalidate_inode_pages2(inode->i_mapping); invalidate_inode_pages2(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 = {
......
...@@ -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"
...@@ -58,27 +58,27 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) ...@@ -58,27 +58,27 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
int res; int res;
res = mode & 0777; res = mode & 0777;
if (S_ISDIR(mode)) if (S_ISDIR(mode))
res |= V9FS_DMDIR; res |= P9_DMDIR;
if (v9ses->extended) { if (v9ses->extended) {
if (S_ISLNK(mode)) if (S_ISLNK(mode))
res |= V9FS_DMSYMLINK; res |= P9_DMSYMLINK;
if (v9ses->nodev == 0) { if (v9ses->nodev == 0) {
if (S_ISSOCK(mode)) if (S_ISSOCK(mode))
res |= V9FS_DMSOCKET; res |= P9_DMSOCKET;
if (S_ISFIFO(mode)) if (S_ISFIFO(mode))
res |= V9FS_DMNAMEDPIPE; res |= P9_DMNAMEDPIPE;
if (S_ISBLK(mode)) if (S_ISBLK(mode))
res |= V9FS_DMDEVICE; res |= P9_DMDEVICE;
if (S_ISCHR(mode)) if (S_ISCHR(mode))
res |= V9FS_DMDEVICE; res |= P9_DMDEVICE;
} }
if ((mode & S_ISUID) == S_ISUID) if ((mode & S_ISUID) == S_ISUID)
res |= V9FS_DMSETUID; res |= P9_DMSETUID;
if ((mode & S_ISGID) == S_ISGID) if ((mode & S_ISGID) == S_ISGID)
res |= V9FS_DMSETGID; res |= P9_DMSETGID;
if ((mode & V9FS_DMLINK)) if ((mode & P9_DMLINK))
res |= V9FS_DMLINK; res |= P9_DMLINK;
} }
return res; return res;
...@@ -97,27 +97,27 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) ...@@ -97,27 +97,27 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
res = mode & 0777; res = mode & 0777;
if ((mode & V9FS_DMDIR) == V9FS_DMDIR) if ((mode & P9_DMDIR) == P9_DMDIR)
res |= S_IFDIR; res |= S_IFDIR;
else if ((mode & V9FS_DMSYMLINK) && (v9ses->extended)) else if ((mode & P9_DMSYMLINK) && (v9ses->extended))
res |= S_IFLNK; res |= S_IFLNK;
else if ((mode & V9FS_DMSOCKET) && (v9ses->extended) else if ((mode & P9_DMSOCKET) && (v9ses->extended)
&& (v9ses->nodev == 0)) && (v9ses->nodev == 0))
res |= S_IFSOCK; res |= S_IFSOCK;
else if ((mode & V9FS_DMNAMEDPIPE) && (v9ses->extended) else if ((mode & P9_DMNAMEDPIPE) && (v9ses->extended)
&& (v9ses->nodev == 0)) && (v9ses->nodev == 0))
res |= S_IFIFO; res |= S_IFIFO;
else if ((mode & V9FS_DMDEVICE) && (v9ses->extended) else if ((mode & P9_DMDEVICE) && (v9ses->extended)
&& (v9ses->nodev == 0)) && (v9ses->nodev == 0))
res |= S_IFBLK; res |= S_IFBLK;
else else
res |= S_IFREG; res |= S_IFREG;
if (v9ses->extended) { if (v9ses->extended) {
if ((mode & V9FS_DMSETUID) == V9FS_DMSETUID) if ((mode & P9_DMSETUID) == P9_DMSETUID)
res |= S_ISUID; res |= S_ISUID;
if ((mode & V9FS_DMSETGID) == V9FS_DMSETGID) if ((mode & P9_DMSETGID) == P9_DMSETGID)
res |= S_ISGID; res |= S_ISGID;
} }
...@@ -132,26 +132,26 @@ int v9fs_uflags2omode(int uflags) ...@@ -132,26 +132,26 @@ int v9fs_uflags2omode(int uflags)
switch (uflags&3) { switch (uflags&3) {
default: default:
case O_RDONLY: case O_RDONLY:
ret = V9FS_OREAD; ret = P9_OREAD;
break; break;
case O_WRONLY: case O_WRONLY:
ret = V9FS_OWRITE; ret = P9_OWRITE;
break; break;
case O_RDWR: case O_RDWR:
ret = V9FS_ORDWR; ret = P9_ORDWR;
break; break;
} }
if (uflags & O_EXCL) if (uflags & O_EXCL)
ret |= V9FS_OEXCL; ret |= P9_OEXCL;
if (uflags & O_TRUNC) if (uflags & O_TRUNC)
ret |= V9FS_OTRUNC; ret |= P9_OTRUNC;
if (uflags & O_APPEND) if (uflags & O_APPEND)
ret |= V9FS_OAPPEND; ret |= P9_OAPPEND;
return ret; return ret;
} }
...@@ -164,7 +164,7 @@ int v9fs_uflags2omode(int uflags) ...@@ -164,7 +164,7 @@ int v9fs_uflags2omode(int uflags)
*/ */
static void static void
v9fs_blank_wstat(struct v9fs_wstat *wstat) v9fs_blank_wstat(struct p9_wstat *wstat)
{ {
wstat->type = ~0; wstat->type = ~0;
wstat->dev = ~0; wstat->dev = ~0;
...@@ -197,7 +197,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) ...@@ -197,7 +197,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
struct inode *inode; struct inode *inode;
struct v9fs_session_info *v9ses = sb->s_fs_info; struct v9fs_session_info *v9ses = sb->s_fs_info;
dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode); P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
inode = new_inode(sb); inode = new_inode(sb);
if (inode) { if (inode) {
...@@ -215,7 +215,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) ...@@ -215,7 +215,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
case S_IFCHR: case S_IFCHR:
case S_IFSOCK: case S_IFSOCK:
if(!v9ses->extended) { if(!v9ses->extended) {
dprintk(DEBUG_ERROR, "special files without extended mode\n"); P9_DPRINTK(P9_DEBUG_ERROR,
"special files without extended mode\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
init_special_inode(inode, inode->i_mode, init_special_inode(inode, inode->i_mode,
...@@ -227,7 +228,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) ...@@ -227,7 +228,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
break; break;
case S_IFLNK: case S_IFLNK:
if(!v9ses->extended) { if(!v9ses->extended) {
dprintk(DEBUG_ERROR, "extended modes used w/o 9P2000.u\n"); P9_DPRINTK(P9_DEBUG_ERROR,
"extended modes used w/o 9P2000.u\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
inode->i_op = &v9fs_symlink_inode_operations; inode->i_op = &v9fs_symlink_inode_operations;
...@@ -241,71 +243,19 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) ...@@ -241,71 +243,19 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
inode->i_fop = &v9fs_dir_operations; inode->i_fop = &v9fs_dir_operations;
break; break;
default: default:
dprintk(DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n", P9_DPRINTK(P9_DEBUG_ERROR,
"BAD mode 0x%x S_IFMT 0x%x\n",
mode, mode & S_IFMT); mode, mode & S_IFMT);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
} else { } else {
eprintk(KERN_WARNING, "Problem allocating inode\n"); P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
return inode; return inode;
} }
static int /*
v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name, u32 perm,
u8 mode, char *extension, u32 *fidp, struct v9fs_qid *qid, u32 *iounit)
{
int fid;
int err;
struct v9fs_fcall *fcall;
fid = v9fs_get_idpool(&v9ses->fidpool);
if (fid < 0) {
eprintk(KERN_WARNING, "no free fids available\n");
return -ENOSPC;
}
err = v9fs_t_walk(v9ses, pfid, fid, NULL, &fcall);
if (err < 0) {
PRINT_FCALL_ERROR("clone error", fcall);
if (fcall && fcall->id == RWALK)
goto clunk_fid;
else
goto put_fid;
}
kfree(fcall);
err = v9fs_t_create(v9ses, fid, name, perm, mode, extension, &fcall);
if (err < 0) {
PRINT_FCALL_ERROR("create fails", fcall);
goto clunk_fid;
}
if (iounit)
*iounit = fcall->params.rcreate.iounit;
if (qid)
*qid = fcall->params.rcreate.qid;
if (fidp)
*fidp = fid;
kfree(fcall);
return 0;
clunk_fid:
v9fs_t_clunk(v9ses, fid);
fid = V9FS_NOFID;
put_fid:
if (fid != V9FS_NOFID)
v9fs_put_idpool(fid, &v9ses->fidpool);
kfree(fcall);
return err;
}
static struct v9fs_fid* static struct v9fs_fid*
v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
{ {
...@@ -355,23 +305,25 @@ v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) ...@@ -355,23 +305,25 @@ v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
kfree(fcall); kfree(fcall);
return ERR_PTR(err); return ERR_PTR(err);
} }
*/
static struct inode * static struct inode *
v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid, v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
struct super_block *sb) struct super_block *sb)
{ {
int err, umode; int err, umode;
struct inode *ret; struct inode *ret;
struct v9fs_fcall *fcall; struct p9_stat *st;
ret = NULL; ret = NULL;
err = v9fs_t_stat(v9ses, fid, &fcall); st = p9_client_stat(fid);
if (err) { if (IS_ERR(st)) {
PRINT_FCALL_ERROR("stat error", fcall); err = PTR_ERR(st);
st = NULL;
goto error; goto error;
} }
umode = p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode); umode = p9mode2unixmode(v9ses, st->mode);
ret = v9fs_get_inode(sb, umode); ret = v9fs_get_inode(sb, umode);
if (IS_ERR(ret)) { if (IS_ERR(ret)) {
err = PTR_ERR(ret); err = PTR_ERR(ret);
...@@ -379,12 +331,13 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid, ...@@ -379,12 +331,13 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid,
goto error; goto error;
} }
v9fs_stat2inode(&fcall->params.rstat.stat, ret, sb); v9fs_stat2inode(st, ret, sb);
kfree(fcall); ret->i_ino = v9fs_qid2ino(&st->qid);
kfree(st);
return ret; return ret;
error: error:
kfree(fcall); kfree(st);
if (ret) if (ret)
iput(ret); iput(ret);
...@@ -401,43 +354,20 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid, ...@@ -401,43 +354,20 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid,
static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
{ {
struct v9fs_fcall *fcall = NULL; struct inode *file_inode;
struct super_block *sb = NULL; struct v9fs_session_info *v9ses;
struct v9fs_session_info *v9ses = NULL; struct p9_fid *v9fid;
struct v9fs_fid *v9fid = NULL;
struct inode *file_inode = NULL;
int fid = -1;
int result = 0;
dprintk(DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file, P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
rmdir); rmdir);
file_inode = file->d_inode; file_inode = file->d_inode;
sb = file_inode->i_sb;
v9ses = v9fs_inode2v9ses(file_inode); v9ses = v9fs_inode2v9ses(file_inode);
v9fid = v9fs_fid_clone(file); v9fid = v9fs_fid_clone(file);
if(IS_ERR(v9fid)) if(IS_ERR(v9fid))
return PTR_ERR(v9fid); return PTR_ERR(v9fid);
fid = v9fid->fid; return p9_client_remove(v9fid);
if (fid < 0) {
dprintk(DEBUG_ERROR, "inode #%lu, no fid!\n",
file_inode->i_ino);
return -EBADF;
}
result = v9fs_t_remove(v9ses, fid, &fcall);
if (result < 0) {
PRINT_FCALL_ERROR("remove fails", fcall);
goto Error;
}
v9fs_put_idpool(fid, &v9ses->fidpool);
v9fs_fid_destroy(v9fid);
Error:
kfree(fcall);
return result;
} }
static int static int
...@@ -446,61 +376,59 @@ v9fs_open_created(struct inode *inode, struct file *file) ...@@ -446,61 +376,59 @@ v9fs_open_created(struct inode *inode, struct file *file)
return 0; return 0;
} }
/** /**
* v9fs_vfs_create - VFS hook to create files * v9fs_create - Create a file
* @inode: directory inode that is being deleted * @dentry: dentry that is being created
* @dentry: dentry that is being deleted * @perm: create permissions
* @mode: create permissions * @mode: open mode
* @nd: path information
* *
*/ */
static struct p9_fid *
static int v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, struct dentry *dentry, char *extension, u32 perm, u8 mode)
struct nameidata *nd)
{ {
int err; int err;
u32 fid, perm, iounit; char *name;
int flags; struct p9_fid *dfid, *ofid, *fid;
struct v9fs_session_info *v9ses;
struct v9fs_fid *dfid, *vfid, *ffid;
struct inode *inode; struct inode *inode;
struct v9fs_qid qid;
struct file *filp;
inode = NULL; err = 0;
vfid = NULL; ofid = NULL;
v9ses = v9fs_inode2v9ses(dir); fid = NULL;
name = (char *) dentry->d_name.name;
dfid = v9fs_fid_clone(dentry->d_parent); dfid = v9fs_fid_clone(dentry->d_parent);
if(IS_ERR(dfid)) { if(IS_ERR(dfid)) {
err = PTR_ERR(dfid); err = PTR_ERR(dfid);
dfid = NULL;
goto error; goto error;
} }
perm = unixmode2p9mode(v9ses, mode); /* clone a fid to use for creation */
if (nd && nd->flags & LOOKUP_OPEN) ofid = p9_client_walk(dfid, 0, NULL, 1);
flags = nd->intent.open.flags - 1; if (IS_ERR(ofid)) {
else err = PTR_ERR(ofid);
flags = O_RDWR; ofid = NULL;
goto error;
err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name, }
perm, v9fs_uflags2omode(flags), NULL, &fid, &qid, &iounit);
if (err) err = p9_client_fcreate(ofid, name, perm, mode, extension);
goto clunk_dfid; if (err < 0)
goto error;
vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry); /* now walk from the parent so we can get unopened fid */
v9fs_fid_clunk(v9ses, dfid); fid = p9_client_walk(dfid, 1, &name, 0);
if (IS_ERR(vfid)) { if (IS_ERR(fid)) {
err = PTR_ERR(vfid); err = PTR_ERR(fid);
vfid = NULL; fid = NULL;
goto error; goto error;
} } else
dfid = NULL;
inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb); /* instantiate inode and assign the unopened fid to the dentry */
inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
err = PTR_ERR(inode); err = PTR_ERR(inode);
inode = NULL;
goto error; goto error;
} }
...@@ -508,35 +436,78 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, ...@@ -508,35 +436,78 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
dentry->d_op = &v9fs_cached_dentry_operations; dentry->d_op = &v9fs_cached_dentry_operations;
else else
dentry->d_op = &v9fs_dentry_operations; dentry->d_op = &v9fs_dentry_operations;
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
v9fs_fid_add(dentry, fid);
return ofid;
if (nd && nd->flags & LOOKUP_OPEN) { error:
ffid = v9fs_fid_create(v9ses, fid); if (dfid)
if (!ffid) p9_client_clunk(dfid);
return -ENOMEM;
if (ofid)
p9_client_clunk(ofid);
if (fid)
p9_client_clunk(fid);
return ERR_PTR(err);
}
/**
* v9fs_vfs_create - VFS hook to create files
* @inode: directory inode that is being created
* @dentry: dentry that is being deleted
* @mode: create permissions
* @nd: path information
*
*/
static int
v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
struct nameidata *nd)
{
int err;
u32 perm;
int flags;
struct v9fs_session_info *v9ses;
struct p9_fid *fid;
struct file *filp;
err = 0;
fid = NULL;
v9ses = v9fs_inode2v9ses(dir);
perm = unixmode2p9mode(v9ses, mode);
if (nd && nd->flags & LOOKUP_OPEN)
flags = nd->intent.open.flags - 1;
else
flags = O_RDWR;
fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
v9fs_uflags2omode(flags));
if (IS_ERR(fid)) {
err = PTR_ERR(fid);
fid = NULL;
goto error;
}
/* if we are opening a file, assign the open fid to the file */
if (nd && nd->flags & LOOKUP_OPEN) {
filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
v9fs_fid_destroy(ffid); err = PTR_ERR(filp);
return PTR_ERR(filp); goto error;
} }
ffid->rdir_pos = 0; filp->private_data = fid;
ffid->rdir_fcall = NULL; } else
ffid->fidopen = 1; p9_client_clunk(fid);
ffid->iounit = iounit;
ffid->filp = filp;
filp->private_data = ffid;
}
return 0; return 0;
clunk_dfid:
v9fs_fid_clunk(v9ses, dfid);
error: error:
if (vfid) if (fid)
v9fs_fid_destroy(vfid); p9_client_clunk(fid);
return err; return err;
} }
...@@ -552,57 +523,23 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, ...@@ -552,57 +523,23 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
{ {
int err; int err;
u32 fid, perm; u32 perm;
struct v9fs_session_info *v9ses; struct v9fs_session_info *v9ses;
struct v9fs_fid *dfid, *vfid; struct p9_fid *fid;
struct inode *inode;
inode = NULL; P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
vfid = NULL; err = 0;
v9ses = v9fs_inode2v9ses(dir); v9ses = v9fs_inode2v9ses(dir);
dfid = v9fs_fid_clone(dentry->d_parent);
if(IS_ERR(dfid)) {
err = PTR_ERR(dfid);
goto error;
}
perm = unixmode2p9mode(v9ses, mode | S_IFDIR); perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name, if (IS_ERR(fid)) {
perm, V9FS_OREAD, NULL, &fid, NULL, NULL); err = PTR_ERR(fid);
fid = NULL;
if (err) {
dprintk(DEBUG_ERROR, "create error %d\n", err);
goto clean_up_dfid;
} }
vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry); if (fid)
if (IS_ERR(vfid)) { p9_client_clunk(fid);
err = PTR_ERR(vfid);
vfid = NULL;
goto clean_up_dfid;
}
v9fs_fid_clunk(v9ses, dfid);
inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
inode = NULL;
v9fs_fid_destroy(vfid);
goto error;
}
if(v9ses->cache)
dentry->d_op = &v9fs_cached_dentry_operations;
else
dentry->d_op = &v9fs_dentry_operations;
d_instantiate(dentry, inode);
return 0;
clean_up_dfid:
v9fs_fid_clunk(v9ses, dfid);
error:
return err; return err;
} }
...@@ -619,104 +556,54 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -619,104 +556,54 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
{ {
struct super_block *sb; struct super_block *sb;
struct v9fs_session_info *v9ses; struct v9fs_session_info *v9ses;
struct v9fs_fid *dirfid; struct p9_fid *dfid, *fid;
struct v9fs_fid *fid;
struct inode *inode; struct inode *inode;
struct v9fs_fcall *fcall = NULL; char *name;
int dirfidnum = -1;
int newfid = -1;
int result = 0; int result = 0;
dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n", P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
dir, dentry->d_name.name, dentry, nameidata); dir, dentry->d_name.name, dentry, nameidata);
sb = dir->i_sb; sb = dir->i_sb;
v9ses = v9fs_inode2v9ses(dir); v9ses = v9fs_inode2v9ses(dir);
dirfid = v9fs_fid_lookup(dentry->d_parent); dfid = v9fs_fid_lookup(dentry->d_parent);
if (IS_ERR(dfid))
if(IS_ERR(dirfid)) return ERR_PTR(PTR_ERR(dfid));
return ERR_PTR(PTR_ERR(dirfid));
name = (char *) dentry->d_name.name;
dirfidnum = dirfid->fid; fid = p9_client_walk(dfid, 1, &name, 1);
if (IS_ERR(fid)) {
newfid = v9fs_get_idpool(&v9ses->fidpool); result = PTR_ERR(fid);
if (newfid < 0) {
eprintk(KERN_WARNING, "newfid fails!\n");
result = -ENOSPC;
goto Release_Dirfid;
}
result = v9fs_t_walk(v9ses, dirfidnum, newfid,
(char *)dentry->d_name.name, &fcall);
up(&dirfid->lock);
if (result < 0) {
if (fcall && fcall->id == RWALK)
v9fs_t_clunk(v9ses, newfid);
else
v9fs_put_idpool(newfid, &v9ses->fidpool);
if (result == -ENOENT) { if (result == -ENOENT) {
d_add(dentry, NULL); d_add(dentry, NULL);
dprintk(DEBUG_VFS,
"Return negative dentry %p count %d\n",
dentry, atomic_read(&dentry->d_count));
kfree(fcall);
return NULL; return NULL;
} }
dprintk(DEBUG_ERROR, "walk error:%d\n", result);
goto FreeFcall;
}
kfree(fcall);
result = v9fs_t_stat(v9ses, newfid, &fcall);
if (result < 0) {
dprintk(DEBUG_ERROR, "stat error\n");
goto FreeFcall;
}
inode = v9fs_get_inode(sb, p9mode2unixmode(v9ses,
fcall->params.rstat.stat.mode));
if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) { return ERR_PTR(result);
eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n",
PTR_ERR(inode));
result = -ENOSPC;
goto FreeFcall;
} }
inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid); inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
if (IS_ERR(inode)) {
fid = v9fs_fid_create(v9ses, newfid); result = PTR_ERR(inode);
if (fid == NULL) { inode = NULL;
dprintk(DEBUG_ERROR, "couldn't insert\n"); goto error;
result = -ENOMEM;
goto FreeFcall;
} }
result = v9fs_fid_insert(fid, dentry); result = v9fs_fid_add(dentry, fid);
if (result < 0) if (result < 0)
goto FreeFcall; goto error;
fid->qid = fcall->params.rstat.stat.qid;
v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb);
if((fid->qid.version)&&(v9ses->cache)) if((fid->qid.version)&&(v9ses->cache))
dentry->d_op = &v9fs_cached_dentry_operations; dentry->d_op = &v9fs_cached_dentry_operations;
else else
dentry->d_op = &v9fs_dentry_operations; dentry->d_op = &v9fs_dentry_operations;
d_add(dentry, inode); d_add(dentry, inode);
kfree(fcall);
return NULL; return NULL;
Release_Dirfid: error:
up(&dirfid->lock); if (fid)
p9_client_clunk(fid);
FreeFcall:
kfree(fcall);
return ERR_PTR(result); return ERR_PTR(result);
} }
...@@ -758,73 +645,54 @@ static int ...@@ -758,73 +645,54 @@ static int
v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry) struct inode *new_dir, struct dentry *new_dentry)
{ {
struct inode *old_inode = old_dentry->d_inode; struct inode *old_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode); struct v9fs_session_info *v9ses;
struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry); struct p9_fid *oldfid;
struct v9fs_fid *olddirfid; struct p9_fid *olddirfid;
struct v9fs_fid *newdirfid; struct p9_fid *newdirfid;
struct v9fs_wstat wstat; struct p9_wstat wstat;
struct v9fs_fcall *fcall = NULL; int retval;
int fid = -1;
int olddirfidnum = -1;
int newdirfidnum = -1;
int retval = 0;
dprintk(DEBUG_VFS, "\n");
P9_DPRINTK(P9_DEBUG_VFS, "\n");
retval = 0;
old_inode = old_dentry->d_inode;
v9ses = v9fs_inode2v9ses(old_inode);
oldfid = v9fs_fid_lookup(old_dentry);
if(IS_ERR(oldfid)) if(IS_ERR(oldfid))
return PTR_ERR(oldfid); return PTR_ERR(oldfid);
olddirfid = v9fs_fid_clone(old_dentry->d_parent); olddirfid = v9fs_fid_clone(old_dentry->d_parent);
if(IS_ERR(olddirfid)) { if(IS_ERR(olddirfid)) {
retval = PTR_ERR(olddirfid); retval = PTR_ERR(olddirfid);
goto Release_lock; goto done;
} }
newdirfid = v9fs_fid_clone(new_dentry->d_parent); newdirfid = v9fs_fid_clone(new_dentry->d_parent);
if(IS_ERR(newdirfid)) { if(IS_ERR(newdirfid)) {
retval = PTR_ERR(newdirfid); retval = PTR_ERR(newdirfid);
goto Clunk_olddir; goto clunk_olddir;
} }
/* 9P can only handle file rename in the same directory */ /* 9P can only handle file rename in the same directory */
if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) { if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
dprintk(DEBUG_ERROR, "old dir and new dir are different\n"); P9_DPRINTK(P9_DEBUG_ERROR,
"old dir and new dir are different\n");
retval = -EXDEV; retval = -EXDEV;
goto Clunk_newdir; goto clunk_newdir;
}
fid = oldfid->fid;
olddirfidnum = olddirfid->fid;
newdirfidnum = newdirfid->fid;
if (fid < 0) {
dprintk(DEBUG_ERROR, "no fid for old file #%lu\n",
old_inode->i_ino);
retval = -EBADF;
goto Clunk_newdir;
} }
v9fs_blank_wstat(&wstat); v9fs_blank_wstat(&wstat);
wstat.muid = v9ses->name; wstat.muid = v9ses->name;
wstat.name = (char *) new_dentry->d_name.name; wstat.name = (char *) new_dentry->d_name.name;
retval = p9_client_wstat(oldfid, &wstat);
retval = v9fs_t_wstat(v9ses, fid, &wstat, &fcall); clunk_newdir:
p9_client_clunk(olddirfid);
if (retval < 0) clunk_olddir:
PRINT_FCALL_ERROR("wstat error", fcall); p9_client_clunk(newdirfid);
kfree(fcall);
Clunk_newdir:
v9fs_fid_clunk(v9ses, newdirfid);
Clunk_olddir:
v9fs_fid_clunk(v9ses, olddirfid);
Release_lock:
up(&oldfid->lock);
done:
return retval; return retval;
} }
...@@ -840,28 +708,30 @@ static int ...@@ -840,28 +708,30 @@ static int
v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat) struct kstat *stat)
{ {
struct v9fs_fcall *fcall = NULL; int err;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); struct v9fs_session_info *v9ses;
struct v9fs_fid *fid = v9fs_fid_clone(dentry); struct p9_fid *fid;
int err = -EPERM; struct p9_stat *st;
dprintk(DEBUG_VFS, "dentry: %p\n", dentry); P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
if(IS_ERR(fid)) err = -EPERM;
v9ses = v9fs_inode2v9ses(dentry->d_inode);
if (v9ses->cache == CACHE_LOOSE)
return simple_getattr(mnt, dentry, stat);
fid = v9fs_fid_lookup(dentry);
if (IS_ERR(fid))
return PTR_ERR(fid); return PTR_ERR(fid);
err = v9fs_t_stat(v9ses, fid->fid, &fcall); st = p9_client_stat(fid);
if (IS_ERR(st))
return PTR_ERR(st);
if (err < 0) v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb);
dprintk(DEBUG_ERROR, "stat error\n");
else {
v9fs_stat2inode(&fcall->params.rstat.stat, dentry->d_inode,
dentry->d_inode->i_sb);
generic_fillattr(dentry->d_inode, stat); generic_fillattr(dentry->d_inode, stat);
}
kfree(fcall); kfree(st);
v9fs_fid_clunk(v9ses, fid); return 0;
return err;
} }
/** /**
...@@ -873,13 +743,15 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -873,13 +743,15 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
{ {
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); int retval;
struct v9fs_fid *fid = v9fs_fid_clone(dentry); struct v9fs_session_info *v9ses;
struct v9fs_fcall *fcall = NULL; struct p9_fid *fid;
struct v9fs_wstat wstat; struct p9_wstat wstat;
int res = -EPERM;
dprintk(DEBUG_VFS, "\n"); P9_DPRINTK(P9_DEBUG_VFS, "\n");
retval = -EPERM;
v9ses = v9fs_inode2v9ses(dentry->d_inode);
fid = v9fs_fid_lookup(dentry);
if(IS_ERR(fid)) if(IS_ERR(fid))
return PTR_ERR(fid); return PTR_ERR(fid);
...@@ -904,17 +776,11 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) ...@@ -904,17 +776,11 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
wstat.n_gid = iattr->ia_gid; wstat.n_gid = iattr->ia_gid;
} }
res = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall); retval = p9_client_wstat(fid, &wstat);
if (retval >= 0)
retval = inode_setattr(dentry->d_inode, iattr);
if (res < 0) return retval;
PRINT_FCALL_ERROR("wstat error", fcall);
kfree(fcall);
if (res >= 0)
res = inode_setattr(dentry->d_inode, iattr);
v9fs_fid_clunk(v9ses, fid);
return res;
} }
/** /**
...@@ -926,7 +792,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) ...@@ -926,7 +792,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
*/ */
void void
v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, v9fs_stat2inode(struct p9_stat *stat, struct inode *inode,
struct super_block *sb) struct super_block *sb)
{ {
int n; int n;
...@@ -967,8 +833,9 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, ...@@ -967,8 +833,9 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode,
case 'b': case 'b':
break; break;
default: default:
dprintk(DEBUG_ERROR, "Unknown special type %c (%.*s)\n", P9_DPRINTK(P9_DEBUG_ERROR,
type, stat->extension.len, stat->extension.str); "Unknown special type %c (%.*s)\n", type,
stat->extension.len, stat->extension.str);
}; };
inode->i_rdev = MKDEV(major, minor); inode->i_rdev = MKDEV(major, minor);
} else } else
...@@ -976,8 +843,8 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, ...@@ -976,8 +843,8 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode,
inode->i_size = stat->length; inode->i_size = stat->length;
inode->i_blocks = /* not real number of blocks, but 512 byte ones ... */
(inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits; inode->i_blocks = (inode->i_size + 512 - 1) >> 9;
} }
/** /**
...@@ -987,7 +854,7 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, ...@@ -987,7 +854,7 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode,
* BUG: potential for inode number collisions? * BUG: potential for inode number collisions?
*/ */
ino_t v9fs_qid2ino(struct v9fs_qid *qid) ino_t v9fs_qid2ino(struct p9_qid *qid)
{ {
u64 path = qid->path + 2; u64 path = qid->path + 2;
ino_t i = 0; ino_t i = 0;
...@@ -1010,56 +877,46 @@ ino_t v9fs_qid2ino(struct v9fs_qid *qid) ...@@ -1010,56 +877,46 @@ ino_t v9fs_qid2ino(struct v9fs_qid *qid)
static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
{ {
int retval = -EPERM; int retval;
struct v9fs_fcall *fcall = NULL; struct v9fs_session_info *v9ses;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); struct p9_fid *fid;
struct v9fs_fid *fid = v9fs_fid_clone(dentry); struct p9_stat *st;
P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
retval = -EPERM;
v9ses = v9fs_inode2v9ses(dentry->d_inode);
fid = v9fs_fid_lookup(dentry);
if(IS_ERR(fid)) if(IS_ERR(fid))
return PTR_ERR(fid); return PTR_ERR(fid);
if (!v9ses->extended) { if (!v9ses->extended)
retval = -EBADF; return -EBADF;
dprintk(DEBUG_ERROR, "not extended\n");
goto ClunkFid;
}
dprintk(DEBUG_VFS, " %s\n", dentry->d_name.name);
retval = v9fs_t_stat(v9ses, fid->fid, &fcall);
if (retval < 0) {
dprintk(DEBUG_ERROR, "stat error\n");
goto FreeFcall;
}
if (!fcall) { st = p9_client_stat(fid);
retval = -EIO; if (IS_ERR(st))
goto ClunkFid; return PTR_ERR(st);
}
if (!(fcall->params.rstat.stat.mode & V9FS_DMSYMLINK)) { if (!(st->mode & P9_DMSYMLINK)) {
retval = -EINVAL; retval = -EINVAL;
goto FreeFcall; goto done;
} }
/* copy extension buffer into buffer */ /* copy extension buffer into buffer */
if (fcall->params.rstat.stat.extension.len < buflen) if (st->extension.len < buflen)
buflen = fcall->params.rstat.stat.extension.len + 1; buflen = st->extension.len + 1;
memmove(buffer, fcall->params.rstat.stat.extension.str, buflen - 1); memmove(buffer, st->extension.str, buflen - 1);
buffer[buflen-1] = 0; buffer[buflen-1] = 0;
dprintk(DEBUG_ERROR, "%s -> %.*s (%s)\n", dentry->d_name.name, fcall->params.rstat.stat.extension.len, P9_DPRINTK(P9_DEBUG_VFS,
fcall->params.rstat.stat.extension.str, buffer); "%s -> %.*s (%s)\n", dentry->d_name.name, st->extension.len,
retval = buflen; st->extension.str, buffer);
FreeFcall: retval = buflen;
kfree(fcall);
ClunkFid:
v9fs_fid_clunk(v9ses, fid);
done:
kfree(st);
return retval; return retval;
} }
...@@ -1084,14 +941,14 @@ static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer, ...@@ -1084,14 +941,14 @@ static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
if (buflen > PATH_MAX) if (buflen > PATH_MAX)
buflen = PATH_MAX; buflen = PATH_MAX;
dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
retval = v9fs_readlink(dentry, link, buflen); retval = v9fs_readlink(dentry, link, buflen);
if (retval > 0) { if (retval > 0) {
if ((ret = copy_to_user(buffer, link, retval)) != 0) { if ((ret = copy_to_user(buffer, link, retval)) != 0) {
dprintk(DEBUG_ERROR, "problem copying to user: %d\n", P9_DPRINTK(P9_DEBUG_ERROR,
ret); "problem copying to user: %d\n", ret);
retval = ret; retval = ret;
} }
} }
...@@ -1112,7 +969,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) ...@@ -1112,7 +969,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
int len = 0; int len = 0;
char *link = __getname(); char *link = __getname();
dprintk(DEBUG_VFS, "%s n", dentry->d_name.name); P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
if (!link) if (!link)
link = ERR_PTR(-ENOMEM); link = ERR_PTR(-ENOMEM);
...@@ -1141,7 +998,7 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void ...@@ -1141,7 +998,7 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void
{ {
char *s = nd_get_link(nd); char *s = nd_get_link(nd);
dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s); P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
if (!IS_ERR(s)) if (!IS_ERR(s))
__putname(s); __putname(s);
} }
...@@ -1149,66 +1006,24 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void ...@@ -1149,66 +1006,24 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void
static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
int mode, const char *extension) int mode, const char *extension)
{ {
int err; u32 perm;
u32 fid, perm;
struct v9fs_session_info *v9ses; struct v9fs_session_info *v9ses;
struct v9fs_fid *dfid, *vfid = NULL; struct p9_fid *fid;
struct inode *inode = NULL;
v9ses = v9fs_inode2v9ses(dir); v9ses = v9fs_inode2v9ses(dir);
if (!v9ses->extended) { if (!v9ses->extended) {
dprintk(DEBUG_ERROR, "not extended\n"); P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n");
return -EPERM; return -EPERM;
} }
dfid = v9fs_fid_clone(dentry->d_parent);
if(IS_ERR(dfid)) {
err = PTR_ERR(dfid);
goto error;
}
perm = unixmode2p9mode(v9ses, mode); perm = unixmode2p9mode(v9ses, mode);
fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
P9_OREAD);
if (IS_ERR(fid))
return PTR_ERR(fid);
err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name, p9_client_clunk(fid);
perm, V9FS_OREAD, (char *) extension, &fid, NULL, NULL);
if (err)
goto clunk_dfid;
err = v9fs_t_clunk(v9ses, fid);
if (err)
goto clunk_dfid;
vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
if (IS_ERR(vfid)) {
err = PTR_ERR(vfid);
vfid = NULL;
goto clunk_dfid;
}
inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
inode = NULL;
goto free_vfid;
}
if(v9ses->cache)
dentry->d_op = &v9fs_cached_dentry_operations;
else
dentry->d_op = &v9fs_dentry_operations;
d_instantiate(dentry, inode);
return 0; return 0;
free_vfid:
v9fs_fid_destroy(vfid);
clunk_dfid:
v9fs_fid_clunk(v9ses, dfid);
error:
return err;
} }
/** /**
...@@ -1224,8 +1039,8 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, ...@@ -1224,8 +1039,8 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
static int static int
v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
{ {
dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino,
symname); dentry->d_name.name, symname);
return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname); return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
} }
...@@ -1247,11 +1062,11 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1247,11 +1062,11 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
struct dentry *dentry) struct dentry *dentry)
{ {
int retval; int retval;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); struct p9_fid *oldfid;
struct v9fs_fid *oldfid;
char *name; char *name;
dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, P9_DPRINTK(P9_DEBUG_VFS,
" %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
old_dentry->d_name.name); old_dentry->d_name.name);
oldfid = v9fs_fid_clone(old_dentry); oldfid = v9fs_fid_clone(old_dentry);
...@@ -1265,11 +1080,11 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1265,11 +1080,11 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
} }
sprintf(name, "%d\n", oldfid->fid); sprintf(name, "%d\n", oldfid->fid);
retval = v9fs_vfs_mkspecial(dir, dentry, V9FS_DMLINK, name); retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
__putname(name); __putname(name);
clunk_fid: clunk_fid:
v9fs_fid_clunk(v9ses, oldfid); p9_client_clunk(oldfid);
return retval; return retval;
} }
...@@ -1288,7 +1103,8 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) ...@@ -1288,7 +1103,8 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
int retval; int retval;
char *name; char *name;
dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, P9_DPRINTK(P9_DEBUG_VFS,
" %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
if (!new_valid_dev(rdev)) if (!new_valid_dev(rdev))
......
...@@ -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");
} }
/** /**
...@@ -234,7 +217,7 @@ static int v9fs_show_options(struct seq_file *m, struct vfsmount *mnt) ...@@ -234,7 +217,7 @@ static int v9fs_show_options(struct seq_file *m, struct vfsmount *mnt)
struct v9fs_session_info *v9ses = mnt->mnt_sb->s_fs_info; struct v9fs_session_info *v9ses = mnt->mnt_sb->s_fs_info;
if (v9ses->debug != 0) if (v9ses->debug != 0)
seq_printf(m, ",debug=%u", v9ses->debug); seq_printf(m, ",debug=%x", v9ses->debug);
if (v9ses->port != V9FS_PORT) if (v9ses->port != V9FS_PORT)
seq_printf(m, ",port=%u", v9ses->port); seq_printf(m, ",port=%u", v9ses->port);
if (v9ses->maxdata != 9000) if (v9ses->maxdata != 9000)
......
...@@ -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) := 9pnet.o
9pnet-objs := \
mod.o \
trans_fd.o \
mux.o \
client.o \
conv.o \
error.o \
fcprint.o \
util.o \
9pnet-$(CONFIG_SYSCTL) += sysctl.o
/*
* net/9p/clnt.c
*
* 9P Client
*
* 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
*
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/idr.h>
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/uaccess.h>
#include <net/9p/9p.h>
#include <net/9p/transport.h>
#include <net/9p/conn.h>
#include <net/9p/client.h>
static struct p9_fid *p9_fid_create(struct p9_client *clnt);
static void p9_fid_destroy(struct p9_fid *fid);
static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu);
struct p9_client *p9_client_create(struct p9_transport *trans, int msize,
int dotu)
{
int err, n;
struct p9_client *clnt;
struct p9_fcall *tc, *rc;
struct p9_str *version;
err = 0;
tc = NULL;
rc = NULL;
clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL);
if (!clnt)
return ERR_PTR(-ENOMEM);
P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n",
clnt, trans, msize, dotu);
spin_lock_init(&clnt->lock);
clnt->trans = trans;
clnt->msize = msize;
clnt->dotu = dotu;
INIT_LIST_HEAD(&clnt->fidlist);
clnt->fidpool = p9_idpool_create();
if (!clnt->fidpool) {
err = PTR_ERR(clnt->fidpool);
clnt->fidpool = NULL;
goto error;
}
clnt->conn = p9_conn_create(clnt->trans, clnt->msize, &clnt->dotu);
if (IS_ERR(clnt->conn)) {
err = PTR_ERR(clnt->conn);
clnt->conn = NULL;
goto error;
}
tc = p9_create_tversion(clnt->msize, clnt->dotu?"9P2000.u":"9P2000");
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
version = &rc->params.rversion.version;
if (version->len == 8 && !memcmp(version->str, "9P2000.u", 8))
clnt->dotu = 1;
else if (version->len == 6 && !memcmp(version->str, "9P2000", 6))
clnt->dotu = 0;
else {
err = -EREMOTEIO;
goto error;
}
n = rc->params.rversion.msize;
if (n < clnt->msize)
clnt->msize = n;
kfree(tc);
kfree(rc);
return clnt;
error:
kfree(tc);
kfree(rc);
p9_client_destroy(clnt);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_client_create);
void p9_client_destroy(struct p9_client *clnt)
{
struct p9_fid *fid, *fidptr;
P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
if (clnt->conn) {
p9_conn_destroy(clnt->conn);
clnt->conn = NULL;
}
if (clnt->trans) {
clnt->trans->close(clnt->trans);
kfree(clnt->trans);
clnt->trans = NULL;
}
list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist)
p9_fid_destroy(fid);
if (clnt->fidpool)
p9_idpool_destroy(clnt->fidpool);
kfree(clnt);
}
EXPORT_SYMBOL(p9_client_destroy);
void p9_client_disconnect(struct p9_client *clnt)
{
P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
clnt->trans->status = Disconnected;
p9_conn_cancel(clnt->conn, -EIO);
}
EXPORT_SYMBOL(p9_client_disconnect);
struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
char *uname, char *aname)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_fid *fid;
P9_DPRINTK(P9_DEBUG_9P, "clnt %p afid %d uname %s aname %s\n",
clnt, afid?afid->fid:-1, uname, aname);
err = 0;
tc = NULL;
rc = NULL;
fid = p9_fid_create(clnt);
if (IS_ERR(fid)) {
err = PTR_ERR(fid);
fid = NULL;
goto error;
}
tc = p9_create_tattach(fid->fid, afid?afid->fid:P9_NOFID, uname, aname);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
memmove(&fid->qid, &rc->params.rattach.qid, sizeof(struct p9_qid));
kfree(tc);
kfree(rc);
return fid;
error:
kfree(tc);
kfree(rc);
if (fid)
p9_fid_destroy(fid);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_client_attach);
struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname, char *aname)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_fid *fid;
P9_DPRINTK(P9_DEBUG_9P, "clnt %p uname %s aname %s\n", clnt, uname,
aname);
err = 0;
tc = NULL;
rc = NULL;
fid = p9_fid_create(clnt);
if (IS_ERR(fid)) {
err = PTR_ERR(fid);
fid = NULL;
goto error;
}
tc = p9_create_tauth(fid->fid, uname, aname);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
memmove(&fid->qid, &rc->params.rauth.qid, sizeof(struct p9_qid));
kfree(tc);
kfree(rc);
return fid;
error:
kfree(tc);
kfree(rc);
if (fid)
p9_fid_destroy(fid);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_client_auth);
struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
int clone)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
struct p9_fid *fid;
P9_DPRINTK(P9_DEBUG_9P, "fid %d nwname %d wname[0] %s\n",
oldfid->fid, nwname, wnames?wnames[0]:NULL);
err = 0;
tc = NULL;
rc = NULL;
clnt = oldfid->clnt;
if (clone) {
fid = p9_fid_create(clnt);
if (IS_ERR(fid)) {
err = PTR_ERR(fid);
fid = NULL;
goto error;
}
fid->uid = oldfid->uid;
} else
fid = oldfid;
tc = p9_create_twalk(oldfid->fid, fid->fid, nwname, wnames);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err) {
if (rc && rc->id == P9_RWALK)
goto clunk_fid;
else
goto error;
}
if (rc->params.rwalk.nwqid != nwname) {
err = -ENOENT;
goto clunk_fid;
}
if (nwname)
memmove(&fid->qid,
&rc->params.rwalk.wqids[rc->params.rwalk.nwqid - 1],
sizeof(struct p9_qid));
else
fid->qid = oldfid->qid;
kfree(tc);
kfree(rc);
return fid;
clunk_fid:
kfree(tc);
kfree(rc);
rc = NULL;
tc = p9_create_tclunk(fid->fid);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
p9_conn_rpc(clnt->conn, tc, &rc);
error:
kfree(tc);
kfree(rc);
if (fid && (fid != oldfid))
p9_fid_destroy(fid);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_client_walk);
int p9_client_open(struct p9_fid *fid, int mode)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d mode %d\n", fid->fid, mode);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
if (fid->mode != -1)
return -EINVAL;
tc = p9_create_topen(fid->fid, mode);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto done;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto done;
fid->mode = mode;
fid->iounit = rc->params.ropen.iounit;
done:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_open);
int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
char *extension)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d name %s perm %d mode %d\n", fid->fid,
name, perm, mode);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
if (fid->mode != -1)
return -EINVAL;
tc = p9_create_tcreate(fid->fid, name, perm, mode, extension,
clnt->dotu);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto done;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto done;
fid->mode = mode;
fid->iounit = rc->params.ropen.iounit;
done:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_fcreate);
int p9_client_clunk(struct p9_fid *fid)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
tc = p9_create_tclunk(fid->fid);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto done;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto done;
p9_fid_destroy(fid);
done:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_clunk);
int p9_client_remove(struct p9_fid *fid)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
tc = p9_create_tremove(fid->fid);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto done;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto done;
p9_fid_destroy(fid);
done:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_remove);
int p9_client_read(struct p9_fid *fid, char *data, u64 offset, u32 count)
{
int err, n, rsize, total;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu %d\n", fid->fid,
(long long unsigned) offset, count);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
total = 0;
rsize = fid->iounit;
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
rsize = clnt->msize - P9_IOHDRSZ;
do {
if (count < rsize)
rsize = count;
tc = p9_create_tread(fid->fid, offset, rsize);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
n = rc->params.rread.count;
if (n > count)
n = count;
memmove(data, rc->params.rread.data, n);
count -= n;
data += n;
offset += n;
total += n;
kfree(tc);
tc = NULL;
kfree(rc);
rc = NULL;
} while (count > 0 && n == rsize);
return total;
error:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_read);
int p9_client_write(struct p9_fid *fid, char *data, u64 offset, u32 count)
{
int err, n, rsize, total;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
(long long unsigned) offset, count);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
total = 0;
rsize = fid->iounit;
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
rsize = clnt->msize - P9_IOHDRSZ;
do {
if (count < rsize)
rsize = count;
tc = p9_create_twrite(fid->fid, offset, rsize, data);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
n = rc->params.rread.count;
count -= n;
data += n;
offset += n;
total += n;
kfree(tc);
tc = NULL;
kfree(rc);
rc = NULL;
} while (count > 0);
return total;
error:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_write);
int
p9_client_uread(struct p9_fid *fid, char __user *data, u64 offset, u32 count)
{
int err, n, rsize, total;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
(long long unsigned) offset, count);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
total = 0;
rsize = fid->iounit;
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
rsize = clnt->msize - P9_IOHDRSZ;
do {
if (count < rsize)
rsize = count;
tc = p9_create_tread(fid->fid, offset, rsize);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
n = rc->params.rread.count;
if (n > count)
n = count;
err = copy_to_user(data, rc->params.rread.data, n);
if (err) {
err = -EFAULT;
goto error;
}
count -= n;
data += n;
offset += n;
total += n;
kfree(tc);
tc = NULL;
kfree(rc);
rc = NULL;
} while (count > 0 && n == rsize);
return total;
error:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_uread);
int
p9_client_uwrite(struct p9_fid *fid, const char __user *data, u64 offset,
u32 count)
{
int err, n, rsize, total;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
(long long unsigned) offset, count);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
total = 0;
rsize = fid->iounit;
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
rsize = clnt->msize - P9_IOHDRSZ;
do {
if (count < rsize)
rsize = count;
tc = p9_create_twrite_u(fid->fid, offset, rsize, data);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
n = rc->params.rread.count;
count -= n;
data += n;
offset += n;
total += n;
kfree(tc);
tc = NULL;
kfree(rc);
rc = NULL;
} while (count > 0);
return total;
error:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_uwrite);
int p9_client_readn(struct p9_fid *fid, char *data, u64 offset, u32 count)
{
int n, total;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
(long long unsigned) offset, count);
n = 0;
total = 0;
while (count) {
n = p9_client_read(fid, data, offset, count);
if (n <= 0)
break;
data += n;
offset += n;
count -= n;
total += n;
}
if (n < 0)
total = n;
return total;
}
EXPORT_SYMBOL(p9_client_readn);
struct p9_stat *p9_client_stat(struct p9_fid *fid)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
struct p9_stat *ret;
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
err = 0;
tc = NULL;
rc = NULL;
ret = NULL;
clnt = fid->clnt;
tc = p9_create_tstat(fid->fid);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
ret = p9_clone_stat(&rc->params.rstat.stat, clnt->dotu);
if (IS_ERR(ret)) {
err = PTR_ERR(ret);
ret = NULL;
goto error;
}
kfree(tc);
kfree(rc);
return ret;
error:
kfree(tc);
kfree(rc);
kfree(ret);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_client_stat);
int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
{
int err;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
err = 0;
tc = NULL;
rc = NULL;
clnt = fid->clnt;
tc = p9_create_twstat(fid->fid, wst, clnt->dotu);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto done;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
done:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_wstat);
struct p9_stat *p9_client_dirread(struct p9_fid *fid, u64 offset)
{
int err, n, m;
struct p9_fcall *tc, *rc;
struct p9_client *clnt;
struct p9_stat st, *ret;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu\n", fid->fid,
(long long unsigned) offset);
err = 0;
tc = NULL;
rc = NULL;
ret = NULL;
clnt = fid->clnt;
/* if the offset is below or above the current response, free it */
if (offset < fid->rdir_fpos || (fid->rdir_fcall &&
offset >= fid->rdir_fpos+fid->rdir_fcall->params.rread.count)) {
fid->rdir_pos = 0;
if (fid->rdir_fcall)
fid->rdir_fpos += fid->rdir_fcall->params.rread.count;
kfree(fid->rdir_fcall);
fid->rdir_fcall = NULL;
if (offset < fid->rdir_fpos)
fid->rdir_fpos = 0;
}
if (!fid->rdir_fcall) {
n = fid->iounit;
if (!n || n > clnt->msize-P9_IOHDRSZ)
n = clnt->msize - P9_IOHDRSZ;
while (1) {
if (fid->rdir_fcall) {
fid->rdir_fpos +=
fid->rdir_fcall->params.rread.count;
kfree(fid->rdir_fcall);
fid->rdir_fcall = NULL;
}
tc = p9_create_tread(fid->fid, fid->rdir_fpos, n);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_conn_rpc(clnt->conn, tc, &rc);
if (err)
goto error;
n = rc->params.rread.count;
if (n == 0)
goto done;
fid->rdir_fcall = rc;
rc = NULL;
if (offset >= fid->rdir_fpos &&
offset < fid->rdir_fpos+n)
break;
}
fid->rdir_pos = 0;
}
m = offset - fid->rdir_fpos;
if (m < 0)
goto done;
n = p9_deserialize_stat(fid->rdir_fcall->params.rread.data + m,
fid->rdir_fcall->params.rread.count - m, &st, clnt->dotu);
if (!n) {
err = -EIO;
goto error;
}
fid->rdir_pos += n;
st.size = n;
ret = p9_clone_stat(&st, clnt->dotu);
if (IS_ERR(ret)) {
err = PTR_ERR(ret);
ret = NULL;
goto error;
}
done:
kfree(tc);
kfree(rc);
return ret;
error:
kfree(tc);
kfree(rc);
kfree(ret);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_client_dirread);
static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu)
{
int n;
char *p;
struct p9_stat *ret;
n = sizeof(struct p9_stat) + st->name.len + st->uid.len + st->gid.len +
st->muid.len;
if (dotu)
n += st->extension.len;
ret = kmalloc(n, GFP_KERNEL);
if (!ret)
return ERR_PTR(-ENOMEM);
memmove(ret, st, sizeof(struct p9_stat));
p = ((char *) ret) + sizeof(struct p9_stat);
memmove(p, st->name.str, st->name.len);
p += st->name.len;
memmove(p, st->uid.str, st->uid.len);
p += st->uid.len;
memmove(p, st->gid.str, st->gid.len);
p += st->gid.len;
memmove(p, st->muid.str, st->muid.len);
p += st->muid.len;
if (dotu) {
memmove(p, st->extension.str, st->extension.len);
p += st->extension.len;
}
return ret;
}
static struct p9_fid *p9_fid_create(struct p9_client *clnt)
{
int err;
struct p9_fid *fid;
P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL);
if (!fid)
return ERR_PTR(-ENOMEM);
fid->fid = p9_idpool_get(clnt->fidpool);
if (fid->fid < 0) {
err = -ENOSPC;
goto error;
}
memset(&fid->qid, 0, sizeof(struct p9_qid));
fid->mode = -1;
fid->rdir_fpos = 0;
fid->rdir_pos = 0;
fid->rdir_fcall = NULL;
fid->uid = current->fsuid;
fid->clnt = clnt;
fid->aux = NULL;
spin_lock(&clnt->lock);
list_add(&fid->flist, &clnt->fidlist);
spin_unlock(&clnt->lock);
return fid;
error:
kfree(fid);
return ERR_PTR(err);
}
static void p9_fid_destroy(struct p9_fid *fid)
{
struct p9_client *clnt;
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
clnt = fid->clnt;
p9_idpool_put(fid->fid, clnt->fidpool);
spin_lock(&clnt->lock);
list_del(&fid->flist);
spin_unlock(&clnt->lock);
kfree(fid->rdir_fcall);
kfree(fid);
}
/* /*
* linux/fs/9p/conv.c * net/9p/conv.c
* *
* 9P protocol conversion functions * 9P protocol conversion functions
* *
...@@ -29,11 +29,8 @@ ...@@ -29,11 +29,8 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include "debug.h" #include <net/9p/9p.h>
#include "v9fs.h"
#include "9p.h"
#include "conv.h"
/* /*
* Buffer to help with string parsing * Buffer to help with string parsing
...@@ -59,8 +56,9 @@ static int buf_check_size(struct cbuf *buf, int len) ...@@ -59,8 +56,9 @@ static int buf_check_size(struct cbuf *buf, int len)
{ {
if (buf->p + len > buf->ep) { if (buf->p + len > buf->ep) {
if (buf->p < buf->ep) { if (buf->p < buf->ep) {
eprintk(KERN_ERR, "buffer overflow: want %d has %d\n", P9_EPRINTK(KERN_ERR,
len, (int)(buf->ep - buf->p)); "buffer overflow: want %d has %d\n", len,
(int)(buf->ep - buf->p));
dump_stack(); dump_stack();
buf->p = buf->ep + 1; buf->p = buf->ep + 1;
} }
...@@ -183,7 +181,7 @@ static u64 buf_get_int64(struct cbuf *buf) ...@@ -183,7 +181,7 @@ static u64 buf_get_int64(struct cbuf *buf)
return ret; return ret;
} }
static void buf_get_str(struct cbuf *buf, struct v9fs_str *vstr) static void buf_get_str(struct cbuf *buf, struct p9_str *vstr)
{ {
vstr->len = buf_get_int16(buf); vstr->len = buf_get_int16(buf);
if (!buf_check_overflow(buf) && buf_check_size(buf, vstr->len)) { if (!buf_check_overflow(buf) && buf_check_size(buf, vstr->len)) {
...@@ -195,7 +193,7 @@ static void buf_get_str(struct cbuf *buf, struct v9fs_str *vstr) ...@@ -195,7 +193,7 @@ static void buf_get_str(struct cbuf *buf, struct v9fs_str *vstr)
} }
} }
static void buf_get_qid(struct cbuf *bufp, struct v9fs_qid *qid) static void buf_get_qid(struct cbuf *bufp, struct p9_qid *qid)
{ {
qid->type = buf_get_int8(bufp); qid->type = buf_get_int8(bufp);
qid->version = buf_get_int32(bufp); qid->version = buf_get_int32(bufp);
...@@ -203,18 +201,18 @@ static void buf_get_qid(struct cbuf *bufp, struct v9fs_qid *qid) ...@@ -203,18 +201,18 @@ static void buf_get_qid(struct cbuf *bufp, struct v9fs_qid *qid)
} }
/** /**
* v9fs_size_wstat - calculate the size of a variable length stat struct * p9_size_wstat - calculate the size of a variable length stat struct
* @stat: metadata (stat) structure * @stat: metadata (stat) structure
* @extended: non-zero if 9P2000.u * @dotu: non-zero if 9P2000.u
* *
*/ */
static int v9fs_size_wstat(struct v9fs_wstat *wstat, int extended) static int p9_size_wstat(struct p9_wstat *wstat, int dotu)
{ {
int size = 0; int size = 0;
if (wstat == NULL) { if (wstat == NULL) {
eprintk(KERN_ERR, "v9fs_size_stat: got a NULL stat pointer\n"); P9_EPRINTK(KERN_ERR, "p9_size_stat: got a NULL stat pointer\n");
return 0; return 0;
} }
...@@ -239,7 +237,7 @@ static int v9fs_size_wstat(struct v9fs_wstat *wstat, int extended) ...@@ -239,7 +237,7 @@ static int v9fs_size_wstat(struct v9fs_wstat *wstat, int extended)
if (wstat->muid) if (wstat->muid)
size += strlen(wstat->muid); size += strlen(wstat->muid);
if (extended) { if (dotu) {
size += 4 + /* n_uid[4] */ size += 4 + /* n_uid[4] */
4 + /* n_gid[4] */ 4 + /* n_gid[4] */
4 + /* n_muid[4] */ 4 + /* n_muid[4] */
...@@ -255,12 +253,12 @@ static int v9fs_size_wstat(struct v9fs_wstat *wstat, int extended) ...@@ -255,12 +253,12 @@ static int v9fs_size_wstat(struct v9fs_wstat *wstat, int extended)
* buf_get_stat - safely decode a recieved metadata (stat) structure * buf_get_stat - safely decode a recieved metadata (stat) structure
* @bufp: buffer to deserialize * @bufp: buffer to deserialize
* @stat: metadata (stat) structure * @stat: metadata (stat) structure
* @extended: non-zero if 9P2000.u * @dotu: non-zero if 9P2000.u
* *
*/ */
static void static void
buf_get_stat(struct cbuf *bufp, struct v9fs_stat *stat, int extended) buf_get_stat(struct cbuf *bufp, struct p9_stat *stat, int dotu)
{ {
stat->size = buf_get_int16(bufp); stat->size = buf_get_int16(bufp);
stat->type = buf_get_int16(bufp); stat->type = buf_get_int16(bufp);
...@@ -277,7 +275,7 @@ buf_get_stat(struct cbuf *bufp, struct v9fs_stat *stat, int extended) ...@@ -277,7 +275,7 @@ buf_get_stat(struct cbuf *bufp, struct v9fs_stat *stat, int extended)
buf_get_str(bufp, &stat->gid); buf_get_str(bufp, &stat->gid);
buf_get_str(bufp, &stat->muid); buf_get_str(bufp, &stat->muid);
if (extended) { if (dotu) {
buf_get_str(bufp, &stat->extension); buf_get_str(bufp, &stat->extension);
stat->n_uid = buf_get_int32(bufp); stat->n_uid = buf_get_int32(bufp);
stat->n_gid = buf_get_int32(bufp); stat->n_gid = buf_get_int32(bufp);
...@@ -286,18 +284,18 @@ buf_get_stat(struct cbuf *bufp, struct v9fs_stat *stat, int extended) ...@@ -286,18 +284,18 @@ buf_get_stat(struct cbuf *bufp, struct v9fs_stat *stat, int extended)
} }
/** /**
* v9fs_deserialize_stat - decode a received metadata structure * p9_deserialize_stat - decode a received metadata structure
* @buf: buffer to deserialize * @buf: buffer to deserialize
* @buflen: length of received buffer * @buflen: length of received buffer
* @stat: metadata structure to decode into * @stat: metadata structure to decode into
* @extended: non-zero if 9P2000.u * @dotu: non-zero if 9P2000.u
* *
* Note: stat will point to the buf region. * Note: stat will point to the buf region.
*/ */
int int
v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat, p9_deserialize_stat(void *buf, u32 buflen, struct p9_stat *stat,
int extended) int dotu)
{ {
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
...@@ -305,13 +303,14 @@ v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat, ...@@ -305,13 +303,14 @@ v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat,
buf_init(bufp, buf, buflen); buf_init(bufp, buf, buflen);
p = bufp->p; p = bufp->p;
buf_get_stat(bufp, stat, extended); buf_get_stat(bufp, stat, dotu);
if (buf_check_overflow(bufp)) if (buf_check_overflow(bufp))
return 0; return 0;
else else
return bufp->p - p; return bufp->p - p;
} }
EXPORT_SYMBOL(p9_deserialize_stat);
/** /**
* deserialize_fcall - unmarshal a response * deserialize_fcall - unmarshal a response
...@@ -319,13 +318,13 @@ v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat, ...@@ -319,13 +318,13 @@ v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat,
* @buflen: length of received buffer * @buflen: length of received buffer
* @rcall: fcall structure to populate * @rcall: fcall structure to populate
* @rcalllen: length of fcall structure to populate * @rcalllen: length of fcall structure to populate
* @extended: non-zero if 9P2000.u * @dotu: non-zero if 9P2000.u
* *
*/ */
int int
v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall, p9_deserialize_fcall(void *buf, u32 buflen, struct p9_fcall *rcall,
int extended) int dotu)
{ {
struct cbuf buffer; struct cbuf buffer;
...@@ -338,102 +337,104 @@ v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall, ...@@ -338,102 +337,104 @@ v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall,
rcall->id = buf_get_int8(bufp); rcall->id = buf_get_int8(bufp);
rcall->tag = buf_get_int16(bufp); rcall->tag = buf_get_int16(bufp);
dprintk(DEBUG_CONV, "size %d id %d tag %d\n", rcall->size, rcall->id, P9_DPRINTK(P9_DEBUG_CONV, "size %d id %d tag %d\n", rcall->size,
rcall->tag); rcall->id, rcall->tag);
switch (rcall->id) { switch (rcall->id) {
default: default:
eprintk(KERN_ERR, "unknown message type: %d\n", rcall->id); P9_EPRINTK(KERN_ERR, "unknown message type: %d\n", rcall->id);
return -EPROTO; return -EPROTO;
case RVERSION: case P9_RVERSION:
rcall->params.rversion.msize = buf_get_int32(bufp); rcall->params.rversion.msize = buf_get_int32(bufp);
buf_get_str(bufp, &rcall->params.rversion.version); buf_get_str(bufp, &rcall->params.rversion.version);
break; break;
case RFLUSH: case P9_RFLUSH:
break; break;
case RATTACH: case P9_RATTACH:
rcall->params.rattach.qid.type = buf_get_int8(bufp); rcall->params.rattach.qid.type = buf_get_int8(bufp);
rcall->params.rattach.qid.version = buf_get_int32(bufp); rcall->params.rattach.qid.version = buf_get_int32(bufp);
rcall->params.rattach.qid.path = buf_get_int64(bufp); rcall->params.rattach.qid.path = buf_get_int64(bufp);
break; break;
case RWALK: case P9_RWALK:
rcall->params.rwalk.nwqid = buf_get_int16(bufp); rcall->params.rwalk.nwqid = buf_get_int16(bufp);
if (rcall->params.rwalk.nwqid > V9FS_MAXWELEM) { if (rcall->params.rwalk.nwqid > P9_MAXWELEM) {
eprintk(KERN_ERR, "Rwalk with more than %d qids: %d\n", P9_EPRINTK(KERN_ERR,
V9FS_MAXWELEM, rcall->params.rwalk.nwqid); "Rwalk with more than %d qids: %d\n",
P9_MAXWELEM, rcall->params.rwalk.nwqid);
return -EPROTO; return -EPROTO;
} }
for (i = 0; i < rcall->params.rwalk.nwqid; i++) for (i = 0; i < rcall->params.rwalk.nwqid; i++)
buf_get_qid(bufp, &rcall->params.rwalk.wqids[i]); buf_get_qid(bufp, &rcall->params.rwalk.wqids[i]);
break; break;
case ROPEN: case P9_ROPEN:
buf_get_qid(bufp, &rcall->params.ropen.qid); buf_get_qid(bufp, &rcall->params.ropen.qid);
rcall->params.ropen.iounit = buf_get_int32(bufp); rcall->params.ropen.iounit = buf_get_int32(bufp);
break; break;
case RCREATE: case P9_RCREATE:
buf_get_qid(bufp, &rcall->params.rcreate.qid); buf_get_qid(bufp, &rcall->params.rcreate.qid);
rcall->params.rcreate.iounit = buf_get_int32(bufp); rcall->params.rcreate.iounit = buf_get_int32(bufp);
break; break;
case RREAD: case P9_RREAD:
rcall->params.rread.count = buf_get_int32(bufp); rcall->params.rread.count = buf_get_int32(bufp);
rcall->params.rread.data = bufp->p; rcall->params.rread.data = bufp->p;
buf_check_size(bufp, rcall->params.rread.count); buf_check_size(bufp, rcall->params.rread.count);
break; break;
case RWRITE: case P9_RWRITE:
rcall->params.rwrite.count = buf_get_int32(bufp); rcall->params.rwrite.count = buf_get_int32(bufp);
break; break;
case RCLUNK: case P9_RCLUNK:
break; break;
case RREMOVE: case P9_RREMOVE:
break; break;
case RSTAT: case P9_RSTAT:
buf_get_int16(bufp); buf_get_int16(bufp);
buf_get_stat(bufp, &rcall->params.rstat.stat, extended); buf_get_stat(bufp, &rcall->params.rstat.stat, dotu);
break; break;
case RWSTAT: case P9_RWSTAT:
break; break;
case RERROR: case P9_RERROR:
buf_get_str(bufp, &rcall->params.rerror.error); buf_get_str(bufp, &rcall->params.rerror.error);
if (extended) if (dotu)
rcall->params.rerror.errno = buf_get_int16(bufp); rcall->params.rerror.errno = buf_get_int16(bufp);
break; break;
} }
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
dprintk(DEBUG_ERROR, "buffer overflow\n"); P9_DPRINTK(P9_DEBUG_ERROR, "buffer overflow\n");
return -EIO; return -EIO;
} }
return bufp->p - bufp->sp; return bufp->p - bufp->sp;
} }
EXPORT_SYMBOL(p9_deserialize_fcall);
static inline void v9fs_put_int8(struct cbuf *bufp, u8 val, u8 * p) static inline void p9_put_int8(struct cbuf *bufp, u8 val, u8 * p)
{ {
*p = val; *p = val;
buf_put_int8(bufp, val); buf_put_int8(bufp, val);
} }
static inline void v9fs_put_int16(struct cbuf *bufp, u16 val, u16 * p) static inline void p9_put_int16(struct cbuf *bufp, u16 val, u16 * p)
{ {
*p = val; *p = val;
buf_put_int16(bufp, val); buf_put_int16(bufp, val);
} }
static inline void v9fs_put_int32(struct cbuf *bufp, u32 val, u32 * p) static inline void p9_put_int32(struct cbuf *bufp, u32 val, u32 * p)
{ {
*p = val; *p = val;
buf_put_int32(bufp, val); buf_put_int32(bufp, val);
} }
static inline void v9fs_put_int64(struct cbuf *bufp, u64 val, u64 * p) static inline void p9_put_int64(struct cbuf *bufp, u64 val, u64 * p)
{ {
*p = val; *p = val;
buf_put_int64(bufp, val); buf_put_int64(bufp, val);
} }
static void static void
v9fs_put_str(struct cbuf *bufp, char *data, struct v9fs_str *str) p9_put_str(struct cbuf *bufp, char *data, struct p9_str *str)
{ {
int len; int len;
char *s; char *s;
...@@ -451,7 +452,16 @@ v9fs_put_str(struct cbuf *bufp, char *data, struct v9fs_str *str) ...@@ -451,7 +452,16 @@ v9fs_put_str(struct cbuf *bufp, char *data, struct v9fs_str *str)
} }
static int static int
v9fs_put_user_data(struct cbuf *bufp, const char __user * data, int count, p9_put_data(struct cbuf *bufp, const char *data, int count,
unsigned char **pdata)
{
*pdata = buf_alloc(bufp, count);
memmove(*pdata, data, count);
return count;
}
static int
p9_put_user_data(struct cbuf *bufp, const char __user *data, int count,
unsigned char **pdata) unsigned char **pdata)
{ {
*pdata = buf_alloc(bufp, count); *pdata = buf_alloc(bufp, count);
...@@ -459,162 +469,167 @@ v9fs_put_user_data(struct cbuf *bufp, const char __user * data, int count, ...@@ -459,162 +469,167 @@ v9fs_put_user_data(struct cbuf *bufp, const char __user * data, int count,
} }
static void static void
v9fs_put_wstat(struct cbuf *bufp, struct v9fs_wstat *wstat, p9_put_wstat(struct cbuf *bufp, struct p9_wstat *wstat,
struct v9fs_stat *stat, int statsz, int extended) struct p9_stat *stat, int statsz, int dotu)
{ {
v9fs_put_int16(bufp, statsz, &stat->size); p9_put_int16(bufp, statsz, &stat->size);
v9fs_put_int16(bufp, wstat->type, &stat->type); p9_put_int16(bufp, wstat->type, &stat->type);
v9fs_put_int32(bufp, wstat->dev, &stat->dev); p9_put_int32(bufp, wstat->dev, &stat->dev);
v9fs_put_int8(bufp, wstat->qid.type, &stat->qid.type); p9_put_int8(bufp, wstat->qid.type, &stat->qid.type);
v9fs_put_int32(bufp, wstat->qid.version, &stat->qid.version); p9_put_int32(bufp, wstat->qid.version, &stat->qid.version);
v9fs_put_int64(bufp, wstat->qid.path, &stat->qid.path); p9_put_int64(bufp, wstat->qid.path, &stat->qid.path);
v9fs_put_int32(bufp, wstat->mode, &stat->mode); p9_put_int32(bufp, wstat->mode, &stat->mode);
v9fs_put_int32(bufp, wstat->atime, &stat->atime); p9_put_int32(bufp, wstat->atime, &stat->atime);
v9fs_put_int32(bufp, wstat->mtime, &stat->mtime); p9_put_int32(bufp, wstat->mtime, &stat->mtime);
v9fs_put_int64(bufp, wstat->length, &stat->length); p9_put_int64(bufp, wstat->length, &stat->length);
v9fs_put_str(bufp, wstat->name, &stat->name); p9_put_str(bufp, wstat->name, &stat->name);
v9fs_put_str(bufp, wstat->uid, &stat->uid); p9_put_str(bufp, wstat->uid, &stat->uid);
v9fs_put_str(bufp, wstat->gid, &stat->gid); p9_put_str(bufp, wstat->gid, &stat->gid);
v9fs_put_str(bufp, wstat->muid, &stat->muid); p9_put_str(bufp, wstat->muid, &stat->muid);
if (extended) { if (dotu) {
v9fs_put_str(bufp, wstat->extension, &stat->extension); p9_put_str(bufp, wstat->extension, &stat->extension);
v9fs_put_int32(bufp, wstat->n_uid, &stat->n_uid); p9_put_int32(bufp, wstat->n_uid, &stat->n_uid);
v9fs_put_int32(bufp, wstat->n_gid, &stat->n_gid); p9_put_int32(bufp, wstat->n_gid, &stat->n_gid);
v9fs_put_int32(bufp, wstat->n_muid, &stat->n_muid); p9_put_int32(bufp, wstat->n_muid, &stat->n_muid);
} }
} }
static struct v9fs_fcall * static struct p9_fcall *
v9fs_create_common(struct cbuf *bufp, u32 size, u8 id) p9_create_common(struct cbuf *bufp, u32 size, u8 id)
{ {
struct v9fs_fcall *fc; struct p9_fcall *fc;
size += 4 + 1 + 2; /* size[4] id[1] tag[2] */ size += 4 + 1 + 2; /* size[4] id[1] tag[2] */
fc = kmalloc(sizeof(struct v9fs_fcall) + size, GFP_KERNEL); fc = kmalloc(sizeof(struct p9_fcall) + size, GFP_KERNEL);
if (!fc) if (!fc)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
fc->sdata = (char *)fc + sizeof(*fc); fc->sdata = (char *)fc + sizeof(*fc);
buf_init(bufp, (char *)fc->sdata, size); buf_init(bufp, (char *)fc->sdata, size);
v9fs_put_int32(bufp, size, &fc->size); p9_put_int32(bufp, size, &fc->size);
v9fs_put_int8(bufp, id, &fc->id); p9_put_int8(bufp, id, &fc->id);
v9fs_put_int16(bufp, V9FS_NOTAG, &fc->tag); p9_put_int16(bufp, P9_NOTAG, &fc->tag);
return fc; return fc;
} }
void v9fs_set_tag(struct v9fs_fcall *fc, u16 tag) void p9_set_tag(struct p9_fcall *fc, u16 tag)
{ {
fc->tag = tag; fc->tag = tag;
*(__le16 *) (fc->sdata + 5) = cpu_to_le16(tag); *(__le16 *) (fc->sdata + 5) = cpu_to_le16(tag);
} }
EXPORT_SYMBOL(p9_set_tag);
struct v9fs_fcall *v9fs_create_tversion(u32 msize, char *version) struct p9_fcall *p9_create_tversion(u32 msize, char *version)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4 + 2 + strlen(version); /* msize[4] version[s] */ size = 4 + 2 + strlen(version); /* msize[4] version[s] */
fc = v9fs_create_common(bufp, size, TVERSION); fc = p9_create_common(bufp, size, P9_TVERSION);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, msize, &fc->params.tversion.msize); p9_put_int32(bufp, msize, &fc->params.tversion.msize);
v9fs_put_str(bufp, version, &fc->params.tversion.version); p9_put_str(bufp, version, &fc->params.tversion.version);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_tversion);
#if 0 struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname)
struct v9fs_fcall *v9fs_create_tauth(u32 afid, char *uname, char *aname)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4 + 2 + strlen(uname) + 2 + strlen(aname); /* afid[4] uname[s] aname[s] */ /* afid[4] uname[s] aname[s] */
fc = v9fs_create_common(bufp, size, TAUTH); size = 4 + 2 + strlen(uname) + 2 + strlen(aname);
fc = p9_create_common(bufp, size, P9_TAUTH);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, afid, &fc->params.tauth.afid); p9_put_int32(bufp, afid, &fc->params.tauth.afid);
v9fs_put_str(bufp, uname, &fc->params.tauth.uname); p9_put_str(bufp, uname, &fc->params.tauth.uname);
v9fs_put_str(bufp, aname, &fc->params.tauth.aname); p9_put_str(bufp, aname, &fc->params.tauth.aname);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
#endif /* 0 */ EXPORT_SYMBOL(p9_create_tauth);
struct v9fs_fcall * struct p9_fcall *
v9fs_create_tattach(u32 fid, u32 afid, char *uname, char *aname) p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4 + 4 + 2 + strlen(uname) + 2 + strlen(aname); /* fid[4] afid[4] uname[s] aname[s] */ /* fid[4] afid[4] uname[s] aname[s] */
fc = v9fs_create_common(bufp, size, TATTACH); size = 4 + 4 + 2 + strlen(uname) + 2 + strlen(aname);
fc = p9_create_common(bufp, size, P9_TATTACH);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.tattach.fid); p9_put_int32(bufp, fid, &fc->params.tattach.fid);
v9fs_put_int32(bufp, afid, &fc->params.tattach.afid); p9_put_int32(bufp, afid, &fc->params.tattach.afid);
v9fs_put_str(bufp, uname, &fc->params.tattach.uname); p9_put_str(bufp, uname, &fc->params.tattach.uname);
v9fs_put_str(bufp, aname, &fc->params.tattach.aname); p9_put_str(bufp, aname, &fc->params.tattach.aname);
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_tattach);
struct v9fs_fcall *v9fs_create_tflush(u16 oldtag) struct p9_fcall *p9_create_tflush(u16 oldtag)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 2; /* oldtag[2] */ size = 2; /* oldtag[2] */
fc = v9fs_create_common(bufp, size, TFLUSH); fc = p9_create_common(bufp, size, P9_TFLUSH);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int16(bufp, oldtag, &fc->params.tflush.oldtag); p9_put_int16(bufp, oldtag, &fc->params.tflush.oldtag);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_tflush);
struct v9fs_fcall *v9fs_create_twalk(u32 fid, u32 newfid, u16 nwname, struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname,
char **wnames) char **wnames)
{ {
int i, size; int i, size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
if (nwname > V9FS_MAXWELEM) { if (nwname > P9_MAXWELEM) {
dprintk(DEBUG_ERROR, "nwname > %d\n", V9FS_MAXWELEM); P9_DPRINTK(P9_DEBUG_ERROR, "nwname > %d\n", P9_MAXWELEM);
return NULL; return NULL;
} }
...@@ -623,122 +638,160 @@ struct v9fs_fcall *v9fs_create_twalk(u32 fid, u32 newfid, u16 nwname, ...@@ -623,122 +638,160 @@ struct v9fs_fcall *v9fs_create_twalk(u32 fid, u32 newfid, u16 nwname,
size += 2 + strlen(wnames[i]); /* wname[s] */ size += 2 + strlen(wnames[i]); /* wname[s] */
} }
fc = v9fs_create_common(bufp, size, TWALK); fc = p9_create_common(bufp, size, P9_TWALK);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.twalk.fid); p9_put_int32(bufp, fid, &fc->params.twalk.fid);
v9fs_put_int32(bufp, newfid, &fc->params.twalk.newfid); p9_put_int32(bufp, newfid, &fc->params.twalk.newfid);
v9fs_put_int16(bufp, nwname, &fc->params.twalk.nwname); p9_put_int16(bufp, nwname, &fc->params.twalk.nwname);
for (i = 0; i < nwname; i++) { for (i = 0; i < nwname; i++) {
v9fs_put_str(bufp, wnames[i], &fc->params.twalk.wnames[i]); p9_put_str(bufp, wnames[i], &fc->params.twalk.wnames[i]);
} }
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_twalk);
struct v9fs_fcall *v9fs_create_topen(u32 fid, u8 mode) struct p9_fcall *p9_create_topen(u32 fid, u8 mode)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4 + 1; /* fid[4] mode[1] */ size = 4 + 1; /* fid[4] mode[1] */
fc = v9fs_create_common(bufp, size, TOPEN); fc = p9_create_common(bufp, size, P9_TOPEN);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.topen.fid); p9_put_int32(bufp, fid, &fc->params.topen.fid);
v9fs_put_int8(bufp, mode, &fc->params.topen.mode); p9_put_int8(bufp, mode, &fc->params.topen.mode);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_topen);
struct v9fs_fcall *v9fs_create_tcreate(u32 fid, char *name, u32 perm, u8 mode, struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode,
char *extension, int extended) char *extension, int dotu)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4 + 2 + strlen(name) + 4 + 1; /* fid[4] name[s] perm[4] mode[1] */ /* fid[4] name[s] perm[4] mode[1] */
if (extended) { size = 4 + 2 + strlen(name) + 4 + 1;
if (dotu) {
size += 2 + /* extension[s] */ size += 2 + /* extension[s] */
(extension == NULL ? 0 : strlen(extension)); (extension == NULL ? 0 : strlen(extension));
} }
fc = v9fs_create_common(bufp, size, TCREATE); fc = p9_create_common(bufp, size, P9_TCREATE);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.tcreate.fid); p9_put_int32(bufp, fid, &fc->params.tcreate.fid);
v9fs_put_str(bufp, name, &fc->params.tcreate.name); p9_put_str(bufp, name, &fc->params.tcreate.name);
v9fs_put_int32(bufp, perm, &fc->params.tcreate.perm); p9_put_int32(bufp, perm, &fc->params.tcreate.perm);
v9fs_put_int8(bufp, mode, &fc->params.tcreate.mode); p9_put_int8(bufp, mode, &fc->params.tcreate.mode);
if (extended) if (dotu)
v9fs_put_str(bufp, extension, &fc->params.tcreate.extension); p9_put_str(bufp, extension, &fc->params.tcreate.extension);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_tcreate);
struct v9fs_fcall *v9fs_create_tread(u32 fid, u64 offset, u32 count) struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4 + 8 + 4; /* fid[4] offset[8] count[4] */ size = 4 + 8 + 4; /* fid[4] offset[8] count[4] */
fc = v9fs_create_common(bufp, size, TREAD); fc = p9_create_common(bufp, size, P9_TREAD);
if (IS_ERR(fc))
goto error;
p9_put_int32(bufp, fid, &fc->params.tread.fid);
p9_put_int64(bufp, offset, &fc->params.tread.offset);
p9_put_int32(bufp, count, &fc->params.tread.count);
if (buf_check_overflow(bufp)) {
kfree(fc);
fc = ERR_PTR(-ENOMEM);
}
error:
return fc;
}
EXPORT_SYMBOL(p9_create_tread);
struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count,
const char *data)
{
int size, err;
struct p9_fcall *fc;
struct cbuf buffer;
struct cbuf *bufp = &buffer;
/* fid[4] offset[8] count[4] data[count] */
size = 4 + 8 + 4 + count;
fc = p9_create_common(bufp, size, P9_TWRITE);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.tread.fid); p9_put_int32(bufp, fid, &fc->params.twrite.fid);
v9fs_put_int64(bufp, offset, &fc->params.tread.offset); p9_put_int64(bufp, offset, &fc->params.twrite.offset);
v9fs_put_int32(bufp, count, &fc->params.tread.count); p9_put_int32(bufp, count, &fc->params.twrite.count);
err = p9_put_data(bufp, data, count, &fc->params.twrite.data);
if (err) {
kfree(fc);
fc = ERR_PTR(err);
}
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_twrite);
struct v9fs_fcall *v9fs_create_twrite(u32 fid, u64 offset, u32 count, struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count,
const char __user * data) const char __user *data)
{ {
int size, err; int size, err;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4 + 8 + 4 + count; /* fid[4] offset[8] count[4] data[count] */ /* fid[4] offset[8] count[4] data[count] */
fc = v9fs_create_common(bufp, size, TWRITE); size = 4 + 8 + 4 + count;
fc = p9_create_common(bufp, size, P9_TWRITE);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.twrite.fid); p9_put_int32(bufp, fid, &fc->params.twrite.fid);
v9fs_put_int64(bufp, offset, &fc->params.twrite.offset); p9_put_int64(bufp, offset, &fc->params.twrite.offset);
v9fs_put_int32(bufp, count, &fc->params.twrite.count); p9_put_int32(bufp, count, &fc->params.twrite.count);
err = v9fs_put_user_data(bufp, data, count, &fc->params.twrite.data); err = p9_put_user_data(bufp, data, count, &fc->params.twrite.data);
if (err) { if (err) {
kfree(fc); kfree(fc);
fc = ERR_PTR(err); fc = ERR_PTR(err);
...@@ -748,98 +801,103 @@ struct v9fs_fcall *v9fs_create_twrite(u32 fid, u64 offset, u32 count, ...@@ -748,98 +801,103 @@ struct v9fs_fcall *v9fs_create_twrite(u32 fid, u64 offset, u32 count,
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_twrite_u);
struct v9fs_fcall *v9fs_create_tclunk(u32 fid) struct p9_fcall *p9_create_tclunk(u32 fid)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4; /* fid[4] */ size = 4; /* fid[4] */
fc = v9fs_create_common(bufp, size, TCLUNK); fc = p9_create_common(bufp, size, P9_TCLUNK);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.tclunk.fid); p9_put_int32(bufp, fid, &fc->params.tclunk.fid);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_tclunk);
struct v9fs_fcall *v9fs_create_tremove(u32 fid) struct p9_fcall *p9_create_tremove(u32 fid)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4; /* fid[4] */ size = 4; /* fid[4] */
fc = v9fs_create_common(bufp, size, TREMOVE); fc = p9_create_common(bufp, size, P9_TREMOVE);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.tremove.fid); p9_put_int32(bufp, fid, &fc->params.tremove.fid);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_tremove);
struct v9fs_fcall *v9fs_create_tstat(u32 fid) struct p9_fcall *p9_create_tstat(u32 fid)
{ {
int size; int size;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
size = 4; /* fid[4] */ size = 4; /* fid[4] */
fc = v9fs_create_common(bufp, size, TSTAT); fc = p9_create_common(bufp, size, P9_TSTAT);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.tstat.fid); p9_put_int32(bufp, fid, &fc->params.tstat.fid);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_tstat);
struct v9fs_fcall *v9fs_create_twstat(u32 fid, struct v9fs_wstat *wstat, struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat,
int extended) int dotu)
{ {
int size, statsz; int size, statsz;
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct cbuf buffer; struct cbuf buffer;
struct cbuf *bufp = &buffer; struct cbuf *bufp = &buffer;
statsz = v9fs_size_wstat(wstat, extended); statsz = p9_size_wstat(wstat, dotu);
size = 4 + 2 + 2 + statsz; /* fid[4] stat[n] */ size = 4 + 2 + 2 + statsz; /* fid[4] stat[n] */
fc = v9fs_create_common(bufp, size, TWSTAT); fc = p9_create_common(bufp, size, P9_TWSTAT);
if (IS_ERR(fc)) if (IS_ERR(fc))
goto error; goto error;
v9fs_put_int32(bufp, fid, &fc->params.twstat.fid); p9_put_int32(bufp, fid, &fc->params.twstat.fid);
buf_put_int16(bufp, statsz + 2); buf_put_int16(bufp, statsz + 2);
v9fs_put_wstat(bufp, wstat, &fc->params.twstat.stat, statsz, extended); p9_put_wstat(bufp, wstat, &fc->params.twstat.stat, statsz, dotu);
if (buf_check_overflow(bufp)) { if (buf_check_overflow(bufp)) {
kfree(fc); kfree(fc);
fc = ERR_PTR(-ENOMEM); fc = ERR_PTR(-ENOMEM);
} }
error: error:
return fc; return fc;
} }
EXPORT_SYMBOL(p9_create_twstat);
/* /*
* 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);
/* /*
* linux/fs/9p/fcprint.c * net/9p/fcprint.c
* *
* Print 9P call. * Print 9P call.
* *
...@@ -25,61 +25,59 @@ ...@@ -25,61 +25,59 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <net/9p/9p.h>
#include "debug.h" #ifdef CONFIG_NET_9P_DEBUG
#include "v9fs.h"
#include "9p.h"
#include "mux.h"
static int static int
v9fs_printqid(char *buf, int buflen, struct v9fs_qid *q) p9_printqid(char *buf, int buflen, struct p9_qid *q)
{ {
int n; int n;
char b[10]; char b[10];
n = 0; n = 0;
if (q->type & V9FS_QTDIR) if (q->type & P9_QTDIR)
b[n++] = 'd'; b[n++] = 'd';
if (q->type & V9FS_QTAPPEND) if (q->type & P9_QTAPPEND)
b[n++] = 'a'; b[n++] = 'a';
if (q->type & V9FS_QTAUTH) if (q->type & P9_QTAUTH)
b[n++] = 'A'; b[n++] = 'A';
if (q->type & V9FS_QTEXCL) if (q->type & P9_QTEXCL)
b[n++] = 'l'; b[n++] = 'l';
if (q->type & V9FS_QTTMP) if (q->type & P9_QTTMP)
b[n++] = 't'; b[n++] = 't';
if (q->type & V9FS_QTSYMLINK) if (q->type & P9_QTSYMLINK)
b[n++] = 'L'; b[n++] = 'L';
b[n] = '\0'; b[n] = '\0';
return scnprintf(buf, buflen, "(%.16llx %x %s)", (long long int) q->path, return scnprintf(buf, buflen, "(%.16llx %x %s)",
q->version, b); (long long int) q->path, q->version, b);
} }
static int static int
v9fs_printperm(char *buf, int buflen, int perm) p9_printperm(char *buf, int buflen, int perm)
{ {
int n; int n;
char b[15]; char b[15];
n = 0; n = 0;
if (perm & V9FS_DMDIR) if (perm & P9_DMDIR)
b[n++] = 'd'; b[n++] = 'd';
if (perm & V9FS_DMAPPEND) if (perm & P9_DMAPPEND)
b[n++] = 'a'; b[n++] = 'a';
if (perm & V9FS_DMAUTH) if (perm & P9_DMAUTH)
b[n++] = 'A'; b[n++] = 'A';
if (perm & V9FS_DMEXCL) if (perm & P9_DMEXCL)
b[n++] = 'l'; b[n++] = 'l';
if (perm & V9FS_DMTMP) if (perm & P9_DMTMP)
b[n++] = 't'; b[n++] = 't';
if (perm & V9FS_DMDEVICE) if (perm & P9_DMDEVICE)
b[n++] = 'D'; b[n++] = 'D';
if (perm & V9FS_DMSOCKET) if (perm & P9_DMSOCKET)
b[n++] = 'S'; b[n++] = 'S';
if (perm & V9FS_DMNAMEDPIPE) if (perm & P9_DMNAMEDPIPE)
b[n++] = 'P'; b[n++] = 'P';
if (perm & V9FS_DMSYMLINK) if (perm & P9_DMSYMLINK)
b[n++] = 'L'; b[n++] = 'L';
b[n] = '\0'; b[n] = '\0';
...@@ -87,7 +85,7 @@ v9fs_printperm(char *buf, int buflen, int perm) ...@@ -87,7 +85,7 @@ v9fs_printperm(char *buf, int buflen, int perm)
} }
static int static int
v9fs_printstat(char *buf, int buflen, struct v9fs_stat *st, int extended) p9_printstat(char *buf, int buflen, struct p9_stat *st, int extended)
{ {
int n; int n;
...@@ -105,9 +103,9 @@ v9fs_printstat(char *buf, int buflen, struct v9fs_stat *st, int extended) ...@@ -105,9 +103,9 @@ v9fs_printstat(char *buf, int buflen, struct v9fs_stat *st, int extended)
n += scnprintf(buf+n, buflen-n, "(%d)", st->n_muid); n += scnprintf(buf+n, buflen-n, "(%d)", st->n_muid);
n += scnprintf(buf+n, buflen-n, " q "); n += scnprintf(buf+n, buflen-n, " q ");
n += v9fs_printqid(buf+n, buflen-n, &st->qid); n += p9_printqid(buf+n, buflen-n, &st->qid);
n += scnprintf(buf+n, buflen-n, " m "); n += scnprintf(buf+n, buflen-n, " m ");
n += v9fs_printperm(buf+n, buflen-n, st->mode); n += p9_printperm(buf+n, buflen-n, st->mode);
n += scnprintf(buf+n, buflen-n, " at %d mt %d l %lld", n += scnprintf(buf+n, buflen-n, " at %d mt %d l %lld",
st->atime, st->mtime, (long long int) st->length); st->atime, st->mtime, (long long int) st->length);
...@@ -119,7 +117,7 @@ v9fs_printstat(char *buf, int buflen, struct v9fs_stat *st, int extended) ...@@ -119,7 +117,7 @@ v9fs_printstat(char *buf, int buflen, struct v9fs_stat *st, int extended)
} }
static int static int
v9fs_dumpdata(char *buf, int buflen, u8 *data, int datalen) p9_dumpdata(char *buf, int buflen, u8 *data, int datalen)
{ {
int i, n; int i, n;
...@@ -139,13 +137,13 @@ v9fs_dumpdata(char *buf, int buflen, u8 *data, int datalen) ...@@ -139,13 +137,13 @@ v9fs_dumpdata(char *buf, int buflen, u8 *data, int datalen)
} }
static int static int
v9fs_printdata(char *buf, int buflen, u8 *data, int datalen) p9_printdata(char *buf, int buflen, u8 *data, int datalen)
{ {
return v9fs_dumpdata(buf, buflen, data, datalen<16?datalen:16); return p9_dumpdata(buf, buflen, data, datalen < 16?datalen:16);
} }
int int
v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended) p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
{ {
int i, ret, type, tag; int i, ret, type, tag;
...@@ -157,21 +155,23 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended) ...@@ -157,21 +155,23 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended)
ret = 0; ret = 0;
switch (type) { switch (type) {
case TVERSION: case P9_TVERSION:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Tversion tag %u msize %u version '%.*s'", tag, "Tversion tag %u msize %u version '%.*s'", tag,
fc->params.tversion.msize, fc->params.tversion.version.len, fc->params.tversion.msize,
fc->params.tversion.version.str); fc->params.tversion.version.len,
fc->params.tversion.version.str);
break; break;
case RVERSION: case P9_RVERSION:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Rversion tag %u msize %u version '%.*s'", tag, "Rversion tag %u msize %u version '%.*s'", tag,
fc->params.rversion.msize, fc->params.rversion.version.len, fc->params.rversion.msize,
fc->params.rversion.version.str); fc->params.rversion.version.len,
fc->params.rversion.version.str);
break; break;
case TAUTH: case P9_TAUTH:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Tauth tag %u afid %d uname '%.*s' aname '%.*s'", tag, "Tauth tag %u afid %d uname '%.*s' aname '%.*s'", tag,
fc->params.tauth.afid, fc->params.tauth.uname.len, fc->params.tauth.afid, fc->params.tauth.uname.len,
...@@ -179,93 +179,97 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended) ...@@ -179,93 +179,97 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended)
fc->params.tauth.aname.str); fc->params.tauth.aname.str);
break; break;
case RAUTH: case P9_RAUTH:
ret += scnprintf(buf+ret, buflen-ret, "Rauth tag %u qid ", tag); ret += scnprintf(buf+ret, buflen-ret, "Rauth tag %u qid ", tag);
v9fs_printqid(buf+ret, buflen-ret, &fc->params.rauth.qid); p9_printqid(buf+ret, buflen-ret, &fc->params.rauth.qid);
break; break;
case TATTACH: case P9_TATTACH:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Tattach tag %u fid %d afid %d uname '%.*s' aname '%.*s'", "Tattach tag %u fid %d afid %d uname '%.*s' aname '%.*s'", tag,
tag, fc->params.tattach.fid, fc->params.tattach.afid, fc->params.tattach.fid, fc->params.tattach.afid,
fc->params.tattach.uname.len, fc->params.tattach.uname.str, fc->params.tattach.uname.len, fc->params.tattach.uname.str,
fc->params.tattach.aname.len, fc->params.tattach.aname.str); fc->params.tattach.aname.len, fc->params.tattach.aname.str);
break; break;
case RATTACH: case P9_RATTACH:
ret += scnprintf(buf+ret, buflen-ret, "Rattach tag %u qid ", tag); ret += scnprintf(buf+ret, buflen-ret, "Rattach tag %u qid ",
v9fs_printqid(buf+ret, buflen-ret, &fc->params.rattach.qid); tag);
p9_printqid(buf+ret, buflen-ret, &fc->params.rattach.qid);
break; break;
case RERROR: case P9_RERROR:
ret += scnprintf(buf+ret, buflen-ret, "Rerror tag %u ename '%.*s'", ret += scnprintf(buf+ret, buflen-ret,
tag, fc->params.rerror.error.len, "Rerror tag %u ename '%.*s'", tag,
fc->params.rerror.error.str); fc->params.rerror.error.len,
fc->params.rerror.error.str);
if (extended) if (extended)
ret += scnprintf(buf+ret, buflen-ret, " ecode %d\n", ret += scnprintf(buf+ret, buflen-ret, " ecode %d\n",
fc->params.rerror.errno); fc->params.rerror.errno);
break; break;
case TFLUSH: case P9_TFLUSH:
ret += scnprintf(buf+ret, buflen-ret, "Tflush tag %u oldtag %u", ret += scnprintf(buf+ret, buflen-ret, "Tflush tag %u oldtag %u",
tag, fc->params.tflush.oldtag); tag, fc->params.tflush.oldtag);
break; break;
case RFLUSH: case P9_RFLUSH:
ret += scnprintf(buf+ret, buflen-ret, "Rflush tag %u", tag); ret += scnprintf(buf+ret, buflen-ret, "Rflush tag %u", tag);
break; break;
case TWALK: case P9_TWALK:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Twalk tag %u fid %d newfid %d nwname %d", tag, "Twalk tag %u fid %d newfid %d nwname %d", tag,
fc->params.twalk.fid, fc->params.twalk.newfid, fc->params.twalk.fid, fc->params.twalk.newfid,
fc->params.twalk.nwname); fc->params.twalk.nwname);
for(i = 0; i < fc->params.twalk.nwname; i++) for (i = 0; i < fc->params.twalk.nwname; i++)
ret += scnprintf(buf+ret, buflen-ret," '%.*s'", ret += scnprintf(buf+ret, buflen-ret, " '%.*s'",
fc->params.twalk.wnames[i].len, fc->params.twalk.wnames[i].len,
fc->params.twalk.wnames[i].str); fc->params.twalk.wnames[i].str);
break; break;
case RWALK: case P9_RWALK:
ret += scnprintf(buf+ret, buflen-ret, "Rwalk tag %u nwqid %d", ret += scnprintf(buf+ret, buflen-ret, "Rwalk tag %u nwqid %d",
tag, fc->params.rwalk.nwqid); tag, fc->params.rwalk.nwqid);
for(i = 0; i < fc->params.rwalk.nwqid; i++) for (i = 0; i < fc->params.rwalk.nwqid; i++)
ret += v9fs_printqid(buf+ret, buflen-ret, ret += p9_printqid(buf+ret, buflen-ret,
&fc->params.rwalk.wqids[i]); &fc->params.rwalk.wqids[i]);
break; break;
case TOPEN: case P9_TOPEN:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Topen tag %u fid %d mode %d", tag, "Topen tag %u fid %d mode %d", tag,
fc->params.topen.fid, fc->params.topen.mode); fc->params.topen.fid, fc->params.topen.mode);
break; break;
case ROPEN: case P9_ROPEN:
ret += scnprintf(buf+ret, buflen-ret, "Ropen tag %u", tag); ret += scnprintf(buf+ret, buflen-ret, "Ropen tag %u", tag);
ret += v9fs_printqid(buf+ret, buflen-ret, &fc->params.ropen.qid); ret += p9_printqid(buf+ret, buflen-ret, &fc->params.ropen.qid);
ret += scnprintf(buf+ret, buflen-ret," iounit %d", ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
fc->params.ropen.iounit); fc->params.ropen.iounit);
break; break;
case TCREATE: case P9_TCREATE:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Tcreate tag %u fid %d name '%.*s' perm ", tag, "Tcreate tag %u fid %d name '%.*s' perm ", tag,
fc->params.tcreate.fid, fc->params.tcreate.name.len, fc->params.tcreate.fid, fc->params.tcreate.name.len,
fc->params.tcreate.name.str); fc->params.tcreate.name.str);
ret += v9fs_printperm(buf+ret, buflen-ret, fc->params.tcreate.perm); ret += p9_printperm(buf+ret, buflen-ret,
fc->params.tcreate.perm);
ret += scnprintf(buf+ret, buflen-ret, " mode %d", ret += scnprintf(buf+ret, buflen-ret, " mode %d",
fc->params.tcreate.mode); fc->params.tcreate.mode);
break; break;
case RCREATE: case P9_RCREATE:
ret += scnprintf(buf+ret, buflen-ret, "Rcreate tag %u", tag); ret += scnprintf(buf+ret, buflen-ret, "Rcreate tag %u", tag);
ret += v9fs_printqid(buf+ret, buflen-ret, &fc->params.rcreate.qid); ret += p9_printqid(buf+ret, buflen-ret,
&fc->params.rcreate.qid);
ret += scnprintf(buf+ret, buflen-ret, " iounit %d", ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
fc->params.rcreate.iounit); fc->params.rcreate.iounit);
break; break;
case TREAD: case P9_TREAD:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Tread tag %u fid %d offset %lld count %u", tag, "Tread tag %u fid %d offset %lld count %u", tag,
fc->params.tread.fid, fc->params.tread.fid,
...@@ -273,66 +277,66 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended) ...@@ -273,66 +277,66 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended)
fc->params.tread.count); fc->params.tread.count);
break; break;
case RREAD: case P9_RREAD:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Rread tag %u count %u data ", tag, "Rread tag %u count %u data ", tag,
fc->params.rread.count); fc->params.rread.count);
ret += v9fs_printdata(buf+ret, buflen-ret, fc->params.rread.data, ret += p9_printdata(buf+ret, buflen-ret, fc->params.rread.data,
fc->params.rread.count); fc->params.rread.count);
break; break;
case TWRITE: case P9_TWRITE:
ret += scnprintf(buf+ret, buflen-ret, ret += scnprintf(buf+ret, buflen-ret,
"Twrite tag %u fid %d offset %lld count %u data ", "Twrite tag %u fid %d offset %lld count %u data ",
tag, fc->params.twrite.fid, tag, fc->params.twrite.fid,
(long long int) fc->params.twrite.offset, (long long int) fc->params.twrite.offset,
fc->params.twrite.count); fc->params.twrite.count);
ret += v9fs_printdata(buf+ret, buflen-ret, fc->params.twrite.data, ret += p9_printdata(buf+ret, buflen-ret, fc->params.twrite.data,
fc->params.twrite.count); fc->params.twrite.count);
break; break;
case RWRITE: case P9_RWRITE:
ret += scnprintf(buf+ret, buflen-ret, "Rwrite tag %u count %u", ret += scnprintf(buf+ret, buflen-ret, "Rwrite tag %u count %u",
tag, fc->params.rwrite.count); tag, fc->params.rwrite.count);
break; break;
case TCLUNK: case P9_TCLUNK:
ret += scnprintf(buf+ret, buflen-ret, "Tclunk tag %u fid %d", ret += scnprintf(buf+ret, buflen-ret, "Tclunk tag %u fid %d",
tag, fc->params.tclunk.fid); tag, fc->params.tclunk.fid);
break; break;
case RCLUNK: case P9_RCLUNK:
ret += scnprintf(buf+ret, buflen-ret, "Rclunk tag %u", tag); ret += scnprintf(buf+ret, buflen-ret, "Rclunk tag %u", tag);
break; break;
case TREMOVE: case P9_TREMOVE:
ret += scnprintf(buf+ret, buflen-ret, "Tremove tag %u fid %d", ret += scnprintf(buf+ret, buflen-ret, "Tremove tag %u fid %d",
tag, fc->params.tremove.fid); tag, fc->params.tremove.fid);
break; break;
case RREMOVE: case P9_RREMOVE:
ret += scnprintf(buf+ret, buflen-ret, "Rremove tag %u", tag); ret += scnprintf(buf+ret, buflen-ret, "Rremove tag %u", tag);
break; break;
case TSTAT: case P9_TSTAT:
ret += scnprintf(buf+ret, buflen-ret, "Tstat tag %u fid %d", ret += scnprintf(buf+ret, buflen-ret, "Tstat tag %u fid %d",
tag, fc->params.tstat.fid); tag, fc->params.tstat.fid);
break; break;
case RSTAT: case P9_RSTAT:
ret += scnprintf(buf+ret, buflen-ret, "Rstat tag %u ", tag); ret += scnprintf(buf+ret, buflen-ret, "Rstat tag %u ", tag);
ret += v9fs_printstat(buf+ret, buflen-ret, &fc->params.rstat.stat, ret += p9_printstat(buf+ret, buflen-ret, &fc->params.rstat.stat,
extended); extended);
break; break;
case TWSTAT: case P9_TWSTAT:
ret += scnprintf(buf+ret, buflen-ret, "Twstat tag %u fid %d ", ret += scnprintf(buf+ret, buflen-ret, "Twstat tag %u fid %d ",
tag, fc->params.twstat.fid); tag, fc->params.twstat.fid);
ret += v9fs_printstat(buf+ret, buflen-ret, &fc->params.twstat.stat, ret += p9_printstat(buf+ret, buflen-ret,
extended); &fc->params.twstat.stat, extended);
break; break;
case RWSTAT: case P9_RWSTAT:
ret += scnprintf(buf+ret, buflen-ret, "Rwstat tag %u", tag); ret += scnprintf(buf+ret, buflen-ret, "Rwstat tag %u", tag);
break; break;
...@@ -343,3 +347,12 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended) ...@@ -343,3 +347,12 @@ v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended)
return ret; return ret;
} }
#else
int
p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
{
return 0;
}
EXPORT_SYMBOL(p9_printfcall);
#endif /* CONFIG_NET_9P_DEBUG */
/* /*
* 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");
/* /*
* linux/fs/9p/mux.c * net/9p/mux.c
* *
* Protocol Multiplexer * Protocol Multiplexer
* *
...@@ -30,13 +30,9 @@ ...@@ -30,13 +30,9 @@
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <net/9p/9p.h>
#include "debug.h" #include <net/9p/transport.h>
#include "v9fs.h" #include <net/9p/conn.h>
#include "9p.h"
#include "conv.h"
#include "transport.h"
#include "mux.h"
#define ERREQFLUSH 1 #define ERREQFLUSH 1
#define SCHED_TIMEOUT 10 #define SCHED_TIMEOUT 10
...@@ -55,33 +51,33 @@ enum { ...@@ -55,33 +51,33 @@ enum {
Flushed, Flushed,
}; };
struct v9fs_mux_poll_task; struct p9_mux_poll_task;
struct v9fs_req { struct p9_req {
spinlock_t lock; spinlock_t lock; /* protect request structure */
int tag; int tag;
struct v9fs_fcall *tcall; struct p9_fcall *tcall;
struct v9fs_fcall *rcall; struct p9_fcall *rcall;
int err; int err;
v9fs_mux_req_callback cb; p9_conn_req_callback cb;
void *cba; void *cba;
int flush; int flush;
struct list_head req_list; struct list_head req_list;
}; };
struct v9fs_mux_data { struct p9_conn {
spinlock_t lock; spinlock_t lock; /* protect lock structure */
struct list_head mux_list; struct list_head mux_list;
struct v9fs_mux_poll_task *poll_task; struct p9_mux_poll_task *poll_task;
int msize; int msize;
unsigned char *extended; unsigned char *extended;
struct v9fs_transport *trans; struct p9_transport *trans;
struct v9fs_idpool tagpool; struct p9_idpool *tagpool;
int err; int err;
wait_queue_head_t equeue; wait_queue_head_t equeue;
struct list_head req_list; struct list_head req_list;
struct list_head unsent_req_list; struct list_head unsent_req_list;
struct v9fs_fcall *rcall; struct p9_fcall *rcall;
int rpos; int rpos;
char *rbuf; char *rbuf;
int wpos; int wpos;
...@@ -95,44 +91,44 @@ struct v9fs_mux_data { ...@@ -95,44 +91,44 @@ struct v9fs_mux_data {
unsigned long wsched; unsigned long wsched;
}; };
struct v9fs_mux_poll_task { struct p9_mux_poll_task {
struct task_struct *task; struct task_struct *task;
struct list_head mux_list; struct list_head mux_list;
int muxnum; int muxnum;
}; };
struct v9fs_mux_rpc { struct p9_mux_rpc {
struct v9fs_mux_data *m; struct p9_conn *m;
int err; int err;
struct v9fs_fcall *tcall; struct p9_fcall *tcall;
struct v9fs_fcall *rcall; struct p9_fcall *rcall;
wait_queue_head_t wqueue; wait_queue_head_t wqueue;
}; };
static int v9fs_poll_proc(void *); static int p9_poll_proc(void *);
static void v9fs_read_work(struct work_struct *work); static void p9_read_work(struct work_struct *work);
static void v9fs_write_work(struct work_struct *work); static void p9_write_work(struct work_struct *work);
static void v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address, static void p9_pollwait(struct file *filp, wait_queue_head_t *wait_address,
poll_table * p); poll_table * p);
static u16 v9fs_mux_get_tag(struct v9fs_mux_data *); static u16 p9_mux_get_tag(struct p9_conn *);
static void v9fs_mux_put_tag(struct v9fs_mux_data *, u16); static void p9_mux_put_tag(struct p9_conn *, u16);
static DEFINE_MUTEX(v9fs_mux_task_lock); static DEFINE_MUTEX(p9_mux_task_lock);
static struct workqueue_struct *v9fs_mux_wq; static struct workqueue_struct *p9_mux_wq;
static int v9fs_mux_num; static int p9_mux_num;
static int v9fs_mux_poll_task_num; static int p9_mux_poll_task_num;
static struct v9fs_mux_poll_task v9fs_mux_poll_tasks[100]; static struct p9_mux_poll_task p9_mux_poll_tasks[100];
int v9fs_mux_global_init(void) int p9_mux_global_init(void)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++)
v9fs_mux_poll_tasks[i].task = NULL; p9_mux_poll_tasks[i].task = NULL;
v9fs_mux_wq = create_workqueue("v9fs"); p9_mux_wq = create_workqueue("v9fs");
if (!v9fs_mux_wq) { if (!p9_mux_wq) {
printk(KERN_WARNING "v9fs: mux: creating workqueue failed\n"); printk(KERN_WARNING "v9fs: mux: creating workqueue failed\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -140,114 +136,117 @@ int v9fs_mux_global_init(void) ...@@ -140,114 +136,117 @@ int v9fs_mux_global_init(void)
return 0; return 0;
} }
void v9fs_mux_global_exit(void) void p9_mux_global_exit(void)
{ {
destroy_workqueue(v9fs_mux_wq); destroy_workqueue(p9_mux_wq);
} }
/** /**
* v9fs_mux_calc_poll_procs - calculates the number of polling procs * p9_mux_calc_poll_procs - calculates the number of polling procs
* based on the number of mounted v9fs filesystems. * based on the number of mounted v9fs filesystems.
* *
* The current implementation returns sqrt of the number of mounts. * The current implementation returns sqrt of the number of mounts.
*/ */
static int v9fs_mux_calc_poll_procs(int muxnum) static int p9_mux_calc_poll_procs(int muxnum)
{ {
int n; int n;
if (v9fs_mux_poll_task_num) if (p9_mux_poll_task_num)
n = muxnum / v9fs_mux_poll_task_num + n = muxnum / p9_mux_poll_task_num +
(muxnum % v9fs_mux_poll_task_num ? 1 : 0); (muxnum % p9_mux_poll_task_num ? 1 : 0);
else else
n = 1; n = 1;
if (n > ARRAY_SIZE(v9fs_mux_poll_tasks)) if (n > ARRAY_SIZE(p9_mux_poll_tasks))
n = ARRAY_SIZE(v9fs_mux_poll_tasks); n = ARRAY_SIZE(p9_mux_poll_tasks);
return n; return n;
} }
static int v9fs_mux_poll_start(struct v9fs_mux_data *m) static int p9_mux_poll_start(struct p9_conn *m)
{ {
int i, n; int i, n;
struct v9fs_mux_poll_task *vpt, *vptlast; struct p9_mux_poll_task *vpt, *vptlast;
struct task_struct *pproc; struct task_struct *pproc;
dprintk(DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, v9fs_mux_num, P9_DPRINTK(P9_DEBUG_MUX, "mux %p muxnum %d procnum %d\n", m, p9_mux_num,
v9fs_mux_poll_task_num); p9_mux_poll_task_num);
mutex_lock(&v9fs_mux_task_lock); mutex_lock(&p9_mux_task_lock);
n = v9fs_mux_calc_poll_procs(v9fs_mux_num + 1); n = p9_mux_calc_poll_procs(p9_mux_num + 1);
if (n > v9fs_mux_poll_task_num) { if (n > p9_mux_poll_task_num) {
for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) { for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) {
if (v9fs_mux_poll_tasks[i].task == NULL) { if (p9_mux_poll_tasks[i].task == NULL) {
vpt = &v9fs_mux_poll_tasks[i]; vpt = &p9_mux_poll_tasks[i];
dprintk(DEBUG_MUX, "create proc %p\n", vpt); P9_DPRINTK(P9_DEBUG_MUX, "create proc %p\n",
pproc = kthread_create(v9fs_poll_proc, vpt, vpt);
"v9fs-poll"); pproc = kthread_create(p9_poll_proc, vpt,
"v9fs-poll");
if (!IS_ERR(pproc)) { if (!IS_ERR(pproc)) {
vpt->task = pproc; vpt->task = pproc;
INIT_LIST_HEAD(&vpt->mux_list); INIT_LIST_HEAD(&vpt->mux_list);
vpt->muxnum = 0; vpt->muxnum = 0;
v9fs_mux_poll_task_num++; p9_mux_poll_task_num++;
wake_up_process(vpt->task); wake_up_process(vpt->task);
} }
break; break;
} }
} }
if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) if (i >= ARRAY_SIZE(p9_mux_poll_tasks))
dprintk(DEBUG_ERROR, "warning: no free poll slots\n"); P9_DPRINTK(P9_DEBUG_ERROR,
"warning: no free poll slots\n");
} }
n = (v9fs_mux_num + 1) / v9fs_mux_poll_task_num + n = (p9_mux_num + 1) / p9_mux_poll_task_num +
((v9fs_mux_num + 1) % v9fs_mux_poll_task_num ? 1 : 0); ((p9_mux_num + 1) % p9_mux_poll_task_num ? 1 : 0);
vptlast = NULL; vptlast = NULL;
for (i = 0; i < ARRAY_SIZE(v9fs_mux_poll_tasks); i++) { for (i = 0; i < ARRAY_SIZE(p9_mux_poll_tasks); i++) {
vpt = &v9fs_mux_poll_tasks[i]; vpt = &p9_mux_poll_tasks[i];
if (vpt->task != NULL) { if (vpt->task != NULL) {
vptlast = vpt; vptlast = vpt;
if (vpt->muxnum < n) { if (vpt->muxnum < n) {
dprintk(DEBUG_MUX, "put in proc %d\n", i); P9_DPRINTK(P9_DEBUG_MUX, "put in proc %d\n", i);
list_add(&m->mux_list, &vpt->mux_list); list_add(&m->mux_list, &vpt->mux_list);
vpt->muxnum++; vpt->muxnum++;
m->poll_task = vpt; m->poll_task = vpt;
memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); memset(&m->poll_waddr, 0,
init_poll_funcptr(&m->pt, v9fs_pollwait); sizeof(m->poll_waddr));
init_poll_funcptr(&m->pt, p9_pollwait);
break; break;
} }
} }
} }
if (i >= ARRAY_SIZE(v9fs_mux_poll_tasks)) { if (i >= ARRAY_SIZE(p9_mux_poll_tasks)) {
if (vptlast == NULL) if (vptlast == NULL)
return -ENOMEM; return -ENOMEM;
dprintk(DEBUG_MUX, "put in proc %d\n", i); P9_DPRINTK(P9_DEBUG_MUX, "put in proc %d\n", i);
list_add(&m->mux_list, &vptlast->mux_list); list_add(&m->mux_list, &vptlast->mux_list);
vptlast->muxnum++; vptlast->muxnum++;
m->poll_task = vptlast; m->poll_task = vptlast;
memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
init_poll_funcptr(&m->pt, v9fs_pollwait); init_poll_funcptr(&m->pt, p9_pollwait);
} }
v9fs_mux_num++; p9_mux_num++;
mutex_unlock(&v9fs_mux_task_lock); mutex_unlock(&p9_mux_task_lock);
return 0; return 0;
} }
static void v9fs_mux_poll_stop(struct v9fs_mux_data *m) static void p9_mux_poll_stop(struct p9_conn *m)
{ {
int i; int i;
struct v9fs_mux_poll_task *vpt; struct p9_mux_poll_task *vpt;
mutex_lock(&v9fs_mux_task_lock); mutex_lock(&p9_mux_task_lock);
vpt = m->poll_task; vpt = m->poll_task;
list_del(&m->mux_list); list_del(&m->mux_list);
for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
if (m->poll_waddr[i] != NULL) { if (m->poll_waddr[i] != NULL) {
remove_wait_queue(m->poll_waddr[i], &m->poll_wait[i]); remove_wait_queue(m->poll_waddr[i], &m->poll_wait[i]);
m->poll_waddr[i] = NULL; m->poll_waddr[i] = NULL;
...@@ -255,31 +254,31 @@ static void v9fs_mux_poll_stop(struct v9fs_mux_data *m) ...@@ -255,31 +254,31 @@ static void v9fs_mux_poll_stop(struct v9fs_mux_data *m)
} }
vpt->muxnum--; vpt->muxnum--;
if (!vpt->muxnum) { if (!vpt->muxnum) {
dprintk(DEBUG_MUX, "destroy proc %p\n", vpt); P9_DPRINTK(P9_DEBUG_MUX, "destroy proc %p\n", vpt);
kthread_stop(vpt->task); kthread_stop(vpt->task);
vpt->task = NULL; vpt->task = NULL;
v9fs_mux_poll_task_num--; p9_mux_poll_task_num--;
} }
v9fs_mux_num--; p9_mux_num--;
mutex_unlock(&v9fs_mux_task_lock); mutex_unlock(&p9_mux_task_lock);
} }
/** /**
* v9fs_mux_init - allocate and initialize the per-session mux data * p9_conn_create - allocate and initialize the per-session mux data
* Creates the polling task if this is the first session. * Creates the polling task if this is the first session.
* *
* @trans - transport structure * @trans - transport structure
* @msize - maximum message size * @msize - maximum message size
* @extended - pointer to the extended flag * @extended - pointer to the extended flag
*/ */
struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, struct p9_conn *p9_conn_create(struct p9_transport *trans, int msize,
unsigned char *extended) unsigned char *extended)
{ {
int i, n; int i, n;
struct v9fs_mux_data *m, *mtmp; struct p9_conn *m, *mtmp;
dprintk(DEBUG_MUX, "transport %p msize %d\n", trans, msize); P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans, msize);
m = kmalloc(sizeof(struct v9fs_mux_data), GFP_KERNEL); m = kmalloc(sizeof(struct p9_conn), GFP_KERNEL);
if (!m) if (!m)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -288,8 +287,12 @@ struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, ...@@ -288,8 +287,12 @@ struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize,
m->msize = msize; m->msize = msize;
m->extended = extended; m->extended = extended;
m->trans = trans; m->trans = trans;
idr_init(&m->tagpool.pool); m->tagpool = p9_idpool_create();
init_MUTEX(&m->tagpool.lock); if (!m->tagpool) {
kfree(m);
return ERR_PTR(PTR_ERR(m->tagpool));
}
m->err = 0; m->err = 0;
init_waitqueue_head(&m->equeue); init_waitqueue_head(&m->equeue);
INIT_LIST_HEAD(&m->req_list); INIT_LIST_HEAD(&m->req_list);
...@@ -299,29 +302,29 @@ struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, ...@@ -299,29 +302,29 @@ struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize,
m->rbuf = NULL; m->rbuf = NULL;
m->wpos = m->wsize = 0; m->wpos = m->wsize = 0;
m->wbuf = NULL; m->wbuf = NULL;
INIT_WORK(&m->rq, v9fs_read_work); INIT_WORK(&m->rq, p9_read_work);
INIT_WORK(&m->wq, v9fs_write_work); INIT_WORK(&m->wq, p9_write_work);
m->wsched = 0; m->wsched = 0;
memset(&m->poll_waddr, 0, sizeof(m->poll_waddr)); memset(&m->poll_waddr, 0, sizeof(m->poll_waddr));
m->poll_task = NULL; m->poll_task = NULL;
n = v9fs_mux_poll_start(m); n = p9_mux_poll_start(m);
if (n) if (n)
return ERR_PTR(n); return ERR_PTR(n);
n = trans->poll(trans, &m->pt); n = trans->poll(trans, &m->pt);
if (n & POLLIN) { if (n & POLLIN) {
dprintk(DEBUG_MUX, "mux %p can read\n", m); P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
set_bit(Rpending, &m->wsched); set_bit(Rpending, &m->wsched);
} }
if (n & POLLOUT) { if (n & POLLOUT) {
dprintk(DEBUG_MUX, "mux %p can write\n", m); P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m);
set_bit(Wpending, &m->wsched); set_bit(Wpending, &m->wsched);
} }
for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) { for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) {
if (IS_ERR(m->poll_waddr[i])) { if (IS_ERR(m->poll_waddr[i])) {
v9fs_mux_poll_stop(m); p9_mux_poll_stop(m);
mtmp = (void *)m->poll_waddr; /* the error code */ mtmp = (void *)m->poll_waddr; /* the error code */
kfree(m); kfree(m);
m = mtmp; m = mtmp;
...@@ -331,56 +334,58 @@ struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize, ...@@ -331,56 +334,58 @@ struct v9fs_mux_data *v9fs_mux_init(struct v9fs_transport *trans, int msize,
return m; return m;
} }
EXPORT_SYMBOL(p9_conn_create);
/** /**
* v9fs_mux_destroy - cancels all pending requests and frees mux resources * p9_mux_destroy - cancels all pending requests and frees mux resources
*/ */
void v9fs_mux_destroy(struct v9fs_mux_data *m) void p9_conn_destroy(struct p9_conn *m)
{ {
dprintk(DEBUG_MUX, "mux %p prev %p next %p\n", m, P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m,
m->mux_list.prev, m->mux_list.next); m->mux_list.prev, m->mux_list.next);
v9fs_mux_cancel(m, -ECONNRESET); p9_conn_cancel(m, -ECONNRESET);
if (!list_empty(&m->req_list)) { if (!list_empty(&m->req_list)) {
/* wait until all processes waiting on this session exit */ /* wait until all processes waiting on this session exit */
dprintk(DEBUG_MUX, "mux %p waiting for empty request queue\n", P9_DPRINTK(P9_DEBUG_MUX,
m); "mux %p waiting for empty request queue\n", m);
wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000); wait_event_timeout(m->equeue, (list_empty(&m->req_list)), 5000);
dprintk(DEBUG_MUX, "mux %p request queue empty: %d\n", m, P9_DPRINTK(P9_DEBUG_MUX, "mux %p request queue empty: %d\n", m,
list_empty(&m->req_list)); list_empty(&m->req_list));
} }
v9fs_mux_poll_stop(m); p9_mux_poll_stop(m);
m->trans = NULL; m->trans = NULL;
p9_idpool_destroy(m->tagpool);
kfree(m); kfree(m);
} }
EXPORT_SYMBOL(p9_conn_destroy);
/** /**
* v9fs_pollwait - called by files poll operation to add v9fs-poll task * p9_pollwait - called by files poll operation to add v9fs-poll task
* to files wait queue * to files wait queue
*/ */
static void static void
v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address, p9_pollwait(struct file *filp, wait_queue_head_t *wait_address,
poll_table * p) poll_table * p)
{ {
int i; int i;
struct v9fs_mux_data *m; struct p9_conn *m;
m = container_of(p, struct v9fs_mux_data, pt); m = container_of(p, struct p9_conn, pt);
for(i = 0; i < ARRAY_SIZE(m->poll_waddr); i++) for (i = 0; i < ARRAY_SIZE(m->poll_waddr); i++)
if (m->poll_waddr[i] == NULL) if (m->poll_waddr[i] == NULL)
break; break;
if (i >= ARRAY_SIZE(m->poll_waddr)) { if (i >= ARRAY_SIZE(m->poll_waddr)) {
dprintk(DEBUG_ERROR, "not enough wait_address slots\n"); P9_DPRINTK(P9_DEBUG_ERROR, "not enough wait_address slots\n");
return; return;
} }
m->poll_waddr[i] = wait_address; m->poll_waddr[i] = wait_address;
if (!wait_address) { if (!wait_address) {
dprintk(DEBUG_ERROR, "no wait_address\n"); P9_DPRINTK(P9_DEBUG_ERROR, "no wait_address\n");
m->poll_waddr[i] = ERR_PTR(-EIO); m->poll_waddr[i] = ERR_PTR(-EIO);
return; return;
} }
...@@ -390,9 +395,9 @@ v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address, ...@@ -390,9 +395,9 @@ v9fs_pollwait(struct file *filp, wait_queue_head_t * wait_address,
} }
/** /**
* v9fs_poll_mux - polls a mux and schedules read or write works if necessary * p9_poll_mux - polls a mux and schedules read or write works if necessary
*/ */
static void v9fs_poll_mux(struct v9fs_mux_data *m) static void p9_poll_mux(struct p9_conn *m)
{ {
int n; int n;
...@@ -401,69 +406,69 @@ static void v9fs_poll_mux(struct v9fs_mux_data *m) ...@@ -401,69 +406,69 @@ static void v9fs_poll_mux(struct v9fs_mux_data *m)
n = m->trans->poll(m->trans, NULL); n = m->trans->poll(m->trans, NULL);
if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) { if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) {
dprintk(DEBUG_MUX, "error mux %p err %d\n", m, n); P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n);
if (n >= 0) if (n >= 0)
n = -ECONNRESET; n = -ECONNRESET;
v9fs_mux_cancel(m, n); p9_conn_cancel(m, n);
} }
if (n & POLLIN) { if (n & POLLIN) {
set_bit(Rpending, &m->wsched); set_bit(Rpending, &m->wsched);
dprintk(DEBUG_MUX, "mux %p can read\n", m); P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
if (!test_and_set_bit(Rworksched, &m->wsched)) { if (!test_and_set_bit(Rworksched, &m->wsched)) {
dprintk(DEBUG_MUX, "schedule read work mux %p\n", m); P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
queue_work(v9fs_mux_wq, &m->rq); queue_work(p9_mux_wq, &m->rq);
} }
} }
if (n & POLLOUT) { if (n & POLLOUT) {
set_bit(Wpending, &m->wsched); set_bit(Wpending, &m->wsched);
dprintk(DEBUG_MUX, "mux %p can write\n", m); P9_DPRINTK(P9_DEBUG_MUX, "mux %p can write\n", m);
if ((m->wsize || !list_empty(&m->unsent_req_list)) if ((m->wsize || !list_empty(&m->unsent_req_list))
&& !test_and_set_bit(Wworksched, &m->wsched)) { && !test_and_set_bit(Wworksched, &m->wsched)) {
dprintk(DEBUG_MUX, "schedule write work mux %p\n", m); P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
queue_work(v9fs_mux_wq, &m->wq); queue_work(p9_mux_wq, &m->wq);
} }
} }
} }
/** /**
* v9fs_poll_proc - polls all v9fs transports for new events and queues * p9_poll_proc - polls all v9fs transports for new events and queues
* the appropriate work to the work queue * the appropriate work to the work queue
*/ */
static int v9fs_poll_proc(void *a) static int p9_poll_proc(void *a)
{ {
struct v9fs_mux_data *m, *mtmp; struct p9_conn *m, *mtmp;
struct v9fs_mux_poll_task *vpt; struct p9_mux_poll_task *vpt;
vpt = a; vpt = a;
dprintk(DEBUG_MUX, "start %p %p\n", current, vpt); P9_DPRINTK(P9_DEBUG_MUX, "start %p %p\n", current, vpt);
while (!kthread_should_stop()) { while (!kthread_should_stop()) {
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
list_for_each_entry_safe(m, mtmp, &vpt->mux_list, mux_list) { list_for_each_entry_safe(m, mtmp, &vpt->mux_list, mux_list) {
v9fs_poll_mux(m); p9_poll_mux(m);
} }
dprintk(DEBUG_MUX, "sleeping...\n"); P9_DPRINTK(P9_DEBUG_MUX, "sleeping...\n");
schedule_timeout(SCHED_TIMEOUT * HZ); schedule_timeout(SCHED_TIMEOUT * HZ);
} }
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
dprintk(DEBUG_MUX, "finish\n"); P9_DPRINTK(P9_DEBUG_MUX, "finish\n");
return 0; return 0;
} }
/** /**
* v9fs_write_work - called when a transport can send some data * p9_write_work - called when a transport can send some data
*/ */
static void v9fs_write_work(struct work_struct *work) static void p9_write_work(struct work_struct *work)
{ {
int n, err; int n, err;
struct v9fs_mux_data *m; struct p9_conn *m;
struct v9fs_req *req; struct p9_req *req;
m = container_of(work, struct v9fs_mux_data, wq); m = container_of(work, struct p9_conn, wq);
if (m->err < 0) { if (m->err < 0) {
clear_bit(Wworksched, &m->wsched); clear_bit(Wworksched, &m->wsched);
...@@ -478,7 +483,7 @@ static void v9fs_write_work(struct work_struct *work) ...@@ -478,7 +483,7 @@ static void v9fs_write_work(struct work_struct *work)
spin_lock(&m->lock); spin_lock(&m->lock);
again: again:
req = list_entry(m->unsent_req_list.next, struct v9fs_req, req = list_entry(m->unsent_req_list.next, struct p9_req,
req_list); req_list);
list_move_tail(&req->req_list, &m->req_list); list_move_tail(&req->req_list, &m->req_list);
if (req->err == ERREQFLUSH) if (req->err == ERREQFLUSH)
...@@ -487,21 +492,25 @@ static void v9fs_write_work(struct work_struct *work) ...@@ -487,21 +492,25 @@ static void v9fs_write_work(struct work_struct *work)
m->wbuf = req->tcall->sdata; m->wbuf = req->tcall->sdata;
m->wsize = req->tcall->size; m->wsize = req->tcall->size;
m->wpos = 0; m->wpos = 0;
dump_data(m->wbuf, m->wsize);
spin_unlock(&m->lock); spin_unlock(&m->lock);
} }
dprintk(DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos, m->wsize); P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos,
m->wsize);
clear_bit(Wpending, &m->wsched); clear_bit(Wpending, &m->wsched);
err = m->trans->write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos); err = m->trans->write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos);
dprintk(DEBUG_MUX, "mux %p sent %d bytes\n", m, err); P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err);
if (err == -EAGAIN) { if (err == -EAGAIN) {
clear_bit(Wworksched, &m->wsched); clear_bit(Wworksched, &m->wsched);
return; return;
} }
if (err <= 0) if (err < 0)
goto error;
else if (err == 0) {
err = -EREMOTEIO;
goto error; goto error;
}
m->wpos += err; m->wpos += err;
if (m->wpos == m->wsize) if (m->wpos == m->wsize)
...@@ -514,8 +523,8 @@ static void v9fs_write_work(struct work_struct *work) ...@@ -514,8 +523,8 @@ static void v9fs_write_work(struct work_struct *work)
n = m->trans->poll(m->trans, NULL); n = m->trans->poll(m->trans, NULL);
if (n & POLLOUT) { if (n & POLLOUT) {
dprintk(DEBUG_MUX, "schedule write work mux %p\n", m); P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
queue_work(v9fs_mux_wq, &m->wq); queue_work(p9_mux_wq, &m->wq);
} else } else
clear_bit(Wworksched, &m->wsched); clear_bit(Wworksched, &m->wsched);
} else } else
...@@ -523,27 +532,28 @@ static void v9fs_write_work(struct work_struct *work) ...@@ -523,27 +532,28 @@ static void v9fs_write_work(struct work_struct *work)
return; return;
error: error:
v9fs_mux_cancel(m, err); p9_conn_cancel(m, err);
clear_bit(Wworksched, &m->wsched); clear_bit(Wworksched, &m->wsched);
} }
static void process_request(struct v9fs_mux_data *m, struct v9fs_req *req) static void process_request(struct p9_conn *m, struct p9_req *req)
{ {
int ecode; int ecode;
struct v9fs_str *ename; struct p9_str *ename;
if (!req->err && req->rcall->id == RERROR) { if (!req->err && req->rcall->id == P9_RERROR) {
ecode = req->rcall->params.rerror.errno; ecode = req->rcall->params.rerror.errno;
ename = &req->rcall->params.rerror.error; ename = &req->rcall->params.rerror.error;
dprintk(DEBUG_MUX, "Rerror %.*s\n", ename->len, ename->str); P9_DPRINTK(P9_DEBUG_MUX, "Rerror %.*s\n", ename->len,
ename->str);
if (*m->extended) if (*m->extended)
req->err = -ecode; req->err = -ecode;
if (!req->err) { if (!req->err) {
req->err = v9fs_errstr2errno(ename->str, ename->len); req->err = p9_errstr2errno(ename->str, ename->len);
if (!req->err) { /* string match failed */ if (!req->err) { /* string match failed */
PRINT_FCALL_ERROR("unknown error", req->rcall); PRINT_FCALL_ERROR("unknown error", req->rcall);
...@@ -553,47 +563,48 @@ static void process_request(struct v9fs_mux_data *m, struct v9fs_req *req) ...@@ -553,47 +563,48 @@ static void process_request(struct v9fs_mux_data *m, struct v9fs_req *req)
req->err = -ESERVERFAULT; req->err = -ESERVERFAULT;
} }
} else if (req->tcall && req->rcall->id != req->tcall->id + 1) { } else if (req->tcall && req->rcall->id != req->tcall->id + 1) {
dprintk(DEBUG_ERROR, "fcall mismatch: expected %d, got %d\n", P9_DPRINTK(P9_DEBUG_ERROR,
req->tcall->id + 1, req->rcall->id); "fcall mismatch: expected %d, got %d\n",
req->tcall->id + 1, req->rcall->id);
if (!req->err) if (!req->err)
req->err = -EIO; req->err = -EIO;
} }
} }
/** /**
* v9fs_read_work - called when there is some data to be read from a transport * p9_read_work - called when there is some data to be read from a transport
*/ */
static void v9fs_read_work(struct work_struct *work) static void p9_read_work(struct work_struct *work)
{ {
int n, err; int n, err;
struct v9fs_mux_data *m; struct p9_conn *m;
struct v9fs_req *req, *rptr, *rreq; struct p9_req *req, *rptr, *rreq;
struct v9fs_fcall *rcall; struct p9_fcall *rcall;
char *rbuf; char *rbuf;
m = container_of(work, struct v9fs_mux_data, rq); m = container_of(work, struct p9_conn, rq);
if (m->err < 0) if (m->err < 0)
return; return;
rcall = NULL; rcall = NULL;
dprintk(DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos); P9_DPRINTK(P9_DEBUG_MUX, "start mux %p pos %d\n", m, m->rpos);
if (!m->rcall) { if (!m->rcall) {
m->rcall = m->rcall =
kmalloc(sizeof(struct v9fs_fcall) + m->msize, GFP_KERNEL); kmalloc(sizeof(struct p9_fcall) + m->msize, GFP_KERNEL);
if (!m->rcall) { if (!m->rcall) {
err = -ENOMEM; err = -ENOMEM;
goto error; goto error;
} }
m->rbuf = (char *)m->rcall + sizeof(struct v9fs_fcall); m->rbuf = (char *)m->rcall + sizeof(struct p9_fcall);
m->rpos = 0; m->rpos = 0;
} }
clear_bit(Rpending, &m->wsched); clear_bit(Rpending, &m->wsched);
err = m->trans->read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos); err = m->trans->read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos);
dprintk(DEBUG_MUX, "mux %p got %d bytes\n", m, err); P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err);
if (err == -EAGAIN) { if (err == -EAGAIN) {
clear_bit(Rworksched, &m->wsched); clear_bit(Rworksched, &m->wsched);
return; return;
...@@ -606,7 +617,7 @@ static void v9fs_read_work(struct work_struct *work) ...@@ -606,7 +617,7 @@ static void v9fs_read_work(struct work_struct *work)
while (m->rpos > 4) { while (m->rpos > 4) {
n = le32_to_cpu(*(__le32 *) m->rbuf); n = le32_to_cpu(*(__le32 *) m->rbuf);
if (n >= m->msize) { if (n >= m->msize) {
dprintk(DEBUG_ERROR, P9_DPRINTK(P9_DEBUG_ERROR,
"requested packet size too big: %d\n", n); "requested packet size too big: %d\n", n);
err = -EIO; err = -EIO;
goto error; goto error;
...@@ -615,32 +626,33 @@ static void v9fs_read_work(struct work_struct *work) ...@@ -615,32 +626,33 @@ static void v9fs_read_work(struct work_struct *work)
if (m->rpos < n) if (m->rpos < n)
break; break;
dump_data(m->rbuf, n);
err = err =
v9fs_deserialize_fcall(m->rbuf, n, m->rcall, *m->extended); p9_deserialize_fcall(m->rbuf, n, m->rcall, *m->extended);
if (err < 0) { if (err < 0) {
goto error; goto error;
} }
if ((v9fs_debug_level&DEBUG_FCALL) == DEBUG_FCALL) { #ifdef CONFIG_NET_9P_DEBUG
if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
char buf[150]; char buf[150];
v9fs_printfcall(buf, sizeof(buf), m->rcall, p9_printfcall(buf, sizeof(buf), m->rcall,
*m->extended); *m->extended);
printk(KERN_NOTICE ">>> %p %s\n", m, buf); printk(KERN_NOTICE ">>> %p %s\n", m, buf);
} }
#endif
rcall = m->rcall; rcall = m->rcall;
rbuf = m->rbuf; rbuf = m->rbuf;
if (m->rpos > n) { if (m->rpos > n) {
m->rcall = kmalloc(sizeof(struct v9fs_fcall) + m->msize, m->rcall = kmalloc(sizeof(struct p9_fcall) + m->msize,
GFP_KERNEL); GFP_KERNEL);
if (!m->rcall) { if (!m->rcall) {
err = -ENOMEM; err = -ENOMEM;
goto error; goto error;
} }
m->rbuf = (char *)m->rcall + sizeof(struct v9fs_fcall); m->rbuf = (char *)m->rcall + sizeof(struct p9_fcall);
memmove(m->rbuf, rbuf + n, m->rpos - n); memmove(m->rbuf, rbuf + n, m->rpos - n);
m->rpos -= n; m->rpos -= n;
} else { } else {
...@@ -649,8 +661,8 @@ static void v9fs_read_work(struct work_struct *work) ...@@ -649,8 +661,8 @@ static void v9fs_read_work(struct work_struct *work)
m->rpos = 0; m->rpos = 0;
} }
dprintk(DEBUG_MUX, "mux %p fcall id %d tag %d\n", m, rcall->id, P9_DPRINTK(P9_DEBUG_MUX, "mux %p fcall id %d tag %d\n", m,
rcall->tag); rcall->id, rcall->tag);
req = NULL; req = NULL;
spin_lock(&m->lock); spin_lock(&m->lock);
...@@ -677,10 +689,10 @@ static void v9fs_read_work(struct work_struct *work) ...@@ -677,10 +689,10 @@ static void v9fs_read_work(struct work_struct *work)
wake_up(&m->equeue); wake_up(&m->equeue);
} }
} else { } else {
if (err >= 0 && rcall->id != RFLUSH) if (err >= 0 && rcall->id != P9_RFLUSH)
dprintk(DEBUG_ERROR, P9_DPRINTK(P9_DEBUG_ERROR,
"unexpected response mux %p id %d tag %d\n", "unexpected response mux %p id %d tag %d\n",
m, rcall->id, rcall->tag); m, rcall->id, rcall->tag);
kfree(rcall); kfree(rcall);
} }
} }
...@@ -692,8 +704,8 @@ static void v9fs_read_work(struct work_struct *work) ...@@ -692,8 +704,8 @@ static void v9fs_read_work(struct work_struct *work)
n = m->trans->poll(m->trans, NULL); n = m->trans->poll(m->trans, NULL);
if (n & POLLIN) { if (n & POLLIN) {
dprintk(DEBUG_MUX, "schedule read work mux %p\n", m); P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
queue_work(v9fs_mux_wq, &m->rq); queue_work(p9_mux_wq, &m->rq);
} else } else
clear_bit(Rworksched, &m->wsched); clear_bit(Rworksched, &m->wsched);
} else } else
...@@ -701,13 +713,13 @@ static void v9fs_read_work(struct work_struct *work) ...@@ -701,13 +713,13 @@ static void v9fs_read_work(struct work_struct *work)
return; return;
error: error:
v9fs_mux_cancel(m, err); p9_conn_cancel(m, err);
clear_bit(Rworksched, &m->wsched); clear_bit(Rworksched, &m->wsched);
} }
/** /**
* v9fs_send_request - send 9P request * p9_send_request - send 9P request
* The function can sleep until the request is scheduled for sending. * The function can sleep until the request is scheduled for sending.
* The function can be interrupted. Return from the function is not * The function can be interrupted. Return from the function is not
* a guarantee that the request is sent successfully. Can return errors * a guarantee that the request is sent successfully. Can return errors
...@@ -718,37 +730,40 @@ static void v9fs_read_work(struct work_struct *work) ...@@ -718,37 +730,40 @@ static void v9fs_read_work(struct work_struct *work)
* @cb: callback function to call when response is received * @cb: callback function to call when response is received
* @cba: parameter to pass to the callback function * @cba: parameter to pass to the callback function
*/ */
static struct v9fs_req *v9fs_send_request(struct v9fs_mux_data *m, static struct p9_req *p9_send_request(struct p9_conn *m,
struct v9fs_fcall *tc, struct p9_fcall *tc,
v9fs_mux_req_callback cb, void *cba) p9_conn_req_callback cb, void *cba)
{ {
int n; int n;
struct v9fs_req *req; struct p9_req *req;
dprintk(DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current, P9_DPRINTK(P9_DEBUG_MUX, "mux %p task %p tcall %p id %d\n", m, current,
tc, tc->id); tc, tc->id);
if (m->err < 0) if (m->err < 0)
return ERR_PTR(m->err); return ERR_PTR(m->err);
req = kmalloc(sizeof(struct v9fs_req), GFP_KERNEL); req = kmalloc(sizeof(struct p9_req), GFP_KERNEL);
if (!req) if (!req)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (tc->id == TVERSION) if (tc->id == P9_TVERSION)
n = V9FS_NOTAG; n = P9_NOTAG;
else else
n = v9fs_mux_get_tag(m); n = p9_mux_get_tag(m);
if (n < 0) if (n < 0)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
v9fs_set_tag(tc, n); p9_set_tag(tc, n);
if ((v9fs_debug_level&DEBUG_FCALL) == DEBUG_FCALL) {
#ifdef CONFIG_NET_9P_DEBUG
if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
char buf[150]; char buf[150];
v9fs_printfcall(buf, sizeof(buf), tc, *m->extended); p9_printfcall(buf, sizeof(buf), tc, *m->extended);
printk(KERN_NOTICE "<<< %p %s\n", m, buf); printk(KERN_NOTICE "<<< %p %s\n", m, buf);
} }
#endif
spin_lock_init(&req->lock); spin_lock_init(&req->lock);
req->tag = n; req->tag = n;
...@@ -769,26 +784,26 @@ static struct v9fs_req *v9fs_send_request(struct v9fs_mux_data *m, ...@@ -769,26 +784,26 @@ static struct v9fs_req *v9fs_send_request(struct v9fs_mux_data *m,
n = m->trans->poll(m->trans, NULL); n = m->trans->poll(m->trans, NULL);
if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched)) if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
queue_work(v9fs_mux_wq, &m->wq); queue_work(p9_mux_wq, &m->wq);
return req; return req;
} }
static void v9fs_mux_free_request(struct v9fs_mux_data *m, struct v9fs_req *req) static void p9_mux_free_request(struct p9_conn *m, struct p9_req *req)
{ {
v9fs_mux_put_tag(m, req->tag); p9_mux_put_tag(m, req->tag);
kfree(req); kfree(req);
} }
static void v9fs_mux_flush_cb(struct v9fs_req *freq, void *a) static void p9_mux_flush_cb(struct p9_req *freq, void *a)
{ {
v9fs_mux_req_callback cb; p9_conn_req_callback cb;
int tag; int tag;
struct v9fs_mux_data *m; struct p9_conn *m;
struct v9fs_req *req, *rreq, *rptr; struct p9_req *req, *rreq, *rptr;
m = a; m = a;
dprintk(DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m, P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p rc %p err %d oldtag %d\n", m,
freq->tcall, freq->rcall, freq->err, freq->tcall, freq->rcall, freq->err,
freq->tcall->params.tflush.oldtag); freq->tcall->params.tflush.oldtag);
...@@ -820,22 +835,23 @@ static void v9fs_mux_flush_cb(struct v9fs_req *freq, void *a) ...@@ -820,22 +835,23 @@ static void v9fs_mux_flush_cb(struct v9fs_req *freq, void *a)
kfree(freq->tcall); kfree(freq->tcall);
kfree(freq->rcall); kfree(freq->rcall);
v9fs_mux_free_request(m, freq); p9_mux_free_request(m, freq);
} }
static int static int
v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req) p9_mux_flush_request(struct p9_conn *m, struct p9_req *req)
{ {
struct v9fs_fcall *fc; struct p9_fcall *fc;
struct v9fs_req *rreq, *rptr; struct p9_req *rreq, *rptr;
dprintk(DEBUG_MUX, "mux %p req %p tag %d\n", m, req, req->tag); P9_DPRINTK(P9_DEBUG_MUX, "mux %p req %p tag %d\n", m, req, req->tag);
/* if a response was received for a request, do nothing */ /* if a response was received for a request, do nothing */
spin_lock(&req->lock); spin_lock(&req->lock);
if (req->rcall || req->err) { if (req->rcall || req->err) {
spin_unlock(&req->lock); spin_unlock(&req->lock);
dprintk(DEBUG_MUX, "mux %p req %p response already received\n", m, req); P9_DPRINTK(P9_DEBUG_MUX,
"mux %p req %p response already received\n", m, req);
return 0; return 0;
} }
...@@ -846,7 +862,8 @@ v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req) ...@@ -846,7 +862,8 @@ v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req)
/* if the request is not sent yet, just remove it from the list */ /* if the request is not sent yet, just remove it from the list */
list_for_each_entry_safe(rreq, rptr, &m->unsent_req_list, req_list) { list_for_each_entry_safe(rreq, rptr, &m->unsent_req_list, req_list) {
if (rreq->tag == req->tag) { if (rreq->tag == req->tag) {
dprintk(DEBUG_MUX, "mux %p req %p request is not sent yet\n", m, req); P9_DPRINTK(P9_DEBUG_MUX,
"mux %p req %p request is not sent yet\n", m, req);
list_del(&rreq->req_list); list_del(&rreq->req_list);
req->flush = Flushed; req->flush = Flushed;
spin_unlock(&m->lock); spin_unlock(&m->lock);
...@@ -858,42 +875,42 @@ v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req) ...@@ -858,42 +875,42 @@ v9fs_mux_flush_request(struct v9fs_mux_data *m, struct v9fs_req *req)
spin_unlock(&m->lock); spin_unlock(&m->lock);
clear_thread_flag(TIF_SIGPENDING); clear_thread_flag(TIF_SIGPENDING);
fc = v9fs_create_tflush(req->tag); fc = p9_create_tflush(req->tag);
v9fs_send_request(m, fc, v9fs_mux_flush_cb, m); p9_send_request(m, fc, p9_mux_flush_cb, m);
return 1; return 1;
} }
static void static void
v9fs_mux_rpc_cb(struct v9fs_req *req, void *a) p9_conn_rpc_cb(struct p9_req *req, void *a)
{ {
struct v9fs_mux_rpc *r; struct p9_mux_rpc *r;
dprintk(DEBUG_MUX, "req %p r %p\n", req, a); P9_DPRINTK(P9_DEBUG_MUX, "req %p r %p\n", req, a);
r = a; r = a;
r->rcall = req->rcall; r->rcall = req->rcall;
r->err = req->err; r->err = req->err;
if (req->flush!=None && !req->err) if (req->flush != None && !req->err)
r->err = -ERESTARTSYS; r->err = -ERESTARTSYS;
wake_up(&r->wqueue); wake_up(&r->wqueue);
} }
/** /**
* v9fs_mux_rpc - sends 9P request and waits until a response is available. * p9_mux_rpc - sends 9P request and waits until a response is available.
* The function can be interrupted. * The function can be interrupted.
* @m: mux data * @m: mux data
* @tc: request to be sent * @tc: request to be sent
* @rc: pointer where a pointer to the response is stored * @rc: pointer where a pointer to the response is stored
*/ */
int int
v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, p9_conn_rpc(struct p9_conn *m, struct p9_fcall *tc,
struct v9fs_fcall **rc) struct p9_fcall **rc)
{ {
int err, sigpending; int err, sigpending;
unsigned long flags; unsigned long flags;
struct v9fs_req *req; struct p9_req *req;
struct v9fs_mux_rpc r; struct p9_mux_rpc r;
r.err = 0; r.err = 0;
r.tcall = tc; r.tcall = tc;
...@@ -910,10 +927,10 @@ v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, ...@@ -910,10 +927,10 @@ v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc,
clear_thread_flag(TIF_SIGPENDING); clear_thread_flag(TIF_SIGPENDING);
} }
req = v9fs_send_request(m, tc, v9fs_mux_rpc_cb, &r); req = p9_send_request(m, tc, p9_conn_rpc_cb, &r);
if (IS_ERR(req)) { if (IS_ERR(req)) {
err = PTR_ERR(req); err = PTR_ERR(req);
dprintk(DEBUG_MUX, "error %d\n", err); P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err);
return err; return err;
} }
...@@ -921,15 +938,16 @@ v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, ...@@ -921,15 +938,16 @@ v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc,
if (r.err < 0) if (r.err < 0)
err = r.err; err = r.err;
if (err == -ERESTARTSYS && m->trans->status == Connected && m->err == 0) { if (err == -ERESTARTSYS && m->trans->status == Connected
if (v9fs_mux_flush_request(m, req)) { && m->err == 0) {
if (p9_mux_flush_request(m, req)) {
/* wait until we get response of the flush message */ /* wait until we get response of the flush message */
do { do {
clear_thread_flag(TIF_SIGPENDING); clear_thread_flag(TIF_SIGPENDING);
err = wait_event_interruptible(r.wqueue, err = wait_event_interruptible(r.wqueue,
r.rcall || r.err); r.rcall || r.err);
} while (!r.rcall && !r.err && err==-ERESTARTSYS && } while (!r.rcall && !r.err && err == -ERESTARTSYS &&
m->trans->status==Connected && !m->err); m->trans->status == Connected && !m->err);
err = -ERESTARTSYS; err = -ERESTARTSYS;
} }
...@@ -947,50 +965,52 @@ v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc, ...@@ -947,50 +965,52 @@ v9fs_mux_rpc(struct v9fs_mux_data *m, struct v9fs_fcall *tc,
else else
kfree(r.rcall); kfree(r.rcall);
v9fs_mux_free_request(m, req); p9_mux_free_request(m, req);
if (err > 0) if (err > 0)
err = -EIO; err = -EIO;
return err; return err;
} }
EXPORT_SYMBOL(p9_conn_rpc);
#if 0 #ifdef P9_NONBLOCK
/** /**
* v9fs_mux_rpcnb - sends 9P request without waiting for response. * p9_conn_rpcnb - sends 9P request without waiting for response.
* @m: mux data * @m: mux data
* @tc: request to be sent * @tc: request to be sent
* @cb: callback function to be called when response arrives * @cb: callback function to be called when response arrives
* @cba: value to pass to the callback function * @cba: value to pass to the callback function
*/ */
int v9fs_mux_rpcnb(struct v9fs_mux_data *m, struct v9fs_fcall *tc, int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc,
v9fs_mux_req_callback cb, void *a) p9_conn_req_callback cb, void *a)
{ {
int err; int err;
struct v9fs_req *req; struct p9_req *req;
req = v9fs_send_request(m, tc, cb, a); req = p9_send_request(m, tc, cb, a);
if (IS_ERR(req)) { if (IS_ERR(req)) {
err = PTR_ERR(req); err = PTR_ERR(req);
dprintk(DEBUG_MUX, "error %d\n", err); P9_DPRINTK(P9_DEBUG_MUX, "error %d\n", err);
return PTR_ERR(req); return PTR_ERR(req);
} }
dprintk(DEBUG_MUX, "mux %p tc %p tag %d\n", m, tc, req->tag); P9_DPRINTK(P9_DEBUG_MUX, "mux %p tc %p tag %d\n", m, tc, req->tag);
return 0; return 0;
} }
#endif /* 0 */ EXPORT_SYMBOL(p9_conn_rpcnb);
#endif /* P9_NONBLOCK */
/** /**
* v9fs_mux_cancel - cancel all pending requests with error * p9_conn_cancel - cancel all pending requests with error
* @m: mux data * @m: mux data
* @err: error code * @err: error code
*/ */
void v9fs_mux_cancel(struct v9fs_mux_data *m, int err) void p9_conn_cancel(struct p9_conn *m, int err)
{ {
struct v9fs_req *req, *rtmp; struct p9_req *req, *rtmp;
LIST_HEAD(cancel_list); LIST_HEAD(cancel_list);
dprintk(DEBUG_ERROR, "mux %p err %d\n", m, err); P9_DPRINTK(P9_DEBUG_ERROR, "mux %p err %d\n", m, err);
m->err = err; m->err = err;
spin_lock(&m->lock); spin_lock(&m->lock);
list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) { list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
...@@ -1014,20 +1034,21 @@ void v9fs_mux_cancel(struct v9fs_mux_data *m, int err) ...@@ -1014,20 +1034,21 @@ void v9fs_mux_cancel(struct v9fs_mux_data *m, int err)
wake_up(&m->equeue); wake_up(&m->equeue);
} }
EXPORT_SYMBOL(p9_conn_cancel);
static u16 v9fs_mux_get_tag(struct v9fs_mux_data *m) static u16 p9_mux_get_tag(struct p9_conn *m)
{ {
int tag; int tag;
tag = v9fs_get_idpool(&m->tagpool); tag = p9_idpool_get(m->tagpool);
if (tag < 0) if (tag < 0)
return V9FS_NOTAG; return P9_NOTAG;
else else
return (u16) tag; return (u16) tag;
} }
static void v9fs_mux_put_tag(struct v9fs_mux_data *m, u16 tag) static void p9_mux_put_tag(struct p9_conn *m, u16 tag)
{ {
if (tag != V9FS_NOTAG && v9fs_check_idpool(tag, &m->tagpool)) if (tag != P9_NOTAG && p9_idpool_check(tag, m->tagpool))
v9fs_put_idpool(tag, &m->tagpool); p9_idpool_put(tag, m->tagpool);
} }
/* /*
* 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);
}
...@@ -32,39 +32,230 @@ ...@@ -32,39 +32,230 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/un.h> #include <linux/un.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <linux/inet.h> #include <linux/inet.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/file.h> #include <linux/file.h>
#include <net/9p/9p.h>
#include <net/9p/transport.h>
#include "debug.h" #define P9_PORT 564
#include "v9fs.h"
#include "transport.h"
#define V9FS_PORT 564 struct p9_trans_fd {
struct v9fs_trans_fd {
struct file *rd; struct file *rd;
struct file *wr; struct file *wr;
}; };
static int p9_socket_open(struct p9_transport *trans, struct socket *csocket);
static int p9_fd_open(struct p9_transport *trans, int rfd, int wfd);
static int p9_fd_read(struct p9_transport *trans, void *v, int len);
static int p9_fd_write(struct p9_transport *trans, void *v, int len);
static unsigned int p9_fd_poll(struct p9_transport *trans,
struct poll_table_struct *pt);
static void p9_fd_close(struct p9_transport *trans);
struct p9_transport *p9_trans_create_tcp(const char *addr, int port)
{
int err;
struct p9_transport *trans;
struct socket *csocket;
struct sockaddr_in sin_server;
csocket = NULL;
trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL);
if (!trans)
return ERR_PTR(-ENOMEM);
trans->write = p9_fd_write;
trans->read = p9_fd_read;
trans->close = p9_fd_close;
trans->poll = p9_fd_poll;
sin_server.sin_family = AF_INET;
sin_server.sin_addr.s_addr = in_aton(addr);
sin_server.sin_port = htons(port);
sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket);
if (!csocket) {
P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n");
err = -EIO;
goto error;
}
err = csocket->ops->connect(csocket,
(struct sockaddr *)&sin_server,
sizeof(struct sockaddr_in), 0);
if (err < 0) {
P9_EPRINTK(KERN_ERR,
"p9_trans_tcp: problem connecting socket to %s\n",
addr);
goto error;
}
err = p9_socket_open(trans, csocket);
if (err < 0)
goto error;
return trans;
error:
if (csocket)
sock_release(csocket);
kfree(trans);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_trans_create_tcp);
struct p9_transport *p9_trans_create_unix(const char *addr)
{
int err;
struct socket *csocket;
struct sockaddr_un sun_server;
struct p9_transport *trans;
csocket = NULL;
trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL);
if (!trans)
return ERR_PTR(-ENOMEM);
trans->write = p9_fd_write;
trans->read = p9_fd_read;
trans->close = p9_fd_close;
trans->poll = p9_fd_poll;
if (strlen(addr) > UNIX_PATH_MAX) {
P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n",
addr);
err = -ENAMETOOLONG;
goto error;
}
sun_server.sun_family = PF_UNIX;
strcpy(sun_server.sun_path, addr);
sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket);
err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server,
sizeof(struct sockaddr_un) - 1, 0);
if (err < 0) {
P9_EPRINTK(KERN_ERR,
"p9_trans_unix: problem connecting socket: %s: %d\n",
addr, err);
goto error;
}
err = p9_socket_open(trans, csocket);
if (err < 0)
goto error;
return trans;
error:
if (csocket)
sock_release(csocket);
kfree(trans);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_trans_create_unix);
struct p9_transport *p9_trans_create_fd(int rfd, int wfd)
{
int err;
struct p9_transport *trans;
if (rfd == ~0 || wfd == ~0) {
printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n");
return ERR_PTR(-ENOPROTOOPT);
}
trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL);
if (!trans)
return ERR_PTR(-ENOMEM);
trans->write = p9_fd_write;
trans->read = p9_fd_read;
trans->close = p9_fd_close;
trans->poll = p9_fd_poll;
err = p9_fd_open(trans, rfd, wfd);
if (err < 0)
goto error;
return trans;
error:
kfree(trans);
return ERR_PTR(err);
}
EXPORT_SYMBOL(p9_trans_create_fd);
static int p9_socket_open(struct p9_transport *trans, struct socket *csocket)
{
int fd, ret;
csocket->sk->sk_allocation = GFP_NOIO;
fd = sock_map_fd(csocket);
if (fd < 0) {
P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to map fd\n");
return fd;
}
ret = p9_fd_open(trans, fd, fd);
if (ret < 0) {
P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n");
sockfd_put(csocket);
return ret;
}
((struct p9_trans_fd *)trans->priv)->rd->f_flags |= O_NONBLOCK;
return 0;
}
static int p9_fd_open(struct p9_transport *trans, int rfd, int wfd)
{
struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd),
GFP_KERNEL);
if (!ts)
return -ENOMEM;
ts->rd = fget(rfd);
ts->wr = fget(wfd);
if (!ts->rd || !ts->wr) {
if (ts->rd)
fput(ts->rd);
if (ts->wr)
fput(ts->wr);
kfree(ts);
return -EIO;
}
trans->priv = ts;
trans->status = Connected;
return 0;
}
/** /**
* v9fs_fd_read- read from a fd * p9_fd_read- read from a fd
* @v9ses: session information * @v9ses: session information
* @v: buffer to receive data into * @v: buffer to receive data into
* @len: size of receive buffer * @len: size of receive buffer
* *
*/ */
static int v9fs_fd_read(struct v9fs_transport *trans, void *v, int len) static int p9_fd_read(struct p9_transport *trans, void *v, int len)
{ {
int ret; int ret;
struct v9fs_trans_fd *ts; struct p9_trans_fd *ts = NULL;
if (!trans || trans->status == Disconnected || !(ts = trans->priv)) if (trans && trans->status != Disconnected)
ts = trans->priv;
if (!ts)
return -EREMOTEIO; return -EREMOTEIO;
if (!(ts->rd->f_flags & O_NONBLOCK)) if (!(ts->rd->f_flags & O_NONBLOCK))
dprintk(DEBUG_ERROR, "blocking read ...\n"); P9_DPRINTK(P9_DEBUG_ERROR, "blocking read ...\n");
ret = kernel_read(ts->rd, ts->rd->f_pos, v, len); ret = kernel_read(ts->rd, ts->rd->f_pos, v, len);
if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN) if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
...@@ -73,23 +264,26 @@ static int v9fs_fd_read(struct v9fs_transport *trans, void *v, int len) ...@@ -73,23 +264,26 @@ static int v9fs_fd_read(struct v9fs_transport *trans, void *v, int len)
} }
/** /**
* v9fs_fd_write - write to a socket * p9_fd_write - write to a socket
* @v9ses: session information * @v9ses: session information
* @v: buffer to send data from * @v: buffer to send data from
* @len: size of send buffer * @len: size of send buffer
* *
*/ */
static int v9fs_fd_write(struct v9fs_transport *trans, void *v, int len) static int p9_fd_write(struct p9_transport *trans, void *v, int len)
{ {
int ret; int ret;
mm_segment_t oldfs; mm_segment_t oldfs;
struct v9fs_trans_fd *ts; struct p9_trans_fd *ts = NULL;
if (trans && trans->status != Disconnected)
ts = trans->priv;
if (!trans || trans->status == Disconnected || !(ts = trans->priv)) if (!ts)
return -EREMOTEIO; return -EREMOTEIO;
if (!(ts->wr->f_flags & O_NONBLOCK)) if (!(ts->wr->f_flags & O_NONBLOCK))
dprintk(DEBUG_ERROR, "blocking write ...\n"); P9_DPRINTK(P9_DEBUG_ERROR, "blocking write ...\n");
oldfs = get_fs(); oldfs = get_fs();
set_fs(get_ds()); set_fs(get_ds());
...@@ -103,13 +297,16 @@ static int v9fs_fd_write(struct v9fs_transport *trans, void *v, int len) ...@@ -103,13 +297,16 @@ static int v9fs_fd_write(struct v9fs_transport *trans, void *v, int len)
} }
static unsigned int static unsigned int
v9fs_fd_poll(struct v9fs_transport *trans, struct poll_table_struct *pt) p9_fd_poll(struct p9_transport *trans, struct poll_table_struct *pt)
{ {
int ret, n; int ret, n;
struct v9fs_trans_fd *ts; struct p9_trans_fd *ts = NULL;
mm_segment_t oldfs; mm_segment_t oldfs;
if (!trans || trans->status != Connected || !(ts = trans->priv)) if (trans && trans->status == Connected)
ts = trans->priv;
if (!ts)
return -EREMOTEIO; return -EREMOTEIO;
if (!ts->rd->f_op || !ts->rd->f_op->poll) if (!ts->rd->f_op || !ts->rd->f_op->poll)
...@@ -134,138 +331,19 @@ v9fs_fd_poll(struct v9fs_transport *trans, struct poll_table_struct *pt) ...@@ -134,138 +331,19 @@ v9fs_fd_poll(struct v9fs_transport *trans, struct poll_table_struct *pt)
ret = (ret & ~POLLOUT) | (n & ~POLLIN); ret = (ret & ~POLLOUT) | (n & ~POLLIN);
} }
end: end:
set_fs(oldfs); set_fs(oldfs);
return ret; return ret;
} }
static int v9fs_fd_open(struct v9fs_session_info *v9ses, int rfd, int wfd)
{
struct v9fs_transport *trans = v9ses->transport;
struct v9fs_trans_fd *ts = kmalloc(sizeof(struct v9fs_trans_fd),
GFP_KERNEL);
if (!ts)
return -ENOMEM;
ts->rd = fget(rfd);
ts->wr = fget(wfd);
if (!ts->rd || !ts->wr) {
if (ts->rd)
fput(ts->rd);
if (ts->wr)
fput(ts->wr);
kfree(ts);
return -EIO;
}
trans->priv = ts;
trans->status = Connected;
return 0;
}
static int v9fs_fd_init(struct v9fs_session_info *v9ses, const char *addr,
char *data)
{
if (v9ses->rfdno == ~0 || v9ses->wfdno == ~0) {
printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n");
return -ENOPROTOOPT;
}
return v9fs_fd_open(v9ses, v9ses->rfdno, v9ses->wfdno);
}
static int v9fs_socket_open(struct v9fs_session_info *v9ses,
struct socket *csocket)
{
int fd, ret;
csocket->sk->sk_allocation = GFP_NOIO;
if ((fd = sock_map_fd(csocket)) < 0) {
eprintk(KERN_ERR, "v9fs_socket_open: failed to map fd\n");
ret = fd;
release_csocket:
sock_release(csocket);
return ret;
}
if ((ret = v9fs_fd_open(v9ses, fd, fd)) < 0) {
sockfd_put(csocket);
eprintk(KERN_ERR, "v9fs_socket_open: failed to open fd\n");
goto release_csocket;
}
((struct v9fs_trans_fd *)v9ses->transport->priv)->rd->f_flags |=
O_NONBLOCK;
return 0;
}
static int v9fs_tcp_init(struct v9fs_session_info *v9ses, const char *addr,
char *data)
{
int ret;
struct socket *csocket = NULL;
struct sockaddr_in sin_server;
sin_server.sin_family = AF_INET;
sin_server.sin_addr.s_addr = in_aton(addr);
sin_server.sin_port = htons(v9ses->port);
sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket);
if (!csocket) {
eprintk(KERN_ERR, "v9fs_trans_tcp: problem creating socket\n");
return -1;
}
ret = csocket->ops->connect(csocket,
(struct sockaddr *)&sin_server,
sizeof(struct sockaddr_in), 0);
if (ret < 0) {
eprintk(KERN_ERR,
"v9fs_trans_tcp: problem connecting socket to %s\n",
addr);
return ret;
}
return v9fs_socket_open(v9ses, csocket);
}
static int
v9fs_unix_init(struct v9fs_session_info *v9ses, const char *addr, char *data)
{
int ret;
struct socket *csocket;
struct sockaddr_un sun_server;
if (strlen(addr) > UNIX_PATH_MAX) {
eprintk(KERN_ERR, "v9fs_trans_unix: address too long: %s\n",
addr);
return -ENAMETOOLONG;
}
sun_server.sun_family = PF_UNIX;
strcpy(sun_server.sun_path, addr);
sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket);
ret = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server,
sizeof(struct sockaddr_un) - 1, 0);
if (ret < 0) {
eprintk(KERN_ERR,
"v9fs_trans_unix: problem connecting socket: %s: %d\n",
addr, ret);
return ret;
}
return v9fs_socket_open(v9ses, csocket);
}
/** /**
* v9fs_sock_close - shutdown socket * p9_sock_close - shutdown socket
* @trans: private socket structure * @trans: private socket structure
* *
*/ */
static void v9fs_fd_close(struct v9fs_transport *trans) static void p9_fd_close(struct p9_transport *trans)
{ {
struct v9fs_trans_fd *ts; struct p9_trans_fd *ts;
if (!trans) if (!trans)
return; return;
...@@ -283,26 +361,3 @@ static void v9fs_fd_close(struct v9fs_transport *trans) ...@@ -283,26 +361,3 @@ static void v9fs_fd_close(struct v9fs_transport *trans)
kfree(ts); kfree(ts);
} }
struct v9fs_transport v9fs_trans_fd = {
.init = v9fs_fd_init,
.write = v9fs_fd_write,
.read = v9fs_fd_read,
.close = v9fs_fd_close,
.poll = v9fs_fd_poll,
};
struct v9fs_transport v9fs_trans_tcp = {
.init = v9fs_tcp_init,
.write = v9fs_fd_write,
.read = v9fs_fd_read,
.close = v9fs_fd_close,
.poll = v9fs_fd_poll,
};
struct v9fs_transport v9fs_trans_unix = {
.init = v9fs_unix_init,
.write = v9fs_fd_write,
.read = v9fs_fd_read,
.close = v9fs_fd_close,
.poll = v9fs_fd_poll,
};
/*
* 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