FreeBSD kernel /amd64 XEN device code
blkfront.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/module.h>
#include <sys/sysctl.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <machine/vmparam.h>
#include <xen/xen-os.h>
#include <xen/hypervisor.h>
#include <xen/xen_intr.h>
#include <xen/gnttab.h>
#include <contrib/xen/grant_table.h>
#include <contrib/xen/io/protocols.h>
#include <xen/xenbus/xenbusvar.h>
#include <machine/_inttypes.h>
#include <geom/geom_disk.h>
#include <dev/xen/blkfront/block.h>
#include "xenbus_if.h"
Include dependency graph for blkfront.c:

Go to the source code of this file.

Macros

#define DPRINTK(fmt, args...)
 
#define XBD_SECTOR_SHFT   9
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void xbd_closing (device_t)
 
static void xbd_startio (struct xbd_softc *sc)
 
static MALLOC_DEFINE (M_XENBLOCKFRONT, "xbd", "Xen Block Front driver data")
 
 SYSCTL_NODE (_hw, OID_AUTO, xbd, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "xbd driver parameters")
 
 SYSCTL_INT (_hw_xbd, OID_AUTO, xbd_enable_indirect, CTLFLAG_RDTUN, &xbd_enable_indirect, 0, "Enable xbd indirect segments")
 
static void xbd_freeze (struct xbd_softc *sc, xbd_flag_t xbd_flag)
 
static void xbd_thaw (struct xbd_softc *sc, xbd_flag_t xbd_flag)
 
static void xbd_cm_freeze (struct xbd_softc *sc, struct xbd_command *cm, xbdc_flag_t cm_flag)
 
static void xbd_cm_thaw (struct xbd_softc *sc, struct xbd_command *cm)
 
static void xbd_flush_requests (struct xbd_softc *sc)
 
static void xbd_free_command (struct xbd_command *cm)
 
static void xbd_mksegarray (bus_dma_segment_t *segs, int nsegs, grant_ref_t *gref_head, int otherend_id, int readonly, grant_ref_t *sg_ref, struct blkif_request_segment *sg)
 
static void xbd_queue_cb (void *arg, bus_dma_segment_t *segs, int nsegs, int error)
 
static int xbd_queue_request (struct xbd_softc *sc, struct xbd_command *cm)
 
static void xbd_restart_queue_callback (void *arg)
 
static struct xbd_commandxbd_bio_command (struct xbd_softc *sc)
 
static void xbd_bio_complete (struct xbd_softc *sc, struct xbd_command *cm)
 
static void xbd_int (void *xsc)
 
static void xbd_quiesce (struct xbd_softc *sc)
 
static void xbd_dump_complete (struct xbd_command *cm)
 
static int xbd_dump (void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
 
static int xbd_open (struct disk *dp)
 
static int xbd_close (struct disk *dp)
 
static int xbd_ioctl (struct disk *dp, u_long cmd, void *addr, int flag, struct thread *td)
 
static void xbd_strategy (struct bio *bp)
 
static int xbd_alloc_ring (struct xbd_softc *sc)
 
static void xbd_free_ring (struct xbd_softc *sc)
 
static int xbd_feature_string (struct xbd_softc *sc, char *features, size_t len)
 
static int xbd_sysctl_features (SYSCTL_HANDLER_ARGS)
 
static void xbd_setup_sysctl (struct xbd_softc *xbd)
 
static void xbd_vdevice_to_unit (uint32_t vdevice, int *unit, const char **name)
 
int xbd_instance_create (struct xbd_softc *sc, blkif_sector_t sectors, int vdevice, uint16_t vdisk_info, unsigned long sector_size, unsigned long phys_sector_size)
 
static void xbd_free (struct xbd_softc *sc)
 
static void xbd_initialize (struct xbd_softc *sc)
 
static void xbd_connect (struct xbd_softc *sc)
 
static int xbd_probe (device_t dev)
 
static int xbd_attach (device_t dev)
 
static int xbd_detach (device_t dev)
 
static int xbd_suspend (device_t dev)
 
static int xbd_resume (device_t dev)
 
static void xbd_backend_changed (device_t dev, XenbusState backend_state)
 
 DRIVER_MODULE (xbd, xenbusb_front, xbd_driver, xbd_devclass, 0, 0)
 

Variables

static int xbd_enable_indirect = 1
 
static device_method_t xbd_methods []
 
static driver_t xbd_driver
 
devclass_t xbd_devclass
 

Macro Definition Documentation

◆ DPRINTK

#define DPRINTK (   fmt,
  args... 
)

Definition at line 76 of file blkfront.c.

◆ XBD_SECTOR_SHFT

#define XBD_SECTOR_SHFT   9

Definition at line 79 of file blkfront.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DRIVER_MODULE()

DRIVER_MODULE ( xbd  ,
xenbusb_front  ,
xbd_driver  ,
xbd_devclass  ,
,
 
)

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_XENBLOCKFRONT  ,
"xbd"  ,
"Xen Block Front driver data"   
)
static

◆ SYSCTL_INT()

SYSCTL_INT ( _hw_xbd  ,
OID_AUTO  ,
xbd_enable_indirect  ,
CTLFLAG_RDTUN  ,
xbd_enable_indirect,
,
"Enable xbd indirect segments"   
)

◆ SYSCTL_NODE()

SYSCTL_NODE ( _hw  ,
OID_AUTO  ,
xbd  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"xbd driver parameters"   
)

◆ xbd_alloc_ring()

static int xbd_alloc_ring ( struct xbd_softc sc)
static

Definition at line 750 of file blkfront.c.

References xbd_softc::xbd_dev, xbd_int(), xbd_softc::xbd_ring, xbd_softc::xbd_ring_pages, xbd_softc::xbd_ring_ref, xbd_softc::xen_intr_handle, and xs_printf().

Referenced by xbd_initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_attach()

static int xbd_attach ( device_t  dev)
static

◆ xbd_backend_changed()

static void xbd_backend_changed ( device_t  dev,
XenbusState  backend_state 
)
static

Callback received when the backend's state changes.

Definition at line 1591 of file blkfront.c.

References DPRINTK, xbd_closing(), xbd_connect(), xbd_softc::xbd_disk, xbd_initialize(), and xbd_softc::xbd_users.

Here is the call graph for this function:

◆ xbd_bio_command()

◆ xbd_bio_complete()

static void xbd_bio_complete ( struct xbd_softc sc,
struct xbd_command cm 
)
static

Definition at line 460 of file blkfront.c.

References xbd_command::cm_bp, xbd_command::cm_status, and xbd_free_command().

Referenced by xbd_int().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_close()

static int xbd_close ( struct disk *  dp)
static

Definition at line 687 of file blkfront.c.

References xbd_closing(), xbd_softc::xbd_dev, xbd_softc::xbd_flags, and xbd_softc::xbd_users.

Referenced by xbd_instance_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_closing()

static void xbd_closing ( device_t  dev)
static

Handle the change of state of the backend to Closing. We must delete our device-layer structures now, to ensure that writes are flushed through to the backend. Once this is done, we can switch to Closed in acknowledgement.

Definition at line 1418 of file blkfront.c.

References DPRINTK, and xbd_softc::xbd_disk.

Referenced by xbd_backend_changed(), and xbd_close().

Here is the caller graph for this function:

◆ xbd_cm_freeze()

static void xbd_cm_freeze ( struct xbd_softc sc,
struct xbd_command cm,
xbdc_flag_t  cm_flag 
)
static

Definition at line 116 of file blkfront.c.

References xbd_command::cm_flags, xbd_freeze(), XBDCF_FROZEN, and XBDF_NONE.

Referenced by xbd_queue_request(), and xbd_startio().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_cm_thaw()

static void xbd_cm_thaw ( struct xbd_softc sc,
struct xbd_command cm 
)
static

Definition at line 126 of file blkfront.c.

References xbd_command::cm_flags, xbd_thaw(), XBDCF_FROZEN, and XBDF_NONE.

Referenced by xbd_int().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_connect()

◆ xbd_detach()

static int xbd_detach ( device_t  dev)
static

Definition at line 1529 of file blkfront.c.

References DPRINTK, xbd_free(), and xbd_softc::xbd_io_lock.

Here is the call graph for this function:

◆ xbd_dump()

◆ xbd_dump_complete()

static void xbd_dump_complete ( struct xbd_command cm)
static

Definition at line 589 of file blkfront.c.

References xbd_enqueue_cm(), and XBD_Q_COMPLETE.

Referenced by xbd_dump().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_feature_string()

static int xbd_feature_string ( struct xbd_softc sc,
char *  features,
size_t  len 
)
static

Definition at line 837 of file blkfront.c.

References xbd_softc::xbd_flags, XBDF_BARRIER, XBDF_DISCARD, XBDF_FLUSH, and XBDF_PERSISTENT.

Referenced by xbd_instance_create(), and xbd_sysctl_features().

Here is the caller graph for this function:

◆ xbd_flush_requests()

