03fc3c
From a92dcf5a6cc49660d75a67966b0eb093b88e3b4c Mon Sep 17 00:00:00 2001
03fc3c
From: "Tinguely, Mark" <mark.tinguely@hpe.com>
03fc3c
Date: Wed, 9 May 2018 16:50:25 +0200
03fc3c
Subject: [PATCH] Aadd HPE XFS support
03fc3c
MIME-Version: 1.0
03fc3c
Content-Type: text/plain; charset=UTF-8
03fc3c
Content-Transfer-Encoding: 8bit
03fc3c
03fc3c
HPE XFS has a different superblock magic and type name
03fc3c
to allow the community XFS and HPE XFS to coexist in
03fc3c
the same linux kernel.
03fc3c
03fc3c
This patch add HPE XFS support to the quota-tools so
03fc3c
our customers can use it.
03fc3c
03fc3c
Signed-off-by: Mark Tinguely <mark.tinguely@hpe.com>
03fc3c
Signed-off-by: Jan Kara <jack@suse.cz>
03fc3c
Signed-off-by: Petr Písař <ppisar@redhat.com>
03fc3c
---
03fc3c
 bylabel.c    |  4 +++-
03fc3c
 mntopt.h     |  1 +
03fc3c
 quot.c       |  3 ++-
03fc3c
 quotacheck.c |  5 +++--
03fc3c
 quotaio.c    |  3 ++-
03fc3c
 quotaon.c    |  6 ++++--
03fc3c
 quotasys.c   | 10 +++++++---
03fc3c
 7 files changed, 22 insertions(+), 10 deletions(-)
