Re: [LTP] [PATCH 1/5] mremap01: Convert to new API

Cyril Hrubis <[email protected]>
Newsgroups it.linux.lists.ltp
Message-ID <anRz55OQe2cjL12R@rei>
Hi!
> -	/*
> -	 * Call mmap to map virtual memory (memsize bytes) from the
> -	 * beginning of temporary file (offset is 0) into memory.
> -	 */
> -	addr = mmap(0, memsize, PROT_WRITE, MAP_SHARED, fildes, 0);
> +	for (ind = 0; ind < newsize; ind++)
> +		addr[ind] = (char)ind;
>  
> -	/* Check for the return value of mmap() */
> -	if (addr == (char *)MAP_FAILED) {
> -		tst_brkm(TBROK, cleanup, "mmaping Failed on %s", TEMPFILE);
> -	}
> +	SAFE_MSYNC(addr, newsize, MS_SYNC);
>  
> -	/* Stretch the file to newsize of virtual memory block */
> -	if (lseek(fildes, (off_t) newsize, SEEK_SET) != (off_t) newsize) {
> -		tst_brkm(TBROK, cleanup, "lseek() to %d offset pos. Failed, "
> -			 "error=%d : %s", newsize, errno, strerror(errno));
> -	}
> +	if (verify_file())
> +		tst_res(TFAIL, "mremap()'d region did not sync to the file");
> +	else
> +		tst_res(TPASS, "Functionality of mremap() is correct");
>  
> -	/* Write one byte data into temporary file */
> -	if (write(fildes, "\0", 1) != 1) {
> -		tst_brkm(TBROK | TERRNO, cleanup, "writing to %s failed",
> -			 TEMPFILE);
> -	}

We should probably ftruncate(fd, 0) here so that we start with the same
state on -i 10.

> +	SAFE_MUNMAP(addr, newsize);
> +	addr = MAP_FAILED;

Can we patch SAFE_MUNMAP() to set the addr to MAP_FAILED as we do in
SAFE_CLOSE()?


Otherwise:
Reviewed-by: Cyril Hrubis <[email protected]>

-- 
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.