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
1diff --git a/curtin/block/dasd.py b/curtin/block/dasd.py
2index 9e5b43e..3423601 100644
3--- a/curtin/block/dasd.py
4+++ b/curtin/block/dasd.py
5@@ -32,6 +32,57 @@ class DasdPartitionTable:
6 def tracks_needed(self, size_in_bytes):
7 return ((size_in_bytes - 1) // self.bytes_per_track) + 1
8
9+ def _ptable_for_new_partition(self, partnumber, partsize):
10+ if partnumber > 3:
11+ raise ValueError('DASD devices only allow 3 partitions')
12+
13+ # first partition always starts at track 2
14+ # all others start after the previous partition ends
15+ if partnumber == 1:
16+ start = 2
17+ else:
18+ start = int(self.partitions[-1].end) + 1
19+ end = start + self.tracks_needed(partsize) - 1
20+
21+ return [
22+ (p.start, p.end) for p in self.partitions[:partnumber-1]
23+ ] + [(start, end)]
24+
25+ def add_partition(self, partnumber, partsize):
26+ """ Add a partition to this DasdDevice specifying partnumber and size.
27+
28+ :param partnumber: integer value of partition number (1, 2 or 3)
29+ :param partsize: partition sizes in bytes.
30+
31+ :raises: ValueError on invalid devname
32+
33+ Example fdasd command with defaults:
34+ fdasd --verbose --config=/tmp/curtin/dasd-part1.fdasd /dev/dasdb
35+ """
36+ LOG.debug(
37+ "add_partition: partnumber: %s partsize: %s",
38+ partnumber, partsize)
39+
40+ partitions = self._ptable_for_new_partition(partnumber, partsize)
41+ LOG.debug("fdasd: partitions to be created: %s", partitions)
42+ content = "\n".join([
43+ "[%s,%s]" % (part[0], part[1]) for part in partitions
44+ ])
45+ LOG.debug("fdasd: content=\n%s", content)
46+ wfp = tempfile.NamedTemporaryFile(suffix=".fdasd", delete=False)
47+ wfp.close()
48+ util.write_file(wfp.name, content)
49+ cmd = ['fdasd', '--verbose', '--config=%s' % wfp.name, self.devname]
50+ LOG.debug('Partitioning %s with %s', self.devname, cmd)
51+ try:
52+ out, err = util.subp(cmd, capture=True)
53+ except util.ProcessExecutionError as e:
54+ LOG.error("Partitioning failed: %s", e)
55+ raise
56+ finally:
57+ if os.path.exists(wfp.name):
58+ os.unlink(wfp.name)
59+
60 @classmethod
61 def from_fdasd_output(cls, devname, output):
62 line_iter = iter(output.splitlines())
63@@ -226,59 +277,6 @@ class DasdDevice(CcwDevice):
64 def devname(self):
65 return '/dev/disk/by-path/ccw-%s' % self.device_id
66
67- def partition(self, partnumber, partsize, strict=True):
68- """ Add a partition to this DasdDevice specifying partnumber and size.
69-
70- :param partnumber: integer value of partition number (1, 2 or 3)
71- :param partsize: partition sizes in bytes.
72- :param strict: boolean which enforces that dasd device exists before
73- issuing fdasd command, defaults to True.
74-
75- :raises: RuntimeError if strict==True and devname does not exist.
76- :raises: ValueError on invalid devname
77-
78- Example fdasd command with defaults:
79- fdasd --verbose --config=/tmp/curtin/dasd-part1.fdasd /dev/dasdb
80- """
81- if partnumber > 3:
82- raise ValueError('DASD devices only allow 3 partitions')
83-
84- if strict and not os.path.exists(self.devname):
85- raise RuntimeError("devname '%s' does not exist" % self.devname)
86-
87- pt = DasdPartitionTable.from_fdasd(self.devname)
88- new_partitions = []
89- for partinfo in pt.partitions[0:partnumber]:
90- new_partitions.append((partinfo.start, partinfo.end))
91-
92- # first partition always starts at track 2
93- # all others start after the previous partition ends
94- if partnumber == 1:
95- start = 2
96- else:
97- start = int(pt.partitions[-1].end) + 1
98- # end is inclusive
99- end = start + pt.tracks_needed(partsize) - 1
100- new_partitions.append((start, end))
101-
102- content = "\n".join(["[%s,%s]" % (part[0], part[1])
103- for part in new_partitions])
104- LOG.debug("fdasd: partitions to be created: %s", new_partitions)
105- LOG.debug("fdasd: content=\n%s", content)
106- wfp = tempfile.NamedTemporaryFile(suffix=".fdasd", delete=False)
107- wfp.close()
108- util.write_file(wfp.name, content)
109- cmd = ['fdasd', '--verbose', '--config=%s' % wfp.name, self.devname]
110- LOG.debug('Partitioning %s with %s', self.devname, cmd)
111- try:
112- out, err = util.subp(cmd, capture=True)
113- except util.ProcessExecutionError as e:
114- LOG.error("Partitioning failed: %s", e)
115- raise
116- finally:
117- if os.path.exists(wfp.name):
118- os.unlink(wfp.name)
119-
120 def is_not_formatted(self):
121 """ Returns a boolean indicating if the specified device_id is not yet
122 formatted.
123diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
124index 66dfdb4..e29c1e4 100644
125--- a/curtin/commands/block_meta.py
126+++ b/curtin/commands/block_meta.py
127@@ -946,9 +946,8 @@ def partition_handler(info, storage_config):
128 "--typecode=%s:%s" % (partnumber, typecode), disk]
129 util.subp(cmd, capture=True)
130 elif disk_ptable == "vtoc":
131- disk_device_id = storage_config.get(device).get('device_id')
132- dasd_device = dasd.DasdDevice(disk_device_id)
133- dasd_device.partition(partnumber, length_bytes)
134+ dasd_pt = dasd.DasdPartitionTable.from_fdasd(disk)
135+ dasd_pt.add_partition(partnumber, length_bytes)
136 else:
137 raise ValueError("parent partition has invalid partition table")
138

Subscribers

People subscribed via source and target branches