u2mfn: add API to use specific u2mfn FD

This enable to get multiple pages (via u2mfn_alloc_kpage) - kernel module holds
pointer to it in per-FD struct, so the same FD can't be reused for the next request.

More elegant solution should involve kernel module modification (stored page
list or sth), but it is planed to replace this part of code with libxenvchan
(or even more generic version), so this temporary solution should be enough.
This commit is contained in:
Marek Marczykowski 2012-11-03 01:46:02 +01:00
parent 6b23655fb7
commit debcf6d24a
2 changed files with 38 additions and 18 deletions

View File

@ -31,11 +31,24 @@ static int u2mfn_fd = -1;
static int get_fd() static int get_fd()
{ {
if (u2mfn_fd == -1) { if (u2mfn_fd == -1)
u2mfn_fd = open("/proc/u2mfn", O_RDWR); u2mfn_fd = u2mfn_get_fd();
if (u2mfn_fd < 0) if (u2mfn_fd < 0)
return -1; return -1;
} return 0;
}
int u2mfn_get_fd()
{
return open("/proc/u2mfn", O_RDWR);
}
int u2mfn_get_mfn_for_page_with_fd(int fd, long va, int *mfn)
{
*mfn = ioctl(fd, U2MFN_GET_MFN_FOR_PAGE, va);
if (*mfn == -1)
return -1;
return 0; return 0;
} }
@ -43,7 +56,12 @@ int u2mfn_get_mfn_for_page(long va, int *mfn)
{ {
if (get_fd()) if (get_fd())
return -1; return -1;
*mfn = ioctl(u2mfn_fd, U2MFN_GET_MFN_FOR_PAGE, va); return u2mfn_get_mfn_for_page_with_fd(u2mfn_fd, va, mfn);
}
int u2mfn_get_last_mfn_with_fd(int fd, int *mfn)
{
*mfn = ioctl(fd, U2MFN_GET_LAST_MFN, 0);
if (*mfn == -1) if (*mfn == -1)
return -1; return -1;
@ -54,22 +72,20 @@ int u2mfn_get_last_mfn(int *mfn)
{ {
if (get_fd()) if (get_fd())
return -1; return -1;
return u2mfn_get_last_mfn_with_fd(u2mfn_fd, mfn);
*mfn = ioctl(u2mfn_fd, U2MFN_GET_LAST_MFN, 0);
if (*mfn == -1)
return -1;
return 0;
} }
char *u2mfn_alloc_kpage_with_fd(int fd)
{
char *ret;
ret =
mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return ret;
}
char *u2mfn_alloc_kpage() char *u2mfn_alloc_kpage()
{ {
char *ret;
if (get_fd()) if (get_fd())
return MAP_FAILED; return MAP_FAILED;
ret = return u2mfn_alloc_kpage_with_fd(u2mfn_fd);
mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, u2mfn_fd, 0);
return ret;
} }

View File

@ -19,6 +19,10 @@
* *
*/ */
int u2mfn_get_fd();
int u2mfn_get_mfn_for_page(long va, int *mfn) ; int u2mfn_get_mfn_for_page(long va, int *mfn) ;
int u2mfn_get_mfn_for_page_with_fd(int fd, long va, int *mfn) ;
int u2mfn_get_last_mfn(int *mfn) ; int u2mfn_get_last_mfn(int *mfn) ;
char *u2mfn_alloc_kpage(void) ; int u2mfn_get_last_mfn_with_fd(int fd, int *mfn) ;
char *u2mfn_alloc_kpage(void);
char *u2mfn_alloc_kpage_with_fd(int fd);