public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: DAN LI <li.dan@cn.fujitsu.com>
Cc: LTP list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH v2] mmap/mmap12.c: new case to test MAP_POPULATE of mmap
Date: Tue, 25 Jun 2013 16:17:27 +0200	[thread overview]
Message-ID: <20130625141727.GK31268@rei> (raw)
In-Reply-To: <51C95F37.3000409@cn.fujitsu.com>

Hi!
> +static int page_check(void)
> +{
> +	int pid;
> +	int ret;
> +	int pm;
> +	int num_pages;
> +	long index;
> +	off_t offset;
> +	size_t page_sz;
> +	char maps_dev[PATHLEN];
> +	char pagemap_dev[PATHLEN];
> +	char line[LINELEN];
> +	FILE *maps;
> +	unsigned long vm_start;
> +	unsigned long vm_end;
> +	unsigned long long pagemap;
> +
> +	page_sz = getpagesize();
> +
> +	pid = getpid();
> +	sprintf(maps_dev, "/proc/%d/maps", pid);
> +	sprintf(pagemap_dev, "/proc/%d/pagemap", pid);

Just use "/proc/self/maps" and "/proc/self/pagemap" instead.

> +	maps = fopen(maps_dev, "r");
> +	if (maps == NULL)
> +		tst_brkm(TFAIL | TERRNO, NULL, "Open dev maps failed");
> +
> +	while (fgets(line, LINELEN, maps) != NULL)
> +		if (strstr(line, TEMPFILE) != NULL)
> +			break;
> +
> +	ret = sscanf(line, "%lX-%lX", &vm_start, &vm_end);
> +	if (ret != 2)
> +		tst_brkm(TFAIL | TERRNO, NULL, "Get address space failed");

This part of the code does not cope with unlikely condition that
TEMPFILE is missing from /proc/self/maps we should fail the test in this
case with proper error message.

> +	num_pages = (vm_end - vm_start) / page_sz;
> +	index = (vm_start / page_sz) * sizeof(unsigned long long);
> +
> +	pm = open(pagemap_dev, O_RDONLY);
> +	if (pm == -1)
> +		tst_brkm(TFAIL | TERRNO, NULL, "Open dev pagemap failed");
> +
> +	offset = lseek(pm, index, SEEK_SET);
> +	if (offset != index)
> +		tst_brkm(TFAIL | TERRNO, NULL, "Reposition offset failed");
> +
> +	while (num_pages > 0) {
> +		ret = read(pm, &pagemap, sizeof(unsigned long long));
> +		if (ret < 0)
> +			tst_brkm(TFAIL | TERRNO, NULL, "Read pagemap failed");
> +		/*
> +		 * Check if the page is present.
> +		 */
> +		if (!(pagemap & (1ULL<<63))) {
> +			close(pm);
> +			fclose(maps);
> +			return 1;

I would perpahs be more verbose here and go over all of the pages and
list these that are not mapped, but that is a minor nitpick. 

> +		}
> +		num_pages--;
> +	}
> +
> +	close(pm);
> +	fclose(maps);
> +
> +	return 0;
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

       reply	other threads:[~2013-06-25 14:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <51C95F37.3000409@cn.fujitsu.com>
2013-06-25 14:17 ` chrubis [this message]
     [not found]   ` <51CA495D.9090500@cn.fujitsu.com>
2013-06-27 12:35     ` [LTP] [PATCH v2] mmap/mmap12.c: new case to test MAP_POPULATE of mmap chrubis
     [not found] ` <804366117.1964429.1372157275604.JavaMail.root@redhat.com>
2013-06-26  1:36   ` DAN LI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130625141727.GK31268@rei \
    --to=chrubis@suse.cz \
    --cc=li.dan@cn.fujitsu.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox