aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2011-05-23 06:30:52 -0400
committerChris Mason <chris.mason@oracle.com>2011-05-23 06:30:52 -0400
commit712673339a0d085358fd1cd3a6477cc7979bb69f (patch)
treeb2e268685e3cbba19a4adb2a47d853e4e461fcfc /fs/btrfs/ioctl.c
parentaa2dfb372a2a647beedac163ce6f8b0fcbefac29 (diff)
parent8628764e1a5e1998a42b9713e9edea7753653d01 (diff)
Merge branch 'for-chris' of git://git.kernel.org/pub/scm/linux/kernel/git/arne/btrfs-unstable-arne into inode_numbers
Conflicts: fs/btrfs/Makefile fs/btrfs/ctree.h fs/btrfs/volumes.h Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ed8c055ab70f..e0a061db4353 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1809,6 +1809,75 @@ static long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
1809 return ret; 1809 return ret;
1810} 1810}
1811 1811
1812static long btrfs_ioctl_fs_info(struct btrfs_root *root, void __user *arg)
1813{
1814 struct btrfs_ioctl_fs_info_args fi_args;
1815 struct btrfs_device *device;
1816 struct btrfs_device *next;
1817 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
1818
1819 if (!capable(CAP_SYS_ADMIN))
1820 return -EPERM;
1821
1822 fi_args.num_devices = fs_devices->num_devices;
1823 fi_args.max_id = 0;
1824 memcpy(&fi_args.fsid, root->fs_info->fsid, sizeof(fi_args.fsid));
1825
1826 mutex_lock(&fs_devices->device_list_mutex);
1827 list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
1828 if (device->devid > fi_args.max_id)
1829 fi_args.max_id = device->devid;
1830 }
1831 mutex_unlock(&fs_devices->device_list_mutex);
1832
1833 if (copy_to_user(arg, &fi_args, sizeof(fi_args)))
1834 return -EFAULT;
1835
1836 return 0;
1837}
1838
1839static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
1840{
1841 struct btrfs_ioctl_dev_info_args *di_args;
1842 struct btrfs_device *dev;
1843 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
1844 int ret = 0;
1845 char *s_uuid = NULL;
1846 char empty_uuid[BTRFS_UUID_SIZE] = {0};
1847
1848 if (!capable(CAP_SYS_ADMIN))
1849 return -EPERM;
1850
1851 di_args = memdup_user(arg, sizeof(*di_args));
1852 if (IS_ERR(di_args))
1853 return PTR_ERR(di_args);
1854
1855 if (memcmp(empty_uuid, di_args->uuid, BTRFS_UUID_SIZE) != 0)
1856 s_uuid = di_args->uuid;
1857
1858 mutex_lock(&fs_devices->device_list_mutex);
1859 dev = btrfs_find_device(root, di_args->devid, s_uuid, NULL);
1860 mutex_unlock(&fs_devices->device_list_mutex);
1861
1862 if (!dev) {
1863 ret = -ENODEV;
1864 goto out;
1865 }
1866
1867 di_args->devid = dev->devid;
1868 di_args->bytes_used = dev->bytes_used;
1869 di_args->total_bytes = dev->total_bytes;
1870 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
1871 strncpy(di_args->path, dev->name, sizeof(di_args->path));
1872
1873out:
1874 if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))
1875 ret = -EFAULT;
1876
1877 kfree(di_args);
1878 return ret;
1879}
1880
1812static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, 1881static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
1813 u64 off, u64 olen, u64 destoff) 1882 u64 off, u64 olen, u64 destoff)
1814{ 1883{
@@ -2471,6 +2540,58 @@ static noinline long btrfs_ioctl_wait_sync(struct file *file, void __user *argp)
2471 return btrfs_wait_for_commit(root, transid); 2540 return btrfs_wait_for_commit(root, transid);
2472} 2541}
2473 2542
2543static long btrfs_ioctl_scrub(struct btrfs_root *root, void __user *arg)
2544{
2545 int ret;
2546 struct btrfs_ioctl_scrub_args *sa;
2547
2548 if (!capable(CAP_SYS_ADMIN))
2549 return -EPERM;
2550
2551 sa = memdup_user(arg, sizeof(*sa));
2552 if (IS_ERR(sa))
2553 return PTR_ERR(sa);
2554
2555 ret = btrfs_scrub_dev(root, sa->devid, sa->start, sa->end,
2556 &sa->progress, sa->flags & BTRFS_SCRUB_READONLY);
2557
2558 if (copy_to_user(arg, sa, sizeof(*sa)))
2559 ret = -EFAULT;
2560
2561 kfree(sa);
2562 return ret;
2563}
2564
2565static long btrfs_ioctl_scrub_cancel(struct btrfs_root *root, void __user *arg)
2566{
2567 if (!capable(CAP_SYS_ADMIN))
2568 return -EPERM;
2569
2570 return btrfs_scrub_cancel(root);
2571}
2572
2573static long btrfs_ioctl_scrub_progress(struct btrfs_root *root,
2574 void __user *arg)
2575{
2576 struct btrfs_ioctl_scrub_args *sa;
2577 int ret;
2578
2579 if (!capable(CAP_SYS_ADMIN))
2580 return -EPERM;
2581
2582 sa = memdup_user(arg, sizeof(*sa));
2583 if (IS_ERR(sa))
2584 return PTR_ERR(sa);
2585
2586 ret = btrfs_scrub_progress(root, sa->devid, &sa->progress);
2587
2588 if (copy_to_user(arg, sa, sizeof(*sa)))
2589 ret = -EFAULT;
2590
2591 kfree(sa);
2592 return ret;
2593}
2594
2474long btrfs_ioctl(struct file *file, unsigned int 2595long btrfs_ioctl(struct file *file, unsigned int
2475 cmd, unsigned long arg) 2596 cmd, unsigned long arg)
2476{ 2597{
@@ -2510,6 +2631,10 @@ long btrfs_ioctl(struct file *file, unsigned int
2510 return btrfs_ioctl_add_dev(root, argp); 2631 return btrfs_ioctl_add_dev(root, argp);
2511 case BTRFS_IOC_RM_DEV: 2632 case BTRFS_IOC_RM_DEV:
2512 return btrfs_ioctl_rm_dev(root, argp); 2633 return btrfs_ioctl_rm_dev(root, argp);
2634 case BTRFS_IOC_FS_INFO:
2635 return btrfs_ioctl_fs_info(root, argp);
2636 case BTRFS_IOC_DEV_INFO:
2637 return btrfs_ioctl_dev_info(root, argp);
2513 case BTRFS_IOC_BALANCE: 2638 case BTRFS_IOC_BALANCE:
2514 return btrfs_balance(root->fs_info->dev_root); 2639 return btrfs_balance(root->fs_info->dev_root);
2515 case BTRFS_IOC_CLONE: 2640 case BTRFS_IOC_CLONE:
@@ -2533,6 +2658,12 @@ long btrfs_ioctl(struct file *file, unsigned int
2533 return btrfs_ioctl_start_sync(file, argp); 2658 return btrfs_ioctl_start_sync(file, argp);
2534 case BTRFS_IOC_WAIT_SYNC: 2659 case BTRFS_IOC_WAIT_SYNC:
2535 return btrfs_ioctl_wait_sync(file, argp); 2660 return btrfs_ioctl_wait_sync(file, argp);
2661 case BTRFS_IOC_SCRUB:
2662 return btrfs_ioctl_scrub(root, argp);
2663 case BTRFS_IOC_SCRUB_CANCEL:
2664 return btrfs_ioctl_scrub_cancel(root, argp);
2665 case BTRFS_IOC_SCRUB_PROGRESS:
2666 return btrfs_ioctl_scrub_progress(root, argp);
2536 } 2667 }
2537 2668
2538 return -ENOTTY; 2669 return -ENOTTY;