From patchwork Mon Sep 17 07:52:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kewal X-Patchwork-Id: 970427 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=213.254.12.146; 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 [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42DJKy5yMsz9sB4 for ; Mon, 17 Sep 2018 17:54:11 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6D4DB3E60A1 for ; Mon, 17 Sep 2018 09:54:08 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 896063E6080 for ; Mon, 17 Sep 2018 09:54:06 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-5.smtp.seeweb.it (Postfix) with ESMTP id 346A1600956 for ; Mon, 17 Sep 2018 09:54:04 +0200 (CEST) Date: Mon, 17 Sep 2018 07:52:48 -0000 To: ltp@lists.linux.it Message-ID: <20180917075248.28004-1-kewal@zilogic.com> From: "kewal" Received: from localhost.localdomain (broadband.actcorp.in [49.206.120.93]) by mail.zilogic.com; Mon, 17 Sep 2018 07:53:19 -0000 X-Mailer: git-send-email 2.11.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.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-5.smtp.seeweb.it Subject: [LTP] [PATCH v2] Test statx syscall 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" * statx06.c :- 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/statx06.c | 195 +++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 testcases/kernel/syscalls/statx/statx06.c diff --git a/runtest/syscalls b/runtest/syscalls index 0d0be7713..71b83b25c 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1504,3 +1504,4 @@ statx02 statx02 statx03 statx03 statx04 statx04 statx05 statx05 +statx06 statx06 diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 209fc3a33..c1ceddabf 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -3,3 +3,4 @@ /statx03 /statx04 /statx05 +/statx06 diff --git a/testcases/kernel/syscalls/statx/statx06.c b/testcases/kernel/syscalls/statx/statx06.c new file mode 100644 index 000000000..f64322d7d --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx06.c @@ -0,0 +1,195 @@ +// 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.11. + */ + +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "lapi/stat.h" + +#define MODE(X) (X & (~S_IFMT)) +#define F_PATH_SIZE 50 +#define BUFF_SIZE (PATH_MAX + 50) +#define DEFAULT_MODE 0644 +#define CURRENT_MODE 0777 + +#define CLIENT_PATH "client" +#define SERVER_PATH "server" +#define FORCE_SYNC_FILE "force_sync_file" +#define DONT_SYNC_FILE "dont_sync_file" + +static char cwd[PATH_MAX]; +static char cmd[BUFF_SIZE]; + +static int get_mode(char *file_name, int flag_type, char *flag_name) +{ + char client_path[F_PATH_SIZE]; + struct statx buff; + + snprintf(client_path, sizeof(client_path), "%s/%s", + CLIENT_PATH, file_name); + + TEST(statx(AT_FDCWD, client_path, 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; +} + +static void test_for_dont_sync(void) +{ + unsigned int cur_mode; + char server_path[F_PATH_SIZE]; + + snprintf(server_path, sizeof(server_path), "%s/%s", SERVER_PATH, + DONT_SYNC_FILE); + + get_mode(DONT_SYNC_FILE, AT_STATX_FORCE_SYNC, + "AT_STATX_FORCE_SYNC"); + + SAFE_CHMOD(server_path, CURRENT_MODE); + cur_mode = get_mode(DONT_SYNC_FILE, AT_STATX_DONT_SYNC, + "AT_STATX_DONT_SYNC"); + + if (MODE(cur_mode) == DEFAULT_MODE) + tst_res(TPASS, + "statx() with AT_STATX_DONT_SYNC for mode %o %o", + DEFAULT_MODE, MODE(cur_mode)); + else + tst_res(TFAIL, + "statx() with AT_STATX_DONT_SYNC for mode %o %o", + DEFAULT_MODE, MODE(cur_mode)); +} + +static void test_for_force_sync(void) +{ + unsigned int cur_mode; + char server_path[F_PATH_SIZE]; + + snprintf(server_path, sizeof(server_path), "%s/%s", SERVER_PATH, + FORCE_SYNC_FILE); + + SAFE_CHMOD(server_path, CURRENT_MODE); + cur_mode = get_mode(FORCE_SYNC_FILE, AT_STATX_FORCE_SYNC, + "AT_STATX_FORCE_SYNC"); + + if (MODE(cur_mode) == CURRENT_MODE) + tst_res(TPASS, + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", + CURRENT_MODE, MODE(cur_mode)); + else + tst_res(TFAIL, + "statx() with AT_STATX_FORCE_SYNC for mode %o %o", + CURRENT_MODE, MODE(cur_mode)); +} + +const struct test_cases { + void (*func)(void); +} tcases[] = { + {test_for_dont_sync}, + {test_for_force_sync} +}; + +static void test_statx(unsigned int nr) +{ + const struct test_cases *tc = &tcases[nr]; + + tc->func(); +} + +static void setup(void) +{ + int ret; + char force_sync_file[F_PATH_SIZE]; + char dont_sync_file[F_PATH_SIZE]; + char mount_data[F_PATH_SIZE]; + char server_path[BUFF_SIZE]; + char client_path[BUFF_SIZE]; + char *ip = "127.0.0.1"; + + TESTPTR(getcwd(cwd, PATH_MAX)); + if (TST_RET_PTR == NULL) + tst_brk(TBROK | TST_ERR, "Failed to get PWD"); + + snprintf(force_sync_file, sizeof(force_sync_file), "%s/%s", + SERVER_PATH, FORCE_SYNC_FILE); + snprintf(dont_sync_file, sizeof(dont_sync_file), "%s/%s", + SERVER_PATH, DONT_SYNC_FILE); + + SAFE_MKDIR(SERVER_PATH, DEFAULT_MODE); + SAFE_MKDIR(CLIENT_PATH, DEFAULT_MODE); + SAFE_CREAT(force_sync_file, DEFAULT_MODE); + SAFE_CREAT(dont_sync_file, DEFAULT_MODE); + + snprintf(server_path, sizeof(server_path), ":%s/%s", cwd, SERVER_PATH); + snprintf(client_path, sizeof(client_path), "%s/%s", cwd, CLIENT_PATH); + snprintf(mount_data, sizeof(mount_data), "addr=%s", ip); + + snprintf(cmd, sizeof(cmd), + "exportfs -i -o no_root_squash,rw,sync,no_subtree_check *%s", + server_path); + + ret = tst_system(cmd); + if (WEXITSTATUS(ret) == 127) + tst_brk(TCONF | TST_ERR, "%s not found", cmd); + if (ret == -1) + tst_brk(TBROK | TST_ERR, "failed to exportfs"); + + SAFE_MOUNT(server_path, client_path, "nfs", 0, mount_data); +} + +static void cleanup(void) +{ + if (tst_system("exportfs -ua") == -1) + tst_brk(TBROK | TST_ERR, "failed to clear exportfs"); + + SAFE_UMOUNT(CLIENT_PATH); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .test = test_statx, + .setup = setup, + .cleanup = cleanup, + .min_kver = "4.11", + .needs_tmpdir = 1, + .dev_fs_type = "nfs", + .needs_root = 1, +};