Skip to content

Commit

Permalink
tst_creat_unlinked(): Add missing mode argument
Browse files Browse the repository at this point in the history
The open() syscall requires the mode parameter if O_CREAT flag is used.
Add the missing mode parameter to the tst_creat_unlinked() helper function.

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Petr Vorel <[email protected]>
Signed-off-by: Martin Doucha <[email protected]>
[ pvorel: rebased ]
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
mdoucha authored and pevik committed Dec 13, 2024
1 parent f491b34 commit 73cc67a
Show file tree
Hide file tree
Showing 31 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion include/tst_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ void tst_set_max_runtime(int max_runtime);
* Create and open a random file inside the given dir path.
* It unlinks the file after opening and return file descriptor.
*/
int tst_creat_unlinked(const char *path, int flags);
int tst_creat_unlinked(const char *path, int flags, mode_t mode);

/*
* Returns path to the test temporary directory root (TMPDIR).
Expand Down
4 changes: 2 additions & 2 deletions lib/tst_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ static void prepare_and_mount_hugetlb_fs(void)
mntpoint_mounted = 1;
}

int tst_creat_unlinked(const char *path, int flags)
int tst_creat_unlinked(const char *path, int flags, mode_t mode)
{
char template[PATH_MAX];
int len, c, range;
Expand All @@ -1120,7 +1120,7 @@ int tst_creat_unlinked(const char *path, int flags)
}

flags |= O_CREAT|O_EXCL|O_RDWR;
fd = SAFE_OPEN(template, flags);
fd = SAFE_OPEN(template, flags, mode);
SAFE_UNLINK(template);
return fd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void run_test(void)
int err;
unsigned long free_initial, free_after, free_after_delete;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);

free_initial = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void run_test(void)
free_initial = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
max_iterations = MIN(free_initial, MAX_PAGES_TO_USE);

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);

/* First preallocate file with max_iterations pages */
err = fallocate(fd, 0, 0, hpage_size * max_iterations);
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void run_test(void)
static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void run_test(void)
static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
huge_fd = tst_creat_unlinked(MNTPOINT, 0);
huge_fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void run_test(unsigned int test_type)
static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
huge_fd = tst_creat_unlinked(MNTPOINT, 0);
huge_fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void run_test(void)
static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
huge_fd = tst_creat_unlinked(MNTPOINT, 0);
huge_fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
4 changes: 2 additions & 2 deletions testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static int kernel_has_private_reservations(void)
void *p;

read_meminfo_huge(&t, &f, &r, &s);
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);

p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);

Expand Down Expand Up @@ -182,7 +182,7 @@ static int map_(int s, int hpages, int flags, char *desc, int line)
{
long et, ef, er, es;

map_fd[s] = tst_creat_unlinked(MNTPOINT, 0);
map_fd[s] = tst_creat_unlinked(MNTPOINT, 0, 0600);
map_size[s] = hpages * hpage_size;
map_addr[s] = SAFE_MMAP(NULL, map_size[s], PROT_READ|PROT_WRITE, flags,
map_fd[s], 0);
Expand Down
4 changes: 2 additions & 2 deletions testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static void run_test(void)
void *p;
char buf[IOSZ] __attribute__((aligned(IOSZ)));

fd = tst_creat_unlinked(MNTPOINT, 0);
nfd = tst_creat_unlinked(NORMAL_PATH, O_DIRECT);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
nfd = tst_creat_unlinked(NORMAL_PATH, O_DIRECT, 0600);
p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
memcpy(p, P0, 8);

Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void run_test(void)
void *p;
unsigned long initial_rsvd, map_rsvd, fadvise_rsvd, end_rsvd;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);

initial_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd);
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static void setup(void)
tst_brk(TCONF, "Machine must be >32 bit");
if (hpage_size > FOURGB)
tst_brk(TCONF, "Huge page size is too large");
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void setup(void)
tst_brk(TCONF, "Machine must be >32 bit");
if (hpage_size > FOURGB)
tst_brk(TCONF, "Huge page size is too large");
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void run_test(void)
SAFE_SIGACTION(SIGBUS, &sa, NULL);
SAFE_SIGACTION(SIGSEGV, &sa, NULL);

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);

for (i = 0; i < NUM_REPETITIONS; i++)
if (test_once(fd))
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void run_test(void)
void *p;
unsigned long initial_rsvd, map_rsvd, madvise_rsvd, end_rsvd;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);

initial_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd);
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void setup(void)
tst_brk(TCONF, "Huge page size is too large");
if (TRUNCATE_POINT % hpage_size)
tst_brk(TCONF, "Truncation point is not aligned to huge page size");
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static void setup(void)
{
hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
page_size = getpagesize();
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static void setup(void)
{
page_size = getpagesize();
hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void run_test(unsigned int i)
void *p;
struct tcase *tc = &tcases[i];

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
p = SAFE_MMAP(0, hpage_size, PROT_READ|PROT_WRITE, tc->flags, fd, 0);

ret = mlock(p, hpage_size);
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static void run_test(void)
static void setup(void)
{
hpage_size = tst_get_hugepage_size();
fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void run_test(unsigned int iter)
char pattern = 'A';
size_t size = NR_HUGEPAGES*hpage_size;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
m = SAFE_MMAP(NULL, size, (PROT_READ|PROT_WRITE), MAP_SHARED, fd, 0);

for (i = 0; i < NR_HUGEPAGES; i++) {
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static void setup(void)
hpage_size = tst_get_hugepage_size();
SAFE_SIGACTION(SIGSEGV, &sa, NULL);

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
addr = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
memset(addr, 0, hpage_size);
SAFE_MUNMAP(addr, hpage_size);
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void run_test(void)
long p_size, q_size;
int ret;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
ret = init_slice_boundary(fd);
if (ret)
goto cleanup;
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void run_test(void)
void *p;
int ret;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
p = map_align(3*hpage_size, hpage_size);

SAFE_MUNMAP(p, hpage_size);
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void run_test(void)
void *p;
int ret;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
p = SAFE_MMAP(NULL, 3*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

SAFE_MUNMAP(p, hpage_size);
Expand Down
4 changes: 2 additions & 2 deletions testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ static void run_test(void)
static void setup(void)
{
hpage_size = tst_get_hugepage_size();
fd1 = tst_creat_unlinked(MNTPOINT, 0);
fd2 = tst_creat_unlinked(MNTPOINT, 0);
fd1 = tst_creat_unlinked(MNTPOINT, 0, 0600);
fd2 = tst_creat_unlinked(MNTPOINT, 0, 0600);
}

static void cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void run_test(void)

initial_resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
p = SAFE_MMAP(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

q = SAFE_MMAP(NULL, hpage_size,
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void run_test(void)
unsigned int *pl, *ql;
unsigned long i;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
fd, 0);

Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void run_test(void)
void *p;
unsigned long initial_rsvd, map_rsvd, readahead_rsvd, end_rsvd;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
initial_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);

p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void run_test(void)
unsigned long *pl, *ql;
unsigned long i;

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
fd, 0);

Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/mem/hugetlb/hugemmap/hugemmap34.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void setup(void)
if (r.rlim_cur != RLIM_INFINITY)
tst_brk(TCONF, "Stack rlimit must be 'unlimited'");

fd = tst_creat_unlinked(MNTPOINT, 0);
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);

/* shared memory to pass a (void *) from child process */
shared_area = SAFE_MMAP(0, getpagesize(), PROT_READ|PROT_WRITE,
Expand Down

0 comments on commit 73cc67a

Please sign in to comment.