All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: xfs@oss.sgi.com
Cc: jbacik@fusionio.com, linux-btrfs@vger.kernel.org
Subject: [patch 1/3] xfstests: btrfs/021: test global metadata reservation reporting
Date: Mon, 28 Oct 2013 16:47:16 -0400	[thread overview]
Message-ID: <20131028204902.815790553@sled1.home.jeffreymahoney.com> (raw)
In-Reply-To: 20131028204715.921910478@sled1.home.jeffreymahoney.com

Btrfs can now report the size of the global metadata reservation
via icotl and sysfs.

This test confirms that we get sane results on an empty file system.

ENOTTY and missing /sys/fs/btrfs/<fsid>/allocation are not considered
failures.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 common/rc                |    6 +++
 src/Makefile             |    3 +-
 src/btrfs_ioctl_helper.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/021          |   88 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/021.out      |    2 +
 5 files changed, 188 insertions(+), 1 deletions(-)
 create mode 100644 src/btrfs_ioctl_helper.c
 create mode 100755 tests/btrfs/021
 create mode 100644 tests/btrfs/021.out

Index: xfstests/common/rc
===================================================================
--- xfstests.orig/common/rc
+++ xfstests/common/rc
@@ -65,6 +65,12 @@ _btrfs_get_subvolid()
 	$BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
 }
 
