Re: [PATCH V2 01/10] xfs: Add helper for checking per-inode extent count overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> +int
> +xfs_iext_count_may_overflow(
> +	struct xfs_inode	*ip,
> +	int			whichfork,
> +	int			nr_to_add)
> +{
> +	struct xfs_ifork	*ifp;
> +	uint64_t		max_exts = 0;
> +	uint64_t		nr_exts;
> +
> +	switch (whichfork) {
> +	case XFS_DATA_FORK:
> +		max_exts = MAXEXTNUM;
> +		break;
> +
> +	case XFS_ATTR_FORK:
> +		max_exts = MAXAEXTNUM;
> +		break;
> +
> +	default:
> +		ASSERT(0);
> +		break;
> +	}
> +
> +	ifp = XFS_IFORK_PTR(ip, whichfork);
> +	nr_exts = ifp->if_nextents + nr_to_add;
> +
> +	if (nr_exts > max_exts)
> +		return -EFBIG;
> +
> +	return 0;
> +}

Maybe it's just me, but I would structure this very different (just
cosmetic differences, though).  First add a:

static inline uint32_t xfs_max_extents(int whichfork)
{
	return XFS_ATTR_FORK ? MAXAEXTNUM : MAXEXTNUM;
}

to have a single place that determines the max number of extents.

And the simplify the helper down to:

int
xfs_iext_count_may_overflow(
	struct xfs_inode	*ip,
	int			whichfork,
	int			nr_to_add)
{
	struct xfs_ifork	*ifp = XFS_IFORK_PTR(ip, whichfork);
	uint64_t		max_exts = xfs_max_extents(whichfork);
	uint64_t		nr_exts;

	if (check_add_overflow(ifp->if_nextents, nr_to_add, &nr_exts) ||
	    nr_exts > max_exts))
		return -EFBIG;
	return 0;
}

which actually might be small enough for an inline function now.



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux