示例#1
0
async def _event_devfs(middleware, event_type, args):
    data = args['data']
    if data.get('subsystem') != 'CDEV':
        return

    if data['type'] == 'CREATE':
        disks = await middleware.threaded(
            lambda: sysctl.filter('kern.disks')[0].value.split())
        # Device notified about is not a disk
        if data['cdev'] not in disks:
            return
        # TODO: hack so every disk is not synced independently during boot
        # This is a performance issue
        if os.path.exists('/tmp/.sync_disk_done'):
            await middleware.call('disk.sync', data['cdev'])
            await middleware.call('disk.multipath_sync')
            try:
                with SmartAlert() as sa:
                    sa.device_delete(data['cdev'])
            except Exception:
                pass
    elif data['type'] == 'DESTROY':
        # Device notified about is not a disk
        if not RE_ISDISK.match(data['cdev']):
            return
        # TODO: hack so every disk is not synced independently during boot
        # This is a performance issue
        if os.path.exists('/tmp/.sync_disk_done'):
            await middleware.call('disk.sync_all')
            await middleware.call('disk.multipath_sync')
            try:
                with SmartAlert() as sa:
                    sa.device_delete(data['cdev'])
            except Exception:
                pass
示例#2
0
def event():
    device = os.environ.get('SMARTD_DEVICE')
    if device is None:
        return

    message = os.environ.get('SMARTD_MESSAGE')
    if message is None:
        return

    with SmartAlert() as sa:
        sa.message_add(device, message)
示例#3
0
async def _event_devfs(middleware, event_type, args):
    data = args['data']
    if data.get('subsystem') != 'CDEV':
        return

    if data['type'] == 'CREATE':
        disks = await middleware.run_in_thread(
            lambda: sysctl.filter('kern.disks')[0].value.split())
        # Device notified about is not a disk
        if data['cdev'] not in disks:
            return
        # TODO: hack so every disk is not synced independently during boot
        # This is a performance issue
        if os.path.exists('/tmp/.sync_disk_done'):
            await middleware.call('disk.sync', data['cdev'])
            await middleware.call('disk.sed_unlock', data['cdev'])
            await middleware.call('disk.multipath_sync')
            try:
                with SmartAlert() as sa:
                    sa.device_delete(data['cdev'])
            except Exception:
                pass
    elif data['type'] == 'DESTROY':
        # Device notified about is not a disk
        if not RE_ISDISK.match(data['cdev']):
            return
        # TODO: hack so every disk is not synced independently during boot
        # This is a performance issue
        if os.path.exists('/tmp/.sync_disk_done'):
            await (await middleware.call('disk.sync_all')).wait()
            await middleware.call('disk.multipath_sync')
            try:
                with SmartAlert() as sa:
                    sa.device_delete(data['cdev'])
            except Exception:
                pass
            # If a disk dies we need to reconfigure swaps so we are not left
            # with a single disk mirror swap, which may be a point of failure.
            await middleware.call('disk.swaps_configure')
示例#4
0
    def check_sync(self):
        alerts = []

        with SmartAlert() as sa:
            for msgs in sa.data.values():
                if not msgs:
                    continue
                for msg in msgs:
                    if msg is None:
                        continue
                    alerts.append(Alert(msg))

        return alerts
示例#5
0
    def run(self):
        alerts = []

        with SmartAlert() as sa:
            for msgs in sa.data.values():
                if not msgs:
                    continue
                for msg in msgs:
                    if msg is None:
                        continue
                    alerts.append(Alert(Alert.CRIT, msg, hardware=True))

        return alerts
示例#6
0
def remove(dev):
    if not dev.startswith('/dev/'):
        dev = '/dev/{0}'.format(dev)
    with SmartAlert() as sa:
        sa.device_delete(dev)
示例#7
0
def remove(dev):
    with SmartAlert() as sa:
        sa.device_delete(dev)