|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 7 of 9] xenpaging: move pagefile filedescriptor into struct xenpaging
# HG changeset patch
# User Olaf Hering <olaf@xxxxxxxxx>
# Date 1329769124 -3600
# Node ID c137d7bd207b7b21d69bd6470be285023a4c2baf
# Parent e4b7da7e355998a404252777c274e8e149ce7a63
xenpaging: move pagefile filedescriptor into struct xenpaging
Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
diff -r e4b7da7e3559 -r c137d7bd207b tools/xenpaging/xenpaging.c
--- a/tools/xenpaging/xenpaging.c
+++ b/tools/xenpaging/xenpaging.c
@@ -448,6 +448,14 @@ static struct xenpaging *xenpaging_init(
goto err;
}
+ /* Open file */
+ paging->fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
+ if ( paging->fd < 0 )
+ {
+ PERROR("failed to open file");
+ goto err;
+ }
+
return paging;
err:
@@ -562,7 +570,7 @@ static void put_response(struct mem_even
* Returns 0 on successful evict
* Returns > 0 if gfn can not be evicted
*/
-static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn,
int fd, int slot)
+static int xenpaging_evict_page(struct xenpaging *paging, unsigned long gfn,
int slot)
{
xc_interface *xch = paging->xc_handle;
void *page;
@@ -593,7 +601,7 @@ static int xenpaging_evict_page(struct x
}
/* Copy page */
- ret = write_page(fd, page, slot);
+ ret = write_page(paging->fd, page, slot);
if ( ret < 0 )
{
PERROR("Error copying page %lx", gfn);
@@ -670,7 +678,7 @@ static int xenpaging_resume_page(struct
return ret;
}
-static int xenpaging_populate_page(struct xenpaging *paging, unsigned long
gfn, int fd, int i)
+static int xenpaging_populate_page(struct xenpaging *paging, unsigned long
gfn, int i)
{
xc_interface *xch = paging->xc_handle;
int ret;
@@ -679,7 +687,7 @@ static int xenpaging_populate_page(struc
DPRINTF("populate_page < gfn %lx pageslot %d\n", gfn, i);
/* Read page */
- ret = read_page(fd, paging_buffer, i);
+ ret = read_page(paging->fd, paging_buffer, i);
if ( ret != 0 )
{
PERROR("Error reading page");
@@ -738,7 +746,7 @@ static void resume_pages(struct xenpagin
* Returns 0 on successful evict
* Returns > 0 if no gfn can be evicted
*/
-static int evict_victim(struct xenpaging *paging, int fd, int slot)
+static int evict_victim(struct xenpaging *paging, int slot)
{
xc_interface *xch = paging->xc_handle;
unsigned long gfn;
@@ -771,7 +779,7 @@ static int evict_victim(struct xenpaging
goto out;
}
- ret = xenpaging_evict_page(paging, gfn, fd, slot);
+ ret = xenpaging_evict_page(paging, gfn, slot);
if ( ret < 0 )
goto out;
}
@@ -791,7 +799,7 @@ static int evict_victim(struct xenpaging
* Returns 0 if no gfn can be evicted
* Returns > 0 on successful evict
*/
-static int evict_pages(struct xenpaging *paging, int fd, int num_pages)
+static int evict_pages(struct xenpaging *paging, int num_pages)
{
xc_interface *xch = paging->xc_handle;
int rc, slot, num = 0;
@@ -802,7 +810,7 @@ static int evict_pages(struct xenpaging
if ( paging->slot_to_gfn[slot] )
continue;
- rc = evict_victim(paging, fd, slot);
+ rc = evict_victim(paging, slot);
if ( rc )
{
num = rc < 0 ? -1 : num;
@@ -826,10 +834,6 @@ int main(int argc, char *argv[])
int rc;
xc_interface *xch;
- int open_flags = O_CREAT | O_TRUNC | O_RDWR;
- mode_t open_mode = S_IRUSR | S_IWUSR;
- int fd;
-
/* Initialise domain paging */
paging = xenpaging_init(argc, argv);
if ( paging == NULL )
@@ -841,14 +845,6 @@ int main(int argc, char *argv[])
DPRINTF("starting %s for domain_id %u with pagefile %s\n", argv[0],
paging->mem_event.domain_id, filename);
- /* Open file */
- fd = open(filename, open_flags, open_mode);
- if ( fd < 0 )
- {
- perror("failed to open file");
- return 2;
- }
-
/* ensure that if we get a signal, we'll do cleanup, then exit */
act.sa_handler = close_handler;
act.sa_flags = 0;
@@ -911,7 +907,7 @@ int main(int argc, char *argv[])
else
{
/* Populate the page */
- if ( xenpaging_populate_page(paging, req.gfn, fd, slot) <
0 )
+ if ( xenpaging_populate_page(paging, req.gfn, slot) < 0 )
{
ERROR("Error populating page %"PRIx64"", req.gfn);
goto out;
@@ -1005,7 +1001,7 @@ int main(int argc, char *argv[])
paging->use_poll_timeout = 0;
num = 42;
}
- if ( evict_pages(paging, fd, num) < 0 )
+ if ( evict_pages(paging, num) < 0 )
goto out;
}
/* Resume some pages if target not reached */
@@ -1033,7 +1029,7 @@ int main(int argc, char *argv[])
DPRINTF("xenpaging got signal %d\n", interrupted);
out:
- close(fd);
+ close(paging->fd);
unlink_pagefile();
/* Tear down domain paging */
diff -r e4b7da7e3559 -r c137d7bd207b tools/xenpaging/xenpaging.h
--- a/tools/xenpaging/xenpaging.h
+++ b/tools/xenpaging/xenpaging.h
@@ -50,6 +50,7 @@ struct xenpaging {
int *gfn_to_slot;
struct mem_event mem_event;
+ int fd;
/* number of pages for which data structures were allocated */
int max_pages;
int num_paged_out;
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |