Add ioctl to set per file 'compress' flag
PATCH 1/3 Add ioctl to set per file 'compress' flag
An ioctl is needed to set compress flag (i.e. clear BTRFS_INODE_NOCOMPRESS flag) on per file basis. This patch adds that.
Introduces a generic function to be used by subsequent patches.
Signed-off-by Amit Gud <[email protected]>
fs/btrfs/ioctl.c +50 -0
@@ -1240,6 +1240,54 @@ out:return ret; } +/* Ioctl function to set or clear a flag on the file. */ +static long btrfs_ioctl_inode_flag (struct file *file, +u32 flag,int set) +{ +struct inode *inode = file->f_path.dentry->d_inode; +struct btrfs_inode *ip =BTRFS_I (inode); +struct btrfs_root *root = ip->root; +struct btrfs_trans_handle *trans; +int ret; + +if (!is_owner_or_cap (inode)) +return -EACCES ; + +mutex_lock (&inode->i_mutex); + +/* Bail out if already set / cleared. */ +if (set) { +if (ip->flags & flag) + goto out_unlock; + }else { +if (!(ip->flags & flag)) + goto out_unlock; + } + + ret =mnt_want_write (file->f_path.mnt); +if (ret) + goto out_unlock; + +if (set) + ip->flags |= flag; +else + ip->flags &= ~flag; + + trans =btrfs_join_transaction (root,1 ); +BUG_ON (!trans); + + ret =btrfs_update_inode (trans, root, inode); +BUG_ON (ret); + + inode->i_ctime =CURRENT_TIME ; +btrfs_end_transaction (trans, root); + +mnt_drop_write (file->f_path.mnt); + out_unlock: +mutex_unlock (&inode->i_mutex); +return 0 ; +} +long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -1278,6 +1326,8 @@ long btrfs_ioctl(struct file *file, unsicase BTRFS_IOC_SYNC :btrfs_sync_fs (file->f_dentry->d_sb,1 );return 0 ; +case BTRFS_IOC_COMPRESS : +return btrfs_ioctl_inode_flag (file,BTRFS_INODE_NOCOMPRESS ,0 ); }return -ENOTTY ;
fs/btrfs/ioctl.h +2 -0
@@ -65,5 +65,7 @@ struct btrfs_ioctl_clone_range_args {#define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_COMPRESS _IOW(BTRFS_IOCTL_MAGIC, 15, \ + struct btrfs_ioctl_vol_args)#endif
Signature · 2 lines
May the source be with you. http://www.cis.ksu.edu/~gud
Quoted 5 lines · Amit Gud
An ioctl is needed to set compress flag (i.e. clear
BTRFS_INODE_NOCOMPRESSflag) on per file basis. This patch adds that.Introduces a generic function to be used by subsequent patches.
It's probably a better idea to fit these into the existing per-inode flags. This will need some coordination with Ted on how to re-use the existing compression flags if at all and where to fit the new flags in the numerical namespaces.