From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: aalbersh@kernel.org, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/4] xfs_quota: utilize file_setattr to set prjid on special files
Date: Mon, 11 Aug 2025 08:07:47 -0700 [thread overview]
Message-ID: <20250811150747.GB7965@frogsfrogsfrogs> (raw)
In-Reply-To: <20250808-xattrat-syscall-v1-2-48567c29e45c@kernel.org>
On Fri, Aug 08, 2025 at 09:30:17PM +0200, Andrey Albershteyn wrote:
> From: Andrey Albershteyn <aalbersh@redhat.com>
>
> Utilize new file_getattr/file_setattr syscalls to set project ID on
> special files. Previously, special files were skipped due to lack of the
> way to call FS_IOC_SETFSXATTR ioctl on them. The quota accounting was
> therefore missing these inodes (special files created before project
> setup). The ones created after porject initialization did inherit the
> projid flag from the parent.
>
> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
> ---
> quota/project.c | 144 +++++++++++++++++++++++++++++---------------------------
> 1 file changed, 74 insertions(+), 70 deletions(-)
>
> diff --git a/quota/project.c b/quota/project.c
> index adb26945fa57..93d7ace0e11b 100644
> --- a/quota/project.c
> +++ b/quota/project.c
> @@ -4,14 +4,17 @@
> * All Rights Reserved.
> */
>
> +#include <unistd.h>
> #include "command.h"
> #include "input.h"
> #include "init.h"
> +#include "libfrog/file_attr.h"
> #include "quota.h"
>
> static cmdinfo_t project_cmd;
> static prid_t prid;
> static int recurse_depth = -1;
> +static int dfd;
Ew, global scope variables, can we pass that through to check_project?
> enum {
> CHECK_PROJECT = 0x1,
> @@ -19,13 +22,6 @@ enum {
> CLEAR_PROJECT = 0x4,
> };
>
> -#define EXCLUDED_FILE_TYPES(x) \
> - (S_ISCHR((x)) \
> - || S_ISBLK((x)) \
> - || S_ISFIFO((x)) \
> - || S_ISLNK((x)) \
> - || S_ISSOCK((x)))
> -
> static void
> project_help(void)
> {
> @@ -85,8 +81,8 @@ check_project(
> int flag,
> struct FTW *data)
> {
> - struct fsxattr fsx;
> - int fd;
> + int error;
> + struct file_attr fa = { 0 };
>
> if (recurse_depth >= 0 && data->level > recurse_depth)
> return 0;
> @@ -96,30 +92,30 @@ check_project(
> fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
> return 0;
> }
> - if (EXCLUDED_FILE_TYPES(stat->st_mode)) {
> - fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
> - return 0;
> - }
>
> - if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
> - exitcode = 1;
> - fprintf(stderr, _("%s: cannot open %s: %s\n"),
> - progname, path, strerror(errno));
> - } else if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
> - exitcode = 1;
> + error = file_getattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> +#ifndef HAVE_FILE_ATTR
> + if (SPECIAL_FILE(stat->st_mode)) {
> + fprintf(stderr, _("%s: skipping special file %s\n"),
> + progname, path);
> + return 0;
> + }
> +#endif
Yeah, file_getattr really ought to return some error code for "not
supported" and then this becomes:
error = file_getattr(...);
if (error && errno == EOPNOTSUPP) {
fprintf(stderr, _("%s: skipping special file %s\n"),
progname, path);
return 0;
}
if (error) {
fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
progname, path, strerror(errno));
exitcode = 1;
return 0;
}
> fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
> - progname, path, strerror(errno));
> - } else {
> - if (fsx.fsx_projid != prid)
> - printf(_("%s - project identifier is not set"
> - " (inode=%u, tree=%u)\n"),
> - path, fsx.fsx_projid, (unsigned int)prid);
> - if (!(fsx.fsx_xflags & FS_XFLAG_PROJINHERIT) && S_ISDIR(stat->st_mode))
> - printf(_("%s - project inheritance flag is not set\n"),
> - path);
> + progname, path, strerror(errno));
> + exitcode = 1;
> + return 0;
> }
> - if (fd != -1)
> - close(fd);
> +
> + if (fa.fa_projid != prid)
> + printf(_("%s - project identifier is not set"
> + " (inode=%u, tree=%u)\n"),
> + path, fa.fa_projid, (unsigned int)prid);
> + if (!(fa.fa_xflags & FS_XFLAG_PROJINHERIT) && S_ISDIR(stat->st_mode))
> + printf(_("%s - project inheritance flag is not set\n"),
> + path);
> +
> return 0;
> }
>
> @@ -130,8 +126,8 @@ clear_project(
> int flag,
> struct FTW *data)
> {
> - struct fsxattr fsx;
> - int fd;
> + int error;
> + struct file_attr fa;
>
> if (recurse_depth >= 0 && data->level > recurse_depth)
> return 0;
> @@ -141,32 +137,31 @@ clear_project(
> fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
> return 0;
> }
> - if (EXCLUDED_FILE_TYPES(stat->st_mode)) {
> - fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
> - return 0;
> - }
>
> - if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
> - exitcode = 1;
> - fprintf(stderr, _("%s: cannot open %s: %s\n"),
> - progname, path, strerror(errno));
> - return 0;
> - } else if (xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx) < 0) {
> - exitcode = 1;
> + error = file_getattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> +#ifndef HAVE_FILE_ATTR
> + if (SPECIAL_FILE(stat->st_mode)) {
> + fprintf(stderr, _("%s: skipping special file %s\n"),
> + progname, path);
> + return 0;
> + }
> +#endif
> fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
> - progname, path, strerror(errno));
> - close(fd);
> + progname, path, strerror(errno));
> + exitcode = 1;
> return 0;
> }
>
> - fsx.fsx_projid = 0;
> - fsx.fsx_xflags &= ~FS_XFLAG_PROJINHERIT;
> - if (xfsctl(path, fd, FS_IOC_FSSETXATTR, &fsx) < 0) {
> - exitcode = 1;
> + fa.fa_projid = 0;
> + fa.fa_xflags &= ~FS_XFLAG_PROJINHERIT;
> +
> + error = file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> fprintf(stderr, _("%s: cannot clear project on %s: %s\n"),
> progname, path, strerror(errno));
> + exitcode = 1;
> }
> - close(fd);
> return 0;
> }
>
> @@ -177,8 +172,8 @@ setup_project(
> int flag,
> struct FTW *data)
> {
> - struct fsxattr fsx;
> - int fd;
> + struct file_attr fa;
> + int error;
>
> if (recurse_depth >= 0 && data->level > recurse_depth)
> return 0;
> @@ -188,32 +183,32 @@ setup_project(
> fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
> return 0;
> }
> - if (EXCLUDED_FILE_TYPES(stat->st_mode)) {
> - fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
> - return 0;
> - }
>
> - if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
> - exitcode = 1;
> - fprintf(stderr, _("%s: cannot open %s: %s\n"),
> - progname, path, strerror(errno));
> - return 0;
> - } else if (xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx) < 0) {
> - exitcode = 1;
> + error = file_getattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> +#ifndef HAVE_FILE_ATTR
> + if (SPECIAL_FILE(stat->st_mode)) {
> + fprintf(stderr, _("%s: skipping special file %s\n"),
> + progname, path);
> + return 0;
> + }
> +#endif
> fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
> - progname, path, strerror(errno));
> - close(fd);
> + progname, path, strerror(errno));
> + exitcode = 1;
> return 0;
> }
>
> - fsx.fsx_projid = prid;
> - fsx.fsx_xflags |= FS_XFLAG_PROJINHERIT;
> - if (xfsctl(path, fd, FS_IOC_FSSETXATTR, &fsx) < 0) {
> - exitcode = 1;
> + fa.fa_projid = prid;
> + if (S_ISDIR(stat->st_mode))
> + fa.fa_xflags |= FS_XFLAG_PROJINHERIT;
> +
> + error = file_setattr(dfd, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> fprintf(stderr, _("%s: cannot set project on %s: %s\n"),
> progname, path, strerror(errno));
> + exitcode = 1;
> }
> - close(fd);
> return 0;
> }
>
> @@ -223,6 +218,13 @@ project_operations(
> char *dir,
> int type)
> {
> + dfd = open(dir, O_RDONLY|O_NOCTTY);
> + if (dfd < -1) {
> + printf(_("Error opening dir %s for project %s...\n"), dir,
> + project);
> + return;
> + }
> +
> switch (type) {
> case CHECK_PROJECT:
> printf(_("Checking project %s (path %s)...\n"), project, dir);
> @@ -237,6 +239,8 @@ project_operations(
> nftw(dir, clear_project, 100, FTW_PHYS|FTW_MOUNT);
> break;
> }
> +
> + close(dfd);
> }
>
> static void
>
> --
> 2.49.0
>
>
next prev parent reply other threads:[~2025-08-11 15:07 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 19:28 Tests for file_getattr()/file_setattr() and xfsprogs update Andrey Albershteyn
2025-08-08 19:30 ` [PATCH 0/4] xfsprogs: utilize file_getattr() and file_setattr() Andrey Albershteyn
2025-08-08 19:30 ` [PATCH 1/4] libfrog: add wrappers for file_getattr/file_setattr syscalls Andrey Albershteyn
2025-08-11 15:02 ` Darrick J. Wong
2025-08-11 17:44 ` Andrey Albershteyn
2025-08-12 14:53 ` Darrick J. Wong
2025-08-08 19:30 ` [PATCH 2/4] xfs_quota: utilize file_setattr to set prjid on special files Andrey Albershteyn
2025-08-11 15:07 ` Darrick J. Wong [this message]
2025-08-11 17:51 ` Andrey Albershteyn
2025-08-08 19:30 ` [PATCH 3/4] xfs_io: make ls/chattr work with " Andrey Albershteyn
2025-08-11 15:12 ` Darrick J. Wong
2025-08-11 17:57 ` Andrey Albershteyn
2025-08-12 17:28 ` Darrick J. Wong
2025-08-08 19:30 ` [PATCH 4/4] xfs_db: use file_setattr to copy attributes on special files with rdump Andrey Albershteyn
2025-08-11 15:14 ` Darrick J. Wong
2025-08-11 17:59 ` Andrey Albershteyn
2025-08-08 19:31 ` [PATCH 0/3] Test file_getattr and file_setattr syscalls Andrey Albershteyn
2025-08-08 19:31 ` [PATCH 1/3] file_attr: introduce program to set/get fsxattr Andrey Albershteyn
2025-08-11 15:23 ` Darrick J. Wong
2025-08-11 18:06 ` Andrey Albershteyn
2025-08-11 17:51 ` Zorro Lang
2025-08-11 18:12 ` Andrey Albershteyn
2025-08-08 19:31 ` [PATCH 2/3] generic: introduce test to test file_getattr/file_setattr syscalls Andrey Albershteyn
2025-08-11 15:17 ` Darrick J. Wong
2025-08-11 18:13 ` Andrey Albershteyn
2025-08-11 17:55 ` Zorro Lang
2025-08-11 18:18 ` Andrey Albershteyn
2025-08-11 18:43 ` Zorro Lang
2025-08-08 19:31 ` [PATCH 3/3] xfs: test quota's project ID on special files Andrey Albershteyn
2025-08-11 15:21 ` Darrick J. Wong
2025-08-11 18:21 ` Andrey Albershteyn
2025-08-11 17:46 ` Zorro Lang
2025-08-11 18:20 ` Andrey Albershteyn
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=20250811150747.GB7965@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@kernel.org \
--cc=aalbersh@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.