[PATCH 2/2] add support for recreating a btrfs subvolume
Gene Czarcinski
gene at czarc.net
Wed Oct 16 14:14:25 UTC 2013
This patch is intended to implement the BTRFS equivalent of
reformatting a subvolume from a kickstart. That is, a subvolume
is destroyed and then (re)created. As currently implemented this
is a "hack" which only works for a subvolume with the "/"
mountpoint. Once the pykickstart package has been updated
to separate --noformat and --useexisting parameters so that they
can have different meanings, the simple test for "/" can be
removed the the rest of the patch is good.
To invoke this functionality, the user must specify --useexisting
on the btrfs command for the "/" mountpoint. If the subvolume
does not exist, it does not matter and processing will continue.
Again, once pykickstart is updated, this will work for other
subvolumes.
---
pyanaconda/kickstart.py | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index f364113..660dd9b 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -369,7 +369,9 @@ class BTRFSData(commands.btrfs.F17_BTRFSData):
if self.mountpoint != "" and self.mountpoint[0] != '/':
raise KickstartValueError(formatErrorMsg(self.lineno, msg="The mount point \"%s\" is not valid." % (self.mountpoint,)))
- if not self.format: # --noformat
+ # FIXME: The following hack only exists until pykickstart can be updated to separate
+ # --noformat and --useexisting into separate parameters so they can have different meanings
+ if not self.format and self.mountpoint != "/": # --noformat
if not self.subvol:
raise KickstartValueError(formatErrorMsg(self.lineno, msg="Specifying btrfs command for existing volume %s invalid" % self.name))
@@ -393,6 +395,16 @@ class BTRFSData(commands.btrfs.F17_BTRFSData):
except KeyError:
pass
+ # Handle pre-existing subvol to be deleted
+ if self.subvol:
+ device = devicetree.getDeviceByName(self.name)
+ if device:
+ if self.preexist:
+ storage.destroyDevice(device)
+ log.info("As requested by specified --useexisting, destroying existing BTRFS subvolume %s" % self.name)
+ else:
+ raise KickstartValueError(formatErrorMsg(self.lineno, msg="Specified BTRFS subvolume %s already exists, specify --useexisting to recreate" % self.name))
+
request = storage.newBTRFS(name=name,
subvol=self.subvol,
mountpoint=self.mountpoint,
--
1.8.3.1
More information about the anaconda-patches
mailing list