diff options
Diffstat (limited to 'fs/9p/vfs_inode.c')
| -rw-r--r-- | fs/9p/vfs_inode.c | 753 |
1 files changed, 283 insertions, 470 deletions
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index c76cd8fa3f6c..c602c0e054a2 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c | |||
| @@ -34,10 +34,10 @@ | |||
| 34 | #include <linux/namei.h> | 34 | #include <linux/namei.h> |
| 35 | #include <linux/idr.h> | 35 | #include <linux/idr.h> |
| 36 | #include <linux/sched.h> | 36 | #include <linux/sched.h> |
| 37 | #include <net/9p/9p.h> | ||
| 38 | #include <net/9p/client.h> | ||
| 37 | 39 | ||
| 38 | #include "debug.h" | ||
| 39 | #include "v9fs.h" | 40 | #include "v9fs.h" |
| 40 | #include "9p.h" | ||
| 41 | #include "v9fs_vfs.h" | 41 | #include "v9fs_vfs.h" |
| 42 | #include "fid.h" | 42 | #include "fid.h" |
| 43 | 43 | ||
| @@ -58,27 +58,27 @@ static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) | |||
| 58 | int res; | 58 | int res; |
| 59 | res = mode & 0777; | 59 | res = mode & 0777; |
| 60 | if (S_ISDIR(mode)) | 60 | if (S_ISDIR(mode)) |
| 61 | res |= V9FS_DMDIR; | 61 | res |= P9_DMDIR; |
| 62 | if (v9ses->extended) { | 62 | if (v9ses->extended) { |
| 63 | if (S_ISLNK(mode)) | 63 | if (S_ISLNK(mode)) |
| 64 | res |= V9FS_DMSYMLINK; | 64 | res |= P9_DMSYMLINK; |
| 65 | if (v9ses->nodev == 0) { | 65 | if (v9ses->nodev == 0) { |
| 66 | if (S_ISSOCK(mode)) | 66 | if (S_ISSOCK(mode)) |
| 67 | res |= V9FS_DMSOCKET; | 67 | res |= P9_DMSOCKET; |
| 68 | if (S_ISFIFO(mode)) | 68 | if (S_ISFIFO(mode)) |
| 69 | res |= V9FS_DMNAMEDPIPE; | 69 | res |= P9_DMNAMEDPIPE; |
| 70 | if (S_ISBLK(mode)) | 70 | if (S_ISBLK(mode)) |
| 71 | res |= V9FS_DMDEVICE; | 71 | res |= P9_DMDEVICE; |
| 72 | if (S_ISCHR(mode)) | 72 | if (S_ISCHR(mode)) |
| 73 | res |= V9FS_DMDEVICE; | 73 | res |= P9_DMDEVICE; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | if ((mode & S_ISUID) == S_ISUID) | 76 | if ((mode & S_ISUID) == S_ISUID) |
| 77 | res |= V9FS_DMSETUID; | 77 | res |= P9_DMSETUID; |
| 78 | if ((mode & S_ISGID) == S_ISGID) | 78 | if ((mode & S_ISGID) == S_ISGID) |
| 79 | res |= V9FS_DMSETGID; | 79 | res |= P9_DMSETGID; |
| 80 | if ((mode & V9FS_DMLINK)) | 80 | if ((mode & P9_DMLINK)) |
| 81 | res |= V9FS_DMLINK; | 81 | res |= P9_DMLINK; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | return res; | 84 | return res; |
| @@ -97,27 +97,27 @@ static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) | |||
| 97 | 97 | ||
| 98 | res = mode & 0777; | 98 | res = mode & 0777; |
| 99 | 99 | ||
| 100 | if ((mode & V9FS_DMDIR) == V9FS_DMDIR) | 100 | if ((mode & P9_DMDIR) == P9_DMDIR) |
| 101 | res |= S_IFDIR; | 101 | res |= S_IFDIR; |
| 102 | else if ((mode & V9FS_DMSYMLINK) && (v9ses->extended)) | 102 | else if ((mode & P9_DMSYMLINK) && (v9ses->extended)) |
| 103 | res |= S_IFLNK; | 103 | res |= S_IFLNK; |
| 104 | else if ((mode & V9FS_DMSOCKET) && (v9ses->extended) | 104 | else if ((mode & P9_DMSOCKET) && (v9ses->extended) |
| 105 | && (v9ses->nodev == 0)) | 105 | && (v9ses->nodev == 0)) |
| 106 | res |= S_IFSOCK; | 106 | res |= S_IFSOCK; |
| 107 | else if ((mode & V9FS_DMNAMEDPIPE) && (v9ses->extended) | 107 | else if ((mode & P9_DMNAMEDPIPE) && (v9ses->extended) |
| 108 | && (v9ses->nodev == 0)) | 108 | && (v9ses->nodev == 0)) |
| 109 | res |= S_IFIFO; | 109 | res |= S_IFIFO; |
| 110 | else if ((mode & V9FS_DMDEVICE) && (v9ses->extended) | 110 | else if ((mode & P9_DMDEVICE) && (v9ses->extended) |
| 111 | && (v9ses->nodev == 0)) | 111 | && (v9ses->nodev == 0)) |
| 112 | res |= S_IFBLK; | 112 | res |= S_IFBLK; |
| 113 | else | 113 | else |
| 114 | res |= S_IFREG; | 114 | res |= S_IFREG; |
| 115 | 115 | ||
| 116 | if (v9ses->extended) { | 116 | if (v9ses->extended) { |
| 117 | if ((mode & V9FS_DMSETUID) == V9FS_DMSETUID) | 117 | if ((mode & P9_DMSETUID) == P9_DMSETUID) |
| 118 | res |= S_ISUID; | 118 | res |= S_ISUID; |
| 119 | 119 | ||
| 120 | if ((mode & V9FS_DMSETGID) == V9FS_DMSETGID) | 120 | if ((mode & P9_DMSETGID) == P9_DMSETGID) |
| 121 | res |= S_ISGID; | 121 | res |= S_ISGID; |
| 122 | } | 122 | } |
| 123 | 123 | ||
| @@ -132,26 +132,26 @@ int v9fs_uflags2omode(int uflags) | |||
| 132 | switch (uflags&3) { | 132 | switch (uflags&3) { |
| 133 | default: | 133 | default: |
| 134 | case O_RDONLY: | 134 | case O_RDONLY: |
| 135 | ret = V9FS_OREAD; | 135 | ret = P9_OREAD; |
| 136 | break; | 136 | break; |
| 137 | 137 | ||
| 138 | case O_WRONLY: | 138 | case O_WRONLY: |
| 139 | ret = V9FS_OWRITE; | 139 | ret = P9_OWRITE; |
| 140 | break; | 140 | break; |
| 141 | 141 | ||
| 142 | case O_RDWR: | 142 | case O_RDWR: |
| 143 | ret = V9FS_ORDWR; | 143 | ret = P9_ORDWR; |
| 144 | break; | 144 | break; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | if (uflags & O_EXCL) | 147 | if (uflags & O_EXCL) |
| 148 | ret |= V9FS_OEXCL; | 148 | ret |= P9_OEXCL; |
| 149 | 149 | ||
| 150 | if (uflags & O_TRUNC) | 150 | if (uflags & O_TRUNC) |
| 151 | ret |= V9FS_OTRUNC; | 151 | ret |= P9_OTRUNC; |
| 152 | 152 | ||
| 153 | if (uflags & O_APPEND) | 153 | if (uflags & O_APPEND) |
| 154 | ret |= V9FS_OAPPEND; | 154 | ret |= P9_OAPPEND; |
| 155 | 155 | ||
| 156 | return ret; | 156 | return ret; |
| 157 | } | 157 | } |
| @@ -164,7 +164,7 @@ int v9fs_uflags2omode(int uflags) | |||
| 164 | */ | 164 | */ |
| 165 | 165 | ||
| 166 | static void | 166 | static void |
| 167 | v9fs_blank_wstat(struct v9fs_wstat *wstat) | 167 | v9fs_blank_wstat(struct p9_wstat *wstat) |
| 168 | { | 168 | { |
| 169 | wstat->type = ~0; | 169 | wstat->type = ~0; |
| 170 | wstat->dev = ~0; | 170 | wstat->dev = ~0; |
| @@ -197,7 +197,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) | |||
| 197 | struct inode *inode; | 197 | struct inode *inode; |
| 198 | struct v9fs_session_info *v9ses = sb->s_fs_info; | 198 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
| 199 | 199 | ||
| 200 | dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode); | 200 | P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode); |
| 201 | 201 | ||
| 202 | inode = new_inode(sb); | 202 | inode = new_inode(sb); |
| 203 | if (inode) { | 203 | if (inode) { |
| @@ -215,7 +215,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) | |||
| 215 | case S_IFCHR: | 215 | case S_IFCHR: |
| 216 | case S_IFSOCK: | 216 | case S_IFSOCK: |
| 217 | if(!v9ses->extended) { | 217 | if(!v9ses->extended) { |
| 218 | dprintk(DEBUG_ERROR, "special files without extended mode\n"); | 218 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 219 | "special files without extended mode\n"); | ||
| 219 | return ERR_PTR(-EINVAL); | 220 | return ERR_PTR(-EINVAL); |
| 220 | } | 221 | } |
| 221 | init_special_inode(inode, inode->i_mode, | 222 | init_special_inode(inode, inode->i_mode, |
| @@ -227,7 +228,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) | |||
| 227 | break; | 228 | break; |
| 228 | case S_IFLNK: | 229 | case S_IFLNK: |
| 229 | if(!v9ses->extended) { | 230 | if(!v9ses->extended) { |
| 230 | dprintk(DEBUG_ERROR, "extended modes used w/o 9P2000.u\n"); | 231 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 232 | "extended modes used w/o 9P2000.u\n"); | ||
| 231 | return ERR_PTR(-EINVAL); | 233 | return ERR_PTR(-EINVAL); |
| 232 | } | 234 | } |
| 233 | inode->i_op = &v9fs_symlink_inode_operations; | 235 | inode->i_op = &v9fs_symlink_inode_operations; |
| @@ -241,71 +243,19 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) | |||
| 241 | inode->i_fop = &v9fs_dir_operations; | 243 | inode->i_fop = &v9fs_dir_operations; |
| 242 | break; | 244 | break; |
| 243 | default: | 245 | default: |
| 244 | dprintk(DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n", | 246 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 247 | "BAD mode 0x%x S_IFMT 0x%x\n", | ||
| 245 | mode, mode & S_IFMT); | 248 | mode, mode & S_IFMT); |
| 246 | return ERR_PTR(-EINVAL); | 249 | return ERR_PTR(-EINVAL); |
| 247 | } | 250 | } |
| 248 | } else { | 251 | } else { |
| 249 | eprintk(KERN_WARNING, "Problem allocating inode\n"); | 252 | P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n"); |
| 250 | return ERR_PTR(-ENOMEM); | 253 | return ERR_PTR(-ENOMEM); |
| 251 | } | 254 | } |
| 252 | return inode; | 255 | return inode; |
| 253 | } | 256 | } |
| 254 | 257 | ||
| 255 | static int | 258 | /* |
| 256 | v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name, u32 perm, | ||
| 257 | u8 mode, char *extension, u32 *fidp, struct v9fs_qid *qid, u32 *iounit) | ||
| 258 | { | ||
| 259 | int fid; | ||
| 260 | int err; | ||
| 261 | struct v9fs_fcall *fcall; | ||
| 262 | |||
| 263 | fid = v9fs_get_idpool(&v9ses->fidpool); | ||
| 264 | if (fid < 0) { | ||
| 265 | eprintk(KERN_WARNING, "no free fids available\n"); | ||
| 266 | return -ENOSPC; | ||
| 267 | } | ||
| 268 | |||
| 269 | err = v9fs_t_walk(v9ses, pfid, fid, NULL, &fcall); | ||
| 270 | if (err < 0) { | ||
| 271 | PRINT_FCALL_ERROR("clone error", fcall); | ||
| 272 | if (fcall && fcall->id == RWALK) | ||
| 273 | goto clunk_fid; | ||
| 274 | else | ||
| 275 | goto put_fid; | ||
| 276 | } | ||
| 277 | kfree(fcall); | ||
| 278 | |||
| 279 | err = v9fs_t_create(v9ses, fid, name, perm, mode, extension, &fcall); | ||
| 280 | if (err < 0) { | ||
| 281 | PRINT_FCALL_ERROR("create fails", fcall); | ||
| 282 | goto clunk_fid; | ||
| 283 | } | ||
| 284 | |||
| 285 | if (iounit) | ||
| 286 | *iounit = fcall->params.rcreate.iounit; | ||
| 287 | |||
| 288 | if (qid) | ||
| 289 | *qid = fcall->params.rcreate.qid; | ||
| 290 | |||
| 291 | if (fidp) | ||
| 292 | *fidp = fid; | ||
| 293 | |||
| 294 | kfree(fcall); | ||
| 295 | return 0; | ||
| 296 | |||
| 297 | clunk_fid: | ||
| 298 | v9fs_t_clunk(v9ses, fid); | ||
| 299 | fid = V9FS_NOFID; | ||
| 300 | |||
| 301 | put_fid: | ||
| 302 | if (fid != V9FS_NOFID) | ||
| 303 | v9fs_put_idpool(fid, &v9ses->fidpool); | ||
| 304 | |||
| 305 | kfree(fcall); | ||
| 306 | return err; | ||
| 307 | } | ||
| 308 | |||
| 309 | static struct v9fs_fid* | 259 | static struct v9fs_fid* |
| 310 | v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) | 260 | v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) |
| 311 | { | 261 | { |
| @@ -355,23 +305,25 @@ error: | |||
| 355 | kfree(fcall); | 305 | kfree(fcall); |
| 356 | return ERR_PTR(err); | 306 | return ERR_PTR(err); |
| 357 | } | 307 | } |
| 308 | */ | ||
| 358 | 309 | ||
| 359 | static struct inode * | 310 | static struct inode * |
| 360 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid, | 311 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
| 361 | struct super_block *sb) | 312 | struct super_block *sb) |
| 362 | { | 313 | { |
| 363 | int err, umode; | 314 | int err, umode; |
| 364 | struct inode *ret; | 315 | struct inode *ret; |
| 365 | struct v9fs_fcall *fcall; | 316 | struct p9_stat *st; |
| 366 | 317 | ||
| 367 | ret = NULL; | 318 | ret = NULL; |
| 368 | err = v9fs_t_stat(v9ses, fid, &fcall); | 319 | st = p9_client_stat(fid); |
| 369 | if (err) { | 320 | if (IS_ERR(st)) { |
| 370 | PRINT_FCALL_ERROR("stat error", fcall); | 321 | err = PTR_ERR(st); |
| 322 | st = NULL; | ||
| 371 | goto error; | 323 | goto error; |
| 372 | } | 324 | } |
| 373 | 325 | ||
| 374 | umode = p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode); | 326 | umode = p9mode2unixmode(v9ses, st->mode); |
| 375 | ret = v9fs_get_inode(sb, umode); | 327 | ret = v9fs_get_inode(sb, umode); |
| 376 | if (IS_ERR(ret)) { | 328 | if (IS_ERR(ret)) { |
| 377 | err = PTR_ERR(ret); | 329 | err = PTR_ERR(ret); |
| @@ -379,12 +331,13 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid, | |||
| 379 | goto error; | 331 | goto error; |
| 380 | } | 332 | } |
| 381 | 333 | ||
| 382 | v9fs_stat2inode(&fcall->params.rstat.stat, ret, sb); | 334 | v9fs_stat2inode(st, ret, sb); |
| 383 | kfree(fcall); | 335 | ret->i_ino = v9fs_qid2ino(&st->qid); |
| 336 | kfree(st); | ||
| 384 | return ret; | 337 | return ret; |
| 385 | 338 | ||
| 386 | error: | 339 | error: |
| 387 | kfree(fcall); | 340 | kfree(st); |
| 388 | if (ret) | 341 | if (ret) |
| 389 | iput(ret); | 342 | iput(ret); |
| 390 | 343 | ||
| @@ -401,43 +354,20 @@ error: | |||
| 401 | 354 | ||
| 402 | static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) | 355 | static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) |
| 403 | { | 356 | { |
| 404 | struct v9fs_fcall *fcall = NULL; | 357 | struct inode *file_inode; |
| 405 | struct super_block *sb = NULL; | 358 | struct v9fs_session_info *v9ses; |
| 406 | struct v9fs_session_info *v9ses = NULL; | 359 | struct p9_fid *v9fid; |
| 407 | struct v9fs_fid *v9fid = NULL; | ||
| 408 | struct inode *file_inode = NULL; | ||
| 409 | int fid = -1; | ||
| 410 | int result = 0; | ||
| 411 | 360 | ||
| 412 | dprintk(DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file, | 361 | P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file, |
| 413 | rmdir); | 362 | rmdir); |
| 414 | 363 | ||
| 415 | file_inode = file->d_inode; | 364 | file_inode = file->d_inode; |
| 416 | sb = file_inode->i_sb; | ||
| 417 | v9ses = v9fs_inode2v9ses(file_inode); | 365 | v9ses = v9fs_inode2v9ses(file_inode); |
| 418 | v9fid = v9fs_fid_clone(file); | 366 | v9fid = v9fs_fid_clone(file); |
| 419 | if(IS_ERR(v9fid)) | 367 | if(IS_ERR(v9fid)) |
| 420 | return PTR_ERR(v9fid); | 368 | return PTR_ERR(v9fid); |
| 421 | 369 | ||
| 422 | fid = v9fid->fid; | 370 | return p9_client_remove(v9fid); |
| 423 | if (fid < 0) { | ||
| 424 | dprintk(DEBUG_ERROR, "inode #%lu, no fid!\n", | ||
| 425 | file_inode->i_ino); | ||
| 426 | return -EBADF; | ||
| 427 | } | ||
| 428 | |||
| 429 | result = v9fs_t_remove(v9ses, fid, &fcall); | ||
| 430 | if (result < 0) { | ||
| 431 | PRINT_FCALL_ERROR("remove fails", fcall); | ||
| 432 | goto Error; | ||
| 433 | } | ||
| 434 | |||
| 435 | v9fs_put_idpool(fid, &v9ses->fidpool); | ||
| 436 | v9fs_fid_destroy(v9fid); | ||
| 437 | |||
| 438 | Error: | ||
| 439 | kfree(fcall); | ||
| 440 | return result; | ||
| 441 | } | 371 | } |
| 442 | 372 | ||
| 443 | static int | 373 | static int |
| @@ -446,61 +376,59 @@ v9fs_open_created(struct inode *inode, struct file *file) | |||
| 446 | return 0; | 376 | return 0; |
| 447 | } | 377 | } |
| 448 | 378 | ||
| 379 | |||
| 449 | /** | 380 | /** |
| 450 | * v9fs_vfs_create - VFS hook to create files | 381 | * v9fs_create - Create a file |
| 451 | * @inode: directory inode that is being deleted | 382 | * @dentry: dentry that is being created |
| 452 | * @dentry: dentry that is being deleted | 383 | * @perm: create permissions |
| 453 | * @mode: create permissions | 384 | * @mode: open mode |
| 454 | * @nd: path information | ||
| 455 | * | 385 | * |
| 456 | */ | 386 | */ |
| 457 | 387 | static struct p9_fid * | |
| 458 | static int | 388 | v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, |
| 459 | v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, | 389 | struct dentry *dentry, char *extension, u32 perm, u8 mode) |
| 460 | struct nameidata *nd) | ||
| 461 | { | 390 | { |
| 462 | int err; | 391 | int err; |
| 463 | u32 fid, perm, iounit; | 392 | char *name; |
| 464 | int flags; | 393 | struct p9_fid *dfid, *ofid, *fid; |
| 465 | struct v9fs_session_info *v9ses; | ||
| 466 | struct v9fs_fid *dfid, *vfid, *ffid; | ||
| 467 | struct inode *inode; | 394 | struct inode *inode; |
| 468 | struct v9fs_qid qid; | ||
| 469 | struct file *filp; | ||
| 470 | 395 | ||
| 471 | inode = NULL; | 396 | err = 0; |
| 472 | vfid = NULL; | 397 | ofid = NULL; |
| 473 | v9ses = v9fs_inode2v9ses(dir); | 398 | fid = NULL; |
| 399 | name = (char *) dentry->d_name.name; | ||
| 474 | dfid = v9fs_fid_clone(dentry->d_parent); | 400 | dfid = v9fs_fid_clone(dentry->d_parent); |
| 475 | if(IS_ERR(dfid)) { | 401 | if(IS_ERR(dfid)) { |
| 476 | err = PTR_ERR(dfid); | 402 | err = PTR_ERR(dfid); |
| 403 | dfid = NULL; | ||
| 477 | goto error; | 404 | goto error; |
| 478 | } | 405 | } |
| 479 | 406 | ||
| 480 | perm = unixmode2p9mode(v9ses, mode); | 407 | /* clone a fid to use for creation */ |
| 481 | if (nd && nd->flags & LOOKUP_OPEN) | 408 | ofid = p9_client_walk(dfid, 0, NULL, 1); |
| 482 | flags = nd->intent.open.flags - 1; | 409 | if (IS_ERR(ofid)) { |
| 483 | else | 410 | err = PTR_ERR(ofid); |
| 484 | flags = O_RDWR; | 411 | ofid = NULL; |
| 485 | 412 | goto error; | |
| 486 | err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name, | 413 | } |
| 487 | perm, v9fs_uflags2omode(flags), NULL, &fid, &qid, &iounit); | ||
| 488 | 414 | ||
| 489 | if (err) | 415 | err = p9_client_fcreate(ofid, name, perm, mode, extension); |
| 490 | goto clunk_dfid; | 416 | if (err < 0) |
| 417 | goto error; | ||
| 491 | 418 | ||
| 492 | vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry); | 419 | /* now walk from the parent so we can get unopened fid */ |
| 493 | v9fs_fid_clunk(v9ses, dfid); | 420 | fid = p9_client_walk(dfid, 1, &name, 0); |
| 494 | if (IS_ERR(vfid)) { | 421 | if (IS_ERR(fid)) { |
| 495 | err = PTR_ERR(vfid); | 422 | err = PTR_ERR(fid); |
| 496 | vfid = NULL; | 423 | fid = NULL; |
| 497 | goto error; | 424 | goto error; |
| 498 | } | 425 | } else |
| 426 | dfid = NULL; | ||
| 499 | 427 | ||
| 500 | inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb); | 428 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 429 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | ||
| 501 | if (IS_ERR(inode)) { | 430 | if (IS_ERR(inode)) { |
| 502 | err = PTR_ERR(inode); | 431 | err = PTR_ERR(inode); |
| 503 | inode = NULL; | ||
| 504 | goto error; | 432 | goto error; |
| 505 | } | 433 | } |
| 506 | 434 | ||
| @@ -508,35 +436,78 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, | |||
| 508 | dentry->d_op = &v9fs_cached_dentry_operations; | 436 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 509 | else | 437 | else |
| 510 | dentry->d_op = &v9fs_dentry_operations; | 438 | dentry->d_op = &v9fs_dentry_operations; |
| 439 | |||
| 511 | d_instantiate(dentry, inode); | 440 | d_instantiate(dentry, inode); |
| 441 | v9fs_fid_add(dentry, fid); | ||
| 442 | return ofid; | ||
| 512 | 443 | ||
| 513 | if (nd && nd->flags & LOOKUP_OPEN) { | 444 | error: |
| 514 | ffid = v9fs_fid_create(v9ses, fid); | 445 | if (dfid) |
| 515 | if (!ffid) | 446 | p9_client_clunk(dfid); |
| 516 | return -ENOMEM; | 447 | |
| 448 | if (ofid) | ||
| 449 | p9_client_clunk(ofid); | ||
| 450 | |||
| 451 | if (fid) | ||
| 452 | p9_client_clunk(fid); | ||
| 453 | |||
| 454 | return ERR_PTR(err); | ||
| 455 | } | ||
| 456 | |||
| 457 | /** | ||
| 458 | * v9fs_vfs_create - VFS hook to create files | ||
| 459 | * @inode: directory inode that is being created | ||
| 460 | * @dentry: dentry that is being deleted | ||
| 461 | * @mode: create permissions | ||
| 462 | * @nd: path information | ||
| 463 | * | ||
| 464 | */ | ||
| 517 | 465 | ||
| 466 | static int | ||
| 467 | v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, | ||
| 468 | struct nameidata *nd) | ||
| 469 | { | ||
| 470 | int err; | ||
| 471 | u32 perm; | ||
| 472 | int flags; | ||
| 473 | struct v9fs_session_info *v9ses; | ||
| 474 | struct p9_fid *fid; | ||
| 475 | struct file *filp; | ||
| 476 | |||
| 477 | err = 0; | ||
| 478 | fid = NULL; | ||
| 479 | v9ses = v9fs_inode2v9ses(dir); | ||
| 480 | perm = unixmode2p9mode(v9ses, mode); | ||
| 481 | if (nd && nd->flags & LOOKUP_OPEN) | ||
| 482 | flags = nd->intent.open.flags - 1; | ||
| 483 | else | ||
| 484 | flags = O_RDWR; | ||
| 485 | |||
| 486 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, | ||
| 487 | v9fs_uflags2omode(flags)); | ||
| 488 | if (IS_ERR(fid)) { | ||
| 489 | err = PTR_ERR(fid); | ||
| 490 | fid = NULL; | ||
| 491 | goto error; | ||
| 492 | } | ||
| 493 | |||
| 494 | /* if we are opening a file, assign the open fid to the file */ | ||
| 495 | if (nd && nd->flags & LOOKUP_OPEN) { | ||
| 518 | filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); | 496 | filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); |
| 519 | if (IS_ERR(filp)) { | 497 | if (IS_ERR(filp)) { |
| 520 | v9fs_fid_destroy(ffid); | 498 | err = PTR_ERR(filp); |
| 521 | return PTR_ERR(filp); | 499 | goto error; |
| 522 | } | 500 | } |
| 523 | 501 | ||
| 524 | ffid->rdir_pos = 0; | 502 | filp->private_data = fid; |
| 525 | ffid->rdir_fcall = NULL; | 503 | } else |
| 526 | ffid->fidopen = 1; | 504 | p9_client_clunk(fid); |
| 527 | ffid->iounit = iounit; | ||
| 528 | ffid->filp = filp; | ||
| 529 | filp->private_data = ffid; | ||
| 530 | } | ||
| 531 | 505 | ||
| 532 | return 0; | 506 | return 0; |
| 533 | 507 | ||
| 534 | clunk_dfid: | ||
| 535 | v9fs_fid_clunk(v9ses, dfid); | ||
| 536 | |||
| 537 | error: | 508 | error: |
| 538 | if (vfid) | 509 | if (fid) |
| 539 | v9fs_fid_destroy(vfid); | 510 | p9_client_clunk(fid); |
| 540 | 511 | ||
| 541 | return err; | 512 | return err; |
| 542 | } | 513 | } |
| @@ -552,57 +523,23 @@ error: | |||
| 552 | static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | 523 | static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
| 553 | { | 524 | { |
| 554 | int err; | 525 | int err; |
| 555 | u32 fid, perm; | 526 | u32 perm; |
| 556 | struct v9fs_session_info *v9ses; | 527 | struct v9fs_session_info *v9ses; |
| 557 | struct v9fs_fid *dfid, *vfid; | 528 | struct p9_fid *fid; |
| 558 | struct inode *inode; | ||
| 559 | 529 | ||
| 560 | inode = NULL; | 530 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 561 | vfid = NULL; | 531 | err = 0; |
| 562 | v9ses = v9fs_inode2v9ses(dir); | 532 | v9ses = v9fs_inode2v9ses(dir); |
| 563 | dfid = v9fs_fid_clone(dentry->d_parent); | ||
| 564 | if(IS_ERR(dfid)) { | ||
| 565 | err = PTR_ERR(dfid); | ||
| 566 | goto error; | ||
| 567 | } | ||
| 568 | |||
| 569 | perm = unixmode2p9mode(v9ses, mode | S_IFDIR); | 533 | perm = unixmode2p9mode(v9ses, mode | S_IFDIR); |
| 570 | 534 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD); | |
| 571 | err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name, | 535 | if (IS_ERR(fid)) { |
| 572 | perm, V9FS_OREAD, NULL, &fid, NULL, NULL); | 536 | err = PTR_ERR(fid); |
| 573 | 537 | fid = NULL; | |
| 574 | if (err) { | ||
| 575 | dprintk(DEBUG_ERROR, "create error %d\n", err); | ||
| 576 | goto clean_up_dfid; | ||
| 577 | } | 538 | } |
| 578 | 539 | ||
| 579 | vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry); | 540 | if (fid) |
| 580 | if (IS_ERR(vfid)) { | 541 | p9_client_clunk(fid); |
| 581 | err = PTR_ERR(vfid); | ||
| 582 | vfid = NULL; | ||
| 583 | goto clean_up_dfid; | ||
| 584 | } | ||
| 585 | 542 | ||
| 586 | v9fs_fid_clunk(v9ses, dfid); | ||
| 587 | inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb); | ||
| 588 | if (IS_ERR(inode)) { | ||
| 589 | err = PTR_ERR(inode); | ||
| 590 | inode = NULL; | ||
| 591 | v9fs_fid_destroy(vfid); | ||
| 592 | goto error; | ||
| 593 | } | ||
| 594 | |||
| 595 | if(v9ses->cache) | ||
| 596 | dentry->d_op = &v9fs_cached_dentry_operations; | ||
| 597 | else | ||
| 598 | dentry->d_op = &v9fs_dentry_operations; | ||
| 599 | d_instantiate(dentry, inode); | ||
| 600 | return 0; | ||
| 601 | |||
| 602 | clean_up_dfid: | ||
| 603 | v9fs_fid_clunk(v9ses, dfid); | ||
| 604 | |||
| 605 | error: | ||
| 606 | return err; | 543 | return err; |
| 607 | } | 544 | } |
| 608 | 545 | ||
| @@ -619,104 +556,54 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, | |||
| 619 | { | 556 | { |
| 620 | struct super_block *sb; | 557 | struct super_block *sb; |
| 621 | struct v9fs_session_info *v9ses; | 558 | struct v9fs_session_info *v9ses; |
| 622 | struct v9fs_fid *dirfid; | 559 | struct p9_fid *dfid, *fid; |
| 623 | struct v9fs_fid *fid; | ||
| 624 | struct inode *inode; | 560 | struct inode *inode; |
| 625 | struct v9fs_fcall *fcall = NULL; | 561 | char *name; |
| 626 | int dirfidnum = -1; | ||
| 627 | int newfid = -1; | ||
| 628 | int result = 0; | 562 | int result = 0; |
| 629 | 563 | ||
| 630 | dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n", | 564 | P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n", |
| 631 | dir, dentry->d_name.name, dentry, nameidata); | 565 | dir, dentry->d_name.name, dentry, nameidata); |
| 632 | 566 | ||
| 633 | sb = dir->i_sb; | 567 | sb = dir->i_sb; |
| 634 | v9ses = v9fs_inode2v9ses(dir); | 568 | v9ses = v9fs_inode2v9ses(dir); |
| 635 | dirfid = v9fs_fid_lookup(dentry->d_parent); | 569 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 636 | 570 | if (IS_ERR(dfid)) | |
| 637 | if(IS_ERR(dirfid)) | 571 | return ERR_PTR(PTR_ERR(dfid)); |
| 638 | return ERR_PTR(PTR_ERR(dirfid)); | 572 | |
| 639 | 573 | name = (char *) dentry->d_name.name; | |
| 640 | dirfidnum = dirfid->fid; | 574 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 641 | 575 | if (IS_ERR(fid)) { | |
| 642 | newfid = v9fs_get_idpool(&v9ses->fidpool); | 576 | result = PTR_ERR(fid); |
| 643 | if (newfid < 0) { | ||
| 644 | eprintk(KERN_WARNING, "newfid fails!\n"); | ||
| 645 | result = -ENOSPC; | ||
| 646 | goto Release_Dirfid; | ||
| 647 | } | ||
| 648 | |||
| 649 | result = v9fs_t_walk(v9ses, dirfidnum, newfid, | ||
| 650 | (char *)dentry->d_name.name, &fcall); | ||
| 651 | |||
| 652 | up(&dirfid->lock); | ||
| 653 | |||
| 654 | if (result < 0) { | ||
| 655 | if (fcall && fcall->id == RWALK) | ||
| 656 | v9fs_t_clunk(v9ses, newfid); | ||
| 657 | else | ||
| 658 | v9fs_put_idpool(newfid, &v9ses->fidpool); | ||
| 659 | |||
| 660 | if (result == -ENOENT) { | 577 | if (result == -ENOENT) { |
| 661 | d_add(dentry, NULL); | 578 | d_add(dentry, NULL); |
| 662 | dprintk(DEBUG_VFS, | ||
| 663 | "Return negative dentry %p count %d\n", | ||
| 664 | dentry, atomic_read(&dentry->d_count)); | ||
| 665 | kfree(fcall); | ||
| 666 | return NULL; | 579 | return NULL; |
| 667 | } | 580 | } |
| 668 | dprintk(DEBUG_ERROR, "walk error:%d\n", result); | ||
| 669 | goto FreeFcall; | ||
| 670 | } | ||
| 671 | kfree(fcall); | ||
| 672 | |||
| 673 | result = v9fs_t_stat(v9ses, newfid, &fcall); | ||
| 674 | if (result < 0) { | ||
| 675 | dprintk(DEBUG_ERROR, "stat error\n"); | ||
| 676 | goto FreeFcall; | ||
| 677 | } | ||
| 678 | |||
| 679 | inode = v9fs_get_inode(sb, p9mode2unixmode(v9ses, | ||
| 680 | fcall->params.rstat.stat.mode)); | ||
| 681 | 581 | ||
| 682 | if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) { | 582 | return ERR_PTR(result); |
| 683 | eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n", | ||
| 684 | PTR_ERR(inode)); | ||
| 685 | |||
| 686 | result = -ENOSPC; | ||
| 687 | goto FreeFcall; | ||
| 688 | } | 583 | } |
| 689 | 584 | ||
| 690 | inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid); | 585 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 691 | 586 | if (IS_ERR(inode)) { | |
| 692 | fid = v9fs_fid_create(v9ses, newfid); | 587 | result = PTR_ERR(inode); |
| 693 | if (fid == NULL) { | 588 | inode = NULL; |
| 694 | dprintk(DEBUG_ERROR, "couldn't insert\n"); | 589 | goto error; |
| 695 | result = -ENOMEM; | ||
| 696 | goto FreeFcall; | ||
| 697 | } | 590 | } |
| 698 | 591 | ||
| 699 | result = v9fs_fid_insert(fid, dentry); | 592 | result = v9fs_fid_add(dentry, fid); |
| 700 | if (result < 0) | 593 | if (result < 0) |
| 701 | goto FreeFcall; | 594 | goto error; |
| 702 | 595 | ||
| 703 | fid->qid = fcall->params.rstat.stat.qid; | ||
| 704 | v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb); | ||
| 705 | if((fid->qid.version)&&(v9ses->cache)) | 596 | if((fid->qid.version)&&(v9ses->cache)) |
| 706 | dentry->d_op = &v9fs_cached_dentry_operations; | 597 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 707 | else | 598 | else |
| 708 | dentry->d_op = &v9fs_dentry_operations; | 599 | dentry->d_op = &v9fs_dentry_operations; |
| 709 | 600 | ||
| 710 | d_add(dentry, inode); | 601 | d_add(dentry, inode); |
| 711 | kfree(fcall); | ||
| 712 | |||
| 713 | return NULL; | 602 | return NULL; |
| 714 | 603 | ||
| 715 | Release_Dirfid: | 604 | error: |
| 716 | up(&dirfid->lock); | 605 | if (fid) |
| 717 | 606 | p9_client_clunk(fid); | |
| 718 | FreeFcall: | ||
| 719 | kfree(fcall); | ||
| 720 | 607 | ||
| 721 | return ERR_PTR(result); | 608 | return ERR_PTR(result); |
| 722 | } | 609 | } |
| @@ -758,73 +645,54 @@ static int | |||
| 758 | v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, | 645 | v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 759 | struct inode *new_dir, struct dentry *new_dentry) | 646 | struct inode *new_dir, struct dentry *new_dentry) |
| 760 | { | 647 | { |
| 761 | struct inode *old_inode = old_dentry->d_inode; | 648 | struct inode *old_inode; |
| 762 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode); | 649 | struct v9fs_session_info *v9ses; |
| 763 | struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry); | 650 | struct p9_fid *oldfid; |
| 764 | struct v9fs_fid *olddirfid; | 651 | struct p9_fid *olddirfid; |
| 765 | struct v9fs_fid *newdirfid; | 652 | struct p9_fid *newdirfid; |
| 766 | struct v9fs_wstat wstat; | 653 | struct p9_wstat wstat; |
| 767 | struct v9fs_fcall *fcall = NULL; | 654 | int retval; |
| 768 | int fid = -1; | ||
| 769 | int olddirfidnum = -1; | ||
| 770 | int newdirfidnum = -1; | ||
| 771 | int retval = 0; | ||
| 772 | |||
| 773 | dprintk(DEBUG_VFS, "\n"); | ||
| 774 | 655 | ||
| 656 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); | ||
| 657 | retval = 0; | ||
| 658 | old_inode = old_dentry->d_inode; | ||
| 659 | v9ses = v9fs_inode2v9ses(old_inode); | ||
| 660 | oldfid = v9fs_fid_lookup(old_dentry); | ||
| 775 | if(IS_ERR(oldfid)) | 661 | if(IS_ERR(oldfid)) |
| 776 | return PTR_ERR(oldfid); | 662 | return PTR_ERR(oldfid); |
| 777 | 663 | ||
| 778 | olddirfid = v9fs_fid_clone(old_dentry->d_parent); | 664 | olddirfid = v9fs_fid_clone(old_dentry->d_parent); |
| 779 | if(IS_ERR(olddirfid)) { | 665 | if(IS_ERR(olddirfid)) { |
| 780 | retval = PTR_ERR(olddirfid); | 666 | retval = PTR_ERR(olddirfid); |
| 781 | goto Release_lock; | 667 | goto done; |
| 782 | } | 668 | } |
| 783 | 669 | ||
| 784 | newdirfid = v9fs_fid_clone(new_dentry->d_parent); | 670 | newdirfid = v9fs_fid_clone(new_dentry->d_parent); |
| 785 | if(IS_ERR(newdirfid)) { | 671 | if(IS_ERR(newdirfid)) { |
| 786 | retval = PTR_ERR(newdirfid); | 672 | retval = PTR_ERR(newdirfid); |
| 787 | goto Clunk_olddir; | 673 | goto clunk_olddir; |
| 788 | } | 674 | } |
| 789 | 675 | ||
| 790 | /* 9P can only handle file rename in the same directory */ | 676 | /* 9P can only handle file rename in the same directory */ |
| 791 | if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) { | 677 | if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) { |
| 792 | dprintk(DEBUG_ERROR, "old dir and new dir are different\n"); | 678 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 679 | "old dir and new dir are different\n"); | ||
| 793 | retval = -EXDEV; | 680 | retval = -EXDEV; |
| 794 | goto Clunk_newdir; | 681 | goto clunk_newdir; |
| 795 | } | ||
| 796 | |||
| 797 | fid = oldfid->fid; | ||
| 798 | olddirfidnum = olddirfid->fid; | ||
| 799 | newdirfidnum = newdirfid->fid; | ||
| 800 | |||
| 801 | if (fid < 0) { | ||
| 802 | dprintk(DEBUG_ERROR, "no fid for old file #%lu\n", | ||
| 803 | old_inode->i_ino); | ||
| 804 | retval = -EBADF; | ||
| 805 | goto Clunk_newdir; | ||
| 806 | } | 682 | } |
| 807 | 683 | ||
| 808 | v9fs_blank_wstat(&wstat); | 684 | v9fs_blank_wstat(&wstat); |
| 809 | wstat.muid = v9ses->name; | 685 | wstat.muid = v9ses->name; |
| 810 | wstat.name = (char *) new_dentry->d_name.name; | 686 | wstat.name = (char *) new_dentry->d_name.name; |
| 687 | retval = p9_client_wstat(oldfid, &wstat); | ||
| 811 | 688 | ||
| 812 | retval = v9fs_t_wstat(v9ses, fid, &wstat, &fcall); | 689 | clunk_newdir: |
| 690 | p9_client_clunk(olddirfid); | ||
| 813 | 691 | ||
| 814 | if (retval < 0) | 692 | clunk_olddir: |
| 815 | PRINT_FCALL_ERROR("wstat error", fcall); | 693 | p9_client_clunk(newdirfid); |
| 816 | |||
| 817 | kfree(fcall); | ||
| 818 | |||
| 819 | Clunk_newdir: | ||
| 820 | v9fs_fid_clunk(v9ses, newdirfid); | ||
| 821 | |||
| 822 | Clunk_olddir: | ||
| 823 | v9fs_fid_clunk(v9ses, olddirfid); | ||
| 824 | |||
| 825 | Release_lock: | ||
| 826 | up(&oldfid->lock); | ||
| 827 | 694 | ||
| 695 | done: | ||
| 828 | return retval; | 696 | return retval; |
| 829 | } | 697 | } |
| 830 | 698 | ||
| @@ -840,28 +708,27 @@ static int | |||
| 840 | v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, | 708 | v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 841 | struct kstat *stat) | 709 | struct kstat *stat) |
| 842 | { | 710 | { |
| 843 | struct v9fs_fcall *fcall = NULL; | 711 | int err; |
| 844 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); | 712 | struct v9fs_session_info *v9ses; |
| 845 | struct v9fs_fid *fid = v9fs_fid_clone(dentry); | 713 | struct p9_fid *fid; |
| 846 | int err = -EPERM; | 714 | struct p9_stat *st; |
| 847 | 715 | ||
| 848 | dprintk(DEBUG_VFS, "dentry: %p\n", dentry); | 716 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); |
| 849 | if(IS_ERR(fid)) | 717 | err = -EPERM; |
| 718 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | ||
| 719 | fid = v9fs_fid_lookup(dentry); | ||
| 720 | if (IS_ERR(fid)) | ||
| 850 | return PTR_ERR(fid); | 721 | return PTR_ERR(fid); |
| 851 | 722 | ||
| 852 | err = v9fs_t_stat(v9ses, fid->fid, &fcall); | 723 | st = p9_client_stat(fid); |
| 724 | if (IS_ERR(st)) | ||
| 725 | return PTR_ERR(st); | ||
| 853 | 726 | ||
| 854 | if (err < 0) | 727 | v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb); |
| 855 | dprintk(DEBUG_ERROR, "stat error\n"); | ||
| 856 | else { | ||
| 857 | v9fs_stat2inode(&fcall->params.rstat.stat, dentry->d_inode, | ||
| 858 | dentry->d_inode->i_sb); | ||
| 859 | generic_fillattr(dentry->d_inode, stat); | 728 | generic_fillattr(dentry->d_inode, stat); |
| 860 | } | ||
| 861 | 729 | ||
| 862 | kfree(fcall); | 730 | kfree(st); |
| 863 | v9fs_fid_clunk(v9ses, fid); | 731 | return 0; |
| 864 | return err; | ||
| 865 | } | 732 | } |
| 866 | 733 | ||
| 867 | /** | 734 | /** |
| @@ -873,13 +740,15 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, | |||
| 873 | 740 | ||
| 874 | static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) | 741 | static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) |
| 875 | { | 742 | { |
| 876 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); | 743 | int retval; |
| 877 | struct v9fs_fid *fid = v9fs_fid_clone(dentry); | 744 | struct v9fs_session_info *v9ses; |
| 878 | struct v9fs_fcall *fcall = NULL; | 745 | struct p9_fid *fid; |
| 879 | struct v9fs_wstat wstat; | 746 | struct p9_wstat wstat; |
| 880 | int res = -EPERM; | ||
| 881 | 747 | ||
| 882 | dprintk(DEBUG_VFS, "\n"); | 748 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 749 | retval = -EPERM; | ||
| 750 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | ||
| 751 | fid = v9fs_fid_lookup(dentry); | ||
| 883 | if(IS_ERR(fid)) | 752 | if(IS_ERR(fid)) |
| 884 | return PTR_ERR(fid); | 753 | return PTR_ERR(fid); |
| 885 | 754 | ||
| @@ -904,17 +773,11 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
| 904 | wstat.n_gid = iattr->ia_gid; | 773 | wstat.n_gid = iattr->ia_gid; |
| 905 | } | 774 | } |
| 906 | 775 | ||
| 907 | res = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall); | 776 | retval = p9_client_wstat(fid, &wstat); |
| 777 | if (retval >= 0) | ||
| 778 | retval = inode_setattr(dentry->d_inode, iattr); | ||
| 908 | 779 | ||
| 909 | if (res < 0) | 780 | return retval; |
| 910 | PRINT_FCALL_ERROR("wstat error", fcall); | ||
| 911 | |||
| 912 | kfree(fcall); | ||
| 913 | if (res >= 0) | ||
| 914 | res = inode_setattr(dentry->d_inode, iattr); | ||
| 915 | |||
| 916 | v9fs_fid_clunk(v9ses, fid); | ||
| 917 | return res; | ||
| 918 | } | 781 | } |
| 919 | 782 | ||
| 920 | /** | 783 | /** |
| @@ -926,7 +789,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
| 926 | */ | 789 | */ |
| 927 | 790 | ||
| 928 | void | 791 | void |
| 929 | v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, | 792 | v9fs_stat2inode(struct p9_stat *stat, struct inode *inode, |
| 930 | struct super_block *sb) | 793 | struct super_block *sb) |
| 931 | { | 794 | { |
| 932 | int n; | 795 | int n; |
| @@ -967,8 +830,9 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, | |||
| 967 | case 'b': | 830 | case 'b': |
| 968 | break; | 831 | break; |
| 969 | default: | 832 | default: |
| 970 | dprintk(DEBUG_ERROR, "Unknown special type %c (%.*s)\n", | 833 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 971 | type, stat->extension.len, stat->extension.str); | 834 | "Unknown special type %c (%.*s)\n", type, |
| 835 | stat->extension.len, stat->extension.str); | ||
| 972 | }; | 836 | }; |
| 973 | inode->i_rdev = MKDEV(major, minor); | 837 | inode->i_rdev = MKDEV(major, minor); |
| 974 | } else | 838 | } else |
| @@ -976,8 +840,8 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, | |||
| 976 | 840 | ||
| 977 | inode->i_size = stat->length; | 841 | inode->i_size = stat->length; |
| 978 | 842 | ||
| 979 | inode->i_blocks = | 843 | /* not real number of blocks, but 512 byte ones ... */ |
| 980 | (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits; | 844 | inode->i_blocks = (inode->i_size + 512 - 1) >> 9; |
| 981 | } | 845 | } |
| 982 | 846 | ||
| 983 | /** | 847 | /** |
| @@ -987,7 +851,7 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode, | |||
| 987 | * BUG: potential for inode number collisions? | 851 | * BUG: potential for inode number collisions? |
| 988 | */ | 852 | */ |
| 989 | 853 | ||
| 990 | ino_t v9fs_qid2ino(struct v9fs_qid *qid) | 854 | ino_t v9fs_qid2ino(struct p9_qid *qid) |
| 991 | { | 855 | { |
| 992 | u64 path = qid->path + 2; | 856 | u64 path = qid->path + 2; |
| 993 | ino_t i = 0; | 857 | ino_t i = 0; |
| @@ -1010,56 +874,46 @@ ino_t v9fs_qid2ino(struct v9fs_qid *qid) | |||
| 1010 | 874 | ||
| 1011 | static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) | 875 | static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) |
| 1012 | { | 876 | { |
| 1013 | int retval = -EPERM; | 877 | int retval; |
| 1014 | 878 | ||
| 1015 | struct v9fs_fcall *fcall = NULL; | 879 | struct v9fs_session_info *v9ses; |
| 1016 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); | 880 | struct p9_fid *fid; |
| 1017 | struct v9fs_fid *fid = v9fs_fid_clone(dentry); | 881 | struct p9_stat *st; |
| 1018 | 882 | ||
| 883 | P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name); | ||
| 884 | retval = -EPERM; | ||
| 885 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | ||
| 886 | fid = v9fs_fid_lookup(dentry); | ||
| 1019 | if(IS_ERR(fid)) | 887 | if(IS_ERR(fid)) |
| 1020 | return PTR_ERR(fid); | 888 | return PTR_ERR(fid); |
| 1021 | 889 | ||
| 1022 | if (!v9ses->extended) { | 890 | if (!v9ses->extended) |
| 1023 | retval = -EBADF; | 891 | return -EBADF; |
| 1024 | dprintk(DEBUG_ERROR, "not extended\n"); | ||
| 1025 | goto ClunkFid; | ||
| 1026 | } | ||
| 1027 | |||
| 1028 | dprintk(DEBUG_VFS, " %s\n", dentry->d_name.name); | ||
| 1029 | retval = v9fs_t_stat(v9ses, fid->fid, &fcall); | ||
| 1030 | |||
| 1031 | if (retval < 0) { | ||
| 1032 | dprintk(DEBUG_ERROR, "stat error\n"); | ||
| 1033 | goto FreeFcall; | ||
| 1034 | } | ||
| 1035 | 892 | ||
| 1036 | if (!fcall) { | 893 | st = p9_client_stat(fid); |
| 1037 | retval = -EIO; | 894 | if (IS_ERR(st)) |
| 1038 | goto ClunkFid; | 895 | return PTR_ERR(st); |
| 1039 | } | ||
| 1040 | 896 | ||
| 1041 | if (!(fcall->params.rstat.stat.mode & V9FS_DMSYMLINK)) { | 897 | if (!(st->mode & P9_DMSYMLINK)) { |
| 1042 | retval = -EINVAL; | 898 | retval = -EINVAL; |
| 1043 | goto FreeFcall; | 899 | goto done; |
| 1044 | } | 900 | } |
| 1045 | 901 | ||
| 1046 | /* copy extension buffer into buffer */ | 902 | /* copy extension buffer into buffer */ |
| 1047 | if (fcall->params.rstat.stat.extension.len < buflen) | 903 | if (st->extension.len < buflen) |
| 1048 | buflen = fcall->params.rstat.stat.extension.len + 1; | 904 | buflen = st->extension.len + 1; |
| 1049 | 905 | ||
| 1050 | memmove(buffer, fcall->params.rstat.stat.extension.str, buflen - 1); | 906 | memmove(buffer, st->extension.str, buflen - 1); |
| 1051 | buffer[buflen-1] = 0; | 907 | buffer[buflen-1] = 0; |
| 1052 | 908 | ||
| 1053 | dprintk(DEBUG_ERROR, "%s -> %.*s (%s)\n", dentry->d_name.name, fcall->params.rstat.stat.extension.len, | 909 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1054 | fcall->params.rstat.stat.extension.str, buffer); | 910 | "%s -> %.*s (%s)\n", dentry->d_name.name, st->extension.len, |
| 1055 | retval = buflen; | 911 | st->extension.str, buffer); |
| 1056 | 912 | ||
| 1057 | FreeFcall: | 913 | retval = buflen; |
| 1058 | kfree(fcall); | ||
| 1059 | |||
| 1060 | ClunkFid: | ||
| 1061 | v9fs_fid_clunk(v9ses, fid); | ||
| 1062 | 914 | ||
| 915 | done: | ||
| 916 | kfree(st); | ||
| 1063 | return retval; | 917 | return retval; |
| 1064 | } | 918 | } |
| 1065 | 919 | ||
| @@ -1084,14 +938,14 @@ static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer, | |||
| 1084 | if (buflen > PATH_MAX) | 938 | if (buflen > PATH_MAX) |
| 1085 | buflen = PATH_MAX; | 939 | buflen = PATH_MAX; |
| 1086 | 940 | ||
| 1087 | dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); | 941 | P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry); |
| 1088 | 942 | ||
| 1089 | retval = v9fs_readlink(dentry, link, buflen); | 943 | retval = v9fs_readlink(dentry, link, buflen); |
| 1090 | 944 | ||
| 1091 | if (retval > 0) { | 945 | if (retval > 0) { |
| 1092 | if ((ret = copy_to_user(buffer, link, retval)) != 0) { | 946 | if ((ret = copy_to_user(buffer, link, retval)) != 0) { |
| 1093 | dprintk(DEBUG_ERROR, "problem copying to user: %d\n", | 947 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 1094 | ret); | 948 | "problem copying to user: %d\n", ret); |
| 1095 | retval = ret; | 949 | retval = ret; |
| 1096 | } | 950 | } |
| 1097 | } | 951 | } |
| @@ -1112,7 +966,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
| 1112 | int len = 0; | 966 | int len = 0; |
| 1113 | char *link = __getname(); | 967 | char *link = __getname(); |
| 1114 | 968 | ||
| 1115 | dprintk(DEBUG_VFS, "%s n", dentry->d_name.name); | 969 | P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name); |
| 1116 | 970 | ||
| 1117 | if (!link) | 971 | if (!link) |
| 1118 | link = ERR_PTR(-ENOMEM); | 972 | link = ERR_PTR(-ENOMEM); |
| @@ -1141,7 +995,7 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void | |||
| 1141 | { | 995 | { |
| 1142 | char *s = nd_get_link(nd); | 996 | char *s = nd_get_link(nd); |
| 1143 | 997 | ||
| 1144 | dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s); | 998 | P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, s); |
| 1145 | if (!IS_ERR(s)) | 999 | if (!IS_ERR(s)) |
| 1146 | __putname(s); | 1000 | __putname(s); |
| 1147 | } | 1001 | } |
| @@ -1149,66 +1003,24 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void | |||
| 1149 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, | 1003 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, |
| 1150 | int mode, const char *extension) | 1004 | int mode, const char *extension) |
| 1151 | { | 1005 | { |
| 1152 | int err; | 1006 | u32 perm; |
| 1153 | u32 fid, perm; | ||
| 1154 | struct v9fs_session_info *v9ses; | 1007 | struct v9fs_session_info *v9ses; |
| 1155 | struct v9fs_fid *dfid, *vfid = NULL; | 1008 | struct p9_fid *fid; |
| 1156 | struct inode *inode = NULL; | ||
| 1157 | 1009 | ||
| 1158 | v9ses = v9fs_inode2v9ses(dir); | 1010 | v9ses = v9fs_inode2v9ses(dir); |
| 1159 | if (!v9ses->extended) { | 1011 | if (!v9ses->extended) { |
| 1160 | dprintk(DEBUG_ERROR, "not extended\n"); | 1012 | P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n"); |
| 1161 | return -EPERM; | 1013 | return -EPERM; |
| 1162 | } | 1014 | } |
| 1163 | 1015 | ||
| 1164 | dfid = v9fs_fid_clone(dentry->d_parent); | ||
| 1165 | if(IS_ERR(dfid)) { | ||
| 1166 | err = PTR_ERR(dfid); | ||
| 1167 | goto error; | ||
| 1168 | } | ||
| 1169 | |||
| 1170 | perm = unixmode2p9mode(v9ses, mode); | 1016 | perm = unixmode2p9mode(v9ses, mode); |
| 1017 | fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm, | ||
| 1018 | P9_OREAD); | ||
| 1019 | if (IS_ERR(fid)) | ||
| 1020 | return PTR_ERR(fid); | ||
| 1171 | 1021 | ||
| 1172 | err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name, | 1022 | p9_client_clunk(fid); |
| 1173 | perm, V9FS_OREAD, (char *) extension, &fid, NULL, NULL); | ||
| 1174 | |||
| 1175 | if (err) | ||
| 1176 | goto clunk_dfid; | ||
| 1177 | |||
| 1178 | err = v9fs_t_clunk(v9ses, fid); | ||
| 1179 | if (err) | ||
| 1180 | goto clunk_dfid; | ||
| 1181 | |||
| 1182 | vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry); | ||
| 1183 | if (IS_ERR(vfid)) { | ||
| 1184 | err = PTR_ERR(vfid); | ||
| 1185 | vfid = NULL; | ||
| 1186 | goto clunk_dfid; | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb); | ||
| 1190 | if (IS_ERR(inode)) { | ||
| 1191 | err = PTR_ERR(inode); | ||
| 1192 | inode = NULL; | ||
| 1193 | goto free_vfid; | ||
| 1194 | } | ||
| 1195 | |||
| 1196 | if(v9ses->cache) | ||
| 1197 | dentry->d_op = &v9fs_cached_dentry_operations; | ||
| 1198 | else | ||
| 1199 | dentry->d_op = &v9fs_dentry_operations; | ||
| 1200 | d_instantiate(dentry, inode); | ||
| 1201 | return 0; | 1023 | return 0; |
| 1202 | |||
| 1203 | free_vfid: | ||
| 1204 | v9fs_fid_destroy(vfid); | ||
| 1205 | |||
| 1206 | clunk_dfid: | ||
| 1207 | v9fs_fid_clunk(v9ses, dfid); | ||
| 1208 | |||
| 1209 | error: | ||
| 1210 | return err; | ||
| 1211 | |||
| 1212 | } | 1024 | } |
| 1213 | 1025 | ||
| 1214 | /** | 1026 | /** |
| @@ -1224,8 +1036,8 @@ error: | |||
| 1224 | static int | 1036 | static int |
| 1225 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | 1037 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) |
| 1226 | { | 1038 | { |
| 1227 | dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, | 1039 | P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, |
| 1228 | symname); | 1040 | dentry->d_name.name, symname); |
| 1229 | 1041 | ||
| 1230 | return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname); | 1042 | return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname); |
| 1231 | } | 1043 | } |
| @@ -1247,11 +1059,11 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, | |||
| 1247 | struct dentry *dentry) | 1059 | struct dentry *dentry) |
| 1248 | { | 1060 | { |
| 1249 | int retval; | 1061 | int retval; |
| 1250 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); | 1062 | struct p9_fid *oldfid; |
| 1251 | struct v9fs_fid *oldfid; | ||
| 1252 | char *name; | 1063 | char *name; |
| 1253 | 1064 | ||
| 1254 | dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, | 1065 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1066 | " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, | ||
| 1255 | old_dentry->d_name.name); | 1067 | old_dentry->d_name.name); |
| 1256 | 1068 | ||
| 1257 | oldfid = v9fs_fid_clone(old_dentry); | 1069 | oldfid = v9fs_fid_clone(old_dentry); |
| @@ -1265,11 +1077,11 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, | |||
| 1265 | } | 1077 | } |
| 1266 | 1078 | ||
| 1267 | sprintf(name, "%d\n", oldfid->fid); | 1079 | sprintf(name, "%d\n", oldfid->fid); |
| 1268 | retval = v9fs_vfs_mkspecial(dir, dentry, V9FS_DMLINK, name); | 1080 | retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name); |
| 1269 | __putname(name); | 1081 | __putname(name); |
| 1270 | 1082 | ||
| 1271 | clunk_fid: | 1083 | clunk_fid: |
| 1272 | v9fs_fid_clunk(v9ses, oldfid); | 1084 | p9_client_clunk(oldfid); |
| 1273 | return retval; | 1085 | return retval; |
| 1274 | } | 1086 | } |
| 1275 | 1087 | ||
| @@ -1288,7 +1100,8 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) | |||
| 1288 | int retval; | 1100 | int retval; |
| 1289 | char *name; | 1101 | char *name; |
| 1290 | 1102 | ||
| 1291 | dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, | 1103 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1104 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, | ||
| 1292 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); | 1105 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); |
| 1293 | 1106 | ||
| 1294 | if (!new_valid_dev(rdev)) | 1107 | if (!new_valid_dev(rdev)) |
