Skip to content

Commit

Permalink
quota: port to mnt_idmap
Browse files Browse the repository at this point in the history
Convert to struct mnt_idmap.

Last cycle we merged the necessary infrastructure in
256c8ae ("fs: introduce dedicated idmap type for mounts").
This is just the conversion to struct mnt_idmap.

Currently we still pass around the plain namespace that was attached to a
mount. This is in general pretty convenient but it makes it easy to
conflate namespaces that are relevant on the filesystem with namespaces
that are relevent on the mount level. Especially for non-vfs developers
without detailed knowledge in this area this can be a potential source for
bugs.

Once the conversion to struct mnt_idmap is done all helpers down to the
really low-level helpers will take a struct mnt_idmap argument instead of
two namespace arguments. This way it becomes impossible to conflate the two
eliminating the possibility of any bugs. All of the vfs and all filesystems
only operate on struct mnt_idmap.

Acked-by: Dave Chinner <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Christian Brauner (Microsoft) <[email protected]>
  • Loading branch information
brauner committed Jan 19, 2023
1 parent 9452e93 commit f861646
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
9 changes: 4 additions & 5 deletions fs/ext2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,22 +1621,21 @@ int ext2_getattr(struct mnt_idmap *idmap, const struct path *path,
int ext2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
struct iattr *iattr)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
struct inode *inode = d_inode(dentry);
int error;

error = setattr_prepare(&nop_mnt_idmap, dentry, iattr);
if (error)
return error;

