From patchwork Fri Nov 1 12:55:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1187997 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 (sender SPF authorized) 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 474MdH6jWCz9sPj for ; Fri, 1 Nov 2019 23:56:18 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4F1163C23EB for ; Fri, 1 Nov 2019 13:56:16 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 81E013C23FF for ; Fri, 1 Nov 2019 13:55:53 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id C80811000A28 for ; Fri, 1 Nov 2019 13:55:47 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.68,254,1569254400"; d="scan'208";a="77795790" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Nov 2019 20:55:39 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id D09294CE1508; Fri, 1 Nov 2019 20:47:38 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 1 Nov 2019 20:55:39 +0800 From: Yang Xu To: Date: Fri, 1 Nov 2019 20:55:55 +0800 Message-ID: <1572612959-20577-2-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20191031152646.GA7078@dell5510> <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: D09294CE1508.AD442 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/5] syscalls/quotactl01.c: Add Q_GETNEXQUOTA test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Q_GETNEXTQUOTA was introduced since linux 4.6, this operation is the same as Q_GETQUOTA, but it returns quota information for the next ID greater than or equal to id that has a quota set. Signed-off-by: Yang Xu Reviewed-by: Petr Vorel --- configure.ac | 1 + include/lapi/quotactl.h | 26 +++++---- m4/ltp-quota.m4 | 7 +++ .../kernel/syscalls/quotactl/quotactl01.c | 53 ++++++++++++++----- 4 files changed, 61 insertions(+), 26 deletions(-) create mode 100644 m4/ltp-quota.m4 diff --git a/configure.ac b/configure.ac index 62c5a0bb4..31999cd7a 100644 --- a/configure.ac +++ b/configure.ac @@ -248,6 +248,7 @@ AC_DEFINE_UNQUOTED(NUMA_ERROR_MSG, ["$numa_error_msg"], [Error message when no N LTP_CHECK_SYSCALL_PERF_EVENT_OPEN +LTP_CHECK_SYSCALL_QUOTACTL LTP_CHECK_SYSCALL_SIGNALFD LTP_CHECK_SYSCALL_UTIMENSAT LTP_CHECK_TASKSTATS diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h index 729472f69..afce865bc 100644 --- a/include/lapi/quotactl.h +++ b/include/lapi/quotactl.h @@ -1,26 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) 2017 Fujitsu Ltd. + * Copyright (c) 2017-2019 Fujitsu Ltd. * Author: Xiao Yang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * Author: Yang Xu */ #ifndef LAPI_QUOTACTL_H__ # define LAPI_QUOTACTL_H__ +#ifdef HAVE_STRUCT_IF_NEXTDQBLK +# include +#endif +#include + # ifndef Q_XGETNEXTQUOTA # define Q_XGETNEXTQUOTA XQM_CMD(9) # endif +# ifndef Q_GETNEXTQUOTA +# define Q_GETNEXTQUOTA 0x800009 /* get disk limits and usage >= ID */ +# endif + #endif /* LAPI_QUOTACTL_H__ */ diff --git a/m4/ltp-quota.m4 b/m4/ltp-quota.m4 new file mode 100644 index 000000000..e8d08c6b7 --- /dev/null +++ b/m4/ltp-quota.m4 @@ -0,0 +1,7 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2019 Fujitsu Ltd. +dnl Author: Yang Xu + +AC_DEFUN([LTP_CHECK_SYSCALL_QUOTACTL],[ +AC_CHECK_TYPES([struct if_nextdqblk],,,[#include ]) +]) diff --git a/testcases/kernel/syscalls/quotactl/quotactl01.c b/testcases/kernel/syscalls/quotactl/quotactl01.c index 2f563515d..7dda58417 100644 --- a/testcases/kernel/syscalls/quotactl/quotactl01.c +++ b/testcases/kernel/syscalls/quotactl/quotactl01.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Crackerjack Project., 2007 -* Copyright (c) 2016 Fujitsu Ltd. +* Copyright (c) 2016-2019 FUJITSU LIMITED. All rights reserved * Author: Xiao Yang * * This testcase checks the basic flag of quotactl(2) for non-XFS filesystems: @@ -16,19 +16,23 @@ * flag for user. * 6) quotactl(2) succeeds to get quota format with Q_GETFMT flag for user. * 7) quotactl(2) succeeds to update quota usages with Q_SYNC flag for user. -* 8) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for user. -* 9) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for group. -* 10) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag +* 8) quotactl(2) succeeds to get disk quota limit greater than or equal to +* ID with Q_GETNEXTSTAT flag for user. +* 9) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for user. +* 10) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for group. +* 11) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag * for group. -* 11) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag +* 12) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag * for group. -* 12) quotactl(2) succeeds to set information about quotafile with Q_SETINFO +* 13) quotactl(2) succeeds to set information about quotafile with Q_SETINFO * flag for group. -* 13) quotactl(2) succeeds to get information about quotafile with Q_GETINFO +* 14) quotactl(2) succeeds to get information about quotafile with Q_GETINFO * flag for group. -* 14) quotactl(2) succeeds to get quota format with Q_GETFMT flag for group. -* 15) quotactl(2) succeeds to update quota usages with Q_SYNC flag for group. -* 16) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for group. +* 15) quotactl(2) succeeds to get quota format with Q_GETFMT flag for group. +* 16) quotactl(2) succeeds to update quota usages with Q_SYNC flag for group. +* 17) quotactl(2) succeeds to get disk quota limit greater than or equal to +* ID with Q_GETNEXTSTAT flag for group. +* 18) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for group. */ #include "config.h" @@ -36,11 +40,13 @@ #include #include #include -#include +#include "lapi/quotactl.h" #include "tst_test.h" -#define QFMT_VFS_V0 2 +#ifndef QFMT_VFS_V0 +# define QFMT_VFS_V0 2 +#endif #define USRPATH MNTPOINT "/aquota.user" #define GRPPATH MNTPOINT "/aquota.group" #define FMTID QFMT_VFS_V0 @@ -61,6 +67,10 @@ static struct dqinfo set_qf = { static struct dqinfo res_qf; static int32_t fmt_buf; +#if defined(HAVE_STRUCT_IF_NEXTDQBLK) +static struct if_nextdqblk res_ndq; +#endif + static struct tcase { int cmd; int *id; @@ -94,6 +104,12 @@ static struct tcase { {QCMD(Q_SYNC, USRQUOTA), &test_id, &res_dq, NULL, NULL, 0, "update quota usages for user"}, +#if defined(HAVE_STRUCT_IF_NEXTDQBLK) + {QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_id, &res_ndq, + &test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id), + "get next disk quota limit for user"}, +#endif + {QCMD(Q_QUOTAOFF, USRQUOTA), &test_id, USRPATH, NULL, NULL, 0, "turn off quota for user"}, @@ -120,6 +136,12 @@ static struct tcase { {QCMD(Q_SYNC, GRPQUOTA), &test_id, &res_dq, NULL, NULL, 0, "update quota usages for group"}, +#if defined(HAVE_STRUCT_IF_NEXTDQBLK) + {QCMD(Q_GETNEXTQUOTA, GRPQUOTA), &test_id, &res_ndq, + &test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id), + "get next disk quota limit for group"}, +#endif + {QCMD(Q_QUOTAOFF, GRPQUOTA), &test_id, GRPPATH, NULL, NULL, 0, "turn off quota for group"} }; @@ -155,8 +177,15 @@ static void verify_quota(unsigned int n) res_dq.dqb_bsoftlimit = 0; res_qf.dqi_igrace = 0; fmt_buf = 0; +#if defined(HAVE_STRUCT_IF_NEXTDQBLK) + res_ndq.dqb_id = -1; +#endif TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr)); + if (TST_ERR == EINVAL) { + tst_res(TCONF, "Current system doesn't support this cmd"); + return; + } if (TST_RET == -1) { tst_res(TFAIL | TTERRNO, "quotactl failed to %s", tc->des); return; From patchwork Fri Nov 1 12:55:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1187999 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 (sender SPF authorized) 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 474Mdd49cxz9sPj for ; Fri, 1 Nov 2019 23:56:37 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BDA6B3C2405 for ; Fri, 1 Nov 2019 13:56:34 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 3BE0D3C2420 for ; Fri, 1 Nov 2019 13:55:57 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id 716CA602297 for ; Fri, 1 Nov 2019 13:55:52 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.68,254,1569254400"; d="scan'208";a="77795794" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Nov 2019 20:55:45 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 79E0C41B7076; Fri, 1 Nov 2019 20:47:41 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 1 Nov 2019 20:55:41 +0800 From: Yang Xu To: Date: Fri, 1 Nov 2019 20:55:56 +0800 Message-ID: <1572612959-20577-3-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20191031152646.GA7078@dell5510> <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 79E0C41B7076.AD8F1 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v3 2/5] syscalls/quotactl02.c: Add Q_XGETQSTATV test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Q_XGETQSTATV returns XFS filesystem-specific quota information in the fs_quota_statv pointed to by addr. The qs_version field of the structure should be filled with the version of the structure supported by the caller (for now, only FS_QSTAT_VERSION1 is supported). Signed-off-by: Yang Xu Reviewed-by: Petr Vorel --- include/lapi/quotactl.h | 4 + m4/ltp-quota.m4 | 1 + .../kernel/syscalls/quotactl/quotactl02.c | 193 +++++++----------- .../kernel/syscalls/quotactl/quotactl02.h | 152 ++++++++++++++ 4 files changed, 236 insertions(+), 114 deletions(-) create mode 100644 testcases/kernel/syscalls/quotactl/quotactl02.h diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h index afce865bc..787f4691e 100644 --- a/include/lapi/quotactl.h +++ b/include/lapi/quotactl.h @@ -13,6 +13,10 @@ #endif #include +# ifndef Q_XGETQSTATV +# define Q_XGETQSTATV XQM_CMD(8) +# endif + # ifndef Q_XGETNEXTQUOTA # define Q_XGETNEXTQUOTA XQM_CMD(9) # endif diff --git a/m4/ltp-quota.m4 b/m4/ltp-quota.m4 index e8d08c6b7..bcdff7041 100644 --- a/m4/ltp-quota.m4 +++ b/m4/ltp-quota.m4 @@ -4,4 +4,5 @@ dnl Author: Yang Xu AC_DEFUN([LTP_CHECK_SYSCALL_QUOTACTL],[ AC_CHECK_TYPES([struct if_nextdqblk],,,[#include ]) +AC_CHECK_TYPES([struct fs_quota_statv],,,[#include ]) ]) diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c index edba84391..a3703d79b 100644 --- a/testcases/kernel/syscalls/quotactl/quotactl02.c +++ b/testcases/kernel/syscalls/quotactl/quotactl02.c @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) 2013 Fujitsu Ltd. + * Copyright (c) 2013-2019 FUJITSU LIMITED. All rights reserved * Author: DAN LI + * Author: Yang Xu */ /* @@ -9,132 +10,98 @@ * * Description: * This testcase checks basic flags of quotactl(2) for an XFS file system: - * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status. - * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status. + * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status + * for user. + * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status + * for usr. * 3) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota - * limits. + * limits for user. * 4) quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk - * quota limits. + * quota limits greater than or equal to ID for user. + * 5) quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv + * for user. + * 6) quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv + * for user. + * 7) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status + * for group. + * 8) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status + * for group. + * 9) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota + * limits for group. + * 10)quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk + * quota limits for group. + * 11)quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv + * for group. + * 12)quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv + * for group. */ -#define _GNU_SOURCE -#include "config.h" -#include -#include -#include -#include -#include "tst_test.h" -#include "lapi/quotactl.h" +#include "quotactl02.h" #ifdef HAVE_XFS_XQM_H -# include - -static void check_qoff(int, char *); -static void check_qon(int, char *); -static void check_qlim(int, char *); - -static uint32_t test_id; -static struct fs_disk_quota set_dquota = { - .d_rtb_softlimit = 1000, - .d_fieldmask = FS_DQ_RTBSOFT -}; -static uint32_t qflag = XFS_QUOTA_UDQ_ENFD; -static const char mntpoint[] = "mnt_point"; +static uint32_t qflagu = XFS_QUOTA_UDQ_ENFD; +static uint32_t qflagg = XFS_QUOTA_GDQ_ENFD; static struct t_case { int cmd; void *addr; void (*func_check)(); int check_subcmd; + int flag; char *des; } tcases[] = { - {QCMD(Q_XQUOTAOFF, USRQUOTA), &qflag, check_qoff, Q_XGETQSTAT, - "turn off xfs quota and get xfs quota off status"}, - {QCMD(Q_XQUOTAON, USRQUOTA), &qflag, check_qon, Q_XGETQSTAT, - "turn on xfs quota and get xfs quota on status"}, - {QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, Q_XGETQUOTA, - "Q_XGETQUOTA"}, - {QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, Q_XGETNEXTQUOTA, - "Q_XGETNEXTQUOTA"}, -}; - -static void check_qoff(int subcmd, char *desp) -{ - int res; - struct fs_quota_stat res_qstat; - - res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev, test_id, - (void *) &res_qstat); - if (res == -1) { - tst_res(TFAIL | TERRNO, - "quotactl() failed to get xfs quota off status"); - return; - } - - if (res_qstat.qs_flags & XFS_QUOTA_UDQ_ENFD) { - tst_res(TFAIL, "xfs quota enforcement was on unexpectedly"); - return; - } - - tst_res(TPASS, "quoactl() succeeded to %s", desp); -} - -static void check_qon(int subcmd, char *desp) -{ - int res; - struct fs_quota_stat res_qstat; - - res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev, - test_id, (void *) &res_qstat); - if (res == -1) { - tst_res(TFAIL | TERRNO, - "quotactl() failed to get xfs quota on status"); - return; - } + {QCMD(Q_XQUOTAOFF, USRQUOTA), &qflagu, check_qoff, + QCMD(Q_XGETQSTAT, USRQUOTA), 1, + "turn off xfs quota and get xfs quota off status for user"}, + + {QCMD(Q_XQUOTAON, USRQUOTA), &qflagu, check_qon, + QCMD(Q_XGETQSTAT, USRQUOTA), 1, + "turn on xfs quota and get xfs quota on status for user"}, + + {QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, + QCMD(Q_XGETQUOTA, USRQUOTA), 0, + "Q_XGETQUOTA for user"}, + + {QCMD(Q_XSETQLIM, USRQUOTA), &set_dquota, check_qlim, + QCMD(Q_XGETNEXTQUOTA, USRQUOTA), 0, + "Q_XGETNEXTQUOTA for user"}, + +#if defined(HAVE_STRUCT_FS_QUOTA_STATV) + {QCMD(Q_XQUOTAOFF, USRQUOTA), &qflagu, check_qoffv, + QCMD(Q_XGETQSTATV, USRQUOTA), 1, + "turn off xfs quota and get xfs quota off statv for user"}, + + {QCMD(Q_XQUOTAON, USRQUOTA), &qflagu, check_qonv, + QCMD(Q_XGETQSTATV, USRQUOTA), 1, + "turn on xfs quota and get xfs quota on statv for user"}, +#endif - if (!(res_qstat.qs_flags & XFS_QUOTA_UDQ_ENFD)) { - tst_res(TFAIL, "xfs quota enforcement was off unexpectedly"); - return; - } + {QCMD(Q_XQUOTAOFF, GRPQUOTA), &qflagg, check_qoff, + QCMD(Q_XGETQSTAT, GRPQUOTA), 1, + "turn off xfs quota and get xfs quota off status for group"}, - tst_res(TPASS, "quoactl() succeeded to %s", desp); -} + {QCMD(Q_XQUOTAON, GRPQUOTA), &qflagg, check_qon, + QCMD(Q_XGETQSTAT, GRPQUOTA), 1, + "turn on xfs quota and get xfs quota on status for group"}, -static void check_qlim(int subcmd, char *desp) -{ - int res; - static struct fs_disk_quota res_dquota; - - res_dquota.d_rtb_softlimit = 0; - - res = quotactl(QCMD(subcmd, USRQUOTA), tst_device->dev, - test_id, (void *) &res_dquota); - if (res == -1) { - if (errno == EINVAL) { - tst_brk(TCONF | TERRNO, - "%s wasn't supported in quotactl()", desp); - } - tst_res(TFAIL | TERRNO, - "quotactl() failed to get xfs disk quota limits"); - return; - } + {QCMD(Q_XSETQLIM, GRPQUOTA), &set_dquota, check_qlim, + QCMD(Q_XGETQUOTA, GRPQUOTA), 0, + "Q_XGETQUOTA for group"}, - if (res_dquota.d_id != test_id) { - tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u", - res_dquota.d_id, test_id); - return; - } + {QCMD(Q_XSETQLIM, GRPQUOTA), &set_dquota, check_qlim, + QCMD(Q_XGETNEXTQUOTA, GRPQUOTA), 0, + "Q_XGETNEXTQUOTA for group"}, - if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) { - tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu, expected %llu", - res_dquota.d_rtb_hardlimit, - set_dquota.d_rtb_hardlimit); - return; - } +#if defined(HAVE_STRUCT_FS_QUOTA_STATV) + {QCMD(Q_XQUOTAOFF, GRPQUOTA), &qflagg, check_qoffv, + QCMD(Q_XGETQSTATV, GRPQUOTA), 1, + "turn off xfs quota and get xfs quota off statv for group"}, - tst_res(TPASS, "quoactl() succeeded to set and use %s to get xfs disk quota limits", - desp); -} + {QCMD(Q_XQUOTAON, GRPQUOTA), &qflagg, check_qonv, + QCMD(Q_XGETQSTATV, GRPQUOTA), 1, + "turn on xfs quota and get xfs quota on statv for group"}, +#endif +}; static void setup(void) { @@ -151,14 +118,12 @@ static void verify_quota(unsigned int n) return; } - tc->func_check(tc->check_subcmd, tc->des); + if (tc->flag) + tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr)); + else + tc->func_check(tc->check_subcmd, tc->des); } -static const char *kconfigs[] = { - "CONFIG_XFS_QUOTA", - NULL -}; - static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, @@ -168,7 +133,7 @@ static struct tst_test test = { .mount_device = 1, .dev_fs_type = "xfs", .mntpoint = mntpoint, - .mnt_data = "usrquota", + .mnt_data = "usrquota,grpquota", .setup = setup, }; #else diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.h b/testcases/kernel/syscalls/quotactl/quotactl02.h new file mode 100644 index 000000000..c96cdc3e4 --- /dev/null +++ b/testcases/kernel/syscalls/quotactl/quotactl02.h @@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +#ifndef QUOTACTL02_H +#define QUOTACTL02_H + +#define _GNU_SOURCE +#include "config.h" +#include +#include +#include +#include "tst_test.h" +#include "lapi/quotactl.h" + +#ifdef HAVE_XFS_XQM_H +# include + +static struct fs_disk_quota set_dquota = { + .d_rtb_softlimit = 1000, + .d_fieldmask = FS_DQ_RTBSOFT +}; +static uint32_t test_id; +static const char mntpoint[] = "mnt_point"; +static const char *kconfigs[] = { + "CONFIG_XFS_QUOTA", + NULL +}; +void check_qoff(int subcmd, char *desp, int flag) +{ + int res; + struct fs_quota_stat res_qstat; + + res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstat); + if (res == -1) { + tst_res(TFAIL | TERRNO, + "quotactl() failed to get xfs quota off status"); + return; + } + + if (res_qstat.qs_flags & flag) { + tst_res(TFAIL, "xfs quota enforcement was on unexpectedly"); + return; + } + + tst_res(TPASS, "quoactl() succeeded to %s", desp); +} + +void check_qon(int subcmd, char *desp, int flag) +{ + int res; + struct fs_quota_stat res_qstat; + + res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstat); + if (res == -1) { + tst_res(TFAIL | TERRNO, + "quotactl() failed to get xfs quota on status"); + return; + } + + if (!(res_qstat.qs_flags & flag)) { + tst_res(TFAIL, "xfs quota enforcement was off unexpectedly"); + return; + } + + tst_res(TPASS, "quoactl() succeeded to %s", desp); +} + +#if defined(HAVE_STRUCT_FS_QUOTA_STATV) +void check_qoffv(int subcmd, char *desp, int flag) +{ + int res; + struct fs_quota_statv res_qstatv = { + .qs_version = FS_QSTATV_VERSION1, + }; + + res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv); + if (res == -1) { + tst_res(TFAIL | TERRNO, + "quotactl() failed to get xfs quota off stav"); + return; + } + + if (res_qstatv.qs_flags & flag) { + tst_res(TFAIL, "xfs quota enforcement was on unexpectedly"); + return; + } + + tst_res(TPASS, "quoactl() succeeded to %s", desp); +} + +void check_qonv(int subcmd, char *desp, int flag) +{ + int res; + struct fs_quota_statv res_qstatv = { + .qs_version = FS_QSTATV_VERSION1 + }; + + res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv); + if (res == -1) { + tst_res(TFAIL | TERRNO, + "quotactl() failed to get xfs quota on statv"); + return; + } + + if (!(res_qstatv.qs_flags & flag)) { + tst_res(TFAIL, "xfs quota enforcement was off unexpectedly"); + return; + } + + tst_res(TPASS, "quoactl() succeeded to %s", desp); +} +#endif + +void check_qlim(int subcmd, char *desp) +{ + int res; + static struct fs_disk_quota res_dquota; + + res_dquota.d_rtb_softlimit = 0; + + res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_dquota); + if (res == -1) { + if (errno == EINVAL) { + tst_res(TCONF, + "%s wasn't supported in quotactl()", desp); + } else { + tst_res(TFAIL | TERRNO, + "quotactl() failed to get xfs disk quota limits"); + } + return; + } + + if (res_dquota.d_id != test_id) { + tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u", + res_dquota.d_id, test_id); + return; + } + + if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) { + tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu, expected %llu", + res_dquota.d_rtb_hardlimit, set_dquota.d_rtb_hardlimit); + return; + } + + tst_res(TPASS, "quoactl() succeeded to set and use %s to get xfs disk quota limits", + desp); +} +#endif//HAVE_XFS_XQM_H +#endif From patchwork Fri Nov 1 12:55:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1187996 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 (sender SPF authorized) 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 474MdD38b2z9sPj for ; Fri, 1 Nov 2019 23:56:09 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E4AD63C23FA for ; Fri, 1 Nov 2019 13:56:06 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 1358F3C23FA for ; Fri, 1 Nov 2019 13:55:53 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id B14711400524 for ; Fri, 1 Nov 2019 13:55:51 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.68,254,1569254400"; d="scan'208";a="77795795" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Nov 2019 20:55:45 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id A00534CE1508; Fri, 1 Nov 2019 20:47:43 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 1 Nov 2019 20:55:43 +0800 From: Yang Xu To: Date: Fri, 1 Nov 2019 20:55:57 +0800 Message-ID: <1572612959-20577-4-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20191031152646.GA7078@dell5510> <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: A00534CE1508.AAC76 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 3/5] syscalls/quotactl04: add project quota test for non-xfs filesystem X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This is a variant about quotactl01. It is used to test project quota. I split it into a new case instead of adding it in quotaclt01 because two points: 1)before linux 4.10, ext4 doesn't support project quota 2)on old kernel, kernel doesn't permit mount both prjquota and grpquota together Signed-off-by: Yang Xu --- include/lapi/quotactl.h | 4 + runtest/syscalls | 1 + testcases/kernel/syscalls/quotactl/.gitignore | 1 + .../kernel/syscalls/quotactl/quotactl04.c | 155 ++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 testcases/kernel/syscalls/quotactl/quotactl04.c diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h index 787f4691e..b9ab54483 100644 --- a/include/lapi/quotactl.h +++ b/include/lapi/quotactl.h @@ -13,6 +13,10 @@ #endif #include +#ifndef PRJQUOTA +# define PRJQUOTA 2 +#endif + # ifndef Q_XGETQSTATV # define Q_XGETQSTATV XQM_CMD(8) # endif diff --git a/runtest/syscalls b/runtest/syscalls index 12d3e0d3b..c30e9e620 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -953,6 +953,7 @@ pwritev202_64 pwritev202_64 quotactl01 quotactl01 quotactl02 quotactl02 quotactl03 quotactl03 +quotactl04 quotactl04 read01 read01 read02 read02 diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore index b0ef075e7..1db7c5d98 100644 --- a/testcases/kernel/syscalls/quotactl/.gitignore +++ b/testcases/kernel/syscalls/quotactl/.gitignore @@ -1,3 +1,4 @@ /quotactl01 /quotactl02 /quotactl03 +/quotactl04 diff --git a/testcases/kernel/syscalls/quotactl/quotactl04.c b/testcases/kernel/syscalls/quotactl/quotactl04.c new file mode 100644 index 000000000..25ab016cf --- /dev/null +++ b/testcases/kernel/syscalls/quotactl/quotactl04.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * This testcase checks the basic flag of quotactl(2) for project quota on + * non-XFS filesystems. + * + * 1) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for project. + * 2) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag + * for project. + * 3) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag + * for project. + * 4) quotactl(2) succeeds to set information about quotafile with Q_SETINFO + * flag for project. + * 5) quotactl(2) succeeds to get information about quotafile with Q_GETINFO + * flag for project. + * 6) quotactl(2) succeeds to get quota format with Q_GETFMT flag for project. + * 7) quotactl(2) succeeds to get disk quota limit greater than or equal to + * ID with Q_GETNEXTQUOTA flag for project. + * 8) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for project. + */ + +#include +#include +#include +#include +#include +#include "config.h" +#include "lapi/quotactl.h" +#include "tst_test.h" + +#ifndef QFMT_VFS_V1 +# define QFMT_VFS_V1 4 +#endif +#define FMTID QFMT_VFS_V1 +#define MNTPOINT "mntpoint" +static int32_t fmt_id = FMTID; +static int test_id, mount_flag; +static struct dqblk set_dq = { + .dqb_bsoftlimit = 100, + .dqb_valid = QIF_BLIMITS +}; +static struct dqblk res_dq; +static struct dqinfo set_qf = { + .dqi_bgrace = 80, + .dqi_valid = IIF_BGRACE +}; + +static struct dqinfo res_qf; +static int32_t fmt_buf; + +#if defined(HAVE_STRUCT_IF_NEXTDQBLK) +static struct if_nextdqblk res_ndq; +#endif + +static struct tcase { + int cmd; + int *id; + void *addr; + void *set_data; + void *res_data; + int sz; + char *des; +} tcases[] = { + {QCMD(Q_QUOTAON, PRJQUOTA), &fmt_id, NULL, + NULL, NULL, 0, "turn on quota for project"}, + + {QCMD(Q_SETQUOTA, PRJQUOTA), &test_id, &set_dq, + NULL, NULL, 0, "set disk quota limit for project"}, + + {QCMD(Q_GETQUOTA, PRJQUOTA), &test_id, &res_dq, + &set_dq.dqb_bsoftlimit, &res_dq.dqb_bsoftlimit, + sizeof(res_dq.dqb_bsoftlimit), "get disk quota limit for project"}, + + {QCMD(Q_SETINFO, PRJQUOTA), &test_id, &set_qf, + NULL, NULL, 0, "set information about quotafile for project"}, + + {QCMD(Q_GETINFO, PRJQUOTA), &test_id, &res_qf, + &set_qf.dqi_bgrace, &res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace), + "get information about quotafile for project"}, + + {QCMD(Q_GETFMT, PRJQUOTA), &test_id, &fmt_buf, + &fmt_id, &fmt_buf, sizeof(fmt_buf), + "get quota format for project"}, + +#if defined(HAVE_STRUCT_IF_NEXTDQBLK) + {QCMD(Q_GETNEXTQUOTA, PRJQUOTA), &test_id, &res_ndq, + &test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id), + "get next disk quota limit for project"}, +#endif + + {QCMD(Q_QUOTAOFF, PRJQUOTA), &test_id, NULL, + NULL, NULL, 0, "turn off quota for project"}, + +}; + +static void setup(void) +{ + const char *const extra_opts[] = {"-O quota,project", NULL}; + + test_id = geteuid(); + SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, extra_opts); + SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "quota"); + mount_flag = 1; +} + +static void cleanup(void) +{ + if (mount_flag && tst_umount(MNTPOINT)) + tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT); +} + +static void verify_quota(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + + res_dq.dqb_bsoftlimit = 0; + res_qf.dqi_igrace = 0; + fmt_buf = 0; + + TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "quotactl failed to %s", tc->des); + return; + } + + if (memcmp(tc->res_data, tc->set_data, tc->sz)) { + tst_res(TFAIL, "quotactl failed to %s", tc->des); + tst_res_hexd(TINFO, tc->res_data, tc->sz, "retval: "); + tst_res_hexd(TINFO, tc->set_data, tc->sz, "expected: "); + return; + } + + tst_res(TPASS, "quotactl succeeded to %s", tc->des); +} + +static const char *kconfigs[] = { + "CONFIG_QFMT_V2", + NULL +}; + +static struct tst_test test = { + .needs_tmpdir = 1, + .needs_root = 1, + .needs_kconfigs = kconfigs, + .min_kver = "4.10", /* commit 689c958cbe6b (ext4: add project quota support) */ + .test = verify_quota, + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .needs_device = 1, + .dev_fs_type = "ext4", + .mntpoint = MNTPOINT, +}; From patchwork Fri Nov 1 12:55:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1187995 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 (sender SPF authorized) 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 474Md0089yz9sPj for ; Fri, 1 Nov 2019 23:56:02 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B13DB3C2419 for ; Fri, 1 Nov 2019 13:55:58 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id D5B1C3C23F1 for ; Fri, 1 Nov 2019 13:55:50 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 8F2851400524 for ; Fri, 1 Nov 2019 13:55:49 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.68,254,1569254400"; d="scan'208";a="77795797" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Nov 2019 20:55:45 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 558764CE1514; Fri, 1 Nov 2019 20:47:45 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 1 Nov 2019 20:55:45 +0800 From: Yang Xu To: Date: Fri, 1 Nov 2019 20:55:58 +0800 Message-ID: <1572612959-20577-5-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20191031152646.GA7078@dell5510> <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: 558764CE1514.AACED X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 4/5] syscalls/quotactl05: add project quota test for xfs filesystem X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This is a variant about quotactl02. It is used to test project quota. I split it into a new case instead of adding it in quotaclt02 because kernel doesn't permit mount both group and project quota before commit d892d5864f02 ("xfs: Start using pquotaino from the superblock."). Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/quotactl/.gitignore | 2 + .../kernel/syscalls/quotactl/quotactl05.c | 99 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 testcases/kernel/syscalls/quotactl/quotactl05.c diff --git a/runtest/syscalls b/runtest/syscalls index c30e9e620..f2c7b0daf 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -954,6 +954,7 @@ quotactl01 quotactl01 quotactl02 quotactl02 quotactl03 quotactl03 quotactl04 quotactl04 +quotactl05 quotactl05 read01 read01 read02 read02 diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore index 1db7c5d98..9621e7717 100644 --- a/testcases/kernel/syscalls/quotactl/.gitignore +++ b/testcases/kernel/syscalls/quotactl/.gitignore @@ -2,3 +2,5 @@ /quotactl02 /quotactl03 /quotactl04 +/quotactl05 + diff --git a/testcases/kernel/syscalls/quotactl/quotactl05.c b/testcases/kernel/syscalls/quotactl/quotactl05.c new file mode 100644 index 000000000..2c4f49f7c --- /dev/null +++ b/testcases/kernel/syscalls/quotactl/quotactl05.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * Test Name: quotactl05 + * + * Description: + * This testcase checks basic flags of quotactl(2) for project on an XFS file + * system: + * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status + * for project. + * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status + * for project. + * 3) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota + * limits for project. + * 4) quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk + * quota limits Cgreater than or equal to ID for project. + * 5) quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv + * for project. + * 6) quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv + * for project. + */ +#include "quotactl02.h" +#if defined(HAVE_XFS_XQM_H) + +static uint32_t qflagp = XFS_QUOTA_PDQ_ENFD; +static struct t_case { + int cmd; + void *addr; + void (*func_check)(); + int check_subcmd; + int flag; + char *des; +} tcases[] = { + {QCMD(Q_XQUOTAOFF, PRJQUOTA), &qflagp, check_qoff, + QCMD(Q_XGETQSTAT, PRJQUOTA), 1, + "turn off xfs quota and get xfs quota off status for project"}, + + {QCMD(Q_XQUOTAON, PRJQUOTA), &qflagp, check_qon, + QCMD(Q_XGETQSTAT, PRJQUOTA), 1, + "turn on xfs quota and get xfs quota on status for project"}, + + {QCMD(Q_XSETQLIM, PRJQUOTA), &set_dquota, check_qlim, + QCMD(Q_XGETQUOTA, PRJQUOTA), 0, + "Q_XGETQUOTA for project"}, + + {QCMD(Q_XSETQLIM, PRJQUOTA), &set_dquota, check_qlim, + QCMD(Q_XGETNEXTQUOTA, PRJQUOTA), 0, + "Q_XGETNEXTQUOTA for project"}, + +#if defined(HAVE_STRUCT_FS_QUOTA_STATV) + {QCMD(Q_XQUOTAOFF, PRJQUOTA), &qflagp, check_qoffv, + QCMD(Q_XGETQSTATV, PRJQUOTA), 1, + "turn off xfs quota and get xfs quota off statv for project"}, + + {QCMD(Q_XQUOTAON, PRJQUOTA), &qflagp, check_qonv, + QCMD(Q_XGETQSTATV, PRJQUOTA), 1, + "turn on xfs quota and get xfs quota on statv for project"}, +#endif +}; + +static void setup(void) +{ + test_id = geteuid(); +} + +static void verify_quota(unsigned int n) +{ + struct t_case *tc = &tcases[n]; + + TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des); + return; + } + + if (tc->flag) + tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr)); + else + tc->func_check(tc->check_subcmd, tc->des); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .needs_root = 1, + .needs_kconfigs = kconfigs, + .test = verify_quota, + .tcnt = ARRAY_SIZE(tcases), + .mount_device = 1, + .dev_fs_type = "xfs", + .mntpoint = mntpoint, + .mnt_data = "prjquota", + .setup = setup, +}; + +#else + TST_TEST_TCONF("This system didn't have "); +#endif From patchwork Fri Nov 1 12:55:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1187998 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 (sender SPF authorized) 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 474MdT60Qlz9sPj for ; Fri, 1 Nov 2019 23:56:29 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AC5153C240E for ; Fri, 1 Nov 2019 13:56:26 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 33F5E3C2420 for ; Fri, 1 Nov 2019 13:55:57 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id E288E1400536 for ; Fri, 1 Nov 2019 13:55:53 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.68,254,1569254400"; d="scan'208";a="77795801" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 01 Nov 2019 20:55:51 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id C5C9841B7076; Fri, 1 Nov 2019 20:47:46 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 1 Nov 2019 20:55:47 +0800 From: Yang Xu To: Date: Fri, 1 Nov 2019 20:55:59 +0800 Message-ID: <1572612959-20577-6-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20191031152646.GA7078@dell5510> <1572612959-20577-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-yoursite-MailScanner-ID: C5C9841B7076.ADEFC X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v3 5/5] syscalls/quotactl06: Add new testcase X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check various errnos for the quotactl(). Signed-off-by: Yang Xu --- runtest/syscalls | 1 + testcases/kernel/syscalls/quotactl/.gitignore | 1 + .../kernel/syscalls/quotactl/quotactl06.c | 183 ++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 testcases/kernel/syscalls/quotactl/quotactl06.c diff --git a/runtest/syscalls b/runtest/syscalls index f2c7b0daf..93b7a3f78 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -955,6 +955,7 @@ quotactl02 quotactl02 quotactl03 quotactl03 quotactl04 quotactl04 quotactl05 quotactl05 +quotactl06 quotactl06 read01 read01 read02 read02 diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore index 9621e7717..b9a015654 100644 --- a/testcases/kernel/syscalls/quotactl/.gitignore +++ b/testcases/kernel/syscalls/quotactl/.gitignore @@ -3,4 +3,5 @@ /quotactl03 /quotactl04 /quotactl05 +/quotactl06 diff --git a/testcases/kernel/syscalls/quotactl/quotactl06.c b/testcases/kernel/syscalls/quotactl/quotactl06.c new file mode 100644 index 000000000..9c98bfde7 --- /dev/null +++ b/testcases/kernel/syscalls/quotactl/quotactl06.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + * + * Tests basic error handling of the quotactl syscall. + * Description: + * 1) quotactl fails with EACCES when cmd is Q_QUOTAON and addr + * existed but not a regular file. + * 2) quotaclt fails with ENOENT when the file specified by special + * or addr does not exist. + * 3) quotactl fails with EBUSTY when cmd is Q_QUOTAON and another + * Q_QUOTAON had already been performed. + * 4) quotactl fails with EFAULT when addr or special is invalid. + * 5) quotactl fails with EINVAL when cmd or type is invalid. + * 6) quotactl fails with ENOTBLK when special is not a block device. + * 7) quotactl fails with ESRCH when no disk quota is found for the + * indicated user and quotas have not been turned on for this fs. + * 8) quotactl fails with ESRCH when cmd is Q_QUOTAON, but the quota + * format was not found. + * 9) quotactl fails with ESRCH when cmd is Q_GETNEXTQUOTA, but there + * is no ID greater than or equal to id that has an active quota. + * 10) quotactl fails with ERANGE when cmd is Q_SETQUOTA, but the + * specified limits are out of the range allowed by the quota format. + * 11) quotactl fails with EPERM when the caller lacked the required + * privilege (CAP_SYS_ADMIN) for the specified operation. + */ +#include +#include +#include "tst_test.h" +#include "lapi/quotactl.h" +#include "tst_capability.h" + +#define OPTION_INVALID 999 +#define QFMT_VFS_V0 2 +#define USRPATH MNTPOINT "/aquota.user" +#define FMTID QFMT_VFS_V0 + +#define MNTPOINT "mntpoint" +#define TESTDIR1 MNTPOINT "/testdir1" +#define TESTDIR2 MNTPOINT "/testdir2" + +static int32_t fmt_id = FMTID; +static int32_t fmt_invalid = 999; +static int test_invalid; +static int test_id; +static struct dqblk set_dq = { + .dqb_bsoftlimit = 100, + .dqb_valid = QIF_BLIMITS +}; + +static struct dqblk set_dqmax = { + .dqb_bsoftlimit = 0x7fffffffffffffffLL, /* 2^63-1 */ + .dqb_valid = QIF_BLIMITS +}; + +struct tst_cap dropadmin = { + .action = TST_CAP_DROP, + .id = CAP_SYS_ADMIN, + .name = "CAP_SYS_ADMIN", +}; + +struct tst_cap needadmin = { + .action = TST_CAP_REQ, + .id = CAP_SYS_ADMIN, + .name = "CAP_SYS_ADMIN", +}; + +static struct tcase { + int cmd; + int *id; + void *addr; + int exp_err; + int on_flag; +} tcases[] = { + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, TESTDIR1, EACCES, 0 }, + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, TESTDIR2, ENOENT, 0}, + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, USRPATH, EBUSY, 1}, + {QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1}, + {QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, USRPATH, EINVAL, 0}, + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, USRPATH, ENOTBLK, 0}, + {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0}, + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, USRPATH, ESRCH, 0}, + {QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, USRPATH, ESRCH, 0}, + {QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1}, + {QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, USRPATH, EPERM, 0}, +}; + +static void verify_quotactl(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + int quota_on = 0; + int drop_flag = 0; + + if (!tc->addr) + tc->addr = tst_get_bad_addr(NULL); + if (tc->on_flag) { + TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev, FMTID, USRPATH)); + if (TST_RET == -1) + tst_brk(TBROK, + "quotactl with Q_QUOTAON returned %ld", TST_RET); + quota_on = 1; + } + + if (tc->exp_err == EPERM) { + tst_cap_action(&dropadmin); + drop_flag = 1; + } + + if (tc->exp_err == ENOTBLK) + TEST(quotactl(tc->cmd, "/dev/null", *tc->id, tc->addr)); + else + TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr)); + if (TST_RET == -1) { + if (tc->exp_err == TST_ERR) { + tst_res(TPASS | TTERRNO, + "quotactl failed as expected"); + } else if (*tc->id == test_invalid && tc->exp_err == EINVAL) { + tst_res(TFAIL, + "quotactl Q_GETNEXTQUOTA option is not supported."); + } else { + tst_res(TFAIL | TTERRNO, + "quotactl failed unexpectedly; expected %s, but got", + tst_strerrno(tc->exp_err)); + } + } else { + tst_res(TFAIL, "quotactl returned wrong value: %ld", TST_RET); + } + + if (quota_on) { + TEST(quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev, FMTID, USRPATH)); + if (TST_RET == -1) + tst_brk(TBROK, + "quotactl with Q_QUOTAOFF returned %ld", TST_RET); + quota_on = 0; + } + + if (drop_flag) { + tst_cap_action(&needadmin); + drop_flag = 0; + } +} + +static void setup(void) +{ + const char *const cmd[] = {"quotacheck", "-uF", "vfsv0", MNTPOINT, NULL}; + int ret; + + ret = tst_run_cmd(cmd, NULL, NULL, 1); + switch (ret) { + case 0: + break; + case 255: + tst_brk(TBROK, "quotacheck binary not installed"); + break; + default: + tst_brk(TBROK, "quotacheck exited with %i", ret); + } + + if (access(USRPATH, F_OK) == -1) + tst_brk(TFAIL | TERRNO, "user quotafile didn't exist"); + + SAFE_MKDIR(TESTDIR1, 0666); + test_id = geteuid(); + test_invalid = test_id + 1; +} + +static const char *kconfigs[] = { + "CONFIG_QFMT_V2", + NULL +}; + +static struct tst_test test = { + .setup = setup, + .needs_kconfigs = kconfigs, + .tcnt = ARRAY_SIZE(tcases), + .test = verify_quotactl, + .dev_fs_type = "ext4", + .mntpoint = MNTPOINT, + .mount_device = 1, + .mnt_data = "usrquota", + .needs_root = 1, +};