Skip to content

Commit

Permalink
Merge pull request #1074 from schakrava/897_renamed_drives
Browse files Browse the repository at this point in the history
897 renamed drives
  • Loading branch information
schakrava committed Dec 30, 2015
2 parents bef9cea + b6081dc commit b37b8e0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 76 deletions.
9 changes: 9 additions & 0 deletions src/rockstor/scripts/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from system.osi import run_command
import requests
from django.conf import settings
from storageadmin.models import Setup


BASE_DIR = settings.ROOT_DIR
BASE_BIN = '%sbin' % BASE_DIR
Expand All @@ -42,6 +44,13 @@ def main():
sys.exit(1)
print('BTRFS device scan complete')

#if the appliance is not setup, there's nothing more to do beyond
#device scan
setup = Setup.objects.first()
if (setup is None or setup.setup_user is False):
print('Appliance is not yet setup.')
return

num_attempts = 0
while True:
try:
Expand Down
60 changes: 32 additions & 28 deletions src/rockstor/scripts/qgroup_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,38 @@

def main():
for p in Pool.objects.all():
print('Processing pool(%s)' % p.name)
mnt_pt = mount_root(p)
o, e, rc = run_command([BTRFS, 'subvol', 'list', mnt_pt])
subvol_ids = []
for l in o:
if (re.match('ID ', l) is not None):
subvol_ids.append(l.split()[1])

o, e, rc = run_command([BTRFS, 'qgroup', 'show', mnt_pt], throw=False)
if (rc != 0):
print('Quotas not enabled on pool(%s). Skipping it.' % p.name)
continue

qgroup_ids = []
for l in o:
if (re.match('0/', l) is not None):
q = l.split()[0].split('/')[1]
if (q == '5'):
continue
qgroup_ids.append(l.split()[0].split('/')[1])

for q in qgroup_ids:
if (q not in subvol_ids):
print('qgroup %s not in use. deleting' % q)
run_command([BTRFS, 'qgroup', 'destroy', '0/%s' % q, mnt_pt])
else:
print('qgroup %s is in use. Moving on.' % q)
print('Finished processing pool(%s)' % p.name)
try:
print('Processing pool(%s)' % p.name)
mnt_pt = mount_root(p)
o, e, rc = run_command([BTRFS, 'subvol', 'list', mnt_pt])
subvol_ids = []
for l in o:
if (re.match('ID ', l) is not None):
subvol_ids.append(l.split()[1])

o, e, rc = run_command([BTRFS, 'qgroup', 'show', mnt_pt], throw=False)
if (rc != 0):
print('Quotas not enabled on pool(%s). Skipping it.' % p.name)
continue

qgroup_ids = []
for l in o:
if (re.match('0/', l) is not None):
q = l.split()[0].split('/')[1]
if (q == '5'):
continue
qgroup_ids.append(l.split()[0].split('/')[1])

for q in qgroup_ids:
if (q not in subvol_ids):
print('qgroup %s not in use. deleting' % q)
run_command([BTRFS, 'qgroup', 'destroy', '0/%s' % q, mnt_pt])
else:
print('qgroup %s is in use. Moving on.' % q)
print('Finished processing pool(%s)' % p.name)
except Exception, e:
print ('Exception while qgroup-cleanup of Pool(%s): %s' %
(p.name, e.__str__()))


if __name__ == '__main__':
Expand Down
52 changes: 28 additions & 24 deletions src/rockstor/scripts/qgroup_maxout_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,37 @@

def main():
for p in Pool.objects.all():
print('Processing pool(%s)' % p.name)
mnt_pt = mount_root(p)
o, e, rc = run_command([BTRFS, 'qgroup', 'show', '-p', mnt_pt],
throw=False)
if (rc != 0):
print('Quotas not enabled on pool(%s). Skipping it.' % p.name)
continue

