From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 05/15] lib/tst_fs: Add tst_fill_fs()
Date: Tue, 10 Oct 2017 14:31:55 +0200 [thread overview]
Message-ID: <20171010123205.20147-5-chrubis@suse.cz> (raw)
In-Reply-To: <20171010123205.20147-1-chrubis@suse.cz>
Adds a simple helper to fill a filesystem.
All the funciton does is to create and write to files in a given
directory until write() fails with ENOSPC.
This is intended to be used in various filesystem related tests such as
fallocate and stress tests.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
include/tst_fs.h | 5 +++++
lib/tst_fill_fs.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+)
create mode 100644 lib/tst_fill_fs.c
diff --git a/include/tst_fs.h b/include/tst_fs.h
index 1f6d2bab5..0ad535c2b 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -151,6 +151,11 @@ int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount);
*/
const char **tst_get_supported_fs_types(void);
+/*
+ * Creates and writes to files on given path until write fails with ENOSPC
+ */
+void tst_fill_fs(const char *path, int verbose);
+
#ifdef TST_TEST_H__
static inline long tst_fs_type(const char *path)
{
diff --git a/lib/tst_fill_fs.c b/lib/tst_fill_fs.c
new file mode 100644
index 000000000..6b2bbbcd7
--- /dev/null
+++ b/lib/tst_fill_fs.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * 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, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+void tst_fill_fs(const char *path, int verbose)
+{
+ int i = 0;
+ char file[PATH_MAX];
+ char buf[4096];
+ size_t len;
+ ssize_t ret;
+ int fd;
+
+ for (;;) {
+ len = random() % (1024 * 102400);
+
+ snprintf(file, sizeof(file), "%s/file%i", path, i++);
+
+ if (verbose)
+ tst_res(TINFO, "Creating file %s size %zu", file, len);
+
+ fd = SAFE_OPEN(file, O_WRONLY | O_CREAT, 0700);
+
+ while (len) {
+ ret = write(fd, buf, MIN(len, sizeof(buf)));
+
+ if (ret < 0) {
+ SAFE_CLOSE(fd);
+
+ if (errno != ENOSPC)
+ tst_brk(TBROK | TERRNO, "write()");
+
+ tst_res(TINFO | TERRNO, "write()");
+ return;
+ }
+
+ len -= ret;
+ }
+
+ SAFE_CLOSE(fd);
+ }
+}
--
2.13.5
next prev parent reply other threads:[~2017-10-10 12:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 12:31 [LTP] [PATCH v2 01/15] lib/tst_mkfs: Clear first 512k of the device Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 02/15] lib: Add interface to list supported filesystems Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 03/15] SAFE_MOUNT: Handle FUSE mounts as well Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 04/15] lib/tst_test: Add .all_filesystems flag Cyril Hrubis
2017-10-11 8:42 ` Jan Stancek
2017-10-11 9:54 ` Cyril Hrubis
2017-10-11 10:38 ` Jan Stancek
2017-10-11 11:11 ` Cyril Hrubis
2017-10-11 11:17 ` Jan Stancek
2017-10-10 12:31 ` Cyril Hrubis [this message]
2017-10-10 12:31 ` [LTP] [PATCH v2 06/15] syscalls/fallocate05: New test Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 07/15] syscalls/msync04: Run test for all filesystems Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 08/15] syscalls/fallocate04: Convert to the new library Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 09/15] syscalls/fallocate04: Run test for all filesystems Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 10/15] syscalls/setxattr01: Convert to the new library Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 11/15] syscalls/setxattr01: Run test for all filesystems Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 12/15] syscallse/setxattr02: Convert to the new library Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 13/15] syscalls/fsync01: " Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 14/15] syscalls/fsync01: Run test for all filesystems Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 15/15] fs/fs_fill: Add a test to fill a FS in a few threads Cyril Hrubis
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=20171010123205.20147-5-chrubis@suse.cz \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox