From patchwork Fri Dec 7 08:42:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "vaishnavi.d" X-Patchwork-Id: 1009220 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=zilogic.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43B5bg1hmcz9s47 for ; Fri, 7 Dec 2018 19:43:40 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 107213E6DE7 for ; Fri, 7 Dec 2018 09:43:37 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 48AE43E6DCA for ; Fri, 7 Dec 2018 09:43:34 +0100 (CET) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 123D3200243 for ; Fri, 7 Dec 2018 09:43:31 +0100 (CET) Date: Fri, 07 Dec 2018 08:42:21 -0000 To: ltp@lists.linux.it Message-ID: <1544172141-1676-1-git-send-email-vaishnavi.d@zilogic.com> From: "Vaishnavi" Received: from localhost.localdomain (broadband.actcorp.in [49.204.217.80]) by mail.zilogic.com; Fri, 07 Dec 2018 08:42:49 -0000 X-Mailer: git-send-email 2.1.4 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=MSGID_FROM_MTA_HEADER, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v4] syscalls/statx: Add test for sync flags X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Testcase 1: AT_STATX_DONT_SYNC With AT_STATX_DONT_SYNC server changes should not get sync with client. Testcase 2: AT_STATX_FORCE_SYNC With AT_STATX_FORCE_SYNC server changes should get sync with client. Signed-off-by: Kewal Ukunde Signed-off-by: Vaishnavi.d Signed-off-by: Tarun.T.U Reviewed-by: Petr Vorel --- runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx07.c | 170 +++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 testcases/kernel/syscalls/statx/statx07.c diff --git a/runtest/syscalls b/runtest/syscalls index ac1d2d2..957b999 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1524,5 +1524,6 @@ statx03 statx03 statx04 statx04 statx05 statx05 statx06 statx06 +statx07 statx07 membarrier01 membarrier01 diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index c1cedda..2f5457e 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -4,3 +4,4 @@ /statx04 /statx05 /statx06 +/statx07 diff --git a/testcases/kernel/syscalls/statx/statx07.c b/testcases/kernel/syscalls/statx/statx07.c new file mode 100644 index 0000000..b5fbaf3 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx07.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + */ + +/* + * Test statx + * + * This code tests the following flags: + * 1) AT_STATX_FORCE_SYNC + * 2) AT_STATX_DONT_SYNC + * + * By exportfs cmd creating NFS setup. + * + * A test file is created in server folder and statx is being + * done in client folder. + * + * TESTCASE 1: + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. + + * Then, by using AT_STATX_FORCE_SYNC getting new updated vaue + * from server file changes. + * + * TESTCASE 2: + * BY AT_STATX_SYNC_AS_STAT getting predefined mode value. + * AT_STATX_FORCE_SYNC is called to create cache data of the file. + * Then, by using DONT_SYNC_FILE getting old cached data in client folder, + * but mode has been chaged in server file. + * + * Minimum kernel version required is 4.16. + */ + +#include +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "lapi/stat.h" +#include "old_tmpdir.h" + +#define MODE(X) (X & (~S_IFMT)) +#define BUFF_SIZE PATH_MAX +#define DEFAULT_MODE 0644 +#define CURRENT_MODE 0777 + +#define CLIENT_PATH "client" +#define SERVER_PATH "server" +#define CLI_FORCE_SYNC "client/force_sync_file" +#define CLI_DONT_SYNC "client/dont_sync_file" +#define SERV_FORCE_SYNC "server/force_sync_file" +#define SERV_DONT_SYNC "server/dont_sync_file" + +static char *cwd; +static char cmd[BUFF_SIZE]; +static int mounted; + +static int get_mode(char *file_name, int flag_type, char *flag_name) +{ + struct statx buff; + + TEST(statx(AT_FDCWD, file_name, flag_type, STATX_ALL, &buff)); + + if (TST_RET == -1) + tst_brk(TFAIL | TST_ERR, + "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", + file_name, flag_name); + else + tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_ALL, &buff)", + file_name, flag_name); + + return buff.stx_mode; +} + +const struct test_cases { + char *server_file; + char *client_file; + char *flag_name; + int flag; + unsigned int mode; + +} tcases[] = { + {SERV_DONT_SYNC, + CLI_DONT_SYNC, + "AT_STATX_DONT_SYNC", + AT_STATX_DONT_SYNC, + DEFAULT_MODE}, + {SERV_FORCE_SYNC, + CLI_FORCE_SYNC, + "AT_STATX_FORCE_SYNC", + AT_STATX_FORCE_SYNC, + CURRENT_MODE} +}; + +static void test_statx(unsigned int nr) +{ + const struct test_cases *tc = &tcases[nr]; + unsigned int cur_mode; + + get_mode(tc->client_file, AT_STATX_FORCE_SYNC, "AT_STATX_FORCE_SYNC"); + + SAFE_CHMOD(tc->server_file, CURRENT_MODE); + cur_mode = get_mode(tc->client_file, tc->flag, tc->flag_name); + + if (MODE(cur_mode) == tc->mode) + tst_res(TPASS, + "statx() with %s for mode %o %o", + tc->flag_name, tc->mode, MODE(cur_mode)); + else + tst_res(TFAIL, + "statx() with %s for mode %o %o", + tc->flag_name, tc->mode, MODE(cur_mode)); +} + +static void setup(void) +{ + int ret; + char server_path[BUFF_SIZE]; + + cwd = tst_get_tmpdir(); + + SAFE_MKDIR(SERVER_PATH, DEFAULT_MODE); + SAFE_MKDIR(CLIENT_PATH, DEFAULT_MODE); + SAFE_CREAT(SERV_FORCE_SYNC, DEFAULT_MODE); + SAFE_CREAT(SERV_DONT_SYNC, DEFAULT_MODE); + + snprintf(server_path, sizeof(server_path), ":%s/%s", cwd, SERVER_PATH); + + snprintf(cmd, sizeof(cmd), + "exportfs -i -o no_root_squash,rw,sync,no_subtree_check *%.1024s", + server_path); + + ret = tst_system(cmd); + if (WEXITSTATUS(ret) == 127) + tst_brk(TCONF | TST_ERR, "%s not found", cmd); + if (ret) + tst_brk(TBROK | TST_ERR, "failed to exportfs"); + + if (mount(server_path, CLIENT_PATH, "nfs", 0, "addr=127.0.0.1")) { + if (errno == EOPNOTSUPP) + tst_brk(TCONF | TERRNO, "nfs server not set up?"); + tst_brk(TBROK | TERRNO, "mount() nfs failed"); + } + mounted = 1; +} + +static void cleanup(void) +{ + snprintf(cmd, sizeof(cmd), + "exportfs -u *:%s/%s", cwd, SERVER_PATH); + + if (tst_system(cmd) == -1) + tst_res(TWARN | TST_ERR, "failed to clear exportfs"); + + if (mounted) + SAFE_UMOUNT(CLIENT_PATH); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = test_statx, + .setup = setup, + .cleanup = cleanup, + .min_kver = "4.16", + .needs_tmpdir = 1, + .dev_fs_type = "nfs", + .needs_root = 1, +};