From patchwork Wed Jan 18 03:07:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murphy Zhou X-Patchwork-Id: 9522537 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 BAEEF6020A for ; Wed, 18 Jan 2017 03:07:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA52C2849C for ; Wed, 18 Jan 2017 03:07:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F5FA28549; Wed, 18 Jan 2017 03:07:46 +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=unavailable 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 52E3728516 for ; Wed, 18 Jan 2017 03:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751354AbdARDHp (ORCPT ); Tue, 17 Jan 2017 22:07:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38898 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751496AbdARDHo (ORCPT ); Tue, 17 Jan 2017 22:07:44 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 076D47F09D; Wed, 18 Jan 2017 03:07:32 +0000 (UTC) Received: from localhost (dhcp-12-130.nay.redhat.com [10.66.12.130]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0I37UuS026158; Tue, 17 Jan 2017 22:07:31 -0500 From: Xiong Zhou To: fstests@vger.kernel.org Cc: linux-nvdimm@ml01.01.org, Xiong Zhou Subject: [PATCH 2/4] src/t_mmap_dio: add mmap dio test Date: Wed, 18 Jan 2017 11:07:04 +0800 Message-Id: <1484708826-23529-3-git-send-email-xzhou@redhat.com> In-Reply-To: <1484708826-23529-1-git-send-email-xzhou@redhat.com> References: <1484708826-23529-1-git-send-email-xzhou@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 18 Jan 2017 03:07:32 +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 To test read/write between a mmap area of one file and another file directly, with different size. Signed-off-by: Xiong Zhou --- .gitignore | 1 + src/Makefile | 2 +- src/t_mmap_dio.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/t_mmap_dio.c diff --git a/.gitignore b/.gitignore index 7dcea14..48a40a0 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,7 @@ /src/cloner /src/renameat2 /src/t_rename_overwrite +/src/t_mmap_dio # dmapi/ binaries /dmapi/src/common/cmd/read_invis diff --git a/src/Makefile b/src/Makefile index 94d74aa..eb5a56c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ godown resvtest writemod makeextents itrash rename \ multi_open_unlink dmiperf unwritten_sync genhashnames t_holes \ t_mmap_writev t_truncate_cmtime dirhash_collide t_rename_overwrite \ - holetest t_truncate_self + holetest t_truncate_self t_mmap_dio LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \ diff --git a/src/t_mmap_dio.c b/src/t_mmap_dio.c new file mode 100644 index 0000000..545e900 --- /dev/null +++ b/src/t_mmap_dio.c @@ -0,0 +1,81 @@ +/* + * This programme was originally written by + * Jeff Moyer + */ +#define _GNU_SOURCE 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void usage(char *prog) +{ + fprintf(stderr, + "usage: %s \n", + prog); + exit(1); +} + +void err_exit(char *op, unsigned long len) +{ + fprintf(stderr, "%s(%s) len %lu\n", + op, strerror(errno), len); + exit(1); +} + +int main(int argc, char **argv) +{ + int fd, fd2, ret; + char *map; + unsigned long len; + + if (argc < 3) + usage(basename(argv[0])); + + len = strtoul(argv[3], NULL, 10); + if (errno == ERANGE) + err_exit("strtoul", 0); + + /* Open source file and mmap*/ + fd = open(argv[1], O_RDWR, 0644); + if (fd < 0) + err_exit("open s", len); + + map = (char *)mmap(NULL, len, + PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (map == MAP_FAILED) + err_exit("mmap", len); + + /* Open dest file with O_DIRECT */ + fd2 = open(argv[2], O_RDWR|O_DIRECT, 0644); + if (fd2 < 0) + err_exit("open d", len); + + /* First, test storing to dest file from source mapping */ + ret = write(fd2, map, len); + if (ret != len) + err_exit("write", len); + + ret = (int)lseek(fd2, 0, SEEK_SET); + if (ret == -1) + err_exit("lseek", len); + + /* Next, test reading from dest file into source mapping */ + ret = read(fd2, map, len); + if (ret != len) + err_exit("read", len); + ret = msync(map, len, MS_SYNC); + if (ret < 0) + err_exit("msync", len); + + ret = munmap(map, len); + if (ret < 0) + err_exit("munmap", len); + + exit(0); +}