Merge lp:~raharper/curtin/set_bcache_cache_mode into lp:~curtin-dev/curtin/trunk

Proposed by Ryan Harper
Status: Merged
Merged at revision: 292
Proposed branch: lp:~raharper/curtin/set_bcache_cache_mode
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 104 lines (+44/-1)
3 files modified
curtin/commands/block_meta.py (+37/-0)
examples/tests/mdadm_bcache.yaml (+1/-0)
tests/vmtests/test_mdadm_bcache.py (+6/-1)
To merge this branch: bzr merge lp:~raharper/curtin/set_bcache_cache_mode
Reviewer Review Type Date Requested Status
Scott Moser (community) Approve
Review via email: mp+276194@code.launchpad.net

Description of the change

Update curtin to write out cache mode for bcache devices if 'cache_mode' is present in storage config for bcache devices.
Update vmtest for bcache to confirm that we can set cache_mode; note it also confirms that the setting is persistent since we reboot between curtin install and vmtest validation.

Fixes: lp:1510334

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

one suggestion in line. other than that, looks good.
and if i'm wrong on that, then go ahead and commit anyway.

review: Approve
296. By Ryan Harper

Find bcache device name via backing device holders

Add function get_holders which reads /sys/class/block/<dev>/holders
Use get_holders to list the bcache backing device holders to find the
assigned bcache device name

297. By Ryan Harper

vmtest: switch bcache test to use check_file_stripped_line

Use common check function in bcache testcase

298. By Ryan Harper

make check fixes for bcache cache_mode changes

Apply cleanups as found by make check

299. By Ryan Harper

vmtest: switch bcache test to use regex

After looking at how stripped line output works, using a
regex is more flexible in the face of bcache adding/removing
cache modes.

Revision history for this message
Ryan Harper (raharper) wrote :

I've addressed two things:

1) Blake highlighted that relying the the bcache storage config id isn't robust; it could be any string though in practice it tends to the the correct value. Instead, use the backing device to look up the bcache device name via sysfs holders dir.

2) Switch testcase to use check_file_regex

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/commands/block_meta.py'
2--- curtin/commands/block_meta.py 2015-10-26 10:02:13 +0000
3+++ curtin/commands/block_meta.py 2015-10-30 13:40:20 +0000
4@@ -155,6 +155,22 @@
5 util.subp(cmd, rcs=[0, 1, 2, 5], capture=True)
6
7
8+def get_holders(devname):
9+ if not devname:
10+ return []
11+
12+ devname_sysfs = \
13+ '/sys/class/block/{}/holders'.format(os.path.basename(devname))
14+ if not os.path.exists(devname_sysfs):
15+ err = ('No sysfs path to device holders:'
16+ ' {}'.format(devname_sysfs))
17+ LOG.error(err)
18+ raise ValueError(err)
19+
20+ LOG.debug('Getting blockdev holders: {}'.format(devname_sysfs))
21+ return os.listdir(devname_sysfs)
22+
23+
24 def clear_holders(sys_block_path):
25 holders = os.listdir(os.path.join(sys_block_path, "holders"))
26 LOG.info("clear_holders running on '%s', with holders '%s'" %
27@@ -882,6 +898,8 @@
28 storage_config)
29 cache_device = get_path_to_storage_volume(info.get('cache_device'),
30 storage_config)
31+ cache_mode = info.get('cache_mode', None)
32+
33 if not backing_device or not cache_device:
34 raise ValueError("backing device and cache device for bcache must be \
35 specified")
36@@ -909,6 +927,25 @@
37 fp.write(path)
38 fp.close()
39
40+ if cache_mode:
41+ # find the actual bcache device name via sysfs using the
42+ # backing device's holders directory.
43+ holders = get_holders(backing_device)
44+
45+ if len(holders) != 1:
46+ err = ('Invalid number of holding devices:'
47+ ' {}'.format(holders))
48+ LOG.error(err)
49+ raise ValueError(err)
50+
51+ [bcache_dev] = holders
52+ LOG.info("Setting cache_mode on {} to {}".format(bcache_dev,
53+ cache_mode))
54+ cache_mode_file = \
55+ '/sys/block/{}/bcache/cache_mode'.format(info.get('id'))
56+ with open(cache_mode_file, "w") as fp:
57+ fp.write(cache_mode)
58+
59 if info.get('name'):
60 # Make dname rule for this dev
61 make_dname(info.get('id'), storage_config)
62
63=== modified file 'examples/tests/mdadm_bcache.yaml'
64--- examples/tests/mdadm_bcache.yaml 2015-08-12 14:26:23 +0000
65+++ examples/tests/mdadm_bcache.yaml 2015-10-30 13:40:20 +0000
66@@ -46,6 +46,7 @@
67 name: cached_array
68 backing_device: mddevice
69 cache_device: sda5
70+ cache_mode: writeback
71 - id: sda1_root
72 type: format
73 fstype: ext4
74
75=== modified file 'tests/vmtests/test_mdadm_bcache.py'
76--- tests/vmtests/test_mdadm_bcache.py 2015-10-26 10:39:59 +0000
77+++ tests/vmtests/test_mdadm_bcache.py 2015-10-30 13:40:20 +0000
78@@ -50,13 +50,15 @@
79 cd OUTPUT_COLLECT_D
80 bcache-super-show /dev/vda6 > bcache_super_vda6
81 ls /sys/fs/bcache > bcache_ls
82+ cat /sys/block/bcache0/bcache/cache_mode > bcache_cache_mode
83 """)]
84 fstab_expected = {
85 '/dev/bcache0': '/media/data'
86 }
87
88 def test_bcache_output_files_exist(self):
89- self.output_files_exist(["bcache_super_vda6", "bcache_ls"])
90+ self.output_files_exist(["bcache_super_vda6", "bcache_ls",
91+ "bcache_cache_mode"])
92
93 def test_bcache_status(self):
94 bcache_cset_uuid = None
95@@ -68,6 +70,9 @@
96 with open(os.path.join(self.td.mnt, "bcache_ls"), "r") as fp:
97 self.assertTrue(bcache_cset_uuid in fp.read().splitlines())
98
99+ def test_bcache_cachemode(self):
100+ self.check_file_regex("bcache_cache_mode", r"\[writeback\]")
101+
102
103 class WilyTestMdadmBcache(TestMdadmBcacheAbs):
104 __test__ = True

Subscribers

People subscribed via source and target branches