]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: print sysfs paths of mounted filesystems
authorDarrick J. Wong <djwong@kernel.org>
Thu, 23 May 2024 16:25:27 +0000 (09:25 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 3 Jun 2024 18:37:43 +0000 (11:37 -0700)
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
man/man8/xfs_io.8
quota/quota.c
quota/quota.h
quota/util.c

index af2f87a202093a8456c7d9a452564936d1324aa4..8e50ec14c8fd1fa46927c3eaaa74e5006a48790b 100644 (file)
@@ -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);
 }
index 56abe000f235fb350c4ec7e21292033893ce442a..3ce280a75b4a1551f806a56fffec88613d8e6cf6 100644 (file)
@@ -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
index 0747cedcb8c2930b651e40792d0b80effc27f33a..fea55f03b34257dfcbe1232612c577ecbd23fc25 100644 (file)
@@ -58,6 +58,8 @@ quota_mount(
        if (xfsquotactl(XFS_GETQUOTA, dev, type, id, (void *)&d) < 0)
                return 0;
 
+       dquot_fudge_numbers(&d);
+
        if (!(flags & VERBOSE_FLAG)) {
                count = 0;
                if ((form & XFS_BLOCK_QUOTA) && d.d_bcount)
index 78b0d66d2a4f8ff85cb16e0ae7850d1f3243d899..ece920ef6c1b46981c1dc366075314eef9b0027b 100644 (file)
@@ -49,6 +49,26 @@ extern char *pct_to_string(uint64_t __v, uint64_t __t, char *__c, uint __s);
 
 extern FILE *fopen_write_secure(char *__filename);
 
+void __dquot_fudge_numbers(struct fs_disk_quota *d);
+
+extern int expert;
+
+/*
+ * Fudge the rtblock quota numbers if we're running in fstests so we don't have
+ * to rewrite fstests.
+ */
+static inline bool
+dquot_want_fudged_numbers(void)
+{
+       return expert && getenv("XFSTESTS_RTQUOTA_FAKERY") != NULL;
+}
+
+static inline void dquot_fudge_numbers(struct fs_disk_quota *d)
+{
+       if (dquot_want_fudged_numbers())
+               __dquot_fudge_numbers(d);
+}
+
 /*
  * Various utility routine flags
  */
index 361d2a8ef5c68315633ddaa78b39233afe547307..ab2d33231bf0f0dec31c8e7fc1adcf439be30003 100644 (file)
@@ -427,3 +427,29 @@ fopen_write_secure(
        }
        return fp;
 }
+
+/*
+ * Push the rt block quota numbers into the regular block quota numbers so that
+ * we don't have to rewrite fstests.  The limits have to match, and the regular
+ * block timer cannot be active.  Only call this if you know what you are
+ * doing!
+ */
+void
+__dquot_fudge_numbers(
+       struct fs_disk_quota    *d)
+{
+       if (!d->d_btimer && !d->d_btimer_hi) {
+               d->d_btimer = d->d_rtbtimer;
+               d->d_btimer_hi = d->d_rtbtimer_hi;
+               d->d_rtbtimer = 0;
+               d->d_rtbtimer_hi = 0;
+       }
+
+       if (d->d_blk_hardlimit == d->d_rtb_hardlimit)
+               d->d_rtb_hardlimit = 0;
+       if (d->d_blk_softlimit == d->d_rtb_softlimit)
+               d->d_rtb_softlimit = 0;
+
+       d->d_bcount += d->d_rtbcount;
+       d->d_rtbcount = 0;
+}