From d26f6bda3f779b102bd2136a317045dbd897f09b Mon Sep 17 00:00:00 2001 From: Li Zefan Date: Mon, 25 Oct 2010 15:11:43 +0800 Subject: [PATCH] --- yaml --- r: 231746 b: refs/heads/master c: 8844355df7f4e091b03cc131e1549631238b397b h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/fs/btrfs/ctree.h | 7 -- trunk/fs/btrfs/extent-tree.c | 3 +- trunk/fs/btrfs/inode.c | 8 -- trunk/fs/btrfs/ioctl.c | 199 +++++++++-------------------------- trunk/fs/btrfs/ioctl.h | 3 - trunk/fs/btrfs/transaction.c | 8 -- trunk/fs/btrfs/transaction.h | 1 - trunk/fs/btrfs/xattr.c | 18 ---- trunk/fs/btrfs/zlib.c | 7 +- 10 files changed, 56 insertions(+), 200 deletions(-) diff --git a/[refs] b/[refs] index 7359fb46adfa..6c749445b1ee 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 26c79f6ba0ccdc4bbc8ef8721406d37e9178e30b +refs/heads/master: 8844355df7f4e091b03cc131e1549631238b397b diff --git a/trunk/fs/btrfs/ctree.h b/trunk/fs/btrfs/ctree.h index 4403e5643d43..af52f6d7a4d8 100644 --- a/trunk/fs/btrfs/ctree.h +++ b/trunk/fs/btrfs/ctree.h @@ -597,8 +597,6 @@ struct btrfs_dir_item { u8 type; } __attribute__ ((__packed__)); -#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0) - struct btrfs_root_item { struct btrfs_inode_item inode; __le64 generation; @@ -1895,11 +1893,6 @@ BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, last_snapshot, 64); -static inline bool btrfs_root_readonly(struct btrfs_root *root) -{ - return root->root_item.flags & BTRFS_ROOT_SUBVOL_RDONLY; -} - /* struct btrfs_super_block */ BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); diff --git a/trunk/fs/btrfs/extent-tree.c b/trunk/fs/btrfs/extent-tree.c index b180efdc8b68..7e5162e5c411 100644 --- a/trunk/fs/btrfs/extent-tree.c +++ b/trunk/fs/btrfs/extent-tree.c @@ -7971,14 +7971,13 @@ static int set_block_group_ro(struct btrfs_block_group_cache *cache) if (sinfo->bytes_used + sinfo->bytes_reserved + sinfo->bytes_pinned + sinfo->bytes_may_use + sinfo->bytes_readonly + - cache->reserved_pinned + num_bytes <= sinfo->total_bytes) { + cache->reserved_pinned + num_bytes < sinfo->total_bytes) { sinfo->bytes_readonly += num_bytes; sinfo->bytes_reserved += cache->reserved_pinned; cache->reserved_pinned = 0; cache->ro = 1; ret = 0; } - spin_unlock(&cache->lock); spin_unlock(&sinfo->lock); return ret; diff --git a/trunk/fs/btrfs/inode.c b/trunk/fs/btrfs/inode.c index 956f1eb913b1..5f9194438f7c 100644 --- a/trunk/fs/btrfs/inode.c +++ b/trunk/fs/btrfs/inode.c @@ -3671,12 +3671,8 @@ static int btrfs_setattr_size(struct inode *inode, struct iattr *attr) static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) { struct inode *inode = dentry->d_inode; - struct btrfs_root *root = BTRFS_I(inode)->root; int err; - if (btrfs_root_readonly(root)) - return -EROFS; - err = inode_change_ok(inode, attr); if (err) return err; @@ -7210,10 +7206,6 @@ static int btrfs_set_page_dirty(struct page *page) static int btrfs_permission(struct inode *inode, int mask) { - struct btrfs_root *root = BTRFS_I(inode)->root; - - if (btrfs_root_readonly(root) && (mask & MAY_WRITE)) - return -EROFS; if ((BTRFS_I(inode)->flags & BTRFS_INODE_READONLY) && (mask & MAY_WRITE)) return -EACCES; return generic_permission(inode, mask, btrfs_check_acl); diff --git a/trunk/fs/btrfs/ioctl.c b/trunk/fs/btrfs/ioctl.c index ad1983524f97..f87552a1d7ea 100644 --- a/trunk/fs/btrfs/ioctl.c +++ b/trunk/fs/btrfs/ioctl.c @@ -147,9 +147,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) unsigned int flags, oldflags; int ret; - if (btrfs_root_readonly(root)) - return -EROFS; - if (copy_from_user(&flags, arg, sizeof(flags))) return -EFAULT; @@ -363,8 +360,7 @@ static noinline int create_subvol(struct btrfs_root *root, } static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, - char *name, int namelen, u64 *async_transid, - bool readonly) + char *name, int namelen, u64 *async_transid) { struct inode *inode; struct dentry *parent; @@ -382,7 +378,6 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, btrfs_init_block_rsv(&pending_snapshot->block_rsv); pending_snapshot->dentry = dentry; pending_snapshot->root = root; - pending_snapshot->readonly = readonly; trans = btrfs_start_transaction(root->fs_info->extent_root, 5); if (IS_ERR(trans)) { @@ -514,7 +509,7 @@ static inline int btrfs_may_create(struct inode *dir, struct dentry *child) static noinline int btrfs_mksubvol(struct path *parent, char *name, int namelen, struct btrfs_root *snap_src, - u64 *async_transid, bool readonly) + u64 *async_transid) { struct inode *dir = parent->dentry->d_inode; struct dentry *dentry; @@ -546,7 +541,7 @@ static noinline int btrfs_mksubvol(struct path *parent, if (snap_src) { error = create_snapshot(snap_src, dentry, - name, namelen, async_transid, readonly); + name, namelen, async_transid); } else { error = create_subvol(BTRFS_I(dir)->root, dentry, name, namelen, async_transid); @@ -906,8 +901,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file, char *name, unsigned long fd, int subvol, - u64 *transid, - bool readonly) + u64 *transid) { struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root; struct file *src_file; @@ -925,7 +919,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file, if (subvol) { ret = btrfs_mksubvol(&file->f_path, name, namelen, - NULL, transid, readonly); + NULL, transid); } else { struct inode *src_inode; src_file = fget(fd); @@ -944,7 +938,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file, } ret = btrfs_mksubvol(&file->f_path, name, namelen, BTRFS_I(src_inode)->root, - transid, readonly); + transid); fput(src_file); } out: @@ -952,139 +946,58 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file, } static noinline int btrfs_ioctl_snap_create(struct file *file, - void __user *arg, int subvol) + void __user *arg, int subvol, + int v2) { - struct btrfs_ioctl_vol_args *vol_args; + struct btrfs_ioctl_vol_args *vol_args = NULL; + struct btrfs_ioctl_vol_args_v2 *vol_args_v2 = NULL; + char *name; + u64 fd; int ret; - vol_args = memdup_user(arg, sizeof(*vol_args)); - if (IS_ERR(vol_args)) - return PTR_ERR(vol_args); - vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; - - ret = btrfs_ioctl_snap_create_transid(file, vol_args->name, - vol_args->fd, subvol, - NULL, false); - - kfree(vol_args); - return ret; -} + if (v2) { + u64 transid = 0; + u64 *ptr = NULL; -static noinline int btrfs_ioctl_snap_create_v2(struct file *file, - void __user *arg, int subvol) -{ - struct btrfs_ioctl_vol_args_v2 *vol_args; - int ret; - u64 transid = 0; - u64 *ptr = NULL; - bool readonly = false; + vol_args_v2 = memdup_user(arg, sizeof(*vol_args_v2)); + if (IS_ERR(vol_args_v2)) + return PTR_ERR(vol_args_v2); - vol_args = memdup_user(arg, sizeof(*vol_args)); - if (IS_ERR(vol_args)) - return PTR_ERR(vol_args); - vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0'; + if (vol_args_v2->flags & ~BTRFS_SUBVOL_CREATE_ASYNC) { + ret = -EINVAL; + goto out; + } - if (vol_args->flags & - ~(BTRFS_SUBVOL_CREATE_ASYNC | BTRFS_SUBVOL_RDONLY)) { - ret = -EOPNOTSUPP; - goto out; - } + name = vol_args_v2->name; + fd = vol_args_v2->fd; + vol_args_v2->name[BTRFS_SUBVOL_NAME_MAX] = '\0'; - if (vol_args->flags & BTRFS_SUBVOL_CREATE_ASYNC) - ptr = &transid; - if (vol_args->flags & BTRFS_SUBVOL_RDONLY) - readonly = true; + if (vol_args_v2->flags & BTRFS_SUBVOL_CREATE_ASYNC) + ptr = &transid; - ret = btrfs_ioctl_snap_create_transid(file, vol_args->name, - vol_args->fd, subvol, - ptr, readonly); + ret = btrfs_ioctl_snap_create_transid(file, name, fd, + subvol, ptr); - if (ret == 0 && ptr && - copy_to_user(arg + - offsetof(struct btrfs_ioctl_vol_args_v2, - transid), ptr, sizeof(*ptr))) - ret = -EFAULT; + if (ret == 0 && ptr && + copy_to_user(arg + + offsetof(struct btrfs_ioctl_vol_args_v2, + transid), ptr, sizeof(*ptr))) + ret = -EFAULT; + } else { + vol_args = memdup_user(arg, sizeof(*vol_args)); + if (IS_ERR(vol_args)) + return PTR_ERR(vol_args); + name = vol_args->name; + fd = vol_args->fd; + vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; + + ret = btrfs_ioctl_snap_create_transid(file, name, fd, + subvol, NULL); + } out: kfree(vol_args); - return ret; -} - -static noinline int btrfs_ioctl_subvol_getflags(struct file *file, - void __user *arg) -{ - struct inode *inode = fdentry(file)->d_inode; - struct btrfs_root *root = BTRFS_I(inode)->root; - int ret = 0; - u64 flags = 0; - - if (inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) - return -EINVAL; - - down_read(&root->fs_info->subvol_sem); - if (btrfs_root_readonly(root)) - flags |= BTRFS_SUBVOL_RDONLY; - up_read(&root->fs_info->subvol_sem); - - if (copy_to_user(arg, &flags, sizeof(flags))) - ret = -EFAULT; - - return ret; -} - -static noinline int btrfs_ioctl_subvol_setflags(struct file *file, - void __user *arg) -{ - struct inode *inode = fdentry(file)->d_inode; - struct btrfs_root *root = BTRFS_I(inode)->root; - struct btrfs_trans_handle *trans; - u64 root_flags; - u64 flags; - int ret = 0; - - if (root->fs_info->sb->s_flags & MS_RDONLY) - return -EROFS; - - if (inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) - return -EINVAL; - - if (copy_from_user(&flags, arg, sizeof(flags))) - return -EFAULT; - - if (flags & ~BTRFS_SUBVOL_CREATE_ASYNC) - return -EINVAL; - - if (flags & ~BTRFS_SUBVOL_RDONLY) - return -EOPNOTSUPP; - - down_write(&root->fs_info->subvol_sem); - - /* nothing to do */ - if (!!(flags & BTRFS_SUBVOL_RDONLY) == btrfs_root_readonly(root)) - goto out; - - root_flags = btrfs_root_flags(&root->root_item); - if (flags & BTRFS_SUBVOL_RDONLY) - btrfs_set_root_flags(&root->root_item, - root_flags | BTRFS_ROOT_SUBVOL_RDONLY); - else - btrfs_set_root_flags(&root->root_item, - root_flags & ~BTRFS_ROOT_SUBVOL_RDONLY); - - trans = btrfs_start_transaction(root, 1); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - goto out_reset; - } + kfree(vol_args_v2); - ret = btrfs_update_root(trans, root, - &root->root_key, &root->root_item); - - btrfs_commit_transaction(trans, root); -out_reset: - if (ret) - btrfs_set_root_flags(&root->root_item, root_flags); -out: - up_write(&root->fs_info->subvol_sem); return ret; } @@ -1596,9 +1509,6 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) struct btrfs_ioctl_defrag_range_args *range; int ret; - if (btrfs_root_readonly(root)) - return -EROFS; - ret = mnt_want_write(file->f_path.mnt); if (ret) return ret; @@ -1727,9 +1637,6 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, if (!(file->f_mode & FMODE_WRITE) || (file->f_flags & O_APPEND)) return -EINVAL; - if (btrfs_root_readonly(root)) - return -EROFS; - ret = mnt_want_write(file->f_path.mnt); if (ret) return ret; @@ -2051,10 +1958,6 @@ static long btrfs_ioctl_trans_start(struct file *file) if (file->private_data) goto out; - ret = -EROFS; - if (btrfs_root_readonly(root)) - goto out; - ret = mnt_want_write(file->f_path.mnt); if (ret) goto out; @@ -2354,17 +2257,13 @@ long btrfs_ioctl(struct file *file, unsigned int case FS_IOC_GETVERSION: return btrfs_ioctl_getversion(file, argp); case BTRFS_IOC_SNAP_CREATE: - return btrfs_ioctl_snap_create(file, argp, 0); + return btrfs_ioctl_snap_create(file, argp, 0, 0); case BTRFS_IOC_SNAP_CREATE_V2: - return btrfs_ioctl_snap_create_v2(file, argp, 0); + return btrfs_ioctl_snap_create(file, argp, 0, 1); case BTRFS_IOC_SUBVOL_CREATE: - return btrfs_ioctl_snap_create(file, argp, 1); + return btrfs_ioctl_snap_create(file, argp, 1, 0); case BTRFS_IOC_SNAP_DESTROY: return btrfs_ioctl_snap_destroy(file, argp); - case BTRFS_IOC_SUBVOL_GETFLAGS: - return btrfs_ioctl_subvol_getflags(file, argp); - case BTRFS_IOC_SUBVOL_SETFLAGS: - return btrfs_ioctl_subvol_setflags(file, argp); case BTRFS_IOC_DEFAULT_SUBVOL: return btrfs_ioctl_default_subvol(file, argp); case BTRFS_IOC_DEFRAG: diff --git a/trunk/fs/btrfs/ioctl.h b/trunk/fs/btrfs/ioctl.h index 1223223351fa..c344d12c646b 100644 --- a/trunk/fs/btrfs/ioctl.h +++ b/trunk/fs/btrfs/ioctl.h @@ -31,7 +31,6 @@ struct btrfs_ioctl_vol_args { }; #define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) -#define BTRFS_SUBVOL_RDONLY (1ULL << 1) #define BTRFS_SUBVOL_NAME_MAX 4039 struct btrfs_ioctl_vol_args_v2 { @@ -194,6 +193,4 @@ struct btrfs_ioctl_space_args { #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ struct btrfs_ioctl_vol_args_v2) -#define BTRFS_IOC_SUBVOL_GETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 25, __u64) -#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64) #endif diff --git a/trunk/fs/btrfs/transaction.c b/trunk/fs/btrfs/transaction.c index 29e30d832ec9..f50e931fc217 100644 --- a/trunk/fs/btrfs/transaction.c +++ b/trunk/fs/btrfs/transaction.c @@ -910,7 +910,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, u64 to_reserve = 0; u64 index = 0; u64 objectid; - u64 root_flags; new_root_item = kmalloc(sizeof(*new_root_item), GFP_NOFS); if (!new_root_item) { @@ -968,13 +967,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, btrfs_set_root_last_snapshot(&root->root_item, trans->transid); memcpy(new_root_item, &root->root_item, sizeof(*new_root_item)); - root_flags = btrfs_root_flags(new_root_item); - if (pending->readonly) - root_flags |= BTRFS_ROOT_SUBVOL_RDONLY; - else - root_flags &= ~BTRFS_ROOT_SUBVOL_RDONLY; - btrfs_set_root_flags(new_root_item, root_flags); - old = btrfs_lock_root_node(root); btrfs_cow_block(trans, root, old, NULL, 0, &old); btrfs_set_lock_blocking(old); diff --git a/trunk/fs/btrfs/transaction.h b/trunk/fs/btrfs/transaction.h index 229a594cacd5..f104b57ad4ef 100644 --- a/trunk/fs/btrfs/transaction.h +++ b/trunk/fs/btrfs/transaction.h @@ -62,7 +62,6 @@ struct btrfs_pending_snapshot { struct btrfs_block_rsv block_rsv; /* extra metadata reseration for relocation */ int error; - bool readonly; struct list_head list; }; diff --git a/trunk/fs/btrfs/xattr.c b/trunk/fs/btrfs/xattr.c index a5776531dc2b..698fdd2c739c 100644 --- a/trunk/fs/btrfs/xattr.c +++ b/trunk/fs/btrfs/xattr.c @@ -316,15 +316,6 @@ ssize_t btrfs_getxattr(struct dentry *dentry, const char *name, int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) { - struct btrfs_root *root = BTRFS_I(dentry->d_inode)->root; - - /* - * The permission on security.* and system.* is not checked - * in permission(). - */ - if (btrfs_root_readonly(root)) - return -EROFS; - /* * If this is a request for a synthetic attribute in the system.* * namespace use the generic infrastructure to resolve a handler @@ -345,15 +336,6 @@ int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value, int btrfs_removexattr(struct dentry *dentry, const char *name) { - struct btrfs_root *root = BTRFS_I(dentry->d_inode)->root; - - /* - * The permission on security.* and system.* is not checked - * in permission(). - */ - if (btrfs_root_readonly(root)) - return -EROFS; - /* * If this is a request for a synthetic attribute in the system.* * namespace use the generic infrastructure to resolve a handler diff --git a/trunk/fs/btrfs/zlib.c b/trunk/fs/btrfs/zlib.c index b9cd5445f71c..e5b8b22e07d6 100644 --- a/trunk/fs/btrfs/zlib.c +++ b/trunk/fs/btrfs/zlib.c @@ -75,16 +75,19 @@ static struct workspace *find_zlib_workspace(void) return workspace; } - spin_unlock(&workspace_lock); if (atomic_read(&alloc_workspace) > cpus) { DEFINE_WAIT(wait); + + spin_unlock(&workspace_lock); prepare_to_wait(&workspace_wait, &wait, TASK_UNINTERRUPTIBLE); - if (atomic_read(&alloc_workspace) > cpus) + if (atomic_read(&alloc_workspace) > cpus && !num_workspace) schedule(); finish_wait(&workspace_wait, &wait); goto again; } atomic_inc(&alloc_workspace); + spin_unlock(&workspace_lock); + workspace = kzalloc(sizeof(*workspace), GFP_NOFS); if (!workspace) { ret = -ENOMEM;