Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Partitioning locking and refactoring #955

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/udisks2-sections.txt.daemon.sections.in
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ udisks_linux_block_object_contains_filesystem
udisks_linux_block_object_lock_for_cleanup
udisks_linux_block_object_try_lock_for_cleanup
udisks_linux_block_object_release_cleanup_lock
udisks_linux_block_object_acquire_bsd_lock
<SUBSECTION Standard>
UDISKS_TYPE_LINUX_BLOCK_OBJECT
UDISKS_LINUX_BLOCK_OBJECT
Expand Down
28 changes: 28 additions & 0 deletions src/tests/dbus-tests/test_10_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,34 @@ def test_60_resolve_device(self):
self.assertEqual(len(devices), 1)
self.assertIn(object_path, devices)

# create a partition on another device
disk = self.get_object('/block_devices/' + os.path.basename(self.vdevs[2]))
self.assertIsNotNone(disk)
disk.Format('gpt', self.no_options, dbus_interface=self.iface_prefix + '.Block')
self.addCleanup(self._wipe, self.vdevs[2])
part_label = 'PRTLBLX'
path = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(100 * 1024**2),
'', part_label, self.no_options,
dbus_interface=self.iface_prefix + '.PartitionTable')
part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)
part_uuid = self.get_property_raw(part, '.Partition', 'UUID')
self.assertIsNotNone(part_uuid)
part_name_val = self.get_property_raw(part, '.Partition', 'Name')
self.assertEquals(part_name_val, part_label)

# check that partlabel and partuuid can be resolved
spec = dbus.Dictionary({'partlabel': part_label}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
object_path = '%s/block_devices/%s1' % (self.path_prefix, os.path.basename(self.vdevs[2]))
self.assertEqual(len(devices), 1)
self.assertIn(object_path, devices)
spec = dbus.Dictionary({'partuuid': part_uuid}, signature='sv')
devices = manager.ResolveDevice(spec, self.no_options)
object_path = '%s/block_devices/%s1' % (self.path_prefix, os.path.basename(self.vdevs[2]))
self.assertEqual(len(devices), 1)
self.assertIn(object_path, devices)

def test_80_device_presence(self):
'''Test the debug devices are present on the bus'''
for d in self.vdevs:
Expand Down
55 changes: 19 additions & 36 deletions src/tests/dbus-tests/test_60_partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def _remove_format(self, device):
try:
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to keep the retry here for the wipefs call.


def _create_format(self, device, ftype):
device.Format(ftype, self.no_options, dbus_interface=self.iface_prefix + '.Block')
Expand All @@ -28,9 +26,7 @@ def _remove_partition(self, part):
try:
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
pass

def test_create_mbr_partition(self):
disk = self.get_object('/block_devices/' + os.path.basename(self.vdevs[0]))
Expand All @@ -39,6 +35,7 @@ def test_create_mbr_partition(self):
# create msdos partition table
self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

pttype = self.get_property(disk, '.PartitionTable', 'Type')
pttype.assertEqual('dos')
Expand All @@ -55,7 +52,6 @@ def test_create_mbr_partition(self):
# create partition
path1 = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(100 * 1024**2), part_type, '',
self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path1)
self.assertIsNotNone(part)
Expand Down Expand Up @@ -103,7 +99,6 @@ def test_create_mbr_partition(self):
# create another partition
path2 = disk.CreatePartition(dbus.UInt64(1024**2 + (1024**2 + 100 * 1024**2)), dbus.UInt64(100 * 1024**2),
part_type, '', self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path2)
self.assertIsNotNone(part)
Expand All @@ -113,7 +108,6 @@ def test_create_mbr_partition(self):
# create yet another partition
path3 = disk.CreatePartition(dbus.UInt64(1024**2 + 2 * (1024**2 + 100 * 1024**2)), dbus.UInt64(100 * 1024**2),
part_type, '', self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path3)
self.assertIsNotNone(part)
Expand All @@ -136,11 +130,11 @@ def create_extended_partition(self, ext_options, log_options, part_type=''):
# create msdos partition table
self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create extended partition
ext_path = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(150 * 1024**2), part_type, '',
ext_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

ext_part = self.bus.get_object(self.iface_prefix, ext_path)
self.assertIsNotNone(ext_part)
Expand All @@ -163,7 +157,6 @@ def create_extended_partition(self, ext_options, log_options, part_type=''):
# create logical partition
log_path = disk.CreatePartition(dbus.UInt64(1024**2), dbus.UInt64(50 * 1024**2), '', '',
log_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

log_part = self.bus.get_object(self.iface_prefix, log_path)
self.assertIsNotNone(log_part)
Expand All @@ -180,7 +173,6 @@ def create_extended_partition(self, ext_options, log_options, part_type=''):
# create one more logical partition
log_path2 = disk.CreatePartition(dbus.UInt64(dbus_offset.value + dbus_size.value), dbus.UInt64(50 * 1024**2), '', '',
log_options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

log_part2 = self.bus.get_object(self.iface_prefix, log_path2)
self.assertIsNotNone(log_part2)
Expand All @@ -202,6 +194,7 @@ def test_fill_with_primary_partitions(self):
# create msdos partition table
self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

options = dbus.Dictionary({'partition-type': 'primary'}, signature='sv')
offset = 1024**2
Expand All @@ -210,7 +203,6 @@ def test_fill_with_primary_partitions(self):
# create primary partition
path = disk.CreatePartition(dbus.UInt64(offset + i * (offset + size)), dbus.UInt64(size), '', '',
options, dbus_interface=self.iface_prefix + '.PartitionTable')
self.udev_settle()

part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)
Expand All @@ -232,6 +224,7 @@ def test_create_gpt_partition(self):
pttype.assertEqual('gpt')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

gpt_name = 'home'
gpt_type = '933ac7e1-2eb4-4f13-b844-0e14e2aef915'
Expand All @@ -241,7 +234,6 @@ def test_create_gpt_partition(self):
gpt_type, gpt_name,
self.no_options, dbus_interface=self.iface_prefix + '.PartitionTable')