qgroup_ids = []
for l in o:
if (re.match('qgroupid', l) is not None or
re.match('-------', l) is not None):
try:
print('Processing pool(%s)' % p.name)
mnt_pt = mount_root(p)
o, e, rc = run_command([BTRFS, 'qgroup', 'show', '-p', mnt_pt],
throw=False)
if (rc != 0):
print('Quotas not enabled on pool(%s). Skipping it.' % p.name)
continue
cols = l.strip().split()
if (len(cols) != 4):
print('Ignoring unexcepted line(%s).' % l)
continue
if (cols[3] == '---'):
print('No parent qgroup for %s' % l)
continue
qgroup_ids.append(cols[3])

for q in qgroup_ids:
print('relaxing the limit on qgroup %s' % q)
run_command([BTRFS, 'qgroup', 'limit', 'none', q, mnt_pt])
qgroup_ids = []
for l in o:
if (re.match('qgroupid', l) is not None or
re.match('-------', l) is not None):
continue
cols = l.strip().split()
if (len(cols) != 4):
print('Ignoring unexcepted line(%s).' % l)
continue
if (cols[3] == '---'):
print('No parent qgroup for %s' % l)
continue
qgroup_ids.append(cols[3])

for q in qgroup_ids:
print('relaxing the limit on qgroup %s' % q)
run_command([BTRFS, 'qgroup', 'limit', 'none', q, mnt_pt])

print('Finished processing pool(%s)' % p.name)
print('Finished processing pool(%s)' % p.name)
except Exception, e:
print ('Exception while qgroup-maxout of Pool(%s): %s' %
(p.name, e.__str__()))


if __name__ == '__main__':
Expand Down
58 changes: 34 additions & 24 deletions src/rockstor/storageadmin/views/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,34 @@ class CommandView(NFSExportMixin, APIView):
BasicAuthentication, RockstorOAuth2Authentication,)
permission_classes = (IsAuthenticated,)

@staticmethod
@transaction.atomic
def _refresh_pool_state():
for p in Pool.objects.all():
if (p.disk_set.count() == 0):
p.delete()
continue
try:
mount_root(p)
fd = p.disk_set.first()
pool_info = get_pool_info(fd.name)
p.name = pool_info['label']
p.raid = pool_raid('%s%s' % (settings.MNT_PT, p.name))['data']
p.size = pool_usage('%s%s' % (settings.MNT_PT, p.name))[0]
p.save()
except Exception, e:
logger.error('Exception while refreshing state for '
'Pool(%s). Moving on: %s' %
(p.name, e.__str__()))
logger.exception(e)

@transaction.atomic
def post(self, request, command):
if (command == 'bootstrap'):

for pool in Pool.objects.all():
try:
mount_root(pool)
except Exception, e:
e_msg = ('Exception while mounting a pool(%s) during '
'bootstrap: %s' % (pool.name, e.__str__()))
logger.error(e_msg)
self._refresh_pool_state()
for p in Pool.objects.all():
import_shares(p, request)

for share in Share.objects.all():
try:
Expand All @@ -78,6 +95,15 @@ def post(self, request, command):
e_msg = ('Exception while mounting a share(%s) during '
'bootstrap: %s' % (share.name, e.__str__()))
logger.error(e_msg)
logger.exception(e)

try:
import_snapshots(share)
except Exception, e:
e_msg = ('Exception while importing Snapshots of '
'Share(%s): %s' % (share.name, e.__str__()))
logger.error(e_msg)
logger.exception(e)

for snap in Snapshot.objects.all():
if (snap.uvisible):
Expand Down Expand Up @@ -224,23 +250,7 @@ def post(self, request, command):
handle_exception(Exception(msg), request)

if (command == 'refresh-pool-state'):
for p in Pool.objects.all():
if (p.disk_set.count() == 0):
p.delete()
continue
try:
mount_root(p)
fd = p.disk_set.first()
pool_info = get_pool_info(fd.name)
p.name = pool_info['label']
p.raid = pool_raid('%s%s' % (settings.MNT_PT, p.name))['data']
p.size = pool_usage('%s%s' % (settings.MNT_PT, p.name))[0]
p.save()
except Exception, e:
logger.error('Exception while refreshing state for '
'Pool(%s). Moving on: %s' %
(p.name, e.__str__()))
logger.exception(e)
self._refresh_pool_state()
return Response()

if (command == 'refresh-share-state'):
Expand Down

0 comments on commit b37b8e0

Please sign in to comment.