Merge ~mwhudson/curtin:partition-dasd-without-device_id into curtin:master

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: aa3b5848467933c8b14dab6899360d83ff28a45c
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~mwhudson/curtin:partition-dasd-without-device_id
Merge into: curtin:master
Diff against target: 137 lines (+53/-56)
2 files modified
curtin/block/dasd.py (+51/-53)
curtin/commands/block_meta.py (+2/-3)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Paride Legovini Pending
Review via email: mp+395330@code.launchpad.net

This proposal supersedes a proposal from 2020-11-19.

Commit message

allow adding a vtoc partition without a device id

this is needed for the "dasd passed to kvm via virtio" use case

Description of the change

pls note the prerequisite branch

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Paride Legovini (paride) wrote : Posted in a previous version of this proposal

LGTM from the code perspective, but I didn't test it.

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote : Posted in a previous version of this proposal

Hmm prerequisite branches and a bot that squash merges do not get along.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/curtin/block/dasd.py b/curtin/block/dasd.py
index 9e5b43e..3423601 100644
--- a/curtin/block/dasd.py
+++ b/curtin/block/dasd.py
@@ -32,6 +32,57 @@ class DasdPartitionTable:
32 def tracks_needed(self, size_in_bytes):32 def tracks_needed(self, size_in_bytes):
33 return ((size_in_bytes - 1) // self.bytes_per_track) + 133 return ((size_in_bytes - 1) // self.bytes_per_track) + 1
3434
35 def _ptable_for_new_partition(self, partnumber, partsize):
36 if partnumber > 3:
37 raise ValueError('DASD devices only allow 3 partitions')
38
39 # first partition always starts at track 2
40 # all others start after the previous partition ends
41 if partnumber == 1:
42 start = 2
43 else:
44 start = int(self.partitions[-1].end) + 1
45 end = start + self.tracks_needed(partsize) - 1
46
47 return [
48 (p.start, p.end) for p in self.partitions[:partnumber-1]
49 ] + [(start, end)]
50
51 def add_partition(self, partnumber, partsize):
52 """ Add a partition to this DasdDevice specifying partnumber and size.
53
54 :param partnumber: integer value of partition number (1, 2 or 3)
55 :param partsize: partition sizes in bytes.
56
57 :raises: ValueError on invalid devname
58
59 Example fdasd command with defaults:
60 fdasd --verbose --config=/tmp/curtin/dasd-part1.fdasd /dev/dasdb
61 """
62 LOG.debug(
63 "add_partition: partnumber: %s partsize: %s",
64 partnumber, partsize)
65
66 partitions = self._ptable_for_new_partition(partnumber, partsize)
67 LOG.debug("fdasd: partitions to be created: %s", partitions)
68 content = "\n".join([
69 "[%s,%s]" % (part[0], part[1]) for part in partitions
70 ])
71 LOG.debug("fdasd: content=\n%s", content)
72 wfp = tempfile.NamedTemporaryFile(suffix=".fdasd", delete=False)
73 wfp.close()
74 util.write_file(wfp.name, content)
75 cmd = ['fdasd', '--verbose', '--config=%s' % wfp.name, self.devname]
76 LOG.debug('Partitioning %s with %s', self.devname, cmd)
77 try:
78 out, err = util.subp(cmd, capture=True)
79 except util.ProcessExecutionError as e:
80 LOG.error("Partitioning failed: %s", e)
81 raise
82 finally:
83 if os.path.exists(wfp.name):
84 os.unlink(wfp.name)
85
35 @classmethod86 @classmethod
36 def from_fdasd_output(cls, devname, output):87 def from_fdasd_output(cls, devname, output):
37 line_iter = iter(output.splitlines())88 line_iter = iter(output.splitlines())
@@ -226,59 +277,6 @@ class DasdDevice(CcwDevice):
226 def devname(self):277 def devname(self):
227 return '/dev/disk/by-path/ccw-%s' % self.device_id278 return '/dev/disk/by-path/ccw-%s' % self.device_id
228279
229 def partition(self, partnumber, partsize, strict=True):
230 """ Add a partition to this DasdDevice specifying partnumber and size.
231
232 :param partnumber: integer value of partition number (1, 2 or 3)
233 :param partsize: partition sizes in bytes.
234 :param strict: boolean which enforces that dasd device exists before
235 issuing fdasd command, defaults to True.
236
237 :raises: RuntimeError if strict==True and devname does not exist.
238 :raises: ValueError on invalid devname
239
240 Example fdasd command with defaults:
241 fdasd --verbose --config=/tmp/curtin/dasd-part1.fdasd /dev/dasdb
242 """
243 if partnumber > 3:
244 raise ValueError('DASD devices only allow 3 partitions')
245
246 if strict and not os.path.exists(self.devname):
247 raise RuntimeError("devname '%s' does not exist" % self.devname)
248
249 pt = DasdPartitionTable.from_fdasd(self.devname)
250 new_partitions = []
251 for partinfo in pt.partitions[0:partnumber]:
252 new_partitions.append((partinfo.start, partinfo.end))
253
254 # first partition always starts at track 2
255 # all others start after the previous partition ends
256 if partnumber == 1:
257 start = 2
258 else:
259 start = int(pt.partitions[-1].end) + 1
260 # end is inclusive
261 end = start + pt.tracks_needed(partsize) - 1
262 new_partitions.append((start, end))
263
264 content = "\n".join(["[%s,%s]" % (part[0], part[1])
265 for part in new_partitions])
266 LOG.debug("fdasd: partitions to be created: %s", new_partitions)
267 LOG.debug("fdasd: content=\n%s", content)
268 wfp = tempfile.NamedTemporaryFile(suffix=".fdasd", delete=False)
269 wfp.close()
270 util.write_file(wfp.name, content)
271 cmd = ['fdasd', '--verbose', '--config=%s' % wfp.name, self.devname]
272 LOG.debug('Partitioning %s with %s', self.devname, cmd)
273 try:
274 out, err = util.subp(cmd, capture=True)
275 except util.ProcessExecutionError as e:
276 LOG.error("Partitioning failed: %s", e)
277 raise
278 finally:
279 if os.path.exists(wfp.name):
280 os.unlink(wfp.name)
281
282 def is_not_formatted(self):280 def is_not_formatted(self):
283 """ Returns a boolean indicating if the specified device_id is not yet281 """ Returns a boolean indicating if the specified device_id is not yet
284 formatted.282 formatted.
diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
index 66dfdb4..e29c1e4 100644
--- a/curtin/commands/block_meta.py
+++ b/curtin/commands/block_meta.py
@@ -946,9 +946,8 @@ def partition_handler(info, storage_config):
946 "--typecode=%s:%s" % (partnumber, typecode), disk]946 "--typecode=%s:%s" % (partnumber, typecode), disk]
947 util.subp(cmd, capture=True)947 util.subp(cmd, capture=True)
948 elif disk_ptable == "vtoc":948 elif disk_ptable == "vtoc":
949 disk_device_id = storage_config.get(device).get('device_id')949 dasd_pt = dasd.DasdPartitionTable.from_fdasd(disk)
950 dasd_device = dasd.DasdDevice(disk_device_id)950 dasd_pt.add_partition(partnumber, length_bytes)
951 dasd_device.partition(partnumber, length_bytes)
952 else:951 else:
953 raise ValueError("parent partition has invalid partition table")952 raise ValueError("parent partition has invalid partition table")
954953

Subscribers

People subscribed via source and target branches