bool IsSystemAndBootDiskSame()

in host/common/unix/portablehelpersmajor.cpp [2785:2899]


bool IsSystemAndBootDiskSame(const VolumeSummaries_t & volumeSummaries, std::string & errormsg)
{
    DebugPrintf( SV_LOG_DEBUG, "ENTERED %s\n", FUNCTION_NAME ) ;
    /*
        - Find all devices with attribute has_bootable_partition set
            - Fail if none is found - bug in VIC
            - Fail if more than one found - bug in VIC
    */
    VolumeSummaries_t vVSBootPart;
    std::string strVSBootPart;
    ConstVolumeSummariesIter itrVS(volumeSummaries.begin());
    for (/*empty*/; itrVS != volumeSummaries.end(); ++itrVS)
    {
        ConstAttributesIter_t it = itrVS->attributes.find(NsVolumeAttributes::HAS_BOOTABLE_PARTITION);
        if (it != itrVS->attributes.end() && (0 == it->second.compare("true")))
        {
            DebugPrintf( SV_LOG_DEBUG, "vVSBootPart: %s\n", itrVS->name.c_str() ) ;
            vVSBootPart.push_back(*itrVS);
            strVSBootPart += itrVS->name;
            strVSBootPart += ", ";
        }
    }
    if ( 0 == vVSBootPart.size() )
    {
        /* Note: If we are here then its a bug in VIC */
        errormsg = "No device found in volumeSummaries with bootable partition attribute set.";
        return false;
    }
    if ( vVSBootPart.size() > 1 )
    {
        /* Note: If we are here then its a bug in VIC */
        errormsg = "bootable partition identified on multiple disks in volumeSummaries. ";
        errormsg += strVSBootPart;
        return false;
    }
    
    /*
        - Find logical volume with mount point root "/"
            - Copy volume group for this lv in string rootVG
            - Find all disks matching rootVG
                - Fail if none is found - Bug in VIC
                - Fail if more than one found - root volume on multiple disk
        - If root is mounted on partition volume
            - search through children of each disk
            - Copy name of root partition to rootPartition
    */
    std::string rootDisk;
    std::string rootVG;
    std::string rootPartition;
    for (itrVS = volumeSummaries.begin(); itrVS != volumeSummaries.end(); ++itrVS)
    {
        if ( (0 == itrVS->mountPoint.compare("/")) && (VolumeSummary::LOGICAL_VOLUME == itrVS->type) )
        {
            rootVG = itrVS->volumeGroup;
            break;
        }
        else if ( VolumeSummary::DISK == itrVS->type )
        {
            ConstVolumeSummariesIter itrVSChild(itrVS->children.begin());
            for (/*empty*/; itrVSChild != itrVS->children.end(); ++itrVSChild)
            {
                if ( 0 == itrVSChild->mountPoint.compare("/") )
                {
                    rootPartition = itrVSChild->name;
                    rootDisk = itrVS->name;
                    break;
                }
            }
            if (0 == itrVS->mountPoint.compare("/")) {
                rootPartition = itrVS->name;
                rootDisk = itrVS->name;
                break;
            }
        }
    }
    
    DebugPrintf( SV_LOG_DEBUG, "%s: rootVG=%s, rootPartition=%s\n", FUNCTION_NAME, rootVG.c_str(), rootPartition.c_str()) ;
    if ( rootVG.length() )
    {
        VolumeSummaries_t vVSRootVGDisks;
        for (itrVS = volumeSummaries.begin(); itrVS != volumeSummaries.end(); ++itrVS)
        {
            if ( (VolumeSummary::DISK == itrVS->type) && (0 == itrVS->volumeGroup.compare(rootVG)) )
            {
                vVSRootVGDisks.push_back(*itrVS);
                rootDisk += itrVS->name;
                rootDisk += ", ";
                DebugPrintf( SV_LOG_DEBUG, "vVSRootVGDisks: %s\n", itrVS->name.c_str() ) ;
            }
        }
        
        if ( vVSRootVGDisks.size() > 1)
        {
            DebugPrintf( SV_LOG_DEBUG, "Root is laid on an LVM device coming from multiple disks");
        }
        else if ( vVSRootVGDisks.size() < 1)
        {
            errormsg = "System/root volume not linked to any disks.";
            errormsg += " System disk: ";
            errormsg += rootDisk;
            errormsg += " Root VG: ";
            errormsg += rootVG;
            return false;
        }
    }
    else if ( !rootPartition.length() )
    {
        /* Note: If we are here then its a bug in VIC */
        errormsg = "System/root volume not found in volumeSummaries.";
        return false;
    }

    DebugPrintf( SV_LOG_DEBUG, "rootDisk = %s\n", rootDisk.c_str());
    return true;
}