ioctl.c (6cda3eb62ef42aa5acd649bf99c8db544e0f4051) ioctl.c (5d847a8ed970d17e2734ff9e07a74fe36cceb24e)
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 423 unchanged lines hidden (view full) ---

432 balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1);
433 }
434
435out_unlock:
436 mutex_unlock(&inode->i_mutex);
437 return 0;
438}
439
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 423 unchanged lines hidden (view full) ---

432 balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1);
433 }
434
435out_unlock:
436 mutex_unlock(&inode->i_mutex);
437 return 0;
438}
439
440/*
441 * Called inside transaction, so use GFP_NOFS
442 */
443
444static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg)
445{
446 u64 new_size;
447 u64 old_size;
448 u64 devid = 1;
449 struct btrfs_ioctl_vol_args *vol_args;
450 struct btrfs_trans_handle *trans;
451 struct btrfs_device *device = NULL;

--- 4 unchanged lines hidden (view full) ---

456 int mod = 0;
457
458 if (root->fs_info->sb->s_flags & MS_RDONLY)
459 return -EROFS;
460
461 if (!capable(CAP_SYS_ADMIN))
462 return -EPERM;
463
440static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg)
441{
442 u64 new_size;
443 u64 old_size;
444 u64 devid = 1;
445 struct btrfs_ioctl_vol_args *vol_args;
446 struct btrfs_trans_handle *trans;
447 struct btrfs_device *device = NULL;

--- 4 unchanged lines hidden (view full) ---

452 int mod = 0;
453
454 if (root->fs_info->sb->s_flags & MS_RDONLY)
455 return -EROFS;
456
457 if (!capable(CAP_SYS_ADMIN))
458 return -EPERM;
459
464 vol_args = memdup_user(arg, sizeof(*vol_args));
465 if (IS_ERR(vol_args))
466 return PTR_ERR(vol_args);
460 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
467
461
462 if (!vol_args)
463 return -ENOMEM;
464
465 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
466 ret = -EFAULT;
467 goto out;
468 }
469
468 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
469 namelen = strlen(vol_args->name);
470
471 mutex_lock(&root->fs_info->volume_mutex);
472 sizestr = vol_args->name;
473 devstr = strchr(sizestr, ':');
474 if (devstr) {
475 char *end;

--- 60 unchanged lines hidden (view full) ---

536 ret = btrfs_grow_device(trans, device, new_size);
537 btrfs_commit_transaction(trans, root);
538 } else {
539 ret = btrfs_shrink_device(device, new_size);
540 }
541
542out_unlock:
543 mutex_unlock(&root->fs_info->volume_mutex);
470 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
471 namelen = strlen(vol_args->name);
472
473 mutex_lock(&root->fs_info->volume_mutex);
474 sizestr = vol_args->name;
475 devstr = strchr(sizestr, ':');
476 if (devstr) {
477 char *end;

--- 60 unchanged lines hidden (view full) ---

538 ret = btrfs_grow_device(trans, device, new_size);
539 btrfs_commit_transaction(trans, root);
540 } else {
541 ret = btrfs_shrink_device(device, new_size);
542 }
543
544out_unlock:
545 mutex_unlock(&root->fs_info->volume_mutex);
546out:
544 kfree(vol_args);
545 return ret;
546}
547
548static noinline int btrfs_ioctl_snap_create(struct file *file,
549 void __user *arg, int subvol)
550{
551 struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
552 struct btrfs_ioctl_vol_args *vol_args;
553 struct btrfs_dir_item *di;
554 struct btrfs_path *path;
555 struct file *src_file;
556 u64 root_dirid;
557 int namelen;
558 int ret = 0;
559
560 if (root->fs_info->sb->s_flags & MS_RDONLY)
561 return -EROFS;
562
547 kfree(vol_args);
548 return ret;
549}
550
551static noinline int btrfs_ioctl_snap_create(struct file *file,
552 void __user *arg, int subvol)
553{
554 struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
555 struct btrfs_ioctl_vol_args *vol_args;
556 struct btrfs_dir_item *di;
557 struct btrfs_path *path;
558 struct file *src_file;
559 u64 root_dirid;
560 int namelen;
561 int ret = 0;
562
563 if (root->fs_info->sb->s_flags & MS_RDONLY)
564 return -EROFS;
565
563 vol_args = memdup_user(arg, sizeof(*vol_args));
564 if (IS_ERR(vol_args))
565 return PTR_ERR(vol_args);
566 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
566
567
568 if (!vol_args)
569 return -ENOMEM;
570
571 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
572 ret = -EFAULT;
573 goto out;
574 }
575
567 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
568 namelen = strlen(vol_args->name);
569 if (strchr(vol_args->name, '/')) {
570 ret = -EINVAL;
571 goto out;
572 }
573
574 path = btrfs_alloc_path();

