Skip to contentSkip to conversation

src/godown: support f2fs triggering specific ioctl

PATCH In review Jaegeuk Kim 2 participants 4 messages Jan 8, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 src/godown: support f2fs triggering specific ioctl

This patch triggers the F2FS-related ioctl for godown.

---
 src/godown.c | 88 ++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 65 insertions(+), 23 deletions(-)
src/godown.c +65 -23
index b140a41..b44790b 100644
@@ -19,33 +19,82 @@
 #include <syslog.h>
 #include "global.h"
 
+#define F2FS_IOCTL_MAGIC	0xf5
+#define F2FS_IOC_GOINGDOWN	_IO(F2FS_IOCTL_MAGIC, 6)
+
+enum ftypes {
+	XFS_FS,
+	F2FS_FS,
+};
+
 static char *xprogname;
+static char *mnt_dir;
+static int verbose_opt = 0;
+static int flushlog_opt = 0;
 
+static enum ftypes fs = XFS_FS;
 
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: %s [-f] [-v] mnt-dir\n", xprogname);
+	fprintf(stderr, "usage: %s [-f] [-v] [-s 0/1] mnt-dir\n", xprogname);
+}
+
+static int
+xfs_goingdown(int fd)
+{
+	int flag;
+
+	flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH
+			    : XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
+	if (verbose_opt) {
+		printf("Calling XFS_IOC_GOINGDOWN\n");
+	}
+
+	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
+			mnt_dir);
+	if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
+		fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
+				xprogname, mnt_dir, strerror(errno));
+		return 1;
+	}
+	return 0;
+}
+
+static int
+f2fs_goingdown(int fd)
+{
+	if (verbose_opt) {
+		printf("Calling F2FS_IOC_GOINGDOWN\n");
+	}
+	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
+			mnt_dir);
+	if ((ioctl(fd, F2FS_IOC_GOINGDOWN)) == -1) {
+		fprintf(stderr, "%s: error on ioctl(GOINGDOWN) of \"%s\": %s\n",
+				xprogname, mnt_dir, strerror(errno));
+		return 1;
+	}
+	return 0;
+
 }
 
 int
 main(int argc, char *argv[])
 {
-	int c;
-	int flag;
-	int flushlog_opt = 0;
-	int verbose_opt = 0;
+	int c, fd;
 	struct stat st;
-	char *mnt_dir;
-	int fd;
+	int ret = 0;
 
       	xprogname = argv[0];
 
-	while ((c = getopt(argc, argv, "fv")) != -1) {
+	while ((c = getopt(argc, argv, "fs:v")) != -1) {
 		switch (c) {
 		case 'f':
 			flushlog_opt = 1;
 			break;
+		case 's':
+			fs = atoi(optarg);
+			break;
 		case 'v':
 			verbose_opt = 1;
 			break;
@@ -94,10 +143,6 @@ main(int argc, char *argv[])
 	}
 #endif
 
-
-	flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH 
-			    : XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
-
 	if (verbose_opt) {
 		printf("Opening \"%s\"\n", mnt_dir);
 	}
@@ -107,18 +152,15 @@ main(int argc, char *argv[])
 		return 1;
 	}
 
-	if (verbose_opt) {
-		printf("Calling XFS_IOC_GOINGDOWN\n");
+	switch (fs) {
+	case XFS_FS:
+		ret = xfs_goingdown(fd);
+		break;
+	case F2FS_FS:
+		ret = f2fs_goingdown(fd);
+		break;
 	}
-	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
-		mnt_dir);
-	if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
-		fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
-			xprogname, mnt_dir, strerror(errno));
-		return 1;
-	}
-
 	close(fd);
 
-	return 0;
+	return ret;
 }
Signature · 1 line
2.1.1
#1 lore raw

PATCH 2/2 f2fs/087: test power failure test using godown

This patch adds f2fs/087 to test power failure by using godown.