static void xbd_flush_requests ( struct xbd_softc sc)
inlinestatic

Definition at line 136 of file blkfront.c.

References notify(), xbd_softc::xbd_ring, and xbd_softc::xen_intr_handle.

Referenced by xbd_queue_cb(), and xbd_startio().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_free()

◆ xbd_free_command()

static void xbd_free_command ( struct xbd_command cm)
static

Definition at line 147 of file blkfront.c.

References xbd_command::cm_bp, xbd_command::cm_complete, xbd_command::cm_flags, xbd_command::cm_sc, xbd_enqueue_cm(), XBD_Q_FREE, XBD_Q_NONE, xbd_thaw(), XBDCF_INITIALIZER, XBDCF_Q_MASK, and XBDF_CM_SHORTAGE.

Referenced by xbd_bio_complete(), xbd_connect(), xbd_dump(), xbd_int(), and xbd_queue_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_free_ring()

static void xbd_free_ring ( struct xbd_softc sc)
static

Definition at line 818 of file blkfront.c.

References gnttab_end_foreign_access_ref(), xbd_softc::xbd_ring, xbd_softc::xbd_ring_pages, and xbd_softc::xbd_ring_ref.

Referenced by xbd_free().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_freeze()

static void xbd_freeze ( struct xbd_softc sc,
xbd_flag_t  xbd_flag 
)
static

Definition at line 92 of file blkfront.c.

References xbd_softc::xbd_flags, xbd_softc::xbd_qfrozen_cnt, and XBDF_NONE.

Referenced by xbd_bio_command(), and xbd_cm_freeze().

Here is the caller graph for this function:

◆ xbd_initialize()

static void xbd_initialize ( struct xbd_softc sc)
static

Definition at line 1096 of file blkfront.c.

References xbd_alloc_ring(), xbd_softc::xbd_dev, XBD_MAX_REQUESTS, xbd_softc::xbd_max_requests, XBD_MAX_RING_PAGES, xbd_softc::xbd_ring_pages, xbd_softc::xen_intr_handle, xs_printf(), and xs_scanf().

Referenced by xbd_backend_changed(), and xbd_resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_instance_create()

int xbd_instance_create ( struct xbd_softc sc,
blkif_sector_t  sectors,
int  vdevice,
uint16_t  vdisk_info,
unsigned long  sector_size,
unsigned long  phys_sector_size 
)

Definition at line 1000 of file blkfront.c.

References xbd_close(), xbd_softc::xbd_dev, xbd_softc::xbd_disk, xbd_dump(), xbd_feature_string(), xbd_softc::xbd_flags, xbd_ioctl(), xbd_softc::xbd_max_request_size, xbd_open(), xbd_strategy(), xbd_softc::xbd_unit, xbd_vdevice_to_unit(), XBDF_BARRIER, and XBDF_FLUSH.

Referenced by xbd_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_int()

◆ xbd_ioctl()

static int xbd_ioctl ( struct disk *  dp,
u_long  cmd,
void *  addr,
int  flag,
struct thread *  td 
)
static

Definition at line 708 of file blkfront.c.

Referenced by xbd_instance_create().

Here is the caller graph for this function:

◆ xbd_mksegarray()

static void xbd_mksegarray ( bus_dma_segment_t *  segs,
int  nsegs,
grant_ref_t *  gref_head,
int  otherend_id,
int  readonly,
grant_ref_t *  sg_ref,
struct blkif_request_segment *  sg 
)
static

Definition at line 162 of file blkfront.c.

References gnttab_claim_grant_reference(), gnttab_grant_foreign_access_ref(), and XBD_SECTOR_SHFT.

Referenced by xbd_queue_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_open()

static int xbd_open ( struct disk *  dp)
static

Definition at line 672 of file blkfront.c.

References xbd_softc::xbd_flags, xbd_softc::xbd_users, and XBDF_OPEN.

Referenced by xbd_instance_create().

Here is the caller graph for this function:

◆ xbd_probe()

static int xbd_probe ( device_t  dev)
static

Definition at line 1436 of file blkfront.c.

References xs_read().

Here is the call graph for this function:

◆ xbd_queue_cb()

◆ xbd_queue_request()

static int xbd_queue_request ( struct xbd_softc sc,
struct xbd_command cm 
)
static

Definition at line 296 of file blkfront.c.

References xbd_command::cm_bp, xbd_command::cm_data, xbd_command::cm_datalen, xbd_command::cm_map, xbd_cm_freeze(), xbd_softc::xbd_io_dmat, xbd_queue_cb(), and XBDCF_ASYNC_MAPPING.

