[SRU Bionic 2/4] xfs: merge the projid fields in struct xfs_icdinode

Stefan Bader stefan.bader at canonical.com
Fri Nov 19 08:49:32 UTC 2021


On 16.11.21 20:56, Thadeu Lima de Souza Cascardo wrote:
> From: Christoph Hellwig <hch at lst.de>
> 
> BugLink: https://bugs.launchpad.net/bugs/1950239
> 
> There is no point in splitting the fields like this in an purely
> in-memory structure.
> 
> Signed-off-by: Christoph Hellwig <hch at lst.de>
> Reviewed-by: Darrick J. Wong <darrick.wong at oracle.com>
> Signed-off-by: Darrick J. Wong <darrick.wong at oracle.com>
> (backported from commit de7a866fd41b227b0aa6e9cbeb0dae221c12f542)
> [cascardo: conflicts because of changed code, including:
>   new function xfs_qm_id_for_quotatype on xfs_dquot.c
>   XFS_QMOPT_DQALLOC flag turned into a bool
>   xfs_qm_quotacheck_dqadjust losing the id parameter
>   support for FSSETXATTR, introducing xfs_fill_fsxattr
>   new v5 bulkstat structure
> ]
> [cascardo: looked for missing conversions of xfs_get_projid]
> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo at canonical.com>
> ---
>   fs/xfs/libxfs/xfs_inode_buf.c | 11 +++++------
>   fs/xfs/libxfs/xfs_inode_buf.h |  3 +--
>   fs/xfs/xfs_icache.c           |  4 ++--
>   fs/xfs/xfs_inode.c            |  6 +++---
>   fs/xfs/xfs_inode.h            | 21 +--------------------
>   fs/xfs/xfs_inode_item.c       |  4 ++--
>   fs/xfs/xfs_ioctl.c            | 10 +++++-----
>   fs/xfs/xfs_iops.c             |  2 +-
>   fs/xfs/xfs_itable.c           |  4 ++--
>   fs/xfs/xfs_qm.c               | 10 +++++-----
>   fs/xfs/xfs_qm_bhv.c           |  2 +-
>   11 files changed, 28 insertions(+), 49 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
> index 080dced91047..aeb00e758e23 100644
> --- a/fs/xfs/libxfs/xfs_inode_buf.c
> +++ b/fs/xfs/libxfs/xfs_inode_buf.c
> @@ -223,13 +223,12 @@ xfs_inode_from_disk(
>   	to->di_version = from->di_version;
>   	if (to->di_version == 1) {
>   		set_nlink(inode, be16_to_cpu(from->di_onlink));
> -		to->di_projid_lo = 0;
> -		to->di_projid_hi = 0;
> +		to->di_projid = 0;
>   		to->di_version = 2;
>   	} else {
>   		set_nlink(inode, be32_to_cpu(from->di_nlink));
> -		to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
> -		to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
> +		to->di_projid = (prid_t)be16_to_cpu(from->di_projid_hi) << 16 |
> +					be16_to_cpu(from->di_projid_lo);
>   	}
>   
>   	to->di_format = from->di_format;
> @@ -290,8 +289,8 @@ xfs_inode_to_disk(
>   	to->di_format = from->di_format;
>   	to->di_uid = cpu_to_be32(from->di_uid);
>   	to->di_gid = cpu_to_be32(from->di_gid);
> -	to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
> -	to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
> +	to->di_projid_lo = cpu_to_be16(from->di_projid & 0xffff);
> +	to->di_projid_hi = cpu_to_be16(from->di_projid >> 16);

Hm... are the _lo/_hi pieces not gone? ^

>   
>   	memset(to->di_pad, 0, sizeof(to->di_pad));
>   	to->di_atime.t_sec = cpu_to_be32(inode->i_atime.tv_sec);
> diff --git a/fs/xfs/libxfs/xfs_inode_buf.h b/fs/xfs/libxfs/xfs_inode_buf.h
> index a9c97a356c30..97d49d372578 100644
> --- a/fs/xfs/libxfs/xfs_inode_buf.h
> +++ b/fs/xfs/libxfs/xfs_inode_buf.h
> @@ -33,8 +33,7 @@ struct xfs_icdinode {
>   	uint16_t	di_flushiter;	/* incremented on flush */
>   	uint32_t	di_uid;		/* owner's user id */
>   	uint32_t	di_gid;		/* owner's group id */
> -	uint16_t	di_projid_lo;	/* lower part of owner's project id */
> -	uint16_t	di_projid_hi;	/* higher part of owner's project id */
> +	uint32_t	di_projid;	/* owner's project id */
>   	xfs_fsize_t	di_size;	/* number of bytes in file */
>   	xfs_rfsblock_t	di_nblocks;	/* # of direct & btree blocks used */
>   	xfs_extlen_t	di_extsize;	/* basic/minimum extent size for file */
> diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
> index 2d6cc99364db..f755de4726a8 100644
> --- a/fs/xfs/xfs_icache.c
> +++ b/fs/xfs/xfs_icache.c
> @@ -1434,7 +1434,7 @@ xfs_inode_match_id(
>   		return 0;
>   
>   	if ((eofb->eof_flags & XFS_EOF_FLAGS_PRID) &&
> -	    xfs_get_projid(ip) != eofb->eof_prid)
> +	    ip->i_d.di_projid != eofb->eof_prid)
>   		return 0;
>   
>   	return 1;
> @@ -1458,7 +1458,7 @@ xfs_inode_match_id_union(
>   		return 1;
>   
>   	if ((eofb->eof_flags & XFS_EOF_FLAGS_PRID) &&
> -	    xfs_get_projid(ip) == eofb->eof_prid)
> +	    ip->i_d.di_projid == eofb->eof_prid)
>   		return 1;
>   
>   	return 0;
> diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
> index c9875003fb27..51de8ad95adb 100644
> --- a/fs/xfs/xfs_inode.c
> +++ b/fs/xfs/xfs_inode.c
> @@ -799,7 +799,7 @@ xfs_ialloc(
>   	inode->i_uid = current_fsuid();
>   	ip->i_d.di_uid = xfs_kuid_to_uid(inode->i_uid);
>   	inode->i_rdev = rdev;
> -	xfs_set_projid(ip, prid);
> +	ip->i_d.di_projid = prid;
>   
>   	if (pip && XFS_INHERIT_GID(pip)) {
>   		inode->i_gid = VFS_I(pip)->i_gid;
> @@ -1436,7 +1436,7 @@ xfs_link(
>   	 * the tree quota mechanism could be circumvented.
>   	 */
>   	if (unlikely((tdp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
> -		     (xfs_get_projid(tdp) != xfs_get_projid(sip)))) {
> +		     tdp->i_d.di_projid != sip->i_d.di_projid)) {
>   		error = -EXDEV;
>   		goto error_return;
>   	}
> @@ -3010,7 +3010,7 @@ xfs_rename(
>   	 * tree quota mechanism would be circumvented.
>   	 */
>   	if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
> -		     (xfs_get_projid(target_dp) != xfs_get_projid(src_ip)))) {
> +		     target_dp->i_d.di_projid != src_ip->i_d.di_projid)) {
>   		error = -EXDEV;
>   		goto out_trans_cancel;
>   	}
> diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
> index d383e392ec9d..aff5f306086d 100644
> --- a/fs/xfs/xfs_inode.h
> +++ b/fs/xfs/xfs_inode.h
> @@ -177,30 +177,11 @@ xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
>   	return ret;
>   }
>   
> -/*
> - * Project quota id helpers (previously projid was 16bit only
> - * and using two 16bit values to hold new 32bit projid was chosen
> - * to retain compatibility with "old" filesystems).
> - */
> -static inline prid_t
> -xfs_get_projid(struct xfs_inode *ip)
> -{
> -	return (prid_t)ip->i_d.di_projid_hi << 16 | ip->i_d.di_projid_lo;
> -}
> -
> -static inline void
> -xfs_set_projid(struct xfs_inode *ip,
> -		prid_t projid)
> -{
> -	ip->i_d.di_projid_hi = (uint16_t) (projid >> 16);
> -	ip->i_d.di_projid_lo = (uint16_t) (projid & 0xffff);
> -}
> -
>   static inline prid_t
>   xfs_get_initial_prid(struct xfs_inode *dp)
>   {
>   	if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
> -		return xfs_get_projid(dp);
> +		return dp->i_d.di_projid;
>   
>   	return XFS_PROJID_DEFAULT;
>   }
> diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
> index 6ee5c3bf19ad..e8e341e7fa99 100644
> --- a/fs/xfs/xfs_inode_item.c
> +++ b/fs/xfs/xfs_inode_item.c
> @@ -324,8 +324,8 @@ xfs_inode_to_log_dinode(
>   	to->di_format = from->di_format;
>   	to->di_uid = from->di_uid;
>   	to->di_gid = from->di_gid;
> -	to->di_projid_lo = from->di_projid_lo;
> -	to->di_projid_hi = from->di_projid_hi;
> +	to->di_projid_lo = from->di_projid & 0xffff;
> +	to->di_projid_hi = from->di_projid >> 16;

Hm... are the _lo/_hi pieces not gone? ^

>   
>   	memset(to->di_pad, 0, sizeof(to->di_pad));
>   	memset(to->di_pad3, 0, sizeof(to->di_pad3));
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 4e09fd6a7cd2..787dc7711b4b 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -909,7 +909,7 @@ xfs_ioc_fsgetxattr(
>   	fa.fsx_extsize = ip->i_d.di_extsize << ip->i_mount->m_sb.sb_blocklog;
>   	fa.fsx_cowextsize = ip->i_d.di_cowextsize <<
>   			ip->i_mount->m_sb.sb_blocklog;
> -	fa.fsx_projid = xfs_get_projid(ip);
> +	fa.fsx_projid = ip->i_d.di_projid;
>   
>   	if (attr) {
>   		if (ip->i_afp) {
> @@ -1319,7 +1319,7 @@ xfs_ioctl_setattr_check_projid(
>   	if (current_user_ns() == &init_user_ns)
>   		return 0;
>   
> -	if (xfs_get_projid(ip) != fa->fsx_projid)
> +	if (ip->i_d.di_projid != fa->fsx_projid)
>   		return -EINVAL;
>   	if ((fa->fsx_xflags & FS_XFLAG_PROJINHERIT) !=
>   	    (ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT))
> @@ -1382,7 +1382,7 @@ xfs_ioctl_setattr(
>   
>   
>   	if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp) &&
> -	    xfs_get_projid(ip) != fa->fsx_projid) {
> +	    ip->i_d.di_projid != fa->fsx_projid) {
>   		code = xfs_qm_vop_chown_reserve(tp, ip, udqp, NULL, pdqp,
>   				capable(CAP_FOWNER) ?  XFS_QMOPT_FORCE_RES : 0);
>   		if (code)	/* out of quota */
> @@ -1414,13 +1414,13 @@ xfs_ioctl_setattr(
>   		VFS_I(ip)->i_mode &= ~(S_ISUID|S_ISGID);
>   
>   	/* Change the ownerships and register project quota modifications */
> -	if (xfs_get_projid(ip) != fa->fsx_projid) {
> +	if (ip->i_d.di_projid != fa->fsx_projid) {
>   		if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp)) {
>   			olddquot = xfs_qm_vop_chown(tp, ip,
>   						&ip->i_pdquot, pdqp);
>   		}
>   		ASSERT(ip->i_d.di_version > 1);
> -		xfs_set_projid(ip, fa->fsx_projid);
> +		ip->i_d.di_projid = fa->fsx_projid;
>   	}
>   
>   	/*
> diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
> index b336d41a9f41..eff30ffd98b0 100644
> --- a/fs/xfs/xfs_iops.c
> +++ b/fs/xfs/xfs_iops.c
> @@ -675,7 +675,7 @@ xfs_setattr_nonsize(
>   		ASSERT(gdqp == NULL);
>   		error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid),
>   					   xfs_kgid_to_gid(gid),
> -					   xfs_get_projid(ip),
> +					   ip->i_d.di_projid,
>   					   qflags, &udqp, &gdqp, NULL);
>   		if (error)
>   			return error;
> diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
> index d58310514423..587e8108e1de 100644
> --- a/fs/xfs/xfs_itable.c
> +++ b/fs/xfs/xfs_itable.c
> @@ -75,8 +75,8 @@ xfs_bulkstat_one_int(
>   	/* xfs_iget returns the following without needing
>   	 * further change.
>   	 */
> -	buf->bs_projid_lo = dic->di_projid_lo;
> -	buf->bs_projid_hi = dic->di_projid_hi;
> +	buf->bs_projid_lo = dic->di_projid & 0xFFFF;
> +	buf->bs_projid_hi = dic->di_projid >> 16;

Hm... are the _lo/_hi pieces not gone? ^

>   	buf->bs_ino = ino;
>   	buf->bs_uid = dic->di_uid;
>   	buf->bs_gid = dic->di_gid;
> diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
> index b897b11afb2c..e91b444f118a 100644
> --- a/fs/xfs/xfs_qm.c
> +++ b/fs/xfs/xfs_qm.c
> @@ -363,7 +363,7 @@ xfs_qm_dqattach_locked(
>   	}
>   
>   	if (XFS_IS_PQUOTA_ON(mp) && !ip->i_pdquot) {
> -		error = xfs_qm_dqattach_one(ip, xfs_get_projid(ip), XFS_DQ_PROJ,
> +		error = xfs_qm_dqattach_one(ip, ip->i_d.di_projid, XFS_DQ_PROJ,
>   						flags & XFS_QMOPT_DQALLOC,
>   						&ip->i_pdquot);
>   		if (error)
> @@ -1203,7 +1203,7 @@ xfs_qm_dqusage_adjust(
>   	}
>   
>   	if (XFS_IS_PQUOTA_ON(mp)) {
> -		error = xfs_qm_quotacheck_dqadjust(ip, xfs_get_projid(ip),
> +		error = xfs_qm_quotacheck_dqadjust(ip, ip->i_d.di_projid,
>   						   XFS_DQ_PROJ, nblks, rtblks);
>   		if (error)
>   			goto error0;
> @@ -1739,7 +1739,7 @@ xfs_qm_vop_dqalloc(
>   		}
>   	}
>   	if ((flags & XFS_QMOPT_PQUOTA) && XFS_IS_PQUOTA_ON(mp)) {
> -		if (xfs_get_projid(ip) != prid) {
> +		if (ip->i_d.di_projid != prid) {
>   			xfs_iunlock(ip, lockflags);
>   			error = xfs_qm_dqget(mp, NULL, (xfs_dqid_t)prid,
>   						 XFS_DQ_PROJ,
> @@ -1875,7 +1875,7 @@ xfs_qm_vop_chown_reserve(
>   	}
>   
>   	if (XFS_IS_PQUOTA_ON(ip->i_mount) && pdqp &&
> -	    xfs_get_projid(ip) != be32_to_cpu(pdqp->q_core.d_id)) {
> +	    ip->i_d.di_projid != be32_to_cpu(pdqp->q_core.d_id)) {
>   		prjflags = XFS_QMOPT_ENOSPC;
>   		pdq_delblks = pdqp;
>   		if (delblks) {
> @@ -1976,7 +1976,7 @@ xfs_qm_vop_create_dqattach(
>   	}
>   	if (pdqp && XFS_IS_PQUOTA_ON(mp)) {
>   		ASSERT(ip->i_pdquot == NULL);
> -		ASSERT(xfs_get_projid(ip) == be32_to_cpu(pdqp->q_core.d_id));
> +		ASSERT(ip->i_d.di_projid == be32_to_cpu(pdqp->q_core.d_id));
>   
>   		ip->i_pdquot = xfs_qm_dqhold(pdqp);
>   		xfs_trans_mod_dquot(tp, pdqp, XFS_TRANS_DQ_ICOUNT, 1);
> diff --git a/fs/xfs/xfs_qm_bhv.c b/fs/xfs/xfs_qm_bhv.c
> index 42c0daae81e0..90807f891a7f 100644
> --- a/fs/xfs/xfs_qm_bhv.c
> +++ b/fs/xfs/xfs_qm_bhv.c
> @@ -72,7 +72,7 @@ xfs_qm_statvfs(
>   	xfs_mount_t		*mp = ip->i_mount;
>   	xfs_dquot_t		*dqp;
>   
> -	if (!xfs_qm_dqget(mp, NULL, xfs_get_projid(ip), XFS_DQ_PROJ, 0, &dqp)) {
> +	if (!xfs_qm_dqget(mp, NULL, ip->i_d.di_projid, XFS_DQ_PROJ, 0, &dqp)) {
>   		xfs_fill_statvfs_from_dquot(statp, dqp);
>   		xfs_qm_dqput(dqp);
>   	}
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20211119/0ad63006/attachment.sig>


More information about the kernel-team mailing list