Files
@ bd21c8aa7237
Branch filter:
Location: vmkdrivers/vmkdrivers/vmkplexer/src/scsi/vmkplexer_scsi.c
bd21c8aa7237
6.5 KiB
text/x-csrc
ESXi-6.0.0b
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | /*
**********************************************************
* Copyright 2010 VMware, Inc. All rights reserved.
**********************************************************
*/
/*
* vmkplexer_scsi.c --
*
* Management of global resources for SCSI layer
*/
#include "vmkapi.h"
#include <vmkplexer_module.h>
#include <vmkplexer_init.h>
#include <vmkplexer_scsi.h>
#include <vmkplexer_mempool.h>
#define VMKPLXR_LOG_HANDLE VmkplxrScsi
#include <vmkplexer_log.h>
/*
* Thin-vmklinux scsi cmd slabs are backed by this mempool.
* Min and Max values are based on the number of outstanding IOs,
* currently ESX supports 64k commands.
* Min size reserved = 64k * align(slab item size)
* 64k * 512 = 32M
* Here slab item is scsi_cmd struct and it's aligned size is 512 bytes.
*
* Max size of 50M is choosen to provide some room for any overhead with
* internal allocatiion housekeeping. Also, curently slabs backed by
* mempool can't give back extra memory to mempool.
*/
#define VMKPLXR_SCSICMD_MEMPOOL "vmkplxrScsiCmdMempool"
#define VMKPLXR_SCSICMD_POOL_MIN (32*1024*1024)
#define VMKPLXR_SCSICMD_POOL_MAX (50*1024*1024)
vmk_MemPool scsiCmdMemPool;
#define SIZE_IN_PAGES(size) (((size) + (VMK_PAGE_SIZE - 1)) / VMK_PAGE_SIZE)
#define VMK_SCSI_SLAB_CONTROL_OFFSET(size, alignment) \
((((size) + vmk_SlabControlSize()) > VMK_UTIL_ROUNDUP((size), (alignment))) ? \
(VMK_UTIL_ROUNDUP((size), (alignment)) - vmk_SlabControlSize()) : (size))
/*
*-----------------------------------------------------------------------------
*
* VmkplxrScsiCmdMempoolCreate --
*
* Create scsiCmdMemPool - a backing mempool for the scsi cmd slabs.
*
* Results:
* VMK_OK on success, panics otherwise
*
* Side effects:
* scsiCmdMemPool may have been created
*
*-----------------------------------------------------------------------------
*/
static VMK_ReturnStatus
VmkplxrScsiCmdMempoolCreate(void)
{
vmk_MemPoolProps props;
VMK_ReturnStatus status = VMK_OK;
/*
* set reservation, limit - size in pages
*/
props.module = vmk_ModuleStackTop();
status = vmkplxr_GetMemPool(&props.parentMemPool);
VMK_ASSERT(status == VMK_OK);
props.memPoolType = VMK_MEM_POOL_LEAF;
props.resourceProps.reservation = SIZE_IN_PAGES(VMKPLXR_SCSICMD_POOL_MIN);
props.resourceProps.limit = SIZE_IN_PAGES(VMKPLXR_SCSICMD_POOL_MAX);
status = vmk_NameInitialize(&props.name, VMKPLXR_SCSICMD_MEMPOOL);
VMK_ASSERT(status == VMK_OK);
status = vmk_MemPoolCreate(&props, &scsiCmdMemPool);
if (status != VMK_OK) {
vmk_Panic("VmkplxrScsiCmdMempoolCreate: vmk_MemPoolCreate failed for %s: %s",
VMKPLXR_SCSICMD_MEMPOOL, vmk_StatusToString(status));
}
return status;
}
/*
*-----------------------------------------------------------------------------
*
* VmkplxrScsiCmdMempoolDestroy --
*
* Destroy scsiCmdMemPool.
*
* Results:
* None.
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
static void
VmkplxrScsiCmdMempoolDestroy(void)
{
VMK_ReturnStatus status;
status = vmk_MemPoolDestroy(scsiCmdMemPool);
VMK_ASSERT(status == VMK_OK);
}
/*
*-----------------------------------------------------------------------------
*
* vmkplxr_ScsiCmdSlabCreate --
*
* Create scsi cmd slab for the thin vmklinux client.
*
* This is wrapper for vmk_SlabCreate function.
* Thin-vmklinux clients should provide slab object size and it's
* moduleID and this function will setup rest of the scsi cmd slab
* properties based on storage layer's scsiCmdSlab.
*
* Results:
* If successful, the vmk_SlabID of the cache so created, or
* VMK_SLABID_INVALID otherwise.
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
vmk_SlabID
vmkplxr_ScsiCmdSlabCreate(vmkplxr_ScsiCmdSlabPool *slabpool)
{
vmk_SlabCreateProps props;
VMK_ReturnStatus status;
vmk_SlabID slab = VMK_INVALID_SLAB_ID;
VMK_ASSERT(vmk_PreemptionIsEnabled() == VMK_FALSE);
if (slabpool->moduleID == VMK_INVALID_MODULE_ID) {
VMKPLXR_WIRPID("Invalid module ID");
goto error;
}
/*
* slab name, owner
*/
vmk_NameInitialize(&(props.name), slabpool->name);
props.module = slabpool->moduleID;
/*
* slabs are backed up by mempool
*/
props.type = VMK_SLAB_TYPE_MEMPOOL;
props.typeSpecific.memPool.memPool = scsiCmdMemPool;
props.typeSpecific.memPool.physContiguity = VMK_MEM_PHYS_ANY_CONTIGUITY;
props.typeSpecific.memPool.physRange = VMK_PHYS_ADDR_ANY;
/*
* slab size - storage scsiCmdSlab values used here
* minObj is kept same for all thin vmklinux clients and this value is choosen
* not based on number HBAs each vmklinux support but how much IO activity we
* may see, even if vmklinux has just one HBA to it - user can issue more IOs
* to it and that vmklinux should be ready to handle the IO workload.
* And with drivers of large queue depth and with high IO load, that the
* number of allocated slab objects can be close to or higher than the minObj
* value, even with single HBA driver is bound to vmklinux.
*/
props.maxObj = vmk_ScsiCommandMaxCommands();
props.minObj = props.maxObj / 20;
/*
* slab object properties
*/
props.objSize = slabpool->objSize;
props.alignment = VMK_L1_CACHELINE_SIZE;
props.ctrlOffset = VMK_SCSI_SLAB_CONTROL_OFFSET(props.objSize, props.alignment);
/*
* slab - nullify unused ones
*/
props.constructor = NULL;
props.destructor = NULL;
props.constructorArg.ptr = NULL;
/*
* create slab
*/
status = vmk_SlabCreate(&props, &slab);
if (status != VMK_OK) {
vmk_Panic("vmkplxr_ScsiCmdSlabCreate: vmk_SlabCreate failed for %s: %s",
slabpool->name, vmk_StatusToString(status));
}
error:
return slab;
}
VMK_MODULE_EXPORT_SYMBOL(vmkplxr_ScsiCmdSlabCreate);
/*
*-----------------------------------------------------------------------------
*
* vmkplxr_ScsiInit/Cleanup --
*
* Init and cleanup routines for SCSI layer.
*
* Results:
* None.
*
* Side effects:
* None.
*
*-----------------------------------------------------------------------------
*/
VMK_ReturnStatus
vmkplxr_ScsiInit(void)
{
VMK_ReturnStatus status;
VMKPLXR_CREATE_LOG();
status = VmkplxrScsiCmdMempoolCreate();
return status;
}
void
vmkplxr_ScsiCleanup(void)
{
VmkplxrScsiCmdMempoolDestroy();
VMKPLXR_DESTROY_LOG();
}
|