Referenced by xbd_startio().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_quiesce()

static void xbd_quiesce ( struct xbd_softc sc)
static

Quiesce the disk writes for a dump file before allowing the next buffer.

Definition at line 566 of file blkfront.c.

References xbd_int(), XBD_Q_BUSY, xbd_queue_length(), and xbd_softc::xbd_ring.

Referenced by xbd_dump().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_restart_queue_callback()

static void xbd_restart_queue_callback ( void *  arg)
static

Definition at line 321 of file blkfront.c.

References xbd_softc::xbd_io_lock, xbd_startio(), xbd_thaw(), and XBDF_GNT_SHORTAGE.

Referenced by xbd_bio_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_resume()

static int xbd_resume ( device_t  dev)
static

Definition at line 1571 of file blkfront.c.

References DPRINTK, xbd_free(), xbd_initialize(), xbd_softc::xbd_state, XBD_STATE_CONNECTED, and xen_suspend_cancelled.

Here is the call graph for this function:

◆ xbd_setup_sysctl()

static void xbd_setup_sysctl ( struct xbd_softc xbd)
static

Definition at line 894 of file blkfront.c.

References xbd_softc::xbd_dev, xbd_softc::xbd_max_request_segments, xbd_softc::xbd_max_request_size, xbd_softc::xbd_max_requests, xbd_softc::xbd_ring_pages, and xbd_sysctl_features().

Referenced by xbd_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_startio()

static void xbd_startio ( struct xbd_softc sc)
static

◆ xbd_strategy()

static void xbd_strategy ( struct bio *  bp)
static

Definition at line 723 of file blkfront.c.

References xbd_enqueue_bio(), xbd_softc::xbd_io_lock, and xbd_startio().

Referenced by xbd_instance_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_suspend()

static int xbd_suspend ( device_t  dev)
static

Definition at line 1542 of file blkfront.c.

References xbd_softc::xbd_cm_q, xbd_softc::xbd_io_lock, XBD_Q_BUSY, xbd_queue_length(), xbd_softc::xbd_state, and XBD_STATE_SUSPENDED.

Here is the call graph for this function:

◆ xbd_sysctl_features()

static int xbd_sysctl_features ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 876 of file blkfront.c.

References xbd_feature_string().

Referenced by xbd_setup_sysctl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xbd_thaw()

static void xbd_thaw ( struct xbd_softc sc,
xbd_flag_t  xbd_flag 
)
static

Definition at line 102 of file blkfront.c.

References xbd_softc::xbd_flags, xbd_softc::xbd_qfrozen_cnt, and XBDF_NONE.

Referenced by xbd_cm_thaw(), xbd_free_command(), xbd_int(), and xbd_restart_queue_callback().

Here is the caller graph for this function:

◆ xbd_vdevice_to_unit()

static void xbd_vdevice_to_unit ( uint32_t  vdevice,
int *  unit,
const char **  name 
)
static

Definition at line 937 of file blkfront.c.

Referenced by xbd_attach(), and xbd_instance_create().

Here is the caller graph for this function:

Variable Documentation

◆ xbd_devclass

devclass_t xbd_devclass

Definition at line 1649 of file blkfront.c.

◆ xbd_driver

driver_t xbd_driver
static
Initial value:
= {
"xbd",
sizeof(struct xbd_softc),
}
static device_method_t xbd_methods[]
Definition: blkfront.c:1629

Definition at line 1644 of file blkfront.c.

◆ xbd_enable_indirect

int xbd_enable_indirect = 1
static

Definition at line 84 of file blkfront.c.

Referenced by xbd_connect().

◆ xbd_methods

device_method_t xbd_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, xbd_probe),
DEVMETHOD(device_attach, xbd_attach),
DEVMETHOD(device_detach, xbd_detach),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD(device_suspend, xbd_suspend),
DEVMETHOD(device_resume, xbd_resume),
DEVMETHOD(xenbus_otherend_changed, xbd_backend_changed),
{ 0, 0 }
}
static int xbd_resume(device_t dev)
Definition: blkfront.c:1571
static int xbd_detach(device_t dev)
Definition: blkfront.c:1529
static void xbd_backend_changed(device_t dev, XenbusState backend_state)
Definition: blkfront.c:1591
static int xbd_attach(device_t dev)
Definition: blkfront.c:1485
static int xbd_suspend(device_t dev)
Definition: blkfront.c:1542
static int xbd_probe(device_t dev)
Definition: blkfront.c:1436

Definition at line 1629 of file blkfront.c.