+_btrfs_get_fsid()
+{
+	local dev=$1
+	$BTRFS_UTIL_PROG filesystem show $dev|awk '/uuid:/ {print $NF}'
+}
+
 # Prints the md5 checksum of a given file
 _md5_checksum()
 {
Index: xfstests/src/Makefile
===================================================================
--- xfstests.orig/src/Makefile
+++ xfstests/src/Makefile
@@ -18,7 +18,8 @@ LINUX_TARGETS = xfsctl bstat t_mtab getd
 	locktest unwritten_mmap bulkstat_unlink_test t_stripealign \
 	bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \
 	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
-	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec
+	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec \
+	btrfs_ioctl_helper
 
 SUBDIRS =
 
Index: xfstests/src/btrfs_ioctl_helper.c
===================================================================
--- /dev/null
+++ xfstests/src/btrfs_ioctl_helper.c
@@ -0,0 +1,90 @@
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <sys/fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#ifndef BTRFS_IOCTL_MAGIC
+#define BTRFS_IOCTL_MAGIC 0x94
+#endif
+
+#ifndef BTRFS_IOC_GLOBAL_RSV
+#define BTRFS_IOC_GLOBAL_RSV _IOR(BTRFS_IOCTL_MAGIC, 20, uint64_t)
+#endif
+
+static int global_rsv_ioctl(int fd, int argc, char *argv[])
+{
+	uint64_t reserved;
+	int ret = ioctl(fd, BTRFS_IOC_GLOBAL_RSV, &reserved);
+	if (ret)
+		return -errno;
+
+	printf("%llu\n", (unsigned long long)reserved);
+	return 0;
+}
+
+#define IOCTL_TABLE_ENTRY(_ioctl_name, _handler) \
+	{ .name = #_ioctl_name, .ioctl_cmd = BTRFS_IOC_##_ioctl_name, \
+	  .handler = _handler, }
+
+struct ioctl_table_entry {
+	const char *name;
+	unsigned ioctl_cmd;
+	int (*handler)(int fd, int argc, char *argv[]);
+};
+
+static struct ioctl_table_entry ioctls[] = {
+	IOCTL_TABLE_ENTRY(GLOBAL_RSV, global_rsv_ioctl),
+};
+
+int
+main(int argc, char *argv[])
+{
+	int fd;
+	int ret;
+	struct ioctl_table_entry *entry = NULL;
+	int i;
+
+	if (argc < 3) {
+		fprintf(stderr,
+			"usage: %s <fs mount point> <ioctl name> [args..]\n",
+			argv[0]);
+		return 1;
+	}
+
+	fd = open(argv[1], O_RDONLY|O_DIRECTORY);
+	if (fd < 0) {
+		perror(argv[1]);
+		return 1;
+	}
+
+	for (i = 0; i < (sizeof(ioctls)/sizeof(ioctls[0])); i++) {
+		if (strcmp(argv[2], ioctls[i].name) == 0) {
+			entry = &ioctls[i];
+			break;
+		}
+	}
+
+	if (!entry) {
+		fprintf(stderr, "ERROR: unknown ioctl %s\n", argv[2]);
+		close(fd);
+		return 1;
+	}
+
+	ret = entry->handler(fd, argc - 3, argv + 3);
+	if (ret == -ENOTTY) {
+		printf("Not implemented.\n");
+		close(fd);
+		return 0;
+	} else if (ret) {
+		fprintf(stderr, "ERROR: %s failed: %s\n",
+			entry->name, strerror(-ret));
+		close(fd);
+		return 1;
+	}
+
+	close(fd);
+	return 0;
+}
Index: xfstests/tests/btrfs/021
===================================================================
--- /dev/null
+++ xfstests/tests/btrfs/021
@@ -0,0 +1,88 @@
+#!/bin/bash
+# FA QA Test No. 021
+#
+# Test global metadata reservation reporting
+#
+# 1) Create empty file system
+# 2) Call the BTRFS_IOC_GLOBAL_RSV ioctl and confirm it is 0 < x < 10MB
+# 3) Read the /sys/fs/btrfs/<fsid>/allocation/global_rsv_reserved file
+#    and confirm the value is 0 < x < 10 MB
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2013 SUSE, All Rights Reserved.
+#
+# 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
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter.btrfs
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+
+# Check to see if the reservation is 0 < x <= 10MB
+# At the time of this writing, it should always be exactly 4 MB
+# but that is an implementation detail subject to change.
+check_reserved() {
+	reserved="$2"
+	method="$3"
+	if [ "$1" != 0 ]; then
+		echo "$method: failed: $reserved"
+		exit 1
+	fi
+	if [ "$reserved" = "Not implemented." ]; then
+		echo "Skipping ioctl test. Not implemented." >> $seqres.full
+		return
+	fi
+	if [ -n "$(echo $reserved | tr -d 0-9)" ]; then
+		echo "ERROR: numerical value expected (got $reserved)"
+		exit 1
+	fi
+	if [ "$reserved" -le 0 -o \
+	       "$reserved" -gt "$(( 10 * 1024 * 1024 ))" ]; then
+		echo "$method: out of range: $reserved."
+		exit
+	fi
+}
+
+# ioctl
+reserved="$(src/btrfs_ioctl_helper $SCRATCH_MNT GLOBAL_RSV 2>&1)"
+check_reserved $? "$reserved" "ioctl"
+
+# sysfs
+# If this directory is here, the files must be here as well
+SYSFS_PREFIX="/sys/fs/btrfs/$(_btrfs_get_fsid $SCRATCH_DEV)/allocation"
+if [ -d "$SYSFS_PREFIX" ]; then
+	reserved="$(cat $SYSFS_PREFIX/global_rsv_reserved 2>&1)"
+	check_reserved $? "$reserved" "sysfs:reserved"
+	size="$(cat $SYSFS_PREFIX/global_rsv_size 2>&1)"
+	check_reserved $? "$size" "sysfs:size"
+fi
+
+echo "Silence is golden"
+status=0
+exit
Index: xfstests/tests/btrfs/021.out
===================================================================
--- /dev/null
+++ xfstests/tests/btrfs/021.out
@@ -0,0 +1,2 @@
+QA output created by 021
+Silence is golden



WARNING: multiple messages have this Message-ID (diff)
From: Jeff Mahoney <jeffm@suse.com>
To: xfs@oss.sgi.com
Cc: linux-btrfs@vger.kernel.org, jbacik@fusionio.com
Subject: [patch 1/3] xfstests: btrfs/021: test global metadata reservation reporting
Date: Mon, 28 Oct 2013 16:47:16 -0400	[thread overview]
Message-ID: <20131028204902.815790553@sled1.home.jeffreymahoney.com> (raw)
In-Reply-To: 20131028204715.921910478@sled1.home.jeffreymahoney.com

[-- Attachment #1: 0001-xfstests-btrfs-021-test-global-metadata-reservatio.patch --]
[-- Type: text/plain, Size: 6960 bytes --]

Btrfs can now report the size of the global metadata reservation
via icotl and sysfs.

This test confirms that we get sane results on an empty file system.

ENOTTY and missing /sys/fs/btrfs/<fsid>/allocation are not considered
failures.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 common/rc                |    6 +++
 src/Makefile             |    3 +-
 src/btrfs_ioctl_helper.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/021          |   88 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/021.out      |    2 +
 5 files changed, 188 insertions(+), 1 deletions(-)
 create mode 100644 src/btrfs_ioctl_helper.c
 create mode 100755 tests/btrfs/021
 create mode 100644 tests/btrfs/021.out

Index: xfstests/common/rc
===================================================================
--- xfstests.orig/common/rc
+++ xfstests/common/rc
@@ -65,6 +65,12 @@ _btrfs_get_subvolid()
 	$BTRFS_UTIL_PROG sub list $mnt | grep $name | awk '{ print $2 }'
 }
 
+_btrfs_get_fsid()
+{
+	local dev=$1
+	$BTRFS_UTIL_PROG filesystem show $dev|awk '/uuid:/ {print $NF}'
+}
+
 # Prints the md5 checksum of a given file
 _md5_checksum()
 {
Index: xfstests/src/Makefile
===================================================================
--- xfstests.orig/src/Makefile
+++ xfstests/src/Makefile
@@ -18,7 +18,8 @@ LINUX_TARGETS = xfsctl bstat t_mtab getd
 	locktest unwritten_mmap bulkstat_unlink_test t_stripealign \
 	bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \
 	stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
-	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec
+	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec \
+	btrfs_ioctl_helper
 
 SUBDIRS =
 
Index: xfstests/src/btrfs_ioctl_helper.c
===================================================================
--- /dev/null
+++ xfstests/src/btrfs_ioctl_helper.c
@@ -0,0 +1,90 @@
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <sys/fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#ifndef BTRFS_IOCTL_MAGIC
+#define BTRFS_IOCTL_MAGIC 0x94
+#endif
+
+#ifndef BTRFS_IOC_GLOBAL_RSV
+#define BTRFS_IOC_GLOBAL_RSV _IOR(BTRFS_IOCTL_MAGIC, 20, uint64_t)
+#endif
+
+static int global_rsv_ioctl(int fd, int argc, char *argv[])
+{
+	uint64_t reserved;
+	int ret = ioctl(fd, BTRFS_IOC_GLOBAL_RSV, &reserved);
+	if (ret)
+		return -errno;
+
+	printf("%llu\n", (unsigned long long)reserved);
+	return 0;
+}
+
+#define IOCTL_TABLE_ENTRY(_ioctl_name, _handler) \
+	{ .name = #_ioctl_name, .ioctl_cmd = BTRFS_IOC_##_ioctl_name, \
+	  .handler = _handler, }
+
+struct ioctl_table_entry {
+	const char *name;
+	unsigned ioctl_cmd;
+	int (*handler)(int fd, int argc, char *argv[]);
+};
+
+static struct ioctl_table_entry ioctls[] = {
+	IOCTL_TABLE_ENTRY(GLOBAL_RSV, global_rsv_ioctl),
+};
+
+int
+main(int argc, char *argv[])
+{
+	int fd;
+	int ret;
+	struct ioctl_table_entry *entry = NULL;
+	int i;
+
+	if (argc < 3) {
+		fprintf(stderr,
+			"usage: %s <fs mount point> <ioctl name> [args..]\n",
+			argv[0]);
+		return 1;
+	}
+
+	fd = open(argv[1], O_RDONLY|O_DIRECTORY);
+	if (fd < 0) {
+		perror(argv[1]);
+		return 1;
+	}
+
+	for (i = 0; i < (sizeof(ioctls)/sizeof(ioctls[0])); i++) {
+		if (strcmp(argv[2], ioctls[i].name) == 0) {
+			entry = &ioctls[i];
+			break;
+		}
+	}
+
+	if (!entry) {
+		fprintf(stderr, "ERROR: unknown ioctl %s\n", argv[2]);
+		close(fd);
+		return 1;
+	}
+
+	ret = entry->handler(fd, argc - 3, argv + 3);
+	if (ret == -ENOTTY) {
+		printf("Not implemented.\n");
+		close(fd);
+		return 0;
+	} else if (ret) {
+		fprintf(stderr, "ERROR: %s failed: %s\n",
+			entry->name, strerror(-ret));
+		close(fd);
+		return 1;
+	}
+
+	close(fd);
+	return 0;
+}
Index: xfstests/tests/btrfs/021
===================================================================
--- /dev/null
+++ xfstests/tests/btrfs/021
@@ -0,0 +1,88 @@
+#!/bin/bash
+# FA QA Test No. 021
+#
+# Test global metadata reservation reporting
+#
+# 1) Create empty file system
+# 2) Call the BTRFS_IOC_GLOBAL_RSV ioctl and confirm it is 0 < x < 10MB
+# 3) Read the /sys/fs/btrfs/<fsid>/allocation/global_rsv_reserved file
+#    and confirm the value is 0 < x < 10 MB
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2013 SUSE, All Rights Reserved.
+#
+# 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
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter.btrfs
+
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+
+# Check to see if the reservation is 0 < x <= 10MB
+# At the time of this writing, it should always be exactly 4 MB
+# but that is an implementation detail subject to change.
+check_reserved() {
+	reserved="$2"
+	method="$3"
+	if [ "$1" != 0 ]; then
+		echo "$method: failed: $reserved"
+		exit 1
+	fi
+	if [ "$reserved" = "Not implemented." ]; then
+		echo "Skipping ioctl test. Not implemented." >> $seqres.full
+		return
+	fi
+	if [ -n "$(echo $reserved | tr -d 0-9)" ]; then
+		echo "ERROR: numerical value expected (got $reserved)"
+		exit 1
+	fi
+	if [ "$reserved" -le 0 -o \
+	       "$reserved" -gt "$(( 10 * 1024 * 1024 ))" ]; then
+		echo "$method: out of range: $reserved."
+		exit
+	fi
+}
+
+# ioctl
+reserved="$(src/btrfs_ioctl_helper $SCRATCH_MNT GLOBAL_RSV 2>&1)"
+check_reserved $? "$reserved" "ioctl"
+
+# sysfs
+# If this directory is here, the files must be here as well
+SYSFS_PREFIX="/sys/fs/btrfs/$(_btrfs_get_fsid $SCRATCH_DEV)/allocation"
+if [ -d "$SYSFS_PREFIX" ]; then
+	reserved="$(cat $SYSFS_PREFIX/global_rsv_reserved 2>&1)"
+	check_reserved $? "$reserved" "sysfs:reserved"
+	size="$(cat $SYSFS_PREFIX/global_rsv_size 2>&1)"
+	check_reserved $? "$size" "sysfs:size"
+fi
+
+echo "Silence is golden"
+status=0
+exit
Index: xfstests/tests/btrfs/021.out
===================================================================
--- /dev/null
+++ xfstests/tests/btrfs/021.out
@@ -0,0 +1,2 @@
+QA output created by 021
+Silence is golden


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2013-10-28 22:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-28 20:47 [patch 0/3] xfstests: for btrfs publishing/export patchset (v3) Jeff Mahoney
2013-10-28 20:47 ` Jeff Mahoney
2013-10-28 20:47 ` Jeff Mahoney [this message]
2013-10-28 20:47   ` [patch 1/3] xfstests: btrfs/021: test global metadata reservation reporting Jeff Mahoney
2013-10-28 20:47 ` [patch 2/3] xfstests: btrfs/022: test sysfs exports of allocation and device membership info Jeff Mahoney
2013-10-28 20:47   ` Jeff Mahoney
2013-10-28 20:47 ` [patch 3/3] xfstests: btrfs/023,024,025: test feature ioctl and sysfs interfaces Jeff Mahoney
2013-10-28 20:47   ` [patch 3/3] xfstests: btrfs/023, 024, 025: " Jeff Mahoney
  -- strict thread matches above, loose matches on Subject: below --
2013-10-29 19:26 [patch 0/3] xfstests: for btrfs publishing/export patchset (v4) Jeff Mahoney
2013-10-29 19:26 ` [patch 1/3] xfstests: btrfs/021: test global metadata reservation reporting Jeff Mahoney
2013-10-29 19:26   ` Jeff Mahoney
2013-10-28 19:52 [PATCH 0/3] xfstests: for btrfs publishing/export patchset (v2) Jeff Mahoney
2013-10-28 19:52 ` [PATCH 1/3] xfstests: btrfs/021: test global metadata reservation reporting Jeff Mahoney
2013-10-28 19:52   ` Jeff Mahoney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131028204902.815790553@sled1.home.jeffreymahoney.com \
    --to=jeffm@suse.com \
    --cc=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.