4
4
5
5
#include <assert.h>
6
6
#include <stddef.h>
7
- #include <stdint.h>
8
7
#include <sched.h>
9
8
#include <fcntl.h>
10
9
#include <sys/param.h>
11
10
#include <sys/mount.h>
12
11
#include <sys/stat.h>
13
12
#include <sys/statfs.h>
14
- #include <linux/mount.h>
15
13
#include <linux/stat.h>
16
- #include <asm/unistd.h>
17
14
15
+ #include "statmount.h"
18
16
#include "../../kselftest.h"
19
17
20
18
static const char * const known_fs [] = {
@@ -36,18 +34,6 @@ static const char *const known_fs[] = {
36
34
"ufs" , "v7" , "vboxsf" , "vfat" , "virtiofs" , "vxfs" , "xenfs" , "xfs" ,
37
35
"zonefs" , NULL };
38
36
39
- static int statmount (uint64_t mnt_id , uint64_t mask , struct statmount * buf ,
40
- size_t bufsize , unsigned int flags )
41
- {
42
- struct mnt_id_req req = {
43
- .size = MNT_ID_REQ_SIZE_VER0 ,
44
- .mnt_id = mnt_id ,
45
- .param = mask ,
46
- };
47
-
48
- return syscall (__NR_statmount , & req , buf , bufsize , flags );
49
- }
50
-
51
37
static struct statmount * statmount_alloc (uint64_t mnt_id , uint64_t mask , unsigned int flags )
52
38
{
53
39
size_t bufsize = 1 << 15 ;
@@ -56,7 +42,7 @@ static struct statmount *statmount_alloc(uint64_t mnt_id, uint64_t mask, unsigne
56
42
int ret ;
57
43
58
44
for (;;) {
59
- ret = statmount (mnt_id , mask , tmp , bufsize , flags );
45
+ ret = statmount (mnt_id , 0 , mask , tmp , bufsize , flags );
60
46
if (ret != -1 )
61
47
break ;
62
48
if (tofree )
@@ -122,7 +108,6 @@ static int orig_root;
122
108
static uint64_t root_id , parent_id ;
123
109
static uint32_t old_root_id , old_parent_id ;
124
110
125
-
126
111
static void cleanup_namespace (void )
127
112
{
128
113
fchdir (orig_root );
@@ -138,7 +123,7 @@ static void setup_namespace(void)
138
123
uid_t uid = getuid ();
139
124
gid_t gid = getgid ();
140
125
141
- ret = unshare (CLONE_NEWNS |CLONE_NEWUSER );
126
+ ret = unshare (CLONE_NEWNS |CLONE_NEWUSER | CLONE_NEWPID );
142
127
if (ret == -1 )
143
128
ksft_exit_fail_msg ("unsharing mountns and userns: %s\n" ,
144
129
strerror (errno ));
@@ -208,25 +193,13 @@ static int setup_mount_tree(int log2_num)
208
193
return 0 ;
209
194
}
210
195
211
- static ssize_t listmount (uint64_t mnt_id , uint64_t last_mnt_id ,
212
- uint64_t list [], size_t num , unsigned int flags )
213
- {
214
- struct mnt_id_req req = {
215
- .size = MNT_ID_REQ_SIZE_VER0 ,
216
- .mnt_id = mnt_id ,
217
- .param = last_mnt_id ,
218
- };
219
-
220
- return syscall (__NR_listmount , & req , list , num , flags );
221
- }
222
-
223
196
static void test_listmount_empty_root (void )
224
197
{
225
198
ssize_t res ;
226
199
const unsigned int size = 32 ;
227
200
uint64_t list [size ];
228
201
229
- res = listmount (LSMT_ROOT , 0 , list , size , 0 );
202
+ res = listmount (LSMT_ROOT , 0 , 0 , list , size , 0 );
230
203
if (res == -1 ) {
231
204
ksft_test_result_fail ("listmount: %s\n" , strerror (errno ));
232
205
return ;
@@ -251,7 +224,7 @@ static void test_statmount_zero_mask(void)
251
224
struct statmount sm ;
252
225
int ret ;
253
226
254
- ret = statmount (root_id , 0 , & sm , sizeof (sm ), 0 );
227
+ ret = statmount (root_id , 0 , 0 , & sm , sizeof (sm ), 0 );
255
228
if (ret == -1 ) {
256
229
ksft_test_result_fail ("statmount zero mask: %s\n" ,
257
230
strerror (errno ));
@@ -277,7 +250,7 @@ static void test_statmount_mnt_basic(void)
277
250
int ret ;
278
251
uint64_t mask = STATMOUNT_MNT_BASIC ;
279
252
280
- ret = statmount (root_id , mask , & sm , sizeof (sm ), 0 );
253
+ ret = statmount (root_id , 0 , mask , & sm , sizeof (sm ), 0 );
281
254
if (ret == -1 ) {
282
255
ksft_test_result_fail ("statmount mnt basic: %s\n" ,
283
256
strerror (errno ));
@@ -337,7 +310,7 @@ static void test_statmount_sb_basic(void)
337
310
struct statx sx ;
338
311
struct statfs sf ;
339
312
340
- ret = statmount (root_id , mask , & sm , sizeof (sm ), 0 );
313
+ ret = statmount (root_id , 0 , mask , & sm , sizeof (sm ), 0 );
341
314
if (ret == -1 ) {
342
315
ksft_test_result_fail ("statmount sb basic: %s\n" ,
343
316
strerror (errno ));
@@ -498,14 +471,14 @@ static void test_statmount_string(uint64_t mask, size_t off, const char *name)
498
471
exactsize = sm -> size ;
499
472
shortsize = sizeof (* sm ) + i ;
500
473
501
- ret = statmount (root_id , mask , sm , exactsize , 0 );
474
+ ret = statmount (root_id , 0 , mask , sm , exactsize , 0 );
502
475
if (ret == -1 ) {
503
476
ksft_test_result_fail ("statmount exact size: %s\n" ,
504
477
strerror (errno ));
505
478
goto out ;
506
479
}
507
480
errno = 0 ;
508
- ret = statmount (root_id , mask , sm , shortsize , 0 );
481
+ ret = statmount (root_id , 0 , mask , sm , shortsize , 0 );
509
482
if (ret != -1 || errno != EOVERFLOW ) {
510
483
ksft_test_result_fail ("should have failed with EOVERFLOW: %s\n" ,
511
484
strerror (errno ));
@@ -533,7 +506,7 @@ static void test_listmount_tree(void)
533
506
if (res == -1 )
534
507
return ;
535
508
536
- num = res = listmount (LSMT_ROOT , 0 , list , size , 0 );
509
+ num = res = listmount (LSMT_ROOT , 0 , 0 , list , size , 0 );
537
510
if (res == -1 ) {
538
511
ksft_test_result_fail ("listmount: %s\n" , strerror (errno ));
539
512
return ;
@@ -545,7 +518,7 @@ static void test_listmount_tree(void)
545
518
}
546
519
547
520
for (i = 0 ; i < size - step ;) {
548
- res = listmount (LSMT_ROOT , i ? list2 [i - 1 ] : 0 , list2 + i , step , 0 );
521
+ res = listmount (LSMT_ROOT , 0 , i ? list2 [i - 1 ] : 0 , list2 + i , step , 0 );
549
522
if (res == -1 )
550
523
ksft_test_result_fail ("short listmount: %s\n" ,
551
524
strerror (errno ));
@@ -577,11 +550,11 @@ int main(void)
577
550
int ret ;
578
551
uint64_t all_mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC |
579
552
STATMOUNT_PROPAGATE_FROM | STATMOUNT_MNT_ROOT |
580
- STATMOUNT_MNT_POINT | STATMOUNT_FS_TYPE ;
553
+ STATMOUNT_MNT_POINT | STATMOUNT_FS_TYPE | STATMOUNT_MNT_NS_ID ;
581
554
582
555
ksft_print_header ();
583
556
584
- ret = statmount (0 , 0 , NULL , 0 , 0 );
557
+ ret = statmount (0 , 0 , 0 , NULL , 0 , 0 );
585
558
assert (ret == -1 );
586
559
if (errno == ENOSYS )
587
560
ksft_exit_skip ("statmount() syscall not supported\n" );
0 commit comments