diff options
Diffstat (limited to 'fs/fuse/inode.c')
| -rw-r--r-- | fs/fuse/inode.c | 268 |
1 files changed, 229 insertions, 39 deletions
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 04c80cc957a3..c755a0440a66 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c | |||
| @@ -24,6 +24,13 @@ MODULE_LICENSE("GPL"); | |||
| 24 | 24 | ||
| 25 | spinlock_t fuse_lock; | 25 | spinlock_t fuse_lock; |
| 26 | static kmem_cache_t *fuse_inode_cachep; | 26 | static kmem_cache_t *fuse_inode_cachep; |
| 27 | static struct subsystem connections_subsys; | ||
| 28 | |||
| 29 | struct fuse_conn_attr { | ||
| 30 | struct attribute attr; | ||
| 31 | ssize_t (*show)(struct fuse_conn *, char *); | ||
| 32 | ssize_t (*store)(struct fuse_conn *, const char *, size_t); | ||
| 33 | }; | ||
| 27 | 34 | ||
| 28 | #define FUSE_SUPER_MAGIC 0x65735546 | 35 | #define FUSE_SUPER_MAGIC 0x65735546 |
| 29 | 36 | ||
| @@ -189,6 +196,11 @@ struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, | |||
| 189 | return inode; | 196 | return inode; |
| 190 | } | 197 | } |
| 191 | 198 | ||
| 199 | static void fuse_umount_begin(struct super_block *sb) | ||
| 200 | { | ||
| 201 | fuse_abort_conn(get_fuse_conn_super(sb)); | ||
| 202 | } | ||
| 203 | |||
| 192 | static void fuse_put_super(struct super_block *sb) | 204 | static void fuse_put_super(struct super_block *sb) |
| 193 | { | 205 | { |
| 194 | struct fuse_conn *fc = get_fuse_conn_super(sb); | 206 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
| @@ -200,14 +212,13 @@ static void fuse_put_super(struct super_block *sb) | |||
| 200 | 212 | ||
| 201 | spin_lock(&fuse_lock); | 213 | spin_lock(&fuse_lock); |
| 202 | fc->mounted = 0; | 214 | fc->mounted = 0; |
| 203 | fc->user_id = 0; | 215 | fc->connected = 0; |
| 204 | fc->group_id = 0; | 216 | spin_unlock(&fuse_lock); |
| 205 | fc->flags = 0; | 217 | up_write(&fc->sbput_sem); |
| 206 | /* Flush all readers on this fs */ | 218 | /* Flush all readers on this fs */ |
| 207 | wake_up_all(&fc->waitq); | 219 | wake_up_all(&fc->waitq); |
| 208 | up_write(&fc->sbput_sem); | 220 | kobject_del(&fc->kobj); |
| 209 | fuse_release_conn(fc); | 221 | kobject_put(&fc->kobj); |
| 210 | spin_unlock(&fuse_lock); | ||
| 211 | } | 222 | } |
| 212 | 223 | ||
| 213 | static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr) | 224 | static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr) |
| @@ -356,8 +367,10 @@ static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt) | |||
| 356 | return 0; | 367 | return 0; |
| 357 | } | 368 | } |
| 358 | 369 | ||
| 359 | static void free_conn(struct fuse_conn *fc) | 370 | static void fuse_conn_release(struct kobject *kobj) |
| 360 | { | 371 | { |
| 372 | struct fuse_conn *fc = get_fuse_conn_kobj(kobj); | ||
| 373 | |||
| 361 | while (!list_empty(&fc->unused_list)) { | 374 | while (!list_empty(&fc->unused_list)) { |
| 362 | struct fuse_req *req; | 375 | struct fuse_req *req; |
| 363 | req = list_entry(fc->unused_list.next, struct fuse_req, list); | 376 | req = list_entry(fc->unused_list.next, struct fuse_req, list); |
| @@ -367,33 +380,28 @@ static void free_conn(struct fuse_conn *fc) | |||
| 367 | kfree(fc); | 380 | kfree(fc); |
| 368 | } | 381 | } |
| 369 | 382 | ||
| 370 | /* Must be called with the fuse lock held */ | ||
| 371 | void fuse_release_conn(struct fuse_conn *fc) | ||
| 372 | { | ||
| 373 | fc->count--; | ||
| 374 | if (!fc->count) | ||
| 375 | free_conn(fc); | ||
| 376 | } | ||
| 377 | |||
| 378 | static struct fuse_conn *new_conn(void) | 383 | static struct fuse_conn *new_conn(void) |
| 379 | { | 384 | { |
| 380 | struct fuse_conn *fc; | 385 | struct fuse_conn *fc; |
| 381 | 386 | ||
| 382 | fc = kmalloc(sizeof(*fc), GFP_KERNEL); | 387 | fc = kzalloc(sizeof(*fc), GFP_KERNEL); |
| 383 | if (fc != NULL) { | 388 | if (fc) { |
| 384 | int i; | 389 | int i; |
| 385 | memset(fc, 0, sizeof(*fc)); | ||
| 386 | init_waitqueue_head(&fc->waitq); | 390 | init_waitqueue_head(&fc->waitq); |
| 387 | INIT_LIST_HEAD(&fc->pending); | 391 | INIT_LIST_HEAD(&fc->pending); |
| 388 | INIT_LIST_HEAD(&fc->processing); | 392 | INIT_LIST_HEAD(&fc->processing); |
| 393 | INIT_LIST_HEAD(&fc->io); | ||
| 389 | INIT_LIST_HEAD(&fc->unused_list); | 394 | INIT_LIST_HEAD(&fc->unused_list); |
| 390 | INIT_LIST_HEAD(&fc->background); | 395 | INIT_LIST_HEAD(&fc->background); |
| 391 | sema_init(&fc->outstanding_sem, 0); | 396 | sema_init(&fc->outstanding_sem, 1); /* One for INIT */ |
| 392 | init_rwsem(&fc->sbput_sem); | 397 | init_rwsem(&fc->sbput_sem); |
| 398 | kobj_set_kset_s(fc, connections_subsys); | ||
| 399 | kobject_init(&fc->kobj); | ||
| 400 | atomic_set(&fc->num_waiting, 0); | ||
| 393 | for (i = 0; i < FUSE_MAX_OUTSTANDING; i++) { | 401 | for (i = 0; i < FUSE_MAX_OUTSTANDING; i++) { |
| 394 | struct fuse_req *req = fuse_request_alloc(); | 402 | struct fuse_req *req = fuse_request_alloc(); |
| 395 | if (!req) { | 403 | if (!req) { |
| 396 | free_conn(fc); | 404 | kobject_put(&fc->kobj); |
| 397 | return NULL; | 405 | return NULL; |
| 398 | } | 406 | } |
| 399 | list_add(&req->list, &fc->unused_list); | 407 | list_add(&req->list, &fc->unused_list); |
| @@ -408,25 +416,32 @@ static struct fuse_conn *new_conn(void) | |||
| 408 | static struct fuse_conn *get_conn(struct file *file, struct super_block *sb) | 416 | static struct fuse_conn *get_conn(struct file *file, struct super_block *sb) |
| 409 | { | 417 | { |
| 410 | struct fuse_conn *fc; | 418 | struct fuse_conn *fc; |
| 419 | int err; | ||
| 411 | 420 | ||
| 421 | err = -EINVAL; | ||
| 412 | if (file->f_op != &fuse_dev_operations) | 422 | if (file->f_op != &fuse_dev_operations) |
| 413 | return ERR_PTR(-EINVAL); | 423 | goto out_err; |
| 424 | |||
| 425 | err = -ENOMEM; | ||
| 414 | fc = new_conn(); | 426 | fc = new_conn(); |
| 415 | if (fc == NULL) | 427 | if (!fc) |
| 416 | return ERR_PTR(-ENOMEM); | 428 | goto out_err; |
| 429 | |||
| 417 | spin_lock(&fuse_lock); | 430 | spin_lock(&fuse_lock); |
| 418 | if (file->private_data) { | 431 | err = -EINVAL; |
| 419 | free_conn(fc); | 432 | if (file->private_data) |
| 420 | fc = ERR_PTR(-EINVAL); | 433 | goto out_unlock; |
| 421 | } else { | 434 | |
| 422 | file->private_data = fc; | 435 | kobject_get(&fc->kobj); |
| 423 | *get_fuse_conn_super_p(sb) = fc; | 436 | file->private_data = fc; |
| 424 | fc->mounted = 1; | ||
| 425 | fc->connected = 1; | ||
| 426 | fc->count = 2; | ||
| 427 | } | ||
| 428 | spin_unlock(&fuse_lock); | 437 | spin_unlock(&fuse_lock); |
| 429 | return fc; | 438 | return fc; |
| 439 | |||
| 440 | out_unlock: | ||
| 441 | spin_unlock(&fuse_lock); | ||
| 442 | kobject_put(&fc->kobj); | ||
| 443 | out_err: | ||
| 444 | return ERR_PTR(err); | ||
| 430 | } | 445 | } |
| 431 | 446 | ||
| 432 | static struct inode *get_root_inode(struct super_block *sb, unsigned mode) | 447 | static struct inode *get_root_inode(struct super_block *sb, unsigned mode) |
| @@ -445,16 +460,74 @@ static struct super_operations fuse_super_operations = { | |||
| 445 | .read_inode = fuse_read_inode, | 460 | .read_inode = fuse_read_inode, |
| 446 | .clear_inode = fuse_clear_inode, | 461 | .clear_inode = fuse_clear_inode, |
| 447 | .put_super = fuse_put_super, | 462 | .put_super = fuse_put_super, |
| 463 | .umount_begin = fuse_umount_begin, | ||
| 448 | .statfs = fuse_statfs, | 464 | .statfs = fuse_statfs, |
| 449 | .show_options = fuse_show_options, | 465 | .show_options = fuse_show_options, |
| 450 | }; | 466 | }; |
| 451 | 467 | ||
| 468 | static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) | ||
| 469 | { | ||
| 470 | int i; | ||
| 471 | struct fuse_init_out *arg = &req->misc.init_out; | ||
| 472 | |||
| 473 | if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION) | ||
| 474 | fc->conn_error = 1; | ||
| 475 | else { | ||
| 476 | fc->minor = arg->minor; | ||
| 477 | fc->max_write = arg->minor < 5 ? 4096 : arg->max_write; | ||
| 478 | } | ||
| 479 | |||
| 480 | /* After INIT reply is received other requests can go | ||
| 481 | out. So do (FUSE_MAX_OUTSTANDING - 1) number of | ||
| 482 | up()s on outstanding_sem. The last up() is done in | ||
| 483 | fuse_putback_request() */ | ||
| 484 | for (i = 1; i < FUSE_MAX_OUTSTANDING; i++) | ||
| 485 | up(&fc->outstanding_sem); | ||
| 486 | |||
| 487 | fuse_put_request(fc, req); | ||
| 488 | } | ||
| 489 | |||
| 490 | static void fuse_send_init(struct fuse_conn *fc) | ||
| 491 | { | ||
| 492 | /* This is called from fuse_read_super() so there's guaranteed | ||
| 493 | to be exactly one request available */ | ||
| 494 | struct fuse_req *req = fuse_get_request(fc); | ||
| 495 | struct fuse_init_in *arg = &req->misc.init_in; | ||
| 496 | |||
| 497 | arg->major = FUSE_KERNEL_VERSION; | ||
| 498 | arg->minor = FUSE_KERNEL_MINOR_VERSION; | ||
| 499 | req->in.h.opcode = FUSE_INIT; | ||
| 500 | req->in.numargs = 1; | ||
| 501 | req->in.args[0].size = sizeof(*arg); | ||
| 502 | req->in.args[0].value = arg; | ||
| 503 | req->out.numargs = 1; | ||
| 504 | /* Variable length arguement used for backward compatibility | ||
| 505 | with interface version < 7.5. Rest of init_out is zeroed | ||
| 506 | by do_get_request(), so a short reply is not a problem */ | ||
| 507 | req->out.argvar = 1; | ||
| 508 | req->out.args[0].size = sizeof(struct fuse_init_out); | ||
| 509 | req->out.args[0].value = &req->misc.init_out; | ||
| 510 | req->end = process_init_reply; | ||
| 511 | request_send_background(fc, req); | ||
| 512 | } | ||
| 513 | |||
| 514 | static unsigned long long conn_id(void) | ||
| 515 | { | ||
| 516 | static unsigned long long ctr = 1; | ||
| 517 | unsigned long long val; | ||
| 518 | spin_lock(&fuse_lock); | ||
| 519 | val = ctr++; | ||
| 520 | spin_unlock(&fuse_lock); | ||
| 521 | return val; | ||
| 522 | } | ||
| 523 | |||
| 452 | static int fuse_fill_super(struct super_block *sb, void *data, int silent) | 524 | static int fuse_fill_super(struct super_block *sb, void *data, int silent) |
| 453 | { | 525 | { |
| 454 | struct fuse_conn *fc; | 526 | struct fuse_conn *fc; |
| 455 | struct inode *root; | 527 | struct inode *root; |
| 456 | struct fuse_mount_data d; | 528 | struct fuse_mount_data d; |
| 457 | struct file *file; | 529 | struct file *file; |
| 530 | struct dentry *root_dentry; | ||
| 458 | int err; | 531 | int err; |
| 459 | 532 | ||
| 460 | if (!parse_fuse_opt((char *) data, &d)) | 533 | if (!parse_fuse_opt((char *) data, &d)) |
| @@ -482,23 +555,42 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) | |||
| 482 | if (fc->max_read / PAGE_CACHE_SIZE < fc->bdi.ra_pages) | 555 | if (fc->max_read / PAGE_CACHE_SIZE < fc->bdi.ra_pages) |
| 483 | fc->bdi.ra_pages = fc->max_read / PAGE_CACHE_SIZE; | 556 | fc->bdi.ra_pages = fc->max_read / PAGE_CACHE_SIZE; |
| 484 | 557 | ||
| 558 | /* Used by get_root_inode() */ | ||
| 559 | sb->s_fs_info = fc; | ||
| 560 | |||
| 485 | err = -ENOMEM; | 561 | err = -ENOMEM; |
| 486 | root = get_root_inode(sb, d.rootmode); | 562 | root = get_root_inode(sb, d.rootmode); |
| 487 | if (root == NULL) | 563 | if (!root) |
| 488 | goto err; | 564 | goto err; |
| 489 | 565 | ||
| 490 | sb->s_root = d_alloc_root(root); | 566 | root_dentry = d_alloc_root(root); |
| 491 | if (!sb->s_root) { | 567 | if (!root_dentry) { |
| 492 | iput(root); | 568 | iput(root); |
| 493 | goto err; | 569 | goto err; |
| 494 | } | 570 | } |
| 571 | |||
| 572 | err = kobject_set_name(&fc->kobj, "%llu", conn_id()); | ||
| 573 | if (err) | ||
| 574 | goto err_put_root; | ||
| 575 | |||
| 576 | err = kobject_add(&fc->kobj); | ||
| 577 | if (err) | ||
| 578 | goto err_put_root; | ||
| 579 | |||
| 580 | sb->s_root = root_dentry; | ||
| 581 | spin_lock(&fuse_lock); | ||
| 582 | fc->mounted = 1; | ||
| 583 | fc->connected = 1; | ||
| 584 | spin_unlock(&fuse_lock); | ||
| 585 | |||
| 495 | fuse_send_init(fc); | 586 | fuse_send_init(fc); |
| 587 | |||
| 496 | return 0; | 588 | return 0; |
| 497 | 589 | ||
| 590 | err_put_root: | ||
| 591 | dput(root_dentry); | ||
| 498 | err: | 592 | err: |
| 499 | spin_lock(&fuse_lock); | 593 | kobject_put(&fc->kobj); |
| 500 | fuse_release_conn(fc); | ||
| 501 | spin_unlock(&fuse_lock); | ||
| 502 | return err; | 594 | return err; |
| 503 | } | 595 | } |
| 504 | 596 | ||
| @@ -516,6 +608,69 @@ static struct file_system_type fuse_fs_type = { | |||
| 516 | .kill_sb = kill_anon_super, | 608 | .kill_sb = kill_anon_super, |
| 517 | }; | 609 | }; |
| 518 | 610 | ||
| 611 | static ssize_t fuse_conn_waiting_show(struct fuse_conn *fc, char *page) | ||
| 612 | { | ||
| 613 | return sprintf(page, "%i\n", atomic_read(&fc->num_waiting)); | ||
| 614 | } | ||
| 615 | |||
| 616 | static ssize_t fuse_conn_abort_store(struct fuse_conn *fc, const char *page, | ||
| 617 | size_t count) | ||
| 618 | { | ||
| 619 | fuse_abort_conn(fc); | ||
| 620 | return count; | ||
| 621 | } | ||
| 622 | |||
| 623 | static struct fuse_conn_attr fuse_conn_waiting = | ||
| 624 | __ATTR(waiting, 0400, fuse_conn_waiting_show, NULL); | ||
| 625 | static struct fuse_conn_attr fuse_conn_abort = | ||
| 626 | __ATTR(abort, 0600, NULL, fuse_conn_abort_store); | ||
| 627 | |||
| 628 | static struct attribute *fuse_conn_attrs[] = { | ||
| 629 | &fuse_conn_waiting.attr, | ||
| 630 | &fuse_conn_abort.attr, | ||
| 631 | NULL, | ||
| 632 | }; | ||
| 633 | |||
| 634 | static ssize_t fuse_conn_attr_show(struct kobject *kobj, | ||
| 635 | struct attribute *attr, | ||
| 636 | char *page) | ||
| 637 | { | ||
| 638 | struct fuse_conn_attr *fca = | ||
| 639 | container_of(attr, struct fuse_conn_attr, attr); | ||
| 640 | |||
| 641 | if (fca->show) | ||
| 642 | return fca->show(get_fuse_conn_kobj(kobj), page); | ||
| 643 | else | ||
| 644 | return -EACCES; | ||
| 645 | } | ||
| 646 | |||
| 647 | static ssize_t fuse_conn_attr_store(struct kobject *kobj, | ||
| 648 | struct attribute *attr, | ||
| 649 | const char *page, size_t count) | ||
| 650 | { | ||
| 651 | struct fuse_conn_attr *fca = | ||
| 652 | container_of(attr, struct fuse_conn_attr, attr); | ||
| 653 | |||
| 654 | if (fca->store) | ||
| 655 | return fca->store(get_fuse_conn_kobj(kobj), page, count); | ||
| 656 | else | ||
| 657 | return -EACCES; | ||
| 658 | } | ||
| 659 | |||
| 660 | static struct sysfs_ops fuse_conn_sysfs_ops = { | ||
| 661 | .show = &fuse_conn_attr_show, | ||
| 662 | .store = &fuse_conn_attr_store, | ||
| 663 | }; | ||
| 664 | |||
| 665 | static struct kobj_type ktype_fuse_conn = { | ||
| 666 | .release = fuse_conn_release, | ||
| 667 | .sysfs_ops = &fuse_conn_sysfs_ops, | ||
| 668 | .default_attrs = fuse_conn_attrs, | ||
| 669 | }; | ||
| 670 | |||
| 671 | static decl_subsys(fuse, NULL, NULL); | ||
| 672 | static decl_subsys(connections, &ktype_fuse_conn, NULL); | ||
| 673 | |||
| 519 | static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep, | 674 | static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep, |
| 520 | unsigned long flags) | 675 | unsigned long flags) |
| 521 | { | 676 | { |
| @@ -553,6 +708,34 @@ static void fuse_fs_cleanup(void) | |||
| 553 | kmem_cache_destroy(fuse_inode_cachep); | 708 | kmem_cache_destroy(fuse_inode_cachep); |
| 554 | } | 709 | } |
| 555 | 710 | ||
| 711 | static int fuse_sysfs_init(void) | ||
| 712 | { | ||
| 713 | int err; | ||
| 714 | |||
| 715 | kset_set_kset_s(&fuse_subsys, fs_subsys); | ||
| 716 | err = subsystem_register(&fuse_subsys); | ||
| 717 | if (err) | ||
| 718 | goto out_err; | ||
| 719 | |||
| 720 | kset_set_kset_s(&connections_subsys, fuse_subsys); | ||
| 721 | err = subsystem_register(&connections_subsys); | ||
| 722 | if (err) | ||
| 723 | goto out_fuse_unregister; | ||
| 724 | |||
| 725 | return 0; | ||
| 726 | |||
| 727 | out_fuse_unregister: | ||
| 728 | subsystem_unregister(&fuse_subsys); | ||
| 729 | out_err: | ||
| 730 | return err; | ||
| 731 | } | ||
| 732 | |||
| 733 | static void fuse_sysfs_cleanup(void) | ||
| 734 | { | ||
| 735 | subsystem_unregister(&connections_subsys); | ||
| 736 | subsystem_unregister(&fuse_subsys); | ||
| 737 | } | ||
| 738 | |||
| 556 | static int __init fuse_init(void) | 739 | static int __init fuse_init(void) |
| 557 | { | 740 | { |
| 558 | int res; | 741 | int res; |
| @@ -569,8 +752,14 @@ static int __init fuse_init(void) | |||
| 569 | if (res) | 752 | if (res) |
| 570 | goto err_fs_cleanup; | 753 | goto err_fs_cleanup; |
| 571 | 754 | ||
| 755 | res = fuse_sysfs_init(); | ||
| 756 | if (res) | ||
| 757 | goto err_dev_cleanup; | ||
| 758 | |||
| 572 | return 0; | 759 | return 0; |
| 573 | 760 | ||
| 761 | err_dev_cleanup: | ||
| 762 | fuse_dev_cleanup(); | ||
| 574 | err_fs_cleanup: | 763 | err_fs_cleanup: |
| 575 | fuse_fs_cleanup(); | 764 | fuse_fs_cleanup(); |
| 576 | err: | 765 | err: |
| @@ -581,6 +770,7 @@ static void __exit fuse_exit(void) | |||
| 581 | { | 770 | { |
| 582 | printk(KERN_DEBUG "fuse exit\n"); | 771 | printk(KERN_DEBUG "fuse exit\n"); |
| 583 | 772 | ||
| 773 | fuse_sysfs_cleanup(); | ||
| 584 | fuse_fs_cleanup(); | 774 | fuse_fs_cleanup(); |
| 585 | fuse_dev_cleanup(); | 775 | fuse_dev_cleanup(); |
| 586 | } | 776 | } |
