go-tcmu: github.com/coreos/go-tcmu Index | Files | Directories

package tcmu

import "github.com/coreos/go-tcmu"

tcmu is a package that connects to the TCM in Userspace kernel module, a part of the LIO stack. It provides the ability to emulate a SCSI storage device in pure Go.


Package Files

cmd_handler.go device.go offsets.go poll.go scsi_handler.go struct_access.go

func CachingModePage Uses

func CachingModePage(w io.Writer, wce bool)

func FixedString Uses

func FixedString(s string, length int) []byte

func GenerateSerial Uses

func GenerateSerial(name string) string

type DataSizes Uses

type DataSizes struct {
    VolumeSize int64
    BlockSize  int64

type DevReadyFunc Uses

type DevReadyFunc func(chan *SCSICmd, chan SCSIResponse) error

func MultiThreadedDevReady Uses

func MultiThreadedDevReady(h SCSICmdHandler, threads int) DevReadyFunc

func SingleThreadedDevReady Uses

func SingleThreadedDevReady(h SCSICmdHandler) DevReadyFunc

type Device Uses

type Device struct {
    // contains filtered or unexported fields

func OpenTCMUDevice Uses

func OpenTCMUDevice(devPath string, scsi *SCSIHandler) (*Device, error)

OpenTCMUDevice creates the virtual device based on the details in the SCSIHandler, eventually creating a device under devPath (eg, "/dev") with the file name scsi.VolumeName. The returned Device represents the open device connection to the kernel, and must be closed.

func (*Device) Close Uses

func (d *Device) Close() error

func (*Device) GetDevConfig Uses

func (d *Device) GetDevConfig() string

func (*Device) Sizes Uses

func (d *Device) Sizes() DataSizes

type InquiryInfo Uses

type InquiryInfo struct {
    VendorID   string
    ProductID  string
    ProductRev string

InquiryInfo holds the general vendor information for the emulated SCSI Device. Fields used from this will be padded or trunacted to meet the spec.

type NaaWWN Uses

type NaaWWN struct {
    // OUI is the first three bytes (six hex digits), in ASCII, of your
    // IEEE Organizationally Unique Identifier, eg, "05abcd".
    OUI string
    // The VendorID is the first four bytes (eight hex digits), in ASCII, of
    // the device's vendor-specific ID (perhaps a serial number), eg, "2416c05f".
    VendorID string
    // The VendorIDExt is an optional eight more bytes (16 hex digits) in the same format
    // as the above, if necessary.
    VendorIDExt string

NaaWWN represents the World Wide Name of the SCSI device we are emulating, using the Network Address Authority standard.

func (NaaWWN) DeviceID Uses

func (n NaaWWN) DeviceID() string

func (NaaWWN) NexusID Uses

func (n NaaWWN) NexusID() string

type ReadWriterAt Uses

type ReadWriterAt interface {

type ReadWriterAtCmdHandler Uses

type ReadWriterAtCmdHandler struct {
    RW  ReadWriterAt
    Inq *InquiryInfo

func (ReadWriterAtCmdHandler) HandleCommand Uses

func (h ReadWriterAtCmdHandler) HandleCommand(cmd *SCSICmd) (SCSIResponse, error)

type SCSICmd Uses

type SCSICmd struct {

    // Buf, if provided, may be used as a scratch buffer for copying data to and from the kernel.
    Buf []byte
    // contains filtered or unexported fields

SCSICmd represents a single SCSI command recieved from the kernel to the virtual target.

func (*SCSICmd) CdbLen Uses

func (c *SCSICmd) CdbLen() int

CdbLen returns the length of the command, in bytes.

func (*SCSICmd) CheckCondition Uses

func (c *SCSICmd) CheckCondition(key byte, asc uint16) SCSIResponse

CheckCondition returns a response providing extra sense data. Takes a Sense Key and an Additional Sense Code.

func (*SCSICmd) Command Uses

func (c *SCSICmd) Command() byte

Command returns the SCSI command byte for the command. Useful when used as a comparison to the constants in the scsi package: c.Command() == scsi.Read6

func (*SCSICmd) Device Uses

func (c *SCSICmd) Device() *Device

Device accesses the details of the SCSI device this command is handling.

func (*SCSICmd) GetCDB Uses

func (c *SCSICmd) GetCDB(index int) byte

GetCDB returns the byte at `index` inside the command.

func (*SCSICmd) IllegalRequest Uses

func (c *SCSICmd) IllegalRequest() SCSIResponse

IllegalRequest is a preset response for a request that is malformed or unexpected.

func (*SCSICmd) LBA Uses

func (c *SCSICmd) LBA() uint64

LBA returns the block address that this command wishes to access.

func (*SCSICmd) MediumError Uses

func (c *SCSICmd) MediumError() SCSIResponse

MediumError is a preset response for a read error condition from the device

func (*SCSICmd) NotHandled Uses

func (c *SCSICmd) NotHandled() SCSIResponse

NotHandled creates a response and sense data that tells the kernel this device does not emulate this command.

func (*SCSICmd) Ok Uses

func (c *SCSICmd) Ok() SCSIResponse

Ok creates a SCSIResponse to this command with SAM_STAT_GOOD, the common case for commands that succeed.

func (*SCSICmd) Read Uses

func (c *SCSICmd) Read(b []byte) (n int, err error)

Read, for a SCSICmd, is a io.Reader from the data buffer attached to this SCSI command. If there's data to be written to the virtual device, this is the way to access it.

func (*SCSICmd) RespondSenseData Uses

func (c *SCSICmd) RespondSenseData(status byte, sense []byte) SCSIResponse

RespondSenseData returns a SCSIResponse with the given status byte set and takes a byte array representing the SCSI sense data to be written.

func (*SCSICmd) RespondStatus Uses

func (c *SCSICmd) RespondStatus(status byte) SCSIResponse

RespondStatus returns a SCSIResponse with the given status byte set. Ok() is equivalent to RespondStatus(scsi.SamStatGood).

func (*SCSICmd) TargetFailure Uses

func (c *SCSICmd) TargetFailure() SCSIResponse

TargetFailure is a preset response for returning a hardware error.

func (*SCSICmd) Write Uses

func (c *SCSICmd) Write(b []byte) (n int, err error)

Write, for a SCSICmd, is a io.Writer to the data buffer attached to this SCSI command. It's writing *to* the buffer, which happens most commonly when responding to Read commands (take data and write it back to the kernel buffer)

func (*SCSICmd) XferLen Uses

func (c *SCSICmd) XferLen() uint32

XferLen returns the length of the data buffer this command provides for transfering data to/from the kernel.

type SCSICmdHandler Uses

type SCSICmdHandler interface {
    HandleCommand(cmd *SCSICmd) (SCSIResponse, error)

SCSICmdHandler is a simple request/response handler for SCSI commands coming to TCMU. A SCSI error is reported as an SCSIResponse with an error bit set, while returning a Go error is for flagrant, process-ending errors (OOM, perhaps).

type SCSIHandler Uses

type SCSIHandler struct {
    // The volume name and resultant device name.
    VolumeName string
    // The size of the device and the blocksize for the device.
    DataSizes DataSizes
    // The loopback HBA for the emulated SCSI device
    HBA int
    // The LUN for the emulated HBA
    LUN int
    // The SCSI World Wide Identifer for the device
    // Called once the device is ready. Should spawn a goroutine (or several)
    // to handle commands coming in the first channel, and send their associated
    // responses down the second channel, ordering optional.
    DevReady DevReadyFunc

SCSIHandler is the high-level data for the emulated SCSI device.

func BasicSCSIHandler Uses

func BasicSCSIHandler(rw ReadWriterAt) *SCSIHandler

type SCSIResponse Uses

type SCSIResponse struct {
    // contains filtered or unexported fields

A SCSIResponse is generated from methods on SCSICmd.

func EmulateEvpdInquiry Uses

func EmulateEvpdInquiry(cmd *SCSICmd, inq *InquiryInfo) (SCSIResponse, error)

func EmulateInquiry Uses

func EmulateInquiry(cmd *SCSICmd, inq *InquiryInfo) (SCSIResponse, error)

func EmulateModeSelect Uses

func EmulateModeSelect(cmd *SCSICmd, wce bool) (SCSIResponse, error)

EmulateModeSelect checks that the only mode selected is the static one returned from EmulateModeSense. `wce` should match the Write Cache Enabled of the EmulateModeSense call.

func EmulateModeSense Uses

func EmulateModeSense(cmd *SCSICmd, wce bool) (SCSIResponse, error)

EmulateModeSense responds to a static Mode Sense command. `wce` enables or diables the SCSI "Write Cache Enabled" flag.

func EmulateRead Uses

func EmulateRead(cmd *SCSICmd, r io.ReaderAt) (SCSIResponse, error)

func EmulateReadCapacity16 Uses

func EmulateReadCapacity16(cmd *SCSICmd) (SCSIResponse, error)

func EmulateServiceActionIn Uses

func EmulateServiceActionIn(cmd *SCSICmd) (SCSIResponse, error)

func EmulateStdInquiry Uses

func EmulateStdInquiry(cmd *SCSICmd, inq *InquiryInfo) (SCSIResponse, error)

func EmulateTestUnitReady Uses

func EmulateTestUnitReady(cmd *SCSICmd) (SCSIResponse, error)

func EmulateWrite Uses

func EmulateWrite(cmd *SCSICmd, r io.WriterAt) (SCSIResponse, error)

type WWN Uses

type WWN interface {
    DeviceID() string
    NexusID() string

WWN provides two WWNs, one for the device itself and one for the loopback device created for the kernel.

func GenerateTestWWN Uses

func GenerateTestWWN() WWN



Package tcmu imports 21 packages (graph) and is imported by 2 packages. Updated 2018-01-11. Refresh now. Tools for package owners.