f2fs: add resgid and resuid to reserve root blocks
Jaegeuk Kim
maintainerPATCH 1/1 f2fs: add resgid and resuid to reserve root blocks
This patch adds mount options to reserve some blocks via resgid=%u,resuid=%u. It only activates with reserve_root=%u.
Signed-off-by Jaegeuk Kim <[email protected]>
--- fs/f2fs/f2fs.h | 26 ++++++++++++++++++++++++-- fs/f2fs/super.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +24 -2
@@ -131,6 +131,12 @@ struct f2fs_mount_info {#define F2FS_CLEAR_FEATURE (sb, mask) \ (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) +/* +* Default values for user and/or group using reserved blocks +*/ +#define F2FS_DEF_RESUID 0 +#define F2FS_DEF_RESGID 0 +/* * For checkpoint manager */
@@ -1111,6 +1117,8 @@ struct f2fs_sb_info {block_t reserved_blocks;/* configurable reserved blocks */ block_t current_reserved_blocks;/* current reserved blocks */ block_t root_reserved_blocks;/* root reserved blocks */ +kuid_t s_resuid;/* reserved blocks for uid */ +kgid_t s_resgid;/* reserved blocks for gid */ unsigned int nquota_files;/* # of quota sysfile */
@@ -1563,6 +1571,20 @@ static inline bool f2fs_has_xattr_block(unsigned int ofs)return ofs ==XATTR_NODE_OFFSET ; } +static inline bool __allow_reserved_blocks (struct f2fs_sb_info *sbi) +{ +if (!test_opt (sbi,RESERVE_ROOT )) +return false; +if (capable (CAP_SYS_RESOURCE )) +return true; +if (uid_eq (sbi->s_resuid,current_fsuid ())) +return true; +if (!gid_eq (sbi->s_resgid,GLOBAL_ROOT_GID ) && +in_group_p (sbi->s_resgid)) +return true; +return false; +} +static inline void f2fs_i_blocks_write (struct inode *,block_t ,bool ,bool );static inline int inc_valid_block_count (struct f2fs_sb_info *sbi,struct inode *inode,blkcnt_t *count)
@@ -1593,7 +1615,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, avail_user_block_count = sbi->user_block_count - sbi->current_reserved_blocks; -if (!(test_opt (sbi,RESERVE_ROOT ) &&capable (CAP_SYS_RESOURCE ))) +if (!__allow_reserved_blocks (sbi)) avail_user_block_count -= sbi->root_reserved_blocks;if (unlikely (sbi->total_valid_block_count > avail_user_block_count)) {
@@ -1794,7 +1816,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, valid_block_count = sbi->total_valid_block_count + sbi->current_reserved_blocks +1 ; -if (!(test_opt (sbi,RESERVE_ROOT ) &&capable (CAP_SYS_RESOURCE ))) +if (!__allow_reserved_blocks (sbi)) valid_block_count += sbi->root_reserved_blocks;if (unlikely (valid_block_count > sbi->user_block_count)) {
fs/f2fs/super.c +44 -2
88 lines not on this page · raw message
Signature · 1 line
2.15.0.531.g2ccb3012c9-goog
Quoted 4 lines · Jaegeuk Kim
This patch adds mount options to reserve some blocks via resgid=%u,resuid=%u. It only activates with reserve_root=%u.
Signed-off-by Jaegeuk Kim <[email protected]>
Reviewed-by Chao Yu <[email protected]>
Thanks,
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot