From 77cba7edd62da9323fae14f9c0520c42b5eaab4b Mon Sep 17 00:00:00 2001 From: Paul Durrant Date: Tue, 9 Apr 2019 17:03:08 +0100 Subject: [PATCH] Report disk size and logical sector size in XENDISK... ...rather than XENVBD. This allows us to use the PDO name rather than the more obscure target number. Also, report the size in MB rather rather than in sectors (now that sector size may be something other than 512B). Also fix some whitespace bugs while in the neighbourhood. Signed-off-by: Paul Durrant --- src/xendisk/pdo.c | 33 ++++++++++++++++++++++----------- src/xenvbd/frontend.c | 14 +++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/xendisk/pdo.c b/src/xendisk/pdo.c index e91b1da..62e15b2 100644 --- a/src/xendisk/pdo.c +++ b/src/xendisk/pdo.c @@ -457,16 +457,17 @@ fail1: static NTSTATUS PdoSendReadCapacity16Synchronous( - IN PXENDISK_PDO Pdo, - OUT PULONG SectorSize, - OUT PULONG PhysSectorSize + IN PXENDISK_PDO Pdo, + OUT PULONG SectorSize, + OUT PULONG PhysSectorSize, + OUT PULONG64 SectorCount ) { - SCSI_REQUEST_BLOCK Srb; - PCDB Cdb; - PREAD_CAPACITY16_DATA Capacity; - ULONG Length; - NTSTATUS status; + SCSI_REQUEST_BLOCK Srb; + PCDB Cdb; + PREAD_CAPACITY16_DATA Capacity; + ULONG Length; + NTSTATUS status; Trace("====>\n"); @@ -501,6 +502,7 @@ PdoSendReadCapacity16Synchronous( *SectorSize = _byteswap_ulong(Capacity->BytesPerBlock); *PhysSectorSize = *SectorSize << Capacity->LogicalPerPhysicalExponent; + *SectorCount = _byteswap_uint64(Capacity->LogicalBlockAddress.QuadPart) + 1; __PdoFree(Capacity); @@ -830,6 +832,8 @@ PdoStartDevice( { ULONG SectorSize; ULONG PhysSectorSize; + ULONG64 SectorCount; + ULONG64 Size; POWER_STATE PowerState; NTSTATUS status; @@ -841,15 +845,22 @@ PdoStartDevice( if (!NT_SUCCESS(status)) goto fail2; - status = PdoSendReadCapacity16Synchronous(Pdo, &SectorSize, &PhysSectorSize); + status = PdoSendReadCapacity16Synchronous(Pdo, + &SectorSize, + &PhysSectorSize, + &SectorCount); if (!NT_SUCCESS(status)) goto fail3; - Trace("SectorSize = %u PhysSectorSize = %u\n", SectorSize, PhysSectorSize); - Pdo->SectorSize = SectorSize; Pdo->PhysSectorSize = PhysSectorSize; + Size = SectorSize * SectorCount; + Size >>= 20; // Scale to megabytes + + Verbose("%s: %luMB (%uB sectors)\n", + __PdoGetName(Pdo), Size, SectorSize); + __PdoSetSystemPowerState(Pdo, PowerSystemWorking); __PdoSetDevicePowerState(Pdo, PowerDeviceD0); diff --git a/src/xenvbd/frontend.c b/src/xenvbd/frontend.c index 3310287..f90e31c 100644 --- a/src/xenvbd/frontend.c +++ b/src/xenvbd/frontend.c @@ -865,13 +865,13 @@ __ReadDiskInfo( } // dump actual values - Verbose("Target[%d] : %lld sectors of %d bytes (%d)\n", Frontend->TargetId, - Frontend->DiskInfo.SectorCount, Frontend->DiskInfo.SectorSize, - Frontend->DiskInfo.PhysSectorSize); - Verbose("Target[%d] : %d %s (%08x) %s\n", Frontend->TargetId, - __Size(&Frontend->DiskInfo), __Units(&Frontend->DiskInfo), - Frontend->DiskInfo.DiskInfo, - Frontend->Caps.SurpriseRemovable ? "SURPRISE_REMOVABLE" : ""); + Trace("Target[%d] : %lld sectors of %d bytes (%d)\n", Frontend->TargetId, + Frontend->DiskInfo.SectorCount, Frontend->DiskInfo.SectorSize, + Frontend->DiskInfo.PhysSectorSize); + Trace("Target[%d] : %d %s (%08x) %s\n", Frontend->TargetId, + __Size(&Frontend->DiskInfo), __Units(&Frontend->DiskInfo), + Frontend->DiskInfo.DiskInfo, + Frontend->Caps.SurpriseRemovable ? "SURPRISE_REMOVABLE" : ""); } static FORCEINLINE VOID -- 2.39.5