use O_DIRECT
This commit is contained in:
@ -21,10 +21,30 @@ const static char *randomsrc = (char *)"/dev/urandom";
|
||||
|
||||
Shred::Shred()
|
||||
{
|
||||
// Allocate aligned buffers for O_DIRECT
|
||||
if (posix_memalign((void **)&caTfngData, O_DIRECT_PAGE_SIZE, TFNG_DATA_SIZE) != 0)
|
||||
{
|
||||
Logger::logThis()->error("Failed to allocate aligned buffer for tfng data");
|
||||
caTfngData = nullptr;
|
||||
}
|
||||
|
||||
if (posix_memalign((void **)&caReadBuffer, O_DIRECT_PAGE_SIZE, CHUNK_SIZE) != 0)
|
||||
{
|
||||
Logger::logThis()->error("Failed to allocate aligned buffer for read buffer");
|
||||
caReadBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Shred::~Shred()
|
||||
{
|
||||
if (caTfngData != nullptr)
|
||||
{
|
||||
free(caTfngData);
|
||||
}
|
||||
if (caReadBuffer != nullptr)
|
||||
{
|
||||
free(caReadBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,6 +63,12 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
|
||||
drive->u32DriveChecksumAfterShredding = UINT32_MAX;
|
||||
drive->state = Drive::TaskState::SHRED_ACTIVE;
|
||||
|
||||
if ((caTfngData == nullptr) || (caReadBuffer == nullptr))
|
||||
{
|
||||
Logger::logThis()->error("Shred-Task: Aligned memory not available! - Drive: " + drive->getSerial());
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef DRYRUN
|
||||
for (int i = 0; i <= 100; i++)
|
||||
{
|
||||
@ -69,7 +95,13 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
|
||||
}
|
||||
|
||||
// open disk
|
||||
driveFileDiscr = open(cpDrivePath, O_RDWR | O_LARGEFILE);
|
||||
driveFileDiscr = open(cpDrivePath, O_RDWR | O_LARGEFILE | O_DIRECT);
|
||||
if (driveFileDiscr == -1 && errno == EINVAL)
|
||||
{
|
||||
driveFileDiscr = open(cpDrivePath, O_RDWR | O_LARGEFILE);
|
||||
Logger::logThis()->warning("O_DIRECT not supported, using standard I/O - Drive: " + drive->getSerial());
|
||||
}
|
||||
|
||||
if (driveFileDiscr == -1)
|
||||
{
|
||||
std::string errorMsg(strerror(errno));
|
||||
|
||||
Reference in New Issue
Block a user