コード例 #1
0
ファイル: initsvc.storage.php プロジェクト: carriercomm/teebx
function setupStorageDevices(&$conf, $filter = null, $boot = false)
{
    // check that there are mountpoints defined
    if (!is_array($conf['system']['storage']) || !is_array($conf['system']['storage']['fsmounts'])) {
        return 0;
    }
    //
    $setup = mountStorageDevices($conf);
    // check that service configuration exists
    if (!is_array($conf['system']['storage']['services'])) {
        return 0;
    }
    //
    // get callable service functions
    $svcFuncs = getAvailServices();
    // get a copy of the storage config array
    $storageCfg = $conf['system']['storage']['services'];
    // reduce it according to $filter if set
    if ($filter !== null && is_array($filter)) {
        $storageCfg = array_intersect_key($storageCfg, array_flip($filter));
    }
    // now loop thru $storageCfg array to initialize services
    foreach (array_keys($storageCfg) as $service) {
        // first check some required symbols
        if (!is_array($storageCfg[$service])) {
            continue;
        }
        //
        if (!isset($storageCfg[$service]['active'])) {
            continue;
        }
        // skip if disabled...
        if ($storageCfg[$service]['active'] != 1) {
            continue;
        }
        // ...the same if no mount point was set
        if (!isset($storageCfg[$service]['fsmount'])) {
            continue;
        }
        // check that the mount point this service depends on is enabled, else skip it
        $fsMount = $storageCfg[$service]['fsmount'];
        if ($conf['system']['storage']['fsmounts'][$fsMount]['active'] != 1) {
            continue;
        }
        // check that service has a callable function defined
        if (!isset($svcFuncs[$service]['handler'])) {
            $conf['system']['storage']['services'][$service]['active'] = -3;
            $setup['cfgchanged'] = 1;
            msgToSyslog("initialization for service ({$service}) failed because no handler available.");
            continue;
        }
        /*
        	check that the required directory exists, else make it.
        	This also to avoid a system call except the very first time.
        */
        $svcPath = "{$conf['system']['storage']['mountroot']}/{$fsMount}/{$svcFuncs[$service]['dirtree']}";
        if (!is_dir($svcPath)) {
            if (!mkdir($svcPath, 0766, true)) {
                $conf['system']['storage']['services'][$service]['active'] = -1;
                $setup['cfgchanged'] = 1;
                msgToSyslog("making directory for service ({$service}) failed.");
            }
        }
        $svcResult = call_user_func($svcFuncs[$service]['handler'], $svcPath);
        if ($svcResult === false) {
            // disable that service
            $conf['system']['storage']['services'][$service]['active'] = -2;
            $setup['cfgchanged'] = 1;
            msgToSyslog("handler for service ({$service}) failed during execution.");
        }
    }
    // check if configuration was changed due to some errors
    if ($setup['cfgchanged'] != 0) {
        // update configuration with current storage status
        write_config();
        // send this event to syslog
        msgToSyslog('something went wrong during storage initialization, please check status using the UI.', LOG_ERR);
    }
}
コード例 #2
0
function mountStorageDevices(&$conf)
{
    $log = array('cfgchanged' => 0, 'newdevs' => 0, 'fsappend' => array());
    if (!is_array($conf['system']['storage']['fsmounts'])) {
        return $log;
    }
    $devDisabled = 0;
    $devUnchanged = 0;
    $devConfigured = count($conf['system']['storage']['fsmounts']);
    foreach (array_keys($conf['system']['storage']['fsmounts']) as $devMount) {
        if (!is_array($conf['system']['storage']['fsmounts'][$devMount])) {
            // empty set, ignore it
            $devDisabled += 1;
            continue;
        }
        if ($conf['system']['storage']['fsmounts'][$devMount]['active'] != 1) {
            // disabled entry, ignore it
            $devDisabled += 1;
            continue;
        }
        $fullMntPath = "{$conf['system']['storage']['mountroot']}/{$devMount}";
        // check that is not already mounted
        if (isMountpoint($fullMntPath)) {
            $devUnchanged += 1;
            continue;
        }
        // make the fs mount point
        if (!is_dir($fullMntPath)) {
            if (!mkdir($fullMntPath, 0766, true)) {
                // should never happen... but disable entry because will not mount
                $conf['system']['storage']['fsmounts'][$devMount]['active'] = -1;
                $devDisabled += 1;
                $log['cfgchanged'] = 1;
                continue;
            }
        }
        // check that the device to be mounted is ready
        $devFsId = $conf['system']['storage']['fsmounts'][$devMount]['uuid'];
        $ready = waitDeviceFs($devFsId);
        if ($ready === false) {
            // device no longer exists? Anyway mark it as disabled
            $conf['system']['storage']['fsmounts'][$devMount]['active'] = -2;
            $devDisabled += 1;
            $log['cfgchanged'] = 1;
            continue;
        }
        $fsType = $conf['system']['storage']['fsmounts'][$devMount]['filesystem'];
        $fsMntOpts = "-w -t {$fsType} -o noatime";
        // mount the filesystem
        $fstabFsId = mountPart($devFsId, $fullMntPath, $fsMntOpts);
        if ($fstabFsId === false) {
            $conf['system']['storage']['fsmounts'][$devMount]['active'] = -3;
            $devDisabled += 1;
            $log['cfgchanged'] = 1;
            continue;
        }
        // update fstab buffer
        $log['fsappend'][] = $fstabFsId;
    }
    // write down a new fstab if needed
    $log['newdevs'] = count($log['fsappend']);
    msgToSyslog("storage check complete ({$devConfigured} devices configured, {$log['newdevs']} activated, {$devUnchanged} unchanged, {$devDisabled} disabled).");
    if ($log['newdevs'] > 0) {
        setupFstab(getConfiguredDisks($conf, false, true), 'from');
        msgToSyslog('fstab update complete.');
    }
    unset($log['fsappend']);
    return $log;
}