~ubuntu-branches/ubuntu/intrepid/parted/intrepid

« back to all changes in this revision

Viewing changes to debian/patches/parted-dmraid.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2008-08-14 10:52:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080814105222-lzwmytspy0d1ki9s
Tags: 1.8.8.git.2008.03.24-7ubuntu3
debian/patches/parted-dmraid.dpatch: Patch to educate libparted about
dmraid arrays, which use device mapper. Libparted was naming new partition
nodes incorrectly, and not setting the UUIDs for dmraid device nodes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## parted-dmraid.dpatch by Luke Yelavich <themuso@ubuntu.com>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: Patch to ensure that device mapper devices for dmraid arrays do not
 
6
## DP: have extra nodes created needlessly.
 
7
 
 
8
@DPATCH@
 
9
diff -urNad parted-1.8.8.git.2008.03.24~/libparted/arch/linux.c parted-1.8.8.git.2008.03.24/libparted/arch/linux.c
 
10
--- parted-1.8.8.git.2008.03.24~/libparted/arch/linux.c 2008-08-15 09:39:18.000000000 +1000
 
11
+++ parted-1.8.8.git.2008.03.24/libparted/arch/linux.c  2008-08-15 09:41:02.000000000 +1000
 
12
@@ -263,6 +263,10 @@
 
13
 
 
14
 static char* _device_get_part_path (PedDevice* dev, int num);
 
15
 static int _partition_is_mounted_by_path (const char* path);
 
16
+#ifdef ENABLE_DEVICE_MAPPER
 
17
+static int _is_dmraid_device (char* devpath);
 
18
+static char* dmraid_device;
 
19
+#endif
 
20
 
 
21
 static int
 
22
 _is_ide_major (int major)
 
23
@@ -1996,6 +2000,10 @@
 
24
         } else if (!strncmp (dev->path, "/dev/loop", 9)) {
 
25
                 /* Loop devices can only have one partition. */
 
26
                 strcpy (result, dev->path);
 
27
+#ifdef ENABLE_DEVICE_MAPPER
 
28
+        } else if (dev->type == PED_DEVICE_DM && _is_dmraid_device (dev->path)) {
 
29
+                snprintf (result, result_len, "%s%d", dev->path, num);
 
30
+#endif
 
31
         } else if (dev->type == PED_DEVICE_DAC960
 
32
                         || dev->type == PED_DEVICE_CPQARRAY
 
33
                         || dev->type == PED_DEVICE_ATARAID
 
34
@@ -2368,6 +2376,8 @@
 
35
         char*           vol_name = NULL;
 
36
         char*           dev_name = NULL;
 
37
         char*           params = NULL;
 
38
+        char*           dm_uuid = NULL;
 
39
+        int             uuid_len;
 
40
 
 
41
         if (!_has_partitions(disk))
 
42
                 return 0;
 
43
@@ -2401,6 +2411,12 @@
 
44
         dm_task_set_name (task, vol_name);
 
45
         dm_task_add_target (task, 0, part->geom.length,
 
46
                 "linear", params);
 
47
+        if (_is_dmraid_device (disk->dev->path)) {
 
48
+                uuid_len = (strlen (vol_name) + 8);
 
49
+                dm_uuid = (char*) ped_malloc (uuid_len);
 
50
+                snprintf(dm_uuid, uuid_len, "DMRAID-%s", vol_name);
 
51
+                dm_task_set_uuid(task, dm_uuid);
 
52
+        }
 
53
         rc = dm_task_run(task);
 
54
         if (rc >= 0) {
 
55
                 //printf("0 %ld linear %s\n", part->geom.length, params);
 
56
@@ -2408,6 +2424,8 @@
 
57
                 dm_task_destroy(task);
 
58
                 free(params);
 
59
                 free(vol_name);
 
60
+                if (dm_uuid)
 
61
+                        ped_free(dm_uuid);
 
62
                 return 1;
 
63
         } else {
 
64
                 _dm_remove_map_name(vol_name);
 
65
@@ -2443,6 +2461,60 @@
 
66
                 if (!_dm_add_partition (disk, part))
 
67
                         rc = 0;
 
68
         }
 
69
+        if (dmraid_device)
 
70
+                ped_free(dmraid_device);
 
71
+        return rc;
 
72
+}
 
73
+
 
74
+static int
 
75
+_is_dmraid_device (char* devpath)
 
76
+{
 
77
+        struct dm_task* task = NULL;
 
78
+        int             rc = 0;
 
79
+        const char*     dmraid_uuid;
 
80
+        int             dm_len;
 
81
+        char*           dm_name = NULL;
 
82
+
 
83
+        dm_name = strrchr (devpath, '/');
 
84
+        if (dm_name && *dm_name && *(++dm_name))
 
85
+                dm_name = strdup (dm_name);
 
86
+        else
 
87
+                dm_name = strdup (devpath);
 
88
+        if (!dm_name)
 
89
+                return 0;
 
90
+
 
91
+        dm_len = strlen(dm_name);
 
92
+
 
93
+        if (!dmraid_device) {
 
94
+                dmraid_device = (char*) ped_malloc(dm_len);
 
95
+                if (!dmraid_device)
 
96
+                        return 0;
 
97
+        }
 
98
+
 
99
+        if (strcmp (dmraid_device, dm_name) == 0) {
 
100
+                return 1;
 
101
+        }
 
102
+
 
103
+        task = dm_task_create(DM_DEVICE_DEPS);
 
104
+        if (!task)
 
105
+                return 0;
 
106
+
 
107
+        dm_task_set_name(task, dm_name);
 
108
+        rc = dm_task_run(task);
 
109
+        if (rc < 0) {
 
110
+                rc = 0;
 
111
+                goto err;
 
112
+        }
 
113
+        rc = 0;
 
114
+
 
115
+        dmraid_uuid = dm_task_get_uuid(task);
 
116
+        if (strncmp (dmraid_uuid, "DMRAID-", 8)) {
 
117
+                strcpy (dmraid_device, dm_name);
 
118
+                rc = 1;
 
119
+        }
 
120
+
 
121
+err:
 
122
+        dm_task_destroy(task);
 
123
         return rc;
 
124
 }
 
125
 #endif