On Wed, 2014-06-18 at 10:51 -0400, mulhern wrote:
Resolves: fed#1109195
At the point where the filesystem is being created failure because btrfs
is not comfortable with the options specified is worse than success
w/out those particular options.
Signed-off-by: mulhern <amulhern(a)redhat.com>
---
blivet/devices.py | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/blivet/devices.py b/blivet/devices.py
index d488422..eb46b98 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -27,6 +27,7 @@ import tempfile
import abc
from decimal import Decimal
import re
+import itertools
# device backend modules
from .devicelibs import mdraid
@@ -5220,10 +5221,36 @@ class BTRFSVolumeDevice(BTRFSDevice, ContainerDevice):
def _create(self):
log_method_call(self, self.name, status=self.status)
- btrfs.create_volume(devices=[d.path for d in self.parents],
- label=self.format.label,
- data=self.dataLevel,
- metadata=self.metaDataLevel)
+
+ options = [ \
+ ("label", self.format.label),
+ ("data", self.dataLevel),
+ ("metadata", self.metaDataLevel)
+ ]
Why not 'options = [("label", self.format.label),' on
the first line and
having all the other lines aligned with it?
+
+ # Initially, try to create the volume with all non-None options.
+ # If that fails, try all possible combinations of non-None options.
+ # This is a workable approach because:
+ # - The options are independent
+ # - btrfs.create_volume treats None as none specified
+ options = dict((n,v) for n, v in options if v is not None)
+ option_names = options.keys()
+ option_choices = itertools.chain(*(itertools.combinations(option_names, n) for n
in range(len(option_names), -1, -1)))
+ kwargs_choices = (dict(map(lambda n: (n, options[n]), names)) for names in
option_choices)
These two lines are really hard to read and understand. At least for
me.
I like Haskell-like way of doing things, but not in Python.
+
+ for kwargs in kwargs_choices:
+ try:
+ btrfs.create_volume(
+ devices=[d.path for d in self.parents],
+ *kwargs)
+ return
+ except errors.BTRFSError:
+ log.warning(
+ "failed to create device %s with specified options %s",
+ self,
+ kwargs)
This is still quite a crazy roulette, almost russian,
I'd say. Doing
this behind user's back seems like a bad idea to me. Moreso with the
fact that this doesn't log the successfull combination that won the game
in the end.
--
Vratislav Podzimek
Anaconda Rider | RHCE | Red Hat, Inc. | Brno - Czech Republic