From 41262228624c815bcc74a3d778db40c3cee177ce Mon Sep 17 00:00:00 2001 From: Suman Chakravartula Date: Tue, 1 Sep 2015 13:44:06 -0700 Subject: [PATCH] enable quota on imported pools. set qgroup on imported shares. Fixes #687 --- src/rockstor/storageadmin/views/disk.py | 9 +++------ src/rockstor/storageadmin/views/share.py | 2 +- src/rockstor/storageadmin/views/share_helpers.py | 9 ++++++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rockstor/storageadmin/views/disk.py b/src/rockstor/storageadmin/views/disk.py index 32b70d347..1b6e4bfab 100644 --- a/src/rockstor/storageadmin/views/disk.py +++ b/src/rockstor/storageadmin/views/disk.py @@ -15,19 +15,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ + from contextlib import contextmanager from storageadmin.exceptions import RockStorAPIException - -""" -Disk view, for anything at the disk level -""" - from rest_framework.response import Response from django.db import transaction from storageadmin.models import (Disk, Pool, Share) from fs.btrfs import (scan_disks, wipe_disk, blink_disk, enable_quota, btrfs_uuid, pool_usage, mount_root, get_pool_info, - pool_raid) + pool_raid, enable_quota) from storageadmin.serializers import DiskInfoSerializer from storageadmin.util import handle_exception from share_helpers import (import_shares, import_snapshots) @@ -201,6 +197,7 @@ def _btrfs_disk_import(self, dname, request): po.raid = pool_raid('%s%s' % (settings.MNT_PT, po.name))['data'] po.size = pool_usage('%s%s' % (settings.MNT_PT, po.name))[0] po.save() + enable_quota(po) import_shares(po) for share in Share.objects.filter(pool=po): import_snapshots(share) diff --git a/src/rockstor/storageadmin/views/share.py b/src/rockstor/storageadmin/views/share.py index fb4924c60..7ed03bc61 100644 --- a/src/rockstor/storageadmin/views/share.py +++ b/src/rockstor/storageadmin/views/share.py @@ -112,7 +112,7 @@ def post(self, request): #Before creating a new Share, we create the qgroup for it. And during #it's creation, we assign this qgroup to it. During it's creation a 0/x - #qgroup will automatically be created, but it will be come the child of + #qgroup will automatically be created, but it will become the child of #our explicitly-created qgroup(2015/x). #We will set the qgroup limit on our qgroup and it will enforce the diff --git a/src/rockstor/storageadmin/views/share_helpers.py b/src/rockstor/storageadmin/views/share_helpers.py index 8c2141924..a5d69adbd 100644 --- a/src/rockstor/storageadmin/views/share_helpers.py +++ b/src/rockstor/storageadmin/views/share_helpers.py @@ -22,7 +22,8 @@ from storageadmin.models import (Share, Disk, Snapshot, SFTP) from smart_manager.models import ShareUsage from fs.btrfs import (mount_share, mount_snap, is_share_mounted, is_mounted, - umount_root, shares_info, share_usage, snaps_info) + umount_root, shares_info, share_usage, snaps_info, + qgroup_create, update_quota) from storageadmin.util import handle_exception import logging @@ -120,8 +121,10 @@ def import_shares(pool): cshare.rusage, cshare.eusage = share_usage(pool, cshare.qgroup) cshare.save() except Share.DoesNotExist: - nso = Share(pool=pool, qgroup=shares_d[s], name=s, size=pool.size, - subvol_name=s) + pqid = qgroup_create(pool) + update_quota(pool, pqid, pool.size * 1024) + nso = Share(pool=pool, qgroup=shares_d[s], pqgroup=pqid, name=s, + size=pool.size, subvol_name=s) nso.save() mount_share(nso, '%s%s' % (settings.MNT_PT, s))