blob: f90ec9b33e997c75d3f569f7cdf2bddf22e3c66c [file] [log] [blame]
subrata_modakbdb9a152009-06-15 18:42:32 +00001/******************************************************************************/
yaberauneyab8709bf2009-12-20 00:36:35 +00002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
4/* This program is free software; you can redistribute it and/or modify */
5/* it under the terms of the GNU General Public License as published by */
6/* the Free Software Foundation; either version 2 of the License, or */
7/* (at your option) any later version. */
8/* */
9/* This program is distributed in the hope that it will be useful, */
10/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
12/* the GNU General Public License for more details. */
13/* */
14/* You should have received a copy of the GNU General Public License */
15/* along with this program; if not, write to the Free Software */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080016/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
yaberauneyab8709bf2009-12-20 00:36:35 +000017/* */
subrata_modakbdb9a152009-06-15 18:42:32 +000018/******************************************************************************/
19/******************************************************************************/
yaberauneyab8709bf2009-12-20 00:36:35 +000020/* */
21/* File: quotactl01.c */
22/* */
23/* Description: This tests the quotactl() syscall */
24/* */
25/* Usage: <for command-line> */
26/* quotactl01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
27/* where, -c n : Run n copies concurrently. */
28/* -e : Turn on errno logging. */
29/* -i n : Execute test n times. */
30/* -I x : Execute test for x seconds. */
31/* -P x : Pause for x seconds between iterations. */
32/* -t : Turn on syscall timing. */
33/* */
34/* Total Tests: 1 */
35/* */
36/* Test Name: quotactl01 */
37/* History: Porting from Crackerjack to LTP is done by */
38/* Manas Kumar Nayak maknayak@in.ibm.com> */
subrata_modakbdb9a152009-06-15 18:42:32 +000039/******************************************************************************/
yaberauneyacfb70632010-01-10 08:01:15 +000040#ifndef _GNU_SOURCE
41#define _GNU_SOURCE
42#endif
subrata_modakbdb9a152009-06-15 18:42:32 +000043#include <fcntl.h>
44#include <unistd.h>
45#include <sys/syscall.h>
46#include <stdio.h>
47#include <errno.h>
48#include <linux/fs.h>
subrata_modakbdb9a152009-06-15 18:42:32 +000049#include <sys/types.h>
yaberauneyaef772532009-10-09 17:55:43 +000050#include "config.h"
Garrett Cooper40be6482010-11-03 21:00:55 -070051#if defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1)
52#if defined(HAVE_QUOTAV2)
yaberauneyab8709bf2009-12-20 00:36:35 +000053#define _LINUX_QUOTA_VERSION 2
Wanlong Gao354ebb42012-12-07 10:10:04 +080054#else /* HAVE_QUOTAV1 */
yaberauneya7ed9a6c2010-01-20 11:31:39 +000055#define _LINUX_QUOTA_VERSION 1
56#endif
yaberauneya88fe99f2010-01-10 21:10:56 +000057#include <sys/quota.h>
Wanlong Gao354ebb42012-12-07 10:10:04 +080058#else /* ! (HAVE_QUOTAV2 || HAVE_QUOTAV1) */
Garrett Cooper40be6482010-11-03 21:00:55 -070059/* Not HAVE_QUOTAV2 */
yaberauneya4df28652009-10-22 08:25:30 +000060#define BROKEN_QUOTACTL 1
61#endif
subrata_modakbdb9a152009-06-15 18:42:32 +000062
63/* Harness Specific Include Files. */
64#include "test.h"
65#include "usctest.h"
66#include "linux_syscall_numbers.h"
67
68/* Extern Global Variables */
subrata_modakbdb9a152009-06-15 18:42:32 +000069
70/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080071char *TCID = "quotactl01"; /* Test program identifier. */
72int testno;
73int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modakbdb9a152009-06-15 18:42:32 +000074
yaberauneyac2a3ba52010-01-10 22:27:14 +000075#define QUOTACTL(cmd, addr) \
Jan Stancek359980f2013-02-15 10:16:05 +010076 ltp_syscall(__NR_quotactl, QCMD(cmd, USRQUOTA), block_dev, id, \
yaberauneyac2a3ba52010-01-10 22:27:14 +000077 (caddr_t) addr)
yaberauneya7ed9a6c2010-01-20 11:31:39 +000078#ifndef BROKEN_QUOTACTL
yaberauneyac2a3ba52010-01-10 22:27:14 +000079
80#ifndef QUOTAFILE
81/* Default name of the quota file in Fedora 12. */
82#define QUOTAFILE "aquota.user"
83#endif
84
85char quota_started = 0;
yaberauneya7ed9a6c2010-01-20 11:31:39 +000086static char *block_dev, *mountpoint, *quota_file, *quota_loc = NULL;
yaberauneyac2a3ba52010-01-10 22:27:14 +000087int id;
88struct dqblk dq;
yaberauneyacfb70632010-01-10 08:01:15 +000089
subrata_modakbdb9a152009-06-15 18:42:32 +000090/* Extern Global Functions */
91/******************************************************************************/
yaberauneyab8709bf2009-12-20 00:36:35 +000092/* */
93/* Function: cleanup */
94/* */
95/* Description: Performs all one time clean up for this test on successful */
96/* completion, premature exit or failure. Closes all temporary */
97/* files, removes all temporary directories exits the test with */
98/* appropriate return code by calling tst_exit() function. */
99/* */
100/* Input: None. */
101/* */
102/* Output: None. */
103/* */
104/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
105/* On success - Exits calling tst_exit(). With '0' return code. */
106/* */
subrata_modakbdb9a152009-06-15 18:42:32 +0000107/******************************************************************************/
yaberauneyac2a3ba52010-01-10 22:27:14 +0000108extern void cleanup()
109{
110
yaberauneyab8709bf2009-12-20 00:36:35 +0000111 TEST_CLEANUP;
112 tst_rmdir();
subrata_modakbdb9a152009-06-15 18:42:32 +0000113
yaberauneyacfb70632010-01-10 08:01:15 +0000114 if (block_dev) {
yaberauneyac2a3ba52010-01-10 22:27:14 +0000115 if (quota_started == 1 && QUOTACTL(Q_QUOTAOFF, &dq)) {
116 tst_brkm(TBROK | TERRNO, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800117 "failed to disable the quota on %s",
118 block_dev);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000119 }
yaberauneyac2a3ba52010-01-10 22:27:14 +0000120 }
121
subrata_modakbdb9a152009-06-15 18:42:32 +0000122}
123
124/* Local Functions */
125/******************************************************************************/
yaberauneyab8709bf2009-12-20 00:36:35 +0000126/* */
127/* Function: setup */
128/* */
subrata_modakbdb9a152009-06-15 18:42:32 +0000129/* Description: Performs all one time setup for this test. This function is */
yaberauneyab8709bf2009-12-20 00:36:35 +0000130/* typically used to capture signals, create temporary dirs */
131/* and temporary files that may be used in the course of this */
132/* test. */
133/* */
134/* Input: None. */
135/* */
136/* Output: None. */
137/* */
138/* Return: On failure - Exits by calling cleanup(). */
139/* On success - returns 0. */
140/* */
subrata_modakbdb9a152009-06-15 18:42:32 +0000141/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800142void setup()
143{
yaberauneyac2a3ba52010-01-10 22:27:14 +0000144
yaberauneyab8709bf2009-12-20 00:36:35 +0000145 /* Capture signals if any */
146 /* Create temporary directories */
yaberauneyac2a3ba52010-01-10 22:27:14 +0000147
yaberauneyab8709bf2009-12-20 00:36:35 +0000148 if (geteuid() != 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800149 tst_brkm(TCONF, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800150 "You must be root in order to execute this test");
yaberauneyab8709bf2009-12-20 00:36:35 +0000151 }
yaberauneyac2a3ba52010-01-10 22:27:14 +0000152 if ((quota_loc = malloc(FILENAME_MAX)) == NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800153 tst_brkm(TCONF | TERRNO, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800154 "couldn't allocate memory for the quota loc buffer");
yaberauneyac2a3ba52010-01-10 22:27:14 +0000155 }
156
yaberauneyab8709bf2009-12-20 00:36:35 +0000157 TEST_PAUSE;
158 tst_tmpdir();
yaberauneyacfb70632010-01-10 08:01:15 +0000159
yaberauneya7ed9a6c2010-01-20 11:31:39 +0000160 snprintf(quota_loc, FILENAME_MAX, "%s/%s", mountpoint, quota_file);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000161
162 if (QUOTACTL(Q_QUOTAON, quota_loc) != 0) {
Garrett Cooper2c282152010-12-16 00:55:50 -0800163
yaberauneyac2a3ba52010-01-10 22:27:14 +0000164 if (errno == ENOENT) {
165 tst_brkm(TCONF, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166 "quota file - %s - doesn't exist (is the name "
167 "correct?)", quota_loc);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000168 } else {
169 /* Provide a terse explanation for why the command
170 * failed.. */
171 tst_brkm(TCONF | TERRNO, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800172 "failed to enable quotas on block device: %s; "
173 "1. Ensure that the device is mounted with the "
174 "quota option. 2. Check the filesystem status "
175 "with `quotacheck %s'", block_dev, block_dev);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000176 }
177 } else {
178 quota_started = 1;
yaberauneyacfb70632010-01-10 08:01:15 +0000179 }
180
subrata_modakbdb9a152009-06-15 18:42:32 +0000181}
yaberauneyac2a3ba52010-01-10 22:27:14 +0000182#endif
subrata_modakbdb9a152009-06-15 18:42:32 +0000183
184/*
185* WARNING!! This test may cause the potential harm to the system, we DO NOT
186* provide any warranty for the safety!!
187*/
188/*
yaberauneyab8709bf2009-12-20 00:36:35 +0000189* To use this testcase, the quota function must be turned on and the user must
190* be the super user.
subrata_modakbdb9a152009-06-15 18:42:32 +0000191*/
192
yaberauneya4df28652009-10-22 08:25:30 +0000193#ifdef BROKEN_QUOTACTL
Wanlong Gao354ebb42012-12-07 10:10:04 +0800194int main(void)
195{
yaberauneyab8709bf2009-12-20 00:36:35 +0000196 tst_resm(TBROK, "This system doesn't support quota v2");
yaberauneyaef772532009-10-09 17:55:43 +0000197 tst_exit();
198}
199#else
yaberauneyab8709bf2009-12-20 00:36:35 +0000200int cmd[] = {
yaberauneyab8709bf2009-12-20 00:36:35 +0000201 Q_GETQUOTA,
202 Q_SETQUOTA,
203/* Only available in quota v2 */
Garrett Cooper40be6482010-11-03 21:00:55 -0700204#if defined(HAVE_QUOTAV2)
yaberauneyab8709bf2009-12-20 00:36:35 +0000205 Q_GETINFO,
206 Q_SETINFO,
207 Q_GETFMT,
208#endif
209 Q_SYNC
210};
subrata_modakbdb9a152009-06-15 18:42:32 +0000211
Wanlong Gao354ebb42012-12-07 10:10:04 +0800212int main(int ac, char **av)
yaberauneya4df28652009-10-22 08:25:30 +0000213{
yaberauneya7ed9a6c2010-01-20 11:31:39 +0000214
215 static int block_dev_FLAG = 0, mountpoint_FLAG = 0, quota_file_FLAG = 0;
216 option_t opts[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800217 {.option = "b:",.flag = &block_dev_FLAG,.arg = &block_dev},
218 {.option = "m:",.flag = &mountpoint_FLAG,.arg = &mountpoint},
219 {.option = "q:",.flag = &quota_file_FLAG,.arg = &quota_file},
220 {.option = '\0'}
yaberauneya7ed9a6c2010-01-20 11:31:39 +0000221 };
222
yaberauneya4df28652009-10-22 08:25:30 +0000223 int newtid = -1;
yaberauneyab8709bf2009-12-20 00:36:35 +0000224 int ret;
225 int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200226 int lc;
227 char *msg;
yaberauneyacfb70632010-01-10 08:01:15 +0000228
Wanlong Gao354ebb42012-12-07 10:10:04 +0800229 if ((msg = parse_opts(ac, av, (option_t *) opts, NULL)) != (char *)NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -0800230 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
yaberauneya4df28652009-10-22 08:25:30 +0000231 }
subrata_modakbdb9a152009-06-15 18:42:32 +0000232
yaberauneya4df28652009-10-22 08:25:30 +0000233 setup();
subrata_modakbdb9a152009-06-15 18:42:32 +0000234
yaberauneya4df28652009-10-22 08:25:30 +0000235 for (lc = 0; TEST_LOOPING(lc); ++lc) {
236
237 Tst_count = 0;
238
239 for (testno = 0; testno < TST_TOTAL; ++testno) {
240
Wanlong Gao354ebb42012-12-07 10:10:04 +0800241 for (i = 0; i <= sizeof(cmd) / sizeof(cmd[0]); i++) {
yaberauneya4df28652009-10-22 08:25:30 +0000242
yaberauneyac2a3ba52010-01-10 22:27:14 +0000243 ret = QUOTACTL(cmd[i], &dq);
yaberauneyab8709bf2009-12-20 00:36:35 +0000244 if (ret != 0) {
yaberauneyac2a3ba52010-01-10 22:27:14 +0000245 tst_resm(TFAIL | TERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800246 "cmd=0x%x failed", cmd[i]);
yaberauneya4df28652009-10-22 08:25:30 +0000247 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800248 tst_resm(TPASS,
249 "quotactl call succeeded");
yaberauneya4df28652009-10-22 08:25:30 +0000250 }
251
252 }
253
Jan Stancek359980f2013-02-15 10:16:05 +0100254 TEST(ltp_syscall(__NR_set_tid_address, &newtid));
yaberauneya4df28652009-10-22 08:25:30 +0000255
256 if (TEST_RETURN == getpid()) {
257 cleanup();
258 } else {
259 cleanup();
260 tst_exit();
261 }
262
263 }
264
Garrett Cooper2c282152010-12-16 00:55:50 -0800265 }
yaberauneya4df28652009-10-22 08:25:30 +0000266
267 cleanup();
268
subrata_modakbdb9a152009-06-15 18:42:32 +0000269 tst_exit();
yaberauneya4df28652009-10-22 08:25:30 +0000270
subrata_modakbdb9a152009-06-15 18:42:32 +0000271}
Chris Dearmanec6edca2012-10-17 19:54:01 -0700272#endif