예제 #1
0
def umount_root(root_pool_mnt):
    if is_mounted(root_pool_mnt):
        run_command([UMOUNT, "-l", root_pool_mnt])
        for i in range(10):
            if not is_mounted(root_pool_mnt):
                return run_command([RMDIR, root_pool_mnt])
            time.sleep(1)
        run_command([UMOUNT, "-f", root_pool_mnt])
    if os.path.exists(root_pool_mnt):
        return run_command([RMDIR, root_pool_mnt])
    return True
예제 #2
0
def umount_root(root_pool_mnt):
    if (is_mounted(root_pool_mnt)):
        run_command([UMOUNT, '-l', root_pool_mnt])
        for i in range(10):
            if (not is_mounted(root_pool_mnt)):
                return run_command([RMDIR, root_pool_mnt])
            time.sleep(1)
        run_command([UMOUNT, '-f', root_pool_mnt])
    if (os.path.exists(root_pool_mnt)):
        return run_command([RMDIR, root_pool_mnt])
    return True
예제 #3
0
def umount_root(root_pool_mnt):
    if (is_mounted(root_pool_mnt)):
        run_command([UMOUNT, '-l', root_pool_mnt])
        for i in range(10):
            if (not is_mounted(root_pool_mnt)):
                return run_command([RMDIR, root_pool_mnt])
            time.sleep(1)
        run_command([UMOUNT, '-f', root_pool_mnt])
    if (os.path.exists(root_pool_mnt)):
        return run_command([RMDIR, root_pool_mnt])
    return True
예제 #4
0
def mount_source(source_ip, source_share):
    mnt_pt = ('/mnt/backup/%s_%s' % (source_ip, source_share))
    if (is_mounted(mnt_pt)):
        return True
    if (not os.path.isdir(mnt_pt)):
        os.makedirs(mnt_pt)
    cmd = [MOUNT, '%s:%s' % (source_ip, source_share), mnt_pt]
    return run_command(cmd)
예제 #5
0
def mount_source(source_ip, source_share):
    mnt_pt = ('/mnt/backup/%s_%s' % (source_ip, source_share))
    if (is_mounted(mnt_pt)):
        return True
    if (not os.path.isdir(mnt_pt)):
        os.makedirs(mnt_pt)
    cmd = [MOUNT, '%s:%s' % (source_ip, source_share), mnt_pt]
    return run_command(cmd)
예제 #6
0
def mount_share(share, pool_device, mnt_pt):
    if is_mounted(mnt_pt):
        return
    pool_device = "/dev/%s" % pool_device
    mount_root(share.pool, pool_device)
    subvol_str = "subvol=%s" % share.subvol_name
    create_tmp_dir(mnt_pt)
    mnt_cmd = [MOUNT, "-t", "btrfs", "-o", subvol_str, pool_device, mnt_pt]
    return run_command(mnt_cmd)
예제 #7
0
def mount_share(share, mnt_pt):
    if (is_mounted(mnt_pt)):
        return
    mount_root(share["pool"])
    pool_device = ('/dev/%s' % share["pool"]["disks"][0]["name"])
    subvol_str = 'subvol=%s' % share["subvol_name"]
    create_tmp_dir(mnt_pt)
    mnt_cmd = [MOUNT, '-t', 'btrfs', '-o', subvol_str, pool_device, mnt_pt]
    return run_command(mnt_cmd)
예제 #8
0
def mount_share(share, mnt_pt):
    if (is_mounted(mnt_pt)):
        return
    mount_root(share.pool)
    pool_device = ('/dev/%s' % share.pool.disk_set.first().name)
    subvol_str = 'subvol=%s' % share.subvol_name
    create_tmp_dir(mnt_pt)
    mnt_cmd = [MOUNT, '-t', 'btrfs', '-o', subvol_str, pool_device, mnt_pt]
    return run_command(mnt_cmd)
예제 #9
0
def mount_share(share, mnt_pt):
    if (is_mounted(mnt_pt)):
        return
    mount_root(share.pool)
    pool_device = ('/dev/%s' % share.pool.disk_set.first().name)
    subvol_str = 'subvol=%s' % share.subvol_name
    create_tmp_dir(mnt_pt)
    mnt_cmd = [MOUNT, '-t', 'btrfs', '-o', subvol_str, pool_device, mnt_pt]
    return run_command(mnt_cmd)
예제 #10
0
파일: btrfs.py 프로젝트: ygd2013520/onLink
def mount_share(share, mnt_pt):
	if (is_mounted(mnt_pt)):
		return
	mount_root(share["pool"])
	pool_device = ('/dev/%s' % share["pool"]["disks"][0]["name"])
	subvol_str = 'subvol=%s' % share["subvol_name"]
	create_tmp_dir(mnt_pt)
	mnt_cmd = [MOUNT, '-t', 'btrfs', '-o', subvol_str, pool_device, mnt_pt]
	return run_command(mnt_cmd)
