Files
xen/tools/libxc/xc_minios.c
T
Ian Campbell b701ccc8ab tools: Remove xc_map_foreign_batch
It can trivially be replaced by xc_map_foreign_pages which is the
interface I want to move to going forward (by standardising on _bulk
but handling err=NULL as _pages does).

The callers of _batch are checking a mixture of a NULL return or
looking to see if the top nibble of the (usually sole) mfn they pass
has been modified to be non-zero to detect errors. _pages never
modifies the mfn it was given (it's const) and returns NULL on
failure, so adjust the error handling where necessary. Some callers
use a copy of the mfn array, for reuse on failure with _batch, which
is no longer necessary as _pages doesn't modify the array, however I
haven't cleaned that up here.

This reduces the twist maze of xc_map_foreign_* by one, which will be
useful when trying to come up with an underlying stable interface.

NetBSD and Solaris implemented xc_map_foreign_bulk in terms of
xc_map_foreign_batch via a compat layer, so xc_map_foreign_batch
becomes an internal osdep for them.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
Cc: George Dunlap <george.dunlap@eu.citrix.com>
2016-01-22 12:23:34 +00:00

140 lines
3.4 KiB
C

/******************************************************************************
*
* Copyright 2007-2008 Samuel Thibault <samuel.thibault@eu.citrix.com>.
* All rights reserved.
* Use is subject to license terms.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; If not, see <http://www.gnu.org/licenses/>.
*/
#undef NDEBUG
#include <mini-os/types.h>
#include <mini-os/os.h>
#include <mini-os/mm.h>
#include <mini-os/lib.h>
#include <xen/memory.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <inttypes.h>
#include <malloc.h>
#include "xc_private.h"
void minios_interface_close_fd(int fd);
extern void minios_interface_close_fd(int fd);
int osdep_privcmd_open(xc_interface *xch)
{
int fd = alloc_fd(FTYPE_XC);
if ( fd == -1)
return -1;
xch->privcmdfd = fd;
return 0;
}
int osdep_privcmd_close(xc_interface *xch)
{
int fd = xch->privcmdfd;
return close(fd);
}
void minios_interface_close_fd(int fd)
{
files[fd].type = FTYPE_NONE;
}
void *xc_map_foreign_bulk(xc_interface *xch,
uint32_t dom, int prot,
const xen_pfn_t *arr, int *err, unsigned int num)
{
unsigned long pt_prot = 0;
if (prot & PROT_READ)
pt_prot = L1_PROT_RO;
if (prot & PROT_WRITE)
pt_prot = L1_PROT;
return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
}
void *xc_map_foreign_range(xc_interface *xch,
uint32_t dom,
int size, int prot,
unsigned long mfn)
{
unsigned long pt_prot = 0;
if (prot & PROT_READ)
pt_prot = L1_PROT_RO;
if (prot & PROT_WRITE)
pt_prot = L1_PROT;
assert(!(size % getpagesize()));
return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot);
}
void *xc_map_foreign_ranges(xc_interface *xch,
uint32_t dom,
size_t size, int prot, size_t chunksize,
privcmd_mmap_entry_t entries[], int nentries)
{
unsigned long *mfns;
int i, j, n;
unsigned long pt_prot = 0;
void *ret;
if (prot & PROT_READ)
pt_prot = L1_PROT_RO;
if (prot & PROT_WRITE)
pt_prot = L1_PROT;
mfns = malloc((size / XC_PAGE_SIZE) * sizeof(*mfns));
n = 0;
for (i = 0; i < nentries; i++)
for (j = 0; j < chunksize / XC_PAGE_SIZE; j++)
mfns[n++] = entries[i].mfn + j;
ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
free(mfns);
return ret;
}
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
{
if (flush)
fsync(fd);
}
void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
{
return memalign(alignment, size);
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/