def md_next_name(self): count = 0 while True: name = '/dev/md%s' % count if name not in [md.name for md in self.mds]: return name if count >= 127: raise errors.MDAlreadyExistsError( 'Error while generating md name: ' 'names from /dev/md0 to /dev/md127 seem to be busy, ' 'try to generate md name manually') count += 1
def mdcreate(mdname, level, devices, metadata='default'): mds = mddisplay() # check if md device already exists if next((x for x in mds if x['name'] == mdname), False): raise errors.MDAlreadyExistsError( 'Error while creating md: md %s already exists' % mdname) # check if level argument is valid supported_levels = ('0', '1', 'raid0', 'raid1', 'stripe', 'mirror') if level not in supported_levels: raise errors.MDWrongSpecError('Error while creating md device: ' 'level must be one of: %s' % ', '.join(supported_levels)) # check if all necessary devices exist if not set(devices).issubset( set([bd['device'] for bd in hu.list_block_devices(disks=False)])): raise errors.MDNotFoundError( 'Error while creating md: at least one of devices is not found') # check if devices are not parts of some md array if set(devices) & set( itertools.chain.from_iterable(md.get('devices', []) for md in mds)): raise errors.MDDeviceDuplicationError( 'Error while creating md: at least one of devices is ' 'already in belongs to some md') # FIXME: mdadm will ask user to continue creating if any device appears to # be a part of raid array. Superblock zeroing helps to avoid that. for device in devices: mdclean(device) utils.execute('mdadm', '--create', '--force', mdname, '-e', metadata, '--level=%s' % level, '--raid-devices=%s' % len(devices), *devices, check_exit_code=[0])
def mdcreate(mdname, level, device, *args): mds = mddisplay() # check if md device already exists if filter(lambda x: x['name'] == mdname, mds): raise errors.MDAlreadyExistsError( 'Error while creating md: md %s already exists' % mdname) # check if level argument is valid supported_levels = ('0', '1', 'raid0', 'raid1', 'stripe', 'mirror') if level not in supported_levels: raise errors.MDWrongSpecError('Error while creating md device: ' 'level must be one of: %s' % ', '.join(supported_levels)) devices = [device] + list(args) # check if all necessary devices exist if not set(devices).issubset( set([bd['device'] for bd in hu.list_block_devices(disks=False)])): raise errors.MDNotFoundError( 'Error while creating md: at least one of devices is not found') # check if devices are not parts of some md array if set(devices) & \ set(reduce(lambda x, y: x + y, [md.get('devices', []) for md in mds], [])): raise errors.MDDeviceDuplicationError( 'Error while creating md: at least one of devices is ' 'already in belongs to some md') #FIXME: mdadm will ask user to continue creating if any device appears to # be a part of raid array. Superblock zeroing helps to avoid that. map(mdclean, devices) utils.execute('mdadm', '--create', '--force', mdname, '-e0.90', '--level=%s' % level, '--raid-devices=%s' % len(devices), *devices, check_exit_code=[0])