self.udev_settle()
part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)

Expand Down Expand Up @@ -290,6 +282,7 @@ def test_create_with_format(self):
self._create_format(disk, 'dos')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create partition with ext4 format
path = disk.CreatePartitionAndFormat(dbus.UInt64(1024**2), dbus.UInt64(100 * 1024**2), '', '',
Expand Down Expand Up @@ -345,6 +338,7 @@ def test_create_with_format_auto_type_mbr(self):
self._create_format(disk, 'dos')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create partition with udf format and automatically set partition type
# it should be 0x07
Expand Down Expand Up @@ -376,10 +370,11 @@ def test_create_with_format_auto_type_gpt(self):
disk = self.get_object('/block_devices/' + os.path.basename(self.vdevs[0]))
self.assertIsNotNone(disk)

# create msdos partition table
# create gpt partition table
self._create_format(disk, 'gpt')

self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

# create partition with udf format and automatically set partition type
# it should be ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
Expand Down Expand Up @@ -414,9 +409,7 @@ def _remove_format(self, device):
try:
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
device.Format('empty', d, dbus_interface=self.iface_prefix + '.Block')
pass

def _create_format(self, device, ftype):
device.Format(ftype, self.no_options, dbus_interface=self.iface_prefix + '.Block')
Expand All @@ -425,9 +418,7 @@ def _remove_partition(self, part):
try:
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
except dbus.exceptions.DBusException:
self.udev_settle()
time.sleep(5)
part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')
pass

def _create_partition(self, disk, start=1024**2, size=100 * 1024**2, fmt='ext4', type=''):
if fmt:
Expand All @@ -439,7 +430,6 @@ def _create_partition(self, disk, start=1024**2, size=100 * 1024**2, fmt='ext4',
self.no_options,
dbus_interface=self.iface_prefix + '.PartitionTable')

self.udev_settle()
part = self.bus.get_object(self.iface_prefix, path)
self.assertIsNotNone(part)

Expand All @@ -451,14 +441,13 @@ def test_delete(self):

self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
path = str(part.object_path)

part.Delete(self.no_options, dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_name = path.split('/')[-1]
disk_name = os.path.basename(self.vdevs[0])
part_syspath = '/sys/block/%s/%s' % (disk_name, part_name)
Expand All @@ -481,6 +470,7 @@ def test_dos_flags(self):

self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -491,7 +481,6 @@ def test_dos_flags(self):
# set boot flag (10000000(2), 128(10), 0x80(16))
part.SetFlags(dbus.UInt64(128), self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_flags = self.get_property(part, '.Partition', 'Flags')
Expand All @@ -510,6 +499,7 @@ def test_gpt_flags(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk, fmt=False, type=esp_guid)
self.addCleanup(self._remove_partition, part)
Expand All @@ -531,7 +521,6 @@ def test_gpt_flags(self):
# set legacy BIOS bootable flag (100(2), 4(10), 0x4(16))
part.SetFlags(dbus.UInt64(4), self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_flags = self.get_property(part, '.Partition', 'Flags')
Expand All @@ -555,6 +544,7 @@ def test_gpt_type(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -572,7 +562,6 @@ def test_gpt_type(self):
home_guid = '933ac7e1-2eb4-4f13-b844-0e14e2aef915'
part.SetType(home_guid, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_type = self.get_property(part, '.Partition', 'Type')
Expand All @@ -589,6 +578,7 @@ def test_dos_type(self):

self._create_format(disk, 'dos')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -606,7 +596,6 @@ def test_dos_type(self):
part_type = '0x8e' # 'Linux LVM' type, see https://en.wikipedia.org/wiki/Partition_type#PID_8Eh
part.SetType(part_type, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')
self.udev_settle()

# test flags value on types
dbus_type = self.get_property(part, '.Partition', 'Type')
Expand All @@ -624,6 +613,7 @@ def test_resize(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

disk_size = self.get_property(disk, '.Block', 'Size')

Expand All @@ -649,8 +639,6 @@ def test_resize(self):
part.Resize(0, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_offset.assertEqual(initial_offset)
max_size = part_size.value
part_size.assertGreater(initial_size)
Expand All @@ -660,8 +648,6 @@ def test_resize(self):
part.Resize(new_size, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_offset.assertEqual(initial_offset)
# resize should guarantee at least the requested size
part_size.assertGreater(new_size - 1)
Expand All @@ -671,8 +657,6 @@ def test_resize(self):
part.Resize(max_size, self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

part_offset.assertEqual(initial_offset)
part_size.assertGreater(max_size - 1)
part_size.assertLess(disk_size.value)
Expand All @@ -683,6 +667,7 @@ def test_name(self):

self._create_format(disk, 'gpt')
self.addCleanup(self._remove_format, disk)
self.addCleanup(self.wipe_fs, self.vdevs[0])

part = self._create_partition(disk)
self.addCleanup(self._remove_partition, part)
Expand All @@ -700,8 +685,6 @@ def test_name(self):
part.SetName('test', self.no_options,
dbus_interface=self.iface_prefix + '.Partition')

self.udev_settle()

# test flags value on types
dbus_name = self.get_property(part, '.Partition', 'Name')
dbus_name.assertEqual('test')
Expand Down
Loading