Skip to content

Commit

Permalink
Merge pull request #1883 from phillxnet/1882_remove_immutable_flag_pr…
Browse files Browse the repository at this point in the history
…ior_to_share_delete

remove immutable flag prior to share delete. Fixes #1882
  • Loading branch information
schakrava authored Jan 28, 2018
2 parents 93d3a41 + 6b3401e commit cfe93fd
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/rockstor/fs/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
BTRFS = '/sbin/btrfs'
MOUNT = '/bin/mount'
UMOUNT = '/bin/umount'
CHATTR = '/usr/bin/chattr'
DEFAULT_MNT_DIR = '/mnt2/'
RMDIR = '/bin/rmdir'
QID = '2015'
Expand Down Expand Up @@ -557,9 +558,14 @@ def share_id(pool, share_name):
def remove_share(pool, share_name, pqgroup, force=False):
"""
umount share if its mounted.
mount root pool
btrfs subvolume delete root_mnt/vol_name
umount root pool
unsures given pool is mounted.
if force flag set then first delete all share's subvolumes.
btrfs subvolume delete root_mnt/vol_name.
destroy shares qgroup and associated pqgroup.
:param pool: pool object
:param share_name: Share name as in share.name
:param pqgroup: Pqgroup to be removed
:param force: Flag used to also remove all subvolumes of the given share.
"""
if (is_share_mounted(share_name)):
mnt_pt = ('%s%s' % (DEFAULT_MNT_DIR, share_name))
Expand All @@ -568,12 +574,20 @@ def remove_share(pool, share_name, pqgroup, force=False):
subvol_mnt_pt = root_pool_mnt + '/' + share_name
if (not is_subvol(subvol_mnt_pt)):
return
# Remove the immutable flag if set as this will block a subvol delete
# with an 'Operation not permitted' and leave an unmounted share.
# This flag can also break replication as we supplant the transient share.
# The immutable flag has been seen to spontaneously appear. Upon this
# bug being resolved we might consider promoting to force=True calls only.
chattr_cmd = [CHATTR, '-i', subvol_mnt_pt]
run_command(chattr_cmd, log=True)
if (force):
o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-o',
subvol_mnt_pt])
for l in o:
if (re.match('ID ', l) is not None):
subvol = root_pool_mnt + '/' + l.split()[-1]
# TODO: consider recursive immutable flag removal.
run_command([BTRFS, 'subvolume', 'delete', subvol], log=True)
qgroup = ('0/%s' % share_id(pool, share_name))
delete_cmd = [BTRFS, 'subvolume', 'delete', subvol_mnt_pt]
Expand Down

0 comments on commit cfe93fd

Please sign in to comment.