'Format a partition to filesystem type
:param fstype: the filesystem type, e.g.. "ext3", "ext2"
:param args: arguments to be passed to mkfs command.
:param record: if set, output result of mkfs operation to autotest
output'

def mkfs(self, fstype=None, args='', record=True):

    if list_mount_devices().count(self.device):
        raise NameError(('Attempted    to    format    mounted    device    %s' % self.device))
    if (not fstype):
        if self.fstype:
            fstype = self.fstype
        else:
            fstype = 'ext2'
    if self.mkfs_flags:
        args += ('    ' + self.mkfs_flags)
    if (fstype == 'xfs'):
        args += '    -f'
    if self.loop:
        if fstype.startswith('ext'):
            args += '    -F'
        elif (fstype == 'reiserfs'):
            args += '    -f'
    if ('-t' not in args):
        args = ('-t    %s    %s' % (fstype, args))
    args = args.strip()
    mkfs_cmd = ('%s    %s    %s' % (self.mkfs_exec(fstype), args, self.device))
    sys.stdout.flush()
    try:
        utils.system_output(('yes    |    %s' % mkfs_cmd))
    except error.CmdError as e:
        logging.error(e.result_obj)
        if record:
            self.job.record('FAIL', None, mkfs_cmd, error.format_error())
        raise
    except Exception:
        if record:
            self.job.record('FAIL', None, mkfs_cmd, error.format_error())
        raise
    else:
        if record:
            self.job.record('GOOD', None, mkfs_cmd)
        self.fstype = fstype
