Skip to content

Commit

Permalink
Refresh disk state after pool deletion. Fixes #859
Browse files Browse the repository at this point in the history
  • Loading branch information
schakrava committed Oct 9, 2015
1 parent ed384c8 commit 2051f05
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/rockstor/storageadmin/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from home import (login_page, login_submit, logout_user, home)
from snapshot import SnapshotView
from share import (ShareListView, ShareDetailView)
from disk import (DiskMixin, DiskListView, DiskDetailView)
from pool import (PoolListView, PoolDetailView)
from disk import (DiskListView, DiskDetailView)
from command import CommandView
from share_iscsi import ShareIscsiView
from appliances import (ApplianceListView, ApplianceDetailView)
Expand Down
40 changes: 20 additions & 20 deletions src/rockstor/storageadmin/views/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@
logger = logging.getLogger(__name__)


class DiskListView(rfc.GenericView):
class DiskMixin(object):
serializer_class = DiskInfoSerializer

def get_queryset(self, *args, **kwargs):
#do rescan on get.
with self._handle_exception(self.request):
return Disk.objects.all().order_by('name')

@staticmethod
@transaction.atomic
def _scan(self):
def _update_disk_state():
disks = scan_disks(settings.MIN_DISK_SIZE)
for d in disks:
dob = None
Expand Down Expand Up @@ -73,7 +69,15 @@ def _scan(self):
else:
dob.pool = None
if (dob.pool is None and d.root is True):
self._create_root_pool(dob)
p = Pool(name=settings.ROOT_POOL, raid='single')
p.disk_set.add(d)
p.save()
d.pool = p
d.save()
p.size = pool_usage(mount_root(p))[0]
enable_quota(p)
p.uuid = btrfs_uuid(d.name)
p.save()
dob.save()
for do in Disk.objects.all():
if (do.name not in [d.name for d in disks]):
Expand All @@ -89,22 +93,18 @@ def _scan(self):
ds = DiskInfoSerializer(Disk.objects.all().order_by('name'), many=True)
return Response(ds.data)

def _create_root_pool(self, d):
p = Pool(name=settings.ROOT_POOL, raid='single')
p.disk_set.add(d)
p.save()
d.pool = p
d.save()
p.size = pool_usage(mount_root(p))[0]
enable_quota(p)
p.uuid = btrfs_uuid(d.name)
p.save()
return p

class DiskListView(DiskMixin, rfc.GenericView):
serializer_class = DiskInfoSerializer

def get_queryset(self, *args, **kwargs):
with self._handle_exception(self.request):
return Disk.objects.all().order_by('name')

def post(self, request, command, dname=None):
with self._handle_exception(request):
if (command == 'scan'):
return self._scan()
return self._update_disk_state()

e_msg = ('Unsupported command(%s).' % command)
handle_exception(Exception(e_msg), request)
Expand Down
7 changes: 6 additions & 1 deletion src/rockstor/storageadmin/views/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from django.db import transaction
from storageadmin.serializers import PoolInfoSerializer
from storageadmin.models import (Disk, Pool, Share, PoolBalance)
from storageadmin.views import DiskMixin
from fs.btrfs import (add_pool, pool_usage, resize_pool, umount_root,
btrfs_uuid, mount_root, remount, get_pool_info,
pool_raid, start_balance)
Expand Down Expand Up @@ -277,7 +278,7 @@ def post(self, request):
return Response(PoolInfoSerializer(p).data)


class PoolDetailView(PoolMixin, rfc.GenericView):
class PoolDetailView(DiskMixin, PoolMixin, rfc.GenericView):
def get(self, *args, **kwargs):
try:
pool = Pool.objects.get(name=self.kwargs['pname'])
Expand Down Expand Up @@ -455,4 +456,8 @@ def delete(self, request, pname):
pool_path = ('%s%s' % (settings.MNT_PT, pname))
umount_root(pool_path)
pool.delete()
try:
self._update_disk_state()
except Exception, e:
logger.error('Exception while updating disk state: %s' % e.__str__())
return Response()

0 comments on commit 2051f05

Please sign in to comment.