Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replication received_uuid blocker re snap to share promotion #2902 #2911

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/rockstor/fs/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ def remove_share(pool, share_name, pqgroup, force=False):
# TODO: Consider also using the following command to allow delete of the
# initial (anomalous) temp replication snap as share; but this also blindly
# circumvents ro 'protection' for any other share!
# set_property(subvol_mnt_pt, 'ro', 'false', mount=False)
# set_property(subvol_mnt_pt, 'ro', 'false', mount=False, force=True)
toggle_path_rw(subvol_mnt_pt, rw=True)
if force:
o, e, rc = run_command([BTRFS, "subvolume", "list", "-o", subvol_mnt_pt])
Expand Down Expand Up @@ -2308,9 +2308,16 @@ def btrfs_uuid(disk):
return o[0].split()[3]


def set_property(mnt_pt, name, val, mount=True):
def set_property(mnt_pt, name, val, mount=True, force=False):
"""
https://btrfs.readthedocs.io/en/latest/btrfs-property.html
https://btrfs.readthedocs.io/en/latest/btrfs-subvolume.html
"""
if mount is not True or is_mounted(mnt_pt):
cmd = [BTRFS, "property", "set", mnt_pt, name, val]
if not force:
cmd = [BTRFS, "property", "set", mnt_pt, name, val]
else:
cmd = [BTRFS, "property", "set", "-f", mnt_pt, name, val]
return run_command(cmd)


Expand Down
10 changes: 7 additions & 3 deletions src/rockstor/storageadmin/views/clone_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

def create_repclone(share, request, logger, snapshot):
"""
Variant of create_clone but where the share already exists and is to be
Variant of create_clone but where the share may already exist and is to be
supplanted by a snapshot which is effectively moved into the shares prior
position, both in the db and on the file system. This is achieved thus:
Unmount target share - (via remove_share()).
Expand Down Expand Up @@ -74,7 +74,7 @@ def create_repclone(share, request, logger, snapshot):
# Normalise source name across initial quirk share & subsequent snaps.
source_name = snapshot.name.split("/")[-1]
# Note in the above we have to use Object.name for polymorphism, but
# our share is passed by it's subvol (potential fragility point).
# our share is passed by its subvol (potential fragility point).
snap_path = "{}/.snapshots/{}/{}".format(
share.pool.mnt_pt, share.name, source_name
).replace("//", "/")
Expand All @@ -91,7 +91,11 @@ def create_repclone(share, request, logger, snapshot):
# unmounts and then subvol deletes our on disk share
remove_share(share.pool, share.name, PQGROUP_DEFAULT)
# Remove read only flag on our snapshot subvol
set_property(snap_path, "ro", "false", mount=False)
# N.B. more recent btrfs has force requirement re safeguard on received_uuid set.
# However, Rockstor replication cascades ro snapshots used in send/receive.
# The oldest of 3 received snapshot sends is promoted to Share, from 4th replication event onwards.
# As such this subvol is no longer referenced in the ongoing btrfs send/receive cascade.
set_property(snap_path, "ro", "false", mount=False, force=True)
# Ensure removed share path is clean, ie remove mount point.
run_command(["/usr/bin/rm", "-rf", share_path], throw=False)
# Now move snapshot to prior shares location. Given both a share and
Expand Down