---
 tests/f2fs/087     | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/f2fs/087.out | 21 +++++++++++++
 tests/f2fs/group   |  1 +
 3 files changed, 110 insertions(+)
 create mode 100644 tests/f2fs/087
 create mode 100644 tests/f2fs/087.out
 create mode 100644 tests/f2fs/group
tests/f2fs/087 new file +88 -0
new file mode 100644
index 0000000..9410b9f
@@ -0,0 +1,88 @@
+#! /bin/bash
+# FS QA Test No. 087
+#
+# * use godown likewise xfs/087
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2015 Jaegeuk Kim
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs f2fs
+_supported_os Linux
+
+rm -f $seqres.full $tmp.*
+_require_scratch
+
+_run_fsstress()
+{
+	out=$SCRATCH_MNT/fsstress
+	count=$((5000*$i))
+	echo $count
+	param="-p 4 -z -f sync=1 -f write=30 -f rmdir=10 -f link=10 -f creat=10 -f mkdir=10 -f rename=30 -f stat=30 -f unlink=30 -f truncate=20"
+	echo "calling fsstress $param -m8 -n $count" >>$seqres.full
+	FSSTRESS_ARGS=`_scale_fsstress_args $param $FSSTRESS_AVOID -m 8 -n $count -d $out`
+	if ! $FSSTRESS_PROG $FSSTRESS_ARGS >>$seqres.full 2>&1
+	then
+		echo "fsstress failed"
+	fi
+}
+
+# mkfs the FS
+_scratch_mkfs >>$seqres.full 2>&1
+if [ $? -ne 0 ] ; then
+	echo "mkfs failed: $MKFS_OPTIONS"
+fi
+
+i=1
+LOOP=10
+for i in $(seq 1 ${LOOP}); do
+	echo "** mount" >>$seqres.full
+	if ! _scratch_mount >>$seqres.full 2>&1; then
+		echo "mount failed: $MOUNT_OPTIONS"
+	fi
+
+	_run_fsstress
+
+	echo "** godown" >>$seqres.full
+	src/godown -v -f $SCRATCH_MNT -s 1 >>$seqres.full
+
+	umount $SCRATCH_DEV >/dev/null 2>&1
+
+	if _check_scratch_fs; then
+		echo "filesystem is checked ok"
+	else
+		echo "filesystem is NOT ok"
+	fi
+done
+
+status=0
+exit
tests/f2fs/087.out new file +21 -0
new file mode 100644
index 0000000..14bb897
@@ -0,0 +1,21 @@
+QA output created by 087
+5000
+filesystem is checked ok
+10000
+filesystem is checked ok
+15000
+filesystem is checked ok
+20000
+filesystem is checked ok
+25000
+filesystem is checked ok
+30000
+filesystem is checked ok
+35000
+filesystem is checked ok
+40000
+filesystem is checked ok
+45000
+filesystem is checked ok
+50000
+filesystem is checked ok
tests/f2fs/group new file +1 -0
new file mode 100644
index 0000000..dd069d3
@@ -0,0 +1 @@
+087 auto stress
Signature · 1 line
2.1.1
#2 lore raw
In reply to Jaegeuk Kim
Quoted 1 line · Jaegeuk Kim

This patch triggers the F2FS-related ioctl for godown.

hohum, wouldn't it be a whole lot easier to just re-use the XFS ioctl number in f2fs? Then you wouldn't have to duplicate all this code.

If you really want your own unique ioctl number, what about just doing statfs on the target, and if f_type returns F2FS_SUPER_MAGIC, swictch the ioctl nr to F2FS_IOC_GOINGDOWN.

Then if not F2FS_SUPER_MAGIC, leave the ioctl nr at XFS_IOC_GOINGDOWN, and if it fails, it fails (other filesystems might support the original nr.)

And then you can probably just add "f2fs" to the existing testcase, and move it to tests/shared?

-Eric

Quoted 139 lines
---
 src/godown.c | 88 ++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 65 insertions(+), 23 deletions(-)
src/godown.c +65 -23
index b140a41..b44790b 100644
@@ -19,33 +19,82 @@
 #include <syslog.h>
 #include "global.h"
 
