* [PATCH 0/3 V3] xfs_io: hook up statx
@ 2017-04-06 18:43 Eric Sandeen
2017-04-06 18:46 ` [PATCH 1/3] xfs_io: move stat functions to new file Eric Sandeen
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Eric Sandeen @ 2017-04-06 18:43 UTC (permalink / raw)
To: linux-xfs, fsdevel, David Howells
These 3 patches are a third pass to add a statx command
to xfs_io in hopes that it will aid creation of xfstests
statx regression tests.
bare "statx" output should look just like bare "stat" output.
xfs_io> help statx
statx [-v|-r][-m basic | -m all | -m <mask>][-FD] -- extended statistics on the currently open file
Display extended file status.
Options:
-v -- More verbose output
-r -- Print raw statx structure fields
-m mask -- Specify the field mask for the statx call
(can also be 'basic' or 'all'; default STATX_ALL)
-D -- Don't sync attributes with the server
-F -- Force the attributes to be sync'd with the server
xfs_io> statx -r
stat.mask = 0x7ff
stat.blksize = 4096
stat.attributes = 0x0
stat.nlink = 1
stat.uid = 0
stat.gid = 0
stat.mode: 0100644
stat.ino = 3905768
stat.size = 4691
stat.blocks = 16
stat.atime.tv_sec = 1491338515
stat.atime.tv_nsec = 564190075
stat.btime.tv_sec = 0
stat.btime.tv_nsec = 0
stat.ctime.tv_sec = 1489602207
stat.ctime.tv_nsec = 556521524
stat.mtime.tv_sec = 1489602207
stat.mtime.tv_nsec = 556521524
stat.rdev_major = 0
stat.rdev_minor = 0
stat.dev_major = 8
stat.dev_minor = 33
patch 2 factors out some stat functionality, and adds a
raw stat(2) dumper for consistency.
patch 3 implements the statx stuff, and includes a header file
with lots of the new #defines so this can build on older systems;
eventually that can be removed perhaps.
An interesting limitation of all of the xfs_io stat
variants is that they currently can't stat any file that
they can't open, which may or may not be a limitation that
we care about....
-Eric
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] xfs_io: move stat functions to new file
2017-04-06 18:43 [PATCH 0/3 V3] xfs_io: hook up statx Eric Sandeen
@ 2017-04-06 18:46 ` Eric Sandeen
2017-04-10 21:47 ` Darrick J. Wong
2017-04-06 18:48 ` [PATCH 2/3] xfs_io: refactor stat functions, add raw dump Eric Sandeen
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Eric Sandeen @ 2017-04-06 18:46 UTC (permalink / raw)
To: linux-xfs, fsdevel, David Howells
Adding statx will add a bit of code, so break stat-related
functions out of open.c into their own new file.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
V3: remember to call stat_init()!
diff --git a/io/Makefile b/io/Makefile
index 32df568..435ccff 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -11,7 +11,7 @@ HFILES = init.h io.h
CFILES = init.c \
attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
- pwrite.c reflink.c seek.c shutdown.c sync.c truncate.c utimes.c
+ pwrite.c reflink.c seek.c shutdown.c stat.c sync.c truncate.c utimes.c
LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBPTHREAD)
LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE)
diff --git a/io/init.c b/io/init.c
index 06002e6..c15a1e1 100644
--- a/io/init.c
+++ b/io/init.c
@@ -86,6 +86,7 @@ init_commands(void)
seek_init();
sendfile_init();
shutdown_init();
+ stat_init();
sync_init();
sync_range_init();
truncate_init();
diff --git a/io/io.h b/io/io.h
index c40aad0..952bdb8 100644
--- a/io/io.h
+++ b/io/io.h
@@ -53,7 +53,7 @@ extern fileio_t *filetable; /* open file table */
extern int filecount; /* number of open files */
extern fileio_t *file; /* active file in file table */
extern int filelist_f(void);
-
+extern int stat_f(int argc, char **argv);
/*
* Memory mapped file regions
*/
@@ -112,6 +112,7 @@ extern void pwrite_init(void);
extern void quit_init(void);
extern void seek_init(void);
extern void shutdown_init(void);
+extern void stat_init(void);
extern void sync_init(void);
extern void truncate_init(void);
extern void utimes_init(void);
diff --git a/io/open.c b/io/open.c
index 941fdc1..2ed55cf 100644
--- a/io/open.c
+++ b/io/open.c
@@ -39,9 +39,7 @@
#endif
static cmdinfo_t open_cmd;
-static cmdinfo_t stat_cmd;
static cmdinfo_t close_cmd;
-static cmdinfo_t statfs_cmd;
static cmdinfo_t chproj_cmd;
static cmdinfo_t lsproj_cmd;
static cmdinfo_t extsize_cmd;
@@ -49,96 +47,6 @@ static cmdinfo_t inode_cmd;
static prid_t prid;
static long extsize;
-off64_t
-filesize(void)
-{
- struct stat st;
-
- if (fstat(file->fd, &st) < 0) {
- perror("fstat");
- return -1;
- }
- return st.st_size;
-}
-
-static char *
-filetype(mode_t mode)
-{
- switch (mode & S_IFMT) {
- case S_IFSOCK:
- return _("socket");
- case S_IFDIR:
- return _("directory");
- case S_IFCHR:
- return _("char device");
- case S_IFBLK:
- return _("block device");
- case S_IFREG:
- return _("regular file");
- case S_IFLNK:
- return _("symbolic link");
- case S_IFIFO:
- return _("fifo");
- }
- return NULL;
-}
-
-static int
-stat_f(
- int argc,
- char **argv)
-{
- struct dioattr dio;
- struct fsxattr fsx, fsxa;
- struct stat st;
- int verbose = (argc == 2 && !strcmp(argv[1], "-v"));
-
- printf(_("fd.path = \"%s\"\n"), file->name);
- printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
- file->flags & IO_OSYNC ? _("sync") : _("non-sync"),
- file->flags & IO_DIRECT ? _("direct") : _("non-direct"),
- file->flags & IO_READONLY ? _("read-only") : _("read-write"),
- file->flags & IO_REALTIME ? _(",real-time") : "",
- file->flags & IO_APPEND ? _(",append-only") : "",
- file->flags & IO_NONBLOCK ? _(",non-block") : "",
- file->flags & IO_TMPFILE ? _(",tmpfile") : "");
- if (fstat(file->fd, &st) < 0) {
- perror("fstat");
- } else {
- printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
- printf(_("stat.type = %s\n"), filetype(st.st_mode));
- printf(_("stat.size = %lld\n"), (long long)st.st_size);
- printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
- if (verbose) {
- printf(_("stat.atime = %s"), ctime(&st.st_atime));
- printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
- printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
- }
- }
- if (file->flags & IO_FOREIGN)
- return 0;
- if ((xfsctl(file->name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0 ||
- (xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTRA, &fsxa)) < 0) {
- perror("FS_IOC_FSGETXATTR");
- } else {
- printf(_("fsxattr.xflags = 0x%x "), fsx.fsx_xflags);
- printxattr(fsx.fsx_xflags, verbose, 0, file->name, 1, 1);
- printf(_("fsxattr.projid = %u\n"), fsx.fsx_projid);
- printf(_("fsxattr.extsize = %u\n"), fsx.fsx_extsize);
- printf(_("fsxattr.cowextsize = %u\n"), fsx.fsx_cowextsize);
- printf(_("fsxattr.nextents = %u\n"), fsx.fsx_nextents);
- printf(_("fsxattr.naextents = %u\n"), fsxa.fsx_nextents);
- }
- if ((xfsctl(file->name, file->fd, XFS_IOC_DIOINFO, &dio)) < 0) {
- perror("XFS_IOC_DIOINFO");
- } else {
- printf(_("dioattr.mem = 0x%x\n"), dio.d_mem);
- printf(_("dioattr.miniosz = %u\n"), dio.d_miniosz);
- printf(_("dioattr.maxiosz = %u\n"), dio.d_maxiosz);
- }
- return 0;
-}
-
int
openfile(
char *path,
@@ -697,58 +605,6 @@ extsize_f(
return 0;
}
-static int
-statfs_f(
- int argc,
- char **argv)
-{
- struct xfs_fsop_counts fscounts;
- struct xfs_fsop_geom fsgeo;
- struct statfs st;
-
- printf(_("fd.path = \"%s\"\n"), file->name);
- if (platform_fstatfs(file->fd, &st) < 0) {
- perror("fstatfs");
- } else {
- printf(_("statfs.f_bsize = %lld\n"), (long long) st.f_bsize);
- printf(_("statfs.f_blocks = %lld\n"), (long long) st.f_blocks);
- printf(_("statfs.f_bavail = %lld\n"), (long long) st.f_bavail);
- printf(_("statfs.f_files = %lld\n"), (long long) st.f_files);
- printf(_("statfs.f_ffree = %lld\n"), (long long) st.f_ffree);
- }
- if (file->flags & IO_FOREIGN)
- return 0;
- if ((xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) {
- perror("XFS_IOC_FSGEOMETRY_V1");
- } else {
- printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
- printf(_("geom.agcount = %u\n"), fsgeo.agcount);
- printf(_("geom.agblocks = %u\n"), fsgeo.agblocks);
- printf(_("geom.datablocks = %llu\n"),
- (unsigned long long) fsgeo.datablocks);
- printf(_("geom.rtblocks = %llu\n"),
- (unsigned long long) fsgeo.rtblocks);
- printf(_("geom.rtextents = %llu\n"),
- (unsigned long long) fsgeo.rtextents);
- printf(_("geom.rtextsize = %u\n"), fsgeo.rtextsize);
- printf(_("geom.sunit = %u\n"), fsgeo.sunit);
- printf(_("geom.swidth = %u\n"), fsgeo.swidth);
- }
- if ((xfsctl(file->name, file->fd, XFS_IOC_FSCOUNTS, &fscounts)) < 0) {
- perror("XFS_IOC_FSCOUNTS");
- } else {
- printf(_("counts.freedata = %llu\n"),
- (unsigned long long) fscounts.freedata);
- printf(_("counts.freertx = %llu\n"),
- (unsigned long long) fscounts.freertx);
- printf(_("counts.freeino = %llu\n"),
- (unsigned long long) fscounts.freeino);
- printf(_("counts.allocino = %llu\n"),
- (unsigned long long) fscounts.allocino);
- }
- return 0;
-}
-
static void
inode_help(void)
{
@@ -920,14 +776,6 @@ open_init(void)
open_cmd.oneline = _("open the file specified by path");
open_cmd.help = open_help;
- stat_cmd.name = "stat";
- stat_cmd.cfunc = stat_f;
- stat_cmd.argmin = 0;
- stat_cmd.argmax = 1;
- stat_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
- stat_cmd.args = _("[-v]");
- stat_cmd.oneline = _("statistics on the currently open file");
-
close_cmd.name = "close";
close_cmd.altname = "c";
close_cmd.cfunc = close_f;
@@ -936,12 +784,6 @@ open_init(void)
close_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK | CMD_FLAG_ONESHOT;
close_cmd.oneline = _("close the current open file");
- statfs_cmd.name = "statfs";
- statfs_cmd.cfunc = statfs_f;
- statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
- statfs_cmd.oneline =
- _("statistics on the filesystem of the currently open file");
-
chproj_cmd.name = "chproj";
chproj_cmd.cfunc = chproj_f;
chproj_cmd.args = _("[-D | -R] projid");
@@ -983,9 +825,7 @@ open_init(void)
inode_cmd.help = inode_help;
add_command(&open_cmd);
- add_command(&stat_cmd);
add_command(&close_cmd);
- add_command(&statfs_cmd);
add_command(&chproj_cmd);
add_command(&lsproj_cmd);
add_command(&extsize_cmd);
diff --git a/io/stat.c b/io/stat.c
new file mode 100644
index 0000000..3ae9903
--- /dev/null
+++ b/io/stat.c
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2003-2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+#include "libxfs.h"
+
+static cmdinfo_t stat_cmd;
+static cmdinfo_t statfs_cmd;
+
+off64_t
+filesize(void)
+{
+ struct stat st;
+
+ if (fstat(file->fd, &st) < 0) {
+ perror("fstat");
+ return -1;
+ }
+ return st.st_size;
+}
+
+static char *
+filetype(mode_t mode)
+{
+ switch (mode & S_IFMT) {
+ case S_IFSOCK:
+ return _("socket");
+ case S_IFDIR:
+ return _("directory");
+ case S_IFCHR:
+ return _("char device");
+ case S_IFBLK:
+ return _("block device");
+ case S_IFREG:
+ return _("regular file");
+ case S_IFLNK:
+ return _("symbolic link");
+ case S_IFIFO:
+ return _("fifo");
+ }
+ return NULL;
+}
+
+int
+stat_f(
+ int argc,
+ char **argv)
+{
+ struct dioattr dio;
+ struct fsxattr fsx, fsxa;
+ struct stat st;
+ int verbose = (argc == 2 && !strcmp(argv[1], "-v"));
+
+ printf(_("fd.path = \"%s\"\n"), file->name);
+ printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
+ file->flags & IO_OSYNC ? _("sync") : _("non-sync"),
+ file->flags & IO_DIRECT ? _("direct") : _("non-direct"),
+ file->flags & IO_READONLY ? _("read-only") : _("read-write"),
+ file->flags & IO_REALTIME ? _(",real-time") : "",
+ file->flags & IO_APPEND ? _(",append-only") : "",
+ file->flags & IO_NONBLOCK ? _(",non-block") : "",
+ file->flags & IO_TMPFILE ? _(",tmpfile") : "");
+ if (fstat(file->fd, &st) < 0) {
+ perror("fstat");
+ } else {
+ printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
+ printf(_("stat.type = %s\n"), filetype(st.st_mode));
+ printf(_("stat.size = %lld\n"), (long long)st.st_size);
+ printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
+ if (verbose) {
+ printf(_("stat.atime = %s"), ctime(&st.st_atime));
+ printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
+ printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
+ }
+ }
+ if (file->flags & IO_FOREIGN)
+ return 0;
+ if ((xfsctl(file->name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0 ||
+ (xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTRA, &fsxa)) < 0) {
+ perror("FS_IOC_FSGETXATTR");
+ } else {
+ printf(_("fsxattr.xflags = 0x%x "), fsx.fsx_xflags);
+ printxattr(fsx.fsx_xflags, verbose, 0, file->name, 1, 1);
+ printf(_("fsxattr.projid = %u\n"), fsx.fsx_projid);
+ printf(_("fsxattr.extsize = %u\n"), fsx.fsx_extsize);
+ printf(_("fsxattr.cowextsize = %u\n"), fsx.fsx_cowextsize);
+ printf(_("fsxattr.nextents = %u\n"), fsx.fsx_nextents);
+ printf(_("fsxattr.naextents = %u\n"), fsxa.fsx_nextents);
+ }
+ if ((xfsctl(file->name, file->fd, XFS_IOC_DIOINFO, &dio)) < 0) {
+ perror("XFS_IOC_DIOINFO");
+ } else {
+ printf(_("dioattr.mem = 0x%x\n"), dio.d_mem);
+ printf(_("dioattr.miniosz = %u\n"), dio.d_miniosz);
+ printf(_("dioattr.maxiosz = %u\n"), dio.d_maxiosz);
+ }
+ return 0;
+}
+
+static int
+statfs_f(
+ int argc,
+ char **argv)
+{
+ struct xfs_fsop_counts fscounts;
+ struct xfs_fsop_geom fsgeo;
+ struct statfs st;
+
+ printf(_("fd.path = \"%s\"\n"), file->name);
+ if (platform_fstatfs(file->fd, &st) < 0) {
+ perror("fstatfs");
+ } else {
+ printf(_("statfs.f_bsize = %lld\n"), (long long) st.f_bsize);
+ printf(_("statfs.f_blocks = %lld\n"), (long long) st.f_blocks);
+ printf(_("statfs.f_bavail = %lld\n"), (long long) st.f_bavail);
+ printf(_("statfs.f_files = %lld\n"), (long long) st.f_files);
+ printf(_("statfs.f_ffree = %lld\n"), (long long) st.f_ffree);
+ }
+ if (file->flags & IO_FOREIGN)
+ return 0;
+ if ((xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) {
+ perror("XFS_IOC_FSGEOMETRY_V1");
+ } else {
+ printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
+ printf(_("geom.agcount = %u\n"), fsgeo.agcount);
+ printf(_("geom.agblocks = %u\n"), fsgeo.agblocks);
+ printf(_("geom.datablocks = %llu\n"),
+ (unsigned long long) fsgeo.datablocks);
+ printf(_("geom.rtblocks = %llu\n"),
+ (unsigned long long) fsgeo.rtblocks);
+ printf(_("geom.rtextents = %llu\n"),
+ (unsigned long long) fsgeo.rtextents);
+ printf(_("geom.rtextsize = %u\n"), fsgeo.rtextsize);
+ printf(_("geom.sunit = %u\n"), fsgeo.sunit);
+ printf(_("geom.swidth = %u\n"), fsgeo.swidth);
+ }
+ if ((xfsctl(file->name, file->fd, XFS_IOC_FSCOUNTS, &fscounts)) < 0) {
+ perror("XFS_IOC_FSCOUNTS");
+ } else {
+ printf(_("counts.freedata = %llu\n"),
+ (unsigned long long) fscounts.freedata);
+ printf(_("counts.freertx = %llu\n"),
+ (unsigned long long) fscounts.freertx);
+ printf(_("counts.freeino = %llu\n"),
+ (unsigned long long) fscounts.freeino);
+ printf(_("counts.allocino = %llu\n"),
+ (unsigned long long) fscounts.allocino);
+ }
+ return 0;
+}
+
+void
+stat_init(void)
+{
+ stat_cmd.name = "stat";
+ stat_cmd.cfunc = stat_f;
+ stat_cmd.argmin = 0;
+ stat_cmd.argmax = 1;
+ stat_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+ stat_cmd.args = _("[-v]");
+ stat_cmd.oneline = _("statistics on the currently open file");
+
+ statfs_cmd.name = "statfs";
+ statfs_cmd.cfunc = statfs_f;
+ statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+ statfs_cmd.oneline =
+ _("statistics on the filesystem of the currently open file");
+
+ add_command(&stat_cmd);
+ add_command(&statfs_cmd);
+}
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3] xfs_io: refactor stat functions, add raw dump
2017-04-06 18:43 [PATCH 0/3 V3] xfs_io: hook up statx Eric Sandeen
2017-04-06 18:46 ` [PATCH 1/3] xfs_io: move stat functions to new file Eric Sandeen
@ 2017-04-06 18:48 ` Eric Sandeen
2017-04-10 21:48 ` Darrick J. Wong
2017-04-06 18:53 ` [PATCH 3/3] xfs_io: hook up statx Eric Sandeen
2017-04-10 22:36 ` [PATCH 0/3 V3] " David Howells
3 siblings, 1 reply; 11+ messages in thread
From: Eric Sandeen @ 2017-04-06 18:48 UTC (permalink / raw)
To: linux-xfs, fsdevel, David Howells
This adds a "-r" raw structure dump to stat options, and
factors the code a bit; statx will also use print_file_info
and print_xfs_info.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/io/stat.c b/io/stat.c
index 3ae9903..770f3c7 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -59,16 +59,32 @@ filetype(mode_t mode)
return NULL;
}
-int
-stat_f(
- int argc,
- char **argv)
+static int
+dump_raw_stat(struct stat *st)
{
- struct dioattr dio;
- struct fsxattr fsx, fsxa;
- struct stat st;
- int verbose = (argc == 2 && !strcmp(argv[1], "-v"));
+ printf("stat.blksize = %lu\n", st->st_blksize);
+ printf("stat.nlink = %lu\n", st->st_nlink);
+ printf("stat.uid = %u\n", st->st_uid);
+ printf("stat.gid = %u\n", st->st_gid);
+ printf("stat.mode: 0%o\n", st->st_mode);
+ printf("stat.ino = %lu\n", st->st_ino);
+ printf("stat.size = %lu\n", st->st_size);
+ printf("stat.blocks = %lu\n", st->st_blocks);
+ printf("stat.atime.tv_sec = %ld\n", st->st_atim.tv_sec);
+ printf("stat.atime.tv_nsec = %ld\n", st->st_atim.tv_nsec);
+ printf("stat.ctime.tv_sec = %ld\n", st->st_ctim.tv_sec);
+ printf("stat.ctime.tv_nsec = %ld\n", st->st_ctim.tv_nsec);
+ printf("stat.mtime.tv_sec = %ld\n", st->st_mtim.tv_sec);
+ printf("stat.mtime.tv_nsec = %ld\n", st->st_mtim.tv_nsec);
+ printf("stat.rdev_major = %u\n", major(st->st_rdev));
+ printf("stat.rdev_minor = %u\n", minor(st->st_rdev));
+ printf("stat.dev_major = %u\n", major(st->st_dev));
+ printf("stat.dev_minor = %u\n", minor(st->st_dev));
+ return 0;
+}
+void print_file_info(void)
+{
printf(_("fd.path = \"%s\"\n"), file->name);
printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
file->flags & IO_OSYNC ? _("sync") : _("non-sync"),
@@ -78,21 +94,13 @@ stat_f(
file->flags & IO_APPEND ? _(",append-only") : "",
file->flags & IO_NONBLOCK ? _(",non-block") : "",
file->flags & IO_TMPFILE ? _(",tmpfile") : "");
- if (fstat(file->fd, &st) < 0) {
- perror("fstat");
- } else {
- printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
- printf(_("stat.type = %s\n"), filetype(st.st_mode));
- printf(_("stat.size = %lld\n"), (long long)st.st_size);
- printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
- if (verbose) {
- printf(_("stat.atime = %s"), ctime(&st.st_atime));
- printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
- printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
- }
- }
- if (file->flags & IO_FOREIGN)
- return 0;
+}
+
+void print_xfs_info(int verbose)
+{
+ struct dioattr dio;
+ struct fsxattr fsx, fsxa;
+
if ((xfsctl(file->name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0 ||
(xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTRA, &fsxa)) < 0) {
perror("FS_IOC_FSGETXATTR");
@@ -112,6 +120,57 @@ stat_f(
printf(_("dioattr.miniosz = %u\n"), dio.d_miniosz);
printf(_("dioattr.maxiosz = %u\n"), dio.d_maxiosz);
}
+}
+
+int
+stat_f(
+ int argc,
+ char **argv)
+{
+ struct stat st;
+ int c, verbose = 0, raw = 0;
+
+ while ((c = getopt(argc, argv, "rv")) != EOF) {
+ switch (c) {
+ case 'r':
+ raw = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ return command_usage(&stat_cmd);
+ }
+ }
+
+ if (raw && verbose)
+ return command_usage(&stat_cmd);
+
+ if (fstat(file->fd, &st) < 0) {
+ perror("fstat");
+ return 0;
+ }
+
+ if (raw)
+ return dump_raw_stat(&st);
+
+ print_file_info();
+
+ printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
+ printf(_("stat.type = %s\n"), filetype(st.st_mode));
+ printf(_("stat.size = %lld\n"), (long long)st.st_size);
+ printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
+ if (verbose) {
+ printf(_("stat.atime = %s"), ctime(&st.st_atime));
+ printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
+ printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
+ }
+
+ if (file->flags & IO_FOREIGN)
+ return 0;
+
+ print_xfs_info(verbose);
+
return 0;
}
@@ -175,7 +234,7 @@ stat_init(void)
stat_cmd.argmin = 0;
stat_cmd.argmax = 1;
stat_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
- stat_cmd.args = _("[-v]");
+ stat_cmd.args = _("[-v|-r]");
stat_cmd.oneline = _("statistics on the currently open file");
statfs_cmd.name = "statfs";
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index 19e1ae4..e384327 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -872,13 +872,15 @@ Only available in expert mode and requires privileges.
Force the filesystem to shutdown (with or without flushing the log).
Only available in expert mode and requires privileges.
.TP
-.BR stat " [ " \-v " ]"
+.BR stat " [ " \-v "|" \-r " ]"
Selected statistics from
.BR stat (2)
and the XFS_IOC_GETXATTR system call on the current file. If the
.B \-v
option is specified, the atime (last access), mtime
-(last modify), and ctime (last change) timestamps are also displayed.
+(last modify), and ctime (last change) timestamps are also displayed. The
+.B \-r
+option dumps raw fields from the stat structure.
.TP
.B statfs
Selected statistics from
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3] xfs_io: hook up statx
2017-04-06 18:43 [PATCH 0/3 V3] xfs_io: hook up statx Eric Sandeen
2017-04-06 18:46 ` [PATCH 1/3] xfs_io: move stat functions to new file Eric Sandeen
2017-04-06 18:48 ` [PATCH 2/3] xfs_io: refactor stat functions, add raw dump Eric Sandeen
@ 2017-04-06 18:53 ` Eric Sandeen
2017-04-10 21:33 ` [PATCH 3/3 V4] " Eric Sandeen
2017-04-10 22:36 ` [PATCH 0/3 V3] " David Howells
3 siblings, 1 reply; 11+ messages in thread
From: Eric Sandeen @ 2017-04-06 18:53 UTC (permalink / raw)
To: linux-xfs, fsdevel, David Howells
Wire up the statx syscall to xfs_io.
xfs_io> help statx
statx [-v|-r][-m basic | -m all | -m <mask>][-FD] -- extended statistics on the currently open file
Display extended file status.
Options:
-v -- More verbose output
-r -- Print raw statx structure fields
-m mask -- Specify the field mask for the statx call
(can also be 'basic' or 'all'; default STATX_ALL)
-D -- Don't sync attributes with the server
-F -- Force the attributes to be sync'd with the server
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
V3: remove -A, -L, and -O options
allow "basic" and "all" masks
change raw dump format to match stat raw format
make -r and -v exclusive
follow factoring of stat_f()
diff --git a/io/stat.c b/io/stat.c
index 770f3c7..64d4638 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -2,6 +2,9 @@
* Copyright (c) 2003-2005 Silicon Graphics, Inc.
* All Rights Reserved.
*
+ * Copyright (C) 2015, 2017 Red Hat, Inc.
+ * Portions of statx support written by David Howells (dhowells@redhat.com)
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
@@ -20,10 +23,14 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "statx.h"
#include "libxfs.h"
+#include <fcntl.h>
+
static cmdinfo_t stat_cmd;
static cmdinfo_t statfs_cmd;
+static cmdinfo_t statx_cmd;
off64_t
filesize(void)
@@ -226,6 +233,146 @@ statfs_f(
return 0;
}
+static ssize_t
+_statx(int dfd, const char *filename, unsigned flags,
+ unsigned int mask, struct statx *buffer)
+{
+ return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
+}
+
+static void
+statx_help(void)
+{
+ printf(_(
+"\n"
+" Display extended file status.\n"
+"\n"
+" Options:\n"
+" -v -- More verbose output\n"
+" -r -- Print raw statx structure fields\n"
+" -m mask -- Specify the field mask for the statx call\n"
+" (can also be 'basic' or 'all'; default STATX_ALL)\n"
+" -D -- Don't sync attributes with the server\n"
+" -F -- Force the attributes to be sync'd with the server\n"
+"\n"));
+}
+
+/* statx helper */
+static int
+dump_raw_statx(struct statx *stx)
+{
+ printf("stat.mask = 0x%x\n", stx->stx_mask);
+ printf("stat.blksize = %u\n", stx->stx_blksize);
+ printf("stat.attributes = 0x%llx\n", stx->stx_attributes);
+ printf("stat.nlink = %u\n", stx->stx_nlink);
+ printf("stat.uid = %u\n", stx->stx_uid);
+ printf("stat.gid = %u\n", stx->stx_gid);
+ printf("stat.mode: 0%o\n", stx->stx_mode);
+ printf("stat.ino = %llu\n", stx->stx_ino);
+ printf("stat.size = %llu\n", stx->stx_size);
+ printf("stat.blocks = %llu\n", stx->stx_blocks);
+ printf("stat.atime.tv_sec = %lld\n", stx->stx_atime.tv_sec);
+ printf("stat.atime.tv_nsec = %d\n", stx->stx_atime.tv_nsec);
+ printf("stat.btime.tv_sec = %lld\n", stx->stx_btime.tv_sec);
+ printf("stat.btime.tv_nsec = %d\n", stx->stx_btime.tv_nsec);
+ printf("stat.ctime.tv_sec = %lld\n", stx->stx_ctime.tv_sec);
+ printf("stat.ctime.tv_nsec = %d\n", stx->stx_ctime.tv_nsec);
+ printf("stat.mtime.tv_sec = %lld\n", stx->stx_mtime.tv_sec);
+ printf("stat.mtime.tv_nsec = %d\n", stx->stx_mtime.tv_nsec);
+ printf("stat.rdev_major = %u\n", stx->stx_rdev_major);
+ printf("stat.rdev_minor = %u\n", stx->stx_rdev_minor);
+ printf("stat.dev_major = %u\n", stx->stx_dev_major);
+ printf("stat.dev_minor = %u\n", stx->stx_dev_minor);
+ return 0;
+}
+
+/*
+ * options:
+ * - input flags - query type
+ * - output style for flags (and all else?) (chars vs. hex?)
+ * - output - mask out incidental flag or not?
+ */
+int
+statx_f(
+ int argc,
+ char **argv)
+{
+ int c, verbose = 0, raw = 0;
+ char *p;
+ struct statx stx;
+ int atflag = 0;
+ unsigned int mask = STATX_ALL;
+
+ while ((c = getopt(argc, argv, "m:rvFD")) != EOF) {
+ switch (c) {
+ case 'm':
+ if (strcmp(optarg, "basic") == 0)
+ mask = STATX_BASIC_STATS;
+ else if (strcmp(optarg, "all") == 0)
+ mask = STATX_ALL;
+ else {
+ mask = strtoul(optarg, &p, 0);
+ if (!p || p == optarg) {
+ printf(
+ _("non-numeric mask -- %s\n"), optarg);
+ return 0;
+ }
+ }
+ break;
+ case 'r':
+ raw = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'F':
+ atflag &= ~AT_STATX_SYNC_TYPE;
+ atflag |= AT_STATX_FORCE_SYNC;
+ break;
+ case 'D':
+ atflag &= ~AT_STATX_SYNC_TYPE;
+ atflag |= AT_STATX_DONT_SYNC;
+ break;
+ default:
+ return command_usage(&statx_cmd);
+ }
+ }
+
+ if (raw && verbose)
+ return command_usage(&statx_cmd);
+
+ memset(&stx, 0xbf, sizeof(stx));
+ if (_statx(file->fd, NULL, atflag, mask, &stx) < 0) {
+ perror("statx");
+ return 0;
+ }
+
+ if (raw)
+ return dump_raw_statx(&stx);
+
+ print_file_info();
+
+ printf(_("stat.ino = %lld\n"), (long long)stx.stx_ino);
+ printf(_("stat.type = %s\n"), filetype(stx.stx_mode));
+ printf(_("stat.size = %lld\n"), (long long)stx.stx_size);
+ printf(_("stat.blocks = %lld\n"), (long long)stx.stx_blocks);
+ if (verbose) {
+ printf(_("stat.atime = %s"), ctime((time_t *)&stx.stx_atime.tv_sec));
+ printf(_("stat.mtime = %s"), ctime((time_t *)&stx.stx_mtime.tv_sec));
+ printf(_("stat.ctime = %s"), ctime((time_t *)&stx.stx_ctime.tv_sec));
+ if (stx.stx_mask & STATX_BTIME)
+ printf(_("stat.btime = %s"),
+ ctime((time_t *)&stx.stx_btime.tv_sec));
+ }
+
+ if (file->flags & IO_FOREIGN)
+ return 0;
+
+ print_xfs_info(verbose);
+
+ return 0;
+}
+
void
stat_init(void)
{
@@ -237,6 +384,15 @@ stat_init(void)
stat_cmd.args = _("[-v|-r]");
stat_cmd.oneline = _("statistics on the currently open file");
+ statx_cmd.name = "statx";
+ statx_cmd.cfunc = statx_f;
+ statx_cmd.argmin = 0;
+ statx_cmd.argmax = -1;
+ statx_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+ statx_cmd.args = _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
+ statx_cmd.oneline = _("extended statistics on the currently open file");
+ statx_cmd.help = statx_help;
+
statfs_cmd.name = "statfs";
statfs_cmd.cfunc = statfs_f;
statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
@@ -244,5 +400,6 @@ stat_init(void)
_("statistics on the filesystem of the currently open file");
add_command(&stat_cmd);
+ add_command(&statx_cmd);
add_command(&statfs_cmd);
}
diff --git a/io/statx.h b/io/statx.h
new file mode 100644
index 0000000..729a147
--- /dev/null
+++ b/io/statx.h
@@ -0,0 +1,158 @@
+#ifndef XFS_IO_STATX_H
+#define XFS_IO_STATX_H
+
+#include <unistd.h>
+
+#ifndef AT_STATX_SYNC_TYPE
+#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
+#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
+#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
+#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
+#endif
+
+#ifndef AT_NO_AUTOMOUNT
+#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
+#endif
+
+#ifdef __i386__
+#define __NR_statx 383
+#elif defined (__ILP32__)
+#define __NR_statx (__X32_SYSCALL_BIT + 332)
+#else
+#define __NR_statx 332
+#endif
+
+#ifndef STATX_TYPE
+
+/*
+ * Timestamp structure for the timestamps in struct statx.
+ *
+ * tv_sec holds the number of seconds before (negative) or after (positive)
+ * 00:00:00 1st January 1970 UTC.
+ *
+ * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
+ * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
+ *
+ * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
+ * either be both positive or both negative.
+ *
+ * __reserved is held in case we need a yet finer resolution.
+ */
+struct statx_timestamp {
+ __s64 tv_sec;
+ __s32 tv_nsec;
+ __s32 __reserved;
+};
+
+/*
+ * Structures for the extended file attribute retrieval system call
+ * (statx()).
+ *
+ * The caller passes a mask of what they're specifically interested in as a
+ * parameter to statx(). What statx() actually got will be indicated in
+ * st_mask upon return.
+ *
+ * For each bit in the mask argument:
+ *
+ * - if the datum is not supported:
+ *
+ * - the bit will be cleared, and
+ *
+ * - the datum will be set to an appropriate fabricated value if one is
+ * available (eg. CIFS can take a default uid and gid), otherwise
+ *
+ * - the field will be cleared;
+ *
+ * - otherwise, if explicitly requested:
+ *
+ * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
+ * set or if the datum is considered out of date, and
+ *
+ * - the field will be filled in and the bit will be set;
+ *
+ * - otherwise, if not requested, but available in approximate form without any
+ * effort, it will be filled in anyway, and the bit will be set upon return
+ * (it might not be up to date, however, and no attempt will be made to
+ * synchronise the internal state first);
+ *
+ * - otherwise the field and the bit will be cleared before returning.
+ *
+ * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
+ * will have values installed for compatibility purposes so that stat() and
+ * co. can be emulated in userspace.
+ */
+struct statx {
+ /* 0x00 */
+ __u32 stx_mask; /* What results were written [uncond] */
+ __u32 stx_blksize; /* Preferred general I/O size [uncond] */
+ __u64 stx_attributes; /* Flags conveying information about the file [uncond] */
+ /* 0x10 */
+ __u32 stx_nlink; /* Number of hard links */
+ __u32 stx_uid; /* User ID of owner */
+ __u32 stx_gid; /* Group ID of owner */
+ __u16 stx_mode; /* File mode */
+ __u16 __spare0[1];
+ /* 0x20 */
+ __u64 stx_ino; /* Inode number */
+ __u64 stx_size; /* File size */
+ __u64 stx_blocks; /* Number of 512-byte blocks allocated */
+ __u64 __spare1[1];
+ /* 0x40 */
+ struct statx_timestamp stx_atime; /* Last access time */
+ struct statx_timestamp stx_btime; /* File creation time */
+ struct statx_timestamp stx_ctime; /* Last attribute change time */
+ struct statx_timestamp stx_mtime; /* Last data modification time */
+ /* 0x80 */
+ __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
+ __u32 stx_rdev_minor;
+ __u32 stx_dev_major; /* ID of device containing file [uncond] */
+ __u32 stx_dev_minor;
+ /* 0x90 */
+ __u64 __spare2[14]; /* Spare space for future expansion */
+ /* 0x100 */
+};
+
+/*
+ * Flags to be stx_mask
+ *
+ * Query request/result mask for statx() and struct statx::stx_mask.
+ *
+ * These bits should be set in the mask argument of statx() to request
+ * particular items when calling statx().
+ */
+#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
+#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
+#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
+#define STATX_UID 0x00000008U /* Want/got stx_uid */
+#define STATX_GID 0x00000010U /* Want/got stx_gid */
+#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
+#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
+#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
+#define STATX_INO 0x00000100U /* Want/got stx_ino */
+#define STATX_SIZE 0x00000200U /* Want/got stx_size */
+#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
+#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
+#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
+#define STATX_ALL 0x00000fffU /* All currently supported flags */
+
+/*
+ * Attributes to be found in stx_attributes
+ *
+ * These give information about the features or the state of a file that might
+ * be of use to ordinary userspace programs such as GUIs or ls rather than
+ * specialised tools.
+ *
+ * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * semantically. Where possible, the numerical value is picked to correspond
+ * also.
+ */
+#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
+#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
+#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
+#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
+#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
+
+#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
+
+#endif /* STATX_TYPE */
+#endif /* XFS_IO_STATX_H */
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index e384327..f732216 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -882,6 +882,36 @@ option is specified, the atime (last access), mtime
.B \-r
option dumps raw fields from the stat structure.
.TP
+.BI "statx [ \-v|\-r ][ \-m " basic " | \-m " all " | -m " <mask> " ][ \-FD ]"
+Selected statistics from
+.BR stat (2)
+and the XFS_IOC_GETXATTR system call on the current file.
+.RS 1.0i
+.PD 0
+.TP 0.4i
+.B \-v
+Show timestamps
+.TP
+.B \-r
+Dump raw statx structure values
+.TP
+.B \-m basic
+Set the field mask for the statx call to STATX_BASIC_STATS
+.TP
+.B \-m all
+Set the the field mask for the statx call to STATX_ALL (default)
+.TP
+.B \-m <mask>
+Specify a numeric field mask for the statx call
+.TP
+.B \-F
+Force the attributes to be synced with the server
+.TP
+.B \-D
+Don't sync attributes with the server
+.PD
+.RE
+.TP
.B statfs
Selected statistics from
.BR statfs (2)
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3 V4] xfs_io: hook up statx
2017-04-06 18:53 ` [PATCH 3/3] xfs_io: hook up statx Eric Sandeen
@ 2017-04-10 21:33 ` Eric Sandeen
2017-04-10 21:56 ` Darrick J. Wong
2017-04-10 22:07 ` [PATCH 3/3 V5] " Eric Sandeen
0 siblings, 2 replies; 11+ messages in thread
From: Eric Sandeen @ 2017-04-10 21:33 UTC (permalink / raw)
To: linux-xfs, fsdevel, David Howells
Wire up the statx syscall to xfs_io.
xfs_io> help statx
statx [-v|-r][-m basic | -m all | -m <mask>][-FD] -- extended statistics on the currently open file
Display extended file status.
Options:
-v -- More verbose output
-r -- Print raw statx structure fields
-m mask -- Specify the field mask for the statx call
(can also be 'basic' or 'all'; default STATX_ALL)
-D -- Don't sync attributes with the server
-F -- Force the attributes to be sync'd with the server
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
V4: Fix up __NR_statx defines, handle it if not defined (ala dhowells testcase)
fix trailing whitespace in manpage :)
V3: remove -A, -L, and -O options
allow "basic" and "all" masks
change raw dump format to match stat raw format
make -r and -v exclusive
follow factoring of stat_f()
diff --git a/io/stat.c b/io/stat.c
index 770f3c7..efd552f 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -2,6 +2,9 @@
* Copyright (c) 2003-2005 Silicon Graphics, Inc.
* All Rights Reserved.
*
+ * Copyright (C) 2015, 2017 Red Hat, Inc.
+ * Portions of statx support written by David Howells (dhowells@redhat.com)
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
@@ -20,10 +23,14 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "statx.h"
#include "libxfs.h"
+#include <fcntl.h>
+
static cmdinfo_t stat_cmd;
static cmdinfo_t statfs_cmd;
+static cmdinfo_t statx_cmd;
off64_t
filesize(void)
@@ -226,6 +233,151 @@ statfs_f(
return 0;
}
+static ssize_t
+_statx(int dfd, const char *filename, unsigned flags,
+ unsigned int mask, struct statx *buffer)
+{
+#ifdef __NR_statx
+ return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+static void
+statx_help(void)
+{
+ printf(_(
+"\n"
+" Display extended file status.\n"
+"\n"
+" Options:\n"
+" -v -- More verbose output\n"
+" -r -- Print raw statx structure fields\n"
+" -m mask -- Specify the field mask for the statx call\n"
+" (can also be 'basic' or 'all'; default STATX_ALL)\n"
+" -D -- Don't sync attributes with the server\n"
+" -F -- Force the attributes to be sync'd with the server\n"
+"\n"));
+}
+
+/* statx helper */
+static int
+dump_raw_statx(struct statx *stx)
+{
+ printf("stat.mask = 0x%x\n", stx->stx_mask);
+ printf("stat.blksize = %u\n", stx->stx_blksize);
+ printf("stat.attributes = 0x%llx\n", stx->stx_attributes);
+ printf("stat.nlink = %u\n", stx->stx_nlink);
+ printf("stat.uid = %u\n", stx->stx_uid);
+ printf("stat.gid = %u\n", stx->stx_gid);
+ printf("stat.mode: 0%o\n", stx->stx_mode);
+ printf("stat.ino = %llu\n", stx->stx_ino);
+ printf("stat.size = %llu\n", stx->stx_size);
+ printf("stat.blocks = %llu\n", stx->stx_blocks);
+ printf("stat.atime.tv_sec = %lld\n", stx->stx_atime.tv_sec);
+ printf("stat.atime.tv_nsec = %d\n", stx->stx_atime.tv_nsec);
+ printf("stat.btime.tv_sec = %lld\n", stx->stx_btime.tv_sec);
+ printf("stat.btime.tv_nsec = %d\n", stx->stx_btime.tv_nsec);
+ printf("stat.ctime.tv_sec = %lld\n", stx->stx_ctime.tv_sec);
+ printf("stat.ctime.tv_nsec = %d\n", stx->stx_ctime.tv_nsec);
+ printf("stat.mtime.tv_sec = %lld\n", stx->stx_mtime.tv_sec);
+ printf("stat.mtime.tv_nsec = %d\n", stx->stx_mtime.tv_nsec);
+ printf("stat.rdev_major = %u\n", stx->stx_rdev_major);
+ printf("stat.rdev_minor = %u\n", stx->stx_rdev_minor);
+ printf("stat.dev_major = %u\n", stx->stx_dev_major);
+ printf("stat.dev_minor = %u\n", stx->stx_dev_minor);
+ return 0;
+}
+
+/*
+ * options:
+ * - input flags - query type
+ * - output style for flags (and all else?) (chars vs. hex?)
+ * - output - mask out incidental flag or not?
+ */
+int
+statx_f(
+ int argc,
+ char **argv)
+{
+ int c, verbose = 0, raw = 0;
+ char *p;
+ struct statx stx;
+ int atflag = 0;
+ unsigned int mask = STATX_ALL;
+
+ while ((c = getopt(argc, argv, "m:rvFD")) != EOF) {
+ switch (c) {
+ case 'm':
+ if (strcmp(optarg, "basic") == 0)
+ mask = STATX_BASIC_STATS;
+ else if (strcmp(optarg, "all") == 0)
+ mask = STATX_ALL;
+ else {
+ mask = strtoul(optarg, &p, 0);
+ if (!p || p == optarg) {
+ printf(
+ _("non-numeric mask -- %s\n"), optarg);
+ return 0;
+ }
+ }
+ break;
+ case 'r':
+ raw = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'F':
+ atflag &= ~AT_STATX_SYNC_TYPE;
+ atflag |= AT_STATX_FORCE_SYNC;
+ break;
+ case 'D':
+ atflag &= ~AT_STATX_SYNC_TYPE;
+ atflag |= AT_STATX_DONT_SYNC;
+ break;
+ default:
+ return command_usage(&statx_cmd);
+ }
+ }
+
+ if (raw && verbose)
+ return command_usage(&statx_cmd);
+
+ memset(&stx, 0xbf, sizeof(stx));
+ if (_statx(file->fd, NULL, atflag, mask, &stx) < 0) {
+ perror("statx");
+ return 0;
+ }
+
+ if (raw)
+ return dump_raw_statx(&stx);
+
+ print_file_info();
+
+ printf(_("stat.ino = %lld\n"), (long long)stx.stx_ino);
+ printf(_("stat.type = %s\n"), filetype(stx.stx_mode));
+ printf(_("stat.size = %lld\n"), (long long)stx.stx_size);
+ printf(_("stat.blocks = %lld\n"), (long long)stx.stx_blocks);
+ if (verbose) {
+ printf(_("stat.atime = %s"), ctime((time_t *)&stx.stx_atime.tv_sec));
+ printf(_("stat.mtime = %s"), ctime((time_t *)&stx.stx_mtime.tv_sec));
+ printf(_("stat.ctime = %s"), ctime((time_t *)&stx.stx_ctime.tv_sec));
+ if (stx.stx_mask & STATX_BTIME)
+ printf(_("stat.btime = %s"),
+ ctime((time_t *)&stx.stx_btime.tv_sec));
+ }
+
+ if (file->flags & IO_FOREIGN)
+ return 0;
+
+ print_xfs_info(verbose);
+
+ return 0;
+}
+
void
stat_init(void)
{
@@ -237,6 +389,15 @@ stat_init(void)
stat_cmd.args = _("[-v|-r]");
stat_cmd.oneline = _("statistics on the currently open file");
+ statx_cmd.name = "statx";
+ statx_cmd.cfunc = statx_f;
+ statx_cmd.argmin = 0;
+ statx_cmd.argmax = -1;
+ statx_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+ statx_cmd.args = _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
+ statx_cmd.oneline = _("extended statistics on the currently open file");
+ statx_cmd.help = statx_help;
+
statfs_cmd.name = "statfs";
statfs_cmd.cfunc = statfs_f;
statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
@@ -244,5 +405,6 @@ stat_init(void)
_("statistics on the filesystem of the currently open file");
add_command(&stat_cmd);
+ add_command(&statx_cmd);
add_command(&statfs_cmd);
}
diff --git a/io/statx.h b/io/statx.h
new file mode 100644
index 0000000..2d919b9
--- /dev/null
+++ b/io/statx.h
@@ -0,0 +1,161 @@
+#ifndef XFS_IO_STATX_H
+#define XFS_IO_STATX_H
+
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#ifndef AT_STATX_SYNC_TYPE
+#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
+#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
+#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
+#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
+#endif
+
+#ifndef AT_NO_AUTOMOUNT
+#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
+#endif
+
+#ifndef __NR_statx
+# ifdef __i386__
+# define __NR_statx 383
+# elif defined (__ILP32__)
+# define __NR_statx (__X32_SYSCALL_BIT + 332)
+# elif defined (__x86_64__)
+# define __NR_statx 332
+# endif
+#endif
+
+#ifndef STATX_TYPE
+
+/*
+ * Timestamp structure for the timestamps in struct statx.
+ *
+ * tv_sec holds the number of seconds before (negative) or after (positive)
+ * 00:00:00 1st January 1970 UTC.
+ *
+ * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
+ * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
+ *
+ * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
+ * either be both positive or both negative.
+ *
+ * __reserved is held in case we need a yet finer resolution.
+ */
+struct statx_timestamp {
+ __s64 tv_sec;
+ __s32 tv_nsec;
+ __s32 __reserved;
+};
+
+/*
+ * Structures for the extended file attribute retrieval system call
+ * (statx()).
+ *
+ * The caller passes a mask of what they're specifically interested in as a
+ * parameter to statx(). What statx() actually got will be indicated in
+ * st_mask upon return.
+ *
+ * For each bit in the mask argument:
+ *
+ * - if the datum is not supported:
+ *
+ * - the bit will be cleared, and
+ *
+ * - the datum will be set to an appropriate fabricated value if one is
+ * available (eg. CIFS can take a default uid and gid), otherwise
+ *
+ * - the field will be cleared;
+ *
+ * - otherwise, if explicitly requested:
+ *
+ * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
+ * set or if the datum is considered out of date, and
+ *
+ * - the field will be filled in and the bit will be set;
+ *
+ * - otherwise, if not requested, but available in approximate form without any
+ * effort, it will be filled in anyway, and the bit will be set upon return
+ * (it might not be up to date, however, and no attempt will be made to
+ * synchronise the internal state first);
+ *
+ * - otherwise the field and the bit will be cleared before returning.
+ *
+ * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
+ * will have values installed for compatibility purposes so that stat() and
+ * co. can be emulated in userspace.
+ */
+struct statx {
+ /* 0x00 */
+ __u32 stx_mask; /* What results were written [uncond] */
+ __u32 stx_blksize; /* Preferred general I/O size [uncond] */
+ __u64 stx_attributes; /* Flags conveying information about the file [uncond] */
+ /* 0x10 */
+ __u32 stx_nlink; /* Number of hard links */
+ __u32 stx_uid; /* User ID of owner */
+ __u32 stx_gid; /* Group ID of owner */
+ __u16 stx_mode; /* File mode */
+ __u16 __spare0[1];
+ /* 0x20 */
+ __u64 stx_ino; /* Inode number */
+ __u64 stx_size; /* File size */
+ __u64 stx_blocks; /* Number of 512-byte blocks allocated */
+ __u64 __spare1[1];
+ /* 0x40 */
+ struct statx_timestamp stx_atime; /* Last access time */
+ struct statx_timestamp stx_btime; /* File creation time */
+ struct statx_timestamp stx_ctime; /* Last attribute change time */
+ struct statx_timestamp stx_mtime; /* Last data modification time */
+ /* 0x80 */
+ __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
+ __u32 stx_rdev_minor;
+ __u32 stx_dev_major; /* ID of device containing file [uncond] */
+ __u32 stx_dev_minor;
+ /* 0x90 */
+ __u64 __spare2[14]; /* Spare space for future expansion */
+ /* 0x100 */
+};
+
+/*
+ * Flags to be stx_mask
+ *
+ * Query request/result mask for statx() and struct statx::stx_mask.
+ *
+ * These bits should be set in the mask argument of statx() to request
+ * particular items when calling statx().
+ */
+#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
+#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
+#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
+#define STATX_UID 0x00000008U /* Want/got stx_uid */
+#define STATX_GID 0x00000010U /* Want/got stx_gid */
+#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
+#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
+#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
+#define STATX_INO 0x00000100U /* Want/got stx_ino */
+#define STATX_SIZE 0x00000200U /* Want/got stx_size */
+#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
+#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
+#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
+#define STATX_ALL 0x00000fffU /* All currently supported flags */
+
+/*
+ * Attributes to be found in stx_attributes
+ *
+ * These give information about the features or the state of a file that might
+ * be of use to ordinary userspace programs such as GUIs or ls rather than
+ * specialised tools.
+ *
+ * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * semantically. Where possible, the numerical value is picked to correspond
+ * also.
+ */
+#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
+#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
+#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
+#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
+#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
+
+#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
+
+#endif /* STATX_TYPE */
+#endif /* XFS_IO_STATX_H */
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index e384327..1e5c225 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -882,6 +882,36 @@ option is specified, the atime (last access), mtime
.B \-r
option dumps raw fields from the stat structure.
.TP
+.BI "statx [ \-v|\-r ][ \-m " basic " | \-m " all " | -m " <mask> " ][ \-FD ]"
+Selected statistics from
+.BR stat (2)
+and the XFS_IOC_GETXATTR system call on the current file.
+.RS 1.0i
+.PD 0
+.TP 0.4i
+.B \-v
+Show timestamps
+.TP
+.B \-r
+Dump raw statx structure values
+.TP
+.B \-m basic
+Set the field mask for the statx call to STATX_BASIC_STATS
+.TP
+.B \-m all
+Set the the field mask for the statx call to STATX_ALL (default)
+.TP
+.B \-m <mask>
+Specify a numeric field mask for the statx call
+.TP
+.B \-F
+Force the attributes to be synced with the server
+.TP
+.B \-D
+Don't sync attributes with the server
+.PD
+.RE
+.TP
.B statfs
Selected statistics from
.BR statfs (2)
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] xfs_io: move stat functions to new file
2017-04-06 18:46 ` [PATCH 1/3] xfs_io: move stat functions to new file Eric Sandeen
@ 2017-04-10 21:47 ` Darrick J. Wong
0 siblings, 0 replies; 11+ messages in thread
From: Darrick J. Wong @ 2017-04-10 21:47 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-xfs, fsdevel, David Howells
On Thu, Apr 06, 2017 at 01:46:23PM -0500, Eric Sandeen wrote:
> Adding statx will add a bit of code, so break stat-related
> functions out of open.c into their own new file.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
>
> V3: remember to call stat_init()!
>
>
> diff --git a/io/Makefile b/io/Makefile
> index 32df568..435ccff 100644
> --- a/io/Makefile
> +++ b/io/Makefile
> @@ -11,7 +11,7 @@ HFILES = init.h io.h
> CFILES = init.c \
> attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
> getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
> - pwrite.c reflink.c seek.c shutdown.c sync.c truncate.c utimes.c
> + pwrite.c reflink.c seek.c shutdown.c stat.c sync.c truncate.c utimes.c
>
> LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBPTHREAD)
> LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE)
> diff --git a/io/init.c b/io/init.c
> index 06002e6..c15a1e1 100644
> --- a/io/init.c
> +++ b/io/init.c
> @@ -86,6 +86,7 @@ init_commands(void)
> seek_init();
> sendfile_init();
> shutdown_init();
> + stat_init();
> sync_init();
> sync_range_init();
> truncate_init();
> diff --git a/io/io.h b/io/io.h
> index c40aad0..952bdb8 100644
> --- a/io/io.h
> +++ b/io/io.h
> @@ -53,7 +53,7 @@ extern fileio_t *filetable; /* open file table */
> extern int filecount; /* number of open files */
> extern fileio_t *file; /* active file in file table */
> extern int filelist_f(void);
> -
> +extern int stat_f(int argc, char **argv);
> /*
> * Memory mapped file regions
> */
> @@ -112,6 +112,7 @@ extern void pwrite_init(void);
> extern void quit_init(void);
> extern void seek_init(void);
> extern void shutdown_init(void);
> +extern void stat_init(void);
> extern void sync_init(void);
> extern void truncate_init(void);
> extern void utimes_init(void);
> diff --git a/io/open.c b/io/open.c
> index 941fdc1..2ed55cf 100644
> --- a/io/open.c
> +++ b/io/open.c
> @@ -39,9 +39,7 @@
> #endif
>
> static cmdinfo_t open_cmd;
> -static cmdinfo_t stat_cmd;
> static cmdinfo_t close_cmd;
> -static cmdinfo_t statfs_cmd;
> static cmdinfo_t chproj_cmd;
> static cmdinfo_t lsproj_cmd;
> static cmdinfo_t extsize_cmd;
> @@ -49,96 +47,6 @@ static cmdinfo_t inode_cmd;
> static prid_t prid;
> static long extsize;
>
> -off64_t
> -filesize(void)
> -{
> - struct stat st;
> -
> - if (fstat(file->fd, &st) < 0) {
> - perror("fstat");
> - return -1;
> - }
> - return st.st_size;
> -}
> -
> -static char *
> -filetype(mode_t mode)
> -{
> - switch (mode & S_IFMT) {
> - case S_IFSOCK:
> - return _("socket");
> - case S_IFDIR:
> - return _("directory");
> - case S_IFCHR:
> - return _("char device");
> - case S_IFBLK:
> - return _("block device");
> - case S_IFREG:
> - return _("regular file");
> - case S_IFLNK:
> - return _("symbolic link");
> - case S_IFIFO:
> - return _("fifo");
> - }
> - return NULL;
> -}
> -
> -static int
> -stat_f(
> - int argc,
> - char **argv)
> -{
> - struct dioattr dio;
> - struct fsxattr fsx, fsxa;
> - struct stat st;
> - int verbose = (argc == 2 && !strcmp(argv[1], "-v"));
> -
> - printf(_("fd.path = \"%s\"\n"), file->name);
> - printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
> - file->flags & IO_OSYNC ? _("sync") : _("non-sync"),
> - file->flags & IO_DIRECT ? _("direct") : _("non-direct"),
> - file->flags & IO_READONLY ? _("read-only") : _("read-write"),
> - file->flags & IO_REALTIME ? _(",real-time") : "",
> - file->flags & IO_APPEND ? _(",append-only") : "",
> - file->flags & IO_NONBLOCK ? _(",non-block") : "",
> - file->flags & IO_TMPFILE ? _(",tmpfile") : "");
> - if (fstat(file->fd, &st) < 0) {
> - perror("fstat");
> - } else {
> - printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
> - printf(_("stat.type = %s\n"), filetype(st.st_mode));
> - printf(_("stat.size = %lld\n"), (long long)st.st_size);
> - printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
> - if (verbose) {
> - printf(_("stat.atime = %s"), ctime(&st.st_atime));
> - printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
> - printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
> - }
> - }
> - if (file->flags & IO_FOREIGN)
> - return 0;
> - if ((xfsctl(file->name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0 ||
> - (xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTRA, &fsxa)) < 0) {
> - perror("FS_IOC_FSGETXATTR");
> - } else {
> - printf(_("fsxattr.xflags = 0x%x "), fsx.fsx_xflags);
> - printxattr(fsx.fsx_xflags, verbose, 0, file->name, 1, 1);
> - printf(_("fsxattr.projid = %u\n"), fsx.fsx_projid);
> - printf(_("fsxattr.extsize = %u\n"), fsx.fsx_extsize);
> - printf(_("fsxattr.cowextsize = %u\n"), fsx.fsx_cowextsize);
> - printf(_("fsxattr.nextents = %u\n"), fsx.fsx_nextents);
> - printf(_("fsxattr.naextents = %u\n"), fsxa.fsx_nextents);
> - }
> - if ((xfsctl(file->name, file->fd, XFS_IOC_DIOINFO, &dio)) < 0) {
> - perror("XFS_IOC_DIOINFO");
> - } else {
> - printf(_("dioattr.mem = 0x%x\n"), dio.d_mem);
> - printf(_("dioattr.miniosz = %u\n"), dio.d_miniosz);
> - printf(_("dioattr.maxiosz = %u\n"), dio.d_maxiosz);
> - }
> - return 0;
> -}
> -
> int
> openfile(
> char *path,
> @@ -697,58 +605,6 @@ extsize_f(
> return 0;
> }
>
> -static int
> -statfs_f(
> - int argc,
> - char **argv)
> -{
> - struct xfs_fsop_counts fscounts;
> - struct xfs_fsop_geom fsgeo;
> - struct statfs st;
> -
> - printf(_("fd.path = \"%s\"\n"), file->name);
> - if (platform_fstatfs(file->fd, &st) < 0) {
> - perror("fstatfs");
> - } else {
> - printf(_("statfs.f_bsize = %lld\n"), (long long) st.f_bsize);
> - printf(_("statfs.f_blocks = %lld\n"), (long long) st.f_blocks);
> - printf(_("statfs.f_bavail = %lld\n"), (long long) st.f_bavail);
> - printf(_("statfs.f_files = %lld\n"), (long long) st.f_files);
> - printf(_("statfs.f_ffree = %lld\n"), (long long) st.f_ffree);
> - }
> - if (file->flags & IO_FOREIGN)
> - return 0;
> - if ((xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) {
> - perror("XFS_IOC_FSGEOMETRY_V1");
> - } else {
> - printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
> - printf(_("geom.agcount = %u\n"), fsgeo.agcount);
> - printf(_("geom.agblocks = %u\n"), fsgeo.agblocks);
> - printf(_("geom.datablocks = %llu\n"),
> - (unsigned long long) fsgeo.datablocks);
> - printf(_("geom.rtblocks = %llu\n"),
> - (unsigned long long) fsgeo.rtblocks);
> - printf(_("geom.rtextents = %llu\n"),
> - (unsigned long long) fsgeo.rtextents);
> - printf(_("geom.rtextsize = %u\n"), fsgeo.rtextsize);
> - printf(_("geom.sunit = %u\n"), fsgeo.sunit);
> - printf(_("geom.swidth = %u\n"), fsgeo.swidth);
> - }
> - if ((xfsctl(file->name, file->fd, XFS_IOC_FSCOUNTS, &fscounts)) < 0) {
> - perror("XFS_IOC_FSCOUNTS");
> - } else {
> - printf(_("counts.freedata = %llu\n"),
> - (unsigned long long) fscounts.freedata);
> - printf(_("counts.freertx = %llu\n"),
> - (unsigned long long) fscounts.freertx);
> - printf(_("counts.freeino = %llu\n"),
> - (unsigned long long) fscounts.freeino);
> - printf(_("counts.allocino = %llu\n"),
> - (unsigned long long) fscounts.allocino);
> - }
> - return 0;
> -}
> -
> static void
> inode_help(void)
> {
> @@ -920,14 +776,6 @@ open_init(void)
> open_cmd.oneline = _("open the file specified by path");
> open_cmd.help = open_help;
>
> - stat_cmd.name = "stat";
> - stat_cmd.cfunc = stat_f;
> - stat_cmd.argmin = 0;
> - stat_cmd.argmax = 1;
> - stat_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> - stat_cmd.args = _("[-v]");
> - stat_cmd.oneline = _("statistics on the currently open file");
> -
> close_cmd.name = "close";
> close_cmd.altname = "c";
> close_cmd.cfunc = close_f;
> @@ -936,12 +784,6 @@ open_init(void)
> close_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK | CMD_FLAG_ONESHOT;
> close_cmd.oneline = _("close the current open file");
>
> - statfs_cmd.name = "statfs";
> - statfs_cmd.cfunc = statfs_f;
> - statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> - statfs_cmd.oneline =
> - _("statistics on the filesystem of the currently open file");
> -
> chproj_cmd.name = "chproj";
> chproj_cmd.cfunc = chproj_f;
> chproj_cmd.args = _("[-D | -R] projid");
> @@ -983,9 +825,7 @@ open_init(void)
> inode_cmd.help = inode_help;
>
> add_command(&open_cmd);
> - add_command(&stat_cmd);
> add_command(&close_cmd);
> - add_command(&statfs_cmd);
> add_command(&chproj_cmd);
> add_command(&lsproj_cmd);
> add_command(&extsize_cmd);
> diff --git a/io/stat.c b/io/stat.c
> new file mode 100644
> index 0000000..3ae9903
> --- /dev/null
> +++ b/io/stat.c
> @@ -0,0 +1,189 @@
> +/*
> + * Copyright (c) 2003-2005 Silicon Graphics, Inc.
> + * All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "command.h"
> +#include "input.h"
> +#include "init.h"
> +#include "io.h"
> +#include "libxfs.h"
> +
> +static cmdinfo_t stat_cmd;
> +static cmdinfo_t statfs_cmd;
> +
> +off64_t
> +filesize(void)
> +{
> + struct stat st;
> +
> + if (fstat(file->fd, &st) < 0) {
> + perror("fstat");
> + return -1;
> + }
> + return st.st_size;
> +}
> +
> +static char *
> +filetype(mode_t mode)
> +{
> + switch (mode & S_IFMT) {
> + case S_IFSOCK:
> + return _("socket");
> + case S_IFDIR:
> + return _("directory");
> + case S_IFCHR:
> + return _("char device");
> + case S_IFBLK:
> + return _("block device");
> + case S_IFREG:
> + return _("regular file");
> + case S_IFLNK:
> + return _("symbolic link");
> + case S_IFIFO:
> + return _("fifo");
> + }
> + return NULL;
> +}
> +
> +int
> +stat_f(
> + int argc,
> + char **argv)
> +{
> + struct dioattr dio;
> + struct fsxattr fsx, fsxa;
> + struct stat st;
> + int verbose = (argc == 2 && !strcmp(argv[1], "-v"));
> +
> + printf(_("fd.path = \"%s\"\n"), file->name);
> + printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
> + file->flags & IO_OSYNC ? _("sync") : _("non-sync"),
> + file->flags & IO_DIRECT ? _("direct") : _("non-direct"),
> + file->flags & IO_READONLY ? _("read-only") : _("read-write"),
> + file->flags & IO_REALTIME ? _(",real-time") : "",
> + file->flags & IO_APPEND ? _(",append-only") : "",
> + file->flags & IO_NONBLOCK ? _(",non-block") : "",
> + file->flags & IO_TMPFILE ? _(",tmpfile") : "");
> + if (fstat(file->fd, &st) < 0) {
> + perror("fstat");
> + } else {
> + printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
> + printf(_("stat.type = %s\n"), filetype(st.st_mode));
> + printf(_("stat.size = %lld\n"), (long long)st.st_size);
> + printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
> + if (verbose) {
> + printf(_("stat.atime = %s"), ctime(&st.st_atime));
> + printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
> + printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
> + }
> + }
> + if (file->flags & IO_FOREIGN)
> + return 0;
> + if ((xfsctl(file->name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0 ||
> + (xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTRA, &fsxa)) < 0) {
> + perror("FS_IOC_FSGETXATTR");
> + } else {
> + printf(_("fsxattr.xflags = 0x%x "), fsx.fsx_xflags);
> + printxattr(fsx.fsx_xflags, verbose, 0, file->name, 1, 1);
> + printf(_("fsxattr.projid = %u\n"), fsx.fsx_projid);
> + printf(_("fsxattr.extsize = %u\n"), fsx.fsx_extsize);
> + printf(_("fsxattr.cowextsize = %u\n"), fsx.fsx_cowextsize);
> + printf(_("fsxattr.nextents = %u\n"), fsx.fsx_nextents);
> + printf(_("fsxattr.naextents = %u\n"), fsxa.fsx_nextents);
> + }
> + if ((xfsctl(file->name, file->fd, XFS_IOC_DIOINFO, &dio)) < 0) {
> + perror("XFS_IOC_DIOINFO");
> + } else {
> + printf(_("dioattr.mem = 0x%x\n"), dio.d_mem);
> + printf(_("dioattr.miniosz = %u\n"), dio.d_miniosz);
> + printf(_("dioattr.maxiosz = %u\n"), dio.d_maxiosz);
> + }
> + return 0;
> +}
> +
> +static int
> +statfs_f(
> + int argc,
> + char **argv)
> +{
> + struct xfs_fsop_counts fscounts;
> + struct xfs_fsop_geom fsgeo;
> + struct statfs st;
> +
> + printf(_("fd.path = \"%s\"\n"), file->name);
> + if (platform_fstatfs(file->fd, &st) < 0) {
> + perror("fstatfs");
> + } else {
> + printf(_("statfs.f_bsize = %lld\n"), (long long) st.f_bsize);
> + printf(_("statfs.f_blocks = %lld\n"), (long long) st.f_blocks);
> + printf(_("statfs.f_bavail = %lld\n"), (long long) st.f_bavail);
> + printf(_("statfs.f_files = %lld\n"), (long long) st.f_files);
> + printf(_("statfs.f_ffree = %lld\n"), (long long) st.f_ffree);
> + }
> + if (file->flags & IO_FOREIGN)
> + return 0;
> + if ((xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) {
> + perror("XFS_IOC_FSGEOMETRY_V1");
> + } else {
> + printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
> + printf(_("geom.agcount = %u\n"), fsgeo.agcount);
> + printf(_("geom.agblocks = %u\n"), fsgeo.agblocks);
> + printf(_("geom.datablocks = %llu\n"),
> + (unsigned long long) fsgeo.datablocks);
> + printf(_("geom.rtblocks = %llu\n"),
> + (unsigned long long) fsgeo.rtblocks);
> + printf(_("geom.rtextents = %llu\n"),
> + (unsigned long long) fsgeo.rtextents);
> + printf(_("geom.rtextsize = %u\n"), fsgeo.rtextsize);
> + printf(_("geom.sunit = %u\n"), fsgeo.sunit);
> + printf(_("geom.swidth = %u\n"), fsgeo.swidth);
> + }
> + if ((xfsctl(file->name, file->fd, XFS_IOC_FSCOUNTS, &fscounts)) < 0) {
> + perror("XFS_IOC_FSCOUNTS");
> + } else {
> + printf(_("counts.freedata = %llu\n"),
> + (unsigned long long) fscounts.freedata);
> + printf(_("counts.freertx = %llu\n"),
> + (unsigned long long) fscounts.freertx);
> + printf(_("counts.freeino = %llu\n"),
> + (unsigned long long) fscounts.freeino);
> + printf(_("counts.allocino = %llu\n"),
> + (unsigned long long) fscounts.allocino);
> + }
> + return 0;
> +}
> +
> +void
> +stat_init(void)
> +{
> + stat_cmd.name = "stat";
> + stat_cmd.cfunc = stat_f;
> + stat_cmd.argmin = 0;
> + stat_cmd.argmax = 1;
> + stat_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> + stat_cmd.args = _("[-v]");
> + stat_cmd.oneline = _("statistics on the currently open file");
> +
> + statfs_cmd.name = "statfs";
> + statfs_cmd.cfunc = statfs_f;
> + statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> + statfs_cmd.oneline =
> + _("statistics on the filesystem of the currently open file");
> +
> + add_command(&stat_cmd);
> + add_command(&statfs_cmd);
> +}
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] xfs_io: refactor stat functions, add raw dump
2017-04-06 18:48 ` [PATCH 2/3] xfs_io: refactor stat functions, add raw dump Eric Sandeen
@ 2017-04-10 21:48 ` Darrick J. Wong
0 siblings, 0 replies; 11+ messages in thread
From: Darrick J. Wong @ 2017-04-10 21:48 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-xfs, fsdevel, David Howells
On Thu, Apr 06, 2017 at 01:48:50PM -0500, Eric Sandeen wrote:
> This adds a "-r" raw structure dump to stat options, and
> factors the code a bit; statx will also use print_file_info
> and print_xfs_info.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
>
> diff --git a/io/stat.c b/io/stat.c
> index 3ae9903..770f3c7 100644
> --- a/io/stat.c
> +++ b/io/stat.c
> @@ -59,16 +59,32 @@ filetype(mode_t mode)
> return NULL;
> }
>
> -int
> -stat_f(
> - int argc,
> - char **argv)
> +static int
> +dump_raw_stat(struct stat *st)
> {
> - struct dioattr dio;
> - struct fsxattr fsx, fsxa;
> - struct stat st;
> - int verbose = (argc == 2 && !strcmp(argv[1], "-v"));
> + printf("stat.blksize = %lu\n", st->st_blksize);
> + printf("stat.nlink = %lu\n", st->st_nlink);
> + printf("stat.uid = %u\n", st->st_uid);
> + printf("stat.gid = %u\n", st->st_gid);
> + printf("stat.mode: 0%o\n", st->st_mode);
> + printf("stat.ino = %lu\n", st->st_ino);
> + printf("stat.size = %lu\n", st->st_size);
> + printf("stat.blocks = %lu\n", st->st_blocks);
> + printf("stat.atime.tv_sec = %ld\n", st->st_atim.tv_sec);
> + printf("stat.atime.tv_nsec = %ld\n", st->st_atim.tv_nsec);
> + printf("stat.ctime.tv_sec = %ld\n", st->st_ctim.tv_sec);
> + printf("stat.ctime.tv_nsec = %ld\n", st->st_ctim.tv_nsec);
> + printf("stat.mtime.tv_sec = %ld\n", st->st_mtim.tv_sec);
> + printf("stat.mtime.tv_nsec = %ld\n", st->st_mtim.tv_nsec);
> + printf("stat.rdev_major = %u\n", major(st->st_rdev));
> + printf("stat.rdev_minor = %u\n", minor(st->st_rdev));
> + printf("stat.dev_major = %u\n", major(st->st_dev));
> + printf("stat.dev_minor = %u\n", minor(st->st_dev));
> + return 0;
> +}
>
> +void print_file_info(void)
> +{
> printf(_("fd.path = \"%s\"\n"), file->name);
> printf(_("fd.flags = %s,%s,%s%s%s%s%s\n"),
> file->flags & IO_OSYNC ? _("sync") : _("non-sync"),
> @@ -78,21 +94,13 @@ stat_f(
> file->flags & IO_APPEND ? _(",append-only") : "",
> file->flags & IO_NONBLOCK ? _(",non-block") : "",
> file->flags & IO_TMPFILE ? _(",tmpfile") : "");
> - if (fstat(file->fd, &st) < 0) {
> - perror("fstat");
> - } else {
> - printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
> - printf(_("stat.type = %s\n"), filetype(st.st_mode));
> - printf(_("stat.size = %lld\n"), (long long)st.st_size);
> - printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
> - if (verbose) {
> - printf(_("stat.atime = %s"), ctime(&st.st_atime));
> - printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
> - printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
> - }
> - }
> - if (file->flags & IO_FOREIGN)
> - return 0;
> +}
> +
> +void print_xfs_info(int verbose)
> +{
> + struct dioattr dio;
> + struct fsxattr fsx, fsxa;
> +
> if ((xfsctl(file->name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0 ||
> (xfsctl(file->name, file->fd, XFS_IOC_FSGETXATTRA, &fsxa)) < 0) {
> perror("FS_IOC_FSGETXATTR");
> @@ -112,6 +120,57 @@ stat_f(
> printf(_("dioattr.miniosz = %u\n"), dio.d_miniosz);
> printf(_("dioattr.maxiosz = %u\n"), dio.d_maxiosz);
> }
> +}
> +
> +int
> +stat_f(
> + int argc,
> + char **argv)
> +{
> + struct stat st;
> + int c, verbose = 0, raw = 0;
> +
> + while ((c = getopt(argc, argv, "rv")) != EOF) {
> + switch (c) {
> + case 'r':
> + raw = 1;
> + break;
> + case 'v':
> + verbose = 1;
> + break;
> + default:
> + return command_usage(&stat_cmd);
> + }
> + }
> +
> + if (raw && verbose)
> + return command_usage(&stat_cmd);
> +
> + if (fstat(file->fd, &st) < 0) {
> + perror("fstat");
> + return 0;
> + }
> +
> + if (raw)
> + return dump_raw_stat(&st);
> +
> + print_file_info();
> +
> + printf(_("stat.ino = %lld\n"), (long long)st.st_ino);
> + printf(_("stat.type = %s\n"), filetype(st.st_mode));
> + printf(_("stat.size = %lld\n"), (long long)st.st_size);
> + printf(_("stat.blocks = %lld\n"), (long long)st.st_blocks);
> + if (verbose) {
> + printf(_("stat.atime = %s"), ctime(&st.st_atime));
> + printf(_("stat.mtime = %s"), ctime(&st.st_mtime));
> + printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
> + }
> +
> + if (file->flags & IO_FOREIGN)
> + return 0;
> +
> + print_xfs_info(verbose);
> +
> return 0;
> }
>
> @@ -175,7 +234,7 @@ stat_init(void)
> stat_cmd.argmin = 0;
> stat_cmd.argmax = 1;
> stat_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> - stat_cmd.args = _("[-v]");
> + stat_cmd.args = _("[-v|-r]");
> stat_cmd.oneline = _("statistics on the currently open file");
>
> statfs_cmd.name = "statfs";
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index 19e1ae4..e384327 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -872,13 +872,15 @@ Only available in expert mode and requires privileges.
> Force the filesystem to shutdown (with or without flushing the log).
> Only available in expert mode and requires privileges.
> .TP
> -.BR stat " [ " \-v " ]"
> +.BR stat " [ " \-v "|" \-r " ]"
> Selected statistics from
> .BR stat (2)
> and the XFS_IOC_GETXATTR system call on the current file. If the
> .B \-v
> option is specified, the atime (last access), mtime
> -(last modify), and ctime (last change) timestamps are also displayed.
> +(last modify), and ctime (last change) timestamps are also displayed. The
> +.B \-r
> +option dumps raw fields from the stat structure.
> .TP
> .B statfs
> Selected statistics from
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3 V4] xfs_io: hook up statx
2017-04-10 21:33 ` [PATCH 3/3 V4] " Eric Sandeen
@ 2017-04-10 21:56 ` Darrick J. Wong
2017-04-10 22:07 ` [PATCH 3/3 V5] " Eric Sandeen
1 sibling, 0 replies; 11+ messages in thread
From: Darrick J. Wong @ 2017-04-10 21:56 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-xfs, fsdevel, David Howells
On Mon, Apr 10, 2017 at 04:33:44PM -0500, Eric Sandeen wrote:
> Wire up the statx syscall to xfs_io.
>
> xfs_io> help statx
> statx [-v|-r][-m basic | -m all | -m <mask>][-FD] -- extended statistics on the currently open file
>
> Display extended file status.
>
> Options:
> -v -- More verbose output
> -r -- Print raw statx structure fields
> -m mask -- Specify the field mask for the statx call
> (can also be 'basic' or 'all'; default STATX_ALL)
> -D -- Don't sync attributes with the server
> -F -- Force the attributes to be sync'd with the server
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>
> V4: Fix up __NR_statx defines, handle it if not defined (ala dhowells testcase)
> fix trailing whitespace in manpage :)
>
> V3: remove -A, -L, and -O options
> allow "basic" and "all" masks
> change raw dump format to match stat raw format
> make -r and -v exclusive
> follow factoring of stat_f()
>
> diff --git a/io/stat.c b/io/stat.c
> index 770f3c7..efd552f 100644
> --- a/io/stat.c
> +++ b/io/stat.c
> @@ -2,6 +2,9 @@
> * Copyright (c) 2003-2005 Silicon Graphics, Inc.
> * All Rights Reserved.
> *
> + * Copyright (C) 2015, 2017 Red Hat, Inc.
> + * Portions of statx support written by David Howells (dhowells@redhat.com)
> + *
> * This program is free software; you can redistribute it and/or
> * modify it under the terms of the GNU General Public License as
> * published by the Free Software Foundation.
> @@ -20,10 +23,14 @@
> #include "input.h"
> #include "init.h"
> #include "io.h"
> +#include "statx.h"
> #include "libxfs.h"
>
> +#include <fcntl.h>
> +
> static cmdinfo_t stat_cmd;
> static cmdinfo_t statfs_cmd;
> +static cmdinfo_t statx_cmd;
>
> off64_t
> filesize(void)
> @@ -226,6 +233,151 @@ statfs_f(
> return 0;
> }
>
> +static ssize_t
> +_statx(int dfd, const char *filename, unsigned flags,
unsigned int flags?
> + unsigned int mask, struct statx *buffer)
Parameter indentation? i.e.
static ssize_t
_statx(
int dfd,
const char *filename,
unsigned int flags,
unsigned int mask,
struct statx *buffer)
{
> +{
> +#ifdef __NR_statx
> + return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
> +#else
> + errno = ENOSYS;
> + return -1;
> +#endif
> +}
> +
> +static void
> +statx_help(void)
> +{
> + printf(_(
> +"\n"
> +" Display extended file status.\n"
> +"\n"
> +" Options:\n"
> +" -v -- More verbose output\n"
> +" -r -- Print raw statx structure fields\n"
> +" -m mask -- Specify the field mask for the statx call\n"
> +" (can also be 'basic' or 'all'; default STATX_ALL)\n"
> +" -D -- Don't sync attributes with the server\n"
> +" -F -- Force the attributes to be sync'd with the server\n"
> +"\n"));
> +}
> +
> +/* statx helper */
> +static int
> +dump_raw_statx(struct statx *stx)
> +{
> + printf("stat.mask = 0x%x\n", stx->stx_mask);
> + printf("stat.blksize = %u\n", stx->stx_blksize);
> + printf("stat.attributes = 0x%llx\n", stx->stx_attributes);
> + printf("stat.nlink = %u\n", stx->stx_nlink);
> + printf("stat.uid = %u\n", stx->stx_uid);
> + printf("stat.gid = %u\n", stx->stx_gid);
> + printf("stat.mode: 0%o\n", stx->stx_mode);
> + printf("stat.ino = %llu\n", stx->stx_ino);
> + printf("stat.size = %llu\n", stx->stx_size);
> + printf("stat.blocks = %llu\n", stx->stx_blocks);
> + printf("stat.atime.tv_sec = %lld\n", stx->stx_atime.tv_sec);
> + printf("stat.atime.tv_nsec = %d\n", stx->stx_atime.tv_nsec);
> + printf("stat.btime.tv_sec = %lld\n", stx->stx_btime.tv_sec);
> + printf("stat.btime.tv_nsec = %d\n", stx->stx_btime.tv_nsec);
> + printf("stat.ctime.tv_sec = %lld\n", stx->stx_ctime.tv_sec);
> + printf("stat.ctime.tv_nsec = %d\n", stx->stx_ctime.tv_nsec);
> + printf("stat.mtime.tv_sec = %lld\n", stx->stx_mtime.tv_sec);
> + printf("stat.mtime.tv_nsec = %d\n", stx->stx_mtime.tv_nsec);
> + printf("stat.rdev_major = %u\n", stx->stx_rdev_major);
> + printf("stat.rdev_minor = %u\n", stx->stx_rdev_minor);
> + printf("stat.dev_major = %u\n", stx->stx_dev_major);
> + printf("stat.dev_minor = %u\n", stx->stx_dev_minor);
> + return 0;
> +}
> +
> +/*
> + * options:
> + * - input flags - query type
> + * - output style for flags (and all else?) (chars vs. hex?)
> + * - output - mask out incidental flag or not?
> + */
> +int
> +statx_f(
> + int argc,
> + char **argv)
> +{
> + int c, verbose = 0, raw = 0;
> + char *p;
> + struct statx stx;
> + int atflag = 0;
> + unsigned int mask = STATX_ALL;
> +
> + while ((c = getopt(argc, argv, "m:rvFD")) != EOF) {
> + switch (c) {
> + case 'm':
> + if (strcmp(optarg, "basic") == 0)
> + mask = STATX_BASIC_STATS;
> + else if (strcmp(optarg, "all") == 0)
> + mask = STATX_ALL;
> + else {
> + mask = strtoul(optarg, &p, 0);
> + if (!p || p == optarg) {
> + printf(
> + _("non-numeric mask -- %s\n"), optarg);
> + return 0;
> + }
> + }
> + break;
> + case 'r':
> + raw = 1;
> + break;
> + case 'v':
> + verbose = 1;
> + break;
> + case 'F':
> + atflag &= ~AT_STATX_SYNC_TYPE;
> + atflag |= AT_STATX_FORCE_SYNC;
> + break;
> + case 'D':
> + atflag &= ~AT_STATX_SYNC_TYPE;
> + atflag |= AT_STATX_DONT_SYNC;
> + break;
> + default:
> + return command_usage(&statx_cmd);
> + }
> + }
> +
> + if (raw && verbose)
> + return command_usage(&statx_cmd);
> +
> + memset(&stx, 0xbf, sizeof(stx));
> + if (_statx(file->fd, NULL, atflag, mask, &stx) < 0) {
> + perror("statx");
> + return 0;
> + }
> +
> + if (raw)
> + return dump_raw_statx(&stx);
> +
> + print_file_info();
> +
> + printf(_("stat.ino = %lld\n"), (long long)stx.stx_ino);
> + printf(_("stat.type = %s\n"), filetype(stx.stx_mode));
> + printf(_("stat.size = %lld\n"), (long long)stx.stx_size);
> + printf(_("stat.blocks = %lld\n"), (long long)stx.stx_blocks);
> + if (verbose) {
> + printf(_("stat.atime = %s"), ctime((time_t *)&stx.stx_atime.tv_sec));
> + printf(_("stat.mtime = %s"), ctime((time_t *)&stx.stx_mtime.tv_sec));
> + printf(_("stat.ctime = %s"), ctime((time_t *)&stx.stx_ctime.tv_sec));
> + if (stx.stx_mask & STATX_BTIME)
> + printf(_("stat.btime = %s"),
> + ctime((time_t *)&stx.stx_btime.tv_sec));
> + }
> +
> + if (file->flags & IO_FOREIGN)
> + return 0;
> +
> + print_xfs_info(verbose);
> +
> + return 0;
> +}
> +
> void
> stat_init(void)
> {
> @@ -237,6 +389,15 @@ stat_init(void)
> stat_cmd.args = _("[-v|-r]");
> stat_cmd.oneline = _("statistics on the currently open file");
>
> + statx_cmd.name = "statx";
> + statx_cmd.cfunc = statx_f;
> + statx_cmd.argmin = 0;
> + statx_cmd.argmax = -1;
> + statx_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> + statx_cmd.args = _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
> + statx_cmd.oneline = _("extended statistics on the currently open file");
> + statx_cmd.help = statx_help;
> +
> statfs_cmd.name = "statfs";
> statfs_cmd.cfunc = statfs_f;
> statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> @@ -244,5 +405,6 @@ stat_init(void)
> _("statistics on the filesystem of the currently open file");
>
> add_command(&stat_cmd);
> + add_command(&statx_cmd);
> add_command(&statfs_cmd);
> }
> diff --git a/io/statx.h b/io/statx.h
> new file mode 100644
> index 0000000..2d919b9
> --- /dev/null
> +++ b/io/statx.h
> @@ -0,0 +1,161 @@
> +#ifndef XFS_IO_STATX_H
> +#define XFS_IO_STATX_H
> +
> +#include <unistd.h>
> +#include <sys/syscall.h>
> +
> +#ifndef AT_STATX_SYNC_TYPE
> +#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
> +#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
> +#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
> +#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
> +#endif
> +
> +#ifndef AT_NO_AUTOMOUNT
> +#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
> +#endif
> +
> +#ifndef __NR_statx
> +# ifdef __i386__
> +# define __NR_statx 383
> +# elif defined (__ILP32__)
> +# define __NR_statx (__X32_SYSCALL_BIT + 332)
> +# elif defined (__x86_64__)
> +# define __NR_statx 332
> +# endif
> +#endif
No love for m68k? :)
> +
> +#ifndef STATX_TYPE
> +
> +/*
> + * Timestamp structure for the timestamps in struct statx.
> + *
> + * tv_sec holds the number of seconds before (negative) or after (positive)
> + * 00:00:00 1st January 1970 UTC.
> + *
> + * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
> + * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
> + *
> + * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
> + * either be both positive or both negative.
> + *
> + * __reserved is held in case we need a yet finer resolution.
> + */
> +struct statx_timestamp {
> + __s64 tv_sec;
> + __s32 tv_nsec;
> + __s32 __reserved;
> +};
> +
> +/*
> + * Structures for the extended file attribute retrieval system call
> + * (statx()).
> + *
> + * The caller passes a mask of what they're specifically interested in as a
> + * parameter to statx(). What statx() actually got will be indicated in
> + * st_mask upon return.
> + *
> + * For each bit in the mask argument:
> + *
> + * - if the datum is not supported:
> + *
> + * - the bit will be cleared, and
> + *
> + * - the datum will be set to an appropriate fabricated value if one is
> + * available (eg. CIFS can take a default uid and gid), otherwise
> + *
> + * - the field will be cleared;
> + *
> + * - otherwise, if explicitly requested:
> + *
> + * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
> + * set or if the datum is considered out of date, and
> + *
> + * - the field will be filled in and the bit will be set;
> + *
> + * - otherwise, if not requested, but available in approximate form without any
> + * effort, it will be filled in anyway, and the bit will be set upon return
> + * (it might not be up to date, however, and no attempt will be made to
> + * synchronise the internal state first);
> + *
> + * - otherwise the field and the bit will be cleared before returning.
> + *
> + * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
> + * will have values installed for compatibility purposes so that stat() and
> + * co. can be emulated in userspace.
> + */
> +struct statx {
> + /* 0x00 */
> + __u32 stx_mask; /* What results were written [uncond] */
> + __u32 stx_blksize; /* Preferred general I/O size [uncond] */
> + __u64 stx_attributes; /* Flags conveying information about the file [uncond] */
> + /* 0x10 */
> + __u32 stx_nlink; /* Number of hard links */
> + __u32 stx_uid; /* User ID of owner */
> + __u32 stx_gid; /* Group ID of owner */
> + __u16 stx_mode; /* File mode */
> + __u16 __spare0[1];
> + /* 0x20 */
> + __u64 stx_ino; /* Inode number */
> + __u64 stx_size; /* File size */
> + __u64 stx_blocks; /* Number of 512-byte blocks allocated */
> + __u64 __spare1[1];
> + /* 0x40 */
> + struct statx_timestamp stx_atime; /* Last access time */
> + struct statx_timestamp stx_btime; /* File creation time */
> + struct statx_timestamp stx_ctime; /* Last attribute change time */
> + struct statx_timestamp stx_mtime; /* Last data modification time */
> + /* 0x80 */
> + __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
> + __u32 stx_rdev_minor;
> + __u32 stx_dev_major; /* ID of device containing file [uncond] */
> + __u32 stx_dev_minor;
> + /* 0x90 */
> + __u64 __spare2[14]; /* Spare space for future expansion */
> + /* 0x100 */
> +};
> +
> +/*
> + * Flags to be stx_mask
> + *
> + * Query request/result mask for statx() and struct statx::stx_mask.
> + *
> + * These bits should be set in the mask argument of statx() to request
> + * particular items when calling statx().
> + */
> +#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
> +#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
> +#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
> +#define STATX_UID 0x00000008U /* Want/got stx_uid */
> +#define STATX_GID 0x00000010U /* Want/got stx_gid */
> +#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
> +#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
> +#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
> +#define STATX_INO 0x00000100U /* Want/got stx_ino */
> +#define STATX_SIZE 0x00000200U /* Want/got stx_size */
> +#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
> +#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
> +#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
> +#define STATX_ALL 0x00000fffU /* All currently supported flags */
Missing STATX__RESERVED here.
(Yeah yeah, I'm being pedantic...)
> +
> +/*
> + * Attributes to be found in stx_attributes
> + *
> + * These give information about the features or the state of a file that might
> + * be of use to ordinary userspace programs such as GUIs or ls rather than
> + * specialised tools.
> + *
> + * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
> + * semantically. Where possible, the numerical value is picked to correspond
> + * also.
> + */
> +#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
> +#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
> +#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
> +#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
> +#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
> +
> +#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
> +
> +#endif /* STATX_TYPE */
> +#endif /* XFS_IO_STATX_H */
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index e384327..1e5c225 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -882,6 +882,36 @@ option is specified, the atime (last access), mtime
> .B \-r
> option dumps raw fields from the stat structure.
> .TP
> +.BI "statx [ \-v|\-r ][ \-m " basic " | \-m " all " | -m " <mask> " ][ \-FD ]"
> +Selected statistics from
> +.BR stat (2)
> +and the XFS_IOC_GETXATTR system call on the current file.
> +.RS 1.0i
> +.PD 0
> +.TP 0.4i
> +.B \-v
> +Show timestamps
> +.TP
> +.B \-r
> +Dump raw statx structure values
> +.TP
> +.B \-m basic
> +Set the field mask for the statx call to STATX_BASIC_STATS
> +.TP
> +.B \-m all
> +Set the the field mask for the statx call to STATX_ALL (default)
> +.TP
> +.B \-m <mask>
> +Specify a numeric field mask for the statx call
> +.TP
> +.B \-F
> +Force the attributes to be synced with the server
> +.TP
> +.B \-D
> +Don't sync attributes with the server
All of these need trailing end-of-sentence periods since they are full
sentences.
--D
> +.PD
> +.RE
> +.TP
> .B statfs
> Selected statistics from
> .BR statfs (2)
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/3 V5] xfs_io: hook up statx
2017-04-10 21:33 ` [PATCH 3/3 V4] " Eric Sandeen
2017-04-10 21:56 ` Darrick J. Wong
@ 2017-04-10 22:07 ` Eric Sandeen
2017-04-10 22:13 ` Darrick J. Wong
1 sibling, 1 reply; 11+ messages in thread
From: Eric Sandeen @ 2017-04-10 22:07 UTC (permalink / raw)
To: linux-xfs, fsdevel, David Howells
Wire up the statx syscall to xfs_io.
xfs_io> help statx
statx [-v|-r][-m basic | -m all | -m <mask>][-FD] -- extended statistics on the currently open file
Display extended file status.
Options:
-v -- More verbose output
-r -- Print raw statx structure fields
-m mask -- Specify the field mask for the statx call
(can also be 'basic' or 'all'; default STATX_ALL)
-D -- Don't sync attributes with the server
-F -- Force the attributes to be sync'd with the server
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
V5: address djwong's pedantry, except for mst3k ;)
V4: Fix up __NR_statx defines, handle it if not defined (ala dhowells testcase)
fix trailing whitespace in manpage
V3: remove -A, -L, and -O options
allow "basic" and "all" masks
change raw dump format to match stat raw format
make -r and -v exclusive
follow factoring of stat_f()
diff --git a/io/stat.c b/io/stat.c
index 770f3c7..c5b3075 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -2,6 +2,9 @@
* Copyright (c) 2003-2005 Silicon Graphics, Inc.
* All Rights Reserved.
*
+ * Copyright (C) 2015, 2017 Red Hat, Inc.
+ * Portions of statx support written by David Howells (dhowells@redhat.com)
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
@@ -20,10 +23,14 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "statx.h"
#include "libxfs.h"
+#include <fcntl.h>
+
static cmdinfo_t stat_cmd;
static cmdinfo_t statfs_cmd;
+static cmdinfo_t statx_cmd;
off64_t
filesize(void)
@@ -226,6 +233,155 @@ statfs_f(
return 0;
}
+static ssize_t
+_statx(
+ int dfd,
+ const char *filename,
+ unsigned int flags,
+ unsigned int mask,
+ struct statx *buffer)
+{
+#ifdef __NR_statx
+ return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+static void
+statx_help(void)
+{
+ printf(_(
+"\n"
+" Display extended file status.\n"
+"\n"
+" Options:\n"
+" -v -- More verbose output\n"
+" -r -- Print raw statx structure fields\n"
+" -m mask -- Specify the field mask for the statx call\n"
+" (can also be 'basic' or 'all'; default STATX_ALL)\n"
+" -D -- Don't sync attributes with the server\n"
+" -F -- Force the attributes to be sync'd with the server\n"
+"\n"));
+}
+
+/* statx helper */
+static int
+dump_raw_statx(struct statx *stx)
+{
+ printf("stat.mask = 0x%x\n", stx->stx_mask);
+ printf("stat.blksize = %u\n", stx->stx_blksize);
+ printf("stat.attributes = 0x%llx\n", stx->stx_attributes);
+ printf("stat.nlink = %u\n", stx->stx_nlink);
+ printf("stat.uid = %u\n", stx->stx_uid);
+ printf("stat.gid = %u\n", stx->stx_gid);
+ printf("stat.mode: 0%o\n", stx->stx_mode);
+ printf("stat.ino = %llu\n", stx->stx_ino);
+ printf("stat.size = %llu\n", stx->stx_size);
+ printf("stat.blocks = %llu\n", stx->stx_blocks);
+ printf("stat.atime.tv_sec = %lld\n", stx->stx_atime.tv_sec);
+ printf("stat.atime.tv_nsec = %d\n", stx->stx_atime.tv_nsec);
+ printf("stat.btime.tv_sec = %lld\n", stx->stx_btime.tv_sec);
+ printf("stat.btime.tv_nsec = %d\n", stx->stx_btime.tv_nsec);
+ printf("stat.ctime.tv_sec = %lld\n", stx->stx_ctime.tv_sec);
+ printf("stat.ctime.tv_nsec = %d\n", stx->stx_ctime.tv_nsec);
+ printf("stat.mtime.tv_sec = %lld\n", stx->stx_mtime.tv_sec);
+ printf("stat.mtime.tv_nsec = %d\n", stx->stx_mtime.tv_nsec);
+ printf("stat.rdev_major = %u\n", stx->stx_rdev_major);
+ printf("stat.rdev_minor = %u\n", stx->stx_rdev_minor);
+ printf("stat.dev_major = %u\n", stx->stx_dev_major);
+ printf("stat.dev_minor = %u\n", stx->stx_dev_minor);
+ return 0;
+}
+
+/*
+ * options:
+ * - input flags - query type
+ * - output style for flags (and all else?) (chars vs. hex?)
+ * - output - mask out incidental flag or not?
+ */
+int
+statx_f(
+ int argc,
+ char **argv)
+{
+ int c, verbose = 0, raw = 0;
+ char *p;
+ struct statx stx;
+ int atflag = 0;
+ unsigned int mask = STATX_ALL;
+
+ while ((c = getopt(argc, argv, "m:rvFD")) != EOF) {
+ switch (c) {
+ case 'm':
+ if (strcmp(optarg, "basic") == 0)
+ mask = STATX_BASIC_STATS;
+ else if (strcmp(optarg, "all") == 0)
+ mask = STATX_ALL;
+ else {
+ mask = strtoul(optarg, &p, 0);
+ if (!p || p == optarg) {
+ printf(
+ _("non-numeric mask -- %s\n"), optarg);
+ return 0;
+ }
+ }
+ break;
+ case 'r':
+ raw = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'F':
+ atflag &= ~AT_STATX_SYNC_TYPE;
+ atflag |= AT_STATX_FORCE_SYNC;
+ break;
+ case 'D':
+ atflag &= ~AT_STATX_SYNC_TYPE;
+ atflag |= AT_STATX_DONT_SYNC;
+ break;
+ default:
+ return command_usage(&statx_cmd);
+ }
+ }
+
+ if (raw && verbose)
+ return command_usage(&statx_cmd);
+
+ memset(&stx, 0xbf, sizeof(stx));
+ if (_statx(file->fd, NULL, atflag, mask, &stx) < 0) {
+ perror("statx");
+ return 0;
+ }
+
+ if (raw)
+ return dump_raw_statx(&stx);
+
+ print_file_info();
+
+ printf(_("stat.ino = %lld\n"), (long long)stx.stx_ino);
+ printf(_("stat.type = %s\n"), filetype(stx.stx_mode));
+ printf(_("stat.size = %lld\n"), (long long)stx.stx_size);
+ printf(_("stat.blocks = %lld\n"), (long long)stx.stx_blocks);
+ if (verbose) {
+ printf(_("stat.atime = %s"), ctime((time_t *)&stx.stx_atime.tv_sec));
+ printf(_("stat.mtime = %s"), ctime((time_t *)&stx.stx_mtime.tv_sec));
+ printf(_("stat.ctime = %s"), ctime((time_t *)&stx.stx_ctime.tv_sec));
+ if (stx.stx_mask & STATX_BTIME)
+ printf(_("stat.btime = %s"),
+ ctime((time_t *)&stx.stx_btime.tv_sec));
+ }
+
+ if (file->flags & IO_FOREIGN)
+ return 0;
+
+ print_xfs_info(verbose);
+
+ return 0;
+}
+
void
stat_init(void)
{
@@ -237,6 +393,15 @@ stat_init(void)
stat_cmd.args = _("[-v|-r]");
stat_cmd.oneline = _("statistics on the currently open file");
+ statx_cmd.name = "statx";
+ statx_cmd.cfunc = statx_f;
+ statx_cmd.argmin = 0;
+ statx_cmd.argmax = -1;
+ statx_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+ statx_cmd.args = _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
+ statx_cmd.oneline = _("extended statistics on the currently open file");
+ statx_cmd.help = statx_help;
+
statfs_cmd.name = "statfs";
statfs_cmd.cfunc = statfs_f;
statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
@@ -244,5 +409,6 @@ stat_init(void)
_("statistics on the filesystem of the currently open file");
add_command(&stat_cmd);
+ add_command(&statx_cmd);
add_command(&statfs_cmd);
}
diff --git a/io/statx.h b/io/statx.h
new file mode 100644
index 0000000..ff08e27
--- /dev/null
+++ b/io/statx.h
@@ -0,0 +1,162 @@
+#ifndef XFS_IO_STATX_H
+#define XFS_IO_STATX_H
+
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#ifndef AT_STATX_SYNC_TYPE
+#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
+#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
+#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
+#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
+#endif
+
+#ifndef AT_NO_AUTOMOUNT
+#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
+#endif
+
+#ifndef __NR_statx
+# ifdef __i386__
+# define __NR_statx 383
+# elif defined (__ILP32__)
+# define __NR_statx (__X32_SYSCALL_BIT + 332)
+# elif defined (__x86_64__)
+# define __NR_statx 332
+# endif
+#endif
+
+#ifndef STATX_TYPE
+
+/*
+ * Timestamp structure for the timestamps in struct statx.
+ *
+ * tv_sec holds the number of seconds before (negative) or after (positive)
+ * 00:00:00 1st January 1970 UTC.
+ *
+ * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
+ * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
+ *
+ * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
+ * either be both positive or both negative.
+ *
+ * __reserved is held in case we need a yet finer resolution.
+ */
+struct statx_timestamp {
+ __s64 tv_sec;
+ __s32 tv_nsec;
+ __s32 __reserved;
+};
+
+/*
+ * Structures for the extended file attribute retrieval system call
+ * (statx()).
+ *
+ * The caller passes a mask of what they're specifically interested in as a
+ * parameter to statx(). What statx() actually got will be indicated in
+ * st_mask upon return.
+ *
+ * For each bit in the mask argument:
+ *
+ * - if the datum is not supported:
+ *
+ * - the bit will be cleared, and
+ *
+ * - the datum will be set to an appropriate fabricated value if one is
+ * available (eg. CIFS can take a default uid and gid), otherwise
+ *
+ * - the field will be cleared;
+ *
+ * - otherwise, if explicitly requested:
+ *
+ * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
+ * set or if the datum is considered out of date, and
+ *
+ * - the field will be filled in and the bit will be set;
+ *
+ * - otherwise, if not requested, but available in approximate form without any
+ * effort, it will be filled in anyway, and the bit will be set upon return
+ * (it might not be up to date, however, and no attempt will be made to
+ * synchronise the internal state first);
+ *
+ * - otherwise the field and the bit will be cleared before returning.
+ *
+ * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
+ * will have values installed for compatibility purposes so that stat() and
+ * co. can be emulated in userspace.
+ */
+struct statx {
+ /* 0x00 */
+ __u32 stx_mask; /* What results were written [uncond] */
+ __u32 stx_blksize; /* Preferred general I/O size [uncond] */
+ __u64 stx_attributes; /* Flags conveying information about the file [uncond] */
+ /* 0x10 */
+ __u32 stx_nlink; /* Number of hard links */
+ __u32 stx_uid; /* User ID of owner */
+ __u32 stx_gid; /* Group ID of owner */
+ __u16 stx_mode; /* File mode */
+ __u16 __spare0[1];
+ /* 0x20 */
+ __u64 stx_ino; /* Inode number */
+ __u64 stx_size; /* File size */
+ __u64 stx_blocks; /* Number of 512-byte blocks allocated */
+ __u64 __spare1[1];
+ /* 0x40 */
+ struct statx_timestamp stx_atime; /* Last access time */
+ struct statx_timestamp stx_btime; /* File creation time */
+ struct statx_timestamp stx_ctime; /* Last attribute change time */
+ struct statx_timestamp stx_mtime; /* Last data modification time */
+ /* 0x80 */
+ __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
+ __u32 stx_rdev_minor;
+ __u32 stx_dev_major; /* ID of device containing file [uncond] */
+ __u32 stx_dev_minor;
+ /* 0x90 */
+ __u64 __spare2[14]; /* Spare space for future expansion */
+ /* 0x100 */
+};
+
+/*
+ * Flags to be stx_mask
+ *
+ * Query request/result mask for statx() and struct statx::stx_mask.
+ *
+ * These bits should be set in the mask argument of statx() to request
+ * particular items when calling statx().
+ */
+#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
+#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
+#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
+#define STATX_UID 0x00000008U /* Want/got stx_uid */
+#define STATX_GID 0x00000010U /* Want/got stx_gid */
+#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
+#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
+#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
+#define STATX_INO 0x00000100U /* Want/got stx_ino */
+#define STATX_SIZE 0x00000200U /* Want/got stx_size */
+#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
+#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
+#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
+#define STATX_ALL 0x00000fffU /* All currently supported flags */
+#define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */
+
+/*
+ * Attributes to be found in stx_attributes
+ *
+ * These give information about the features or the state of a file that might
+ * be of use to ordinary userspace programs such as GUIs or ls rather than
+ * specialised tools.
+ *
+ * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * semantically. Where possible, the numerical value is picked to correspond
+ * also.
+ */
+#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
+#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
+#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
+#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
+#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
+
+#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
+
+#endif /* STATX_TYPE */
+#endif /* XFS_IO_STATX_H */
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index e384327..b09a178 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -882,6 +882,36 @@ option is specified, the atime (last access), mtime
.B \-r
option dumps raw fields from the stat structure.
.TP
+.BI "statx [ \-v|\-r ][ \-m " basic " | \-m " all " | -m " <mask> " ][ \-FD ]"
+Selected statistics from
+.BR stat (2)
+and the XFS_IOC_GETXATTR system call on the current file.
+.RS 1.0i
+.PD 0
+.TP 0.4i
+.B \-v
+Show timestamps.
+.TP
+.B \-r
+Dump raw statx structure values.
+.TP
+.B \-m basic
+Set the field mask for the statx call to STATX_BASIC_STATS.
+.TP
+.B \-m all
+Set the the field mask for the statx call to STATX_ALL (default).
+.TP
+.B \-m <mask>
+Specify a numeric field mask for the statx call.
+.TP
+.B \-F
+Force the attributes to be synced with the server.
+.TP
+.B \-D
+Don't sync attributes with the server.
+.PD
+.RE
+.TP
.B statfs
Selected statistics from
.BR statfs (2)
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3 V5] xfs_io: hook up statx
2017-04-10 22:07 ` [PATCH 3/3 V5] " Eric Sandeen
@ 2017-04-10 22:13 ` Darrick J. Wong
0 siblings, 0 replies; 11+ messages in thread
From: Darrick J. Wong @ 2017-04-10 22:13 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-xfs, fsdevel, David Howells
On Mon, Apr 10, 2017 at 05:07:58PM -0500, Eric Sandeen wrote:
> Wire up the statx syscall to xfs_io.
>
> xfs_io> help statx
> statx [-v|-r][-m basic | -m all | -m <mask>][-FD] -- extended statistics on the currently open file
>
> Display extended file status.
>
> Options:
> -v -- More verbose output
> -r -- Print raw statx structure fields
> -m mask -- Specify the field mask for the statx call
> (can also be 'basic' or 'all'; default STATX_ALL)
> -D -- Don't sync attributes with the server
> -F -- Force the attributes to be sync'd with the server
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>
> V5: address djwong's pedantry, except for mst3k ;)
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
>
> V4: Fix up __NR_statx defines, handle it if not defined (ala dhowells testcase)
> fix trailing whitespace in manpage
>
> V3: remove -A, -L, and -O options
> allow "basic" and "all" masks
> change raw dump format to match stat raw format
> make -r and -v exclusive
> follow factoring of stat_f()
>
>
> diff --git a/io/stat.c b/io/stat.c
> index 770f3c7..c5b3075 100644
> --- a/io/stat.c
> +++ b/io/stat.c
> @@ -2,6 +2,9 @@
> * Copyright (c) 2003-2005 Silicon Graphics, Inc.
> * All Rights Reserved.
> *
> + * Copyright (C) 2015, 2017 Red Hat, Inc.
> + * Portions of statx support written by David Howells (dhowells@redhat.com)
> + *
> * This program is free software; you can redistribute it and/or
> * modify it under the terms of the GNU General Public License as
> * published by the Free Software Foundation.
> @@ -20,10 +23,14 @@
> #include "input.h"
> #include "init.h"
> #include "io.h"
> +#include "statx.h"
> #include "libxfs.h"
>
> +#include <fcntl.h>
> +
> static cmdinfo_t stat_cmd;
> static cmdinfo_t statfs_cmd;
> +static cmdinfo_t statx_cmd;
>
> off64_t
> filesize(void)
> @@ -226,6 +233,155 @@ statfs_f(
> return 0;
> }
>
> +static ssize_t
> +_statx(
> + int dfd,
> + const char *filename,
> + unsigned int flags,
> + unsigned int mask,
> + struct statx *buffer)
> +{
> +#ifdef __NR_statx
> + return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
> +#else
> + errno = ENOSYS;
> + return -1;
> +#endif
> +}
> +
> +static void
> +statx_help(void)
> +{
> + printf(_(
> +"\n"
> +" Display extended file status.\n"
> +"\n"
> +" Options:\n"
> +" -v -- More verbose output\n"
> +" -r -- Print raw statx structure fields\n"
> +" -m mask -- Specify the field mask for the statx call\n"
> +" (can also be 'basic' or 'all'; default STATX_ALL)\n"
> +" -D -- Don't sync attributes with the server\n"
> +" -F -- Force the attributes to be sync'd with the server\n"
> +"\n"));
> +}
> +
> +/* statx helper */
> +static int
> +dump_raw_statx(struct statx *stx)
> +{
> + printf("stat.mask = 0x%x\n", stx->stx_mask);
> + printf("stat.blksize = %u\n", stx->stx_blksize);
> + printf("stat.attributes = 0x%llx\n", stx->stx_attributes);
> + printf("stat.nlink = %u\n", stx->stx_nlink);
> + printf("stat.uid = %u\n", stx->stx_uid);
> + printf("stat.gid = %u\n", stx->stx_gid);
> + printf("stat.mode: 0%o\n", stx->stx_mode);
> + printf("stat.ino = %llu\n", stx->stx_ino);
> + printf("stat.size = %llu\n", stx->stx_size);
> + printf("stat.blocks = %llu\n", stx->stx_blocks);
> + printf("stat.atime.tv_sec = %lld\n", stx->stx_atime.tv_sec);
> + printf("stat.atime.tv_nsec = %d\n", stx->stx_atime.tv_nsec);
> + printf("stat.btime.tv_sec = %lld\n", stx->stx_btime.tv_sec);
> + printf("stat.btime.tv_nsec = %d\n", stx->stx_btime.tv_nsec);
> + printf("stat.ctime.tv_sec = %lld\n", stx->stx_ctime.tv_sec);
> + printf("stat.ctime.tv_nsec = %d\n", stx->stx_ctime.tv_nsec);
> + printf("stat.mtime.tv_sec = %lld\n", stx->stx_mtime.tv_sec);
> + printf("stat.mtime.tv_nsec = %d\n", stx->stx_mtime.tv_nsec);
> + printf("stat.rdev_major = %u\n", stx->stx_rdev_major);
> + printf("stat.rdev_minor = %u\n", stx->stx_rdev_minor);
> + printf("stat.dev_major = %u\n", stx->stx_dev_major);
> + printf("stat.dev_minor = %u\n", stx->stx_dev_minor);
> + return 0;
> +}
> +
> +/*
> + * options:
> + * - input flags - query type
> + * - output style for flags (and all else?) (chars vs. hex?)
> + * - output - mask out incidental flag or not?
> + */
> +int
> +statx_f(
> + int argc,
> + char **argv)
> +{
> + int c, verbose = 0, raw = 0;
> + char *p;
> + struct statx stx;
> + int atflag = 0;
> + unsigned int mask = STATX_ALL;
> +
> + while ((c = getopt(argc, argv, "m:rvFD")) != EOF) {
> + switch (c) {
> + case 'm':
> + if (strcmp(optarg, "basic") == 0)
> + mask = STATX_BASIC_STATS;
> + else if (strcmp(optarg, "all") == 0)
> + mask = STATX_ALL;
> + else {
> + mask = strtoul(optarg, &p, 0);
> + if (!p || p == optarg) {
> + printf(
> + _("non-numeric mask -- %s\n"), optarg);
> + return 0;
> + }
> + }
> + break;
> + case 'r':
> + raw = 1;
> + break;
> + case 'v':
> + verbose = 1;
> + break;
> + case 'F':
> + atflag &= ~AT_STATX_SYNC_TYPE;
> + atflag |= AT_STATX_FORCE_SYNC;
> + break;
> + case 'D':
> + atflag &= ~AT_STATX_SYNC_TYPE;
> + atflag |= AT_STATX_DONT_SYNC;
> + break;
> + default:
> + return command_usage(&statx_cmd);
> + }
> + }
> +
> + if (raw && verbose)
> + return command_usage(&statx_cmd);
> +
> + memset(&stx, 0xbf, sizeof(stx));
> + if (_statx(file->fd, NULL, atflag, mask, &stx) < 0) {
> + perror("statx");
> + return 0;
> + }
> +
> + if (raw)
> + return dump_raw_statx(&stx);
> +
> + print_file_info();
> +
> + printf(_("stat.ino = %lld\n"), (long long)stx.stx_ino);
> + printf(_("stat.type = %s\n"), filetype(stx.stx_mode));
> + printf(_("stat.size = %lld\n"), (long long)stx.stx_size);
> + printf(_("stat.blocks = %lld\n"), (long long)stx.stx_blocks);
> + if (verbose) {
> + printf(_("stat.atime = %s"), ctime((time_t *)&stx.stx_atime.tv_sec));
> + printf(_("stat.mtime = %s"), ctime((time_t *)&stx.stx_mtime.tv_sec));
> + printf(_("stat.ctime = %s"), ctime((time_t *)&stx.stx_ctime.tv_sec));
> + if (stx.stx_mask & STATX_BTIME)
> + printf(_("stat.btime = %s"),
> + ctime((time_t *)&stx.stx_btime.tv_sec));
> + }
> +
> + if (file->flags & IO_FOREIGN)
> + return 0;
> +
> + print_xfs_info(verbose);
> +
> + return 0;
> +}
> +
> void
> stat_init(void)
> {
> @@ -237,6 +393,15 @@ stat_init(void)
> stat_cmd.args = _("[-v|-r]");
> stat_cmd.oneline = _("statistics on the currently open file");
>
> + statx_cmd.name = "statx";
> + statx_cmd.cfunc = statx_f;
> + statx_cmd.argmin = 0;
> + statx_cmd.argmax = -1;
> + statx_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> + statx_cmd.args = _("[-v|-r][-m basic | -m all | -m <mask>][-FD]");
> + statx_cmd.oneline = _("extended statistics on the currently open file");
> + statx_cmd.help = statx_help;
> +
> statfs_cmd.name = "statfs";
> statfs_cmd.cfunc = statfs_f;
> statfs_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> @@ -244,5 +409,6 @@ stat_init(void)
> _("statistics on the filesystem of the currently open file");
>
> add_command(&stat_cmd);
> + add_command(&statx_cmd);
> add_command(&statfs_cmd);
> }
> diff --git a/io/statx.h b/io/statx.h
> new file mode 100644
> index 0000000..ff08e27
> --- /dev/null
> +++ b/io/statx.h
> @@ -0,0 +1,162 @@
> +#ifndef XFS_IO_STATX_H
> +#define XFS_IO_STATX_H
> +
> +#include <unistd.h>
> +#include <sys/syscall.h>
> +
> +#ifndef AT_STATX_SYNC_TYPE
> +#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */
> +#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */
> +#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */
> +#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */
> +#endif
> +
> +#ifndef AT_NO_AUTOMOUNT
> +#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */
> +#endif
> +
> +#ifndef __NR_statx
> +# ifdef __i386__
> +# define __NR_statx 383
> +# elif defined (__ILP32__)
> +# define __NR_statx (__X32_SYSCALL_BIT + 332)
> +# elif defined (__x86_64__)
> +# define __NR_statx 332
> +# endif
> +#endif
> +
> +#ifndef STATX_TYPE
> +
> +/*
> + * Timestamp structure for the timestamps in struct statx.
> + *
> + * tv_sec holds the number of seconds before (negative) or after (positive)
> + * 00:00:00 1st January 1970 UTC.
> + *
> + * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
> + * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
> + *
> + * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
> + * either be both positive or both negative.
> + *
> + * __reserved is held in case we need a yet finer resolution.
> + */
> +struct statx_timestamp {
> + __s64 tv_sec;
> + __s32 tv_nsec;
> + __s32 __reserved;
> +};
> +
> +/*
> + * Structures for the extended file attribute retrieval system call
> + * (statx()).
> + *
> + * The caller passes a mask of what they're specifically interested in as a
> + * parameter to statx(). What statx() actually got will be indicated in
> + * st_mask upon return.
> + *
> + * For each bit in the mask argument:
> + *
> + * - if the datum is not supported:
> + *
> + * - the bit will be cleared, and
> + *
> + * - the datum will be set to an appropriate fabricated value if one is
> + * available (eg. CIFS can take a default uid and gid), otherwise
> + *
> + * - the field will be cleared;
> + *
> + * - otherwise, if explicitly requested:
> + *
> + * - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
> + * set or if the datum is considered out of date, and
> + *
> + * - the field will be filled in and the bit will be set;
> + *
> + * - otherwise, if not requested, but available in approximate form without any
> + * effort, it will be filled in anyway, and the bit will be set upon return
> + * (it might not be up to date, however, and no attempt will be made to
> + * synchronise the internal state first);
> + *
> + * - otherwise the field and the bit will be cleared before returning.
> + *
> + * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
> + * will have values installed for compatibility purposes so that stat() and
> + * co. can be emulated in userspace.
> + */
> +struct statx {
> + /* 0x00 */
> + __u32 stx_mask; /* What results were written [uncond] */
> + __u32 stx_blksize; /* Preferred general I/O size [uncond] */
> + __u64 stx_attributes; /* Flags conveying information about the file [uncond] */
> + /* 0x10 */
> + __u32 stx_nlink; /* Number of hard links */
> + __u32 stx_uid; /* User ID of owner */
> + __u32 stx_gid; /* Group ID of owner */
> + __u16 stx_mode; /* File mode */
> + __u16 __spare0[1];
> + /* 0x20 */
> + __u64 stx_ino; /* Inode number */
> + __u64 stx_size; /* File size */
> + __u64 stx_blocks; /* Number of 512-byte blocks allocated */
> + __u64 __spare1[1];
> + /* 0x40 */
> + struct statx_timestamp stx_atime; /* Last access time */
> + struct statx_timestamp stx_btime; /* File creation time */
> + struct statx_timestamp stx_ctime; /* Last attribute change time */
> + struct statx_timestamp stx_mtime; /* Last data modification time */
> + /* 0x80 */
> + __u32 stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
> + __u32 stx_rdev_minor;
> + __u32 stx_dev_major; /* ID of device containing file [uncond] */
> + __u32 stx_dev_minor;
> + /* 0x90 */
> + __u64 __spare2[14]; /* Spare space for future expansion */
> + /* 0x100 */
> +};
> +
> +/*
> + * Flags to be stx_mask
> + *
> + * Query request/result mask for statx() and struct statx::stx_mask.
> + *
> + * These bits should be set in the mask argument of statx() to request
> + * particular items when calling statx().
> + */
> +#define STATX_TYPE 0x00000001U /* Want/got stx_mode & S_IFMT */
> +#define STATX_MODE 0x00000002U /* Want/got stx_mode & ~S_IFMT */
> +#define STATX_NLINK 0x00000004U /* Want/got stx_nlink */
> +#define STATX_UID 0x00000008U /* Want/got stx_uid */
> +#define STATX_GID 0x00000010U /* Want/got stx_gid */
> +#define STATX_ATIME 0x00000020U /* Want/got stx_atime */
> +#define STATX_MTIME 0x00000040U /* Want/got stx_mtime */
> +#define STATX_CTIME 0x00000080U /* Want/got stx_ctime */
> +#define STATX_INO 0x00000100U /* Want/got stx_ino */
> +#define STATX_SIZE 0x00000200U /* Want/got stx_size */
> +#define STATX_BLOCKS 0x00000400U /* Want/got stx_blocks */
> +#define STATX_BASIC_STATS 0x000007ffU /* The stuff in the normal stat struct */
> +#define STATX_BTIME 0x00000800U /* Want/got stx_btime */
> +#define STATX_ALL 0x00000fffU /* All currently supported flags */
> +#define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */
> +
> +/*
> + * Attributes to be found in stx_attributes
> + *
> + * These give information about the features or the state of a file that might
> + * be of use to ordinary userspace programs such as GUIs or ls rather than
> + * specialised tools.
> + *
> + * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
> + * semantically. Where possible, the numerical value is picked to correspond
> + * also.
> + */
> +#define STATX_ATTR_COMPRESSED 0x00000004 /* [I] File is compressed by the fs */
> +#define STATX_ATTR_IMMUTABLE 0x00000010 /* [I] File is marked immutable */
> +#define STATX_ATTR_APPEND 0x00000020 /* [I] File is append-only */
> +#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
> +#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
> +
> +#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
> +
> +#endif /* STATX_TYPE */
> +#endif /* XFS_IO_STATX_H */
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index e384327..b09a178 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -882,6 +882,36 @@ option is specified, the atime (last access), mtime
> .B \-r
> option dumps raw fields from the stat structure.
> .TP
> +.BI "statx [ \-v|\-r ][ \-m " basic " | \-m " all " | -m " <mask> " ][ \-FD ]"
> +Selected statistics from
> +.BR stat (2)
> +and the XFS_IOC_GETXATTR system call on the current file.
> +.RS 1.0i
> +.PD 0
> +.TP 0.4i
> +.B \-v
> +Show timestamps.
> +.TP
> +.B \-r
> +Dump raw statx structure values.
> +.TP
> +.B \-m basic
> +Set the field mask for the statx call to STATX_BASIC_STATS.
> +.TP
> +.B \-m all
> +Set the the field mask for the statx call to STATX_ALL (default).
> +.TP
> +.B \-m <mask>
> +Specify a numeric field mask for the statx call.
> +.TP
> +.B \-F
> +Force the attributes to be synced with the server.
> +.TP
> +.B \-D
> +Don't sync attributes with the server.
> +.PD
> +.RE
> +.TP
> .B statfs
> Selected statistics from
> .BR statfs (2)
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/3 V3] xfs_io: hook up statx
2017-04-06 18:43 [PATCH 0/3 V3] xfs_io: hook up statx Eric Sandeen
` (2 preceding siblings ...)
2017-04-06 18:53 ` [PATCH 3/3] xfs_io: hook up statx Eric Sandeen
@ 2017-04-10 22:36 ` David Howells
3 siblings, 0 replies; 11+ messages in thread
From: David Howells @ 2017-04-10 22:36 UTC (permalink / raw)
To: Eric Sandeen; +Cc: dhowells, linux-xfs, fsdevel
Eric Sandeen <sandeen@sandeen.net> wrote:
> These 3 patches are a third pass to add a statx command
> to xfs_io in hopes that it will aid creation of xfstests
> statx regression tests.
Reviewed-and-tested-by: David Howells <dhowells@redhat.com>
to V3 of the first and second patches and V5 of the third patch.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-04-10 22:36 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-06 18:43 [PATCH 0/3 V3] xfs_io: hook up statx Eric Sandeen
2017-04-06 18:46 ` [PATCH 1/3] xfs_io: move stat functions to new file Eric Sandeen
2017-04-10 21:47 ` Darrick J. Wong
2017-04-06 18:48 ` [PATCH 2/3] xfs_io: refactor stat functions, add raw dump Eric Sandeen
2017-04-10 21:48 ` Darrick J. Wong
2017-04-06 18:53 ` [PATCH 3/3] xfs_io: hook up statx Eric Sandeen
2017-04-10 21:33 ` [PATCH 3/3 V4] " Eric Sandeen
2017-04-10 21:56 ` Darrick J. Wong
2017-04-10 22:07 ` [PATCH 3/3 V5] " Eric Sandeen
2017-04-10 22:13 ` Darrick J. Wong
2017-04-10 22:36 ` [PATCH 0/3 V3] " David Howells
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.