subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 2 | /* 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 17 | /* */ |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 20 | /* */ |
| 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_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 39 | /******************************************************************************/ |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 40 | #ifndef _GNU_SOURCE |
| 41 | #define _GNU_SOURCE |
| 42 | #endif |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 43 | #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_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 49 | #include <sys/types.h> |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 50 | #include "config.h" |
Garrett Cooper | 40be648 | 2010-11-03 21:00:55 -0700 | [diff] [blame] | 51 | #if defined(HAVE_QUOTAV2) || defined(HAVE_QUOTAV1) |
| 52 | #if defined(HAVE_QUOTAV2) |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 53 | #define _LINUX_QUOTA_VERSION 2 |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 54 | #else /* HAVE_QUOTAV1 */ |
yaberauneya | 7ed9a6c | 2010-01-20 11:31:39 +0000 | [diff] [blame] | 55 | #define _LINUX_QUOTA_VERSION 1 |
| 56 | #endif |
yaberauneya | 88fe99f | 2010-01-10 21:10:56 +0000 | [diff] [blame] | 57 | #include <sys/quota.h> |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 58 | #else /* ! (HAVE_QUOTAV2 || HAVE_QUOTAV1) */ |
Garrett Cooper | 40be648 | 2010-11-03 21:00:55 -0700 | [diff] [blame] | 59 | /* Not HAVE_QUOTAV2 */ |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 60 | #define BROKEN_QUOTACTL 1 |
| 61 | #endif |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 62 | |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 63 | #include "test.h" |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 64 | #include "linux_syscall_numbers.h" |
| 65 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 66 | char *TCID = "quotactl01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 67 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 68 | int TST_TOTAL = 1; |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 69 | |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 70 | #define QUOTACTL(cmd, addr) \ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 71 | ltp_syscall(__NR_quotactl, QCMD(cmd, USRQUOTA), block_dev, id, \ |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 72 | (caddr_t) addr) |
yaberauneya | 7ed9a6c | 2010-01-20 11:31:39 +0000 | [diff] [blame] | 73 | #ifndef BROKEN_QUOTACTL |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 74 | |
| 75 | #ifndef QUOTAFILE |
| 76 | /* Default name of the quota file in Fedora 12. */ |
| 77 | #define QUOTAFILE "aquota.user" |
| 78 | #endif |
| 79 | |
| 80 | char quota_started = 0; |
yaberauneya | 7ed9a6c | 2010-01-20 11:31:39 +0000 | [diff] [blame] | 81 | static char *block_dev, *mountpoint, *quota_file, *quota_loc = NULL; |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 82 | int id; |
| 83 | struct dqblk dq; |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 84 | |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 85 | /* Extern Global Functions */ |
| 86 | /******************************************************************************/ |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 87 | /* */ |
| 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_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 102 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 103 | void cleanup(void) |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 104 | { |
| 105 | |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 106 | tst_rmdir(); |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 107 | |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 108 | if (block_dev) { |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 109 | if (quota_started == 1 && QUOTACTL(Q_QUOTAOFF, &dq)) { |
| 110 | tst_brkm(TBROK | TERRNO, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 111 | "failed to disable the quota on %s", |
| 112 | block_dev); |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 113 | } |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 114 | } |
| 115 | |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* Local Functions */ |
| 119 | /******************************************************************************/ |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 120 | /* */ |
| 121 | /* Function: setup */ |
| 122 | /* */ |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 123 | /* Description: Performs all one time setup for this test. This function is */ |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 124 | /* 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_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 135 | /******************************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 136 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 137 | { |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 138 | |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 139 | /* Capture signals if any */ |
| 140 | /* Create temporary directories */ |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 141 | |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 142 | if (geteuid() != 0) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 143 | tst_brkm(TCONF, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | "You must be root in order to execute this test"); |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 145 | } |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 146 | if ((quota_loc = malloc(FILENAME_MAX)) == NULL) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 147 | tst_brkm(TCONF | TERRNO, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 148 | "couldn't allocate memory for the quota loc buffer"); |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 149 | } |
| 150 | |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 151 | TEST_PAUSE; |
| 152 | tst_tmpdir(); |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 153 | |
yaberauneya | 7ed9a6c | 2010-01-20 11:31:39 +0000 | [diff] [blame] | 154 | snprintf(quota_loc, FILENAME_MAX, "%s/%s", mountpoint, quota_file); |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 155 | |
| 156 | if (QUOTACTL(Q_QUOTAON, quota_loc) != 0) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 157 | |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 158 | if (errno == ENOENT) { |
| 159 | tst_brkm(TCONF, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 160 | "quota file - %s - doesn't exist (is the name " |
| 161 | "correct?)", quota_loc); |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 162 | } else { |
| 163 | /* Provide a terse explanation for why the command |
| 164 | * failed.. */ |
| 165 | tst_brkm(TCONF | TERRNO, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 166 | "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); |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 170 | } |
| 171 | } else { |
| 172 | quota_started = 1; |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 173 | } |
| 174 | |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 175 | } |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 176 | #endif |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 177 | |
| 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 | /* |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 183 | * To use this testcase, the quota function must be turned on and the user must |
| 184 | * be the super user. |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 185 | */ |
| 186 | |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 187 | #ifdef BROKEN_QUOTACTL |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 188 | int main(void) |
| 189 | { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 190 | tst_brkm(TBROK, NULL, "This system doesn't support quota v2"); |
yaberauneya | ef77253 | 2009-10-09 17:55:43 +0000 | [diff] [blame] | 191 | } |
| 192 | #else |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 193 | int cmd[] = { |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 194 | Q_GETQUOTA, |
| 195 | Q_SETQUOTA, |
| 196 | /* Only available in quota v2 */ |
Garrett Cooper | 40be648 | 2010-11-03 21:00:55 -0700 | [diff] [blame] | 197 | #if defined(HAVE_QUOTAV2) |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 198 | Q_GETINFO, |
| 199 | Q_SETINFO, |
| 200 | Q_GETFMT, |
| 201 | #endif |
| 202 | Q_SYNC |
| 203 | }; |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 204 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 205 | int main(int ac, char **av) |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 206 | { |
yaberauneya | 7ed9a6c | 2010-01-20 11:31:39 +0000 | [diff] [blame] | 207 | |
| 208 | static int block_dev_FLAG = 0, mountpoint_FLAG = 0, quota_file_FLAG = 0; |
| 209 | option_t opts[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 210 | {.option = "b:",.flag = &block_dev_FLAG,.arg = &block_dev}, |
| 211 | {.option = "m:",.flag = &mountpoint_FLAG,.arg = &mountpoint}, |
| 212 | {.option = "q:",.flag = "a_file_FLAG,.arg = "a_file}, |
| 213 | {.option = '\0'} |
yaberauneya | 7ed9a6c | 2010-01-20 11:31:39 +0000 | [diff] [blame] | 214 | }; |
| 215 | |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 216 | int newtid = -1; |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 217 | int ret; |
| 218 | int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 219 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 220 | const char *msg; |
yaberauneya | cfb7063 | 2010-01-10 08:01:15 +0000 | [diff] [blame] | 221 | |
Cyril Hrubis | cf0d626 | 2014-09-23 14:03:31 +0200 | [diff] [blame] | 222 | if ((msg = parse_opts(ac, av, (option_t *) opts, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 223 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 224 | } |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 225 | |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 226 | setup(); |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 227 | |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 228 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 229 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 230 | tst_count = 0; |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 231 | |
| 232 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
| 233 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 234 | for (i = 0; i <= sizeof(cmd) / sizeof(cmd[0]); i++) { |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 235 | |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 236 | ret = QUOTACTL(cmd[i], &dq); |
yaberauneya | b8709bf | 2009-12-20 00:36:35 +0000 | [diff] [blame] | 237 | if (ret != 0) { |
yaberauneya | c2a3ba5 | 2010-01-10 22:27:14 +0000 | [diff] [blame] | 238 | tst_resm(TFAIL | TERRNO, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 239 | "cmd=0x%x failed", cmd[i]); |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 240 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 241 | tst_resm(TPASS, |
| 242 | "quotactl call succeeded"); |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | } |
| 246 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 247 | TEST(ltp_syscall(__NR_set_tid_address, &newtid)); |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 248 | |
| 249 | if (TEST_RETURN == getpid()) { |
| 250 | cleanup(); |
| 251 | } else { |
| 252 | cleanup(); |
| 253 | tst_exit(); |
| 254 | } |
| 255 | |
| 256 | } |
| 257 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 258 | } |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 259 | |
| 260 | cleanup(); |
| 261 | |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 262 | tst_exit(); |
yaberauneya | 4df2865 | 2009-10-22 08:25:30 +0000 | [diff] [blame] | 263 | |
subrata_modak | bdb9a15 | 2009-06-15 18:42:32 +0000 | [diff] [blame] | 264 | } |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 265 | #endif |