The Pedigree Project 0.1
Classes | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ScsiDisk Class Reference
+ Inheritance diagram for ScsiDisk:
+ Collaboration diagram for ScsiDisk:

Classes

class  CacheRangeAdmission
 
struct  Capacity
 
struct  Inquiry
 
struct  Sense
 

Public Member Functions

 ScsiDisk (size_t cacheConstraints=PhysicalMemoryManager::below4GB)
 
void shutdownCache (bool deviceAvailable=true)
 
virtual void shutdownDeviceCache ()
 
bool hasNoCacheLoans ()
 
bool initialise (class ScsiController *pController, size_t nUnit)
 
virtual BufferView read (uint64_t location)
 
bool readInto (uint64_t location, void *buffer, size_t length) override
 
bool readIntoBatch (ReadBuffer *buffers, size_t count) override
 
bool writeFrom (uint64_t location, const void *buffer, size_t length) override
 
bool writeFromBatch (WriteBuffer *buffers, size_t count) override
 
bool syncData () override
 
virtual void write (uint64_t location)
 
virtual void flush (uint64_t location)
 Flush a cached page to disk.
 
virtual bool sync (uint64_t location, bool async)
 
virtual MUST_USE_RESULT bool syncAll ()
 
bool zero (uint64_t location, size_t length) override
 
bool syncPages (const uint64_t *locations, size_t count) override
 
virtual MUST_USE_RESULT bool retireCachePage (uint64_t location)
 
virtual void align (uint64_t location)
 Sets the page boundary alignment after a specific location on the disk.
 
virtual void getName (String &str)
 
virtual uint64_t doRead (uint64_t location)
 
virtual uint64_t doWrite (uint64_t location)
 
virtual uint64_t doWriteDirectPhysical (uint64_t location, uintptr_t page, physical_uintptr_t physical)
 
virtual uint64_t doSync (uint64_t location)
 
virtual PagingStatus doPagingTransfer (PagingOperation operation, uint64_t offset, void *page)
 
virtual size_t getSize () const
 Gets the size of the disk.
 
virtual size_t getBlockCount () const
 
virtual size_t getBlockSize () const
 Gets the preferred I/O extent of the disk.
 
virtual size_t getNativeBlockSize () const
 
virtual bool pin (uint64_t location)
 Pins a cache page.
 
virtual void unpin (uint64_t location)
 
virtual MUST_USE_RESULT uint64_t doWriteDirect (uint64_t location, uintptr_t page)
 
- Public Member Functions inherited from Disk
 Disk (Device *p)
 
virtual Disk * physicalDisk ()
 
bool acquireUse (DiskUse &use)
 
uint32_t endpointId ()
 
virtual bool getPartitionUuid (String &uuid) const
 
virtual bool getPartitionLabel (String &label) const
 
virtual PagingStatus preparePagingTransport (PagingTransport *&transport)
 
void retireEndpoint ()
 
bool tryCloseEndpoint ()
 
void reopenEndpoint ()
 
virtual Type getType ()
 
virtual SubType getSubType ()
 
virtual void dump (String &str)
 
virtual DiskReadView readView (uint64_t location)
 
virtual DiskWriteView writeView (uint64_t location)
 
MUST_USE_RESULT bool readViews (uint64_t location, size_t length, BufferViewSequence &views)
 
void unpinViews (uint64_t location, BufferViewSequence &views)
 
virtual bool cacheIsCritical ()
 Whether or not the cache is critical and cannot be flushed or deleted.
 
- Public Member Functions inherited from Device
 Device (Device *p)
 
Device * getParent () const
 
void setParent (Device *p)
 
virtual const String & getSpecificType ()
 
virtual void setSpecificType (String str)
 
void setPciPosition (uint32_t bus, uint32_t device, uint32_t func)
 
void setPciIdentifiers (uint8_t classCode, uint8_t subclassCode, uint16_t vendorId, uint16_t deviceId, uint8_t progIf)
 
void setPciConfigHeader (const PciBus::ConfigSpace &space)
 
PciBus::ConfigSpace getPciConfigHeader () const
 
uint8_t getPciClassCode ()
 
uint8_t getPciSubclassCode ()
 
uint16_t getPciVendorId ()
 
uint16_t getPciDeviceId ()
 
uint8_t getPciProgInterface ()
 
uint32_t getPciBusPosition ()
 
uint32_t getPciDevicePosition ()
 
uint32_t getPciFunctionNumber ()
 
Device * getPhysicalFunction () const
 
size_t getVirtualFunctionIndex () const
 
void setVirtualFunction (Device *physicalFunction, size_t index)
 
virtual Vector< Address * > & addresses ()
 
