From patchwork Thu Mar 23 06:50:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 9640451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 50A7C602D6 for ; Thu, 23 Mar 2017 07:30:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42A8C284DC for ; Thu, 23 Mar 2017 07:30:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37B5F284F3; Thu, 23 Mar 2017 07:30:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D19C284DD for ; Thu, 23 Mar 2017 07:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752781AbdCWHaS (ORCPT ); Thu, 23 Mar 2017 03:30:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37228 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751461AbdCWHaI (ORCPT ); Thu, 23 Mar 2017 03:30:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00AA821722 for ; Thu, 23 Mar 2017 06:50:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00AA821722 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=zlang@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 00AA821722 Received: from dhcp-12-168.nay.redhat.com (dhcp-12-168.nay.redhat.com [10.66.12.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 402587DFC2 for ; Thu, 23 Mar 2017 06:50:09 +0000 (UTC) From: Zorro Lang To: fstests@vger.kernel.org Subject: [PATCH v7 1/2] fsstress: add mwrite/mread into test operation list Date: Thu, 23 Mar 2017 14:50:04 +0800 Message-Id: <1490251805-22658-1-git-send-email-zlang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 23 Mar 2017 06:50:10 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mmap as a popular and basic operation, most of softwares use it to access files. More and more customers report bugs related with mmap/munmap and other stress conditions. So add mmap read/write test into fsstress to increase mmap related stress to reproduce or find more bugs easily. Signed-off-by: Zorro Lang --- Hi, V7 did below changes: 1) Move inode_info() function call backward, to init "struct st" before use it. 2) Return directly if mmap fails 3) Add HAVE_SYS_MMAN_H detection in mwrite() and mread() functions. Thanks, Zorro configure.ac | 1 + ltp/fsstress.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/global.h | 4 ++ 3 files changed, 119 insertions(+) diff --git a/configure.ac b/configure.ac index fa48d2f..246f92e 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,7 @@ AC_HEADER_STDC xfs/platform_defs.h \ btrfs/ioctl.h \ cifs/ioctl.h \ + sys/mman.h \ ]) AC_CHECK_HEADERS([xfs/xfs_log_format.h],,,[ diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 7e7cf60..f8203cf 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -69,6 +69,8 @@ typedef enum { OP_LINK, OP_MKDIR, OP_MKNOD, + OP_MREAD, + OP_MWRITE, OP_PUNCH, OP_ZERO, OP_COLLAPSE, @@ -168,6 +170,8 @@ void getdents_f(int, long); void link_f(int, long); void mkdir_f(int, long); void mknod_f(int, long); +void mread_f(int, long); +void mwrite_f(int, long); void punch_f(int, long); void zero_f(int, long); void collapse_f(int, long); @@ -208,6 +212,8 @@ 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_MREAD, "mread", mread_f, 2, 0 }, + { OP_MWRITE, "mwrite", mwrite_f, 2, 1 }, { OP_PUNCH, "punch", punch_f, 1, 1 }, { OP_ZERO, "zero", zero_f, 1, 1 }, { OP_COLLAPSE, "collapse", collapse_f, 1, 1 }, @@ -2656,6 +2662,114 @@ mknod_f(int opno, long r) } void +do_mmap(int opno, long r, int prot) +{ +#ifdef HAVE_SYS_MMAN_H + char *addr; + int e; + pathname_t f; + int fd; + size_t len; + __int64_t lr; + off64_t off; + int flags; + struct stat64 stb; + int v; + char st[1024]; + + init_pathname(&f); + if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) { + if (v) + printf("%d/%d: do_mmap - 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: do_mmap - open %s failed %d\n", + procid, opno, f.path, e); + free_pathname(&f); + return; + } + if (fstat64(fd, &stb) < 0) { + if (v) + printf("%d/%d: do_mmap - fstat64 %s failed %d\n", + procid, opno, f.path, errno); + free_pathname(&f); + close(fd); + return; + } + inode_info(st, sizeof(st), &stb, v); + if (stb.st_size == 0) { + if (v) + printf("%d/%d: do_mmap - %s%s zero size\n", procid, opno, + f.path, st); + free_pathname(&f); + close(fd); + return; + } + + lr = ((__int64_t)random() << 32) + random(); + off = (off64_t)(lr % stb.st_size); + off &= (off64_t)(~(sysconf(_SC_PAGE_SIZE) - 1)); + len = (size_t)(random() % MIN(stb.st_size - off, FILELEN_MAX)) + 1; + + flags = (random() % 2) ? MAP_SHARED : MAP_PRIVATE; + addr = mmap(NULL, len, prot, flags, fd, off); + e = (addr == MAP_FAILED) ? errno : 0; + if (e) { + if (v) + printf("%d/%d: do_mmap - mmap failed %s%s [%lld,%d,%s] %d\n", + procid, opno, f.path, st, + (long long)off, (int)len, + (flags & MAP_PRIVATE) ? "MAP_PRIVATE" : "MAP_SHARED", + e); + free_pathname(&f); + close(fd); + return; + } + + if (prot & PROT_WRITE) { + /* PROT_READ maybe set, if PROT_WRITE is set. Not vice versa */ + memset(addr, nameseq & 0xff, len); + } else { + char *buf; + if ((buf = malloc(len)) != NULL) { + memcpy(buf, addr, len); + free(buf); + } + } + e = munmap(addr, len) < 0 ? errno : 0; + if (v) + printf("%d/%d: %s %s%s [%lld,%d] %d\n", + procid, opno, (prot & PROT_WRITE) ? "mwrite" : "mread", + f.path, st, (long long)off, (int)len, e); + + free_pathname(&f); + close(fd); +#endif +} + +void +mread_f(int opno, long r) +{ +#ifdef HAVE_SYS_MMAN_H + do_mmap(opno, r, PROT_READ); +#endif +} + +void +mwrite_f(int opno, long r) +{ +#ifdef HAVE_SYS_MMAN_H + do_mmap(opno, r, PROT_WRITE); +#endif +} + +void punch_f(int opno, long r) { #ifdef HAVE_LINUX_FALLOC_H diff --git a/src/global.h b/src/global.h index f63246b..3920c0d 100644 --- a/src/global.h +++ b/src/global.h @@ -178,4 +178,8 @@ #endif /* HAVE_LINUX_FALLOC_H */ +#ifdef HAVE_SYS_MMAN_H +#include +#endif + #endif /* GLOBAL_H */