OSDN Git Service

sun partition tables: add support for RAID partition types
authorTom "spot" Callaway <tcallawa@redhat.com>
Mon, 22 Dec 2008 14:39:23 +0000 (09:39 -0500)
committerJim Meyering <meyering@redhat.com>
Tue, 23 Dec 2008 09:21:20 +0000 (10:21 +0100)
This patch enables RAID as a supported partition type on Sun disk
layouts, commonly found/used on SPARC hardware. It has been tested
on Aurora SPARC Linux (and Fedora SPARC). I have no idea if Solaris
supports Software RAID or not...

Along with the code change, I wrote a test case that checks if the
RAID partition type is supported on sun disk labels.

* libparted/labels/sun.c [_SunPartitionData] (is_raid): New member.
(sun_read): Initialize the ->is_raid member.
(sun_partition_new): Clear is_raid, like all the other members.
(sun_partition_duplicate): Propagate the is_raid member.
(sun_partition_set_system): Make sun_data->type reflect is_raid.
(sun_partition_set_flag): Also initialize ->is_raid.
(sun_partition_get_flag): Handle PED_PARTITION_RAID.
(sun_partition_is_flag_available): Likewise.
* tests/t4000-sun-raid-type.sh: New file.
* tests/Makefile.am (TESTS): Add t4000-sun-raid-type.sh.

libparted/labels/sun.c
tests/Makefile.am
tests/t4000-sun-raid-type.sh [new file with mode: 0755]

index 6f1900b..76f2b78 100644 (file)
@@ -87,6 +87,7 @@ struct _SunPartitionData {
        int                     is_boot;
        int                     is_root;
        int                     is_lvm;
+       int                     is_raid;
 };
 
 struct _SunDiskData {
@@ -347,6 +348,7 @@ sun_read (PedDisk* disk)
                sun_data->is_boot = sun_data->type == 0x1;
                sun_data->is_root = sun_data->type == 0x2;
                sun_data->is_lvm = sun_data->type == 0x8e;
+               sun_data->is_raid = sun_data->type == 0xfd;
 
                part->num = i + 1;
                part->fs_type = ped_file_system_probe (&part->geom);
@@ -482,6 +484,7 @@ sun_partition_new (const PedDisk* disk, PedPartitionType part_type,
                sun_data->is_boot = 0;
                sun_data->is_root = 0;
                sun_data->is_lvm = 0;
+               sun_data->is_raid = 0;
        } else {
                part->disk_specific = NULL;
        }
@@ -515,6 +518,7 @@ sun_partition_duplicate (const PedPartition* part)
        new_sun_data->is_boot = old_sun_data->is_boot;
        new_sun_data->is_root = old_sun_data->is_root;
        new_sun_data->is_lvm = old_sun_data->is_lvm;
+       new_sun_data->is_raid = old_sun_data->is_raid;
        return new_part;
 }
 
@@ -547,6 +551,10 @@ sun_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
                sun_data->type = 0x8e;
                return 1;
        }
+       if (sun_data->is_raid) {
+               sun_data->type = 0xfd;
+               return 1;
+       }
 
        sun_data->type = 0x83;
        if (fs_type) {
@@ -573,20 +581,38 @@ sun_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
        switch (flag) {
                case PED_PARTITION_BOOT:
                        sun_data->is_boot = state;
-                       if (state)
-                               sun_data->is_root = sun_data->is_lvm = 0;
+                       if (state) {
+                               sun_data->is_lvm = 0;
+                               sun_data->is_raid = 0;
+                               sun_data->is_root = 0;
+                       }
                        return ped_partition_set_system (part, part->fs_type);
 
                case PED_PARTITION_ROOT:
                        sun_data->is_root = state;
-                       if (state)
-                               sun_data->is_boot = sun_data->is_lvm = 0;
+                       if (state) {
+                               sun_data->is_boot = 0;
+                               sun_data->is_lvm = 0;
+                               sun_data->is_raid = 0;
+                       }
                        return ped_partition_set_system (part, part->fs_type);
 
                case PED_PARTITION_LVM:
                        sun_data->is_lvm = state;
-                       if (state)
-                               sun_data->is_root = sun_data->is_boot = 0;
+                       if (state) {
+                               sun_data->is_boot = 0;
+                               sun_data->is_raid = 0;
+                               sun_data->is_root = 0;
+                       }
+                       return ped_partition_set_system (part, part->fs_type);
+
+               case PED_PARTITION_RAID:
+                       sun_data->is_raid = state;
+                       if (state) {
+                               sun_data->is_boot = 0;
+                               sun_data->is_lvm = 0;
+                               sun_data->is_root = 0;
+                       }
                        return ped_partition_set_system (part, part->fs_type);
 
                default:
@@ -612,6 +638,8 @@ sun_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
                        return sun_data->is_root;
                case PED_PARTITION_LVM:
                        return sun_data->is_lvm;
+               case PED_PARTITION_RAID:
+                       return sun_data->is_raid;
 
                default:
                        return 0;
@@ -627,6 +655,7 @@ sun_partition_is_flag_available (const PedPartition* part,
                case PED_PARTITION_BOOT:
                case PED_PARTITION_ROOT:
                case PED_PARTITION_LVM:
+               case PED_PARTITION_RAID:
                        return 1;
 
                default:
index 1c8c753..ab3b7cb 100644 (file)
@@ -9,6 +9,7 @@ TESTS = \
   t2200-dos-label-recog.sh \
   t3000-constraints.sh \
   t3100-resize-ext2-partion.sh \
+  t4000-sun-raid-type.sh \
   t4100-msdos-partition-limits.sh \
   t4100-dvh-partition-limits.sh \
   t4200-partprobe.sh \
diff --git a/tests/t4000-sun-raid-type.sh b/tests/t4000-sun-raid-type.sh
new file mode 100755 (executable)
index 0000000..34c56ee
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Written by Tom "spot" Callaway <tcallawa@redhat.com>
+# Derived from an example by Jim Meyering <jim@meyering.net>
+
+test_description="RAID support on sun disk type"
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+N=10M
+dev=sun-disk-file
+exp="BYT;\n---:20480s:file:512:512:sun:;\n1:0s:50s:51s"
+test_expect_success \
+    'create an empty file as a test disk' \
+    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
+
+test_expect_success \
+    'label the test disk as a sun disk' \
+    'parted -s $dev mklabel sun > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    'create a single partition' \
+    'parted -s $dev unit s mkpart ext2 0s 50s > out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    'print the partition data in machine readable format' \
+    'parted -m -s $dev unit s p > out 2>&1 &&
+     sed "s,^.*/$dev:,---:," out > k && mv k out'
+
+test_expect_success \
+    'check for expected values for the partition' '
+    printf "$exp:::;\n" > exp &&
+    $compare out exp'
+
+test_expect_success \
+    'set the raid flag' \
+    'parted -s $dev set 1 raid >out 2>&1'
+test_expect_success 'check for empty output' '$compare out /dev/null'
+
+test_expect_success \
+    'print the partition data in machine readable format again' \
+    'parted -m -s $dev unit s p > out 2>&1 &&
+     sed "s,^.*/$dev:,---:," out > k && mv k out'
+
+test_expect_success \
+    'check for expected values (including raid flag) for the partition' '
+    printf "$exp:::raid;\n" > exp &&
+    $compare out exp'
+
+test_done