Skip to content

Commit

Permalink
Add option to specify metadata version when creating MD RAID
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtrefny committed Oct 10, 2023
1 parent 2214c37 commit da7c50b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 5 additions & 1 deletion data/org.freedesktop.UDisks2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
@level: The RAID level for the array.
@name: The name for the array.
@chunk: The chunk size (in bytes) or 0 if @level is <quote>raid1</quote>.
@options: Options - known options (in addition to <link linkend="udisks-std-options">standard options</link>) include <parameter>bitmap</parameter> (of type 'ay').
@options: Options - known options (in addition to <link linkend="udisks-std-options">standard options</link>) include <parameter>bitmap</parameter> (of type 'ay') and <parameter>version</parameter> (of type 'ay').
@resulting_array: An object path to the object implementing the #org.freedesktop.UDisks2.MDRaid interface.
@since: 2.0.0
Expand All @@ -171,6 +171,10 @@
is not present, it is up to <literal>mdadm</literal> to decide
whether to create an internal bitmap (typically for arrays larger
than 100 GB) or not.
The @version option specifies the MD metadata version, for example
'0.90'. If not specified the default medata version specified by
<literal>mdadm</literal> is used.
-->
<method name="MDRaidCreate">
<arg name="blocks" direction="in" type="ao"/>
Expand Down
28 changes: 25 additions & 3 deletions src/tests/dbus-tests/test_mdraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ def _force_remove(self, array_name, array_members):
def _zero_superblock(self, device):
self.run_command('mdadm --zero-superblock --force %s' % device)

def _array_create(self, array_name, bitmap=None):
def _array_create(self, array_name, bitmap=None, version=None):
# set the 'force' cleanup now in case create fails
self.addCleanup(self._force_remove, array_name, [m.path for m in self.members])

d = self.no_options
if bitmap:
if bitmap or version:
d = dbus.Dictionary(signature='sv')
d['bitmap'] = self.str_to_ay(bitmap)
if bitmap:
d['bitmap'] = self.str_to_ay(bitmap)
if version:
d['version'] = self.str_to_ay(version)

manager = self.get_object('/Manager')
with wait_for_action('resync'):
Expand Down Expand Up @@ -391,6 +394,25 @@ def test_bitmap_location(self):
dbus_bitmap.assertEqual(self.str_to_ay(sys_bitmap))
self.assertStartswith(sys_bitmap, '+')

@udiskstestcase.tag_test(udiskstestcase.TestTags.UNSTABLE)
def test_metadata_version(self):
array_name = 'udisks_test_version'
array = self._array_create(array_name, version='0.90')

# check IdVersion on the Block interface
for member in self.members:
md_version = self.get_property(member.obj, '.Block', 'IdVersion')
md_version.assertEqual('0.90.0')

array.Delete(self.no_options, dbus_interface=self.iface_prefix + '.MDRaid')
self.udev_settle()

array = self._array_create(array_name)
# check IdVersion on the Block interface
for member in self.members:
md_version = self.get_property(member.obj, '.Block', 'IdVersion')
md_version.assertEqual('1.2')

@udiskstestcase.tag_test(udiskstestcase.TestTags.UNSTABLE)
def test_request_action(self):

Expand Down
4 changes: 3 additions & 1 deletion src/udiskslinuxmanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ handle_mdraid_create (UDisksManager *_object,
guint disks_top = 0;
gboolean success = FALSE;
const gchar *option_bitmap = NULL;
const gchar *option_version = NULL;

if (!udisks_daemon_util_get_caller_uid_sync (manager->daemon,
invocation,
Expand Down Expand Up @@ -767,7 +768,8 @@ handle_mdraid_create (UDisksManager *_object,
disks[disks_top] = NULL;

g_variant_lookup (arg_options, "bitmap", "^&ay", &option_bitmap);
if (!bd_md_create (array_name, arg_level, disks, 0, NULL, option_bitmap, arg_chunk, NULL, &error))
g_variant_lookup (arg_options, "version", "^&ay", &option_version);
if (!bd_md_create (array_name, arg_level, disks, 0, option_version, option_bitmap, arg_chunk, NULL, &error))
{
g_prefix_error (&error, "Error creating RAID array: ");
udisks_simple_job_complete (UDISKS_SIMPLE_JOB (job), FALSE, error->message);
Expand Down

0 comments on commit da7c50b

Please sign in to comment.