xfs
[Top] [All Lists]

[RFC PATCH 2/2] xfs: sysfs attributes for the current log state

To: xfs@xxxxxxxxxxx
Subject: [RFC PATCH 2/2] xfs: sysfs attributes for the current log state
From: Brian Foster <bfoster@xxxxxxxxxx>
Date: Fri, 16 May 2014 14:12:46 -0400
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1400263966-35541-1-git-send-email-bfoster@xxxxxxxxxx>
References: <1400263966-35541-1-git-send-email-bfoster@xxxxxxxxxx>
Create sysfs attributes to export the current runtime state of the log
to userspace. Note that the filesystem should be frozen for best
accuracy/consistency when reading these values, but is not required.
This is for testing and debug purposes only.

Create the following per-mount attributes: log_head_lsn, log_tail_lsn,
reserve_head_lsn and write_head_lsn. These represent the physical log
head, tail and reserve and write grant heads respectively. All values
are exported as raw log sequence numbers (LSN). Note that the grant
heads are in units of bytes while other LSNs are in units of basic
blocks.

Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx>
---
 fs/xfs/xfs_mount.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 9ed9dd0..d0d0617 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -42,6 +42,7 @@
 #include "xfs_trace.h"
 #include "xfs_icache.h"
 #include "xfs_dinode.h"
+#include "xfs_log_priv.h"
 
 
 #ifdef HAVE_PERCPU_SB
@@ -2037,7 +2038,60 @@ struct xfs_sysfs_attr {
 
 #define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
 
+/* sysfs attributes */
+
+STATIC ssize_t
+log_head_lsn_show(
+       struct xfs_mount        *mp,
+       char                    *buf)
+{
+       struct xlog *log = mp->m_log;
+       int ret;
+
+       spin_lock(&log->l_icloglock);
+       ret = snprintf(buf, PAGE_SIZE, "0x%llx\n",
+               xlog_assign_lsn(log->l_curr_cycle, log->l_curr_block));
+       spin_unlock(&log->l_icloglock);
+
+       return ret;
+}
+XFS_SYSFS_ATTR_RO(log_head_lsn);
+
+STATIC ssize_t
+log_tail_lsn_show(
+       struct xfs_mount        *mp,
+       char                    *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "0x%lx\n",
+               atomic64_read(&mp->m_log->l_tail_lsn));
+}
+XFS_SYSFS_ATTR_RO(log_tail_lsn);
+
+STATIC ssize_t
+reserve_head_lsn_show(
+       struct xfs_mount        *mp,
+       char                    *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "0x%lx\n",
+               atomic64_read(&mp->m_log->l_reserve_head.grant));
+}
+XFS_SYSFS_ATTR_RO(reserve_head_lsn);
+
+STATIC ssize_t
+write_head_lsn_show(
+       struct xfs_mount        *mp,
+       char                    *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "0x%lx\n",
+               atomic64_read(&mp->m_log->l_write_head.grant));
+}
+XFS_SYSFS_ATTR_RO(write_head_lsn);
+
 static struct attribute *xfs_sysfs_attrs[] = {
+       ATTR_LIST(log_head_lsn),
+       ATTR_LIST(log_tail_lsn),
+       ATTR_LIST(reserve_head_lsn),
+       ATTR_LIST(write_head_lsn),
        NULL,
 };
 
-- 
1.8.3.1

<Prev in Thread] Current Thread [Next in Thread>