예제 #11
0
def remove_snap(pool, pool_device, share_name, snap_name):
    root_mnt = mount_root(pool, pool_device)
    snap_path = "%s/.snapshots/%s/%s" % (root_mnt, share_name, snap_name)
    if not os.path.exists(snap_path):
        return remove_snap_old(pool, pool_device, share_name, snap_name)
    if is_mounted(snap_path):
        umount_root(snap_path)
    if is_subvol(snap_path):
        return run_command([BTRFS, "subvolume", "delete", snap_path])
    return True
예제 #12
0
def remove_snap(pool, pool_device, share_name, snap_name):
    root_mnt = mount_root(pool, pool_device)
    snap_path = ('%s/.snapshots/%s/%s' %
                 (root_mnt, share_name, snap_name))
    if (not os.path.exists(snap_path)):
        return remove_snap_old(pool, pool_device, share_name, snap_name)
    if (is_mounted(snap_path)):
        umount_root(snap_path)
    if (is_subvol(snap_path)):
        return run_command([BTRFS, 'subvolume', 'delete', snap_path])
    return True
예제 #13
0
def mount_share(share, mnt_pt):
    if (is_mounted(mnt_pt)):
        return
    mount_root(share.pool)
    pool_device = ('/dev/disk/by-id/%s' %
                   share.pool.disk_set.attached().first().target_name)
    subvol_str = 'subvol=%s' % share.subvol_name
    create_tmp_dir(mnt_pt)
    toggle_path_rw(mnt_pt, rw=False)
    mnt_cmd = [MOUNT, '-t', 'btrfs', '-o', subvol_str, pool_device, mnt_pt]
    return run_command(mnt_cmd)
예제 #14
0
def mount_snap(share, snap_name, snap_mnt=None):
    pool_device = "/dev/%s" % share.pool.disk_set.first().name
    share_path = "%s%s" % (DEFAULT_MNT_DIR, share.name)
    rel_snap_path = ".snapshots/%s/%s" % (share.name, snap_name)
    snap_path = "%s%s/%s" % (DEFAULT_MNT_DIR, share.pool.name, rel_snap_path)
    if snap_mnt is None:
        snap_mnt = "%s/.%s" % (share_path, snap_name)
    if is_mounted(snap_mnt):
        return
    mount_share(share, share_path)
    if is_subvol(snap_path):
        create_tmp_dir(snap_mnt)
        return run_command([MOUNT, "-o", "subvol=%s" % rel_snap_path, pool_device, snap_mnt])
예제 #15
0
def mount_snap(share, snap_name, snap_mnt=None):
    pool_device = ('/dev/%s' % share.pool.disk_set.first().name)
    share_path = ('%s%s' % (DEFAULT_MNT_DIR, share.name))
    rel_snap_path = ('.snapshots/%s/%s' % (share.name, snap_name))
    snap_path = ('%s%s/%s' % (DEFAULT_MNT_DIR, share.pool.name, rel_snap_path))
    if (snap_mnt is None):
        snap_mnt = ('%s/.%s' % (share_path, snap_name))
    if (is_mounted(snap_mnt)):
        return
    mount_share(share, share_path)
    if (is_subvol(snap_path)):
        create_tmp_dir(snap_mnt)
        return run_command(
            [MOUNT, '-o',
             'subvol=%s' % rel_snap_path, pool_device, snap_mnt])
예제 #16
0
def mount_snap(share, snap_name, snap_mnt=None):
    pool_device = ('/dev/%s' % share.pool.disk_set.first().name)
    share_path = ('%s%s' % (DEFAULT_MNT_DIR, share.name))
    rel_snap_path = ('.snapshots/%s/%s' % (share.name, snap_name))
    snap_path = ('%s%s/%s' %
                 (DEFAULT_MNT_DIR, share.pool.name, rel_snap_path))
    if (snap_mnt is None):
        snap_mnt = ('%s/.%s' % (share_path, snap_name))
    if (is_mounted(snap_mnt)):
        return
    mount_share(share, share_path)
    if (is_subvol(snap_path)):
        create_tmp_dir(snap_mnt)
        return run_command([MOUNT, '-o', 'subvol=%s' % rel_snap_path,
                            pool_device, snap_mnt])
