FreeBSD kernel /amd64 XEN device code
|
Device driver supporting the vending of block storage from a FreeBSD domain to other domains. More...
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
#include <sys/fcntl.h>
#include <sys/filedesc.h>
#include <sys/kdb.h>
#include <sys/module.h>
#include <sys/namei.h>
#include <sys/proc.h>
#include <sys/rman.h>
#include <sys/taskqueue.h>
#include <sys/types.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <sys/bitstring.h>
#include <sys/sdt.h>
#include <geom/geom.h>
#include <machine/_inttypes.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/vm_kern.h>
#include <xen/xen-os.h>
#include <xen/blkif.h>
#include <xen/gnttab.h>
#include <xen/xen_intr.h>
#include <contrib/xen/event_channel.h>
#include <contrib/xen/grant_table.h>
#include <xen/xenbus/xenbusvar.h>
Go to the source code of this file.
Data Structures | |
struct | xbb_xen_reqlist |
struct | xbb_xen_req |
Object tracking an in-flight I/O from a Xen VBD consumer. More... | |
struct | xbb_ring_config |
Configuration data for the shared memory request ring used to communicate with the front-end client of this this driver. More... | |
struct | xbb_sg |
Structure used to memoize information about a per-request scatter-gather list. More... | |
struct | xbb_dev_data |
struct | xbb_file_data |
union | xbb_backend_data |
struct | xbb_softc |
Macros | |
#define | XBB_MAX_RING_PAGES 32 |
#define | XBB_MAX_REQUESTS __CONST_RING_SIZE(blkif, PAGE_SIZE * XBB_MAX_RING_PAGES) |
#define | XBB_USE_BOUNCE_BUFFERS |
Define to force all I/O to be performed on memory owned by the backend device, with a copy-in/out to the remote domain's memory. More... | |
#define | DPRINTF(fmt, args...) do {} while(0) |
#define | XBB_MAX_REQUEST_SIZE MIN(128 * 1024, BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) |
#define | XBB_MAX_SEGMENTS_PER_REQUEST |
#define | XBB_MAX_SEGMENTS_PER_REQLIST XBB_MAX_SEGMENTS_PER_REQUEST |
Typedefs | |
typedef int(* | xbb_dispatch_t) (struct xbb_softc *xbb, struct xbb_xen_reqlist *reqlist, int operation, int flags) |
Enumerations | |
enum | xbb_reqlist_flags { XBB_REQLIST_NONE = 0x00 , XBB_REQLIST_MAPPED = 0x01 } |
enum | xbb_flag_t { XBBF_READ_ONLY = 0x01 , XBBF_RING_CONNECTED = 0x02 , XBBF_RESOURCE_SHORTAGE = 0x04 , XBBF_SHUTDOWN = 0x08 , XBBF_IN_SHUTDOWN = 0x10 } |
enum | xbb_type { XBB_TYPE_NONE = 0x00 , XBB_TYPE_DISK = 0x01 , XBB_TYPE_FILE = 0x02 } |
Functions | |
__FBSDID ("$FreeBSD$") | |
static | MALLOC_DEFINE (M_XENBLOCKBACK, "xbbd", "Xen Block Back Driver Data") |
Define to enable rudimentary request logging to the console. More... | |
static void | xbb_attach_failed (struct xbb_softc *xbb, int err, const char *fmt,...) __attribute__((format(printf |
static void static int | xbb_shutdown (struct xbb_softc *xbb) |
STAILQ_HEAD (xbb_xen_req_list, xbb_xen_req) | |
STAILQ_HEAD (xbb_xen_reqlist_list, xbb_xen_reqlist) | |
SLIST_HEAD (xbb_xen_req_slist, xbb_xen_req) | |
static struct xbb_xen_req * | xbb_get_req (struct xbb_softc *xbb) |
static void | xbb_release_req (struct xbb_softc *xbb, struct xbb_xen_req *req) |
static void | xbb_release_reqs (struct xbb_softc *xbb, struct xbb_xen_req_list *req_list, int nreqs) |
static uint8_t * | xbb_reqlist_vaddr (struct xbb_xen_reqlist *reqlist, int pagenr, int sector) |
static uint8_t * | xbb_reqlist_bounce_addr (struct xbb_xen_reqlist *reqlist, int pagenr, int sector) |
static uint8_t * | xbb_reqlist_ioaddr (struct xbb_xen_reqlist *reqlist, int pagenr, int sector) |
static uintptr_t | xbb_get_gntaddr (struct xbb_xen_reqlist *reqlist, int pagenr, int sector) |
static uint8_t * | xbb_get_kva (struct xbb_softc *xbb, int nr_pages) |
static void | xbb_free_kva (struct xbb_softc *xbb, uint8_t *kva_ptr, int nr_pages) |
static void | xbb_unmap_reqlist (struct xbb_xen_reqlist *reqlist) |
static struct xbb_xen_reqlist * | xbb_get_reqlist (struct xbb_softc *xbb) |
static void | xbb_release_reqlist (struct xbb_softc *xbb, struct xbb_xen_reqlist *reqlist, int wakeup) |
static int | xbb_get_resources (struct xbb_softc *xbb, struct xbb_xen_reqlist **reqlist, blkif_request_t *ring_req, RING_IDX ring_idx) |
static void | xbb_queue_response (struct xbb_softc *xbb, struct xbb_xen_req *req, int status) |
static void | xbb_push_responses (struct xbb_softc *xbb, int *run_taskqueue, int *notify) |
static void | xbb_complete_reqlist (struct xbb_softc *xbb, struct xbb_xen_reqlist *reqlist) |
static void | xbb_bio_done (struct bio *bio) |
static int | xbb_dispatch_io (struct xbb_softc *xbb, struct xbb_xen_reqlist *reqlist) |
static __inline int | xbb_count_sects (blkif_request_t *ring_req) |
static void | xbb_run_queue (void *context, int pending) |
static int | xbb_filter (void *arg) |
SDT_PROVIDER_DEFINE (xbb) | |
SDT_PROBE_DEFINE1 (xbb, kernel, xbb_dispatch_dev, flush, "int") | |
SDT_PROBE_DEFINE3 (xbb, kernel, xbb_dispatch_dev, read, "int", "uint64_t", "uint64_t") | |
SDT_PROBE_DEFINE3 (xbb, kernel, xbb_dispatch_dev, write, "int", "uint64_t", "uint64_t") | |
static int | xbb_dispatch_dev (struct xbb_softc *xbb, struct xbb_xen_reqlist *reqlist, int operation, int bio_flags) |
SDT_PROBE_DEFINE1 (xbb, kernel, xbb_dispatch_file, flush, "int") | |
SDT_PROBE_DEFINE3 (xbb, kernel, xbb_dispatch_file, read, "int", "uint64_t", "uint64_t") | |
SDT_PROBE_DEFINE3 (xbb, kernel, xbb_dispatch_file, write, "int", "uint64_t", "uint64_t") | |
static int | xbb_dispatch_file (struct xbb_softc *xbb, struct xbb_xen_reqlist *reqlist, int operation, int flags) |
static void | xbb_close_backend (struct xbb_softc *xbb) |
static int | xbb_open_dev (struct xbb_softc *xbb) |
static int | xbb_open_file (struct xbb_softc *xbb) |
static int | xbb_open_backend (struct xbb_softc *xbb) |
static void | xbb_free_communication_mem (struct xbb_softc *xbb) |
static int | xbb_disconnect (struct xbb_softc *xbb) |
static int | xbb_connect_ring (struct xbb_softc *xbb) |
static int | xbb_alloc_communication_mem (struct xbb_softc *xbb) |
static int | xbb_collect_frontend_info (struct xbb_softc *xbb) |
static int | xbb_alloc_requests (struct xbb_softc *xbb) |
static int | xbb_alloc_request_lists (struct xbb_softc *xbb) |
static int | xbb_publish_backend_info (struct xbb_softc *xbb) |
static void | xbb_connect (struct xbb_softc *xbb) |
static int | xbb_probe (device_t dev) |
static void | xbb_setup_sysctl (struct xbb_softc *xbb) |
static void | xbb_attach_disk (device_t dev) |
static void | xbb_attach_cb (struct xs_watch *watch, const char **vec, unsigned int len) |
static int | xbb_attach (device_t dev) |
static int | xbb_detach (device_t dev) |
static int | xbb_suspend (device_t dev) |
static int | xbb_resume (device_t dev) |
static void | xbb_frontend_changed (device_t dev, XenbusState frontend_state) |
DRIVER_MODULE (xbbd, xenbusb_back, xbb_driver, xbb_devclass, 0, 0) | |
Variables | |
static device_method_t | xbb_methods [] |
static driver_t | xbb_driver |
devclass_t | xbb_devclass |
Device driver supporting the vending of block storage from a FreeBSD domain to other domains.
Definition in file blkback.c.
#define XBB_MAX_REQUEST_SIZE MIN(128 * 1024, BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) |
#define XBB_MAX_REQUESTS __CONST_RING_SIZE(blkif, PAGE_SIZE * XBB_MAX_RING_PAGES) |
#define XBB_MAX_RING_PAGES 32 |
#define XBB_MAX_SEGMENTS_PER_REQLIST XBB_MAX_SEGMENTS_PER_REQUEST |
The maximum number of ring pages that we can allow per request list. We limit this to the maximum number of segments per request, because that is already a reasonable number of segments to aggregate. This number should never be smaller than XBB_MAX_SEGMENTS_PER_REQUEST, because that would leave situations where we can't dispatch even one large request.
#define XBB_MAX_SEGMENTS_PER_REQUEST |
The maximum number of segments (within a request header and accompanying segment blocks) per request we will allow in a negotiated block-front/back communication channel.
#define XBB_USE_BOUNCE_BUFFERS |
Define to force all I/O to be performed on memory owned by the backend device, with a copy-in/out to the remote domain's memory.
This driver uses Xen's grant table API to gain access to the memory of the remote domains it serves. When our domain is operating in PV mode, the grant table mechanism directly updates our domain's page table entries to point to the physical pages of the remote domain. This scheme guarantees that blkback and the backing devices it uses can safely perform DMA operations to satisfy requests. In HVM mode, Xen may use a HW IOMMU to insure that our domain cannot DMA to pages owned by another domain. As of Xen 4.0, IOMMU mappings for HVM guests are not updated via the grant table API. For this reason, in HVM mode, we must bounce all requests into memory that is mapped into our domain at domain startup and thus has valid IOMMU mappings.
typedef int(* xbb_dispatch_t) (struct xbb_softc *xbb, struct xbb_xen_reqlist *reqlist, int operation, int flags) |
enum xbb_flag_t |
Per-instance connection state flags.
Enumerator | |
---|---|
XBBF_READ_ONLY | The front-end requested a read-only mount of the back-end device/file. |
XBBF_RING_CONNECTED | Communication with the front-end has been established. |
XBBF_RESOURCE_SHORTAGE | Front-end requests exist in the ring and are waiting for xbb_xen_req objects to free up. |
XBBF_SHUTDOWN | Connection teardown in progress. |
XBBF_IN_SHUTDOWN | A thread is already performing shutdown processing. |
enum xbb_reqlist_flags |
enum xbb_type |
__FBSDID | ( | "$FreeBSD$" | ) |
DRIVER_MODULE | ( | xbbd | , |
xenbusb_back | , | ||
xbb_driver | , | ||
xbb_devclass | , | ||
0 | , | ||
0 | |||
) |
|
static |
Define to enable rudimentary request logging to the console.
Custom malloc type for all driver allocations.
SDT_PROBE_DEFINE1 | ( | xbb | , |
kernel | , | ||
xbb_dispatch_dev | , | ||
flush | , | ||
"int" | |||
) |
SDT_PROBE_DEFINE1 | ( | xbb | , |
kernel | , | ||
xbb_dispatch_file | , | ||
flush | , | ||
"int" | |||
) |
SDT_PROBE_DEFINE3 | ( | xbb | , |
kernel | , | ||
xbb_dispatch_dev | , | ||
read | , | ||
"int" | , | ||
"uint64_t" | , | ||
"uint64_t" | |||
) |
SDT_PROBE_DEFINE3 | ( | xbb | , |
kernel | , | ||
xbb_dispatch_dev | , | ||
write | , | ||
"int" | , | ||
"uint64_t" | , | ||
"uint64_t" | |||
) |
SDT_PROBE_DEFINE3 | ( | xbb | , |
kernel | , | ||
xbb_dispatch_file | , | ||
read | , | ||
"int" | , | ||
"uint64_t" | , | ||
"uint64_t" | |||
) |
SDT_PROBE_DEFINE3 | ( | xbb | , |
kernel | , | ||
xbb_dispatch_file | , | ||
write | , | ||
"int" | , | ||
"uint64_t" | , | ||
"uint64_t" | |||
) |
SDT_PROVIDER_DEFINE | ( | xbb | ) |
SLIST_HEAD | ( | xbb_xen_req_slist | , |
xbb_xen_req | |||
) |
STAILQ_HEAD | ( | xbb_xen_req_list | , |
xbb_xen_req | |||
) |
STAILQ_HEAD | ( | xbb_xen_reqlist_list | , |
xbb_xen_reqlist | |||
) |
|
static |
Size KVA and pseudo-physical address allocations based on negotiated values for the size and number of I/O requests, and the size of our communication ring.
xbb | Per-instance xbb configuration structure. |
These address spaces are used to dynamically map pages in the front-end's domain into our own.
Definition at line 2987 of file blkback.c.
References xbb_softc::dev, DPRINTF, xbb_softc::gnt_base_addr, xbb_softc::kva, xbb_softc::kva_free, xbb_softc::kva_size, xbb_softc::max_request_segments, xbb_softc::max_requests, xbb_softc::pseudo_phys_res, xbb_softc::pseudo_phys_res_id, xbb_softc::reqlist_kva_pages, xbb_softc::reqlist_kva_size, xbb_softc::ring_config, xbb_ring_config::ring_pages, and xenmem_alloc().
Referenced by xbb_connect().
|
static |
Definition at line 3187 of file blkback.c.
References xbb_xen_reqlist::bounce, xbb_softc::dev, xbb_xen_reqlist::gnt_handles, xbb_softc::max_reqlist_segments, xbb_softc::max_reqlist_size, xbb_softc::max_requests, xbb_softc::reqlist_free_stailq, xbb_softc::reqlist_pending_stailq, xbb_softc::request_lists, and xbb_xen_reqlist::xbb.
Referenced by xbb_connect().
|
static |
Allocate per-request data structures given request size and number information negotiated with the front-end.
xbb | Per-instance xbb configuration structure. |
Definition at line 3160 of file blkback.c.
References xbb_softc::dev, xbb_softc::max_requests, xbb_softc::request_free_stailq, and xbb_softc::requests.
Referenced by xbb_connect().
|
static |
Attach to a XenBus device that has been claimed by our probe routine.
dev | NewBus device object representing this Xen Block Back instance. |
Definition at line 3718 of file blkback.c.
References xbb_softc::dev, DPRINTF, xbb_softc::hotplug_done, xbb_softc::hotplug_watch, xbb_softc::io_task, xbb_softc::lock, xbb_softc::otherend_id, xbb_attach_cb(), xbb_attach_disk(), xbb_attach_failed(), XBB_MAX_RING_PAGES, xbb_run_queue(), xs_join(), xs_printf(), and xs_register_watch().
|
static |
Definition at line 3674 of file blkback.c.
References xbb_softc::dev, xbb_softc::dev_mode, xbb_softc::dev_name, xbb_softc::dev_type, xbb_softc::hotplug_done, xbb_attach_disk(), xbb_attach_failed(), xs_gather(), and xs_unregister_watch().
Referenced by xbb_attach().
|
static |
Definition at line 3597 of file blkback.c.
References xbb_softc::dev, xbb_softc::dev_mode, xbb_softc::dev_name, xbb_softc::flags, xbb_softc::hotplug_done, xbb_softc::io_taskqueue, xbb_softc::sector_size, xbb_attach_failed(), xbb_connect(), xbb_open_backend(), xbb_setup_sysctl(), xbb_softc::xbb_stats, xbb_softc::xbb_stats_in, XBBF_READ_ONLY, and xs_printf().
Referenced by xbb_attach(), and xbb_attach_cb().
|
static |
Report an attach time error to the console and Xen, and cleanup this instance by forcing immediate detach processing.
xbb | Per-instance xbb configuration structure. |
err | Errno describing the error. |
fmt | Printf style format and arguments |
Definition at line 3461 of file blkback.c.
References xbb_softc::dev, xbb_softc::lock, xbb_shutdown(), xs_printf(), and xs_vprintf().
Referenced by xbb_attach(), xbb_attach_cb(), and xbb_attach_disk().
|
static |
Completion handler for buffer I/O requests issued by the device backend driver.
bio | The buffer I/O request on which to perform completion processing. |
Definition at line 1469 of file blkback.c.
References xbb_xen_reqlist::bounce, xbb_softc::dev, xbb_softc::dev_name, DPRINTF, xbb_xen_reqlist::kva, xbb_xen_reqlist::pendcnt, xbb_xen_reqlist::residual_512b_sectors, xbb_xen_reqlist::status, xbb_xen_reqlist::xbb, and xbb_complete_reqlist().
Referenced by xbb_dispatch_dev().
|
static |
Close and cleanup any backend device/file specific state for this block back instance.
xbb | Per-instance xbb configuration structure. |
Definition at line 2469 of file blkback.c.
References xbb_softc::backend, xbb_dev_data::cdev, xbb_file_data::cred, xbb_dev_data::csw, xbb_backend_data::dev, xbb_softc::dev_name, xbb_dev_data::dev_ref, xbb_softc::device_type, DPRINTF, xbb_backend_data::file, xbb_softc::flags, xbb_softc::vn, XBB_TYPE_DISK, XBB_TYPE_FILE, XBB_TYPE_NONE, and XBBF_READ_ONLY.
Referenced by xbb_detach(), and xbb_open_backend().
|
static |
Collect front-end information from the XenStore.
xbb | Per-instance xbb configuration structure. |
Definition at line 3029 of file blkback.c.
References xbb_softc::abi, xbb_softc::dev, xbb_ring_config::evtchn, xbb_softc::max_request_segments, xbb_softc::max_request_size, xbb_softc::max_requests, xbb_softc::ring_config, xbb_ring_config::ring_pages, xbb_ring_config::ring_ref, XBB_MAX_RING_PAGES, xs_gather(), and xs_scanf().
Referenced by xbb_connect().
|
static |
Complete a request list.
xbb | Per-instance xbb configuration structure. |
reqlist | Allocated internal request list structure. |
Definition at line 1388 of file blkback.c.
References xbb_xen_reqlist::contig_req_list, xbb_xen_reqlist::ds_t0, xbb_xen_reqlist::ds_tag_type, xbb_xen_reqlist::ds_trans_type, xbb_xen_reqlist::flags, xbb_softc::io_task, xbb_softc::io_taskqueue, xbb_softc::lock, notify(), xbb_xen_reqlist::residual_512b_sectors, xbb_xen_reqlist::status, xbb_push_responses(), xbb_queue_response(), xbb_release_reqlist(), XBB_REQLIST_MAPPED, xbb_softc::xbb_stats, xbb_softc::xbb_stats_in, xbb_unmap_reqlist(), and xbb_softc::xen_intr_handle.
Referenced by xbb_bio_done(), xbb_dispatch_file(), and xbb_dispatch_io().
|
static |
Connect to our blkfront peer now that it has completed publishing its configuration into the XenStore.
xbb | Per-instance xbb configuration structure. |
Definition at line 3308 of file blkback.c.
References xbb_softc::dev, xbb_softc::flags, xbb_softc::hotplug_done, xbb_softc::max_reqlist_segments, xbb_softc::max_reqlist_size, xbb_softc::max_request_segments, xbb_softc::max_requests, xbb_alloc_communication_mem(), xbb_alloc_request_lists(), xbb_alloc_requests(), xbb_collect_frontend_info(), xbb_connect_ring(), xbb_disconnect(), XBB_MAX_SEGMENTS_PER_REQLIST, and xbb_publish_backend_info().
Referenced by xbb_attach_disk(), and xbb_frontend_changed().
|
static |
Map shared memory ring into domain local address space, initialize ring control structures, and bind an interrupt to the event channel used to notify us of ring changes.
xbb | Per-instance xbb configuration structure. |
Definition at line 2854 of file blkback.c.
References xbb_softc::abi, xbb_ring_config::bus_addr, xbb_softc::dev, DPRINTF, xbb_ring_config::evtchn, xbb_softc::flags, xbb_ring_config::gnt_addr, xbb_softc::gnt_base_addr, xbb_ring_config::handle, xbb_softc::kva, xbb_softc::kva_size, xbb_softc::otherend_id, xbb_softc::ring_config, xbb_ring_config::ring_pages, xbb_ring_config::ring_ref, xbb_softc::rings, xbb_ring_config::va, xbb_disconnect(), xbb_filter(), XBB_MAX_RING_PAGES, XBBF_RING_CONNECTED, and xbb_softc::xen_intr_handle.
Referenced by xbb_connect().
|
static |
Definition at line 1785 of file blkback.c.
Referenced by xbb_run_queue().
|
static |
Detach from a block back device instance.
dev | NewBus device object representing this Xen Block Back instance. |
Definition at line 3816 of file blkback.c.
References xbb_softc::dev, xbb_softc::dev_mode, xbb_softc::dev_name, xbb_softc::dev_type, DPRINTF, xbb_softc::io_taskqueue, xbb_softc::lock, xbb_close_backend(), xbb_shutdown(), xbb_softc::xbb_stats, and xbb_softc::xbb_stats_in.
|
static |
Cleanup all inter-domain communication mechanisms.
xbb | Per-instance xbb configuration structure. |
Definition at line 2775 of file blkback.c.
References xbb_softc::active_request_count, xbb_xen_reqlist::bounce, xbb_ring_config::bus_addr, DPRINTF, xbb_softc::flags, xbb_ring_config::gnt_addr, xbb_xen_reqlist::gnt_handles, xbb_ring_config::handle, xbb_softc::io_task, xbb_softc::io_taskqueue, xbb_softc::lock, xbb_softc::request_lists, xbb_softc::requests, xbb_softc::ring_config, xbb_ring_config::ring_pages, xbb_xen_reqlist::xbb, xbb_free_communication_mem(), XBB_MAX_RING_PAGES, XBBF_RING_CONNECTED, and xbb_softc::xen_intr_handle.
Referenced by xbb_connect(), xbb_connect_ring(), and xbb_shutdown().
|
static |
Backend handler for character device access.
xbb | Per-instance xbb configuration structure. |
reqlist | Allocated internal request list structure. |
operation | BIO_* I/O operation code. |
bio_flags | Additional bio_flag data to pass to any generated bios (e.g. BIO_ORDERED).. |
Definition at line 2059 of file blkback.c.
References xbb_softc::backend, xbb_xen_reqlist::bounce, xbb_dev_data::cdev, xbb_dev_data::csw, xbb_backend_data::dev, xbb_softc::dev, DPRINTF, xbb_sg::first_sect, xbb_xen_reqlist::kva, xbb_sg::last_sect, xbb_xen_reqlist::nr_segments, xbb_sg::nsect, xbb_softc::otherend_id, xbb_xen_reqlist::pendcnt, xbb_softc::sector_size, xbb_softc::sector_size_shift, xbb_xen_reqlist::starting_sector_number, xbb_bio_done(), xbb_dispatch_dev(), XBB_MAX_SEGMENTS_PER_REQLIST, xbb_reqlist_ioaddr(), and xbb_softc::xbb_sgs.
Referenced by xbb_dispatch_dev(), and xbb_open_dev().
|
static |
Backend handler for file access.
xbb | Per-instance xbb configuration structure. |
reqlist | Allocated internal request list. |
operation | BIO_* I/O operation code. |
flags | Additional bio_flag data to pass to any generated bios (e.g. BIO_ORDERED).. |
Definition at line 2235 of file blkback.c.
References xbb_softc::backend, xbb_file_data::cred, xbb_softc::dev, xbb_backend_data::file, xbb_sg::first_sect, xbb_sg::last_sect, xbb_xen_reqlist::nr_segments, xbb_sg::nsect, xbb_file_data::saved_xiovecs, xbb_softc::sector_size_shift, xbb_xen_reqlist::starting_sector_number, xbb_xen_reqlist::status, xbb_softc::vn, xbb_complete_reqlist(), xbb_dispatch_file(), xbb_reqlist_ioaddr(), xbb_reqlist_vaddr(), xbb_softc::xbb_sgs, xbb_file_data::xiovecs, and xbb_file_data::xiovecs_vaddr.
Referenced by xbb_dispatch_file(), and xbb_open_file().
|
static |
Parse a blkif request into an internal request structure and send it to the backend for processing.
xbb | Per-instance xbb configuration structure. |
reqlist | Allocated internal request list structure. |
This routine performs the backend common aspects of request parsing including compiling an internal request structure, parsing the S/G list and any secondary ring requests in which they may reside, and the mapping of front-end I/O pages into our domain.
Definition at line 1547 of file blkback.c.
References xbb_xen_reqlist::contig_req_list, xbb_softc::dev, xbb_softc::dev_name, xbb_softc::disable_flush, xbb_softc::dispatch_io, DPRINTF, xbb_xen_reqlist::ds_t0, xbb_xen_reqlist::ds_tag_type, xbb_xen_reqlist::ds_trans_type, xbb_sg::first_sect, xbb_xen_reqlist::flags, xbb_softc::flags, xbb_softc::flush_count, xbb_softc::flush_interval, xbb_ring_config::gnt_addr, xbb_xen_reqlist::gnt_handles, xbb_xen_reqlist::kva, xbb_sg::last_sect, xbb_softc::maps, xbb_softc::max_request_segments, xbb_softc::media_num_sectors, xbb_xen_reqlist::nr_segments, xbb_sg::nsect, xbb_xen_reqlist::operation, xbb_softc::otherend_id, xbb_softc::ring_config, xbb_softc::sector_size, xbb_softc::sector_size_shift, xbb_xen_reqlist::starting_sector_number, xbb_xen_reqlist::status, xbb_xen_reqlist::xbb, xbb_complete_reqlist(), xbb_get_gntaddr(), xbb_get_kva(), XBB_MAX_SEGMENTS_PER_REQLIST, XBB_REQLIST_MAPPED, xbb_softc::xbb_sgs, xbb_softc::xbb_stats, and XBBF_READ_ONLY.
Referenced by xbb_run_queue().
|
static |
Interrupt handler bound to the shared ring's event channel.
arg | Callback argument registerd during event channel binding - the xbb_softc for this instance. |
Definition at line 2028 of file blkback.c.
References xbb_softc::io_task, and xbb_softc::io_taskqueue.
Referenced by xbb_connect_ring().
|
static |
Free dynamically allocated KVA or pseudo-physical address allocations.
xbb | Per-instance xbb configuration structure. |
Definition at line 2752 of file blkback.c.
References xbb_softc::dev, xbb_softc::gnt_base_addr, xbb_softc::kva, xbb_softc::kva_free, xbb_softc::pseudo_phys_res, xbb_softc::pseudo_phys_res_id, and xenmem_free().
Referenced by xbb_disconnect().
|
static |
Free allocated KVA.
xbb | Per-instance xbb configuration structure. |
kva_ptr | Pointer to allocated KVA region. |
nr_pages | Number of pages in the KVA region. |
Definition at line 1068 of file blkback.c.
References xbb_softc::kva, xbb_softc::kva_free, and xbb_softc::lock.
Referenced by xbb_release_reqlist().
|
static |
Handle state changes expressed via the XenStore by our front-end peer.
dev | NewBus device object representing this Xen Block Back instance. |
frontend_state | The new state of the front-end. |
Definition at line 3907 of file blkback.c.
References xbb_softc::dev, DPRINTF, xbb_softc::lock, xbb_connect(), and xbb_shutdown().
|
inlinestatic |
Given a page index and 512b sector offset within that page, calculate an offset into the local pseudo-physical address space used to map a front-end's request data into a request.
reqlist | The request list structure whose pseudo-physical region will be accessed. |
pagenr | The page index used to compute the pseudo-physical offset. |
sector | The 512b sector index used to compute the page relative pseudo-physical offset. |
Depending on configuration, this will either be a local bounce buffer or a pointer to the memory mapped in from the front-end domain for this request.
Definition at line 957 of file blkback.c.
References xbb_softc::gnt_base_addr, xbb_xen_reqlist::kva, xbb_softc::kva, and xbb_xen_reqlist::xbb.
Referenced by xbb_dispatch_io(), and xbb_unmap_reqlist().
|
static |
Get Kernel Virtual Address space for mapping requests.
xbb | Per-instance xbb configuration structure. |
nr_pages | Number of pages needed. |
check_only | If set, check for free KVA but don't allocate it. |
have_lock | If set, xbb lock is already held. |
Note: This should be unnecessary once we have either chaining or scatter/gather support for struct bio. At that point we'll be able to put multiple addresses and lengths in one bio/bio chain and won't need to map everything into one virtual segment.
Definition at line 984 of file blkback.c.
References xbb_softc::flags, xbb_softc::kva, xbb_softc::kva_free, xbb_softc::kva_shortages, xbb_softc::lock, xbb_softc::reqlist_kva_pages, xbb_softc::ring_config, xbb_ring_config::va, and XBBF_RESOURCE_SHORTAGE.
Referenced by xbb_dispatch_io().
|
inlinestatic |
Allocate an internal transaction tracking structure from the free pool.
xbb | Per-instance xbb configuration structure. |
Definition at line 823 of file blkback.c.
References xbb_softc::active_request_count, xbb_softc::lock, and xbb_softc::request_free_stailq.
Referenced by xbb_get_resources().
|
inlinestatic |
Allocate an internal transaction tracking structure from the free pool.
xbb | Per-instance xbb configuration structure. |
Definition at line 1118 of file blkback.c.
References xbb_xen_reqlist::contig_req_list, xbb_xen_reqlist::flags, xbb_xen_reqlist::kva, xbb_softc::lock, xbb_xen_reqlist::nr_segments, xbb_xen_reqlist::num_children, xbb_softc::reqlist_free_stailq, xbb_xen_reqlist::residual_512b_sectors, xbb_xen_reqlist::status, xbb_xen_reqlist::xbb, and XBB_REQLIST_NONE.
Referenced by xbb_get_resources().
|
static |
Request resources and do basic request setup.
xbb | Per-instance xbb configuration structure. |
reqlist | Pointer to reqlist pointer. |
ring_req | Pointer to a block ring request. |
ring_index | The ring index of this request. |
Definition at line 1192 of file blkback.c.
References xbb_softc::abi, xbb_softc::flags, xbb_softc::lock, xbb_xen_reqlist::operation, xbb_softc::reqlist_pending_stailq, xbb_softc::request_shortages, xbb_xen_reqlist::starting_sector_number, xbb_get_req(), xbb_get_reqlist(), xbb_release_req(), xbb_release_reqlist(), xbb_softc::xbb_stats_in, XBBF_RESOURCE_SHORTAGE, and XBBF_SHUTDOWN.
Referenced by xbb_run_queue().
|
static |
Open the backend provider for this connection.
xbb | Per-instance xbb configuration structure. |
Definition at line 2661 of file blkback.c.
References xbb_softc::dev, xbb_softc::dev_name, xbb_softc::device_type, DPRINTF, xbb_softc::flags, xbb_softc::media_num_sectors, xbb_softc::media_size, xbb_softc::sector_size, xbb_softc::sector_size_shift, xbb_softc::vn, xbb_close_backend(), xbb_open_dev(), xbb_open_file(), XBB_TYPE_DISK, and XBBF_READ_ONLY.
Referenced by xbb_attach_disk().
|
static |
Open a character device to be used for backend I/O.
xbb | Per-instance xbb configuration structure. |
Definition at line 2525 of file blkback.c.
References xbb_softc::backend, xbb_dev_data::cdev, xbb_dev_data::csw, xbb_backend_data::dev, xbb_softc::dev, xbb_softc::dev_name, xbb_dev_data::dev_ref, xbb_softc::device_type, xbb_softc::dispatch_io, xbb_softc::media_size, xbb_softc::sector_size, xbb_softc::vn, xbb_dispatch_dev(), and XBB_TYPE_DISK.
Referenced by xbb_open_backend().
|
static |
Open a file to be used for backend I/O.
xbb | Per-instance xbb configuration structure. |
Definition at line 2587 of file blkback.c.
References xbb_softc::backend, xbb_file_data::cred, xbb_softc::dev, xbb_softc::dev_name, xbb_softc::device_type, xbb_softc::dispatch_io, xbb_backend_data::file, xbb_softc::media_size, xbb_softc::sector_size, xbb_softc::vn, xbb_dispatch_file(), and XBB_TYPE_FILE.
Referenced by xbb_open_backend().
|
static |
|
static |
Supply information about the physical device to the frontend via XenBus.
xbb | Per-instance xbb configuration structure. |
Definition at line 3249 of file blkback.c.
References xbb_softc::dev, xbb_softc::flags, xbb_softc::media_num_sectors, xbb_softc::sector_size, XBBF_READ_ONLY, xs_printf(), xs_transaction_end(), and xs_transaction_start().
Referenced by xbb_connect().
|
static |
Send queued responses to blkif requests.
xbb | Per-instance xbb configuration structure. |
run_taskqueue | Flag that is set to 1 if the taskqueue should be run, 0 if it does not need to be run. |
notify | Flag that is set to 1 if the other end should be notified via irq, 0 if the other end should not be notified. |
Definition at line 1351 of file blkback.c.
References xbb_softc::lock, notify(), xbb_softc::reqs_completed, xbb_softc::reqs_queued_for_completion, and xbb_softc::rings.
Referenced by xbb_complete_reqlist().
|
static |
Create and queue a response to a blkif request.
xbb | Per-instance xbb configuration structure. |
req | The request structure to which to respond. |
status | The status code to report. See BLKIF_RSP_* in sys/contrib/xen/io/blkif.h. |
Definition at line 1286 of file blkback.c.
References xbb_softc::abi, xbb_softc::lock, xbb_softc::reqs_completed_with_error, xbb_softc::reqs_queued_for_completion, and xbb_softc::rings.
Referenced by xbb_complete_reqlist().
|
inlinestatic |
Return an allocated transaction tracking structure to the free pool.
xbb | Per-instance xbb configuration structure. |
req | The request structure to free. |
Definition at line 846 of file blkback.c.
References xbb_softc::active_request_count, xbb_softc::lock, and xbb_softc::request_free_stailq.
Referenced by xbb_get_resources().
|
inlinestatic |
Return an allocated transaction tracking structure to the free pool.
xbb | Per-instance xbb configuration structure. |
req | The request list structure to free. |
wakeup | If set, wakeup the work thread if freeing this reqlist during a resource shortage condition. |
Definition at line 1149 of file blkback.c.
References xbb_xen_reqlist::contig_req_list, xbb_softc::flags, xbb_softc::io_task, xbb_softc::io_taskqueue, xbb_xen_reqlist::kva, xbb_softc::lock, xbb_xen_reqlist::nr_segments, xbb_xen_reqlist::num_children, xbb_softc::reqlist_free_stailq, xbb_xen_reqlist::xbb, xbb_free_kva(), xbb_release_reqs(), xbb_shutdown(), XBBF_RESOURCE_SHORTAGE, and XBBF_SHUTDOWN.
Referenced by xbb_complete_reqlist(), and xbb_get_resources().
|
inlinestatic |
Return an xbb_xen_req_list of allocated xbb_xen_reqs to the free pool.
xbb | Per-instance xbb configuration structure. |
req_list | The list of requests to free. |
nreqs | The number of items in the list. |
Definition at line 865 of file blkback.c.
References xbb_softc::active_request_count, xbb_softc::lock, and xbb_softc::request_free_stailq.
Referenced by xbb_release_reqlist().
|
inlinestatic |
Given a page index and 512b sector offset within that page, calculate an offset into a request's local bounce memory region.
reqlist | The request structure whose bounce region will be accessed. |
pagenr | The page index used to compute the bounce offset. |
sector | The 512b sector index used to compute the page relative bounce offset. |
Definition at line 907 of file blkback.c.
References xbb_xen_reqlist::bounce.
Referenced by xbb_reqlist_ioaddr().
|
inlinestatic |
Given a page number and 512b sector offset within that page, calculate an offset into the request's memory region that the underlying backend device/file should use for I/O.
reqlist | The request structure whose I/O region will be accessed. |
pagenr | The page index used to compute the I/O offset. |
sector | The 512b sector index used to compute the page relative I/O offset. |
Depending on configuration, this will either be a local bounce buffer or a pointer to the memory mapped in from the front-end domain for this request.
Definition at line 930 of file blkback.c.
References xbb_reqlist_bounce_addr(), and xbb_reqlist_vaddr().
Referenced by xbb_dispatch_dev(), and xbb_dispatch_file().
|
inlinestatic |
Given a page index and 512b sector offset within that page, calculate an offset into a request's kva region.
reqlist | The request structure whose kva region will be accessed. |
pagenr | The page index used to compute the kva offset. |
sector | The 512b sector index used to compute the page relative kva offset. |
Definition at line 889 of file blkback.c.
References xbb_xen_reqlist::kva.
Referenced by xbb_dispatch_file(), and xbb_reqlist_ioaddr().
|
static |
|
static |
Process incoming requests from the shared communication ring in response to a signal on the ring's event channel.
context | Callback argument registerd during task initialization - the xbb_softc for this instance. |
pending | The number of taskqueue_enqueue events that have occurred since this handler was last run. |
Run so long as there is work to consume and the generation of a response will not overflow the ring.
Definition at line 1814 of file blkback.c.
References xbb_softc::abi, xbb_softc::forced_dispatch, xbb_softc::max_reqlist_segments, xbb_xen_reqlist::next_contig_sector, xbb_softc::no_coalesce_reqs, xbb_softc::normal_dispatch, xbb_xen_reqlist::nr_segments, xbb_xen_reqlist::operation, xbb_softc::reqlist_pending_stailq, xbb_softc::reqs_received, xbb_softc::rings, xbb_softc::total_dispatch, xbb_xen_reqlist::xbb, xbb_count_sects(), xbb_dispatch_io(), and xbb_get_resources().
Referenced by xbb_attach().
|
static |
Setup sysctl variables to control various Block Back parameters.
xbb | Xen Block Back softc. |
Definition at line 3512 of file blkback.c.
References xbb_softc::dev, xbb_softc::disable_flush, xbb_softc::flush_interval, xbb_softc::forced_dispatch, xbb_softc::kva_shortages, xbb_softc::max_request_segments, xbb_softc::max_request_size, xbb_softc::max_requests, xbb_softc::no_coalesce_reqs, xbb_softc::normal_dispatch, xbb_softc::reqs_completed, xbb_softc::reqs_completed_with_error, xbb_softc::reqs_queued_for_completion, xbb_softc::reqs_received, xbb_softc::request_shortages, xbb_softc::ring_config, xbb_ring_config::ring_pages, and xbb_softc::total_dispatch.
Referenced by xbb_attach_disk().
|
static |
Perform device shutdown functions.
xbb | Per-instance xbb configuration structure. |
Mark this instance as shutting down, wait for any active I/O on the backend device/file to drain, disconnect from the front-end, and notify any waiters (e.g. a thread invoking our detach method) that detach can now proceed.
Definition at line 3388 of file blkback.c.
References xbb_softc::dev, DPRINTF, xbb_softc::flags, xbb_softc::hotplug_watch, xbb_softc::lock, xbb_disconnect(), XBBF_IN_SHUTDOWN, XBBF_SHUTDOWN, and xs_unregister_watch().
Referenced by xbb_attach_failed(), xbb_detach(), xbb_frontend_changed(), and xbb_release_reqlist().
|
static |
Prepare this block back device for suspension of this VM.
dev | NewBus device object representing this Xen Block Back instance. |
Definition at line 3870 of file blkback.c.
References xbb_softc::dev.
|
static |
Unmap the front-end pages associated with this I/O request.
req | The request structure to unmap. |
Definition at line 1085 of file blkback.c.
References xbb_xen_reqlist::gnt_handles, xbb_xen_reqlist::nr_segments, xbb_get_gntaddr(), and XBB_MAX_SEGMENTS_PER_REQLIST.
Referenced by xbb_complete_reqlist().
|
static |
|
static |