Commit 5c57b8b6 authored by David Sterba's avatar David Sterba

btrfs: unify naming of flags variables for SETFLAGS and XFLAGS

* The simple 'flags' refer to the btrfs inode
* ... that's in 'binode
* the FS_*_FL variables are 'fsflags'
* the old copies of the variable are prefixed by 'old_'
* Struct inode flags contain 'i_flags'.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 025f2121
...@@ -140,18 +140,18 @@ static unsigned int btrfs_inode_flags_to_fsflags(unsigned int flags) ...@@ -140,18 +140,18 @@ static unsigned int btrfs_inode_flags_to_fsflags(unsigned int flags)
*/ */
void btrfs_sync_inode_flags_to_i_flags(struct inode *inode) void btrfs_sync_inode_flags_to_i_flags(struct inode *inode)
{ {
struct btrfs_inode *ip = BTRFS_I(inode); struct btrfs_inode *binode = BTRFS_I(inode);
unsigned int new_fl = 0; unsigned int new_fl = 0;
if (ip->flags & BTRFS_INODE_SYNC) if (binode->flags & BTRFS_INODE_SYNC)
new_fl |= S_SYNC; new_fl |= S_SYNC;
if (ip->flags & BTRFS_INODE_IMMUTABLE) if (binode->flags & BTRFS_INODE_IMMUTABLE)
new_fl |= S_IMMUTABLE; new_fl |= S_IMMUTABLE;
if (ip->flags & BTRFS_INODE_APPEND) if (binode->flags & BTRFS_INODE_APPEND)
new_fl |= S_APPEND; new_fl |= S_APPEND;
if (ip->flags & BTRFS_INODE_NOATIME) if (binode->flags & BTRFS_INODE_NOATIME)
new_fl |= S_NOATIME; new_fl |= S_NOATIME;
if (ip->flags & BTRFS_INODE_DIRSYNC) if (binode->flags & BTRFS_INODE_DIRSYNC)
new_fl |= S_DIRSYNC; new_fl |= S_DIRSYNC;
set_mask_bits(&inode->i_flags, set_mask_bits(&inode->i_flags,
...@@ -161,8 +161,8 @@ void btrfs_sync_inode_flags_to_i_flags(struct inode *inode) ...@@ -161,8 +161,8 @@ void btrfs_sync_inode_flags_to_i_flags(struct inode *inode)
static int btrfs_ioctl_getflags(struct file *file, void __user *arg) static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
{ {
struct btrfs_inode *ip = BTRFS_I(file_inode(file)); struct btrfs_inode *binode = BTRFS_I(file_inode(file));
unsigned int flags = btrfs_inode_flags_to_fsflags(ip->flags); unsigned int flags = btrfs_inode_flags_to_fsflags(binode->flags);
if (copy_to_user(arg, &flags, sizeof(flags))) if (copy_to_user(arg, &flags, sizeof(flags)))
return -EFAULT; return -EFAULT;
...@@ -189,13 +189,13 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -189,13 +189,13 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
struct btrfs_inode *ip = BTRFS_I(inode); struct btrfs_inode *binode = BTRFS_I(inode);
struct btrfs_root *root = ip->root; struct btrfs_root *root = binode->root;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
unsigned int flags, oldflags; unsigned int fsflags, old_fsflags;
int ret; int ret;
u64 ip_oldflags; u64 old_flags;
unsigned int i_oldflags; unsigned int old_i_flags;
umode_t mode; umode_t mode;
if (!inode_owner_or_capable(inode)) if (!inode_owner_or_capable(inode))
...@@ -204,10 +204,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -204,10 +204,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
if (btrfs_root_readonly(root)) if (btrfs_root_readonly(root))
return -EROFS; return -EROFS;
if (copy_from_user(&flags, arg, sizeof(flags))) if (copy_from_user(&fsflags, arg, sizeof(fsflags)))
return -EFAULT; return -EFAULT;
ret = check_fsflags(flags); ret = check_fsflags(fsflags);
if (ret) if (ret)
return ret; return ret;
...@@ -217,44 +217,44 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -217,44 +217,44 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
inode_lock(inode); inode_lock(inode);
ip_oldflags = ip->flags; old_flags = binode->flags;
i_oldflags = inode->i_flags; old_i_flags = inode->i_flags;
mode = inode->i_mode; mode = inode->i_mode;
flags = btrfs_mask_fsflags_for_type(inode, flags); fsflags = btrfs_mask_fsflags_for_type(inode, fsflags);
oldflags = btrfs_inode_flags_to_fsflags(ip->flags); old_fsflags = btrfs_inode_flags_to_fsflags(binode->flags);
if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) { if ((fsflags ^ old_fsflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
if (!capable(CAP_LINUX_IMMUTABLE)) { if (!capable(CAP_LINUX_IMMUTABLE)) {
ret = -EPERM; ret = -EPERM;
goto out_unlock; goto out_unlock;
} }
} }
if (flags & FS_SYNC_FL) if (fsflags & FS_SYNC_FL)
ip->flags |= BTRFS_INODE_SYNC; binode->flags |= BTRFS_INODE_SYNC;
else else
ip->flags &= ~BTRFS_INODE_SYNC; binode->flags &= ~BTRFS_INODE_SYNC;
if (flags & FS_IMMUTABLE_FL) if (fsflags & FS_IMMUTABLE_FL)
ip->flags |= BTRFS_INODE_IMMUTABLE; binode->flags |= BTRFS_INODE_IMMUTABLE;
else else
ip->flags &= ~BTRFS_INODE_IMMUTABLE; binode->flags &= ~BTRFS_INODE_IMMUTABLE;
if (flags & FS_APPEND_FL) if (fsflags & FS_APPEND_FL)
ip->flags |= BTRFS_INODE_APPEND; binode->flags |= BTRFS_INODE_APPEND;
else else
ip->flags &= ~BTRFS_INODE_APPEND; binode->flags &= ~BTRFS_INODE_APPEND;
if (flags & FS_NODUMP_FL) if (fsflags & FS_NODUMP_FL)
ip->flags |= BTRFS_INODE_NODUMP; binode->flags |= BTRFS_INODE_NODUMP;
else else
ip->flags &= ~BTRFS_INODE_NODUMP; binode->flags &= ~BTRFS_INODE_NODUMP;
if (flags & FS_NOATIME_FL) if (fsflags & FS_NOATIME_FL)
ip->flags |= BTRFS_INODE_NOATIME; binode->flags |= BTRFS_INODE_NOATIME;
else else
ip->flags &= ~BTRFS_INODE_NOATIME; binode->flags &= ~BTRFS_INODE_NOATIME;
if (flags & FS_DIRSYNC_FL) if (fsflags & FS_DIRSYNC_FL)
ip->flags |= BTRFS_INODE_DIRSYNC; binode->flags |= BTRFS_INODE_DIRSYNC;
else else
ip->flags &= ~BTRFS_INODE_DIRSYNC; binode->flags &= ~BTRFS_INODE_DIRSYNC;
if (flags & FS_NOCOW_FL) { if (fsflags & FS_NOCOW_FL) {
if (S_ISREG(mode)) { if (S_ISREG(mode)) {
/* /*
* It's safe to turn csums off here, no extents exist. * It's safe to turn csums off here, no extents exist.
...@@ -262,10 +262,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -262,10 +262,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
* status of the file and will not set it. * status of the file and will not set it.
*/ */
if (inode->i_size == 0) if (inode->i_size == 0)
ip->flags |= BTRFS_INODE_NODATACOW binode->flags |= BTRFS_INODE_NODATACOW
| BTRFS_INODE_NODATASUM; | BTRFS_INODE_NODATASUM;
} else { } else {
ip->flags |= BTRFS_INODE_NODATACOW; binode->flags |= BTRFS_INODE_NODATACOW;
} }
} else { } else {
/* /*
...@@ -273,10 +273,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -273,10 +273,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
*/ */
if (S_ISREG(mode)) { if (S_ISREG(mode)) {
if (inode->i_size == 0) if (inode->i_size == 0)
ip->flags &= ~(BTRFS_INODE_NODATACOW binode->flags &= ~(BTRFS_INODE_NODATACOW
| BTRFS_INODE_NODATASUM); | BTRFS_INODE_NODATASUM);
} else { } else {
ip->flags &= ~BTRFS_INODE_NODATACOW; binode->flags &= ~BTRFS_INODE_NODATACOW;
} }
} }
...@@ -285,18 +285,18 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -285,18 +285,18 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
* flag may be changed automatically if compression code won't make * flag may be changed automatically if compression code won't make
* things smaller. * things smaller.
*/ */
if (flags & FS_NOCOMP_FL) { if (fsflags & FS_NOCOMP_FL) {
ip->flags &= ~BTRFS_INODE_COMPRESS; binode->flags &= ~BTRFS_INODE_COMPRESS;
ip->flags |= BTRFS_INODE_NOCOMPRESS; binode->flags |= BTRFS_INODE_NOCOMPRESS;
ret = btrfs_set_prop(inode, "btrfs.compression", NULL, 0, 0); ret = btrfs_set_prop(inode, "btrfs.compression", NULL, 0, 0);
if (ret && ret != -ENODATA) if (ret && ret != -ENODATA)
goto out_drop; goto out_drop;
} else if (flags & FS_COMPR_FL) { } else if (fsflags & FS_COMPR_FL) {
const char *comp; const char *comp;
ip->flags |= BTRFS_INODE_COMPRESS; binode->flags |= BTRFS_INODE_COMPRESS;
ip->flags &= ~BTRFS_INODE_NOCOMPRESS; binode->flags &= ~BTRFS_INODE_NOCOMPRESS;
comp = btrfs_compress_type2str(fs_info->compress_type); comp = btrfs_compress_type2str(fs_info->compress_type);
if (!comp || comp[0] == 0) if (!comp || comp[0] == 0)
...@@ -311,7 +311,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -311,7 +311,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
ret = btrfs_set_prop(inode, "btrfs.compression", NULL, 0, 0); ret = btrfs_set_prop(inode, "btrfs.compression", NULL, 0, 0);
if (ret && ret != -ENODATA) if (ret && ret != -ENODATA)
goto out_drop; goto out_drop;
ip->flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS); binode->flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
} }
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
...@@ -328,8 +328,8 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -328,8 +328,8 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
btrfs_end_transaction(trans); btrfs_end_transaction(trans);
out_drop: out_drop:
if (ret) { if (ret) {
ip->flags = ip_oldflags; binode->flags = old_flags;
inode->i_flags = i_oldflags; inode->i_flags = old_i_flags;
} }
out_unlock: out_unlock:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment