From patchwork Thu Sep 20 11:27:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vishnu X-Patchwork-Id: 972337 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 42GDxy1YqVz9s4V for ; Thu, 20 Sep 2018 21:28:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 69D163E769A for ; Thu, 20 Sep 2018 13:28:30 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 2B0F83E7648 for ; Thu, 20 Sep 2018 13:28:28 +0200 (CEST) Received: from mail.zilogic.com (mail.zilogic.com [45.33.14.236]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id B90DB1A00904 for ; Thu, 20 Sep 2018 13:28:26 +0200 (CEST) Date: Thu, 20 Sep 2018 11:27:31 -0000 To: ltp@lists.linux.it Message-ID: <20180920112731.6108-1-vishnu@zilogic.com> From: "Vishnu K" Received: from localhost.localdomain (broadband.actcorp.in [49.204.222.247]) by mail.zilogic.com; Thu, 20 Sep 2018 11:28:07 -0000 X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.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-3.smtp.seeweb.it Subject: [LTP] [PATCH v1] Test statx() with flag AT_NO_AUTOMOUNT. 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" Signed-off-by: vishnu@zilogic.com Signed-off-by: vaishnavi.d@zilogic.com Signed-off-by: tarun@zilogic.com --- runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx11.c | 194 +++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 testcases/kernel/syscalls/statx/statx11.c diff --git a/runtest/syscalls b/runtest/syscalls index 0d0be7713..99c9a2fce 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1504,3 +1504,4 @@ statx02 statx02 statx03 statx03 statx04 statx04 statx05 statx05 +statx11 statx11 \ No newline at end of file diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 209fc3a33..606fb1a59 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -3,3 +3,4 @@ /statx03 /statx04 /statx05 +/statx11 diff --git a/testcases/kernel/syscalls/statx/statx11.c b/testcases/kernel/syscalls/statx/statx11.c new file mode 100644 index 000000000..62b4e7b48 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx11.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 or later +/* + * Copyright (c) Zilogic Systems Pvt. Ltd., 2018 + * Email : code@zilogic.com + */ + +/* + * Testcase for statx syscall with AT_NO_AUTOMOUNT flag + * + * --Test Logic-- + * Configure a mount point for autofs. + * + * Spawn a new child process. + * + * statx() is invoked within the child process- + * With AT_NO_AUTOMOUNT flag- Child won't send any autofs notification + * message to parent. + * Without AT_NO_AUTOMOUNT flag- Child will send autofs notification + * message to parent, that can be read via pipe. + * + */ + +#include +#include +#include +#include +#include + +#include "tst_test.h" +#include "lapi/stat.h" + +#define MNTPOINT "mntpoint" + +static int autofs_fds[2] = {-1}; +static int ev_fd = -1; +static int mounted; +static int pipe_created; +static int mnt_dir_created; +static int ev_fd_created; + +static bool check_autofs_notification_msg(int autofs_read_fd, int ev_fd) +{ + int retval; + int max_fd; + fd_set rfds; + u_int64_t statx_status; + struct timeval tv; + bool notification_msg_status; + + max_fd = (autofs_read_fd > ev_fd) ? autofs_read_fd : ev_fd; + + FD_ZERO(&rfds); + FD_SET(autofs_read_fd, &rfds); + FD_SET(ev_fd, &rfds); + + tv.tv_sec = 5; + tv.tv_usec = 0; + + retval = select((max_fd + 1), &rfds, NULL, NULL, &tv); + if (retval == -1) + tst_brk(TBROK | TERRNO, "select() failed"); + + if (FD_ISSET(autofs_read_fd, &rfds)) + notification_msg_status = true; + else + notification_msg_status = false; + + if (FD_ISSET(ev_fd, &rfds)) { + SAFE_READ(0, ev_fd, &statx_status, sizeof(statx_status)); + if (statx_status == 1) + tst_brk(TBROK, "statx() failed"); + else if (statx_status == 2) + tst_res(TINFO, "statx() passed"); + } + + return notification_msg_status; +} + +void autofs_mount(int fd) +{ + char mnt_options[64]; + + SAFE_MKDIR(MNTPOINT, 0666); + mnt_dir_created = 1; + + snprintf(mnt_options, sizeof(mnt_options), + "fd=%i,minproto=5,maxproto=5,direct", fd); + + SAFE_MOUNT("ltp_test", MNTPOINT, "autofs", 0, mnt_options); + mounted = 1; +} + +static void autofs_run_test(bool automount) +{ + pid_t pid; + bool mnt_status; + u_int64_t value; + struct statx file_info; + + pid = SAFE_FORK(); + if (!pid) { + setpgrp(); + + TEST(statx(AT_FDCWD, MNTPOINT, + (automount) ? 0 : AT_NO_AUTOMOUNT, + 0, &file_info) + ); + + if (TST_RET == -1) { + /* 1 -> statx() fail*/ + value = 1; + SAFE_WRITE(1, ev_fd, &value, sizeof(value)); + + exit(1); + } + + /* 2 -> statx() pass*/ + value = 2; + SAFE_WRITE(1, ev_fd, &value, sizeof(value)); + + exit(0); + } + + mnt_status = check_autofs_notification_msg(autofs_fds[0], ev_fd); + if (automount == mnt_status) + tst_res(TPASS, "Mount Status: %d Expected Status: %d", + mnt_status, automount); + else + tst_brk(TFAIL, "Mount Status: %d Expected Status: %d", + mnt_status, automount); + + SAFE_KILL(pid, SIGKILL); + SAFE_WAITPID(pid, NULL, 0); +} + +static void setup(void) +{ + /* + * Need for eventfd()- + * To make the parent process aware that statx() has + * passed/failed in the child process. + */ + ev_fd = eventfd(0, O_NONBLOCK); + if (ev_fd == -1) + tst_brk(TBROK | TERRNO, "eventfd() failed"); + ev_fd_created = 1; + + SAFE_PIPE(autofs_fds); + pipe_created = 1; + + autofs_mount(autofs_fds[1]); +} + +static void cleanup(void) +{ + if (mounted) + SAFE_UMOUNT(MNTPOINT); + + if (mnt_dir_created) + SAFE_RMDIR(MNTPOINT); + + if (ev_fd_created) + SAFE_CLOSE(ev_fd); + + if (pipe_created) { + SAFE_CLOSE(autofs_fds[0]); + SAFE_CLOSE(autofs_fds[1]); + } +} + +const struct { + bool automount; +} tests[] = { {false}, + {true} }; + +static void test_controller(unsigned int tst_nr) +{ + bool automount = tests[tst_nr].automount; + + tst_res(TINFO, "statx(AT_FDCWD, %s, %s, 0, &file_info)", + MNTPOINT, (automount) ? "0" : "AT_NO_AUTOMOUNT"); + + autofs_run_test(automount); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tests), + .test = test_controller, + .needs_tmpdir = 1, + .forks_child = 1, + .needs_root = 1, + .setup = setup, + .cleanup = cleanup, +};