* [PATCH] xfs_io: print sysfs paths of mounted filesystems
@ 2024-06-02 23:29 ` Darrick J. Wong
2024-06-03 12:49 ` Carlos Maiolino
0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2024-06-02 23:29 UTC (permalink / raw)
To: Carlos Maiolino, Kent Overstreet; +Cc: xfs
From: Darrick J. Wong <djwong@kernel.org>
Enable users to print the sysfs or debugfs path for the filesystems
backing the open files.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
io/fsuuid.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
man/man8/xfs_io.8 | 7 +++++
2 files changed, 75 insertions(+)
diff --git a/io/fsuuid.c b/io/fsuuid.c
index af2f87a20209..8e50ec14c8fd 100644
--- a/io/fsuuid.c
+++ b/io/fsuuid.c
@@ -12,6 +12,7 @@
#include "libfrog/logging.h"
static cmdinfo_t fsuuid_cmd;
+static cmdinfo_t sysfspath_cmd;
static int
fsuuid_f(
@@ -35,6 +36,62 @@ fsuuid_f(
return 0;
}
+#ifndef FS_IOC_GETFSSYSFSPATH
+struct fs_sysfs_path {
+ __u8 len;
+ __u8 name[128];
+};
+#define FS_IOC_GETFSSYSFSPATH _IOR(0x15, 1, struct fs_sysfs_path)
+#endif
+
+static void
+sysfspath_help(void)
+{
+ printf(_(
+"\n"
+" print the sysfs path for the open file\n"
+"\n"
+" Prints the path in sysfs where one might find information about the\n"
+" filesystem backing the open files. The path is not required to exist.\n"
+" -d -- return the path in debugfs, if any\n"
+"\n"));
+}
+
+static int
+sysfspath_f(
+ int argc,
+ char **argv)
+{
+ struct fs_sysfs_path path;
+ bool debugfs = false;
+ int c;
+ int ret;
+
+ while ((c = getopt(argc, argv, "d")) != EOF) {
+ switch (c) {
+ case 'd':
+ debugfs = true;
+ break;
+ default:
+ exitcode = 1;
+ return command_usage(&sysfspath_cmd);
+ }
+ }
+
+ ret = ioctl(file->fd, FS_IOC_GETFSSYSFSPATH, &path);
+ if (ret) {
+ xfrog_perror(ret, "FS_IOC_GETSYSFSPATH");
+ exitcode = 1;
+ return 0;
+ }
+
+ if (debugfs)
+ printf("/sys/kernel/debug/%.*s\n", path.len, path.name);
+ else
+ printf("/sys/fs/%.*s\n", path.len, path.name);
+ return 0;
+}
+
void
fsuuid_init(void)
{
@@ -46,4 +103,15 @@ fsuuid_init(void)
fsuuid_cmd.oneline = _("get mounted filesystem UUID");
add_command(&fsuuid_cmd);
+
+ sysfspath_cmd.name = "sysfspath";
+ sysfspath_cmd.cfunc = sysfspath_f;
+ sysfspath_cmd.argmin = 0;
+ sysfspath_cmd.argmax = -1;
+ sysfspath_cmd.args = _("-d");
+ sysfspath_cmd.flags = CMD_NOMAP_OK | CMD_FLAG_FOREIGN_OK;
+ sysfspath_cmd.oneline = _("get mounted filesystem sysfs path");
+ sysfspath_cmd.help = sysfspath_help;
+
+ add_command(&sysfspath_cmd);
}
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index 56abe000f235..3ce280a75b4a 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -1464,6 +1464,13 @@ flag.
.TP
.B fsuuid
Print the mounted filesystem UUID.
+.TP
+.B sysfspath
+Print the sysfs or debugfs path for the mounted filesystem.
+
+The
+.B -d
+option selects debugfs instead of sysfs.
.SH OTHER COMMANDS
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] xfs_io: print sysfs paths of mounted filesystems
2024-06-02 23:29 ` [PATCH] xfs_io: print sysfs paths of mounted filesystems Darrick J. Wong
@ 2024-06-03 12:49 ` Carlos Maiolino
0 siblings, 0 replies; 2+ messages in thread
From: Carlos Maiolino @ 2024-06-03 12:49 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Kent Overstreet, xfs
On Sun, Jun 02, 2024 at 04:29:49PM GMT, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Enable users to print the sysfs or debugfs path for the filesystems
> backing the open files.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
> ---
> io/fsuuid.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> man/man8/xfs_io.8 | 7 +++++
> 2 files changed, 75 insertions(+)
>
> diff --git a/io/fsuuid.c b/io/fsuuid.c
> index af2f87a20209..8e50ec14c8fd 100644
> --- a/io/fsuuid.c
> +++ b/io/fsuuid.c
> @@ -12,6 +12,7 @@
> #include "libfrog/logging.h"
>
> static cmdinfo_t fsuuid_cmd;
> +static cmdinfo_t sysfspath_cmd;
>
> static int
> fsuuid_f(
> @@ -35,6 +36,62 @@ fsuuid_f(
> return 0;
> }
>
> +#ifndef FS_IOC_GETFSSYSFSPATH
> +struct fs_sysfs_path {
> + __u8 len;
> + __u8 name[128];
> +};
> +#define FS_IOC_GETFSSYSFSPATH _IOR(0x15, 1, struct fs_sysfs_path)
> +#endif
> +
> +static void
> +sysfspath_help(void)
> +{
> + printf(_(
> +"\n"
> +" print the sysfs path for the open file\n"
> +"\n"
> +" Prints the path in sysfs where one might find information about the\n"
> +" filesystem backing the open files. The path is not required to exist.\n"
> +" -d -- return the path in debugfs, if any\n"
> +"\n"));
> +}
> +
> +static int
> +sysfspath_f(
> + int argc,
> + char **argv)
> +{
> + struct fs_sysfs_path path;
> + bool debugfs = false;
> + int c;
> + int ret;
> +
> + while ((c = getopt(argc, argv, "d")) != EOF) {
> + switch (c) {
> + case 'd':
> + debugfs = true;
> + break;
> + default:
> + exitcode = 1;
> + return command_usage(&sysfspath_cmd);
> + }
> + }
> +
> + ret = ioctl(file->fd, FS_IOC_GETFSSYSFSPATH, &path);
> + if (ret) {
> + xfrog_perror(ret, "FS_IOC_GETSYSFSPATH");
> + exitcode = 1;
> + return 0;
> + }
> +
> + if (debugfs)
> + printf("/sys/kernel/debug/%.*s\n", path.len, path.name);
> + else
> + printf("/sys/fs/%.*s\n", path.len, path.name);
> + return 0;
> +}
> +
> void
> fsuuid_init(void)
> {
> @@ -46,4 +103,15 @@ fsuuid_init(void)
> fsuuid_cmd.oneline = _("get mounted filesystem UUID");
>
> add_command(&fsuuid_cmd);
> +
> + sysfspath_cmd.name = "sysfspath";
> + sysfspath_cmd.cfunc = sysfspath_f;
> + sysfspath_cmd.argmin = 0;
> + sysfspath_cmd.argmax = -1;
> + sysfspath_cmd.args = _("-d");
> + sysfspath_cmd.flags = CMD_NOMAP_OK | CMD_FLAG_FOREIGN_OK;
> + sysfspath_cmd.oneline = _("get mounted filesystem sysfs path");
> + sysfspath_cmd.help = sysfspath_help;
> +
> + add_command(&sysfspath_cmd);
> }
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index 56abe000f235..3ce280a75b4a 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -1464,6 +1464,13 @@ flag.
> .TP
> .B fsuuid
> Print the mounted filesystem UUID.
> +.TP
> +.B sysfspath
> +Print the sysfs or debugfs path for the mounted filesystem.
> +
> +The
> +.B -d
> +option selects debugfs instead of sysfs.
>
>
> .SH OTHER COMMANDS
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-03 12:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1om_d115LQlficlrvs8z5v0InzJMyVDs_WfIJ1ttxO6uOL4FNNGJWtpebpaOoO0MIL7ZUgh7Xm224Eb-aKVaAg==@protonmail.internalid>
2024-06-02 23:29 ` [PATCH] xfs_io: print sysfs paths of mounted filesystems Darrick J. Wong
2024-06-03 12:49 ` Carlos Maiolino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox