From: Andrey Albershteyn <aalbersh@redhat.com>
To: linux-fsdevel@vgre.kernel.org, linux-xfs@vger.kernel.org
Cc: Andrey Albershteyn <aalbersh@redhat.com>
Subject: [PATCH] libxfs/quota: utilize XFS_IOC_SETFSXATTRAT to set prjid on special files
Date: Thu, 9 May 2024 17:17:15 +0200 [thread overview]
Message-ID: <20240509151714.3623695-2-aalbersh@redhat.com> (raw)
Utilize new XFS ioctl to set project ID on special files.
Previously, special files were skipped due to lack of the way to
call FS_IOC_SETFSXATTR on them. The quota accounting was therefore
missing a few inodes (special files created before project setup).
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
libxfs/xfs_fs.h | 11 ++++
quota/project.c | 139 +++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 144 insertions(+), 6 deletions(-)
diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h
index 6360073865db..1a560dfa7e15 100644
--- a/libxfs/xfs_fs.h
+++ b/libxfs/xfs_fs.h
@@ -662,6 +662,15 @@ typedef struct xfs_swapext
struct xfs_bstat sx_stat; /* stat of target b4 copy */
} xfs_swapext_t;
+/*
+ * Structure passed to XFS_IOC_GETFSXATTRAT/XFS_IOC_GETFSXATTRAT
+ */
+struct xfs_xattrat_req {
+ struct fsxattr __user *fsx; /* XATTR to get/set */
+ __u32 dfd; /* parent dir */
+ const char __user *path; /* NUL terminated path */
+};
+
/*
* Flags for going down operation
*/
@@ -837,6 +846,8 @@ struct xfs_scrub_metadata {
#define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom)
#define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req)
#define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req)
+#define XFS_IOC_GETFSXATTRAT _IOR ('X', 130, struct xfs_xattrat_req)
+#define XFS_IOC_SETFSXATTRAT _IOW ('X', 131, struct xfs_xattrat_req)
/* XFS_IOC_GETFSUUID ---------- deprecated 140 */
diff --git a/quota/project.c b/quota/project.c
index adb26945fa57..e6059db93a77 100644
--- a/quota/project.c
+++ b/quota/project.c
@@ -12,6 +12,8 @@
static cmdinfo_t project_cmd;
static prid_t prid;
static int recurse_depth = -1;
+static int dfd;
+static int dlen;
enum {
CHECK_PROJECT = 0x1,
@@ -78,6 +80,42 @@ project_help(void)
"\n"));
}
+static int
+check_special_file(
+ const char *path,
+ const struct stat *stat,
+ int flag,
+ struct FTW *data)
+{
+ int error;
+ struct fsxattr fa;
+ struct xfs_xattrat_req xreq = {
+ .fsx = &fa,
+ .dfd = dfd,
+ .path = path + (data->level ? dlen + 1 : 0),
+ };
+
+ error = xfsctl(path, dfd, XFS_IOC_GETFSXATTRAT, &xreq);
+ if (error == -ENOTTY) {
+ fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
+ return 0;
+ }
+
+ if (error) {
+ exitcode = 1;
+ fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
+ progname, path, strerror(errno));
+ return 0;
+ }
+
+ if (xreq.fsx->fsx_projid != prid)
+ printf(_("%s - project identifier is not set"
+ " (inode=%u, tree=%u)\n"),
+ path, xreq.fsx->fsx_projid, (unsigned int)prid);
+
+ return 0;
+}
+
static int
check_project(
const char *path,
@@ -97,8 +135,7 @@ check_project(
return 0;
}
if (EXCLUDED_FILE_TYPES(stat->st_mode)) {
- fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
- return 0;
+ return check_special_file(path, stat, flag, data);
}
if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
@@ -123,6 +160,48 @@ check_project(
return 0;
}
+static int
+clear_special_file(
+ const char *path,
+ const struct stat *stat,
+ int flag,
+ struct FTW *data)
+{
+ int error;
+ struct fsxattr fa;
+ struct xfs_xattrat_req xreq = {
+ .fsx = &fa,
+ .dfd = dfd,
+ .path = path + (data->level ? dlen + 1 : 0),
+ };
+
+ error = xfsctl(path, dfd, XFS_IOC_GETFSXATTRAT, &xreq);
+ if (error == -ENOTTY) {
+ fprintf(stderr, _("%s: skipping special file %s\n"),
+ progname, path);
+ return 0;
+ }
+
+ if (error) {
+ exitcode = 1;
+ fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
+ progname, path, strerror(errno));
+ return 0;
+ }
+
+ xreq.fsx->fsx_projid = 0;
+ xreq.fsx->fsx_xflags &= ~FS_XFLAG_PROJINHERIT;
+ error = xfsctl(path, dfd, XFS_IOC_SETFSXATTRAT, &xreq);
+ if (error) {
+ exitcode = 1;
+ fprintf(stderr, _("%s: cannot clear project on %s: %s\n"),
+ progname, path, strerror(errno));
+ return 0;
+ }
+
+ return 0;
+}
+
static int
clear_project(
const char *path,
@@ -142,8 +221,7 @@ clear_project(
return 0;
}
if (EXCLUDED_FILE_TYPES(stat->st_mode)) {
- fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
- return 0;
+ return clear_special_file(path, stat, flag, data);
}
if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
@@ -170,6 +248,47 @@ clear_project(
return 0;
}
+static int
+setup_special_file(
+ const char *path,
+ const struct stat *stat,
+ int flag,
+ struct FTW *data)
+{
+ int error;
+ struct fsxattr fa;
+ struct xfs_xattrat_req xreq = {
+ .fsx = &fa,
+ .dfd = dfd,
+ /* Cut path to parent - make it relative to the dfd */
+ .path = path + (data->level ? dlen + 1 : 0),
+ };
+
+ error = xfsctl(path, dfd, XFS_IOC_GETFSXATTRAT, &xreq);
+ if (error == -ENOTTY) {
+ fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
+ return 0;
+ }
+
+ if (error) {
+ exitcode = 1;
+ fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
+ progname, path, strerror(errno));
+ return 0;
+ }
+ xreq.fsx->fsx_projid = prid;
+ xreq.fsx->fsx_xflags |= FS_XFLAG_PROJINHERIT;
+ error = xfsctl(path, dfd, XFS_IOC_SETFSXATTRAT, &xreq);
+ if (error) {
+ exitcode = 1;
+ fprintf(stderr, _("%s: cannot set project on %s: %s\n"),
+ progname, path, strerror(errno));
+ return 0;
+ }
+
+ return 0;
+}
+
static int
setup_project(
const char *path,
@@ -189,8 +308,7 @@ setup_project(
return 0;
}
if (EXCLUDED_FILE_TYPES(stat->st_mode)) {
- fprintf(stderr, _("%s: skipping special file %s\n"), progname, path);
- return 0;
+ return setup_special_file(path, stat, flag, data);
}
if ((fd = open(path, O_RDONLY|O_NOCTTY)) == -1) {
@@ -223,6 +341,13 @@ project_operations(
char *dir,
int type)
{
+ if ((dfd = open(dir, O_RDONLY|O_NOCTTY)) == -1) {
+ printf(_("Error opening dir %s for project %s...\n"), dir,
+ project);
+ return;
+ }
+ dlen = strlen(dir);
+
switch (type) {
case CHECK_PROJECT:
printf(_("Checking project %s (path %s)...\n"), project, dir);
@@ -237,6 +362,8 @@ project_operations(
nftw(dir, clear_project, 100, FTW_PHYS|FTW_MOUNT);
break;
}
+
+ close(dfd);
}
static void
--
2.42.0
next reply other threads:[~2024-05-09 15:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 15:17 Andrey Albershteyn [this message]
2024-05-09 23:41 ` [PATCH] libxfs/quota: utilize XFS_IOC_SETFSXATTRAT to set prjid on special files Darrick J. Wong
2024-05-10 9:39 ` 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=20240509151714.3623695-2-aalbersh@redhat.com \
--to=aalbersh@redhat.com \
--cc=linux-fsdevel@vgre.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).