03fc3c
03fc3c
diff --git a/bylabel.c b/bylabel.c
03fc3c
index ff10422..5313461 100644
03fc3c
--- a/bylabel.c
03fc3c
+++ b/bylabel.c
03fc3c
@@ -48,6 +48,7 @@ struct ext2_super_block {
03fc3c
 
03fc3c
 #define XFS_SUPER_MAGIC "XFSB"
03fc3c
 #define XFS_SUPER_MAGIC2 "BSFX"
03fc3c
+#define EXFS_SUPER_MAGIC "EXFS"
03fc3c
 struct xfs_super_block {
03fc3c
 	u_char s_magic[4];
03fc3c
 	u_char s_dummy[28];
03fc3c
@@ -107,7 +108,8 @@ static int get_label_uuid(const char *device, char **label, char *uuid)
03fc3c
 	else if (lseek(fd, 0, SEEK_SET) == 0
03fc3c
 		 && read(fd, (char *)&xfsb, sizeof(xfsb)) == sizeof(xfsb)
03fc3c
 		 && (strncmp((char *)&xfsb.s_magic, XFS_SUPER_MAGIC, 4) == 0 ||
03fc3c
-		     strncmp((char *)&xfsb.s_magic, XFS_SUPER_MAGIC2, 4) == 0)) {
03fc3c
+		     strncmp((char *)&xfsb.s_magic, XFS_SUPER_MAGIC2, 4) == 0 ||
03fc3c
+		     strncmp((char *)&xfsb.s_magic, EXFS_SUPER_MAGIC, 4) == 0)) {
03fc3c
 		memcpy(uuid, xfsb.s_uuid, sizeof(xfsb.s_uuid));
03fc3c
 		namesize = sizeof(xfsb.s_fsname);
03fc3c
 		*label = smalloc(namesize + 1);
03fc3c
diff --git a/mntopt.h b/mntopt.h
03fc3c
index 7913048..0f3b0c5 100644
03fc3c
--- a/mntopt.h
03fc3c
+++ b/mntopt.h
03fc3c
@@ -15,6 +15,7 @@
03fc3c
 #define MNTTYPE_UDF		"udf"	/* OSTA UDF file system */
03fc3c
 #define MNTTYPE_REISER		"reiserfs"	/* Reiser file system */
03fc3c
 #define MNTTYPE_XFS		"xfs"	/* SGI XFS file system */
03fc3c
+#define MNTTYPE_EXFS		"exfs"	/* HPE EXFS file system */
03fc3c
 #define MNTTYPE_AUTOFS		"autofs"	/* Automount mountpoint */
03fc3c
 #define MNTTYPE_JFS		"jfs"	/* JFS file system */
03fc3c
 #define MNTTYPE_NFS4		"nfs4"	/* NFSv4 filesystem */
03fc3c
diff --git a/quot.c b/quot.c
03fc3c
index 6311f77..c3a31a4 100644
03fc3c
--- a/quot.c
03fc3c
+++ b/quot.c
03fc3c
@@ -143,7 +143,8 @@ static void mounttable(void)
03fc3c
 
03fc3c
 	while ((mntp = get_next_mount())) {
03fc3c
 		/* Currently, only XFS is implemented... */
03fc3c
-		if (strcmp(mntp->me_type, MNTTYPE_XFS) == 0) {
03fc3c
+		if (strcmp(mntp->me_type, MNTTYPE_XFS) == 0 ||
03fc3c
+		    strcmp(mntp->me_type, MNTTYPE_EXFS) == 0) {
03fc3c
 			checkXFS(mntp->me_devname, mntp->me_dir);
03fc3c
 			doit = 1;
03fc3c
 		}
03fc3c
diff --git a/quotacheck.c b/quotacheck.c
03fc3c
index b1302b6..fd01dfc 100644
03fc3c
--- a/quotacheck.c
03fc3c
+++ b/quotacheck.c
03fc3c
@@ -1042,7 +1042,8 @@ static int detect_filename_format(struct mount_entry *mnt, int type)
03fc3c
 	int fmt;
03fc3c
 
03fc3c
 	if (strcmp(mnt->me_type, MNTTYPE_XFS) == 0 ||
03fc3c
-	    strcmp(mnt->me_type, MNTTYPE_GFS2) == 0)
03fc3c
+	    strcmp(mnt->me_type, MNTTYPE_GFS2) == 0 ||
03fc3c
+	    strcmp(mnt->me_type, MNTTYPE_EXFS) == 0)
03fc3c
 		return QF_XFS;
03fc3c
 
03fc3c
 	if (type == USRQUOTA) {
03fc3c
@@ -1116,7 +1117,7 @@ static int compatible_fs_qfmt(char *fstype, int fmt)
03fc3c
 {
03fc3c
 	/* We never check XFS, NFS, and filesystems supporting VFS metaformat */
03fc3c
 	if (!strcmp(fstype, MNTTYPE_XFS) || nfs_fstype(fstype) ||
03fc3c
-	    meta_qf_fstype(fstype))
03fc3c
+	    meta_qf_fstype(fstype) || !strcmp(fstype, MNTTYPE_EXFS))
03fc3c
 		return 0;
03fc3c
 	/* In all other cases we can pick a format... */
03fc3c
 	if (fmt == -1)
03fc3c
diff --git a/quotaio.c b/quotaio.c
03fc3c
index df893c6..94ae458 100644
03fc3c
--- a/quotaio.c
03fc3c
+++ b/quotaio.c
03fc3c
@@ -79,7 +79,8 @@ struct quota_handle *init_io(struct mount_entry *mnt, int type, int fmt, int fla
03fc3c
 	}
03fc3c
 
03fc3c
 	if (!strcmp(mnt->me_type, MNTTYPE_XFS) ||	/* XFS filesystem? */
03fc3c
-	    !strcmp(mnt->me_type, MNTTYPE_GFS2)) {	/* XFS filesystem? */
03fc3c
+	    !strcmp(mnt->me_type, MNTTYPE_GFS2) ||	/* XFS filesystem? */
03fc3c
+	    !strcmp(mnt->me_type, MNTTYPE_EXFS)) {	/* EXFS filesystem? */
03fc3c
 		if (fmt != -1 && fmt != QF_XFS) {	/* User wanted some other format? */
03fc3c
 			errstr(_("Only XFS quota format is allowed on XFS filesystem.\n"));
03fc3c
 			goto out_handle;
03fc3c
diff --git a/quotaon.c b/quotaon.c
03fc3c
index fe19224..cee2e25 100644
03fc3c
--- a/quotaon.c
03fc3c
+++ b/quotaon.c
03fc3c
@@ -282,7 +282,8 @@ static int newstate(struct mount_entry *mnt, int type, char *extra)
03fc3c
 	if (!strcmp(mnt->me_type, MNTTYPE_GFS2)) {
03fc3c
 		errstr(_("Cannot change state of GFS2 quota.\n"));
03fc3c
 		return 1;
03fc3c
-	} else if (!strcmp(mnt->me_type, MNTTYPE_XFS)) {	/* XFS filesystem has special handling... */
03fc3c
+	} else if (!strcmp(mnt->me_type, MNTTYPE_XFS) ||
03fc3c
+		   !strcmp(mnt->me_type, MNTTYPE_EXFS)) {	/* XFS filesystem has special handling... */
03fc3c
 		if (!kern_qfmt_supp(QF_XFS)) {
03fc3c
 			errstr(_("Cannot change state of XFS quota. It's not compiled in kernel.\n"));
03fc3c
 			return 1;
03fc3c
@@ -337,7 +338,8 @@ static int print_state(struct mount_entry *mnt, int type)
03fc3c
 	if (kern_qfmt_supp(QF_XFS)) {
03fc3c
 		on = kern_quota_state_xfs(mnt->me_devname, type);
03fc3c
 		if (!strcmp(mnt->me_type, MNTTYPE_XFS) ||
03fc3c
-		    !strcmp(mnt->me_type, MNTTYPE_GFS2) || on >= 0) {
03fc3c
+		    !strcmp(mnt->me_type, MNTTYPE_GFS2) || on >= 0 ||
03fc3c
+		    !strcmp(mnt->me_type, MNTTYPE_EXFS)) {
03fc3c
 			if (on < 0)
03fc3c
 				on = 0;
03fc3c
 			if (!(flags & FL_VERBOSE))
03fc3c
diff --git a/quotasys.c b/quotasys.c
03fc3c
index 9336411..d8c0e48 100644
03fc3c
--- a/quotasys.c
03fc3c
+++ b/quotasys.c
03fc3c
@@ -781,7 +781,8 @@ static void copy_mntoptarg(char *buf, const char *optarg, int buflen)
03fc3c
 static int hasquota(const char *dev, struct mntent *mnt, int type, int flags)
03fc3c
 {
03fc3c
 	if (!strcmp(mnt->mnt_type, MNTTYPE_GFS2) ||
03fc3c
-	    !strcmp(mnt->mnt_type, MNTTYPE_XFS))
03fc3c
+	    !strcmp(mnt->mnt_type, MNTTYPE_XFS) ||
03fc3c
+	    !strcmp(mnt->mnt_type, MNTTYPE_EXFS))
03fc3c
 		return hasxfsquota(dev, mnt, type, flags);
03fc3c
 	if (!strcmp(mnt->mnt_type, MNTTYPE_OCFS2))
03fc3c
 		return hasvfsmetaquota(dev, mnt, type, flags);
03fc3c
@@ -953,12 +954,14 @@ add_entry:
03fc3c
 				break;
03fc3c
 			case QF_XFS:
03fc3c
 				if (!strcmp(mnt->me_type, MNTTYPE_XFS) ||
03fc3c
-				    !strcmp(mnt->me_type, MNTTYPE_GFS2))
03fc3c
+				    !strcmp(mnt->me_type, MNTTYPE_GFS2) ||
03fc3c
+				    !strcmp(mnt->me_type, MNTTYPE_EXFS))
03fc3c
 					goto add_entry;
03fc3c
 				break;
03fc3c
 			default:
03fc3c
 				if (strcmp(mnt->me_type, MNTTYPE_XFS) &&
03fc3c
 				    strcmp(mnt->me_type, MNTTYPE_GFS2) &&
03fc3c
+				    strcmp(mnt->me_type, MNTTYPE_EXFS) &&
03fc3c
 				    !nfs_fstype(mnt->me_type))
03fc3c
 					goto add_entry;
03fc3c
 				break;
03fc3c
@@ -1059,7 +1062,8 @@ void init_kernel_interface(void)
03fc3c
 	else {
03fc3c
 		struct v2_dqstats v2_stats;
03fc3c
 
03fc3c
-		if (!stat("/proc/fs/xfs/stat", &st))
03fc3c
+		if (!stat("/proc/fs/xfs/stat", &st) ||
03fc3c
+		    !stat("/proc/fs/exfs/stat", &st))
03fc3c
 			kernel_qfmt[kernel_qfmt_num++] = QF_XFS;
03fc3c
 		else {
03fc3c
 			fs_quota_stat_t dummy;
03fc3c
-- 
03fc3c
2.26.3
03fc3c