From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Chandan Babu R <chandan.babu@oracle.com>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/4] xfs: clean up the XFS_IOC_{GS}ET_RESBLKS handler
Date: Mon, 27 Nov 2023 17:53:29 -0800 [thread overview]
Message-ID: <20231128015329.GQ2766956@frogsfrogsfrogs> (raw)
In-Reply-To: <20231126130124.1251467-2-hch@lst.de>
On Sun, Nov 26, 2023 at 02:01:21PM +0100, Christoph Hellwig wrote:
> The XFS_IOC_GET_RESBLKS and XFS_IOC_SET_RESBLKS already share a fair
> amount of code, and will share even more soon. Move the logic for both
> of them out of the main xfs_file_ioctl function into a
> xfs_ioctl_getset_resblocks helper to share the code and prepare for
> additional changes.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/xfs/xfs_ioctl.c | 87 +++++++++++++++++++++++-----------------------
> 1 file changed, 43 insertions(+), 44 deletions(-)
>
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index a82470e027f727..8faaf2ef67a7b8 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -1862,6 +1862,46 @@ xfs_fs_eofblocks_from_user(
> return 0;
> }
>
> +static int
> +xfs_ioctl_getset_resblocks(
> + struct file *filp,
> + unsigned int cmd,
> + void __user *arg)
> +{
> + struct xfs_mount *mp = XFS_I(file_inode(filp))->i_mount;
> + struct xfs_fsop_resblks fsop = { };
> + int error;
> + uint64_t in;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + if (cmd == XFS_IOC_SET_RESBLKS) {
> + if (xfs_is_readonly(mp))
> + return -EROFS;
> +
> + if (copy_from_user(&fsop, arg, sizeof(fsop)))
> + return -EFAULT;
> +
> + error = mnt_want_write_file(filp);
> + if (error)
> + return error;
> + in = fsop.resblks;
> + error = xfs_reserve_blocks(mp, &in, &fsop);
<shudder> what an interface...
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> + mnt_drop_write_file(filp);
> + if (error)
> + return error;
> + } else {
> + error = xfs_reserve_blocks(mp, NULL, &fsop);
> + if (error)
> + return error;
> + }
> +
> + if (copy_to_user(arg, &fsop, sizeof(fsop)))
> + return -EFAULT;
> + return 0;
> +}
> +
> /*
> * These long-unused ioctls were removed from the official ioctl API in 5.17,
> * but retain these definitions so that we can log warnings about them.
> @@ -2008,50 +2048,9 @@ xfs_file_ioctl(
> return 0;
> }
>
> - case XFS_IOC_SET_RESBLKS: {
> - xfs_fsop_resblks_t inout;
> - uint64_t in;
> -
> - if (!capable(CAP_SYS_ADMIN))
> - return -EPERM;
> -
> - if (xfs_is_readonly(mp))
> - return -EROFS;
> -
> - if (copy_from_user(&inout, arg, sizeof(inout)))
> - return -EFAULT;
> -
> - error = mnt_want_write_file(filp);
> - if (error)
> - return error;
> -
> - /* input parameter is passed in resblks field of structure */
> - in = inout.resblks;
> - error = xfs_reserve_blocks(mp, &in, &inout);
> - mnt_drop_write_file(filp);
> - if (error)
> - return error;
> -
> - if (copy_to_user(arg, &inout, sizeof(inout)))
> - return -EFAULT;
> - return 0;
> - }
> -
> - case XFS_IOC_GET_RESBLKS: {
> - xfs_fsop_resblks_t out;
> -
> - if (!capable(CAP_SYS_ADMIN))
> - return -EPERM;
> -
> - error = xfs_reserve_blocks(mp, NULL, &out);
> - if (error)
> - return error;
> -
> - if (copy_to_user(arg, &out, sizeof(out)))
> - return -EFAULT;
> -
> - return 0;
> - }
> + case XFS_IOC_SET_RESBLKS:
> + case XFS_IOC_GET_RESBLKS:
> + return xfs_ioctl_getset_resblocks(filp, cmd, arg);
>
> case XFS_IOC_FSGROWFSDATA: {
> struct xfs_growfs_data in;
> --
> 2.39.2
>
>
next prev parent reply other threads:[~2023-11-28 1:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-26 13:01 misc cleanups to the resblks interfaces Christoph Hellwig
2023-11-26 13:01 ` [PATCH 1/4] xfs: clean up the XFS_IOC_{GS}ET_RESBLKS handler Christoph Hellwig
2023-11-28 1:53 ` Darrick J. Wong [this message]
2023-11-26 13:01 ` [PATCH 2/4] xfs: clean up the XFS_IOC_FSCOUNTS handler Christoph Hellwig
2023-11-27 16:40 ` Christoph Hellwig
2023-11-28 1:58 ` Darrick J. Wong
2023-11-28 5:30 ` Christoph Hellwig
2023-11-26 13:01 ` [PATCH 3/4] xfs: clean up the xfs_reserve_blocks interface Christoph Hellwig
2023-11-28 2:09 ` Darrick J. Wong
2023-11-28 5:32 ` Christoph Hellwig
2023-11-26 13:01 ` [PATCH 4/4] xfs: clean up xfs_fsops.h Christoph Hellwig
2023-11-28 1:51 ` Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2023-12-04 17:40 misc cleanups to the resblks interfaces v2 Christoph Hellwig
2023-12-04 17:40 ` [PATCH 1/4] xfs: clean up the XFS_IOC_{GS}ET_RESBLKS handler Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231128015329.GQ2766956@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=chandan.babu@oracle.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox