From: Dmitry Monakhov <dmonakhov@openvz.org>
To: linux-fsdevel@vger.kernel.org
Cc: xfs@oss.sgi.com, hch@lst.de, aelder@sgi.com, tytso@mit.edu,
Dmitry Monakhov <dmonakhov@openvz.org>
Subject: [PATCH 06/12] xfstests: add fallocate support to fsstress
Date: Thu, 3 Nov 2011 18:24:55 +0400 [thread overview]
Message-ID: <1320330301-2682-7-git-send-email-dmonakhov@openvz.org> (raw)
In-Reply-To: <1320330301-2682-1-git-send-email-dmonakhov@openvz.org>
Add tests for fallocate(2) syscall
- fallocate: reserve the disk space
- punch: de-allocates the disk space
Since FALLOC_FL_PUNCH_HOLE is relatively new it's value defined
explicitly if not yet defined. Later we may clear that define.
Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
ltp/fsstress.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 126 insertions(+), 1 deletions(-)
diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index 77e0682..f4c8d81 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -24,7 +24,13 @@
#ifdef HAVE_ATTR_ATTRIBUTES_H
#include <attr/attributes.h>
#endif
-
+#ifdef FALLOCATE
+#include <linux/falloc.h>
+#ifndef FALLOC_FL_PUNCH_HOLE
+/* Copy-paste from linux/falloc.h */
+#define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */
+#endif
+#endif
#ifndef HAVE_ATTR_LIST
#define attr_list(path, buf, size, flags, cursor) (errno = -ENOSYS, -1)
#endif
@@ -48,6 +54,7 @@ typedef enum {
OP_CREAT,
OP_DREAD,
OP_DWRITE,
+ OP_FALLOCATE,
OP_FDATASYNC,
OP_FREESP,
OP_FSYNC,
@@ -55,6 +62,7 @@ typedef enum {
OP_LINK,
OP_MKDIR,
OP_MKNOD,
+ OP_PUNCH,
OP_READ,
OP_READLINK,
OP_RENAME,
@@ -128,6 +136,7 @@ void chown_f(int, long);
void creat_f(int, long);
void dread_f(int, long);
void dwrite_f(int, long);
+void fallocate_f(int, long);
void fdatasync_f(int, long);
void freesp_f(int, long);
void fsync_f(int, long);
@@ -135,6 +144,7 @@ void getdents_f(int, long);
void link_f(int, long);
void mkdir_f(int, long);
void mknod_f(int, long);
+void punch_f(int, long);
void read_f(int, long);
void readlink_f(int, long);
void rename_f(int, long);
@@ -159,6 +169,7 @@ opdesc_t ops[] = {
{ OP_CREAT, "creat", creat_f, 4, 1 },
{ OP_DREAD, "dread", dread_f, 4, 0 },
{ OP_DWRITE, "dwrite", dwrite_f, 4, 1 },
+ { OP_FALLOCATE, "fallocate", fallocate_f, 1, 1 },
{ OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1 },
{ OP_FREESP, "freesp", freesp_f, 1, 1 },
{ OP_FSYNC, "fsync", fsync_f, 1, 1 },
@@ -166,6 +177,7 @@ opdesc_t ops[] = {
{ OP_LINK, "link", link_f, 1, 1 },
{ OP_MKDIR, "mkdir", mkdir_f, 2, 1 },
{ OP_MKNOD, "mknod", mknod_f, 2, 1 },
+ { OP_PUNCH, "punch", punch_f, 1, 1 },
{ OP_READ, "read", read_f, 1, 0 },
{ OP_READLINK, "readlink", readlink_f, 1, 0 },
{ OP_RENAME, "rename", rename_f, 2, 1 },
@@ -2012,6 +2024,63 @@ dwrite_f(int opno, long r)
}
void
+fallocate_f(int opno, long r)
+{
+#ifdef FALLOCATE
+ int e;
+ pathname_t f;
+ int fd;
+ __int64_t lr;
+ off64_t off;
+ off64_t len;
+ struct stat64 stb;
+ int v;
+ char st[1024];
+ int mode = 0;
+
+ init_pathname(&f);
+ if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+ if (v)
+ printf("%d/%d: fallocate - no filename\n", procid, opno);
+ free_pathname(&f);
+ return;
+ }
+ fd = open_path(&f, O_RDWR);
+ e = fd < 0 ? errno : 0;
+ check_cwd();
+ if (fd < 0) {
+ if (v)
+ printf("%d/%d: fallocate - open %s failed %d\n",
+ procid, opno, f.path, e);
+ free_pathname(&f);
+ return;
+ }
+ if (fstat64(fd, &stb) < 0) {
+ if (v)
+ printf("%d/%d: fallocate - fstat64 %s failed %d\n",
+ procid, opno, f.path, errno);
+ free_pathname(&f);
+ close(fd);
+ return;
+ }
+ inode_info(st, sizeof(st), &stb, v);
+ lr = ((__int64_t)random() << 32) + random();
+ off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+ off %= maxfsize;
+ len = (off64_t)(random() % (1024 * 1024));
+ mode |= FALLOC_FL_KEEP_SIZE & random();
+ e = fallocate(fd, mode, (loff_t)off, (loff_t)len) < 0 ? errno : 0;
+ if (v)
+ printf("%d/%d: fallocate(%d) %s %st %lld %lld %d\n",
+ procid, opno, mode,
+ f.path, st, (long long)off, (long long)len, e);
+ free_pathname(&f);
+ close(fd);
+#endif
+}
+
+
+void
fdatasync_f(int opno, long r)
{
int e;
@@ -2284,6 +2353,62 @@ mknod_f(int opno, long r)
}
void
+punch_f(int opno, long r)
+{
+#ifdef FALLOCATE
+ int e;
+ pathname_t f;
+ int fd;
+ __int64_t lr;
+ off64_t off;
+ off64_t len;
+ struct stat64 stb;
+ int v;
+ char st[1024];
+ int mode = FALLOC_FL_PUNCH_HOLE;
+
+ init_pathname(&f);
+ if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+ if (v)
+ printf("%d/%d: punch hole - no filename\n", procid, opno);
+ free_pathname(&f);
+ return;
+ }
+ fd = open_path(&f, O_RDWR);
+ e = fd < 0 ? errno : 0;
+ check_cwd();
+ if (fd < 0) {
+ if (v)
+ printf("%d/%d: punch hole - open %s failed %d\n",
+ procid, opno, f.path, e);
+ free_pathname(&f);
+ return;
+ }
+ if (fstat64(fd, &stb) < 0) {
+ if (v)
+ printf("%d/%d: punch hole - fstat64 %s failed %d\n",
+ procid, opno, f.path, errno);
+ free_pathname(&f);
+ close(fd);
+ return;
+ }
+ inode_info(st, sizeof(st), &stb, v);
+ lr = ((__int64_t)random() << 32) + random();
+ off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+ off %= maxfsize;
+ len = (off64_t)(random() % (1024 * 1024));
+ mode |= FALLOC_FL_KEEP_SIZE & random();
+ e = fallocate(fd, mode, (loff_t)off, (loff_t)len) < 0 ? errno : 0;
+ if (v)
+ printf("%d/%d: punch hole(%d) %s %s %lld %lld %d\n",
+ procid, opno, mode,
+ f.path, st, (long long)off, (long long)len, e);
+ free_pathname(&f);
+ close(fd);
+#endif
+}
+
+void
read_f(int opno, long r)
{
char *buf;
--
1.7.1
next prev parent reply other threads:[~2011-11-03 14:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-03 14:24 [PATCH 00/12] Bunch of new stress tests -v4 Dmitry Monakhov
2011-11-03 14:24 ` [PATCH 01/12] xfstests: fsstress dump inode info when possible Dmitry Monakhov
2011-11-03 14:24 ` [PATCH 02/12] xfstests: add different logging option to fsstress Dmitry Monakhov
2011-11-03 14:24 ` [PATCH 03/12] xfstests: fsstress should kill children tasks before exit Dmitry Monakhov
2011-11-03 14:24 ` [PATCH 04/12] xfstests: fsstress add command line style output for show_opts Dmitry Monakhov
2011-11-03 14:24 ` [PATCH 05/12] xfstests: freeze fsstress options for 117'th Dmitry Monakhov
2011-11-03 14:24 ` Dmitry Monakhov [this message]
2011-11-03 14:24 ` [PATCH 07/12] xfstests: fsstress add FS_IOC_{SET,GET}FLAGS operations v2 Dmitry Monakhov
2011-11-03 14:24 ` [PATCH 08/12] xfstests: add fiemap operation to fsstress Dmitry Monakhov
2011-11-03 14:24 ` [PATCH 09/12] xfstests: add a new test that runs fsstress under ENOSPC conditions Dmitry Monakhov
2011-11-07 21:22 ` Dave Chinner
2011-11-08 8:32 ` Dmitry Monakhov
2011-11-07 21:25 ` Dave Chinner
2011-11-03 14:24 ` [PATCH 10/12] xfstests: add a new quota " Dmitry Monakhov
2011-11-03 14:25 ` [PATCH 11/12] xfstress: add regression testcase for d583fb87a3ff0 Dmitry Monakhov
2011-11-03 14:25 ` [PATCH 12/12] xfstress: Test data journaling flag switch for a single file Dmitry Monakhov
2011-11-03 14:55 ` [PATCH 00/12] Bunch of new stress tests -v4 Christoph Hellwig
2011-11-03 15:21 ` Dmitry Monakhov
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=1320330301-2682-7-git-send-email-dmonakhov@openvz.org \
--to=dmonakhov@openvz.org \
--cc=aelder@sgi.com \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=tytso@mit.edu \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).