[PATCH v1 1/4] Mpersify decoder of struct xfs_dqstats

Zhibin Li 08826794brmt at gmail.com
Sun Jul 8 16:11:29 UTC 2018


* xfs_quota_stat.h: New file.
* fetch_struct_xfs_quotastat.c: Likewise.
* Makefile.am: Add them.
* quota.c: Include xfs_quota_stat.h.
Move struct fs_qfilestat and struct xfs_dqstats to xfs_quota_stat.h
<case Q_XGETQSTAT>: Use fetch_struct_quotastat.
---
 Makefile.am                  |  2 ++
 fetch_struct_xfs_quotastat.c | 35 ++++++++++++++++++++++++
 quota.c                      | 63 ++++++++++++++++----------------------------
 xfs_quota_stat.h             | 22 ++++++++++++++++
 4 files changed, 81 insertions(+), 41 deletions(-)
 create mode 100644 fetch_struct_xfs_quotastat.c
 create mode 100644 xfs_quota_stat.h

diff --git a/Makefile.am b/Makefile.am
index 5f3f50a7..9e5eef27 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -144,6 +144,7 @@ strace_SOURCES =	\
 	fetch_struct_stat.c \
 	fetch_struct_stat64.c \
 	fetch_struct_statfs.c \
+	fetch_struct_xfs_quotastat.c \
 	file_handle.c	\
 	file_ioctl.c	\
 	filter_qualify.c \
@@ -348,6 +349,7 @@ strace_SOURCES =	\
 	v4l2.c		\
 	wait.c		\
 	xattr.c		\
+	xfs_quota_stat.h \
 	xlat.c		\
 	xlat.h		\
 	xmalloc.c	\
diff --git a/fetch_struct_xfs_quotastat.c b/fetch_struct_xfs_quotastat.c
new file mode 100644
index 00000000..b2631fd1
--- /dev/null
+++ b/fetch_struct_xfs_quotastat.c
@@ -0,0 +1,35 @@
+#include "defs.h"
+
+#include DEF_MPERS_TYPE(struct_xfs_dqstats)
+
+#include "xfs_quota_stat.h"
+typedef struct xfs_dqstats struct_xfs_dqstats;
+
+#include MPERS_DEFS
+
+MPERS_PRINTER_DECL(bool, fetch_struct_quotastat, struct tcb *const tcp,
+		   const kernel_ulong_t data, void *p)
+{
+	struct xfs_dqstats *dq = p;
+	struct_xfs_dqstats dqstat;
+
+	if (umove_or_printaddr(tcp, data, &dqstat))
+		return false;
+
+	dq->qs_version = dqstat.qs_version;
+	dq->qs_flags = dqstat.qs_flags;
+	dq->qs_pad = dqstat.qs_pad;
+	dq->qs_incoredqs = dqstat.qs_incoredqs;
+	dq->qs_uquota.qfs_ino = dqstat.qs_uquota.qfs_ino;
+	dq->qs_uquota.qfs_nblks = dqstat.qs_uquota.qfs_nblks;
+	dq->qs_uquota.qfs_nextents = dqstat.qs_uquota.qfs_nextents;
+	dq->qs_gquota.qfs_ino = dqstat.qs_gquota.qfs_ino;
+	dq->qs_gquota.qfs_nblks = dqstat.qs_gquota.qfs_nblks;
+	dq->qs_gquota.qfs_nextents = dqstat.qs_gquota.qfs_nextents;
+	dq->qs_btimelimit = dqstat.qs_btimelimit;
+	dq->qs_itimelimit = dqstat.qs_itimelimit;
+	dq->qs_rtbtimelimit = dqstat.qs_rtbtimelimit;
+	dq->qs_bwarnlimit = dqstat.qs_bwarnlimit;
+	dq->qs_iwarnlimit = dqstat.qs_iwarnlimit;
+	return true;
+}
diff --git a/quota.c b/quota.c
index f1ab9bc5..6ec98774 100644
--- a/quota.c
+++ b/quota.c
@@ -32,6 +32,7 @@
 
 #include "defs.h"
 #include "print_fields.h"
+#include "xfs_quota_stat.h"
 
 #define SUBCMDMASK  0x00ff
 #define SUBCMDSHIFT 8
@@ -114,26 +115,6 @@ struct if_dqinfo {
 	uint32_t dqi_valid;
 };
 
-typedef struct fs_qfilestat {
-	uint64_t qfs_ino;	/* inode number */
-	uint64_t qfs_nblks;	/* number of BBs 512-byte-blks */
-	uint32_t qfs_nextents;	/* number of extents */
-} fs_qfilestat_t;
-
-struct xfs_dqstats {
-	int8_t  qs_version;		/* version number for future changes */
-	uint16_t qs_flags;		/* XFS_QUOTA_{U,P,G}DQ_{ACCT,ENFD} */
-	int8_t  qs_pad;			/* unused */
-	fs_qfilestat_t qs_uquota;	/* user quota storage information */
-	fs_qfilestat_t qs_gquota;	/* group quota storage information */
-	uint32_t qs_incoredqs;		/* number of dquots incore */
-	int32_t qs_btimelimit;		/* limit for blks timer */
-	int32_t qs_itimelimit;		/* limit for inodes timer */
-	int32_t qs_rtbtimelimit;	/* limit for rt blks timer */
-	uint16_t qs_bwarnlimit;		/* limit for num warnings */
-	uint16_t qs_iwarnlimit;		/* limit for num warnings */
-};
-
 struct fs_qfilestatv {
 	uint64_t qfs_ino, qfs_nblks;
 	uint32_t qfs_nextents, qfs_pad;
@@ -337,28 +318,28 @@ decode_cmd_data(struct tcb *tcp, uint32_t id, uint32_t cmd, kernel_ulong_t data)
 			return 0;
 		}
 
-		if (umove_or_printaddr(tcp, data, &dq))
-			break;
-		PRINT_FIELD_D("{", dq, qs_version);
-		if (!abbrev(tcp)) {
-			PRINT_FIELD_FLAGS(", ", dq, qs_flags,
-					  xfs_quota_flags, "XFS_QUOTA_???");
-			PRINT_FIELD_U(", ", dq, qs_incoredqs);
-			PRINT_FIELD_U(", qs_uquota={", dq.qs_uquota, qfs_ino);
-			PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nblks);
-			PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nextents);
-			PRINT_FIELD_U("}, qs_gquota={", dq.qs_gquota, qfs_ino);
-			PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nblks);
-			PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nextents);
-			PRINT_FIELD_D("}, ", dq, qs_btimelimit);
-			PRINT_FIELD_D(", ", dq, qs_itimelimit);
-			PRINT_FIELD_D(", ", dq, qs_rtbtimelimit);
-			PRINT_FIELD_U(", ", dq, qs_bwarnlimit);
-			PRINT_FIELD_U(", ", dq, qs_iwarnlimit);
-		} else {
-			tprints(", ...");
+		if (fetch_struct_quotastat(tcp, data, &dq)) {
+			PRINT_FIELD_D("{", dq, qs_version);
+			if (!abbrev(tcp)) {
+				PRINT_FIELD_FLAGS(", ", dq, qs_flags,
+						  xfs_quota_flags, "XFS_QUOTA_???");
+				PRINT_FIELD_U(", ", dq, qs_incoredqs);
+				PRINT_FIELD_U(", qs_uquota={", dq.qs_uquota, qfs_ino);
+				PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nblks);
+				PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nextents);
+				PRINT_FIELD_U("}, qs_gquota={", dq.qs_gquota, qfs_ino);
+				PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nblks);
+				PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nextents);
+				PRINT_FIELD_D("}, ", dq, qs_btimelimit);
+				PRINT_FIELD_D(", ", dq, qs_itimelimit);
+				PRINT_FIELD_D(", ", dq, qs_rtbtimelimit);
+				PRINT_FIELD_U(", ", dq, qs_bwarnlimit);
+				PRINT_FIELD_U(", ", dq, qs_iwarnlimit);
+			} else {
+				tprints(", ...");
+			}
+			tprints("}");
 		}
-		tprints("}");
 		break;
 	}
 	case Q_XGETQSTATV:
diff --git a/xfs_quota_stat.h b/xfs_quota_stat.h
new file mode 100644
index 00000000..4bb8df67
--- /dev/null
+++ b/xfs_quota_stat.h
@@ -0,0 +1,22 @@
+#include <stdint.h>
+#include "kernel_types.h"
+
+typedef struct fs_qfilestat {
+	uint64_t qfs_ino;	/* inode number */
+	uint64_t qfs_nblks;	/* number of BBs 512-byte-blks */
+	uint32_t qfs_nextents;	/* number of extents */
+} fs_qfilestat_t;
+
+struct xfs_dqstats {
+	int8_t  qs_version;		/* version number for future changes */
+	uint16_t qs_flags;		/* XFS_QUOTA_{U,P,G}DQ_{ACCT,ENFD} */
+	int8_t  qs_pad;			/* unused */
+	fs_qfilestat_t qs_uquota;	/* user quota storage information */
+	fs_qfilestat_t qs_gquota;	/* group quota storage information */
+	uint32_t qs_incoredqs;		/* number of dquots incore */
+	int32_t qs_btimelimit;		/* limit for blks timer */
+	int32_t qs_itimelimit;		/* limit for inodes timer */
+	int32_t qs_rtbtimelimit;	/* limit for rt blks timer */
+	uint16_t qs_bwarnlimit;		/* limit for num warnings */
+	uint16_t qs_iwarnlimit;		/* limit for num warnings */
+};
-- 
2.14.4



More information about the Strace-devel mailing list