+#define F2FS_IOCTL_MAGIC	0xf5
+#define F2FS_IOC_GOINGDOWN	_IO(F2FS_IOCTL_MAGIC, 6)
+
+enum ftypes {
+	XFS_FS,
+	F2FS_FS,
+};
+
 static char *xprogname;
+static char *mnt_dir;
+static int verbose_opt = 0;
+static int flushlog_opt = 0;
 
+static enum ftypes fs = XFS_FS;
 
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: %s [-f] [-v] mnt-dir\n", xprogname);
+	fprintf(stderr, "usage: %s [-f] [-v] [-s 0/1] mnt-dir\n", xprogname);
+}
+
+static int
+xfs_goingdown(int fd)
+{
+	int flag;
+
+	flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH
+			    : XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
+	if (verbose_opt) {
+		printf("Calling XFS_IOC_GOINGDOWN\n");
+	}
+
+	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
+			mnt_dir);
+	if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
+		fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
+				xprogname, mnt_dir, strerror(errno));
+		return 1;
+	}
+	return 0;
+}
+
+static int
+f2fs_goingdown(int fd)
+{
+	if (verbose_opt) {
+		printf("Calling F2FS_IOC_GOINGDOWN\n");
+	}
+	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
+			mnt_dir);
+	if ((ioctl(fd, F2FS_IOC_GOINGDOWN)) == -1) {
+		fprintf(stderr, "%s: error on ioctl(GOINGDOWN) of \"%s\": %s\n",
+				xprogname, mnt_dir, strerror(errno));
+		return 1;
+	}
+	return 0;
+
 }
 
 int
 main(int argc, char *argv[])
 {
-	int c;
-	int flag;
-	int flushlog_opt = 0;
-	int verbose_opt = 0;
+	int c, fd;
 	struct stat st;
-	char *mnt_dir;
-	int fd;
+	int ret = 0;
 
       	xprogname = argv[0];
 
-	while ((c = getopt(argc, argv, "fv")) != -1) {
+	while ((c = getopt(argc, argv, "fs:v")) != -1) {
 		switch (c) {
 		case 'f':
 			flushlog_opt = 1;
 			break;
+		case 's':
+			fs = atoi(optarg);
+			break;
 		case 'v':
 			verbose_opt = 1;
 			break;
@@ -94,10 +143,6 @@ main(int argc, char *argv[])
 	}
 #endif
 
-
-	flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH 
-			    : XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
-
 	if (verbose_opt) {
 		printf("Opening \"%s\"\n", mnt_dir);
 	}
@@ -107,18 +152,15 @@ main(int argc, char *argv[])
 		return 1;
 	}
 
-	if (verbose_opt) {
-		printf("Calling XFS_IOC_GOINGDOWN\n");
+	switch (fs) {
+	case XFS_FS:
+		ret = xfs_goingdown(fd);
+		break;
+	case F2FS_FS:
+		ret = f2fs_goingdown(fd);
+		break;
 	}
-	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
-		mnt_dir);
-	if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
-		fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
-			xprogname, mnt_dir, strerror(errno));
-		return 1;
-	}
-
 	close(fd);
 
-	return 0;
+	return ret;
 }
#3 lore raw
Quoted 5 lines · Eric Sandeen
Quoted 1 line · Jaegeuk Kim

This patch triggers the F2FS-related ioctl for godown.

hohum, wouldn't it be a whole lot easier to just re-use the XFS ioctl number in f2fs? Then you wouldn't have to duplicate all this code.

Actually I tried to do like that. But, xfs's goingdown has some specific options wrt flushing logs which provide some rules on data recovery.

So, I decided to add a new ioctl and a test script, (i.e., f2fs/087) which is different from xfs/087.

Quoted 4 lines

If you really want your own unique ioctl number, what about just doing statfs on the target, and if f_type returns F2FS_SUPER_MAGIC, swictch the ioctl nr to F2FS_IOC_GOINGDOWN.