예제 #17
0
def remove_snap(pool, share_name, snap_name):
    root_mnt = mount_root(pool)
    snap_path = "%s/.snapshots/%s/%s" % (root_mnt, share_name, snap_name)
    if is_mounted(snap_path):
        umount_root(snap_path)
    if is_subvol(snap_path):
        qgroup = "0/%s" % share_id(pool, snap_name)
        run_command([BTRFS, "subvolume", "delete", snap_path], log=True)
        return qgroup_destroy(qgroup, root_mnt)
    else:
        o, e, rc = run_command([BTRFS, "subvolume", "list", "-s", root_mnt])
        for l in o:
            # just give the first match.
            if re.match("ID.*%s$" % snap_name, l) is not None:
                snap = "%s/%s" % (root_mnt, l.split()[-1])
                return run_command([BTRFS, "subvolume", "delete", snap], log=True)
예제 #18
0
def remove_snap(pool, share_name, snap_name):
    root_mnt = mount_root(pool)
    snap_path = ('%s/.snapshots/%s/%s' %
                 (root_mnt, share_name, snap_name))
    if (is_mounted(snap_path)):
        umount_root(snap_path)
    if (is_subvol(snap_path)):
        qgroup = ('0/%s' % share_id(pool, snap_name))
        run_command([BTRFS, 'subvolume', 'delete', snap_path], log=True)
        return qgroup_destroy(qgroup, root_mnt)
    else:
        o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-s', root_mnt])
        for l in o:
            #just give the first match.
            if (re.match('ID.*%s$' % snap_name, l) is not None):
                snap = '%s/%s' % (root_mnt, l.split()[-1])
                return run_command([BTRFS, 'subvolume', 'delete', snap], log=True)
예제 #19
0
def remove_snap(pool, share_name, snap_name):
    root_mnt = mount_root(pool)
    snap_path = ('%s/.snapshots/%s/%s' % (root_mnt, share_name, snap_name))
    if (is_mounted(snap_path)):
        umount_root(snap_path)
    if (is_subvol(snap_path)):
        qgroup = ('0/%s' % share_id(pool, snap_name))
        run_command([BTRFS, 'subvolume', 'delete', snap_path], log=True)
        return qgroup_destroy(qgroup, root_mnt)
    else:
        o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-s', root_mnt])
        for l in o:
            #just give the first match.
            if (re.match('ID.*%s$' % snap_name, l) is not None):
                snap = '%s/%s' % (root_mnt, l.split()[-1])
                return run_command([BTRFS, 'subvolume', 'delete', snap],
                                   log=True)
예제 #20
0
def remove_snap(pool, pool_device, share_name, snap_name):
    root_mnt = mount_root(pool, pool_device)
    snap_path = ('%s/.snapshots/%s/%s' % (root_mnt, share_name, snap_name))
    if (is_mounted(snap_path)):
        umount_root(snap_path)
    if (is_subvol(snap_path)):
        return run_command([BTRFS, 'subvolume', 'delete', snap_path])
    else:
        o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-s', root_mnt])
        snap = None
        for l in o:
            #just give the first match.
            if (re.match('ID.*%s$' % snap_name, l) is not None):
                snap = '%s/%s' % (root_mnt, l.split()[-1])
                break
        e_msg = ('This snapshot(%s) was created outside of Rockstor. If you '
                 'really want to delete it, you can do so manually with this '
                 'command: btrfs subvol delete %s' % (snap_name, snap))
        raise Exception(e_msg)
예제 #21
0
def umount_root(root_pool_mnt):
    if (not os.path.exists(root_pool_mnt)):
        return
    try:
        o, e, rc = run_command([UMOUNT, '-l', root_pool_mnt])
    except CommandException as ce:
        if (ce.rc == 32):
            for l in ce.err:
                l = l.strip()
                if (re.search('not mounted$', l) is not None):
                    return
            raise ce
    for i in range(20):
        if (not is_mounted(root_pool_mnt)):
            toggle_path_rw(root_pool_mnt, rw=True)
            run_command([RMDIR, root_pool_mnt])
            return
        time.sleep(2)
    run_command([UMOUNT, '-f', root_pool_mnt])
    toggle_path_rw(root_pool_mnt, rw=True)
    run_command([RMDIR, root_pool_mnt])
    return
예제 #22
0
def umount_root(root_pool_mnt):
    if (not os.path.exists(root_pool_mnt)):
        return
    try:
        o, e, rc = run_command([UMOUNT, '-l', root_pool_mnt])
    except CommandException as ce:
        if (ce.rc == 32):
            for l in ce.err:
                l = l.strip()
                if (re.search('not mounted$', l) is not None):
                    return
            raise ce
    for i in range(20):
        if (not is_mounted(root_pool_mnt)):
            toggle_path_rw(root_pool_mnt, rw=True)
            run_command([RMDIR, root_pool_mnt])
            return
        time.sleep(2)
    run_command([UMOUNT, '-f', root_pool_mnt])
    toggle_path_rw(root_pool_mnt, rw=True)
    run_command([RMDIR, root_pool_mnt])
    return
예제 #23
0
파일: btrfs.py 프로젝트: wli5/rockstor-core
def remove_snap(pool, pool_device, share_name, snap_name):
    root_mnt = mount_root(pool, pool_device)
    snap_path = ('%s/.snapshots/%s/%s' %
                 (root_mnt, share_name, snap_name))
    if (is_mounted(snap_path)):
        umount_root(snap_path)
    if (is_subvol(snap_path)):
        qgroup = ('0/%s' % share_id(pool, pool_device, snap_name))
        run_command([BTRFS, 'subvolume', 'delete', snap_path], log=True)
        return qgroup_destroy(qgroup, root_mnt)
    else:
        o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-s', root_mnt])
        snap = None
        for l in o:
            #just give the first match.
            if (re.match('ID.*%s$' % snap_name, l) is not None):
                snap = '%s/%s' % (root_mnt, l.split()[-1])
                break
        e_msg = ('This snapshot(%s) was created outside of Rockstor. If you '
                 'really want to delete it, you can do so manually with this '
                 'command: btrfs subvol delete %s' % (snap_name, snap))
        raise Exception(e_msg)
예제 #24
0
def set_property(mnt_pt, name, val, mount=True):
    if (mount is not True or is_mounted(mnt_pt)):
        cmd = [BTRFS, 'property', 'set', mnt_pt, name, val]
        return run_command(cmd)
예제 #25
0
def remount(mnt_pt, mnt_options):
    if (is_mounted(mnt_pt)):
        run_command([MOUNT, '-o', 'remount,%s' % mnt_options, mnt_pt])
    return True
예제 #26
0
def set_property(mnt_pt, name, val, mount=True):
    if mount is not True or is_mounted(mnt_pt):
        cmd = [BTRFS, "property", "set", mnt_pt, name, val]
        return run_command(cmd)
예제 #27
0

def umount_root(root_pool_mnt):
    if (not os.path.exists(root_pool_mnt)):
        return
    try:
        o, e, rc = run_command([UMOUNT, '-l', root_pool_mnt])
    except CommandException, ce:
        if (ce.rc == 32):
            for l in ce.err:
                l = l.strip()
                if (re.search('not mounted$', l) is not None):
                    return
            raise ce
    for i in range(20):
        if (not is_mounted(root_pool_mnt)):
            run_command([RMDIR, root_pool_mnt])
            return
        time.sleep(2)
    run_command([UMOUNT, '-f', root_pool_mnt])
    run_command([RMDIR, root_pool_mnt])
    return


def remount(mnt_pt, mnt_options):
    if (is_mounted(mnt_pt)):
        run_command([MOUNT, '-o', 'remount,%s' % mnt_options, mnt_pt])
    return True


def is_subvol(mnt_pt):
예제 #28
0
def remount(mnt_pt, mnt_options):
    if is_mounted(mnt_pt):
        run_command([MOUNT, "-o", "remount,%s" % mnt_options, mnt_pt])
    return True
예제 #29
0
def remount(mnt_pt, mnt_options):
    if (is_mounted(mnt_pt)):
        run_command([MOUNT, '-o', 'remount,%s' % mnt_options, mnt_pt])
    return True
예제 #30
0
def main():
    mnt_pt = sys.argv[1]
    if (not is_mounted(mnt_pt)):
        sys.exit('Docker root(%s) not mounted.' % mnt_pt)
    run_command([DOCKER, '-d', '-s', 'btrfs', '-g', mnt_pt])
예제 #31
0

def umount_root(root_pool_mnt):
    if (not os.path.exists(root_pool_mnt)):
        return
    try:
        o, e, rc = run_command([UMOUNT, '-l', root_pool_mnt])
    except CommandException, ce:
        if (ce.rc == 32):
            for l in ce.err:
                l = l.strip()
                if (re.search('not mounted$', l) is not None):
                    return
            raise ce
    for i in range(20):
        if (not is_mounted(root_pool_mnt)):
            run_command([RMDIR, root_pool_mnt])
            return
        time.sleep(2)
    run_command([UMOUNT, '-f', root_pool_mnt])
    run_command([RMDIR, root_pool_mnt])
    return


def is_subvol(mnt_pt):
    """
    Simple wrapper around "btrfs subvolume show mnt_pt"
    :param mnt_pt: mount point of subvolume to query
    :return: True if subvolume mnt_pt exists, else False
    """
    show_cmd = [BTRFS, 'subvolume', 'show', mnt_pt]
예제 #32
0
def set_property(mnt_pt, name, val, mount=True):
    if (mount is not True or is_mounted(mnt_pt)):
        cmd = [BTRFS, 'property', 'set', mnt_pt, name, val]
        return run_command(cmd)