diff options
| -rw-r--r-- | fs/9p/fid.h | 15 | ||||
| -rw-r--r-- | fs/9p/v9fs.c | 57 | ||||
| -rw-r--r-- | fs/9p/v9fs.h | 85 | ||||
| -rw-r--r-- | fs/9p/vfs_addr.c | 2 | ||||
| -rw-r--r-- | fs/9p/vfs_dir.c | 2 | ||||
| -rw-r--r-- | fs/9p/vfs_file.c | 11 | ||||
| -rw-r--r-- | fs/9p/vfs_inode.c | 50 | ||||
| -rw-r--r-- | fs/9p/vfs_super.c | 35 | ||||
| -rw-r--r-- | include/linux/parser.h | 2 | ||||
| -rw-r--r-- | include/net/9p/9p.h | 240 | ||||
| -rw-r--r-- | include/net/9p/client.h | 35 | ||||
| -rw-r--r-- | include/net/9p/transport.h | 44 | ||||
| -rw-r--r-- | lib/parser.c | 32 | ||||
| -rw-r--r-- | net/9p/Kconfig | 10 | ||||
| -rw-r--r-- | net/9p/Makefile | 3 | ||||
| -rw-r--r-- | net/9p/client.c | 32 | ||||
| -rw-r--r-- | net/9p/conv.c | 128 | ||||
| -rw-r--r-- | net/9p/error.c | 15 | ||||
| -rw-r--r-- | net/9p/fcprint.c | 8 | ||||
| -rw-r--r-- | net/9p/mod.c | 8 | ||||
| -rw-r--r-- | net/9p/trans_fd.c | 204 | ||||
| -rw-r--r-- | net/9p/trans_virtio.c | 175 | ||||
| -rw-r--r-- | net/9p/util.c | 36 |
23 files changed, 1014 insertions, 215 deletions
diff --git a/fs/9p/fid.h b/fs/9p/fid.h index 26e07df783b9..c3bbd6af996d 100644 --- a/fs/9p/fid.h +++ b/fs/9p/fid.h | |||
| @@ -22,6 +22,21 @@ | |||
| 22 | 22 | ||
| 23 | #include <linux/list.h> | 23 | #include <linux/list.h> |
| 24 | 24 | ||
| 25 | /** | ||
| 26 | * struct v9fs_dentry - 9p private data stored in dentry d_fsdata | ||
| 27 | * @lock: protects the fidlist | ||
| 28 | * @fidlist: list of FIDs currently associated with this dentry | ||
| 29 | * | ||
| 30 | * This structure defines the 9p private data associated with | ||
| 31 | * a particular dentry. In particular, this private data is used | ||
| 32 | * to lookup which 9P FID handle should be used for a particular VFS | ||
| 33 | * operation. FID handles are associated with dentries instead of | ||
| 34 | * inodes in order to more closely map functionality to the Plan 9 | ||
| 35 | * expected behavior for FID reclaimation and tracking. | ||
| 36 | * | ||
| 37 | * See Also: Mapping FIDs to Linux VFS model in | ||
| 38 | * Design and Implementation of the Linux 9P File System documentation | ||
| 39 | */ | ||
| 25 | struct v9fs_dentry { | 40 | struct v9fs_dentry { |
| 26 | spinlock_t lock; /* protect fidlist */ | 41 | spinlock_t lock; /* protect fidlist */ |
| 27 | struct list_head fidlist; | 42 | struct list_head fidlist; |
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index 9b0f0222e8bb..047c791427aa 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c | |||
| @@ -71,19 +71,19 @@ static match_table_t tokens = { | |||
| 71 | 71 | ||
| 72 | /** | 72 | /** |
| 73 | * v9fs_parse_options - parse mount options into session structure | 73 | * v9fs_parse_options - parse mount options into session structure |
| 74 | * @options: options string passed from mount | ||
| 75 | * @v9ses: existing v9fs session information | 74 | * @v9ses: existing v9fs session information |
| 76 | * | 75 | * |
| 76 | * Return 0 upon success, -ERRNO upon failure. | ||
| 77 | */ | 77 | */ |
| 78 | 78 | ||
| 79 | static void v9fs_parse_options(struct v9fs_session_info *v9ses) | 79 | static int v9fs_parse_options(struct v9fs_session_info *v9ses) |
| 80 | { | 80 | { |
| 81 | char *options; | 81 | char *options; |
| 82 | substring_t args[MAX_OPT_ARGS]; | 82 | substring_t args[MAX_OPT_ARGS]; |
| 83 | char *p; | 83 | char *p; |
| 84 | int option = 0; | 84 | int option = 0; |
| 85 | char *s, *e; | 85 | char *s, *e; |
| 86 | int ret; | 86 | int ret = 0; |
| 87 | 87 | ||
| 88 | /* setup defaults */ | 88 | /* setup defaults */ |
| 89 | v9ses->afid = ~0; | 89 | v9ses->afid = ~0; |
| @@ -91,19 +91,26 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses) | |||
| 91 | v9ses->cache = 0; | 91 | v9ses->cache = 0; |
| 92 | 92 | ||
| 93 | if (!v9ses->options) | 93 | if (!v9ses->options) |
| 94 | return; | 94 | return 0; |
| 95 | 95 | ||
| 96 | options = kstrdup(v9ses->options, GFP_KERNEL); | 96 | options = kstrdup(v9ses->options, GFP_KERNEL); |
| 97 | if (!options) { | ||
| 98 | P9_DPRINTK(P9_DEBUG_ERROR, | ||
| 99 | "failed to allocate copy of option string\n"); | ||
| 100 | return -ENOMEM; | ||
| 101 | } | ||
| 102 | |||
| 97 | while ((p = strsep(&options, ",")) != NULL) { | 103 | while ((p = strsep(&options, ",")) != NULL) { |
| 98 | int token; | 104 | int token; |
| 99 | if (!*p) | 105 | if (!*p) |
| 100 | continue; | 106 | continue; |
| 101 | token = match_token(p, tokens, args); | 107 | token = match_token(p, tokens, args); |
| 102 | if (token < Opt_uname) { | 108 | if (token < Opt_uname) { |
| 103 | ret = match_int(&args[0], &option); | 109 | int r = match_int(&args[0], &option); |
| 104 | if (ret < 0) { | 110 | if (r < 0) { |
| 105 | P9_DPRINTK(P9_DEBUG_ERROR, | 111 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 106 | "integer field, but no integer?\n"); | 112 | "integer field, but no integer?\n"); |
| 113 | ret = r; | ||
| 107 | continue; | 114 | continue; |
| 108 | } | 115 | } |
| 109 | } | 116 | } |
| @@ -125,10 +132,10 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses) | |||
| 125 | v9ses->afid = option; | 132 | v9ses->afid = option; |
| 126 | break; | 133 | break; |
| 127 | case Opt_uname: | 134 | case Opt_uname: |
| 128 | match_strcpy(v9ses->uname, &args[0]); | 135 | match_strlcpy(v9ses->uname, &args[0], PATH_MAX); |
| 129 | break; | 136 | break; |
| 130 | case Opt_remotename: | 137 | case Opt_remotename: |
| 131 | match_strcpy(v9ses->aname, &args[0]); | 138 | match_strlcpy(v9ses->aname, &args[0], PATH_MAX); |
| 132 | break; | 139 | break; |
| 133 | case Opt_nodevmap: | 140 | case Opt_nodevmap: |
| 134 | v9ses->nodev = 1; | 141 | v9ses->nodev = 1; |
| @@ -139,6 +146,13 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses) | |||
| 139 | 146 | ||
| 140 | case Opt_access: | 147 | case Opt_access: |
| 141 | s = match_strdup(&args[0]); | 148 | s = match_strdup(&args[0]); |
| 149 | if (!s) { | ||
| 150 | P9_DPRINTK(P9_DEBUG_ERROR, | ||
| 151 | "failed to allocate copy" | ||
| 152 | " of option argument\n"); | ||
| 153 | ret = -ENOMEM; | ||
| 154 | break; | ||
| 155 | } | ||
| 142 | v9ses->flags &= ~V9FS_ACCESS_MASK; | 156 | v9ses->flags &= ~V9FS_ACCESS_MASK; |
| 143 | if (strcmp(s, "user") == 0) | 157 | if (strcmp(s, "user") == 0) |
| 144 | v9ses->flags |= V9FS_ACCESS_USER; | 158 | v9ses->flags |= V9FS_ACCESS_USER; |
| @@ -158,6 +172,7 @@ static void v9fs_parse_options(struct v9fs_session_info *v9ses) | |||
| 158 | } | 172 | } |
| 159 | } | 173 | } |
| 160 | kfree(options); | 174 | kfree(options); |
| 175 | return ret; | ||
| 161 | } | 176 | } |
| 162 | 177 | ||
| 163 | /** | 178 | /** |
| @@ -173,6 +188,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, | |||
| 173 | { | 188 | { |
| 174 | int retval = -EINVAL; | 189 | int retval = -EINVAL; |
| 175 | struct p9_fid *fid; | 190 | struct p9_fid *fid; |
| 191 | int rc; | ||
| 176 | 192 | ||
| 177 | v9ses->uname = __getname(); | 193 | v9ses->uname = __getname(); |
| 178 | if (!v9ses->uname) | 194 | if (!v9ses->uname) |
| @@ -190,8 +206,21 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, | |||
| 190 | v9ses->uid = ~0; | 206 | v9ses->uid = ~0; |
| 191 | v9ses->dfltuid = V9FS_DEFUID; | 207 | v9ses->dfltuid = V9FS_DEFUID; |
| 192 | v9ses->dfltgid = V9FS_DEFGID; | 208 | v9ses->dfltgid = V9FS_DEFGID; |
| 193 | v9ses->options = kstrdup(data, GFP_KERNEL); | 209 | if (data) { |
| 194 | v9fs_parse_options(v9ses); | 210 | v9ses->options = kstrdup(data, GFP_KERNEL); |
| 211 | if (!v9ses->options) { | ||
| 212 | P9_DPRINTK(P9_DEBUG_ERROR, | ||
| 213 | "failed to allocate copy of option string\n"); | ||
| 214 | retval = -ENOMEM; | ||
| 215 | goto error; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | rc = v9fs_parse_options(v9ses); | ||
| 220 | if (rc < 0) { | ||
| 221 | retval = rc; | ||
| 222 | goto error; | ||
| 223 | } | ||
| 195 | 224 | ||
| 196 | v9ses->clnt = p9_client_create(dev_name, v9ses->options); | 225 | v9ses->clnt = p9_client_create(dev_name, v9ses->options); |
| 197 | 226 | ||
| @@ -233,7 +262,6 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, | |||
| 233 | return fid; | 262 | return fid; |
| 234 | 263 | ||
| 235 | error: | 264 | error: |
| 236 | v9fs_session_close(v9ses); | ||
| 237 | return ERR_PTR(retval); | 265 | return ERR_PTR(retval); |
| 238 | } | 266 | } |
| 239 | 267 | ||
| @@ -256,9 +284,12 @@ void v9fs_session_close(struct v9fs_session_info *v9ses) | |||
| 256 | } | 284 | } |
| 257 | 285 | ||
| 258 | /** | 286 | /** |
| 259 | * v9fs_session_cancel - mark transport as disconnected | 287 | * v9fs_session_cancel - terminate a session |
| 260 | * and cancel all pending requests. | 288 | * @v9ses: session to terminate |
| 289 | * | ||
| 290 | * mark transport as disconnected and cancel all pending requests. | ||
| 261 | */ | 291 | */ |
| 292 | |||
| 262 | void v9fs_session_cancel(struct v9fs_session_info *v9ses) { | 293 | void v9fs_session_cancel(struct v9fs_session_info *v9ses) { |
| 263 | P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses); | 294 | P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses); |
| 264 | p9_client_disconnect(v9ses->clnt); | 295 | p9_client_disconnect(v9ses->clnt); |
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index 7d3a1018db52..a7d567192998 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h | |||
| @@ -21,18 +21,69 @@ | |||
| 21 | * | 21 | * |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | /* | 24 | /** |
| 25 | * Session structure provides information for an opened session | 25 | * enum p9_session_flags - option flags for each 9P session |
| 26 | * | 26 | * @V9FS_EXTENDED: whether or not to use 9P2000.u extensions |
| 27 | */ | 27 | * @V9FS_ACCESS_SINGLE: only the mounting user can access the hierarchy |
| 28 | * @V9FS_ACCESS_USER: a new attach will be issued for every user (default) | ||
| 29 | * @V9FS_ACCESS_ANY: use a single attach for all users | ||
| 30 | * @V9FS_ACCESS_MASK: bit mask of different ACCESS options | ||
| 31 | * | ||
| 32 | * Session flags reflect options selected by users at mount time | ||
| 33 | */ | ||
| 34 | enum p9_session_flags { | ||
| 35 | V9FS_EXTENDED = 0x01, | ||
| 36 | V9FS_ACCESS_SINGLE = 0x02, | ||
| 37 | V9FS_ACCESS_USER = 0x04, | ||
| 38 | V9FS_ACCESS_ANY = 0x06, | ||
| 39 | V9FS_ACCESS_MASK = 0x06, | ||
| 40 | }; | ||
| 41 | |||
| 42 | /* possible values of ->cache */ | ||
| 43 | /** | ||
| 44 | * enum p9_cache_modes - user specified cache preferences | ||
| 45 | * @CACHE_NONE: do not cache data, dentries, or directory contents (default) | ||
| 46 | * @CACHE_LOOSE: cache data, dentries, and directory contents w/no consistency | ||
| 47 | * | ||
| 48 | * eventually support loose, tight, time, session, default always none | ||
| 49 | */ | ||
| 50 | |||
| 51 | enum p9_cache_modes { | ||
| 52 | CACHE_NONE, | ||
| 53 | CACHE_LOOSE, | ||
| 54 | }; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * struct v9fs_session_info - per-instance session information | ||
| 58 | * @flags: session options of type &p9_session_flags | ||
| 59 | * @nodev: set to 1 to disable device mapping | ||
| 60 | * @debug: debug level | ||
| 61 | * @afid: authentication handle | ||
| 62 | * @cache: cache mode of type &p9_cache_modes | ||
| 63 | * @options: copy of options string given by user | ||
| 64 | * @uname: string user name to mount hierarchy as | ||
| 65 | * @aname: mount specifier for remote hierarchy | ||
| 66 | * @maxdata: maximum data to be sent/recvd per protocol message | ||
| 67 | * @dfltuid: default numeric userid to mount hierarchy as | ||
| 68 | * @dfltgid: default numeric groupid to mount hierarchy as | ||
| 69 | * @uid: if %V9FS_ACCESS_SINGLE, the numeric uid which mounted the hierarchy | ||
| 70 | * @clnt: reference to 9P network client instantiated for this session | ||
| 71 | * @debugfs_dir: reference to debugfs_dir which can be used for add'l debug | ||
| 72 | * | ||
| 73 | * This structure holds state for each session instance established during | ||
| 74 | * a sys_mount() . | ||
| 75 | * | ||
| 76 | * Bugs: there seems to be a lot of state which could be condensed and/or | ||
| 77 | * removed. | ||
| 78 | */ | ||
| 28 | 79 | ||
| 29 | struct v9fs_session_info { | 80 | struct v9fs_session_info { |
| 30 | /* options */ | 81 | /* options */ |
| 31 | unsigned char flags; /* session flags */ | 82 | unsigned char flags; |
| 32 | unsigned char nodev; /* set to 1 if no disable device mapping */ | 83 | unsigned char nodev; |
| 33 | unsigned short debug; /* debug level */ | 84 | unsigned short debug; |
| 34 | unsigned int afid; /* authentication fid */ | 85 | unsigned int afid; |
| 35 | unsigned int cache; /* cache mode */ | 86 | unsigned int cache; |
| 36 | 87 | ||
| 37 | char *options; /* copy of mount options */ | 88 | char *options; /* copy of mount options */ |
| 38 | char *uname; /* user name to mount as */ | 89 | char *uname; /* user name to mount as */ |
| @@ -45,22 +96,6 @@ struct v9fs_session_info { | |||
| 45 | struct dentry *debugfs_dir; | 96 | struct dentry *debugfs_dir; |
| 46 | }; | 97 | }; |
| 47 | 98 | ||
| 48 | /* session flags */ | ||
| 49 | enum { | ||
| 50 | V9FS_EXTENDED = 0x01, /* 9P2000.u */ | ||
| 51 | V9FS_ACCESS_MASK = 0x06, /* access mask */ | ||
| 52 | V9FS_ACCESS_SINGLE = 0x02, /* only one user can access the files */ | ||
| 53 | V9FS_ACCESS_USER = 0x04, /* attache per user */ | ||
| 54 | V9FS_ACCESS_ANY = 0x06, /* use the same attach for all users */ | ||
| 55 | }; | ||
| 56 | |||
| 57 | /* possible values of ->cache */ | ||
| 58 | /* eventually support loose, tight, time, session, default always none */ | ||
| 59 | enum { | ||
| 60 | CACHE_NONE, /* default */ | ||
| 61 | CACHE_LOOSE, /* no consistency */ | ||
| 62 | }; | ||
| 63 | |||
| 64 | extern struct dentry *v9fs_debugfs_root; | 99 | extern struct dentry *v9fs_debugfs_root; |
| 65 | 100 | ||
| 66 | struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *, | 101 | struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *, |
diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index 6248f0e727a3..97d3aed57983 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c | |||
| @@ -43,7 +43,7 @@ | |||
| 43 | /** | 43 | /** |
| 44 | * v9fs_vfs_readpage - read an entire page in from 9P | 44 | * v9fs_vfs_readpage - read an entire page in from 9P |
| 45 | * | 45 | * |
| 46 | * @file: file being read | 46 | * @filp: file being read |
| 47 | * @page: structure to page | 47 | * @page: structure to page |
| 48 | * | 48 | * |
| 49 | */ | 49 | */ |
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 0924d4477da3..88e3787c6ea9 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c | |||
| @@ -60,7 +60,7 @@ static inline int dt_type(struct p9_stat *mistat) | |||
| 60 | 60 | ||
| 61 | /** | 61 | /** |
| 62 | * v9fs_dir_readdir - read a directory | 62 | * v9fs_dir_readdir - read a directory |
| 63 | * @filep: opened file structure | 63 | * @filp: opened file structure |
| 64 | * @dirent: directory structure ??? | 64 | * @dirent: directory structure ??? |
| 65 | * @filldir: function to populate directory structure ??? | 65 | * @filldir: function to populate directory structure ??? |
| 66 | * | 66 | * |
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index a616fff8906d..0d55affe37d4 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c | |||
| @@ -90,10 +90,11 @@ int v9fs_file_open(struct inode *inode, struct file *file) | |||
| 90 | 90 | ||
| 91 | /** | 91 | /** |
| 92 | * v9fs_file_lock - lock a file (or directory) | 92 | * v9fs_file_lock - lock a file (or directory) |
| 93 | * @inode: inode to be opened | 93 | * @filp: file to be locked |
| 94 | * @file: file being opened | 94 | * @cmd: lock command |
| 95 | * @fl: file lock structure | ||
| 95 | * | 96 | * |
| 96 | * XXX - this looks like a local only lock, we should extend into 9P | 97 | * Bugs: this looks like a local only lock, we should extend into 9P |
| 97 | * by using open exclusive | 98 | * by using open exclusive |
| 98 | */ | 99 | */ |
| 99 | 100 | ||
| @@ -118,7 +119,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl) | |||
| 118 | 119 | ||
| 119 | /** | 120 | /** |
| 120 | * v9fs_file_read - read from a file | 121 | * v9fs_file_read - read from a file |
| 121 | * @filep: file pointer to read | 122 | * @filp: file pointer to read |
| 122 | * @data: data buffer to read data into | 123 | * @data: data buffer to read data into |
| 123 | * @count: size of buffer | 124 | * @count: size of buffer |
| 124 | * @offset: offset at which to read data | 125 | * @offset: offset at which to read data |
| @@ -142,7 +143,7 @@ v9fs_file_read(struct file *filp, char __user * data, size_t count, | |||
| 142 | 143 | ||
| 143 | /** | 144 | /** |
| 144 | * v9fs_file_write - write to a file | 145 | * v9fs_file_write - write to a file |
| 145 | * @filep: file pointer to write | 146 | * @filp: file pointer to write |
| 146 | * @data: data buffer to write data from | 147 | * @data: data buffer to write data from |
| 147 | * @count: size of buffer | 148 | * @count: size of buffer |
| 148 | * @offset: offset at which to write data | 149 | * @offset: offset at which to write data |
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 6a28842052ea..40fa807bd929 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c | |||
| @@ -129,6 +129,12 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) | |||
| 129 | return res; | 129 | return res; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | /** | ||
| 133 | * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits | ||
| 134 | * @uflags: flags to convert | ||
| 135 | * | ||
| 136 | */ | ||
| 137 | |||
| 132 | int v9fs_uflags2omode(int uflags) | 138 | int v9fs_uflags2omode(int uflags) |
| 133 | { | 139 | { |
| 134 | int ret; | 140 | int ret; |
| @@ -312,6 +318,14 @@ error: | |||
| 312 | } | 318 | } |
| 313 | */ | 319 | */ |
| 314 | 320 | ||
| 321 | /** | ||
| 322 | * v9fs_inode_from_fid - populate an inode by issuing a attribute request | ||
| 323 | * @v9ses: session information | ||
| 324 | * @fid: fid to issue attribute request for | ||
| 325 | * @sb: superblock on which to create inode | ||
| 326 | * | ||
| 327 | */ | ||
| 328 | |||
| 315 | static struct inode * | 329 | static struct inode * |
| 316 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, | 330 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
| 317 | struct super_block *sb) | 331 | struct super_block *sb) |
| @@ -384,9 +398,12 @@ v9fs_open_created(struct inode *inode, struct file *file) | |||
| 384 | 398 | ||
| 385 | /** | 399 | /** |
| 386 | * v9fs_create - Create a file | 400 | * v9fs_create - Create a file |
| 401 | * @v9ses: session information | ||
| 402 | * @dir: directory that dentry is being created in | ||
| 387 | * @dentry: dentry that is being created | 403 | * @dentry: dentry that is being created |
| 388 | * @perm: create permissions | 404 | * @perm: create permissions |
| 389 | * @mode: open mode | 405 | * @mode: open mode |
| 406 | * @extension: 9p2000.u extension string to support devices, etc. | ||
| 390 | * | 407 | * |
| 391 | */ | 408 | */ |
| 392 | static struct p9_fid * | 409 | static struct p9_fid * |
| @@ -461,7 +478,7 @@ error: | |||
| 461 | 478 | ||
| 462 | /** | 479 | /** |
| 463 | * v9fs_vfs_create - VFS hook to create files | 480 | * v9fs_vfs_create - VFS hook to create files |
| 464 | * @inode: directory inode that is being created | 481 | * @dir: directory inode that is being created |
| 465 | * @dentry: dentry that is being deleted | 482 | * @dentry: dentry that is being deleted |
| 466 | * @mode: create permissions | 483 | * @mode: create permissions |
| 467 | * @nd: path information | 484 | * @nd: path information |
| @@ -519,7 +536,7 @@ error: | |||
| 519 | 536 | ||
| 520 | /** | 537 | /** |
| 521 | * v9fs_vfs_mkdir - VFS mkdir hook to create a directory | 538 | * v9fs_vfs_mkdir - VFS mkdir hook to create a directory |
| 522 | * @inode: inode that is being unlinked | 539 | * @dir: inode that is being unlinked |
| 523 | * @dentry: dentry that is being unlinked | 540 | * @dentry: dentry that is being unlinked |
| 524 | * @mode: mode for new directory | 541 | * @mode: mode for new directory |
| 525 | * | 542 | * |
| @@ -703,9 +720,9 @@ done: | |||
| 703 | 720 | ||
| 704 | /** | 721 | /** |
| 705 | * v9fs_vfs_getattr - retrieve file metadata | 722 | * v9fs_vfs_getattr - retrieve file metadata |
| 706 | * @mnt - mount information | 723 | * @mnt: mount information |
| 707 | * @dentry - file to get attributes on | 724 | * @dentry: file to get attributes on |
| 708 | * @stat - metadata structure to populate | 725 | * @stat: metadata structure to populate |
| 709 | * | 726 | * |
| 710 | */ | 727 | */ |
| 711 | 728 | ||
| @@ -928,7 +945,7 @@ done: | |||
| 928 | /** | 945 | /** |
| 929 | * v9fs_vfs_readlink - read a symlink's location | 946 | * v9fs_vfs_readlink - read a symlink's location |
| 930 | * @dentry: dentry for symlink | 947 | * @dentry: dentry for symlink |
| 931 | * @buf: buffer to load symlink location into | 948 | * @buffer: buffer to load symlink location into |
| 932 | * @buflen: length of buffer | 949 | * @buflen: length of buffer |
| 933 | * | 950 | * |
| 934 | */ | 951 | */ |
| @@ -996,10 +1013,12 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
| 996 | * v9fs_vfs_put_link - release a symlink path | 1013 | * v9fs_vfs_put_link - release a symlink path |
| 997 | * @dentry: dentry for symlink | 1014 | * @dentry: dentry for symlink |
| 998 | * @nd: nameidata | 1015 | * @nd: nameidata |
| 1016 | * @p: unused | ||
| 999 | * | 1017 | * |
| 1000 | */ | 1018 | */ |
| 1001 | 1019 | ||
| 1002 | static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) | 1020 | static void |
| 1021 | v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) | ||
| 1003 | { | 1022 | { |
| 1004 | char *s = nd_get_link(nd); | 1023 | char *s = nd_get_link(nd); |
| 1005 | 1024 | ||
| @@ -1008,6 +1027,15 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void | |||
| 1008 | __putname(s); | 1027 | __putname(s); |
| 1009 | } | 1028 | } |
| 1010 | 1029 | ||
| 1030 | /** | ||
| 1031 | * v9fs_vfs_mkspecial - create a special file | ||
| 1032 | * @dir: inode to create special file in | ||
| 1033 | * @dentry: dentry to create | ||
| 1034 | * @mode: mode to create special file | ||
| 1035 | * @extension: 9p2000.u format extension string representing special file | ||
| 1036 | * | ||
| 1037 | */ | ||
| 1038 | |||
| 1011 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, | 1039 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, |
| 1012 | int mode, const char *extension) | 1040 | int mode, const char *extension) |
| 1013 | { | 1041 | { |
| @@ -1037,7 +1065,7 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, | |||
| 1037 | * @dentry: dentry for symlink | 1065 | * @dentry: dentry for symlink |
| 1038 | * @symname: symlink data | 1066 | * @symname: symlink data |
| 1039 | * | 1067 | * |
| 1040 | * See 9P2000.u RFC for more information | 1068 | * See Also: 9P2000.u RFC for more information |
| 1041 | * | 1069 | * |
| 1042 | */ | 1070 | */ |
| 1043 | 1071 | ||
| @@ -1058,10 +1086,6 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |||
| 1058 | * | 1086 | * |
| 1059 | */ | 1087 | */ |
| 1060 | 1088 | ||
| 1061 | /* XXX - lots of code dup'd from symlink and creates, | ||
| 1062 | * figure out a better reuse strategy | ||
| 1063 | */ | ||
| 1064 | |||
| 1065 | static int | 1089 | static int |
| 1066 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, | 1090 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1067 | struct dentry *dentry) | 1091 | struct dentry *dentry) |
| @@ -1098,7 +1122,7 @@ clunk_fid: | |||
| 1098 | * @dir: inode destination for new link | 1122 | * @dir: inode destination for new link |
| 1099 | * @dentry: dentry for file | 1123 | * @dentry: dentry for file |
| 1100 | * @mode: mode for creation | 1124 | * @mode: mode for creation |
| 1101 | * @dev_t: device associated with special file | 1125 | * @rdev: device associated with special file |
| 1102 | * | 1126 | * |
| 1103 | */ | 1127 | */ |
| 1104 | 1128 | ||
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index a452ac67fc94..bf59c3960494 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c | |||
| @@ -75,6 +75,7 @@ static int v9fs_set_super(struct super_block *s, void *data) | |||
| 75 | * v9fs_fill_super - populate superblock with info | 75 | * v9fs_fill_super - populate superblock with info |
| 76 | * @sb: superblock | 76 | * @sb: superblock |
| 77 | * @v9ses: session information | 77 | * @v9ses: session information |
| 78 | * @flags: flags propagated from v9fs_get_sb() | ||
| 78 | * | 79 | * |
| 79 | */ | 80 | */ |
| 80 | 81 | ||
| @@ -127,29 +128,26 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, | |||
| 127 | fid = v9fs_session_init(v9ses, dev_name, data); | 128 | fid = v9fs_session_init(v9ses, dev_name, data); |
| 128 | if (IS_ERR(fid)) { | 129 | if (IS_ERR(fid)) { |
| 129 | retval = PTR_ERR(fid); | 130 | retval = PTR_ERR(fid); |
| 130 | fid = NULL; | 131 | goto close_session; |
| 131 | kfree(v9ses); | ||
| 132 | v9ses = NULL; | ||
| 133 | goto error; | ||
| 134 | } | 132 | } |
| 135 | 133 | ||
| 136 | st = p9_client_stat(fid); | 134 | st = p9_client_stat(fid); |
| 137 | if (IS_ERR(st)) { | 135 | if (IS_ERR(st)) { |
| 138 | retval = PTR_ERR(st); | 136 | retval = PTR_ERR(st); |
| 139 | goto error; | 137 | goto clunk_fid; |
| 140 | } | 138 | } |
| 141 | 139 | ||
| 142 | sb = sget(fs_type, NULL, v9fs_set_super, v9ses); | 140 | sb = sget(fs_type, NULL, v9fs_set_super, v9ses); |
| 143 | if (IS_ERR(sb)) { | 141 | if (IS_ERR(sb)) { |
| 144 | retval = PTR_ERR(sb); | 142 | retval = PTR_ERR(sb); |
| 145 | goto error; | 143 | goto free_stat; |
| 146 | } | 144 | } |
| 147 | v9fs_fill_super(sb, v9ses, flags); | 145 | v9fs_fill_super(sb, v9ses, flags); |
| 148 | 146 | ||
| 149 | inode = v9fs_get_inode(sb, S_IFDIR | mode); | 147 | inode = v9fs_get_inode(sb, S_IFDIR | mode); |
| 150 | if (IS_ERR(inode)) { | 148 | if (IS_ERR(inode)) { |
| 151 | retval = PTR_ERR(inode); | 149 | retval = PTR_ERR(inode); |
| 152 | goto error; | 150 | goto release_sb; |
| 153 | } | 151 | } |
| 154 | 152 | ||
| 155 | inode->i_uid = uid; | 153 | inode->i_uid = uid; |
| @@ -158,7 +156,7 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, | |||
| 158 | root = d_alloc_root(inode); | 156 | root = d_alloc_root(inode); |
| 159 | if (!root) { | 157 | if (!root) { |
| 160 | retval = -ENOMEM; | 158 | retval = -ENOMEM; |
| 161 | goto error; | 159 | goto release_sb; |
| 162 | } | 160 | } |
| 163 | 161 | ||
| 164 | sb->s_root = root; | 162 | sb->s_root = root; |
| @@ -169,21 +167,22 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, | |||
| 169 | 167 | ||
| 170 | return simple_set_mnt(mnt, sb); | 168 | return simple_set_mnt(mnt, sb); |
| 171 | 169 | ||
| 172 | error: | 170 | release_sb: |
| 173 | kfree(st); | ||
| 174 | if (fid) | ||
| 175 | p9_client_clunk(fid); | ||
| 176 | |||
| 177 | if (v9ses) { | ||
| 178 | v9fs_session_close(v9ses); | ||
| 179 | kfree(v9ses); | ||
| 180 | } | ||
| 181 | |||
| 182 | if (sb) { | 171 | if (sb) { |
| 183 | up_write(&sb->s_umount); | 172 | up_write(&sb->s_umount); |
| 184 | deactivate_super(sb); | 173 | deactivate_super(sb); |
| 185 | } | 174 | } |
| 186 | 175 | ||
| 176 | free_stat: | ||
| 177 | kfree(st); | ||
| 178 | |||
| 179 | clunk_fid: | ||
| 180 | p9_client_clunk(fid); | ||
| 181 | |||
| 182 | close_session: | ||
| 183 | v9fs_session_close(v9ses); | ||
| 184 | kfree(v9ses); | ||
| 185 | |||
| 187 | return retval; | 186 | return retval; |
| 188 | } | 187 | } |
| 189 | 188 | ||
diff --git a/include/linux/parser.h b/include/linux/parser.h index 26b2bdfcaf06..7dcd05075756 100644 --- a/include/linux/parser.h +++ b/include/linux/parser.h | |||
| @@ -29,5 +29,5 @@ int match_token(char *, match_table_t table, substring_t args[]); | |||
| 29 | int match_int(substring_t *, int *result); | 29 | int match_int(substring_t *, int *result); |
| 30 | int match_octal(substring_t *, int *result); | 30 | int match_octal(substring_t *, int *result); |
| 31 | int match_hex(substring_t *, int *result); | 31 | int match_hex(substring_t *, int *result); |
| 32 | void match_strcpy(char *, const substring_t *); | 32 | size_t match_strlcpy(char *, const substring_t *, size_t); |
| 33 | char *match_strdup(const substring_t *); | 33 | char *match_strdup(const substring_t *); |
diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h index 585eb4496990..b3d3e27c6299 100644 --- a/include/net/9p/9p.h +++ b/include/net/9p/9p.h | |||
| @@ -29,14 +29,31 @@ | |||
| 29 | 29 | ||
| 30 | #ifdef CONFIG_NET_9P_DEBUG | 30 | #ifdef CONFIG_NET_9P_DEBUG |
| 31 | 31 | ||
| 32 | #define P9_DEBUG_ERROR (1<<0) | 32 | /** |
| 33 | #define P9_DEBUG_9P (1<<2) | 33 | * enum p9_debug_flags - bits for mount time debug parameter |
| 34 | #define P9_DEBUG_VFS (1<<3) | 34 | * @P9_DEBUG_ERROR: more verbose error messages including original error string |
| 35 | #define P9_DEBUG_CONV (1<<4) | 35 | * @P9_DEBUG_9P: 9P protocol tracing |
| 36 | #define P9_DEBUG_MUX (1<<5) | 36 | * @P9_DEBUG_VFS: VFS API tracing |
| 37 | #define P9_DEBUG_TRANS (1<<6) | 37 | * @P9_DEBUG_CONV: protocol conversion tracing |
| 38 | #define P9_DEBUG_SLABS (1<<7) | 38 | * @P9_DEBUG_MUX: trace management of concurrent transactions |
| 39 | #define P9_DEBUG_FCALL (1<<8) | 39 | * @P9_DEBUG_TRANS: transport tracing |
| 40 | * @P9_DEBUG_SLABS: memory management tracing | ||
| 41 | * @P9_DEBUG_FCALL: verbose dump of protocol messages | ||
| 42 | * | ||
| 43 | * These flags are passed at mount time to turn on various levels of | ||
| 44 | * verbosity and tracing which will be output to the system logs. | ||
| 45 | */ | ||
| 46 | |||
| 47 | enum p9_debug_flags { | ||
| 48 | P9_DEBUG_ERROR = (1<<0), | ||
| 49 | P9_DEBUG_9P = (1<<2), | ||
| 50 | P9_DEBUG_VFS = (1<<3), | ||
| 51 | P9_DEBUG_CONV = (1<<4), | ||
| 52 | P9_DEBUG_MUX = (1<<5), | ||
| 53 | P9_DEBUG_TRANS = (1<<6), | ||
| 54 | P9_DEBUG_SLABS = (1<<7), | ||
| 55 | P9_DEBUG_FCALL = (1<<8), | ||
| 56 | }; | ||
| 40 | 57 | ||
| 41 | extern unsigned int p9_debug_level; | 58 | extern unsigned int p9_debug_level; |
| 42 | 59 | ||
| @@ -62,9 +79,47 @@ do { \ | |||
| 62 | format , __FUNCTION__, task_pid_nr(current), ## arg); \ | 79 | format , __FUNCTION__, task_pid_nr(current), ## arg); \ |
| 63 | } while (0) | 80 | } while (0) |
| 64 | 81 | ||
| 82 | /** | ||
| 83 | * enum p9_msg_t - 9P message types | ||
| 84 | * @P9_TVERSION: version handshake request | ||
| 85 | * @P9_RVERSION: version handshake response | ||
| 86 | * @P9_TAUTH: request to establish authentication channel | ||
| 87 | * @P9_RAUTH: response with authentication information | ||
| 88 | * @P9_TATTACH: establish user access to file service | ||
| 89 | * @P9_RATTACH: response with top level handle to file hierarchy | ||
| 90 | * @P9_TERROR: not used | ||
| 91 | * @P9_RERROR: response for any failed request | ||
| 92 | * @P9_TFLUSH: request to abort a previous request | ||
| 93 | * @P9_RFLUSH: response when previous request has been cancelled | ||
| 94 | * @P9_TWALK: descend a directory hierarchy | ||
| 95 | * @P9_RWALK: response with new handle for position within hierarchy | ||
| 96 | * @P9_TOPEN: prepare a handle for I/O on an existing file | ||
| 97 | * @P9_ROPEN: response with file access information | ||
| 98 | * @P9_TCREATE: prepare a handle for I/O on a new file | ||
| 99 | * @P9_RCREATE: response with file access information | ||
| 100 | * @P9_TREAD: request to transfer data from a file or directory | ||
| 101 | * @P9_RREAD: response with data requested | ||
| 102 | * @P9_TWRITE: reuqest to transfer data to a file | ||
| 103 | * @P9_RWRITE: response with out much data was transfered to file | ||
| 104 | * @P9_TCLUNK: forget about a handle to an entity within the file system | ||
| 105 | * @P9_RCLUNK: response when server has forgotten about the handle | ||
| 106 | * @P9_TREMOVE: request to remove an entity from the hierarchy | ||
| 107 | * @P9_RREMOVE: response when server has removed the entity | ||
| 108 | * @P9_TSTAT: request file entity attributes | ||
| 109 | * @P9_RSTAT: response with file entity attributes | ||
| 110 | * @P9_TWSTAT: request to update file entity attributes | ||
| 111 | * @P9_RWSTAT: response when file entity attributes are updated | ||
| 112 | * | ||
| 113 | * There are 14 basic operations in 9P2000, paired as | ||
| 114 | * requests and responses. The one special case is ERROR | ||
| 115 | * as there is no @P9_TERROR request for clients to transmit to | ||
| 116 | * the server, but the server may respond to any other request | ||
| 117 | * with an @P9_RERROR. | ||
| 118 | * | ||
| 119 | * See Also: http://plan9.bell-labs.com/sys/man/5/INDEX.html | ||
| 120 | */ | ||
| 65 | 121 | ||
| 66 | /* Message Types */ | 122 | enum p9_msg_t { |
| 67 | enum { | ||
| 68 | P9_TVERSION = 100, | 123 | P9_TVERSION = 100, |
| 69 | P9_RVERSION, | 124 | P9_RVERSION, |
| 70 | P9_TAUTH = 102, | 125 | P9_TAUTH = 102, |
| @@ -95,30 +150,71 @@ enum { | |||
| 95 | P9_RWSTAT, | 150 | P9_RWSTAT, |
| 96 | }; | 151 | }; |
| 97 | 152 | ||
| 98 | /* open modes */ | 153 | /** |
| 99 | enum { | 154 | * enum p9_open_mode_t - 9P open modes |
| 155 | * @P9_OREAD: open file for reading only | ||
| 156 | * @P9_OWRITE: open file for writing only | ||
| 157 | * @P9_ORDWR: open file for reading or writing | ||
| 158 | * @P9_OEXEC: open file for execution | ||
| 159 | * @P9_OTRUNC: truncate file to zero-length before opening it | ||
| 160 | * @P9_OREXEC: close the file when an exec(2) system call is made | ||
| 161 | * @P9_ORCLOSE: remove the file when the file is closed | ||
| 162 | * @P9_OAPPEND: open the file and seek to the end | ||
| 163 | * @P9_OEXCL: only create a file, do not open it | ||
| 164 | * | ||
| 165 | * 9P open modes differ slightly from Posix standard modes. | ||
| 166 | * In particular, there are extra modes which specify different | ||
| 167 | * semantic behaviors than may be available on standard Posix | ||
| 168 | * systems. For example, @P9_OREXEC and @P9_ORCLOSE are modes that | ||
| 169 | * most likely will not be issued from the Linux VFS client, but may | ||
| 170 | * be supported by servers. | ||
| 171 | * | ||
| 172 | * See Also: http://plan9.bell-labs.com/magic/man2html/2/open | ||
| 173 | */ | ||
| 174 | |||
| 175 | enum p9_open_mode_t { | ||
| 100 | P9_OREAD = 0x00, | 176 | P9_OREAD = 0x00, |
| 101 | P9_OWRITE = 0x01, | 177 | P9_OWRITE = 0x01, |
| 102 | P9_ORDWR = 0x02, | 178 | P9_ORDWR = 0x02, |
| 103 | P9_OEXEC = 0x03, | 179 | P9_OEXEC = 0x03, |
| 104 | P9_OEXCL = 0x04, | ||
| 105 | P9_OTRUNC = 0x10, | 180 | P9_OTRUNC = 0x10, |
| 106 | P9_OREXEC = 0x20, | 181 | P9_OREXEC = 0x20, |
| 107 | P9_ORCLOSE = 0x40, | 182 | P9_ORCLOSE = 0x40, |
| 108 | P9_OAPPEND = 0x80, | 183 | P9_OAPPEND = 0x80, |
| 109 | }; | 184 | P9_OEXCL = 0x1000, |
| 110 | 185 | }; | |
| 111 | /* permissions */ | 186 | |
| 112 | enum { | 187 | /** |
| 188 | * enum p9_perm_t - 9P permissions | ||
| 189 | * @P9_DMDIR: mode bite for directories | ||
| 190 | * @P9_DMAPPEND: mode bit for is append-only | ||
| 191 | * @P9_DMEXCL: mode bit for excluse use (only one open handle allowed) | ||
| 192 | * @P9_DMMOUNT: mode bite for mount points | ||
| 193 | * @P9_DMAUTH: mode bit for authentication file | ||
| 194 | * @P9_DMTMP: mode bit for non-backed-up files | ||
| 195 | * @P9_DMSYMLINK: mode bit for symbolic links (9P2000.u) | ||
| 196 | * @P9_DMLINK: mode bit for hard-link (9P2000.u) | ||
| 197 | * @P9_DMDEVICE: mode bit for device files (9P2000.u) | ||
| 198 | * @P9_DMNAMEDPIPE: mode bit for named pipe (9P2000.u) | ||
| 199 | * @P9_DMSOCKET: mode bit for socket (9P2000.u) | ||
| 200 | * @P9_DMSETUID: mode bit for setuid (9P2000.u) | ||
| 201 | * @P9_DMSETGID: mode bit for setgid (9P2000.u) | ||
| 202 | * @P9_DMSETVTX: mode bit for sticky bit (9P2000.u) | ||
| 203 | * | ||
| 204 | * 9P permissions differ slightly from Posix standard modes. | ||
| 205 | * | ||
| 206 | * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat | ||
| 207 | */ | ||
| 208 | enum p9_perm_t { | ||
| 113 | P9_DMDIR = 0x80000000, | 209 | P9_DMDIR = 0x80000000, |
| 114 | P9_DMAPPEND = 0x40000000, | 210 | P9_DMAPPEND = 0x40000000, |
| 115 | P9_DMEXCL = 0x20000000, | 211 | P9_DMEXCL = 0x20000000, |
| 116 | P9_DMMOUNT = 0x10000000, | 212 | P9_DMMOUNT = 0x10000000, |
| 117 | P9_DMAUTH = 0x08000000, | 213 | P9_DMAUTH = 0x08000000, |
| 118 | P9_DMTMP = 0x04000000, | 214 | P9_DMTMP = 0x04000000, |
| 215 | /* 9P2000.u extensions */ | ||
| 119 | P9_DMSYMLINK = 0x02000000, | 216 | P9_DMSYMLINK = 0x02000000, |
| 120 | P9_DMLINK = 0x01000000, | 217 | P9_DMLINK = 0x01000000, |
| 121 | /* 9P2000.u extensions */ | ||
| 122 | P9_DMDEVICE = 0x00800000, | 218 | P9_DMDEVICE = 0x00800000, |
| 123 | P9_DMNAMEDPIPE = 0x00200000, | 219 | P9_DMNAMEDPIPE = 0x00200000, |
| 124 | P9_DMSOCKET = 0x00100000, | 220 | P9_DMSOCKET = 0x00100000, |
| @@ -127,8 +223,26 @@ enum { | |||
| 127 | P9_DMSETVTX = 0x00010000, | 223 | P9_DMSETVTX = 0x00010000, |
| 128 | }; | 224 | }; |
| 129 | 225 | ||
| 130 | /* qid.types */ | 226 | /** |
| 131 | enum { | 227 | * enum p9_qid_t - QID types |
| 228 | * @P9_QTDIR: directory | ||
| 229 | * @P9_QTAPPEND: append-only | ||
| 230 | * @P9_QTEXCL: excluse use (only one open handle allowed) | ||
| 231 | * @P9_QTMOUNT: mount points | ||
| 232 | * @P9_QTAUTH: authentication file | ||
| 233 | * @P9_QTTMP: non-backed-up files | ||
| 234 | * @P9_QTSYMLINK: symbolic links (9P2000.u) | ||
| 235 | * @P9_QTLINK: hard-link (9P2000.u) | ||
| 236 | * @P9_QTFILE: normal files | ||
| 237 | * | ||
| 238 | * QID types are a subset of permissions - they are primarily | ||
| 239 | * used to differentiate semantics for a file system entity via | ||
| 240 | * a jump-table. Their value is also the most signifigant 16 bits | ||
| 241 | * of the permission_t | ||
| 242 | * | ||
| 243 | * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat | ||
| 244 | */ | ||
| 245 | enum p9_qid_t { | ||
| 132 | P9_QTDIR = 0x80, | 246 | P9_QTDIR = 0x80, |
| 133 | P9_QTAPPEND = 0x40, | 247 | P9_QTAPPEND = 0x40, |
| 134 | P9_QTEXCL = 0x20, | 248 | P9_QTEXCL = 0x20, |
| @@ -140,6 +254,7 @@ enum { | |||
| 140 | P9_QTFILE = 0x00, | 254 | P9_QTFILE = 0x00, |
| 141 | }; | 255 | }; |
| 142 | 256 | ||
| 257 | /* 9P Magic Numbers */ | ||
| 143 | #define P9_NOTAG (u16)(~0) | 258 | #define P9_NOTAG (u16)(~0) |
| 144 | #define P9_NOFID (u32)(~0) | 259 | #define P9_NOFID (u32)(~0) |
| 145 | #define P9_MAXWELEM 16 | 260 | #define P9_MAXWELEM 16 |
| @@ -147,19 +262,69 @@ enum { | |||
| 147 | /* ample room for Twrite/Rread header */ | 262 | /* ample room for Twrite/Rread header */ |
| 148 | #define P9_IOHDRSZ 24 | 263 | #define P9_IOHDRSZ 24 |
| 149 | 264 | ||
| 265 | /** | ||
| 266 | * struct p9_str - length prefixed string type | ||
| 267 | * @len: length of the string | ||
| 268 | * @str: the string | ||
| 269 | * | ||
| 270 | * The protocol uses length prefixed strings for all | ||
| 271 | * string data, so we replicate that for our internal | ||
| 272 | * string members. | ||
| 273 | */ | ||
| 274 | |||
| 150 | struct p9_str { | 275 | struct p9_str { |
| 151 | u16 len; | 276 | u16 len; |
| 152 | char *str; | 277 | char *str; |
| 153 | }; | 278 | }; |
| 154 | 279 | ||
| 155 | /* qids are the unique ID for a file (like an inode */ | 280 | /** |
| 281 | * struct p9_qid - file system entity information | ||
| 282 | * @type: 8-bit type &p9_qid_t | ||
| 283 | * @version: 16-bit monotonically incrementing version number | ||
| 284 | * @path: 64-bit per-server-unique ID for a file system element | ||
| 285 | * | ||
| 286 | * qids are identifiers used by 9P servers to track file system | ||
| 287 | * entities. The type is used to differentiate semantics for operations | ||
| 288 | * on the entity (ie. read means something different on a directory than | ||
| 289 | * on a file). The path provides a server unique index for an entity | ||
| 290 | * (roughly analogous to an inode number), while the version is updated | ||
| 291 | * every time a file is modified and can be used to maintain cache | ||
| 292 | * coherency between clients and serves. | ||
| 293 | * Servers will often differentiate purely synthetic entities by setting | ||
| 294 | * their version to 0, signaling that they should never be cached and | ||
| 295 | * should be accessed synchronously. | ||
| 296 | * | ||
| 297 | * See Also://plan9.bell-labs.com/magic/man2html/2/stat | ||
| 298 | */ | ||
| 299 | |||
| 156 | struct p9_qid { | 300 | struct p9_qid { |
| 157 | u8 type; | 301 | u8 type; |
| 158 | u32 version; | 302 | u32 version; |
| 159 | u64 path; | 303 | u64 path; |
| 160 | }; | 304 | }; |
| 161 | 305 | ||
| 162 | /* Plan 9 file metadata (stat) structure */ | 306 | /** |
| 307 | * struct p9_stat - file system metadata information | ||
| 308 | * @size: length prefix for this stat structure instance | ||
| 309 | * @type: the type of the server (equivilent to a major number) | ||
| 310 | * @dev: the sub-type of the server (equivilent to a minor number) | ||
| 311 | * @qid: unique id from the server of type &p9_qid | ||
| 312 | * @mode: Plan 9 format permissions of type &p9_perm_t | ||
| 313 | * @atime: Last access/read time | ||
| 314 | * @mtime: Last modify/write time | ||
| 315 | * @length: file length | ||
| 316 | * @name: last element of path (aka filename) in type &p9_str | ||
| 317 | * @uid: owner name in type &p9_str | ||
| 318 | * @gid: group owner in type &p9_str | ||
| 319 | * @muid: last modifier in type &p9_str | ||
| 320 | * @extension: area used to encode extended UNIX support in type &p9_str | ||
| 321 | * @n_uid: numeric user id of owner (part of 9p2000.u extension) | ||
| 322 | * @n_gid: numeric group id (part of 9p2000.u extension) | ||
| 323 | * @n_muid: numeric user id of laster modifier (part of 9p2000.u extension) | ||
| 324 | * | ||
| 325 | * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat | ||
| 326 | */ | ||
| 327 | |||
| 163 | struct p9_stat { | 328 | struct p9_stat { |
| 164 | u16 size; | 329 | u16 size; |
| 165 | u16 type; | 330 | u16 type; |
| @@ -179,10 +344,14 @@ struct p9_stat { | |||
| 179 | u32 n_muid; /* 9p2000.u extensions */ | 344 | u32 n_muid; /* 9p2000.u extensions */ |
| 180 | }; | 345 | }; |
| 181 | 346 | ||
| 182 | /* file metadata (stat) structure used to create Twstat message | 347 | /* |
| 183 | The is similar to p9_stat, but the strings don't point to | 348 | * file metadata (stat) structure used to create Twstat message |
| 184 | the same memory block and should be freed separately | 349 | * The is identical to &p9_stat, but the strings don't point to |
| 185 | */ | 350 | * the same memory block and should be freed separately |
| 351 | * | ||
| 352 | * See Also: http://plan9.bell-labs.com/magic/man2html/2/stat | ||
| 353 | */ | ||
| 354 | |||
| 186 | struct p9_wstat { | 355 | struct p9_wstat { |
| 187 | u16 size; | 356 | u16 size; |
| 188 | u16 type; | 357 | u16 type; |
| @@ -335,10 +504,20 @@ struct p9_twstat { | |||
| 335 | struct p9_rwstat { | 504 | struct p9_rwstat { |
| 336 | }; | 505 | }; |
| 337 | 506 | ||
| 338 | /* | 507 | /** |
| 339 | * fcall is the primary packet structure | 508 | * struct p9_fcall - primary packet structure |
| 340 | * | 509 | * @size: prefixed length of the structure |
| 341 | */ | 510 | * @id: protocol operating identifier of type &p9_msg_t |
| 511 | * @tag: transaction id of the request | ||
| 512 | * @sdata: payload | ||
| 513 | * @params: per-operation parameters | ||
| 514 | * | ||
| 515 | * &p9_fcall represents the structure for all 9P RPC | ||
| 516 | * transactions. Requests are packaged into fcalls, and reponses | ||
| 517 | * must be extracted from them. | ||
| 518 | * | ||
| 519 | * See Also: http://plan9.bell-labs.com/magic/man2html/2/fcall | ||
| 520 | */ | ||
| 342 | 521 | ||
| 343 | struct p9_fcall { | 522 | struct p9_fcall { |
| 344 | u32 size; | 523 | u32 size; |
| @@ -416,4 +595,5 @@ int p9_idpool_check(int id, struct p9_idpool *p); | |||
| 416 | 595 | ||
| 417 | int p9_error_init(void); | 596 | int p9_error_init(void); |
| 418 | int p9_errstr2errno(char *, int); | 597 | int p9_errstr2errno(char *, int); |
| 598 | int p9_trans_fd_init(void); | ||
| 419 | #endif /* NET_9P_H */ | 599 | #endif /* NET_9P_H */ |
diff --git a/include/net/9p/client.h b/include/net/9p/client.h index e52f93d9ac5f..c936dd14de41 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h | |||
| @@ -26,6 +26,23 @@ | |||
| 26 | #ifndef NET_9P_CLIENT_H | 26 | #ifndef NET_9P_CLIENT_H |
| 27 | #define NET_9P_CLIENT_H | 27 | #define NET_9P_CLIENT_H |
| 28 | 28 | ||
| 29 | /** | ||
| 30 | * struct p9_client - per client instance state | ||
| 31 | * @lock: protect @fidlist | ||
| 32 | * @msize: maximum data size negotiated by protocol | ||
| 33 | * @dotu: extension flags negotiated by protocol | ||
| 34 | * @trans_mod: module API instantiated with this client | ||
| 35 | * @trans: tranport instance state and API | ||
| 36 | * @conn: connection state information used by trans_fd | ||
| 37 | * @fidpool: fid handle accounting for session | ||
| 38 | * @fidlist: List of active fid handles | ||
| 39 | * | ||
| 40 | * The client structure is used to keep track of various per-client | ||
| 41 | * state that has been instantiated. | ||
| 42 | * | ||
| 43 | * Bugs: duplicated data and potentially unnecessary elements. | ||
| 44 | */ | ||
| 45 | |||
| 29 | struct p9_client { | 46 | struct p9_client { |
| 30 | spinlock_t lock; /* protect client structure */ | 47 | spinlock_t lock; /* protect client structure */ |
| 31 | int msize; | 48 | int msize; |
| @@ -38,6 +55,24 @@ struct p9_client { | |||
| 38 | struct list_head fidlist; | 55 | struct list_head fidlist; |
| 39 | }; | 56 | }; |
| 40 | 57 | ||
| 58 | /** | ||
| 59 | * struct p9_fid - file system entity handle | ||
| 60 | * @clnt: back pointer to instantiating &p9_client | ||
| 61 | * @fid: numeric identifier for this handle | ||
| 62 | * @mode: current mode of this fid (enum?) | ||
| 63 | * @qid: the &p9_qid server identifier this handle points to | ||
| 64 | * @iounit: the server reported maximum transaction size for this file | ||
| 65 | * @uid: the numeric uid of the local user who owns this handle | ||
| 66 | * @aux: transport specific information (unused?) | ||
| 67 | * @rdir_fpos: tracks offset of file position when reading directory contents | ||
| 68 | * @rdir_pos: (unused?) | ||
| 69 | * @rdir_fcall: holds response of last directory read request | ||
| 70 | * @flist: per-client-instance fid tracking | ||
| 71 | * @dlist: per-dentry fid tracking | ||
| 72 | * | ||
| 73 | * TODO: This needs lots of explanation. | ||
| 74 | */ | ||
| 75 | |||
| 41 | struct p9_fid { | 76 | struct p9_fid { |
| 42 | struct p9_client *clnt; | 77 | struct p9_client *clnt; |
| 43 | u32 fid; | 78 | u32 fid; |
diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h index d2209ae9d18b..0db3a4038dc0 100644 --- a/include/net/9p/transport.h +++ b/include/net/9p/transport.h | |||
| @@ -26,12 +26,40 @@ | |||
| 26 | #ifndef NET_9P_TRANSPORT_H | 26 | #ifndef NET_9P_TRANSPORT_H |
| 27 | #define NET_9P_TRANSPORT_H | 27 | #define NET_9P_TRANSPORT_H |
| 28 | 28 | ||
| 29 | /** | ||
| 30 | * enum p9_trans_status - different states of underlying transports | ||
| 31 | * @Connected: transport is connected and healthy | ||
| 32 | * @Disconnected: transport has been disconnected | ||
| 33 | * @Hung: transport is connected by wedged | ||
| 34 | * | ||
| 35 | * This enumeration details the various states a transport | ||
| 36 | * instatiation can be in. | ||
| 37 | */ | ||
| 38 | |||
| 29 | enum p9_trans_status { | 39 | enum p9_trans_status { |
| 30 | Connected, | 40 | Connected, |
| 31 | Disconnected, | 41 | Disconnected, |
| 32 | Hung, | 42 | Hung, |
| 33 | }; | 43 | }; |
| 34 | 44 | ||
| 45 | /** | ||
| 46 | * struct p9_trans - per-transport state and API | ||
| 47 | * @status: transport &p9_trans_status | ||
| 48 | * @msize: negotiated maximum packet size (duplicate from client) | ||
| 49 | * @extended: negotiated protocol extensions (duplicate from client) | ||
| 50 | * @priv: transport private data | ||
| 51 | * @close: member function to disconnect and close the transport | ||
| 52 | * @rpc: member function to issue a request to the transport | ||
| 53 | * | ||
| 54 | * This is the basic API for a transport instance. It is used as | ||
| 55 | * a handle by the client to issue requests. This interface is currently | ||
| 56 | * in flux during reorganization. | ||
| 57 | * | ||
| 58 | * Bugs: there is lots of duplicated data here and its not clear that | ||
| 59 | * the member functions need to be per-instance versus per transport | ||
| 60 | * module. | ||
| 61 | */ | ||
| 62 | |||
| 35 | struct p9_trans { | 63 | struct p9_trans { |
| 36 | enum p9_trans_status status; | 64 | enum p9_trans_status status; |
| 37 | int msize; | 65 | int msize; |
| @@ -42,6 +70,21 @@ struct p9_trans { | |||
| 42 | struct p9_fcall **rc); | 70 | struct p9_fcall **rc); |
| 43 | }; | 71 | }; |
| 44 | 72 | ||
| 73 | /** | ||
| 74 | * struct p9_trans_module - transport module interface | ||
| 75 | * @list: used to maintain a list of currently available transports | ||
| 76 | * @name: the human-readable name of the transport | ||
| 77 | * @maxsize: transport provided maximum packet size | ||
| 78 | * @def: set if this transport should be considered the default | ||
| 79 | * @create: member function to create a new connection on this transport | ||
| 80 | * | ||
| 81 | * This is the basic API for a transport module which is registered by the | ||
| 82 | * transport module with the 9P core network module and used by the client | ||
| 83 | * to instantiate a new connection on a transport. | ||
| 84 | * | ||
| 85 | * Bugs: the transport module list isn't protected. | ||
| 86 | */ | ||
| 87 | |||
| 45 | struct p9_trans_module { | 88 | struct p9_trans_module { |
| 46 | struct list_head list; | 89 | struct list_head list; |
| 47 | char *name; /* name of transport */ | 90 | char *name; /* name of transport */ |
| @@ -53,5 +96,4 @@ struct p9_trans_module { | |||
| 53 | void v9fs_register_trans(struct p9_trans_module *m); | 96 | void v9fs_register_trans(struct p9_trans_module *m); |
| 54 | struct p9_trans_module *v9fs_match_trans(const substring_t *name); | 97 | struct p9_trans_module *v9fs_match_trans(const substring_t *name); |
| 55 | struct p9_trans_module *v9fs_default_trans(void); | 98 | struct p9_trans_module *v9fs_default_trans(void); |
| 56 | |||
| 57 | #endif /* NET_9P_TRANSPORT_H */ | 99 | #endif /* NET_9P_TRANSPORT_H */ |
diff --git a/lib/parser.c b/lib/parser.c index 703c8c13b346..4f0cbc03e0e8 100644 --- a/lib/parser.c +++ b/lib/parser.c | |||
| @@ -182,18 +182,25 @@ int match_hex(substring_t *s, int *result) | |||
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | /** | 184 | /** |
| 185 | * match_strcpy: - copies the characters from a substring_t to a string | 185 | * match_strlcpy: - Copy the characters from a substring_t to a sized buffer |
| 186 | * @to: string to copy characters to. | 186 | * @dest: where to copy to |
| 187 | * @s: &substring_t to copy | 187 | * @src: &substring_t to copy |
| 188 | * @size: size of destination buffer | ||
| 188 | * | 189 | * |
| 189 | * Description: Copies the set of characters represented by the given | 190 | * Description: Copy the characters in &substring_t @src to the |
| 190 | * &substring_t @s to the c-style string @to. Caller guarantees that @to is | 191 | * c-style string @dest. Copy no more than @size - 1 characters, plus |
| 191 | * large enough to hold the characters of @s. | 192 | * the terminating NUL. Return length of @src. |
| 192 | */ | 193 | */ |
| 193 | void match_strcpy(char *to, const substring_t *s) | 194 | size_t match_strlcpy(char *dest, const substring_t *src, size_t size) |
| 194 | { | 195 | { |
| 195 | memcpy(to, s->from, s->to - s->from); | 196 | size_t ret = src->to - src->from; |
| 196 | to[s->to - s->from] = '\0'; | 197 | |
| 198 | if (size) { | ||
| 199 | size_t len = ret >= size ? size - 1 : ret; | ||
| 200 | memcpy(dest, src->from, len); | ||
| 201 | dest[len] = '\0'; | ||
| 202 | } | ||
| 203 | return ret; | ||
| 197 | } | 204 | } |
| 198 | 205 | ||
| 199 | /** | 206 | /** |
| @@ -206,9 +213,10 @@ void match_strcpy(char *to, const substring_t *s) | |||
| 206 | */ | 213 | */ |
| 207 | char *match_strdup(const substring_t *s) | 214 | char *match_strdup(const substring_t *s) |
| 208 | { | 215 | { |
| 209 | char *p = kmalloc(s->to - s->from + 1, GFP_KERNEL); | 216 | size_t sz = s->to - s->from + 1; |
| 217 | char *p = kmalloc(sz, GFP_KERNEL); | ||
| 210 | if (p) | 218 | if (p) |
| 211 | match_strcpy(p, s); | 219 | match_strlcpy(p, s, sz); |
| 212 | return p; | 220 | return p; |
| 213 | } | 221 | } |
| 214 | 222 | ||
| @@ -216,5 +224,5 @@ EXPORT_SYMBOL(match_token); | |||
| 216 | EXPORT_SYMBOL(match_int); | 224 | EXPORT_SYMBOL(match_int); |
| 217 | EXPORT_SYMBOL(match_octal); | 225 | EXPORT_SYMBOL(match_octal); |
| 218 | EXPORT_SYMBOL(match_hex); | 226 | EXPORT_SYMBOL(match_hex); |
| 219 | EXPORT_SYMBOL(match_strcpy); | 227 | EXPORT_SYMBOL(match_strlcpy); |
| 220 | EXPORT_SYMBOL(match_strdup); | 228 | EXPORT_SYMBOL(match_strdup); |
diff --git a/net/9p/Kconfig b/net/9p/Kconfig index bafc50c9e6ff..ff34c5acc130 100644 --- a/net/9p/Kconfig +++ b/net/9p/Kconfig | |||
| @@ -13,16 +13,6 @@ menuconfig NET_9P | |||
| 13 | 13 | ||
| 14 | If unsure, say N. | 14 | If unsure, say N. |
| 15 | 15 | ||
| 16 | config NET_9P_FD | ||
| 17 | depends on NET_9P | ||
| 18 | default y if NET_9P | ||
| 19 | tristate "9P File Descriptor Transports (Experimental)" | ||
| 20 | help | ||
| 21 | This builds support for file descriptor transports for 9p | ||
| 22 | which includes support for TCP/IP, named pipes, or passed | ||
| 23 | file descriptors. TCP/IP is the default transport for 9p, | ||
| 24 | so if you are going to use 9p, you'll likely want this. | ||
| 25 | |||
| 26 | config NET_9P_VIRTIO | 16 | config NET_9P_VIRTIO |
| 27 | depends on NET_9P && EXPERIMENTAL && VIRTIO | 17 | depends on NET_9P && EXPERIMENTAL && VIRTIO |
| 28 | tristate "9P Virtio Transport (Experimental)" | 18 | tristate "9P Virtio Transport (Experimental)" |
diff --git a/net/9p/Makefile b/net/9p/Makefile index 8a1051101898..519219480db1 100644 --- a/net/9p/Makefile +++ b/net/9p/Makefile | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | obj-$(CONFIG_NET_9P) := 9pnet.o | 1 | obj-$(CONFIG_NET_9P) := 9pnet.o |
| 2 | obj-$(CONFIG_NET_9P_FD) += 9pnet_fd.o | ||
| 3 | obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o | 2 | obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o |
| 4 | 3 | ||
| 5 | 9pnet-objs := \ | 4 | 9pnet-objs := \ |
| @@ -9,8 +8,6 @@ obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o | |||
| 9 | error.o \ | 8 | error.o \ |
| 10 | fcprint.o \ | 9 | fcprint.o \ |
| 11 | util.o \ | 10 | util.o \ |
| 12 | |||
| 13 | 9pnet_fd-objs := \ | ||
| 14 | trans_fd.o \ | 11 | trans_fd.o \ |
| 15 | 12 | ||
| 16 | 9pnet_virtio-objs := \ | 13 | 9pnet_virtio-objs := \ |
diff --git a/net/9p/client.c b/net/9p/client.c index 84e087e24146..2ffe40cf2f01 100644 --- a/net/9p/client.c +++ b/net/9p/client.c | |||
| @@ -64,21 +64,30 @@ static match_table_t tokens = { | |||
| 64 | * @options: options string passed from mount | 64 | * @options: options string passed from mount |
| 65 | * @v9ses: existing v9fs session information | 65 | * @v9ses: existing v9fs session information |
| 66 | * | 66 | * |
| 67 | * Return 0 upon success, -ERRNO upon failure | ||
| 67 | */ | 68 | */ |
| 68 | 69 | ||
| 69 | static void parse_opts(char *options, struct p9_client *clnt) | 70 | static int parse_opts(char *opts, struct p9_client *clnt) |
| 70 | { | 71 | { |
| 72 | char *options; | ||
| 71 | char *p; | 73 | char *p; |
| 72 | substring_t args[MAX_OPT_ARGS]; | 74 | substring_t args[MAX_OPT_ARGS]; |
| 73 | int option; | 75 | int option; |
| 74 | int ret; | 76 | int ret = 0; |
| 75 | 77 | ||
| 76 | clnt->trans_mod = v9fs_default_trans(); | 78 | clnt->trans_mod = v9fs_default_trans(); |
| 77 | clnt->dotu = 1; | 79 | clnt->dotu = 1; |
| 78 | clnt->msize = 8192; | 80 | clnt->msize = 8192; |
| 79 | 81 | ||
| 80 | if (!options) | 82 | if (!opts) |
| 81 | return; | 83 | return 0; |
| 84 | |||
| 85 | options = kstrdup(opts, GFP_KERNEL); | ||
| 86 | if (!options) { | ||
| 87 | P9_DPRINTK(P9_DEBUG_ERROR, | ||
| 88 | "failed to allocate copy of option string\n"); | ||
| 89 | return -ENOMEM; | ||
| 90 | } | ||
| 82 | 91 | ||
| 83 | while ((p = strsep(&options, ",")) != NULL) { | 92 | while ((p = strsep(&options, ",")) != NULL) { |
| 84 | int token; | 93 | int token; |
| @@ -86,10 +95,11 @@ static void parse_opts(char *options, struct p9_client *clnt) | |||
| 86 | continue; | 95 | continue; |
| 87 | token = match_token(p, tokens, args); | 96 | token = match_token(p, tokens, args); |
| 88 | if (token < Opt_trans) { | 97 | if (token < Opt_trans) { |
| 89 | ret = match_int(&args[0], &option); | 98 | int r = match_int(&args[0], &option); |
| 90 | if (ret < 0) { | 99 | if (r < 0) { |
| 91 | P9_DPRINTK(P9_DEBUG_ERROR, | 100 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 92 | "integer field, but no integer?\n"); | 101 | "integer field, but no integer?\n"); |
| 102 | ret = r; | ||
| 93 | continue; | 103 | continue; |
| 94 | } | 104 | } |
| 95 | } | 105 | } |
| @@ -107,6 +117,8 @@ static void parse_opts(char *options, struct p9_client *clnt) | |||
| 107 | continue; | 117 | continue; |
| 108 | } | 118 | } |
| 109 | } | 119 | } |
| 120 | kfree(options); | ||
| 121 | return ret; | ||
| 110 | } | 122 | } |
| 111 | 123 | ||
| 112 | 124 | ||
| @@ -138,16 +150,20 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) | |||
| 138 | if (!clnt) | 150 | if (!clnt) |
| 139 | return ERR_PTR(-ENOMEM); | 151 | return ERR_PTR(-ENOMEM); |
| 140 | 152 | ||
| 153 | clnt->trans = NULL; | ||
| 141 | spin_lock_init(&clnt->lock); | 154 | spin_lock_init(&clnt->lock); |
| 142 | INIT_LIST_HEAD(&clnt->fidlist); | 155 | INIT_LIST_HEAD(&clnt->fidlist); |
| 143 | clnt->fidpool = p9_idpool_create(); | 156 | clnt->fidpool = p9_idpool_create(); |
| 144 | if (!clnt->fidpool) { | 157 | if (IS_ERR(clnt->fidpool)) { |
| 145 | err = PTR_ERR(clnt->fidpool); | 158 | err = PTR_ERR(clnt->fidpool); |
| 146 | clnt->fidpool = NULL; | 159 | clnt->fidpool = NULL; |
| 147 | goto error; | 160 | goto error; |
| 148 | } | 161 | } |
| 149 | 162 | ||
| 150 | parse_opts(options, clnt); | 163 | err = parse_opts(options, clnt); |
| 164 | if (err < 0) | ||
| 165 | goto error; | ||
| 166 | |||
| 151 | if (clnt->trans_mod == NULL) { | 167 | if (clnt->trans_mod == NULL) { |
| 152 | err = -EPROTONOSUPPORT; | 168 | err = -EPROTONOSUPPORT; |
| 153 | P9_DPRINTK(P9_DEBUG_ERROR, | 169 | P9_DPRINTK(P9_DEBUG_ERROR, |
diff --git a/net/9p/conv.c b/net/9p/conv.c index 3fe35d532c87..44547201f5bc 100644 --- a/net/9p/conv.c +++ b/net/9p/conv.c | |||
| @@ -197,7 +197,7 @@ static void buf_get_qid(struct cbuf *bufp, struct p9_qid *qid) | |||
| 197 | 197 | ||
| 198 | /** | 198 | /** |
| 199 | * p9_size_wstat - calculate the size of a variable length stat struct | 199 | * p9_size_wstat - calculate the size of a variable length stat struct |
| 200 | * @stat: metadata (stat) structure | 200 | * @wstat: metadata (stat) structure |
| 201 | * @dotu: non-zero if 9P2000.u | 201 | * @dotu: non-zero if 9P2000.u |
| 202 | * | 202 | * |
| 203 | */ | 203 | */ |
| @@ -511,6 +511,12 @@ p9_create_common(struct cbuf *bufp, u32 size, u8 id) | |||
| 511 | return fc; | 511 | return fc; |
| 512 | } | 512 | } |
| 513 | 513 | ||
| 514 | /** | ||
| 515 | * p9_set_tag - set the tag field of an &p9_fcall structure | ||
| 516 | * @fc: fcall structure to set tag within | ||
| 517 | * @tag: tag id to set | ||
| 518 | */ | ||
| 519 | |||
| 514 | void p9_set_tag(struct p9_fcall *fc, u16 tag) | 520 | void p9_set_tag(struct p9_fcall *fc, u16 tag) |
| 515 | { | 521 | { |
| 516 | fc->tag = tag; | 522 | fc->tag = tag; |
| @@ -518,6 +524,12 @@ void p9_set_tag(struct p9_fcall *fc, u16 tag) | |||
| 518 | } | 524 | } |
| 519 | EXPORT_SYMBOL(p9_set_tag); | 525 | EXPORT_SYMBOL(p9_set_tag); |
| 520 | 526 | ||
| 527 | /** | ||
| 528 | * p9_create_tversion - allocates and creates a T_VERSION request | ||
| 529 | * @msize: requested maximum data size | ||
| 530 | * @version: version string to negotiate | ||
| 531 | * | ||
| 532 | */ | ||
| 521 | struct p9_fcall *p9_create_tversion(u32 msize, char *version) | 533 | struct p9_fcall *p9_create_tversion(u32 msize, char *version) |
| 522 | { | 534 | { |
| 523 | int size; | 535 | int size; |
| @@ -542,6 +554,16 @@ error: | |||
| 542 | } | 554 | } |
| 543 | EXPORT_SYMBOL(p9_create_tversion); | 555 | EXPORT_SYMBOL(p9_create_tversion); |
| 544 | 556 | ||
| 557 | /** | ||
| 558 | * p9_create_tauth - allocates and creates a T_AUTH request | ||
| 559 | * @afid: handle to use for authentication protocol | ||
| 560 | * @uname: user name attempting to authenticate | ||
| 561 | * @aname: mount specifier for remote server | ||
| 562 | * @n_uname: numeric id for user attempting to authneticate | ||
| 563 | * @dotu: 9P2000.u extension flag | ||
| 564 | * | ||
| 565 | */ | ||
| 566 | |||
| 545 | struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname, | 567 | struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname, |
| 546 | u32 n_uname, int dotu) | 568 | u32 n_uname, int dotu) |
| 547 | { | 569 | { |
| @@ -580,6 +602,18 @@ error: | |||
| 580 | } | 602 | } |
| 581 | EXPORT_SYMBOL(p9_create_tauth); | 603 | EXPORT_SYMBOL(p9_create_tauth); |
| 582 | 604 | ||
| 605 | /** | ||
| 606 | * p9_create_tattach - allocates and creates a T_ATTACH request | ||
| 607 | * @fid: handle to use for the new mount point | ||
| 608 | * @afid: handle to use for authentication protocol | ||
| 609 | * @uname: user name attempting to attach | ||
| 610 | * @aname: mount specifier for remote server | ||
| 611 | * @n_uname: numeric id for user attempting to attach | ||
| 612 | * @n_uname: numeric id for user attempting to attach | ||
| 613 | * @dotu: 9P2000.u extension flag | ||
| 614 | * | ||
| 615 | */ | ||
| 616 | |||
| 583 | struct p9_fcall * | 617 | struct p9_fcall * |
| 584 | p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname, | 618 | p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname, |
| 585 | u32 n_uname, int dotu) | 619 | u32 n_uname, int dotu) |
| @@ -616,6 +650,12 @@ error: | |||
| 616 | } | 650 | } |
| 617 | EXPORT_SYMBOL(p9_create_tattach); | 651 | EXPORT_SYMBOL(p9_create_tattach); |
| 618 | 652 | ||
| 653 | /** | ||
| 654 | * p9_create_tflush - allocates and creates a T_FLUSH request | ||
| 655 | * @oldtag: tag id for the transaction we are attempting to cancel | ||
| 656 | * | ||
| 657 | */ | ||
| 658 | |||
| 619 | struct p9_fcall *p9_create_tflush(u16 oldtag) | 659 | struct p9_fcall *p9_create_tflush(u16 oldtag) |
| 620 | { | 660 | { |
| 621 | int size; | 661 | int size; |
| @@ -639,6 +679,15 @@ error: | |||
| 639 | } | 679 | } |
| 640 | EXPORT_SYMBOL(p9_create_tflush); | 680 | EXPORT_SYMBOL(p9_create_tflush); |
| 641 | 681 | ||
| 682 | /** | ||
| 683 | * p9_create_twalk - allocates and creates a T_FLUSH request | ||
| 684 | * @fid: handle we are traversing from | ||
| 685 | * @newfid: a new handle for this transaction | ||
| 686 | * @nwname: number of path elements to traverse | ||
| 687 | * @wnames: array of path elements | ||
| 688 | * | ||
| 689 | */ | ||
| 690 | |||
| 642 | struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname, | 691 | struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname, |
| 643 | char **wnames) | 692 | char **wnames) |
| 644 | { | 693 | { |
| @@ -677,6 +726,13 @@ error: | |||
| 677 | } | 726 | } |
| 678 | EXPORT_SYMBOL(p9_create_twalk); | 727 | EXPORT_SYMBOL(p9_create_twalk); |
| 679 | 728 | ||
| 729 | /** | ||
| 730 | * p9_create_topen - allocates and creates a T_OPEN request | ||
| 731 | * @fid: handle we are trying to open | ||
| 732 | * @mode: what mode we are trying to open the file in | ||
| 733 | * | ||
| 734 | */ | ||
| 735 | |||
| 680 | struct p9_fcall *p9_create_topen(u32 fid, u8 mode) | 736 | struct p9_fcall *p9_create_topen(u32 fid, u8 mode) |
| 681 | { | 737 | { |
| 682 | int size; | 738 | int size; |
| @@ -701,6 +757,19 @@ error: | |||
| 701 | } | 757 | } |
| 702 | EXPORT_SYMBOL(p9_create_topen); | 758 | EXPORT_SYMBOL(p9_create_topen); |
| 703 | 759 | ||
| 760 | /** | ||
| 761 | * p9_create_tcreate - allocates and creates a T_CREATE request | ||
| 762 | * @fid: handle of directory we are trying to create in | ||
| 763 | * @name: name of the file we are trying to create | ||
| 764 | * @perm: permissions for the file we are trying to create | ||
| 765 | * @mode: what mode we are trying to open the file in | ||
| 766 | * @extension: 9p2000.u extension string (for special files) | ||
| 767 | * @dotu: 9p2000.u enabled flag | ||
| 768 | * | ||
| 769 | * Note: Plan 9 create semantics include opening the resulting file | ||
| 770 | * which is why mode is included. | ||
| 771 | */ | ||
| 772 | |||
| 704 | struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode, | 773 | struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode, |
| 705 | char *extension, int dotu) | 774 | char *extension, int dotu) |
| 706 | { | 775 | { |
| @@ -736,6 +805,13 @@ error: | |||
| 736 | } | 805 | } |
| 737 | EXPORT_SYMBOL(p9_create_tcreate); | 806 | EXPORT_SYMBOL(p9_create_tcreate); |
| 738 | 807 | ||
| 808 | /** | ||
| 809 | * p9_create_tread - allocates and creates a T_READ request | ||
| 810 | * @fid: handle of the file we are trying to read | ||
| 811 | * @offset: offset to start reading from | ||
| 812 | * @count: how many bytes to read | ||
| 813 | */ | ||
| 814 | |||
| 739 | struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count) | 815 | struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count) |
| 740 | { | 816 | { |
| 741 | int size; | 817 | int size; |
| @@ -761,6 +837,17 @@ error: | |||
| 761 | } | 837 | } |
| 762 | EXPORT_SYMBOL(p9_create_tread); | 838 | EXPORT_SYMBOL(p9_create_tread); |
| 763 | 839 | ||
| 840 | /** | ||
| 841 | * p9_create_twrite - allocates and creates a T_WRITE request from the kernel | ||
| 842 | * @fid: handle of the file we are trying to write | ||
| 843 | * @offset: offset to start writing at | ||
| 844 | * @count: how many bytes to write | ||
| 845 | * @data: data to write | ||
| 846 | * | ||
| 847 | * This function will create a requst with data buffers from the kernel | ||
| 848 | * such as the page cache. | ||
| 849 | */ | ||
| 850 | |||
| 764 | struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count, | 851 | struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count, |
| 765 | const char *data) | 852 | const char *data) |
| 766 | { | 853 | { |
| @@ -794,6 +881,16 @@ error: | |||
| 794 | } | 881 | } |
| 795 | EXPORT_SYMBOL(p9_create_twrite); | 882 | EXPORT_SYMBOL(p9_create_twrite); |
| 796 | 883 | ||
| 884 | /** | ||
| 885 | * p9_create_twrite_u - allocates and creates a T_WRITE request from userspace | ||
| 886 | * @fid: handle of the file we are trying to write | ||
| 887 | * @offset: offset to start writing at | ||
| 888 | * @count: how many bytes to write | ||
| 889 | * @data: data to write | ||
| 890 | * | ||
| 891 | * This function will create a request with data buffers from userspace | ||
| 892 | */ | ||
| 893 | |||
| 797 | struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count, | 894 | struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count, |
| 798 | const char __user *data) | 895 | const char __user *data) |
| 799 | { | 896 | { |
| @@ -827,6 +924,14 @@ error: | |||
| 827 | } | 924 | } |
| 828 | EXPORT_SYMBOL(p9_create_twrite_u); | 925 | EXPORT_SYMBOL(p9_create_twrite_u); |
| 829 | 926 | ||
| 927 | /** | ||
| 928 | * p9_create_tclunk - allocate a request to forget about a file handle | ||
| 929 | * @fid: handle of the file we closing or forgetting about | ||
| 930 | * | ||
| 931 | * clunk is used both to close open files and to discard transient handles | ||
| 932 | * which may be created during meta-data operations and hierarchy traversal. | ||
| 933 | */ | ||
| 934 | |||
| 830 | struct p9_fcall *p9_create_tclunk(u32 fid) | 935 | struct p9_fcall *p9_create_tclunk(u32 fid) |
| 831 | { | 936 | { |
| 832 | int size; | 937 | int size; |
| @@ -850,6 +955,12 @@ error: | |||
| 850 | } | 955 | } |
| 851 | EXPORT_SYMBOL(p9_create_tclunk); | 956 | EXPORT_SYMBOL(p9_create_tclunk); |
| 852 | 957 | ||
| 958 | /** | ||
| 959 | * p9_create_tremove - allocate and create a request to remove a file | ||
| 960 | * @fid: handle of the file or directory we are removing | ||
| 961 | * | ||
| 962 | */ | ||
| 963 | |||
| 853 | struct p9_fcall *p9_create_tremove(u32 fid) | 964 | struct p9_fcall *p9_create_tremove(u32 fid) |
| 854 | { | 965 | { |
| 855 | int size; | 966 | int size; |
| @@ -873,6 +984,12 @@ error: | |||
| 873 | } | 984 | } |
| 874 | EXPORT_SYMBOL(p9_create_tremove); | 985 | EXPORT_SYMBOL(p9_create_tremove); |
| 875 | 986 | ||
| 987 | /** | ||
| 988 | * p9_create_tstat - allocate and populate a request for attributes | ||
| 989 | * @fid: handle of the file or directory we are trying to get the attributes of | ||
| 990 | * | ||
| 991 | */ | ||
| 992 | |||
| 876 | struct p9_fcall *p9_create_tstat(u32 fid) | 993 | struct p9_fcall *p9_create_tstat(u32 fid) |
| 877 | { | 994 | { |
| 878 | int size; | 995 | int size; |
| @@ -896,6 +1013,14 @@ error: | |||
| 896 | } | 1013 | } |
| 897 | EXPORT_SYMBOL(p9_create_tstat); | 1014 | EXPORT_SYMBOL(p9_create_tstat); |
| 898 | 1015 | ||
| 1016 | /** | ||
| 1017 | * p9_create_tstat - allocate and populate a request to change attributes | ||
| 1018 | * @fid: handle of the file or directory we are trying to change | ||
| 1019 | * @wstat: &p9_stat structure with attributes we wish to set | ||
| 1020 | * @dotu: 9p2000.u enabled flag | ||
| 1021 | * | ||
| 1022 | */ | ||
| 1023 | |||
| 899 | struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat, | 1024 | struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat, |
| 900 | int dotu) | 1025 | int dotu) |
| 901 | { | 1026 | { |
| @@ -922,3 +1047,4 @@ error: | |||
| 922 | return fc; | 1047 | return fc; |
| 923 | } | 1048 | } |
| 924 | EXPORT_SYMBOL(p9_create_twstat); | 1049 | EXPORT_SYMBOL(p9_create_twstat); |
| 1050 | |||
diff --git a/net/9p/error.c b/net/9p/error.c index 64104b9cb422..fdebe4314062 100644 --- a/net/9p/error.c +++ b/net/9p/error.c | |||
| @@ -33,6 +33,13 @@ | |||
| 33 | #include <linux/errno.h> | 33 | #include <linux/errno.h> |
| 34 | #include <net/9p/9p.h> | 34 | #include <net/9p/9p.h> |
| 35 | 35 | ||
| 36 | /** | ||
| 37 | * struct errormap - map string errors from Plan 9 to Linux numeric ids | ||
| 38 | * @name: string sent over 9P | ||
| 39 | * @val: numeric id most closely representing @name | ||
| 40 | * @namelen: length of string | ||
| 41 | * @list: hash-table list for string lookup | ||
| 42 | */ | ||
| 36 | struct errormap { | 43 | struct errormap { |
| 37 | char *name; | 44 | char *name; |
| 38 | int val; | 45 | int val; |
| @@ -177,8 +184,7 @@ static struct errormap errmap[] = { | |||
| 177 | }; | 184 | }; |
| 178 | 185 | ||
| 179 | /** | 186 | /** |
| 180 | * p9_error_init - preload | 187 | * p9_error_init - preload mappings into hash list |
| 181 | * @errstr: error string | ||
| 182 | * | 188 | * |
| 183 | */ | 189 | */ |
| 184 | 190 | ||
| @@ -206,6 +212,7 @@ EXPORT_SYMBOL(p9_error_init); | |||
| 206 | /** | 212 | /** |
| 207 | * errstr2errno - convert error string to error number | 213 | * errstr2errno - convert error string to error number |
| 208 | * @errstr: error string | 214 | * @errstr: error string |
| 215 | * @len: length of error string | ||
| 209 | * | 216 | * |
| 210 | */ | 217 | */ |
| 211 | 218 | ||
| @@ -230,8 +237,8 @@ int p9_errstr2errno(char *errstr, int len) | |||
| 230 | if (errno == 0) { | 237 | if (errno == 0) { |
| 231 | /* TODO: if error isn't found, add it dynamically */ | 238 | /* TODO: if error isn't found, add it dynamically */ |
| 232 | errstr[len] = 0; | 239 | errstr[len] = 0; |
| 233 | printk(KERN_ERR "%s: errstr :%s: not found\n", __func__, | 240 | printk(KERN_ERR "%s: server reported unknown error %s\n", |
| 234 | errstr); | 241 | __func__, errstr); |
| 235 | errno = 1; | 242 | errno = 1; |
| 236 | } | 243 | } |
| 237 | 244 | ||
diff --git a/net/9p/fcprint.c b/net/9p/fcprint.c index 40244fbd9b0d..53dd8e28dd8a 100644 --- a/net/9p/fcprint.c +++ b/net/9p/fcprint.c | |||
| @@ -142,6 +142,14 @@ p9_printdata(char *buf, int buflen, u8 *data, int datalen) | |||
| 142 | return p9_dumpdata(buf, buflen, data, datalen < 16?datalen:16); | 142 | return p9_dumpdata(buf, buflen, data, datalen < 16?datalen:16); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | /** | ||
| 146 | * p9_printfcall - decode and print a protocol structure into a buffer | ||
| 147 | * @buf: buffer to deposit decoded structure into | ||
| 148 | * @buflen: available space in buffer | ||
| 149 | * @fc: protocol rpc structure of type &p9_fcall | ||
| 150 | * @extended: whether or not session is operating with extended protocol | ||
| 151 | */ | ||
| 152 | |||
| 145 | int | 153 | int |
| 146 | p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended) | 154 | p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended) |
| 147 | { | 155 | { |
diff --git a/net/9p/mod.c b/net/9p/mod.c index c285aab2af04..bdee1fb7cc62 100644 --- a/net/9p/mod.c +++ b/net/9p/mod.c | |||
| @@ -39,9 +39,6 @@ module_param_named(debug, p9_debug_level, uint, 0); | |||
| 39 | MODULE_PARM_DESC(debug, "9P debugging level"); | 39 | MODULE_PARM_DESC(debug, "9P debugging level"); |
| 40 | #endif | 40 | #endif |
| 41 | 41 | ||
| 42 | extern int p9_mux_global_init(void); | ||
| 43 | extern void p9_mux_global_exit(void); | ||
| 44 | |||
| 45 | /* | 42 | /* |
| 46 | * Dynamic Transport Registration Routines | 43 | * Dynamic Transport Registration Routines |
| 47 | * | 44 | * |
| @@ -52,7 +49,7 @@ static struct p9_trans_module *v9fs_default_transport; | |||
| 52 | 49 | ||
| 53 | /** | 50 | /** |
| 54 | * v9fs_register_trans - register a new transport with 9p | 51 | * v9fs_register_trans - register a new transport with 9p |
| 55 | * @m - structure describing the transport module and entry points | 52 | * @m: structure describing the transport module and entry points |
| 56 | * | 53 | * |
| 57 | */ | 54 | */ |
| 58 | void v9fs_register_trans(struct p9_trans_module *m) | 55 | void v9fs_register_trans(struct p9_trans_module *m) |
| @@ -65,7 +62,7 @@ EXPORT_SYMBOL(v9fs_register_trans); | |||
| 65 | 62 | ||
| 66 | /** | 63 | /** |
| 67 | * v9fs_match_trans - match transport versus registered transports | 64 | * v9fs_match_trans - match transport versus registered transports |
| 68 | * @arg: string identifying transport | 65 | * @name: string identifying transport |
| 69 | * | 66 | * |
| 70 | */ | 67 | */ |
| 71 | struct p9_trans_module *v9fs_match_trans(const substring_t *name) | 68 | struct p9_trans_module *v9fs_match_trans(const substring_t *name) |
| @@ -110,6 +107,7 @@ static int __init init_p9(void) | |||
| 110 | 107 | ||
| 111 | p9_error_init(); | 108 | p9_error_init(); |
| 112 | printk(KERN_INFO "Installing 9P2000 support\n"); | 109 | printk(KERN_INFO "Installing 9P2000 support\n"); |
| 110 | p9_trans_fd_init(); | ||
| 113 | 111 | ||
| 114 | return ret; | 112 | return ret; |
| 115 | } | 113 | } |
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index f624dff76852..4507f744f44e 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c | |||
| @@ -47,12 +47,29 @@ | |||
| 47 | #define SCHED_TIMEOUT 10 | 47 | #define SCHED_TIMEOUT 10 |
| 48 | #define MAXPOLLWADDR 2 | 48 | #define MAXPOLLWADDR 2 |
| 49 | 49 | ||
| 50 | /** | ||
| 51 | * struct p9_fd_opts - per-transport options | ||
| 52 | * @rfd: file descriptor for reading (trans=fd) | ||
| 53 | * @wfd: file descriptor for writing (trans=fd) | ||
| 54 | * @port: port to connect to (trans=tcp) | ||
| 55 | * | ||
| 56 | */ | ||
| 57 | |||
| 50 | struct p9_fd_opts { | 58 | struct p9_fd_opts { |
| 51 | int rfd; | 59 | int rfd; |
| 52 | int wfd; | 60 | int wfd; |
| 53 | u16 port; | 61 | u16 port; |
| 54 | }; | 62 | }; |
| 55 | 63 | ||
| 64 | |||
| 65 | /** | ||
| 66 | * struct p9_trans_fd - transport state | ||
| 67 | * @rd: reference to file to read from | ||
| 68 | * @wr: reference of file to write to | ||
| 69 | * @conn: connection state reference | ||
| 70 | * | ||
| 71 | */ | ||
| 72 | |||
| 56 | struct p9_trans_fd { | 73 | struct p9_trans_fd { |
| 57 | struct file *rd; | 74 | struct file *rd; |
| 58 | struct file *wr; | 75 | struct file *wr; |
| @@ -90,10 +107,24 @@ enum { | |||
| 90 | }; | 107 | }; |
| 91 | 108 | ||
| 92 | struct p9_req; | 109 | struct p9_req; |
| 93 | |||
| 94 | typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a); | 110 | typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a); |
| 111 | |||
| 112 | /** | ||
| 113 | * struct p9_req - fd mux encoding of an rpc transaction | ||
| 114 | * @lock: protects req_list | ||
| 115 | * @tag: numeric tag for rpc transaction | ||
| 116 | * @tcall: request &p9_fcall structure | ||
| 117 | * @rcall: response &p9_fcall structure | ||
| 118 | * @err: error state | ||
| 119 | * @cb: callback for when response is received | ||
| 120 | * @cba: argument to pass to callback | ||
| 121 | * @flush: flag to indicate RPC has been flushed | ||
| 122 | * @req_list: list link for higher level objects to chain requests | ||
| 123 | * | ||
| 124 | */ | ||
| 125 | |||
| 95 | struct p9_req { | 126 | struct p9_req { |
| 96 | spinlock_t lock; /* protect request structure */ | 127 | spinlock_t lock; |
| 97 | int tag; | 128 | int tag; |
| 98 | struct p9_fcall *tcall; | 129 | struct p9_fcall *tcall; |
| 99 | struct p9_fcall *rcall; | 130 | struct p9_fcall *rcall; |
| @@ -104,7 +135,39 @@ struct p9_req { | |||
| 104 | struct list_head req_list; | 135 | struct list_head req_list; |
| 105 | }; | 136 | }; |
| 106 | 137 | ||
| 107 | struct p9_mux_poll_task; | 138 | struct p9_mux_poll_task { |
| 139 | struct task_struct *task; | ||
| 140 | struct list_head mux_list; | ||
| 141 | int muxnum; | ||
| 142 | }; | ||
| 143 | |||
| 144 | /** | ||
| 145 | * struct p9_conn - fd mux connection state information | ||
| 146 | * @lock: protects mux_list (?) | ||
| 147 | * @mux_list: list link for mux to manage multiple connections (?) | ||
| 148 | * @poll_task: task polling on this connection | ||
| 149 | * @msize: maximum size for connection (dup) | ||
| 150 | * @extended: 9p2000.u flag (dup) | ||
| 151 | * @trans: reference to transport instance for this connection | ||
| 152 | * @tagpool: id accounting for transactions | ||
| 153 | * @err: error state | ||
| 154 | * @equeue: event wait_q (?) | ||
| 155 | * @req_list: accounting for requests which have been sent | ||
| 156 | * @unsent_req_list: accounting for requests that haven't been sent | ||
| 157 | * @rcall: current response &p9_fcall structure | ||
| 158 | * @rpos: read position in current frame | ||
| 159 | * @rbuf: current read buffer | ||
| 160 | * @wpos: write position for current frame | ||
| 161 | * @wsize: amount of data to write for current frame | ||
| 162 | * @wbuf: current write buffer | ||
| 163 | * @poll_wait: array of wait_q's for various worker threads | ||
| 164 | * @poll_waddr: ???? | ||
| 165 | * @pt: poll state | ||
| 166 | * @rq: current read work | ||
| 167 | * @wq: current write work | ||
| 168 | * @wsched: ???? | ||
| 169 | * | ||
| 170 | */ | ||
| 108 | 171 | ||
| 109 | struct p9_conn { | 172 | struct p9_conn { |
| 110 | spinlock_t lock; /* protect lock structure */ | 173 | spinlock_t lock; /* protect lock structure */ |
| @@ -132,11 +195,16 @@ struct p9_conn { | |||
| 132 | unsigned long wsched; | 195 | unsigned long wsched; |
| 133 | }; | 196 | }; |
| 134 | 197 | ||
| 135 | struct p9_mux_poll_task { | 198 | /** |
| 136 | struct task_struct *task; | 199 | * struct p9_mux_rpc - fd mux rpc accounting structure |
| 137 | struct list_head mux_list; | 200 | * @m: connection this request was issued on |
| 138 | int muxnum; | 201 | * @err: error state |
| 139 | }; | 202 | * @tcall: request &p9_fcall |
| 203 | * @rcall: response &p9_fcall | ||
| 204 | * @wqueue: wait queue that client is blocked on for this rpc | ||
| 205 | * | ||
| 206 | * Bug: isn't this information duplicated elsewhere like &p9_req | ||
| 207 | */ | ||
| 140 | 208 | ||
| 141 | struct p9_mux_rpc { | 209 | struct p9_mux_rpc { |
| 142 | struct p9_conn *m; | 210 | struct p9_conn *m; |
| @@ -207,10 +275,12 @@ static void p9_mux_put_tag(struct p9_conn *m, u16 tag) | |||
| 207 | 275 | ||
| 208 | /** | 276 | /** |
| 209 | * p9_mux_calc_poll_procs - calculates the number of polling procs | 277 | * p9_mux_calc_poll_procs - calculates the number of polling procs |
| 210 | * based on the number of mounted v9fs filesystems. | 278 | * @muxnum: number of mounts |
| 211 | * | 279 | * |
| 280 | * Calculation is based on the number of mounted v9fs filesystems. | ||
| 212 | * The current implementation returns sqrt of the number of mounts. | 281 | * The current implementation returns sqrt of the number of mounts. |
| 213 | */ | 282 | */ |
| 283 | |||
| 214 | static int p9_mux_calc_poll_procs(int muxnum) | 284 | static int p9_mux_calc_poll_procs(int muxnum) |
| 215 | { | 285 | { |
| 216 | int n; | 286 | int n; |
| @@ -331,12 +401,11 @@ static void p9_mux_poll_stop(struct p9_conn *m) | |||
| 331 | 401 | ||
| 332 | /** | 402 | /** |
| 333 | * p9_conn_create - allocate and initialize the per-session mux data | 403 | * p9_conn_create - allocate and initialize the per-session mux data |
| 334 | * Creates the polling task if this is the first session. | 404 | * @trans: transport structure |
| 335 | * | 405 | * |
| 336 | * @trans - transport structure | 406 | * Note: Creates the polling task if this is the first session. |
| 337 | * @msize - maximum message size | ||
| 338 | * @extended - extended flag | ||
| 339 | */ | 407 | */ |
| 408 | |||
| 340 | static struct p9_conn *p9_conn_create(struct p9_trans *trans) | 409 | static struct p9_conn *p9_conn_create(struct p9_trans *trans) |
| 341 | { | 410 | { |
| 342 | int i, n; | 411 | int i, n; |
| @@ -406,7 +475,10 @@ static struct p9_conn *p9_conn_create(struct p9_trans *trans) | |||
| 406 | 475 | ||
| 407 | /** | 476 | /** |
| 408 | * p9_mux_destroy - cancels all pending requests and frees mux resources | 477 | * p9_mux_destroy - cancels all pending requests and frees mux resources |
| 478 | * @m: mux to destroy | ||
| 479 | * | ||
| 409 | */ | 480 | */ |
| 481 | |||
| 410 | static void p9_conn_destroy(struct p9_conn *m) | 482 | static void p9_conn_destroy(struct p9_conn *m) |
| 411 | { | 483 | { |
| 412 | P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m, | 484 | P9_DPRINTK(P9_DEBUG_MUX, "mux %p prev %p next %p\n", m, |
| @@ -429,9 +501,14 @@ static void p9_conn_destroy(struct p9_conn *m) | |||
| 429 | } | 501 | } |
| 430 | 502 | ||
| 431 | /** | 503 | /** |
| 432 | * p9_pollwait - called by files poll operation to add v9fs-poll task | 504 | * p9_pollwait - add poll task to the wait queue |
| 433 | * to files wait queue | 505 | * @filp: file pointer being polled |
| 506 | * @wait_address: wait_q to block on | ||
| 507 | * @p: poll state | ||
| 508 | * | ||
| 509 | * called by files poll operation to add v9fs-poll task to files wait queue | ||
| 434 | */ | 510 | */ |
| 511 | |||
| 435 | static void | 512 | static void |
| 436 | p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p) | 513 | p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p) |
| 437 | { | 514 | { |
| @@ -462,7 +539,10 @@ p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, poll_table *p) | |||
| 462 | 539 | ||
| 463 | /** | 540 | /** |
| 464 | * p9_poll_mux - polls a mux and schedules read or write works if necessary | 541 | * p9_poll_mux - polls a mux and schedules read or write works if necessary |
| 542 | * @m: connection to poll | ||
| 543 | * | ||
| 465 | */ | 544 | */ |
| 545 | |||
| 466 | static void p9_poll_mux(struct p9_conn *m) | 546 | static void p9_poll_mux(struct p9_conn *m) |
| 467 | { | 547 | { |
| 468 | int n; | 548 | int n; |
| @@ -499,9 +579,14 @@ static void p9_poll_mux(struct p9_conn *m) | |||
| 499 | } | 579 | } |
| 500 | 580 | ||
| 501 | /** | 581 | /** |
| 502 | * p9_poll_proc - polls all v9fs transports for new events and queues | 582 | * p9_poll_proc - poll worker thread |
| 503 | * the appropriate work to the work queue | 583 | * @a: thread state and arguments |
| 584 | * | ||
| 585 | * polls all v9fs transports for new events and queues the appropriate | ||
| 586 | * work to the work queue | ||
| 587 | * | ||
| 504 | */ | 588 | */ |
| 589 | |||
| 505 | static int p9_poll_proc(void *a) | 590 | static int p9_poll_proc(void *a) |
| 506 | { | 591 | { |
| 507 | struct p9_conn *m, *mtmp; | 592 | struct p9_conn *m, *mtmp; |
| @@ -527,7 +612,10 @@ static int p9_poll_proc(void *a) | |||
| 527 | 612 | ||
| 528 | /** | 613 | /** |
| 529 | * p9_write_work - called when a transport can send some data | 614 | * p9_write_work - called when a transport can send some data |
| 615 | * @work: container for work to be done | ||
| 616 | * | ||
| 530 | */ | 617 | */ |
| 618 | |||
| 531 | static void p9_write_work(struct work_struct *work) | 619 | static void p9_write_work(struct work_struct *work) |
| 532 | { | 620 | { |
| 533 | int n, err; | 621 | int n, err; |
| @@ -638,7 +726,10 @@ static void process_request(struct p9_conn *m, struct p9_req *req) | |||
| 638 | 726 | ||
| 639 | /** | 727 | /** |
| 640 | * p9_read_work - called when there is some data to be read from a transport | 728 | * p9_read_work - called when there is some data to be read from a transport |
| 729 | * @work: container of work to be done | ||
| 730 | * | ||
| 641 | */ | 731 | */ |
| 732 | |||
| 642 | static void p9_read_work(struct work_struct *work) | 733 | static void p9_read_work(struct work_struct *work) |
| 643 | { | 734 | { |
| 644 | int n, err; | 735 | int n, err; |
| @@ -793,7 +884,9 @@ error: | |||
| 793 | * @tc: request to be sent | 884 | * @tc: request to be sent |
| 794 | * @cb: callback function to call when response is received | 885 | * @cb: callback function to call when response is received |
| 795 | * @cba: parameter to pass to the callback function | 886 | * @cba: parameter to pass to the callback function |
| 887 | * | ||
| 796 | */ | 888 | */ |
| 889 | |||
| 797 | static struct p9_req *p9_send_request(struct p9_conn *m, | 890 | static struct p9_req *p9_send_request(struct p9_conn *m, |
| 798 | struct p9_fcall *tc, | 891 | struct p9_fcall *tc, |
| 799 | p9_conn_req_callback cb, void *cba) | 892 | p9_conn_req_callback cb, void *cba) |
| @@ -961,10 +1054,12 @@ p9_conn_rpc_cb(struct p9_req *req, void *a) | |||
| 961 | /** | 1054 | /** |
| 962 | * p9_fd_rpc- sends 9P request and waits until a response is available. | 1055 | * p9_fd_rpc- sends 9P request and waits until a response is available. |
| 963 | * The function can be interrupted. | 1056 | * The function can be interrupted. |
| 964 | * @m: mux data | 1057 | * @t: transport data |
| 965 | * @tc: request to be sent | 1058 | * @tc: request to be sent |
| 966 | * @rc: pointer where a pointer to the response is stored | 1059 | * @rc: pointer where a pointer to the response is stored |
| 1060 | * | ||
| 967 | */ | 1061 | */ |
| 1062 | |||
| 968 | int | 1063 | int |
| 969 | p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) | 1064 | p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) |
| 970 | { | 1065 | { |
| @@ -1041,8 +1136,10 @@ p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) | |||
| 1041 | * @m: mux data | 1136 | * @m: mux data |
| 1042 | * @tc: request to be sent | 1137 | * @tc: request to be sent |
| 1043 | * @cb: callback function to be called when response arrives | 1138 | * @cb: callback function to be called when response arrives |
| 1044 | * @cba: value to pass to the callback function | 1139 | * @a: value to pass to the callback function |
| 1140 | * | ||
| 1045 | */ | 1141 | */ |
| 1142 | |||
| 1046 | int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc, | 1143 | int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc, |
| 1047 | p9_conn_req_callback cb, void *a) | 1144 | p9_conn_req_callback cb, void *a) |
| 1048 | { | 1145 | { |
| @@ -1065,7 +1162,9 @@ int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc, | |||
| 1065 | * p9_conn_cancel - cancel all pending requests with error | 1162 | * p9_conn_cancel - cancel all pending requests with error |
| 1066 | * @m: mux data | 1163 | * @m: mux data |
| 1067 | * @err: error code | 1164 | * @err: error code |
| 1165 | * | ||
| 1068 | */ | 1166 | */ |
| 1167 | |||
| 1069 | void p9_conn_cancel(struct p9_conn *m, int err) | 1168 | void p9_conn_cancel(struct p9_conn *m, int err) |
| 1070 | { | 1169 | { |
| 1071 | struct p9_req *req, *rtmp; | 1170 | struct p9_req *req, *rtmp; |
| @@ -1097,35 +1196,46 @@ void p9_conn_cancel(struct p9_conn *m, int err) | |||
| 1097 | } | 1196 | } |
| 1098 | 1197 | ||
| 1099 | /** | 1198 | /** |
| 1100 | * v9fs_parse_options - parse mount options into session structure | 1199 | * parse_options - parse mount options into session structure |
| 1101 | * @options: options string passed from mount | 1200 | * @options: options string passed from mount |
| 1102 | * @v9ses: existing v9fs session information | 1201 | * @opts: transport-specific structure to parse options into |
| 1103 | * | 1202 | * |
| 1203 | * Returns 0 upon success, -ERRNO upon failure | ||
| 1104 | */ | 1204 | */ |
| 1105 | 1205 | ||
| 1106 | static void parse_opts(char *options, struct p9_fd_opts *opts) | 1206 | static int parse_opts(char *params, struct p9_fd_opts *opts) |
| 1107 | { | 1207 | { |
| 1108 | char *p; | 1208 | char *p; |
| 1109 | substring_t args[MAX_OPT_ARGS]; | 1209 | substring_t args[MAX_OPT_ARGS]; |
| 1110 | int option; | 1210 | int option; |
| 1211 | char *options; | ||
| 1111 | int ret; | 1212 | int ret; |
| 1112 | 1213 | ||
| 1113 | opts->port = P9_PORT; | 1214 | opts->port = P9_PORT; |
| 1114 | opts->rfd = ~0; | 1215 | opts->rfd = ~0; |
| 1115 | opts->wfd = ~0; | 1216 | opts->wfd = ~0; |
| 1116 | 1217 | ||
| 1117 | if (!options) | 1218 | if (!params) |
| 1118 | return; | 1219 | return 0; |
| 1220 | |||
| 1221 | options = kstrdup(params, GFP_KERNEL); | ||
| 1222 | if (!options) { | ||
| 1223 | P9_DPRINTK(P9_DEBUG_ERROR, | ||
| 1224 | "failed to allocate copy of option string\n"); | ||
| 1225 | return -ENOMEM; | ||
| 1226 | } | ||
| 1119 | 1227 | ||
| 1120 | while ((p = strsep(&options, ",")) != NULL) { | 1228 | while ((p = strsep(&options, ",")) != NULL) { |
| 1121 | int token; | 1229 | int token; |
| 1230 | int r; | ||
| 1122 | if (!*p) | 1231 | if (!*p) |
| 1123 | continue; | 1232 | continue; |
| 1124 | token = match_token(p, tokens, args); | 1233 | token = match_token(p, tokens, args); |
| 1125 | ret = match_int(&args[0], &option); | 1234 | r = match_int(&args[0], &option); |
| 1126 | if (ret < 0) { | 1235 | if (r < 0) { |
| 1127 | P9_DPRINTK(P9_DEBUG_ERROR, | 1236 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 1128 | "integer field, but no integer?\n"); | 1237 | "integer field, but no integer?\n"); |
| 1238 | ret = r; | ||
| 1129 | continue; | 1239 | continue; |
| 1130 | } | 1240 | } |
| 1131 | switch (token) { | 1241 | switch (token) { |
| @@ -1142,6 +1252,8 @@ static void parse_opts(char *options, struct p9_fd_opts *opts) | |||
| 1142 | continue; | 1252 | continue; |
| 1143 | } | 1253 | } |
| 1144 | } | 1254 | } |
| 1255 | kfree(options); | ||
| 1256 | return 0; | ||
| 1145 | } | 1257 | } |
| 1146 | 1258 | ||
| 1147 | static int p9_fd_open(struct p9_trans *trans, int rfd, int wfd) | 1259 | static int p9_fd_open(struct p9_trans *trans, int rfd, int wfd) |
| @@ -1193,11 +1305,12 @@ static int p9_socket_open(struct p9_trans *trans, struct socket *csocket) | |||
| 1193 | 1305 | ||
| 1194 | /** | 1306 | /** |
| 1195 | * p9_fd_read- read from a fd | 1307 | * p9_fd_read- read from a fd |
| 1196 | * @v9ses: session information | 1308 | * @trans: transport instance state |
| 1197 | * @v: buffer to receive data into | 1309 | * @v: buffer to receive data into |
| 1198 | * @len: size of receive buffer | 1310 | * @len: size of receive buffer |
| 1199 | * | 1311 | * |
| 1200 | */ | 1312 | */ |
| 1313 | |||
| 1201 | static int p9_fd_read(struct p9_trans *trans, void *v, int len) | 1314 | static int p9_fd_read(struct p9_trans *trans, void *v, int len) |
| 1202 | { | 1315 | { |
| 1203 | int ret; | 1316 | int ret; |
| @@ -1220,11 +1333,12 @@ static int p9_fd_read(struct p9_trans *trans, void *v, int len) | |||
| 1220 | 1333 | ||
| 1221 | /** | 1334 | /** |
| 1222 | * p9_fd_write - write to a socket | 1335 | * p9_fd_write - write to a socket |
| 1223 | * @v9ses: session information | 1336 | * @trans: transport instance state |
| 1224 | * @v: buffer to send data from | 1337 | * @v: buffer to send data from |
| 1225 | * @len: size of send buffer | 1338 | * @len: size of send buffer |
| 1226 | * | 1339 | * |
| 1227 | */ | 1340 | */ |
| 1341 | |||
| 1228 | static int p9_fd_write(struct p9_trans *trans, void *v, int len) | 1342 | static int p9_fd_write(struct p9_trans *trans, void *v, int len) |
| 1229 | { | 1343 | { |
| 1230 | int ret; | 1344 | int ret; |
| @@ -1296,6 +1410,7 @@ end: | |||
| 1296 | * @trans: private socket structure | 1410 | * @trans: private socket structure |
| 1297 | * | 1411 | * |
| 1298 | */ | 1412 | */ |
| 1413 | |||
| 1299 | static void p9_fd_close(struct p9_trans *trans) | 1414 | static void p9_fd_close(struct p9_trans *trans) |
| 1300 | { | 1415 | { |
| 1301 | struct p9_trans_fd *ts; | 1416 | struct p9_trans_fd *ts; |
| @@ -1318,6 +1433,23 @@ static void p9_fd_close(struct p9_trans *trans) | |||
| 1318 | kfree(ts); | 1433 | kfree(ts); |
| 1319 | } | 1434 | } |
| 1320 | 1435 | ||
| 1436 | /* | ||
| 1437 | * stolen from NFS - maybe should be made a generic function? | ||
| 1438 | */ | ||
| 1439 | static inline int valid_ipaddr4(const char *buf) | ||
| 1440 | { | ||
| 1441 | int rc, count, in[4]; | ||
| 1442 | |||
| 1443 | rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]); | ||
| 1444 | if (rc != 4) | ||
| 1445 | return -EINVAL; | ||
| 1446 | for (count = 0; count < 4; count++) { | ||
| 1447 | if (in[count] > 255) | ||
| 1448 | return -EINVAL; | ||
| 1449 | } | ||
| 1450 | return 0; | ||
| 1451 | } | ||
| 1452 | |||
| 1321 | static struct p9_trans * | 1453 | static struct p9_trans * |
| 1322 | p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu) | 1454 | p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu) |
| 1323 | { | 1455 | { |
| @@ -1328,7 +1460,12 @@ p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu) | |||
| 1328 | struct p9_fd_opts opts; | 1460 | struct p9_fd_opts opts; |
| 1329 | struct p9_trans_fd *p; | 1461 | struct p9_trans_fd *p; |
| 1330 | 1462 | ||
| 1331 | parse_opts(args, &opts); | 1463 | err = parse_opts(args, &opts); |
| 1464 | if (err < 0) | ||
| 1465 | return ERR_PTR(err); | ||
| 1466 | |||
| 1467 | if (valid_ipaddr4(addr) < 0) | ||
| 1468 | return ERR_PTR(-EINVAL); | ||
| 1332 | 1469 | ||
| 1333 | csocket = NULL; | 1470 | csocket = NULL; |
| 1334 | trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); | 1471 | trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); |
| @@ -1508,7 +1645,7 @@ static struct p9_trans_module p9_fd_trans = { | |||
| 1508 | .create = p9_trans_create_fd, | 1645 | .create = p9_trans_create_fd, |
| 1509 | }; | 1646 | }; |
| 1510 | 1647 | ||
| 1511 | static int __init p9_trans_fd_init(void) | 1648 | int p9_trans_fd_init(void) |
| 1512 | { | 1649 | { |
| 1513 | int ret = p9_mux_global_init(); | 1650 | int ret = p9_mux_global_init(); |
| 1514 | if (ret) { | 1651 | if (ret) { |
| @@ -1522,9 +1659,4 @@ static int __init p9_trans_fd_init(void) | |||
| 1522 | 1659 | ||
| 1523 | return 0; | 1660 | return 0; |
| 1524 | } | 1661 | } |
| 1525 | 1662 | EXPORT_SYMBOL(p9_trans_fd_init); | |
| 1526 | module_init(p9_trans_fd_init); | ||
| 1527 | |||
| 1528 | MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>"); | ||
| 1529 | MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>"); | ||
| 1530 | MODULE_LICENSE("GPL"); | ||
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index de7a9f532edc..42adc052b149 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c | |||
| @@ -49,29 +49,75 @@ | |||
| 49 | #define VIRTQUEUE_NUM 128 | 49 | #define VIRTQUEUE_NUM 128 |
| 50 | 50 | ||
| 51 | /* a single mutex to manage channel initialization and attachment */ | 51 | /* a single mutex to manage channel initialization and attachment */ |
| 52 | static DECLARE_MUTEX(virtio_9p_lock); | 52 | static DEFINE_MUTEX(virtio_9p_lock); |
| 53 | /* global which tracks highest initialized channel */ | 53 | /* global which tracks highest initialized channel */ |
| 54 | static int chan_index; | 54 | static int chan_index; |
| 55 | 55 | ||
| 56 | #define P9_INIT_MAXTAG 16 | 56 | #define P9_INIT_MAXTAG 16 |
| 57 | 57 | ||
| 58 | #define REQ_STATUS_IDLE 0 | 58 | |
| 59 | #define REQ_STATUS_SENT 1 | 59 | /** |
| 60 | #define REQ_STATUS_RCVD 2 | 60 | * enum p9_req_status_t - virtio request status |
| 61 | #define REQ_STATUS_FLSH 3 | 61 | * @REQ_STATUS_IDLE: request slot unused |
| 62 | * @REQ_STATUS_SENT: request sent to server | ||
| 63 | * @REQ_STATUS_RCVD: response received from server | ||
| 64 | * @REQ_STATUS_FLSH: request has been flushed | ||
| 65 | * | ||
| 66 | * The @REQ_STATUS_IDLE state is used to mark a request slot as unused | ||
| 67 | * but use is actually tracked by the idpool structure which handles tag | ||
| 68 | * id allocation. | ||
| 69 | * | ||
| 70 | */ | ||
| 71 | |||
| 72 | enum p9_req_status_t { | ||
| 73 | REQ_STATUS_IDLE, | ||
| 74 | REQ_STATUS_SENT, | ||
| 75 | REQ_STATUS_RCVD, | ||
| 76 | REQ_STATUS_FLSH, | ||
| 77 | }; | ||
| 78 | |||
| 79 | /** | ||
| 80 | * struct p9_req_t - virtio request slots | ||
| 81 | * @status: status of this request slot | ||
| 82 | * @wq: wait_queue for the client to block on for this request | ||
| 83 | * | ||
| 84 | * The virtio transport uses an array to track outstanding requests | ||
| 85 | * instead of a list. While this may incurr overhead during initial | ||
| 86 | * allocation or expansion, it makes request lookup much easier as the | ||
| 87 | * tag id is a index into an array. (We use tag+1 so that we can accomodate | ||
| 88 | * the -1 tag for the T_VERSION request). | ||
| 89 | * This also has the nice effect of only having to allocate wait_queues | ||
| 90 | * once, instead of constantly allocating and freeing them. Its possible | ||
| 91 | * other resources could benefit from this scheme as well. | ||
| 92 | * | ||
| 93 | */ | ||
| 62 | 94 | ||
| 63 | struct p9_req_t { | 95 | struct p9_req_t { |
| 64 | int status; | 96 | int status; |
| 65 | wait_queue_head_t *wq; | 97 | wait_queue_head_t *wq; |
| 66 | }; | 98 | }; |
| 67 | 99 | ||
| 68 | /* We keep all per-channel information in a structure. | 100 | /** |
| 101 | * struct virtio_chan - per-instance transport information | ||
| 102 | * @initialized: whether the channel is initialized | ||
| 103 | * @inuse: whether the channel is in use | ||
| 104 | * @lock: protects multiple elements within this structure | ||
| 105 | * @vdev: virtio dev associated with this channel | ||
| 106 | * @vq: virtio queue associated with this channel | ||
| 107 | * @tagpool: accounting for tag ids (and request slots) | ||
| 108 | * @reqs: array of request slots | ||
| 109 | * @max_tag: current number of request_slots allocated | ||
| 110 | * @sg: scatter gather list which is used to pack a request (protected?) | ||
| 111 | * | ||
| 112 | * We keep all per-channel information in a structure. | ||
| 69 | * This structure is allocated within the devices dev->mem space. | 113 | * This structure is allocated within the devices dev->mem space. |
| 70 | * A pointer to the structure will get put in the transport private. | 114 | * A pointer to the structure will get put in the transport private. |
| 115 | * | ||
| 71 | */ | 116 | */ |
| 117 | |||
| 72 | static struct virtio_chan { | 118 | static struct virtio_chan { |
| 73 | bool initialized; /* channel is initialized */ | 119 | bool initialized; |
| 74 | bool inuse; /* channel is in use */ | 120 | bool inuse; |
| 75 | 121 | ||
| 76 | spinlock_t lock; | 122 | spinlock_t lock; |
| 77 | 123 | ||
| @@ -86,7 +132,19 @@ static struct virtio_chan { | |||
| 86 | struct scatterlist sg[VIRTQUEUE_NUM]; | 132 | struct scatterlist sg[VIRTQUEUE_NUM]; |
| 87 | } channels[MAX_9P_CHAN]; | 133 | } channels[MAX_9P_CHAN]; |
| 88 | 134 | ||
| 89 | /* Lookup requests by tag */ | 135 | /** |
| 136 | * p9_lookup_tag - Lookup requests by tag | ||
| 137 | * @c: virtio channel to lookup tag within | ||
| 138 | * @tag: numeric id for transaction | ||
| 139 | * | ||
| 140 | * this is a simple array lookup, but will grow the | ||
| 141 | * request_slots as necessary to accomodate transaction | ||
| 142 | * ids which did not previously have a slot. | ||
| 143 | * | ||
| 144 | * Bugs: there is currently no upper limit on request slots set | ||
| 145 | * here, but that should be constrained by the id accounting. | ||
| 146 | */ | ||
| 147 | |||
| 90 | static struct p9_req_t *p9_lookup_tag(struct virtio_chan *c, u16 tag) | 148 | static struct p9_req_t *p9_lookup_tag(struct virtio_chan *c, u16 tag) |
| 91 | { | 149 | { |
| 92 | /* This looks up the original request by tag so we know which | 150 | /* This looks up the original request by tag so we know which |
| @@ -130,11 +188,20 @@ static unsigned int rest_of_page(void *data) | |||
| 130 | return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE); | 188 | return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE); |
| 131 | } | 189 | } |
| 132 | 190 | ||
| 191 | /** | ||
| 192 | * p9_virtio_close - reclaim resources of a channel | ||
| 193 | * @trans: transport state | ||
| 194 | * | ||
| 195 | * This reclaims a channel by freeing its resources and | ||
| 196 | * reseting its inuse flag. | ||
| 197 | * | ||
| 198 | */ | ||
| 199 | |||
| 133 | static void p9_virtio_close(struct p9_trans *trans) | 200 | static void p9_virtio_close(struct p9_trans *trans) |
| 134 | { | 201 | { |
| 135 | struct virtio_chan *chan = trans->priv; | 202 | struct virtio_chan *chan = trans->priv; |
| 136 | int count; | 203 | int count; |
| 137 | unsigned int flags; | 204 | unsigned long flags; |
| 138 | 205 | ||
| 139 | spin_lock_irqsave(&chan->lock, flags); | 206 | spin_lock_irqsave(&chan->lock, flags); |
| 140 | p9_idpool_destroy(chan->tagpool); | 207 | p9_idpool_destroy(chan->tagpool); |
| @@ -144,13 +211,26 @@ static void p9_virtio_close(struct p9_trans *trans) | |||
| 144 | chan->max_tag = 0; | 211 | chan->max_tag = 0; |
| 145 | spin_unlock_irqrestore(&chan->lock, flags); | 212 | spin_unlock_irqrestore(&chan->lock, flags); |
| 146 | 213 | ||
| 147 | down(&virtio_9p_lock); | 214 | mutex_lock(&virtio_9p_lock); |
| 148 | chan->inuse = false; | 215 | chan->inuse = false; |
| 149 | up(&virtio_9p_lock); | 216 | mutex_unlock(&virtio_9p_lock); |
| 150 | 217 | ||
| 151 | kfree(trans); | 218 | kfree(trans); |
| 152 | } | 219 | } |
| 153 | 220 | ||
| 221 | /** | ||
| 222 | * req_done - callback which signals activity from the server | ||
| 223 | * @vq: virtio queue activity was received on | ||
| 224 | * | ||
| 225 | * This notifies us that the server has triggered some activity | ||
| 226 | * on the virtio channel - most likely a response to request we | ||
| 227 | * sent. Figure out which requests now have responses and wake up | ||
| 228 | * those threads. | ||
| 229 | * | ||
| 230 | * Bugs: could do with some additional sanity checking, but appears to work. | ||
| 231 | * | ||
| 232 | */ | ||
| 233 | |||
| 154 | static void req_done(struct virtqueue *vq) | 234 | static void req_done(struct virtqueue *vq) |
| 155 | { | 235 | { |
| 156 | struct virtio_chan *chan = vq->vdev->priv; | 236 | struct virtio_chan *chan = vq->vdev->priv; |
| @@ -169,6 +249,20 @@ static void req_done(struct virtqueue *vq) | |||
| 169 | spin_unlock_irqrestore(&chan->lock, flags); | 249 | spin_unlock_irqrestore(&chan->lock, flags); |
| 170 | } | 250 | } |
| 171 | 251 | ||
| 252 | /** | ||
| 253 | * pack_sg_list - pack a scatter gather list from a linear buffer | ||
| 254 | * @sg: scatter/gather list to pack into | ||
| 255 | * @start: which segment of the sg_list to start at | ||
| 256 | * @limit: maximum segment to pack data to | ||
| 257 | * @data: data to pack into scatter/gather list | ||
| 258 | * @count: amount of data to pack into the scatter/gather list | ||
| 259 | * | ||
| 260 | * sg_lists have multiple segments of various sizes. This will pack | ||
| 261 | * arbitrary data into an existing scatter gather list, segmenting the | ||
| 262 | * data as necessary within constraints. | ||
| 263 | * | ||
| 264 | */ | ||
| 265 | |||
| 172 | static int | 266 | static int |
| 173 | pack_sg_list(struct scatterlist *sg, int start, int limit, char *data, | 267 | pack_sg_list(struct scatterlist *sg, int start, int limit, char *data, |
| 174 | int count) | 268 | int count) |
| @@ -189,6 +283,14 @@ pack_sg_list(struct scatterlist *sg, int start, int limit, char *data, | |||
| 189 | return index-start; | 283 | return index-start; |
| 190 | } | 284 | } |
| 191 | 285 | ||
| 286 | /** | ||
| 287 | * p9_virtio_rpc - issue a request and wait for a response | ||
| 288 | * @t: transport state | ||
| 289 | * @tc: &p9_fcall request to transmit | ||
| 290 | * @rc: &p9_fcall to put reponse into | ||
| 291 | * | ||
| 292 | */ | ||
| 293 | |||
| 192 | static int | 294 | static int |
| 193 | p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) | 295 | p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) |
| 194 | { | 296 | { |
| @@ -263,16 +365,26 @@ p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) | |||
| 263 | return 0; | 365 | return 0; |
| 264 | } | 366 | } |
| 265 | 367 | ||
| 368 | /** | ||
| 369 | * p9_virtio_probe - probe for existence of 9P virtio channels | ||
| 370 | * @vdev: virtio device to probe | ||
| 371 | * | ||
| 372 | * This probes for existing virtio channels. At present only | ||
| 373 | * a single channel is in use, so in the future more work may need | ||
| 374 | * to be done here. | ||
| 375 | * | ||
| 376 | */ | ||
| 377 | |||
| 266 | static int p9_virtio_probe(struct virtio_device *vdev) | 378 | static int p9_virtio_probe(struct virtio_device *vdev) |
| 267 | { | 379 | { |
| 268 | int err; | 380 | int err; |
| 269 | struct virtio_chan *chan; | 381 | struct virtio_chan *chan; |
| 270 | int index; | 382 | int index; |
| 271 | 383 | ||
| 272 | down(&virtio_9p_lock); | 384 | mutex_lock(&virtio_9p_lock); |
| 273 | index = chan_index++; | 385 | index = chan_index++; |
| 274 | chan = &channels[index]; | 386 | chan = &channels[index]; |
| 275 | up(&virtio_9p_lock); | 387 | mutex_unlock(&virtio_9p_lock); |
| 276 | 388 | ||
| 277 | if (chan_index > MAX_9P_CHAN) { | 389 | if (chan_index > MAX_9P_CHAN) { |
| 278 | printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n"); | 390 | printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n"); |
| @@ -301,17 +413,34 @@ static int p9_virtio_probe(struct virtio_device *vdev) | |||
| 301 | out_free_vq: | 413 | out_free_vq: |
| 302 | vdev->config->del_vq(chan->vq); | 414 | vdev->config->del_vq(chan->vq); |
| 303 | fail: | 415 | fail: |
| 304 | down(&virtio_9p_lock); | 416 | mutex_lock(&virtio_9p_lock); |
| 305 | chan_index--; | 417 | chan_index--; |
| 306 | up(&virtio_9p_lock); | 418 | mutex_unlock(&virtio_9p_lock); |
| 307 | return err; | 419 | return err; |
| 308 | } | 420 | } |
| 309 | 421 | ||
| 310 | /* This sets up a transport channel for 9p communication. Right now | 422 | |
| 423 | /** | ||
| 424 | * p9_virtio_create - allocate a new virtio channel | ||
| 425 | * @devname: string identifying the channel to connect to (unused) | ||
| 426 | * @args: args passed from sys_mount() for per-transport options (unused) | ||
| 427 | * @msize: requested maximum packet size | ||
| 428 | * @extended: 9p2000.u enabled flag | ||
| 429 | * | ||
| 430 | * This sets up a transport channel for 9p communication. Right now | ||
| 311 | * we only match the first available channel, but eventually we couldlook up | 431 | * we only match the first available channel, but eventually we couldlook up |
| 312 | * alternate channels by matching devname versus a virtio_config entry. | 432 | * alternate channels by matching devname versus a virtio_config entry. |
| 313 | * We use a simple reference count mechanism to ensure that only a single | 433 | * We use a simple reference count mechanism to ensure that only a single |
| 314 | * mount has a channel open at a time. */ | 434 | * mount has a channel open at a time. |
| 435 | * | ||
| 436 | * Bugs: doesn't allow identification of a specific channel | ||
| 437 | * to allocate, channels are allocated sequentially. This was | ||
| 438 | * a pragmatic decision to get things rolling, but ideally some | ||
| 439 | * way of identifying the channel to attach to would be nice | ||
| 440 | * if we are going to support multiple channels. | ||
| 441 | * | ||
| 442 | */ | ||
| 443 | |||
| 315 | static struct p9_trans * | 444 | static struct p9_trans * |
| 316 | p9_virtio_create(const char *devname, char *args, int msize, | 445 | p9_virtio_create(const char *devname, char *args, int msize, |
| 317 | unsigned char extended) | 446 | unsigned char extended) |
| @@ -320,7 +449,7 @@ p9_virtio_create(const char *devname, char *args, int msize, | |||
| 320 | struct virtio_chan *chan = channels; | 449 | struct virtio_chan *chan = channels; |
| 321 | int index = 0; | 450 | int index = 0; |
| 322 | 451 | ||
| 323 | down(&virtio_9p_lock); | 452 | mutex_lock(&virtio_9p_lock); |
| 324 | while (index < MAX_9P_CHAN) { | 453 | while (index < MAX_9P_CHAN) { |
| 325 | if (chan->initialized && !chan->inuse) { | 454 | if (chan->initialized && !chan->inuse) { |
| 326 | chan->inuse = true; | 455 | chan->inuse = true; |
| @@ -330,7 +459,7 @@ p9_virtio_create(const char *devname, char *args, int msize, | |||
| 330 | chan = &channels[index]; | 459 | chan = &channels[index]; |
| 331 | } | 460 | } |
| 332 | } | 461 | } |
| 333 | up(&virtio_9p_lock); | 462 | mutex_unlock(&virtio_9p_lock); |
| 334 | 463 | ||
| 335 | if (index >= MAX_9P_CHAN) { | 464 | if (index >= MAX_9P_CHAN) { |
| 336 | printk(KERN_ERR "9p: no channels available\n"); | 465 | printk(KERN_ERR "9p: no channels available\n"); |
| @@ -360,6 +489,12 @@ p9_virtio_create(const char *devname, char *args, int msize, | |||
| 360 | return trans; | 489 | return trans; |
| 361 | } | 490 | } |
| 362 | 491 | ||
| 492 | /** | ||
| 493 | * p9_virtio_remove - clean up resources associated with a virtio device | ||
| 494 | * @vdev: virtio device to remove | ||
| 495 | * | ||
| 496 | */ | ||
| 497 | |||
| 363 | static void p9_virtio_remove(struct virtio_device *vdev) | 498 | static void p9_virtio_remove(struct virtio_device *vdev) |
| 364 | { | 499 | { |
| 365 | struct virtio_chan *chan = vdev->priv; | 500 | struct virtio_chan *chan = vdev->priv; |
diff --git a/net/9p/util.c b/net/9p/util.c index ef7215565d88..958fc58cd1ff 100644 --- a/net/9p/util.c +++ b/net/9p/util.c | |||
| @@ -32,11 +32,23 @@ | |||
| 32 | #include <linux/idr.h> | 32 | #include <linux/idr.h> |
| 33 | #include <net/9p/9p.h> | 33 | #include <net/9p/9p.h> |
| 34 | 34 | ||
| 35 | /** | ||
| 36 | * struct p9_idpool - per-connection accounting for tag idpool | ||
| 37 | * @lock: protects the pool | ||
| 38 | * @pool: idr to allocate tag id from | ||
| 39 | * | ||
| 40 | */ | ||
| 41 | |||
| 35 | struct p9_idpool { | 42 | struct p9_idpool { |
| 36 | spinlock_t lock; | 43 | spinlock_t lock; |
| 37 | struct idr pool; | 44 | struct idr pool; |
| 38 | }; | 45 | }; |
| 39 | 46 | ||
| 47 | /** | ||
| 48 | * p9_idpool_create - create a new per-connection id pool | ||
| 49 | * | ||
| 50 | */ | ||
| 51 | |||
| 40 | struct p9_idpool *p9_idpool_create(void) | 52 | struct p9_idpool *p9_idpool_create(void) |
| 41 | { | 53 | { |
| 42 | struct p9_idpool *p; | 54 | struct p9_idpool *p; |
| @@ -52,6 +64,11 @@ struct p9_idpool *p9_idpool_create(void) | |||
| 52 | } | 64 | } |
| 53 | EXPORT_SYMBOL(p9_idpool_create); | 65 | EXPORT_SYMBOL(p9_idpool_create); |
| 54 | 66 | ||
| 67 | /** | ||
| 68 | * p9_idpool_destroy - create a new per-connection id pool | ||
| 69 | * @p: idpool to destory | ||
| 70 | */ | ||
| 71 | |||
| 55 | void p9_idpool_destroy(struct p9_idpool *p) | 72 | void p9_idpool_destroy(struct p9_idpool *p) |
| 56 | { | 73 | { |
| 57 | idr_destroy(&p->pool); | 74 | idr_destroy(&p->pool); |
| @@ -61,9 +78,9 @@ EXPORT_SYMBOL(p9_idpool_destroy); | |||
| 61 | 78 | ||
| 62 | /** | 79 | /** |
| 63 | * p9_idpool_get - allocate numeric id from pool | 80 | * p9_idpool_get - allocate numeric id from pool |
| 64 | * @p - pool to allocate from | 81 | * @p: pool to allocate from |
| 65 | * | 82 | * |
| 66 | * XXX - This seems to be an awful generic function, should it be in idr.c with | 83 | * Bugs: This seems to be an awful generic function, should it be in idr.c with |
| 67 | * the lock included in struct idr? | 84 | * the lock included in struct idr? |
| 68 | */ | 85 | */ |
| 69 | 86 | ||
| @@ -71,7 +88,7 @@ int p9_idpool_get(struct p9_idpool *p) | |||
| 71 | { | 88 | { |
| 72 | int i = 0; | 89 | int i = 0; |
| 73 | int error; | 90 | int error; |
| 74 | unsigned int flags; | 91 | unsigned long flags; |
| 75 | 92 | ||
| 76 | retry: | 93 | retry: |
| 77 | if (idr_pre_get(&p->pool, GFP_KERNEL) == 0) | 94 | if (idr_pre_get(&p->pool, GFP_KERNEL) == 0) |
| @@ -94,15 +111,16 @@ EXPORT_SYMBOL(p9_idpool_get); | |||
| 94 | 111 | ||
| 95 | /** | 112 | /** |
| 96 | * p9_idpool_put - release numeric id from pool | 113 | * p9_idpool_put - release numeric id from pool |
| 97 | * @p - pool to allocate from | 114 | * @id: numeric id which is being released |
| 115 | * @p: pool to release id into | ||
| 98 | * | 116 | * |
| 99 | * XXX - This seems to be an awful generic function, should it be in idr.c with | 117 | * Bugs: This seems to be an awful generic function, should it be in idr.c with |
| 100 | * the lock included in struct idr? | 118 | * the lock included in struct idr? |
| 101 | */ | 119 | */ |
| 102 | 120 | ||
| 103 | void p9_idpool_put(int id, struct p9_idpool *p) | 121 | void p9_idpool_put(int id, struct p9_idpool *p) |
| 104 | { | 122 | { |
| 105 | unsigned int flags; | 123 | unsigned long flags; |
| 106 | spin_lock_irqsave(&p->lock, flags); | 124 | spin_lock_irqsave(&p->lock, flags); |
| 107 | idr_remove(&p->pool, id); | 125 | idr_remove(&p->pool, id); |
| 108 | spin_unlock_irqrestore(&p->lock, flags); | 126 | spin_unlock_irqrestore(&p->lock, flags); |
| @@ -111,11 +129,13 @@ EXPORT_SYMBOL(p9_idpool_put); | |||
| 111 | 129 | ||
| 112 | /** | 130 | /** |
| 113 | * p9_idpool_check - check if the specified id is available | 131 | * p9_idpool_check - check if the specified id is available |
| 114 | * @id - id to check | 132 | * @id: id to check |
| 115 | * @p - pool | 133 | * @p: pool to check |
| 116 | */ | 134 | */ |
| 135 | |||
| 117 | int p9_idpool_check(int id, struct p9_idpool *p) | 136 | int p9_idpool_check(int id, struct p9_idpool *p) |
| 118 | { | 137 | { |
| 119 | return idr_find(&p->pool, id) != NULL; | 138 | return idr_find(&p->pool, id) != NULL; |
| 120 | } | 139 | } |
| 121 | EXPORT_SYMBOL(p9_idpool_check); | 140 | EXPORT_SYMBOL(p9_idpool_check); |
| 141 | |||