virtual uintptr_t getInterruptNumber ()
 
virtual void setInterruptNumber (uintptr_t n)
 
void addChild (Device *pDevice)
 
Device * getChild (size_t n)
 
size_t getNumChildren ()
 
void removeChild (size_t n)
 
void removeChild (Device *d)
 
void replaceChild (Device *src, Device *dest)
 

Public Attributes

struct ScsiDisk::Sense PACKED
 
struct ScsiDisk::Inquiry PACKED
 
struct ScsiDisk::Capacity PACKED
 

Static Public Attributes

static constexpr uint64_t SyncWholeDevice = ~uint64_t{0}
 
- Static Public Attributes inherited from Disk
static constexpr size_t MaxReadBuffers = 32
 
static constexpr size_t MaxWriteBuffers = 32
 
static constexpr size_t MaxSyncPages = 64
 

Protected Member Functions

BufferView acquireView (uint64_t location, bool writable, uint64_t &token) override
 
void releaseView (uint64_t token, bool writable) override
 
virtual bool supportsBufferTransfers () const
 
virtual bool supportsDirectCacheWrite () const
 
virtual Device * dmaDevice () const
 
virtual bool transferBuffer (uint64_t location, void *buffer, size_t length, bool writing)
 
virtual bool transferReadBuffers (ReadBuffer *buffers, size_t count)
 
virtual bool transferWriteBuffers (WriteBuffer *buffers, size_t count)
 
ScsiController * acquirePagingController (OperationBarrier::Lease &use)
 
PagingStatus preparePagingCache (PagingTransport &transport)
 
virtual size_t getCacheFillSize () const
 
size_t getCacheFillLength (uint64_t location) const
 
Cache & getCache ()
 
Inquiry * getInquiry () const
 
- Protected Member Functions inherited from Disk
void reserveEndpoint ()
 
void publishEndpoint ()
 
- Protected Member Functions inherited from Device
 NOT_COPYABLE_OR_ASSIGNABLE (Device)
 

Static Protected Member Functions

static bool syncCacheBatch (const Cache::WritebackPage *pages, size_t count, void *context)
 
- Static Protected Member Functions inherited from Device
static Device & root ()
 

Private Types

enum  ScsiPeripheralType {
  BlockDevice = 0x00 , SequentialDevice = 0x01 , PrinterDevice = 0x02 , ProcessorDevice = 0x03 ,
  WriteOnceDevice = 0x04 , CdDvdDevice = 0x05 , OpticalMemoryDevice = 0x07 , MediumChangerDevice = 0x08 ,
  ArrayDevice = 0x0C , EnclosureDevice = 0x0D , NoDevice = 0x1F
}
 

Private Member Functions

void enterCacheRange (CacheRangeAdmission &admission)
 
void leaveCacheRange (CacheRangeAdmission &admission)
 
bool cacheRangeBlocked (const CacheRangeAdmission &admission) const
 
bool transferBufferRange (uint64_t location, void *buffer, size_t length, bool writing)
 
bool unitReady ()
 
bool readSense (Sense *s)
 
bool sendCommand (ScsiCommand *pCommand, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite=false)
 
bool getCapacityInternal (size_t *blockNumber, size_t *blockSize)
 
bool flushCachePage (uint64_t location, uintptr_t page)
 
bool writePageBuffer (uint64_t location, uintptr_t page)
 
size_t getCachePageValidLength (uint64_t location) const
 
uint64_t getAlignmentPoint (uint64_t location) const
 
bool hasShiftedCacheAlignment () const
 
virtual size_t defaultBlockSize ()
 

Static Private Member Functions

static bool cacheRangesOverlap (uint64_t firstStart, size_t firstLength, uint64_t secondStart, size_t secondLength)
 
static bool retireCachePageCallback (uintptr_t key, uintptr_t page, void *meta)
 
static bool cacheCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta)
 

Private Attributes

class ScsiController * m_pController
 
size_t m_nUnit
 
Cache m_Cache
 
Inquiry * m_Inquiry
 
WaitQueue m_CacheRangeWaiters
 
CacheRangeAdmission * m_FirstCacheRangeAdmission
 
CacheRangeAdmission * m_LastCacheRangeAdmission
 
Mutex m_AlignmentLock
 
Vector< uint64_t > m_AlignPoints
 
bool m_HasShiftedCacheAlignment
 
size_t m_NumBlocks
 
size_t m_BlockSize
 
size_t m_NativeBlockSize
 
ScsiPeripheralType m_DeviceType
 

Additional Inherited Members

- Public Types inherited from Disk
enum  SubType { ATA = 0 , ATAPI }
 
- Public Types inherited from Device
enum  Type {
  Generic , Root , Disk , Bus ,
  Display , Network , Sound , Console ,
  Mouse , Controller , UsbController , UsbGeneric ,
  UsbContainer
}
 
typedef Device *(* Callback) (Device *)
 
- Static Public Member Functions inherited from Device
static bool treeLockHeldByCurrentThread ()
 
static void foreach (Callback callback, Device *root=0)
 
template<class F , class... Args>
static void foreach (pedigree_std::Callable< F > &callback, Device *root, Args... args)
 
static void addToRoot (Device *device)
 
static void searchByVendorId (uint16_t vendorId, void(*callback)(Device *), Device *root=0)
 
static void searchByVendorIdAndDeviceId (uint16_t vendorId, uint16_t deviceId, void(*callback)(Device *), Device *root=0)
 
static void searchByClass (uint16_t classCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassAndSubclass (uint16_t classCode, uint16_t subclassCode, void(*callback)(Device *), Device *root=0)
 
static void searchByClassSubclassAndProgInterface (uint16_t classCode, uint16_t subclassCode, uint8_t progInterface, void(*callback)(Device *), Device *root=0)
 
- Protected Attributes inherited from Device
Vector< Address * > m_Addresses
 
Vector< Device * > m_Children
 
Device * m_pParent
 
Device * m_PhysicalFunction
 
size_t m_VirtualFunctionIndex
 
uintptr_t m_InterruptNumber
 
String m_SpecificType
 
PciBus::ConfigSpace m_ConfigHeader
 
uint8_t m_ClassCode
 
uint8_t m_SubclassCode
 
uint16_t m_VendorId
 
uint16_t m_DeviceId
 
uint8_t m_ProgInterface
 
uint32_t m_PciBusPos
 
uint32_t m_PciDevicePos
 
uint32_t m_PciFunctionNum
 
- Static Protected Attributes inherited from Device
static Device m_Root
 
static Mutex m_TreeLock
 

Detailed Description

Definition at line 41 of file ScsiDisk.h.

Member Enumeration Documentation

◆ ScsiPeripheralType

enum ScsiDisk::ScsiPeripheralType
private

Definition at line 43 of file ScsiDisk.h.

Constructor & Destructor Documentation

◆ ScsiDisk()

ScsiDisk::ScsiDisk ( size_t  cacheConstraints = PhysicalMemoryManager::below4GB)
explicit

Definition at line 244 of file ScsiDisk.cc.

◆ ~ScsiDisk()

ScsiDisk::~ScsiDisk ( )
virtual

Definition at line 263 of file ScsiDisk.cc.

Member Function Documentation

◆ acquirePagingController()

ScsiController * ScsiDisk::acquirePagingController ( OperationBarrier::Lease &  use)
protected

Definition at line 10 of file ScsiDisk-paging.cc.

◆ acquireView()

BufferView ScsiDisk::acquireView ( uint64_t  location,
bool  writable,
uint64_t &  token 
)
overrideprotectedvirtual

Reimplemented from Disk.

Definition at line 469 of file ScsiDisk.cc.

◆ align()

void ScsiDisk::align ( uint64_t  location)
virtual

Sets the page boundary alignment after a specific location on the disk.

For example, a partition beginning at byte 512 should align its first cache page with that boundary rather than with byte zero of the parent.

Use this function to keep the cache pages manipulated in read() and write() aligned with a child device whose start is not naturally page-aligned on the parent.

Reimplemented from Disk.

Definition at line 1240 of file ScsiDisk.cc.

References Vector< T >::count(), getSize(), Device::m_pParent, and Vector< T >::pushBack().

◆ cacheCallback()

bool ScsiDisk::cacheCallback ( CacheConstants::CallbackCause  cause,
uintptr_t  loc,
uintptr_t  page,
void *  meta 
)
staticprivate

Definition at line 206 of file ScsiDisk.cc.

◆ cacheRangeBlocked()

bool ScsiDisk::cacheRangeBlocked ( const CacheRangeAdmission &  admission) const
private

Definition at line 148 of file ScsiDisk.cc.

◆ cacheRangesOverlap()

bool ScsiDisk::cacheRangesOverlap ( uint64_t  firstStart,
size_t  firstLength,
uint64_t  secondStart,
size_t  secondLength 
)
staticprivate

Definition at line 136 of file ScsiDisk.cc.

◆ defaultBlockSize()

virtual size_t ScsiDisk::defaultBlockSize ( )
inlineprivatevirtual

Default block size for a device

Reimplemented in AtaDisk.

Definition at line 300 of file ScsiDisk.h.

◆ dmaDevice()

virtual Device * ScsiDisk::dmaDevice ( ) const
inlineprotectedvirtual

Definition at line 174 of file ScsiDisk.h.

◆ doPagingTransfer()

PagingStatus ScsiDisk::doPagingTransfer ( PagingOperation  operation,
uint64_t  offset,
void *  page 
)
virtual

Definition at line 16 of file ScsiDisk-paging.cc.

◆ doRead()

uint64_t ScsiDisk::doRead ( uint64_t  location)
virtual
Todo:
Cache this somewhere.

Reimplemented in AtaDisk.

Definition at line 1267 of file ScsiDisk.cc.

References getCacheFillLength(), getNativeBlockSize(), Cache::insert(), Cache::lookup(), Cache::release(), and unitReady().

Referenced by AtaDisk::doRead(), and ScsiController::executeRequest().

+ Here is the caller graph for this function:

◆ doSync()

uint64_t ScsiDisk::doSync ( uint64_t  location)
virtual

Definition at line 1512 of file ScsiDisk.cc.

◆ doWrite()

uint64_t ScsiDisk::doWrite ( uint64_t  location)
virtual

Reimplemented in AtaDisk.

Definition at line 1407 of file ScsiDisk.cc.

◆ doWriteDirect()

uint64_t ScsiDisk::doWriteDirect ( uint64_t  location,
uintptr_t  page 
)
virtual

Writes one caller-borrowed page without acquiring cache ownership.

Reimplemented in AtaDisk, AhciDisk, NvmeDisk, and VirtioBlkDisk.

Definition at line 1435 of file ScsiDisk.cc.

References getCachePageValidLength(), unitReady(), and writePageBuffer().

Referenced by ScsiController::executeRequest().

+ Here is the caller graph for this function:

◆ doWriteDirectPhysical()

uint64_t ScsiDisk::doWriteDirectPhysical ( uint64_t  location,
uintptr_t  page,
physical_uintptr_t  physical 
)
virtual

Definition at line 1456 of file ScsiDisk.cc.

◆ enterCacheRange()

void ScsiDisk::enterCacheRange ( CacheRangeAdmission &  admission)
private

Definition at line 161 of file ScsiDisk.cc.

◆ flush()

void ScsiDisk::flush ( uint64_t  location)
virtual

Flush a cached page to disk.

Essentially a no-op if the given location is not actually in cache. Called either by filesystem drivers (on removable disks) or from a central cache manager which handles flushing caches back to the disk on a regular basis.

Will not remove the page from cache, that must be done by the caller.

Reimplemented from Disk.

Definition at line 978 of file ScsiDisk.cc.

References sync().

◆ flushCachePage()

bool ScsiDisk::flushCachePage ( uint64_t  location,
uintptr_t  page 
)
private

Writes a cache page without client-operation admission.

Definition at line 1182 of file ScsiDisk.cc.

References RequestQueue::addRequest(), getAlignmentPoint(), getCachePageValidLength(), getNativeBlockSize(), getSize(), Device::m_pParent, and PciBus::mapDmaPage().

◆ getAlignmentPoint()

uint64_t ScsiDisk::getAlignmentPoint ( uint64_t  location) const
private

Snapshots the most recent alignment boundary for a location.

Definition at line 1621 of file ScsiDisk.cc.

References Vector< T >::count().

Referenced by flushCachePage(), pin(), retireCachePage(), sync(), syncPages(), unpin(), and write().

+ Here is the caller graph for this function:

◆ getBlockCount()

virtual size_t ScsiDisk::getBlockCount ( ) const
inlinevirtual

Definition at line 145 of file ScsiDisk.h.

◆ getBlockSize()

virtual size_t ScsiDisk::getBlockSize ( ) const
inlinevirtual

Gets the preferred I/O extent of the disk.

This may describe a native device block or a larger cache-fill/readahead extent, depending on the implementation. It is independent of the cache page boundary reported by BufferView::size().

Reimplemented from Disk.

Reimplemented in AtaDisk, AhciDisk, NvmeDisk, and VirtioBlkDisk.

Definition at line 149 of file ScsiDisk.h.

Referenced by AtaDisk::getBlockSize().

+ Here is the caller graph for this function:

◆ getCache()

Cache & ScsiDisk::getCache ( )
inlineprotected

Definition at line 206 of file ScsiDisk.h.

◆ getCacheFillLength()

size_t ScsiDisk::getCacheFillLength ( uint64_t  location) const
protected

Returns the native-block-aligned portion of an extent that is safe to transfer.

The final extent of a device may be shorter than the preferred readahead size. Cache allocation is rounded up separately so the final target page can be zero-filled beyond the device boundary.

Definition at line 1389 of file ScsiDisk.cc.

References getCacheFillSize(), getNativeBlockSize(), and getSize().

Referenced by AtaDisk::doRead(), and doRead().

+ Here is the caller graph for this function:

◆ getCacheFillSize()

virtual size_t ScsiDisk::getCacheFillSize ( ) const
inlineprotectedvirtual

Size of one cache fill performed by this implementation.

The generic path owns independently evictable target pages. A subclass may opt into a larger extent only when its doRead() handles partially populated extents page by page.

Reimplemented in AtaDisk.

Definition at line 192 of file ScsiDisk.h.

References TargetInfo::getPageSize().

Referenced by getCacheFillLength(), AtaDisk::getCacheFillSize(), and zero().

+ Here is the caller graph for this function:

◆ getCachePageValidLength()

size_t ScsiDisk::getCachePageValidLength ( uint64_t  location) const
private

Returns the device-backed portion of a cache page at p location.

Definition at line 1612 of file ScsiDisk.cc.

References getSize().

Referenced by doWriteDirect(), flushCachePage(), retireCachePage(), retireCachePageCallback(), syncPages(), write(), and writePageBuffer().

+ Here is the caller graph for this function:

◆ getCapacityInternal()

bool ScsiDisk::getCapacityInternal ( size_t *  blockNumber,
size_t *  blockSize 
)
private

Definition at line 422 of file ScsiDisk.cc.

◆ getInquiry()

Inquiry * ScsiDisk::getInquiry ( ) const
inlineprotected

Definition at line 210 of file ScsiDisk.h.

◆ getName()

virtual void ScsiDisk::getName ( String &  str)
inlinevirtual

Stores the device's name in str.

Reimplemented from Disk.

Reimplemented in AhciDisk, NvmeDisk, VirtioBlkDisk, and AtaDisk.

Definition at line 124 of file ScsiDisk.h.

◆ getNativeBlockSize()

virtual size_t ScsiDisk::getNativeBlockSize ( ) const
inlinevirtual

Retrieves the native block size - that is, the logical block size. This differs from the preferred I/O/cache-fill extent.

Reimplemented from Disk.

Reimplemented in AtaDisk, AhciDisk, NvmeDisk, and VirtioBlkDisk.

Definition at line 157 of file ScsiDisk.h.

Referenced by doRead(), flushCachePage(), getCacheFillLength(), AtaDisk::getNativeBlockSize(), readIntoBatch(), retireCachePage(), syncPages(), write(), writeFromBatch(), writePageBuffer(), and zero().

+ Here is the caller graph for this function:

◆ getSize()

virtual size_t ScsiDisk::getSize ( ) const
inlinevirtual

Gets the size of the disk.

This is the size in bytes of the disk. Reads or writes beyond this size will fail.

Reimplemented from Disk.

Reimplemented in AtaDisk, AhciDisk, NvmeDisk, and VirtioBlkDisk.

Definition at line 141 of file ScsiDisk.h.

Referenced by align(), flushCachePage(), getCacheFillLength(), getCachePageValidLength(), AtaDisk::getSize(), pin(), readIntoBatch(), sync(), syncPages(), unpin(), write(), writeFromBatch(), and zero().

+ Here is the caller graph for this function:

◆ hasNoCacheLoans()

bool ScsiDisk::hasNoCacheLoans ( )

Definition at line 37 of file ScsiDisk-paging.cc.

◆ hasShiftedCacheAlignment()

bool ScsiDisk::hasShiftedCacheAlignment ( ) const
private

Definition at line 1632 of file ScsiDisk.cc.

◆ initialise()

bool ScsiDisk::initialise ( class ScsiController *  pController,
size_t  nUnit 
)
Todo:
Use this data to change how read() and write() work

Definition at line 286 of file ScsiDisk.cc.

References Dec, ServiceManager::enumerateOperations(), ServiceManager::getService(), Hex, Device::m_pParent, ServiceFeatures::provides(), readSense(), Service::serve(), ServiceFeatures::touch, and unitReady().

Referenced by AtaDisk::initialise().

+ Here is the caller graph for this function:

◆ leaveCacheRange()

void ScsiDisk::leaveCacheRange ( CacheRangeAdmission &  admission)
private

Definition at line 185 of file ScsiDisk.cc.

◆ pin()

bool ScsiDisk::pin ( uint64_t  location)
virtual

Pins a cache page.

This allows an upstream user of Disk pages to 'pin' cache pages, causing them to only be freed once all consumers have done an 'unpin'. The pin and unpin semantics allow for memory mappings to be made in a reasonably safe manner, as it can be assumed that the physical page for a particular cache block will not be freed.

Returns
True only when this call acquired a reference to the page currently published for location. Callers must not use an address obtained before a failed pin.

Implements Disk.

Definition at line 1565 of file ScsiDisk.cc.

References Cache::beginMutableLoan(), getAlignmentPoint(), getSize(), Device::m_pParent, Cache::pin(), and Cache::release().

◆ preparePagingCache()

PagingStatus ScsiDisk::preparePagingCache ( PagingTransport &  transport)
protected

Definition at line 19 of file ScsiDisk-paging.cc.

◆ read()

BufferView ScsiDisk::read ( uint64_t  location)
virtual

Read from location on disk and return a view beginning at that byte. location must be 512-byte aligned. The returned view ends at the boundary of the independently owned cache page containing location; its size is unrelated to the device's block or readahead size.

Note
A successful read returns exactly one caller-owned reference to the cache page containing location. The view is non-owning: use unpin() exactly once after every copy and subview is no longer in use. Larger I/O extents do not extend this ownership.
Parameters
locationThe offset from the start of the device, in bytes, to start the read, must be multiple of 512. Prefer readView() for readers and writeView() for scoped mutation. This legacy interface treats every read()/pin() reference as potentially mutable until its matching unpin(). No derived pointers may survive that reference.
Returns
A writable view containing the data, or an empty view on failure. If the data is written, the page is marked as dirty and may be written back to disk at any time (or forced with write() or flush() ).

Reimplemented from Disk.

Definition at line 460 of file ScsiDisk.cc.

◆ readInto()

bool ScsiDisk::readInto ( uint64_t  location,
void *  buffer,
size_t  length 
)
overridevirtual

Transfers exactly length bytes using caller-owned, pinned storage. The buffer must remain valid until return and must not alias this disk's cache. No buffer reference is retained. Failure may have transferred a prefix. Existing block-cache data remains coherent; unsupported transports copy through their ordinary cache views.

Reimplemented from Disk.

Definition at line 558 of file ScsiDisk.cc.

◆ readIntoBatch()

bool ScsiDisk::readIntoBatch ( ReadBuffer *  buffers,
size_t  count 
)
overridevirtual

Reads up to MaxReadBuffers independent ranges into caller-owned, pinned storage. Physical mappings must remain stable until return. Every issued transfer is drained before return, including on failure. complete is reset on entry and set only for fully initialised buffers; successful buffers remain usable when another range fails.

Reimplemented from Disk.

Definition at line 562 of file ScsiDisk.cc.

References getNativeBlockSize(), getSize(), Cache::lookupStable(), Device::m_pParent, Disk::readIntoBatch(), and Cache::release().

◆ readSense()

bool ScsiDisk::readSense ( Sense *  s)
private
Todo:
get the amount of data received from the SCSI device

Definition at line 390 of file ScsiDisk.cc.

Referenced by initialise().

+ Here is the caller graph for this function:

◆ releaseView()

void ScsiDisk::releaseView ( uint64_t  token,
bool  writable 
)
overrideprotectedvirtual

Reimplemented from Disk.

Definition at line 1605 of file ScsiDisk.cc.

◆ retireCachePage()

bool ScsiDisk::retireCachePage ( uint64_t  location)
virtual

Synchronously writes and retires the target cache page containing location.

A successful call means the page is no longer published by this disk's cache. It does not imply that a volatile device write cache has been flushed. Callers must release their own reference to the page before entering this operation.

Returns
True when the page was retired or was already absent. False when this disk does not support retirement or the page must remain available for a later retry.

Reimplemented from Disk.

Definition at line 1150 of file ScsiDisk.cc.

References getAlignmentPoint(), getCachePageValidLength(), getNativeBlockSize(), Device::m_pParent, retireCachePageCallback(), and Cache::retireWriteback().

◆ retireCachePageCallback()

bool ScsiDisk::retireCachePageCallback ( uintptr_t  key,
uintptr_t  page,
void *  meta 
)
staticprivate

Cache::retireWriteback callback; the supplied page is borrowed.

Definition at line 227 of file ScsiDisk.cc.

References RequestQueue::addRequest(), getCachePageValidLength(), and Device::m_pParent.

Referenced by retireCachePage().

+ Here is the caller graph for this function:

◆ sendCommand()

bool ScsiDisk::sendCommand ( ScsiCommand *  pCommand,
uintptr_t  pRespBuffer,
uint16_t  nRespBytes,
bool  bWrite = false 
)
private

Definition at line 452 of file ScsiDisk.cc.

◆ shutdownCache()

void ScsiDisk::shutdownCache ( bool  deviceAvailable = true)

Drains cache callbacks while the disk/controller state is still live. An unavailable device requires discarding dirty data instead of writeback.

Definition at line 268 of file ScsiDisk.cc.

References panic(), and Cache::shutdown().

◆ shutdownDeviceCache()

void ScsiDisk::shutdownDeviceCache ( )
virtual

Definition at line 275 of file ScsiDisk.cc.

◆ supportsBufferTransfers()

virtual bool ScsiDisk::supportsBufferTransfers ( ) const
inlineprotectedvirtual

Definition at line 168 of file ScsiDisk.h.

◆ supportsDirectCacheWrite()

virtual bool ScsiDisk::supportsDirectCacheWrite ( ) const
inlineprotectedvirtual

Definition at line 171 of file ScsiDisk.h.

◆ sync()

bool ScsiDisk::sync ( uint64_t  location,
bool  async 
)
virtual

Writes a cached page and reports failure. Synchronous success includes the device's write-cache flush; asynchronous success means admission only. Unsupported backends return false rather than claiming persistence.

Reimplemented from Disk.

Definition at line 984 of file ScsiDisk.cc.

References getAlignmentPoint(), getSize(), Cache::lookup(), Device::m_pParent, Cache::sync(), Cache::syncBatch(), and syncData().

Referenced by flush().

+ Here is the caller graph for this function:

◆ syncAll()

bool ScsiDisk::syncAll ( )
virtual

Drains existing cached writes and the device write cache synchronously.

Reimplemented from Disk.

Definition at line 1122 of file ScsiDisk.cc.

References RequestQueue::addRequest(), Device::m_pParent, and Cache::syncAll().

◆ syncCacheBatch()

bool ScsiDisk::syncCacheBatch ( const Cache::WritebackPage *  pages,
size_t  count,
void *  context 
)
staticprotected

Definition at line 1078 of file ScsiDisk.cc.

◆ syncData()

bool ScsiDisk::syncData ( )
overridevirtual

Makes preceding successful writeFrom() calls durable. Call after all writes in a batch, including a partially failed batch. writeFrom() alone promises transfer completion, not a device write-cache barrier. Legacy fallbacks persist each write individually, so their final barrier is already done.

Reimplemented from Disk.

Definition at line 904 of file ScsiDisk.cc.

References Device::m_pParent.

Referenced by sync().

+ Here is the caller graph for this function:

◆ syncPages()

bool ScsiDisk::syncPages ( const uint64_t *  locations,
size_t  count 
)
overridevirtual

Synchronously persists every listed cached page, including the device cache.

Reimplemented from Disk.

Definition at line 1036 of file ScsiDisk.cc.

References getAlignmentPoint(), getCachePageValidLength(), getNativeBlockSize(), getSize(), Device::m_pParent, and Cache::syncBatch().

◆ transferBuffer()

bool ScsiDisk::transferBuffer ( uint64_t  location,
void *  buffer,
size_t  length,
bool  writing 
)
protectedvirtual

Definition at line 716 of file ScsiDisk.cc.

◆ transferBufferRange()

bool ScsiDisk::transferBufferRange ( uint64_t  location,
void *  buffer,
size_t  length,
bool  writing 
)
private

Definition at line 720 of file ScsiDisk.cc.

◆ transferReadBuffers()

bool ScsiDisk::transferReadBuffers ( ReadBuffer *  buffers,
size_t  count 
)
protectedvirtual

Definition at line 656 of file ScsiDisk.cc.

◆ transferWriteBuffers()

bool ScsiDisk::transferWriteBuffers ( WriteBuffer *  buffers,
size_t  count 
)
protectedvirtual

Definition at line 894 of file ScsiDisk.cc.

◆ unitReady()

bool ScsiDisk::unitReady ( )
private
Todo:
this can fail with UNIT_ATTN or NOT_READY if the device is removable.

Definition at line 412 of file ScsiDisk.cc.

Referenced by doRead(), doWriteDirect(), and initialise().

+ Here is the caller graph for this function:

◆ unpin()

void ScsiDisk::unpin ( uint64_t  location)
virtual

Unpins a cache page (see pin() for more information and rationale).

Implements Disk.

Definition at line 1595 of file ScsiDisk.cc.

References getAlignmentPoint(), and getSize().

Referenced by ScsiController::cancelRequest(), and ScsiController::executeRequest().

+ Here is the caller graph for this function:

◆ write()

void ScsiDisk::write ( uint64_t  location)
virtual

This function schedules a cache writeback of the given location. The data to be written back is fetched from the cache (pointer returned by read() ).

Parameters
locationThe offset from the start of the device, in bytes, to start the write. Must be 512byte aligned.

Reimplemented from Disk.

Reimplemented in VirtioBlkDisk.

Definition at line 921 of file ScsiDisk.cc.

References getAlignmentPoint(), getCachePageValidLength(), getNativeBlockSize(), getSize(), Cache::lookup(), Device::m_pParent, Cache::markDirty(), and Cache::release().

Referenced by VirtioBlkDisk::write().

+ Here is the caller graph for this function:

◆ writeFrom()

bool ScsiDisk::writeFrom ( uint64_t  location,
const void *  buffer,
size_t  length 
)
overridevirtual

Reimplemented from Disk.

Definition at line 708 of file ScsiDisk.cc.

◆ writeFromBatch()

bool ScsiDisk::writeFromBatch ( WriteBuffer *  buffers,
size_t  count 
)
overridevirtual

Writes caller-owned buffers, draining all issued I/O before return. complete reports each fully transferred range, including on partial failure. Storage must remain valid until return; syncData() supplies durability.

Reimplemented from Disk.

Reimplemented in VirtioBlkDisk.

Definition at line 841 of file ScsiDisk.cc.

References getNativeBlockSize(), getSize(), Cache::lookupStable(), Device::m_pParent, Cache::release(), and Disk::writeFromBatch().

Referenced by VirtioBlkDisk::writeFromBatch().

+ Here is the caller graph for this function:

◆ writePageBuffer()

bool ScsiDisk::writePageBuffer ( uint64_t  location,
uintptr_t  page 
)
private

Issues the SCSI write fallback sequence for one supplied page.

Definition at line 1462 of file ScsiDisk.cc.

References getCachePageValidLength(), and getNativeBlockSize().

Referenced by doWriteDirect().

+ Here is the caller graph for this function:

◆ zero()

bool ScsiDisk::zero ( uint64_t  location,
size_t  length 
)
overridevirtual

Zeroes a range in the cache; syncAll supplies durability. A failed call may have zeroed a prefix. Full cache pages need no old contents read.

Reimplemented from Disk.

Reimplemented in VirtioBlkDisk.

Definition at line 666 of file ScsiDisk.cc.

References Cache::beginMutableLoan(), getCacheFillSize(), getNativeBlockSize(), getSize(), Cache::insert(), Cache::lookup(), Device::m_pParent, Cache::markDirty(), Cache::markNoLongerEditing(), Cache::release(), and Disk::zero().

Referenced by VirtioBlkDisk::zero().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_AlignmentLock

Mutex ScsiDisk::m_AlignmentLock
mutableprivate

Definition at line 289 of file ScsiDisk.h.

◆ m_AlignPoints

Vector<uint64_t> ScsiDisk::m_AlignPoints
private

Definition at line 290 of file ScsiDisk.h.

◆ m_BlockSize

size_t ScsiDisk::m_BlockSize
private

Definition at line 294 of file ScsiDisk.h.

◆ m_Cache

Cache ScsiDisk::m_Cache
private

Definition at line 276 of file ScsiDisk.h.

◆ m_CacheRangeWaiters

WaitQueue ScsiDisk::m_CacheRangeWaiters
private

Definition at line 279 of file ScsiDisk.h.

◆ m_DeviceType

ScsiPeripheralType ScsiDisk::m_DeviceType
private

Definition at line 297 of file ScsiDisk.h.

◆ m_FirstCacheRangeAdmission

CacheRangeAdmission* ScsiDisk::m_FirstCacheRangeAdmission
private

Definition at line 280 of file ScsiDisk.h.

◆ m_HasShiftedCacheAlignment

bool ScsiDisk::m_HasShiftedCacheAlignment
private

Definition at line 291 of file ScsiDisk.h.

◆ m_Inquiry

Inquiry* ScsiDisk::m_Inquiry
private

Definition at line 277 of file ScsiDisk.h.

◆ m_LastCacheRangeAdmission

CacheRangeAdmission* ScsiDisk::m_LastCacheRangeAdmission
private

Definition at line 281 of file ScsiDisk.h.

◆ m_NativeBlockSize

size_t ScsiDisk::m_NativeBlockSize
private

Definition at line 295 of file ScsiDisk.h.

◆ m_NumBlocks

size_t ScsiDisk::m_NumBlocks
private

Definition at line 293 of file ScsiDisk.h.

◆ m_nUnit

size_t ScsiDisk::m_nUnit
private

Definition at line 274 of file ScsiDisk.h.

◆ m_pController

class ScsiController* ScsiDisk::m_pController
private

Definition at line 273 of file ScsiDisk.h.

◆ SyncWholeDevice

constexpr uint64_t ScsiDisk::SyncWholeDevice = ~uint64_t{0}
staticconstexpr

Definition at line 139 of file ScsiDisk.h.


The documentation for this class was generated from the following files: