in host/common/unix/portablehelpersmajor.cpp [1058:1177]
bool CanUnmountMountPointsIncludingMultipath(const char * dev, std::vector<std::string> &mountPoints,std::string & errormsg)
{
bool rv = true;
VolumeSummaries_t volumeSummaries;
VolumeDynamicInfos_t volumeDynamicInfos;
VolumeInfoCollector volumeCollector;
volumeCollector.GetVolumeInfos(volumeSummaries, volumeDynamicInfos, false);
boost::shared_ptr<VolumeReporter> volinfo(new VolumeReporterImp());
VolumeReporter::VolumeReport_t volume_write_info;
volinfo->GetVolumeReport(dev,volumeSummaries,volume_write_info);
volinfo->PrintVolumeReport(volume_write_info);
std::stringstream out;
std::set<std::string> devListToUnmount;
VolumeReporter::EntityWriteStatesIter_t entityIter = volume_write_info.m_EntityWriteStates.begin();
VolumeReporter::EntityWriteStatesIter_t entityEndIter = volume_write_info.m_EntityWriteStates.end();
for(;entityIter != entityEndIter; ++entityIter)
{
VolumeReporter::WriteStates_t::iterator writeStateIter = entityIter->second.begin();
VolumeReporter::WriteStates_t::iterator writeStateEndIter = entityIter->second.end();
for(;writeStateIter != writeStateEndIter;++writeStateIter)
{
if(((*writeStateIter) != VolumeReporter::Mounted) &&
((*writeStateIter) != VolumeReporter::Locked) &&
((*writeStateIter) != VolumeReporter::Writable))
{
out << volinfo->GetEntityTypeStr(entityIter->first.m_Type) << " " << entityIter->first.m_Name;
if(entityIter->first.m_Type != VolumeReporter::Entity_t::EntityVolume)
out << " of device " << dev;
out << " " << volinfo->GetWriteStateStr((*writeStateIter)) << "\n";
errormsg = out.str();
return false;
}
if(((entityIter->first.m_Type == VolumeReporter::Entity_t::EntityChild) ||
(entityIter->first.m_Type == VolumeReporter::Entity_t::EntityMultipath)) && ((*writeStateIter) == VolumeReporter::Mounted))
{
devListToUnmount.insert(entityIter->first.m_Name);
}
}
}
if(IsInstallPathVolume(dev))
{
std::ostringstream ostr;
ostr << "Cannot Hide " << dev << " as it is agent installation volume." << std::endl;
errormsg = ostr.str().c_str();
return false;
}
std::string nestedmountpoints;
if(containsMountedVolumes(dev,nestedmountpoints))
{
std::ostringstream ostr;
ostr << "Cannot Hide " << dev << " as the drive contains mount points.\n";
errormsg = ostr.str().c_str();
return false;
}
if(containsVolpackFiles(dev))
{
std::ostringstream ostr;
ostr << "Cannot Hide " << dev << " as the volume contains virtual volume data.\n";
errormsg = ostr.str().c_str();
return false;
}
std::set<std::string>::iterator volumeIterator(devListToUnmount.begin());
std::set<std::string>::iterator volumeIteratorEnd(devListToUnmount.end());
for(; volumeIterator != volumeIteratorEnd; volumeIterator++)
{
if(IsInstallPathVolume(*volumeIterator))
{
std::ostringstream ostr;
ostr << "Cannot Hide " << (*volumeIterator) << " as it is agent installation volume." << std::endl;
errormsg = ostr.str().c_str();
rv = false;
break;
}
std::string nestedmountpoints;
if(containsMountedVolumes(*volumeIterator,nestedmountpoints))
{
std::ostringstream ostr;
ostr << "Cannot Hide " << (*volumeIterator) << " as the drive contains mount points.\n";
errormsg = ostr.str().c_str();
rv = false;
break;
}
if(containsVolpackFiles(*volumeIterator))
{
std::ostringstream ostr;
ostr << "Cannot Hide " << (*volumeIterator) << " as the volume contains virtual volume data.\n";
errormsg = ostr.str().c_str();
rv = false;
break;
}
std::string devicename=(*volumeIterator);
if(!GetDeviceNameFromSymLink(devicename))
{
DebugPrintf(SV_LOG_ERROR,
"Function %s @LINE %d in FILE %s :failed GetDeviceNameFromSymLink for %s \n",
FUNCTION_NAME, LINE_NO, FILE_NAME, devicename.c_str());
errormsg = "CanUnmountMountPointsIncludingMultipath(): Unable to obtain DeviceName from SymLink ";
errormsg += devicename;
rv = false;
break;
}
if(!GetMountPoints(devicename.c_str(),mountPoints))
{
DebugPrintf(SV_LOG_ERROR,
"Function %s @LINE %d in FILE %s :failed GetMountPoints for %s \n",
FUNCTION_NAME, LINE_NO, FILE_NAME, dev);
errormsg = "Unable to retrieve mountpoints associated with ";
errormsg += (*volumeIterator);
rv = false;
break;
}
}
return rv;
}