Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Create goal must check if security is enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Roy, Sunanda <[email protected]>
  • Loading branch information
Sunanda Roy authored and Juston Li committed Jan 12, 2018
1 parent 86cd4a0 commit bfa8c0e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
52 changes: 41 additions & 11 deletions src/cli/features/core/CreateGoalCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,24 @@ framework::ResultBase *CreateGoalCommand::execute(const framework::ParsedCommand
{
try
{
setupRequestBuilder();
const core::memory_allocator::MemoryAllocationRequest &request = m_requestBuilder.build();
core::memory_allocator::MemoryAllocationLayout layout = m_allocator.layout(request,
m_parser.getNamespaceLabelMajor(), m_parser.getNamespaceLabelMinor());
m_pResult = m_parser.verifySecurityState();

if (userReallyLikesThisLayout(layout, m_parser.getUnits()))
if (NULL == m_pResult)
{
m_allocator.allocate(layout);
m_pResult = m_showGoalAdapter.showCurrentGoal(m_parser.getUnits());
}
else
{
m_pResult = new NoChangeResult();
setupRequestBuilder();
const core::memory_allocator::MemoryAllocationRequest &request = m_requestBuilder.build();
core::memory_allocator::MemoryAllocationLayout layout = m_allocator.layout(request,
m_parser.getNamespaceLabelMajor(), m_parser.getNamespaceLabelMinor());

if (userReallyLikesThisLayout(layout, m_parser.getUnits()))
{
m_allocator.allocate(layout);
m_pResult = m_showGoalAdapter.showCurrentGoal(m_parser.getUnits());
}
else
{
m_pResult = new NoChangeResult();
}
}
}
catch (wbem::framework::Exception &e)
Expand Down Expand Up @@ -659,6 +664,31 @@ void CreateGoalCommand::Parser::parsePropertyConfig()
}
}

framework::ResultBase *CreateGoalCommand::Parser::verifySecurityState()
{
LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

std::string dimms = framework::Parser::getTargetValue(m_parsedCommand, TARGET_DIMM.name);
std::vector<core::device::Device> devices = ShowCommandUtilities::populateDevicesFromDimmsString(dimms, NVM_TRUE);

// Check for valid device security state
for (std::vector<core::device::Device>::const_iterator it = devices.begin(); it != devices.end(); it++)
{
core::device::Device device = (*it);
if (!(LOCK_STATE_DISABLED == device.getLockState()))
{
std::string result;
result = "Invalid device security state. Please set device security state to 'disabled' and try again.";
m_pResult = new framework::ErrorResult(
framework::ErrorResult::ERRORCODE_NOTSUPPORTED,
result);
break;
}
}

return m_pResult;
}

void CreateGoalCommand::Parser::parsePropertyNamespaceLabelVersion()
{
if (!hasError())
Expand Down
2 changes: 2 additions & 0 deletions src/cli/features/core/CreateGoalCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef CR_MGMT_CREATEGOALCOMMAND_H
#define CR_MGMT_CREATEGOALCOMMAND_H

#include <physical_asset/NVDIMMFactory.h>
#include <cli/features/core/framework/CommandBase.h>
#include <libinvm-cli/CommandSpec.h>
#include <libinvm-cli/ErrorResult.h>
Expand Down Expand Up @@ -91,6 +92,7 @@ class NVM_CLI_API CreateGoalCommand : public framework::CommandBase

Parser();
framework::ResultBase *parse(const framework::ParsedCommand &parsedCommand);
virtual framework::ResultBase *verifySecurityState();
int getMemoryMode();
NVM_UINT64 getReserved();
bool isPmTypeAppDirect();
Expand Down

0 comments on commit bfa8c0e

Please sign in to comment.