1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. 4f08c3bdfSopenharmony_ci * Author: Yang Xu <xuyang2018.jy@fujitsu.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci#ifndef QUOTACTL02_H 8f08c3bdfSopenharmony_ci#define QUOTACTL02_H 9f08c3bdfSopenharmony_ci 10f08c3bdfSopenharmony_ci#define _GNU_SOURCE 11f08c3bdfSopenharmony_ci#include <errno.h> 12f08c3bdfSopenharmony_ci#include <unistd.h> 13f08c3bdfSopenharmony_ci#include <stdio.h> 14f08c3bdfSopenharmony_ci#include "tst_test.h" 15f08c3bdfSopenharmony_ci#include "quotactl_syscall_var.h" 16f08c3bdfSopenharmony_ci 17f08c3bdfSopenharmony_ci#ifdef HAVE_XFS_XQM_H 18f08c3bdfSopenharmony_ci# include <xfs/xqm.h> 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic struct fs_disk_quota set_dquota = { 21f08c3bdfSopenharmony_ci .d_rtb_softlimit = 1000, 22f08c3bdfSopenharmony_ci .d_fieldmask = FS_DQ_RTBSOFT 23f08c3bdfSopenharmony_ci}; 24f08c3bdfSopenharmony_cistatic uint32_t test_id; 25f08c3bdfSopenharmony_cistatic int x_getnextquota_nsup; 26f08c3bdfSopenharmony_cistatic int x_getstatv_nsup; 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_cistatic void check_support_cmd(int quotatype) 29f08c3bdfSopenharmony_ci{ 30f08c3bdfSopenharmony_ci struct fs_disk_quota resfs_dquota; 31f08c3bdfSopenharmony_ci struct fs_quota_statv resfs_qstatv = { 32f08c3bdfSopenharmony_ci .qs_version = FS_QSTATV_VERSION1 33f08c3bdfSopenharmony_ci }; 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci x_getnextquota_nsup = 0; 36f08c3bdfSopenharmony_ci x_getstatv_nsup = 0; 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ci TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev, 39f08c3bdfSopenharmony_ci test_id, (void *) &resfs_dquota)); 40f08c3bdfSopenharmony_ci if (TST_ERR == EINVAL || TST_ERR == ENOSYS) 41f08c3bdfSopenharmony_ci x_getnextquota_nsup = 1; 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci TEST(do_quotactl(fd, QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id, 44f08c3bdfSopenharmony_ci (void *) &resfs_qstatv)); 45f08c3bdfSopenharmony_ci if (TST_ERR == EINVAL || TST_ERR == ENOSYS) 46f08c3bdfSopenharmony_ci x_getstatv_nsup = 1; 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic void check_qoff(int subcmd, char *desp, int flag) 51f08c3bdfSopenharmony_ci{ 52f08c3bdfSopenharmony_ci struct fs_quota_stat res_qstat; 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id, 55f08c3bdfSopenharmony_ci (void *) &res_qstat), "do_quotactl() to %s", desp); 56f08c3bdfSopenharmony_ci if (!TST_PASS) 57f08c3bdfSopenharmony_ci return; 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci if (res_qstat.qs_flags & flag) { 60f08c3bdfSopenharmony_ci tst_res(TFAIL, "xfs quota enforcement was on unexpectedly"); 61f08c3bdfSopenharmony_ci return; 62f08c3bdfSopenharmony_ci } 63f08c3bdfSopenharmony_ci 64f08c3bdfSopenharmony_ci tst_res(TPASS, "quotactl() succeeded to %s", desp); 65f08c3bdfSopenharmony_ci} 66f08c3bdfSopenharmony_ci 67f08c3bdfSopenharmony_cistatic void check_qon(int subcmd, char *desp, int flag) 68f08c3bdfSopenharmony_ci{ 69f08c3bdfSopenharmony_ci struct fs_quota_stat res_qstat; 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id, 72f08c3bdfSopenharmony_ci (void *) &res_qstat), "do_quotactl() to %s", desp); 73f08c3bdfSopenharmony_ci if (!TST_PASS) 74f08c3bdfSopenharmony_ci return; 75f08c3bdfSopenharmony_ci 76f08c3bdfSopenharmony_ci if (!(res_qstat.qs_flags & flag)) { 77f08c3bdfSopenharmony_ci tst_res(TFAIL, "xfs quota enforcement was off unexpectedly"); 78f08c3bdfSopenharmony_ci return; 79f08c3bdfSopenharmony_ci } 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_ci tst_res(TPASS, "quotactl() succeeded to %s", desp); 82f08c3bdfSopenharmony_ci} 83f08c3bdfSopenharmony_ci 84f08c3bdfSopenharmony_cistatic void check_qoffv(int subcmd, char *desp, int flag) 85f08c3bdfSopenharmony_ci{ 86f08c3bdfSopenharmony_ci struct fs_quota_statv res_qstatv = { 87f08c3bdfSopenharmony_ci .qs_version = FS_QSTATV_VERSION1, 88f08c3bdfSopenharmony_ci }; 89f08c3bdfSopenharmony_ci 90f08c3bdfSopenharmony_ci TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id, 91f08c3bdfSopenharmony_ci (void *) &res_qstatv), "do_quotactl() to %s", desp); 92f08c3bdfSopenharmony_ci if (!TST_PASS) 93f08c3bdfSopenharmony_ci return; 94f08c3bdfSopenharmony_ci 95f08c3bdfSopenharmony_ci if (res_qstatv.qs_flags & flag) { 96f08c3bdfSopenharmony_ci tst_res(TFAIL, "xfs quota enforcement was on unexpectedly"); 97f08c3bdfSopenharmony_ci return; 98f08c3bdfSopenharmony_ci } 99f08c3bdfSopenharmony_ci 100f08c3bdfSopenharmony_ci tst_res(TPASS, "quotactl() succeeded to %s", desp); 101f08c3bdfSopenharmony_ci} 102f08c3bdfSopenharmony_ci 103f08c3bdfSopenharmony_cistatic void check_qonv(int subcmd, char *desp, int flag) 104f08c3bdfSopenharmony_ci{ 105f08c3bdfSopenharmony_ci struct fs_quota_statv res_qstatv = { 106f08c3bdfSopenharmony_ci .qs_version = FS_QSTATV_VERSION1 107f08c3bdfSopenharmony_ci }; 108f08c3bdfSopenharmony_ci 109f08c3bdfSopenharmony_ci TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id, 110f08c3bdfSopenharmony_ci (void *) &res_qstatv), "do_quotactl() to %s", desp); 111f08c3bdfSopenharmony_ci if (!TST_PASS) 112f08c3bdfSopenharmony_ci return; 113f08c3bdfSopenharmony_ci 114f08c3bdfSopenharmony_ci if (!(res_qstatv.qs_flags & flag)) { 115f08c3bdfSopenharmony_ci tst_res(TFAIL, "xfs quota enforcement was off unexpectedly"); 116f08c3bdfSopenharmony_ci return; 117f08c3bdfSopenharmony_ci } 118f08c3bdfSopenharmony_ci 119f08c3bdfSopenharmony_ci tst_res(TPASS, "quotactl() succeeded to %s", desp); 120f08c3bdfSopenharmony_ci} 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_cistatic void check_qlim(int subcmd, char *desp) 123f08c3bdfSopenharmony_ci{ 124f08c3bdfSopenharmony_ci static struct fs_disk_quota res_dquota; 125f08c3bdfSopenharmony_ci 126f08c3bdfSopenharmony_ci res_dquota.d_rtb_softlimit = 0; 127f08c3bdfSopenharmony_ci 128f08c3bdfSopenharmony_ci TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id, 129f08c3bdfSopenharmony_ci (void *) &res_dquota), "do_quotactl() to %s", desp); 130f08c3bdfSopenharmony_ci if (!TST_PASS) 131f08c3bdfSopenharmony_ci return; 132f08c3bdfSopenharmony_ci 133f08c3bdfSopenharmony_ci if (res_dquota.d_id != test_id) { 134f08c3bdfSopenharmony_ci tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u", 135f08c3bdfSopenharmony_ci res_dquota.d_id, test_id); 136f08c3bdfSopenharmony_ci return; 137f08c3bdfSopenharmony_ci } 138f08c3bdfSopenharmony_ci 139f08c3bdfSopenharmony_ci if (res_dquota.d_rtb_hardlimit != set_dquota.d_rtb_hardlimit) { 140f08c3bdfSopenharmony_ci tst_res(TFAIL, "quotactl() got unexpected rtb soft limit %llu, expected %llu", 141f08c3bdfSopenharmony_ci res_dquota.d_rtb_hardlimit, set_dquota.d_rtb_hardlimit); 142f08c3bdfSopenharmony_ci return; 143f08c3bdfSopenharmony_ci } 144f08c3bdfSopenharmony_ci 145f08c3bdfSopenharmony_ci tst_res(TPASS, "quotactl() succeeded to set and use %s to get xfs disk quota limits", 146f08c3bdfSopenharmony_ci desp); 147f08c3bdfSopenharmony_ci} 148f08c3bdfSopenharmony_ci#endif /* HAVE_XFS_XQM_H */ 149f08c3bdfSopenharmony_ci#endif /* QUOTACTL02_H */ 150