From patchwork Wed Oct 19 10:29:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Monakhov X-Patchwork-Id: 120586 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 7F773B6FA1 for ; Wed, 19 Oct 2011 21:30:06 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755757Ab1JSKaC (ORCPT ); Wed, 19 Oct 2011 06:30:02 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:51243 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753705Ab1JSK37 (ORCPT ); Wed, 19 Oct 2011 06:29:59 -0400 Received: by mail-bw0-f46.google.com with SMTP id zt19so1917801bkb.19 for ; Wed, 19 Oct 2011 03:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=SckuxX4HLvB4Wx+JIgL9QaJxQ6UkT+gRRT03f+1N/48=; b=URzkPW4GK6sYa/cs69N5agpr7l0CHBr/29K9ebZKMC8OKLzl//8pE/NZ+0sFWxmRtW GQCHPZh4p/lbNHvJeUDBbctlR8mEZtOAueSlOUv2pejU99vrlHxjiA+Mo4R86vzBMLyS 9+tvyRRIqKWr3hcjO7RNXHT9Jj7JP5FEGkmSg= Received: by 10.204.154.156 with SMTP id o28mr4443223bkw.12.1319020198368; Wed, 19 Oct 2011 03:29:58 -0700 (PDT) Received: from localhost.localdomain (swsoft-msk-nat.sw.ru. [195.214.232.10]) by mx.google.com with ESMTPS id u10sm5374100bkv.3.2011.10.19.03.29.56 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 19 Oct 2011 03:29:57 -0700 (PDT) From: Dmitry Monakhov To: linux-fsdevel@vger.kernel.org, xfs@oss.sgi.com, linux-ext4@vger.kernel.org, jack@suse.cz, hch@infradead.org, aelder@sgi.com Cc: Dmitry Monakhov Subject: [PATCH 3/8] xfstests: add fallocate support to fsstress Date: Wed, 19 Oct 2011 14:29:44 +0400 Message-Id: <1319020189-13584-4-git-send-email-dmonakhov@openvz.org> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1319020189-13584-1-git-send-email-dmonakhov@openvz.org> References: <1319020189-13584-1-git-send-email-dmonakhov@openvz.org> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.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 --- ltp/fsstress.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 122 insertions(+), 1 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 385d5a0..4aba34f 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -24,7 +24,13 @@ #ifdef HAVE_ATTR_ATTRIBUTES_H #include #endif - +#ifdef FALLOCATE +#include +#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 }, @@ -1981,6 +1993,61 @@ 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; + 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; + } + 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 %lld %lld %d\n", + procid, opno, mode, + f.path, (long long)off, (long long)len, e); + free_pathname(&f); + close(fd); +#endif +} + + +void fdatasync_f(int opno, long r) { int e; @@ -2251,6 +2318,60 @@ 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; + 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; + } + 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 %lld %lld %d\n", + procid, opno, mode, + f.path, (long long)off, (long long)len, e); + free_pathname(&f); + close(fd); +#endif +} + +void read_f(int opno, long r) { char *buf;