Btrfs: mount ro and remount support
[linux-2.6-block.git] / fs / btrfs / ioctl.c
index 4d7cc7c504d02680e28c959d8a1982e43bb49139..52863cebd5942ace87f193519c85dc03134bc695 100644 (file)
@@ -378,6 +378,9 @@ static int btrfs_ioctl_resize(struct btrfs_root *root, void __user *arg)
        int namelen;
        int mod = 0;
 
+       if (root->fs_info->sb->s_flags & MS_RDONLY)
+               return -EROFS;
+
        vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
 
        if (!vol_args)
@@ -478,6 +481,9 @@ static noinline int btrfs_ioctl_snap_create(struct file *file,
        int namelen;
        int ret;
 
+       if (root->fs_info->sb->s_flags & MS_RDONLY)
+               return -EROFS;
+
        vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
 
        if (!vol_args)
@@ -534,6 +540,11 @@ static int btrfs_ioctl_defrag(struct file *file)
 {
        struct inode *inode = fdentry(file)->d_inode;
        struct btrfs_root *root = BTRFS_I(inode)->root;
+       int ret;
+
+       ret = mnt_want_write(file->f_path.mnt);
+       if (ret)
+               return ret;
 
        switch (inode->i_mode & S_IFMT) {
        case S_IFDIR:
@@ -575,6 +586,9 @@ long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
        struct btrfs_ioctl_vol_args *vol_args;
        int ret;
 
+       if (root->fs_info->sb->s_flags & MS_RDONLY)
+               return -EROFS;
+
        vol_args = kmalloc(sizeof(*vol_args), GFP_NOFS);
 
        if (!vol_args)
@@ -621,6 +635,10 @@ long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, u64 off,
         *   they don't overlap)?
         */
 
+       ret = mnt_want_write(file->f_path.mnt);
+       if (ret)
+               return ret;
+
        src_file = fget(srcfd);
        if (!src_file)
                return -EBADF;
@@ -958,6 +976,10 @@ long btrfs_ioctl_trans_start(struct file *file)
                goto out;
        }
 
+       ret = mnt_want_write(file->f_path.mnt);
+       if (ret)
+               goto out;
+
        mutex_lock(&root->fs_info->trans_mutex);
        root->fs_info->open_ioctl_trans++;
        mutex_unlock(&root->fs_info->trans_mutex);