--- 84 unchanged lines hidden (view full) ---

659static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
660{
661 struct btrfs_ioctl_vol_args *vol_args;
662 int ret;
663
664 if (!capable(CAP_SYS_ADMIN))
665 return -EPERM;
666
576 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
577 namelen = strlen(vol_args->name);
578 if (strchr(vol_args->name, '/')) {
579 ret = -EINVAL;
580 goto out;
581 }
582
583 path = btrfs_alloc_path();

--- 84 unchanged lines hidden (view full) ---

668static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
669{
670 struct btrfs_ioctl_vol_args *vol_args;
671 int ret;
672
673 if (!capable(CAP_SYS_ADMIN))
674 return -EPERM;
675
667 vol_args = memdup_user(arg, sizeof(*vol_args));
668 if (IS_ERR(vol_args))
669 return PTR_ERR(vol_args);
676 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
670
677
678 if (!vol_args)
679 return -ENOMEM;
680
681 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
682 ret = -EFAULT;
683 goto out;
684 }
671 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
672 ret = btrfs_init_new_device(root, vol_args->name);
673
685 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
686 ret = btrfs_init_new_device(root, vol_args->name);
687
688out:
674 kfree(vol_args);
675 return ret;
676}
677
678static long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
679{
680 struct btrfs_ioctl_vol_args *vol_args;
681 int ret;
682
683 if (!capable(CAP_SYS_ADMIN))
684 return -EPERM;
685
686 if (root->fs_info->sb->s_flags & MS_RDONLY)
687 return -EROFS;
688
689 kfree(vol_args);
690 return ret;
691}
692
693static long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
694{
695 struct btrfs_ioctl_vol_args *vol_args;
696 int ret;
697
698 if (!capable(CAP_SYS_ADMIN))
699 return -EPERM;
700
701 if (root->fs_info->sb->s_flags & MS_RDONLY)
702 return -EROFS;
703
689 vol_args = memdup_user(arg, sizeof(*vol_args));
690 if (IS_ERR(vol_args))
691 return PTR_ERR(vol_args);
704 vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
692
705
706 if (!vol_args)
707 return -ENOMEM;
708
709 if (copy_from_user(vol_args, arg, sizeof(*vol_args))) {
710 ret = -EFAULT;
711 goto out;
712 }
693 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
694 ret = btrfs_rm_device(root, vol_args->name);
695
713 vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
714 ret = btrfs_rm_device(root, vol_args->name);
715
716out:
696 kfree(vol_args);
697 return ret;
698}
699
700static long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
701 u64 off, u64 olen, u64 destoff)
702{
703 struct inode *inode = fdentry(file)->d_inode;

--- 406 unchanged lines hidden ---
717 kfree(vol_args);
718 return ret;
719}
720
721static long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
722 u64 off, u64 olen, u64 destoff)
723{
724 struct inode *inode = fdentry(file)->d_inode;

--- 406 unchanged lines hidden ---