if (is_quota_modification(mnt_userns, inode, iattr)) {
if (is_quota_modification(&nop_mnt_idmap, inode, iattr)) {
error = dquot_initialize(inode);
if (error)
return error;
}
if (i_uid_needs_update(mnt_userns, iattr, inode) ||
i_gid_needs_update(mnt_userns, iattr, inode)) {
error = dquot_transfer(mnt_userns, inode, iattr);
if (i_uid_needs_update(&nop_mnt_idmap, iattr, inode) ||
i_gid_needs_update(&nop_mnt_idmap, iattr, inode)) {
error = dquot_transfer(&nop_mnt_idmap, inode, iattr);
if (error)
return error;
}
Expand Down
4 changes: 2 additions & 2 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -5467,7 +5467,7 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
if (error)
return error;

if (is_quota_modification(mnt_userns, inode, attr)) {
if (is_quota_modification(idmap, inode, attr)) {
error = dquot_initialize(inode);
if (error)
return error;
Expand All @@ -5491,7 +5491,7 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
* counts xattr inode references.
*/
down_read(&EXT4_I(inode)->xattr_sem);
error = dquot_transfer(mnt_userns, inode, attr);
error = dquot_transfer(idmap, inode, attr);
up_read(&EXT4_I(inode)->xattr_sem);

if (error) {
Expand Down
4 changes: 2 additions & 2 deletions fs/f2fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,15 +965,15 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
if (err)
return err;

if (is_quota_modification(mnt_userns, inode, attr)) {
if (is_quota_modification(idmap, inode, attr)) {
err = f2fs_dquot_initialize(inode);
if (err)
return err;
}
if (i_uid_needs_update(mnt_userns, attr, inode) ||
i_gid_needs_update(mnt_userns, attr, inode)) {
f2fs_lock_op(F2FS_I_SB(inode));
err = dquot_transfer(mnt_userns, inode, attr);
err = dquot_transfer(idmap, inode, attr);
if (err) {
set_sbi_flag(F2FS_I_SB(inode),
SBI_QUOTA_NEED_REPAIR);
Expand Down
2 changes: 1 addition & 1 deletion fs/f2fs/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static int recover_quota_data(struct inode *inode, struct page *page)
if (!attr.ia_valid)
return 0;

err = dquot_transfer(&init_user_ns, inode, &attr);
err = dquot_transfer(&nop_mnt_idmap, inode, &attr);
if (err)
set_sbi_flag(F2FS_I_SB(inode), SBI_QUOTA_NEED_REPAIR);
return err;
Expand Down
4 changes: 2 additions & 2 deletions fs/jfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ int jfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
if (rc)
return rc;

if (is_quota_modification(&init_user_ns, inode, iattr)) {
if (is_quota_modification(&nop_mnt_idmap, inode, iattr)) {
rc = dquot_initialize(inode);
if (rc)
return rc;
}
if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
(iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
rc = dquot_transfer(&init_user_ns, inode, iattr);
rc = dquot_transfer(&nop_mnt_idmap, inode, iattr);
if (rc)
return rc;
}
Expand Down
3 changes: 1 addition & 2 deletions fs/ocfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,6 @@ static int ocfs2_extend_file(struct inode *inode,
int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
struct iattr *attr)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
int status = 0, size_change;
int inode_locked = 0;
struct inode *inode = d_inode(dentry);
Expand Down Expand Up @@ -1147,7 +1146,7 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
if (status)
return status;

if (is_quota_modification(mnt_userns, inode, attr)) {
if (is_quota_modification(&nop_mnt_idmap, inode, attr)) {
status = dquot_initialize(inode);
if (status)
return status;
Expand Down
3 changes: 2 additions & 1 deletion fs/quota/dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -2085,9 +2085,10 @@ EXPORT_SYMBOL(__dquot_transfer);
/* Wrapper for transferring ownership of an inode for uid/gid only
* Called from FSXXX_setattr()
*/
int dquot_transfer(struct user_namespace *mnt_userns, struct inode *inode,
int dquot_transfer(struct mnt_idmap *idmap, struct inode *inode,
struct iattr *iattr)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
struct dquot *transfer_to[MAXQUOTAS] = {};
struct dquot *dquot;
struct super_block *sb = inode->i_sb;
Expand Down
4 changes: 2 additions & 2 deletions fs/reiserfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3276,7 +3276,7 @@ int reiserfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
/* must be turned off for recursive notify_change calls */
ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID);

if (is_quota_modification(&init_user_ns, inode, attr)) {
if (is_quota_modification(&nop_mnt_idmap, inode, attr)) {
error = dquot_initialize(inode);
if (error)
return error;
Expand Down Expand Up @@ -3359,7 +3359,7 @@ int reiserfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
reiserfs_write_unlock(inode->i_sb);
if (error)
goto out;
error = dquot_transfer(&init_user_ns, inode, attr);
error = dquot_transfer(&nop_mnt_idmap, inode, attr);
reiserfs_write_lock(inode->i_sb);
if (error) {
journal_end(&th);
Expand Down
2 changes: 1 addition & 1 deletion fs/zonefs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ static int zonefs_inode_setattr(struct mnt_idmap *idmap,
!uid_eq(iattr->ia_uid, inode->i_uid)) ||
((iattr->ia_valid & ATTR_GID) &&
!gid_eq(iattr->ia_gid, inode->i_gid))) {
ret = dquot_transfer(&init_user_ns, inode, iattr);
ret = dquot_transfer(&nop_mnt_idmap, inode, iattr);
if (ret)
return ret;
}
Expand Down
7 changes: 4 additions & 3 deletions include/linux/quotaops.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
}

/* i_mutex must being held */
static inline bool is_quota_modification(struct user_namespace *mnt_userns,
static inline bool is_quota_modification(struct mnt_idmap *idmap,
struct inode *inode, struct iattr *ia)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
return ((ia->ia_valid & ATTR_SIZE) ||
i_uid_needs_update(mnt_userns, ia, inode) ||
i_gid_needs_update(mnt_userns, ia, inode));
Expand Down Expand Up @@ -116,7 +117,7 @@ int dquot_set_dqblk(struct super_block *sb, struct kqid id,
struct qc_dqblk *di);

int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
int dquot_transfer(struct user_namespace *mnt_userns, struct inode *inode,
int dquot_transfer(struct mnt_idmap *idmap, struct inode *inode,
struct iattr *iattr);

static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
Expand Down Expand Up @@ -236,7 +237,7 @@ static inline void dquot_free_inode(struct inode *inode)
{
}

static inline int dquot_transfer(struct user_namespace *mnt_userns,
static inline int dquot_transfer(struct mnt_idmap *idmap,
struct inode *inode, struct iattr *iattr)
{
return 0;
Expand Down

0 comments on commit f861646

Please sign in to comment.