Oh, I'll change detecting the file system type.
For the common ioctl, it needs to consider ioctl's format where xfs calls xfsctl with flushing options while f2fs triggers ioctl without paramter.

Quoted 6 lines

Then if not F2FS_SUPER_MAGIC, leave the ioctl nr at XFS_IOC_GOINGDOWN, and if it fails, it fails (other filesystems might support the original nr.)

And then you can probably just add "f2fs" to the existing testcase, and move it to tests/shared?

I can't use the same scripts due to the different options used by xfs's goingdown.

Thank you for the comments. :)

Thanks,

Quoted 142 lines

-Eric

Quoted 139 lines
---
 src/godown.c | 88 ++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 65 insertions(+), 23 deletions(-)
src/godown.c +65 -23
index b140a41..b44790b 100644
@@ -19,33 +19,82 @@
 #include <syslog.h>
 #include "global.h"
 
+#define F2FS_IOCTL_MAGIC	0xf5
+#define F2FS_IOC_GOINGDOWN	_IO(F2FS_IOCTL_MAGIC, 6)
+
+enum ftypes {
+	XFS_FS,
+	F2FS_FS,
+};
+
 static char *xprogname;
+static char *mnt_dir;
+static int verbose_opt = 0;
+static int flushlog_opt = 0;
 
+static enum ftypes fs = XFS_FS;
 
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: %s [-f] [-v] mnt-dir\n", xprogname);
+	fprintf(stderr, "usage: %s [-f] [-v] [-s 0/1] mnt-dir\n", xprogname);
+}
+
+static int
+xfs_goingdown(int fd)
+{
+	int flag;
+
+	flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH
+			    : XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
+	if (verbose_opt) {
+		printf("Calling XFS_IOC_GOINGDOWN\n");
+	}
+
+	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
+			mnt_dir);
+	if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
+		fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
+				xprogname, mnt_dir, strerror(errno));
+		return 1;
+	}
+	return 0;
+}
+
+static int
+f2fs_goingdown(int fd)
+{
+	if (verbose_opt) {
+		printf("Calling F2FS_IOC_GOINGDOWN\n");
+	}
+	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
+			mnt_dir);
+	if ((ioctl(fd, F2FS_IOC_GOINGDOWN)) == -1) {
+		fprintf(stderr, "%s: error on ioctl(GOINGDOWN) of \"%s\": %s\n",
+				xprogname, mnt_dir, strerror(errno));
+		return 1;
+	}
+	return 0;
+
 }
 
 int
 main(int argc, char *argv[])
 {
-	int c;
-	int flag;
-	int flushlog_opt = 0;
-	int verbose_opt = 0;
+	int c, fd;
 	struct stat st;
-	char *mnt_dir;
-	int fd;
+	int ret = 0;
 
       	xprogname = argv[0];
 
-	while ((c = getopt(argc, argv, "fv")) != -1) {
+	while ((c = getopt(argc, argv, "fs:v")) != -1) {
 		switch (c) {
 		case 'f':
 			flushlog_opt = 1;
 			break;
+		case 's':
+			fs = atoi(optarg);
+			break;
 		case 'v':
 			verbose_opt = 1;
 			break;
@@ -94,10 +143,6 @@ main(int argc, char *argv[])
 	}
 #endif
 
-
-	flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH 
-			    : XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
-
 	if (verbose_opt) {
 		printf("Opening \"%s\"\n", mnt_dir);
 	}
@@ -107,18 +152,15 @@ main(int argc, char *argv[])
 		return 1;
 	}
 
-	if (verbose_opt) {
-		printf("Calling XFS_IOC_GOINGDOWN\n");
+	switch (fs) {
+	case XFS_FS:
+		ret = xfs_goingdown(fd);
+		break;
+	case F2FS_FS:
+		ret = f2fs_goingdown(fd);
+		break;
 	}
-	syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
-		mnt_dir);
-	if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
-		fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
-			xprogname, mnt_dir, strerror(errno));
-		return 1;
-	}
-
 	close(fd);
 
-	return 0;
+	return ret;
 }