blob: d4315759042144556258421cb539b47532b49a98 [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
subrata_modakbdb9a152009-06-15 18:42:32 +000063#include "test.h"
subrata_modakbdb9a152009-06-15 18:42:32 +000064#include "linux_syscall_numbers.h"
65
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020066char *TCID = "quotactl01";
Wanlong Gao354ebb42012-12-07 10:10:04 +080067int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020068int TST_TOTAL = 1;
subrata_modakbdb9a152009-06-15 18:42:32 +000069
yaberauneyac2a3ba52010-01-10 22:27:14 +000070#define QUOTACTL(cmd, addr) \
Jan Stancek359980f2013-02-15 10:16:05 +010071 ltp_syscall(__NR_quotactl, QCMD(cmd, USRQUOTA), block_dev, id, \
yaberauneyac2a3ba52010-01-10 22:27:14 +000072 (caddr_t) addr)
yaberauneya7ed9a6c2010-01-20 11:31:39 +000073#ifndef BROKEN_QUOTACTL
yaberauneyac2a3ba52010-01-10 22:27:14 +000074
75#ifndef QUOTAFILE
76/* Default name of the quota file in Fedora 12. */
77#define QUOTAFILE "aquota.user"
78#endif
79
80char quota_started = 0;
yaberauneya7ed9a6c2010-01-20 11:31:39 +000081static char *block_dev, *mountpoint, *quota_file, *quota_loc = NULL;
yaberauneyac2a3ba52010-01-10 22:27:14 +000082int id;
83struct dqblk dq;
yaberauneyacfb70632010-01-10 08:01:15 +000084
subrata_modakbdb9a152009-06-15 18:42:32 +000085/* Extern Global Functions */
86/******************************************************************************/
yaberauneyab8709bf2009-12-20 00:36:35 +000087/* */
88/* Function: cleanup */
89/* */
90/* Description: Performs all one time clean up for this test on successful */
91/* completion, premature exit or failure. Closes all temporary */
92/* files, removes all temporary directories exits the test with */
93/* appropriate return code by calling tst_exit() function. */
94/* */
95/* Input: None. */
96/* */
97/* Output: None. */
98/* */
99/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
100/* On success - Exits calling tst_exit(). With '0' return code. */
101/* */
subrata_modakbdb9a152009-06-15 18:42:32 +0000102/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400103void cleanup(void)
yaberauneyac2a3ba52010-01-10 22:27:14 +0000104{
105
yaberauneyab8709bf2009-12-20 00:36:35 +0000106 tst_rmdir();
subrata_modakbdb9a152009-06-15 18:42:32 +0000107
yaberauneyacfb70632010-01-10 08:01:15 +0000108 if (block_dev) {
yaberauneyac2a3ba52010-01-10 22:27:14 +0000109 if (quota_started == 1 && QUOTACTL(Q_QUOTAOFF, &dq)) {
110 tst_brkm(TBROK | TERRNO, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800111 "failed to disable the quota on %s",
112 block_dev);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000113 }
yaberauneyac2a3ba52010-01-10 22:27:14 +0000114 }
115
subrata_modakbdb9a152009-06-15 18:42:32 +0000116}
117
118/* Local Functions */
119/******************************************************************************/
yaberauneyab8709bf2009-12-20 00:36:35 +0000120/* */
121/* Function: setup */
122/* */
subrata_modakbdb9a152009-06-15 18:42:32 +0000123/* Description: Performs all one time setup for this test. This function is */
yaberauneyab8709bf2009-12-20 00:36:35 +0000124/* typically used to capture signals, create temporary dirs */
125/* and temporary files that may be used in the course of this */
126/* test. */
127/* */
128/* Input: None. */
129/* */
130/* Output: None. */
131/* */
132/* Return: On failure - Exits by calling cleanup(). */
133/* On success - returns 0. */
134/* */
subrata_modakbdb9a152009-06-15 18:42:32 +0000135/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400136void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800137{
yaberauneyac2a3ba52010-01-10 22:27:14 +0000138
yaberauneyab8709bf2009-12-20 00:36:35 +0000139 /* Capture signals if any */
140 /* Create temporary directories */
yaberauneyac2a3ba52010-01-10 22:27:14 +0000141
yaberauneyab8709bf2009-12-20 00:36:35 +0000142 if (geteuid() != 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800143 tst_brkm(TCONF, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800144 "You must be root in order to execute this test");
yaberauneyab8709bf2009-12-20 00:36:35 +0000145 }
yaberauneyac2a3ba52010-01-10 22:27:14 +0000146 if ((quota_loc = malloc(FILENAME_MAX)) == NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800147 tst_brkm(TCONF | TERRNO, NULL,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800148 "couldn't allocate memory for the quota loc buffer");
yaberauneyac2a3ba52010-01-10 22:27:14 +0000149 }
150
yaberauneyab8709bf2009-12-20 00:36:35 +0000151 TEST_PAUSE;
152 tst_tmpdir();
yaberauneyacfb70632010-01-10 08:01:15 +0000153
yaberauneya7ed9a6c2010-01-20 11:31:39 +0000154 snprintf(quota_loc, FILENAME_MAX, "%s/%s", mountpoint, quota_file);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000155
156 if (QUOTACTL(Q_QUOTAON, quota_loc) != 0) {
Garrett Cooper2c282152010-12-16 00:55:50 -0800157
yaberauneyac2a3ba52010-01-10 22:27:14 +0000158 if (errno == ENOENT) {
159 tst_brkm(TCONF, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800160 "quota file - %s - doesn't exist (is the name "
161 "correct?)", quota_loc);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000162 } else {
163 /* Provide a terse explanation for why the command
164 * failed.. */
165 tst_brkm(TCONF | TERRNO, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166 "failed to enable quotas on block device: %s; "
167 "1. Ensure that the device is mounted with the "
168 "quota option. 2. Check the filesystem status "
169 "with `quotacheck %s'", block_dev, block_dev);
yaberauneyac2a3ba52010-01-10 22:27:14 +0000170 }
171 } else {
172 quota_started = 1;
yaberauneyacfb70632010-01-10 08:01:15 +0000173 }
174
subrata_modakbdb9a152009-06-15 18:42:32 +0000175}
yaberauneyac2a3ba52010-01-10 22:27:14 +0000176#endif
subrata_modakbdb9a152009-06-15 18:42:32 +0000177
178/*
179* WARNING!! This test may cause the potential harm to the system, we DO NOT
180* provide any warranty for the safety!!
181*/
182/*
yaberauneyab8709bf2009-12-20 00:36:35 +0000183* To use this testcase, the quota function must be turned on and the user must
184* be the super user.
subrata_modakbdb9a152009-06-15 18:42:32 +0000185*/
186
yaberauneya4df28652009-10-22 08:25:30 +0000187#ifdef BROKEN_QUOTACTL
Wanlong Gao354ebb42012-12-07 10:10:04 +0800188int main(void)
189{
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100190 tst_brkm(TBROK, NULL, "This system doesn't support quota v2");
yaberauneyaef772532009-10-09 17:55:43 +0000191}
192#else
yaberauneyab8709bf2009-12-20 00:36:35 +0000193int cmd[] = {
yaberauneyab8709bf2009-12-20 00:36:35 +0000194 Q_GETQUOTA,
195 Q_SETQUOTA,
196/* Only available in quota v2 */
Garrett Cooper40be6482010-11-03 21:00:55 -0700197#if defined(HAVE_QUOTAV2)
yaberauneyab8709bf2009-12-20 00:36:35 +0000198 Q_GETINFO,
199 Q_SETINFO,
200 Q_GETFMT,
201#endif
202 Q_SYNC
203};
subrata_modakbdb9a152009-06-15 18:42:32 +0000204
Wanlong Gao354ebb42012-12-07 10:10:04 +0800205int main(int ac, char **av)
yaberauneya4df28652009-10-22 08:25:30 +0000206{
yaberauneya7ed9a6c2010-01-20 11:31:39 +0000207
208 static int block_dev_FLAG = 0, mountpoint_FLAG = 0, quota_file_FLAG = 0;
209 option_t opts[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800210 {.option = "b:",.flag = &block_dev_FLAG,.arg = &block_dev},
211 {.option = "m:",.flag = &mountpoint_FLAG,.arg = &mountpoint},
212 {.option = "q:",.flag = &quota_file_FLAG,.arg = &quota_file},
213 {.option = '\0'}
yaberauneya7ed9a6c2010-01-20 11:31:39 +0000214 };
215
yaberauneya4df28652009-10-22 08:25:30 +0000216 int newtid = -1;
yaberauneyab8709bf2009-12-20 00:36:35 +0000217 int ret;
218 int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200219 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200220 const char *msg;
yaberauneyacfb70632010-01-10 08:01:15 +0000221
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200222 if ((msg = parse_opts(ac, av, (option_t *) opts, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -0800223 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
yaberauneya4df28652009-10-22 08:25:30 +0000224 }
subrata_modakbdb9a152009-06-15 18:42:32 +0000225
yaberauneya4df28652009-10-22 08:25:30 +0000226 setup();
subrata_modakbdb9a152009-06-15 18:42:32 +0000227
yaberauneya4df28652009-10-22 08:25:30 +0000228 for (lc = 0; TEST_LOOPING(lc); ++lc) {
229
Caspar Zhangd59a6592013-03-07 14:59:12 +0800230 tst_count = 0;
yaberauneya4df28652009-10-22 08:25:30 +0000231
232 for (testno = 0; testno < TST_TOTAL; ++testno) {
233
Wanlong Gao354ebb42012-12-07 10:10:04 +0800234 for (i = 0; i <= sizeof(cmd) / sizeof(cmd[0]); i++) {
yaberauneya4df28652009-10-22 08:25:30 +0000235
yaberauneyac2a3ba52010-01-10 22:27:14 +0000236 ret = QUOTACTL(cmd[i], &dq);
yaberauneyab8709bf2009-12-20 00:36:35 +0000237 if (ret != 0) {
yaberauneyac2a3ba52010-01-10 22:27:14 +0000238 tst_resm(TFAIL | TERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800239 "cmd=0x%x failed", cmd[i]);
yaberauneya4df28652009-10-22 08:25:30 +0000240 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800241 tst_resm(TPASS,
242 "quotactl call succeeded");
yaberauneya4df28652009-10-22 08:25:30 +0000243 }
244
245 }
246
Jan Stancek359980f2013-02-15 10:16:05 +0100247 TEST(ltp_syscall(__NR_set_tid_address, &newtid));
yaberauneya4df28652009-10-22 08:25:30 +0000248
249 if (TEST_RETURN == getpid()) {
250 cleanup();
251 } else {
252 cleanup();
253 tst_exit();
254 }
255
256 }
257
Garrett Cooper2c282152010-12-16 00:55:50 -0800258 }
yaberauneya4df28652009-10-22 08:25:30 +0000259
260 cleanup();
261
subrata_modakbdb9a152009-06-15 18:42:32 +0000262 tst_exit();
yaberauneya4df28652009-10-22 08:25:30 +0000263
subrata_modakbdb9a152009-06-15 18:42:32 +0000264}
Chris Dearmanec6edca2012-10-17 19:54:01 -0700265#endif