~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/disk/mdraid_linux.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* mdraid_linux.c - module to handle Linux Software RAID.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2008,2009,2010  Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  GRUB is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <grub/dl.h>
 
21
#include <grub/disk.h>
 
22
#include <grub/mm.h>
 
23
#include <grub/err.h>
 
24
#include <grub/misc.h>
 
25
#include <grub/raid.h>
 
26
 
 
27
/* Linux RAID on disk structures and constants,
 
28
   copied from include/linux/raid/md_p.h.  */
 
29
 
 
30
#define RESERVED_BYTES                  (64 * 1024)
 
31
#define RESERVED_SECTORS                (RESERVED_BYTES / 512)
 
32
 
 
33
#define NEW_SIZE_SECTORS(x)             ((x & ~(RESERVED_SECTORS - 1)) \
 
34
                                        - RESERVED_SECTORS)
 
35
 
 
36
#define SB_BYTES                        4096
 
37
#define SB_WORDS                        (SB_BYTES / 4)
 
38
#define SB_SECTORS                      (SB_BYTES / 512)
 
39
 
 
40
/*
 
41
 * The following are counted in 32-bit words
 
42
 */
 
43
#define SB_GENERIC_OFFSET               0
 
44
 
 
45
#define SB_PERSONALITY_OFFSET           64
 
46
#define SB_DISKS_OFFSET                 128
 
47
#define SB_DESCRIPTOR_OFFSET            992
 
48
 
 
49
#define SB_GENERIC_CONSTANT_WORDS       32
 
50
#define SB_GENERIC_STATE_WORDS          32
 
51
#define SB_GENERIC_WORDS                (SB_GENERIC_CONSTANT_WORDS + \
 
52
                                         SB_GENERIC_STATE_WORDS)
 
53
 
 
54
#define SB_PERSONALITY_WORDS            64
 
55
#define SB_DESCRIPTOR_WORDS             32
 
56
#define SB_DISKS                        27
 
57
#define SB_DISKS_WORDS                  (SB_DISKS * SB_DESCRIPTOR_WORDS)
 
58
 
 
59
#define SB_RESERVED_WORDS               (1024 \
 
60
                                         - SB_GENERIC_WORDS \
 
61
                                         - SB_PERSONALITY_WORDS \
 
62
                                         - SB_DISKS_WORDS \
 
63
                                         - SB_DESCRIPTOR_WORDS)
 
64
 
 
65
#define SB_EQUAL_WORDS                  (SB_GENERIC_WORDS \
 
66
                                         + SB_PERSONALITY_WORDS \
 
67
                                         + SB_DISKS_WORDS)
 
68
 
 
69
/*
 
70
 * Device "operational" state bits
 
71
 */
 
72
#define DISK_FAULTY                     0
 
73
#define DISK_ACTIVE                     1
 
74
#define DISK_SYNC                       2
 
75
#define DISK_REMOVED                    3
 
76
 
 
77
#define DISK_WRITEMOSTLY                9
 
78
 
 
79
#define SB_MAGIC                        0xa92b4efc
 
80
 
 
81
/*
 
82
 * Superblock state bits
 
83
 */
 
84
#define SB_CLEAN                        0
 
85
#define SB_ERRORS                       1
 
86
 
 
87
#define SB_BITMAP_PRESENT               8
 
88
 
 
89
struct grub_raid_disk_09
 
90
{
 
91
  grub_uint32_t number;         /* Device number in the entire set.  */
 
92
  grub_uint32_t major;          /* Device major number.  */
 
93
  grub_uint32_t minor;          /* Device minor number.  */
 
94
  grub_uint32_t raid_disk;      /* The role of the device in the raid set.  */
 
95
  grub_uint32_t state;          /* Operational state.  */
 
96
  grub_uint32_t reserved[SB_DESCRIPTOR_WORDS - 5];
 
97
};
 
98
 
 
99
struct grub_raid_super_09
 
100
{
 
101
  /*
 
102
   * Constant generic information
 
103
   */
 
104
  grub_uint32_t md_magic;       /* MD identifier.  */
 
105
  grub_uint32_t major_version;  /* Major version.  */
 
106
  grub_uint32_t minor_version;  /* Minor version.  */
 
107
  grub_uint32_t patch_version;  /* Patchlevel version.  */
 
108
  grub_uint32_t gvalid_words;   /* Number of used words in this section.  */
 
109
  grub_uint32_t set_uuid0;      /* Raid set identifier.  */
 
110
  grub_uint32_t ctime;          /* Creation time.  */
 
111
  grub_uint32_t level;          /* Raid personality.  */
 
112
  grub_uint32_t size;           /* Apparent size of each individual disk.  */
 
113
  grub_uint32_t nr_disks;       /* Total disks in the raid set.  */
 
114
  grub_uint32_t raid_disks;     /* Disks in a fully functional raid set.  */
 
115
  grub_uint32_t md_minor;       /* Preferred MD minor device number.  */
 
116
  grub_uint32_t not_persistent; /* Does it have a persistent superblock.  */
 
117
  grub_uint32_t set_uuid1;      /* Raid set identifier #2.  */
 
118
  grub_uint32_t set_uuid2;      /* Raid set identifier #3.  */
 
119
  grub_uint32_t set_uuid3;      /* Raid set identifier #4.  */
 
120
  grub_uint32_t gstate_creserved[SB_GENERIC_CONSTANT_WORDS - 16];
 
121
 
 
122
  /*
 
123
   * Generic state information
 
124
   */
 
125
  grub_uint32_t utime;          /* Superblock update time.  */
 
126
  grub_uint32_t state;          /* State bits (clean, ...).  */
 
127
  grub_uint32_t active_disks;   /* Number of currently active disks.  */
 
128
  grub_uint32_t working_disks;  /* Number of working disks.  */
 
129
  grub_uint32_t failed_disks;   /* Number of failed disks.  */
 
130
  grub_uint32_t spare_disks;    /* Number of spare disks.  */
 
131
  grub_uint32_t sb_csum;        /* Checksum of the whole superblock.  */
 
132
  grub_uint64_t events;         /* Superblock update count.  */
 
133
  grub_uint64_t cp_events;      /* Checkpoint update count.  */
 
134
  grub_uint32_t recovery_cp;    /* Recovery checkpoint sector count.  */
 
135
  grub_uint32_t gstate_sreserved[SB_GENERIC_STATE_WORDS - 12];
 
136
 
 
137
  /*
 
138
   * Personality information
 
139
   */
 
140
  grub_uint32_t layout;         /* The array's physical layout.  */
 
141
  grub_uint32_t chunk_size;     /* Chunk size in bytes.  */
 
142
  grub_uint32_t root_pv;        /* LV root PV.  */
 
143
  grub_uint32_t root_block;     /* LV root block.  */
 
144
  grub_uint32_t pstate_reserved[SB_PERSONALITY_WORDS - 4];
 
145
 
 
146
  /*
 
147
   * Disks information
 
148
   */
 
149
  struct grub_raid_disk_09 disks[SB_DISKS];
 
150
 
 
151
  /*
 
152
   * Reserved
 
153
   */
 
154
  grub_uint32_t reserved[SB_RESERVED_WORDS];
 
155
 
 
156
  /*
 
157
   * Active descriptor
 
158
   */
 
159
  struct grub_raid_disk_09 this_disk;
 
160
} __attribute__ ((packed));
 
161
 
 
162
static grub_err_t
 
163
grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array,
 
164
                    grub_disk_addr_t *start_sector)
 
165
{
 
166
  grub_disk_addr_t sector;
 
167
  grub_uint64_t size;
 
168
  struct grub_raid_super_09 sb;
 
169
  grub_uint32_t *uuid;
 
170
 
 
171
  /* The sector where the mdraid 0.90 superblock is stored, if available.  */
 
172
  size = grub_disk_get_size (disk);
 
173
  if (size == GRUB_DISK_SIZE_UNKNOWN)
 
174
    return grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid");
 
175
  sector = NEW_SIZE_SECTORS (size);
 
176
 
 
177
  if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))
 
178
    return grub_errno;
 
179
 
 
180
  /* Look whether there is a mdraid 0.90 superblock.  */
 
181
  if (sb.md_magic != SB_MAGIC)
 
182
    return grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid");
 
183
 
 
184
  if (sb.major_version != 0 || sb.minor_version != 90)
 
185
    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
 
186
                       "unsupported RAID version: %d.%d",
 
187
                       sb.major_version, sb.minor_version);
 
188
 
 
189
  /* FIXME: Check the checksum.  */
 
190
 
 
191
  /* Multipath.  */
 
192
  if ((int) sb.level == -4)
 
193
    sb.level = 1;
 
194
 
 
195
  if (sb.level != 0 && sb.level != 1 && sb.level != 4 &&
 
196
      sb.level != 5 && sb.level != 6 && sb.level != 10)
 
197
    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
 
198
                       "unsupported RAID level: %d", sb.level);
 
199
  if (sb.this_disk.number == 0xffff || sb.this_disk.number == 0xfffe)
 
200
    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
 
201
                       "spares aren't implemented");
 
202
 
 
203
  array->name = NULL;
 
204
  array->number = sb.md_minor;
 
205
  array->level = sb.level;
 
206
  array->layout = sb.layout;
 
207
  array->total_devs = sb.raid_disks;
 
208
  array->disk_size = (sb.size) ? sb.size * 2 : sector;
 
209
  array->chunk_size = sb.chunk_size >> 9;
 
210
  array->index = sb.this_disk.number;
 
211
  array->uuid_len = 16;
 
212
  array->uuid = grub_malloc (16);
 
213
  if (!array->uuid)
 
214
      return grub_errno;
 
215
 
 
216
  uuid = (grub_uint32_t *) array->uuid;
 
217
  uuid[0] = sb.set_uuid0;
 
218
  uuid[1] = sb.set_uuid1;
 
219
  uuid[2] = sb.set_uuid2;
 
220
  uuid[3] = sb.set_uuid3;
 
221
 
 
222
  *start_sector = 0;
 
223
 
 
224
  return 0;
 
225
}
 
226
 
 
227
static struct grub_raid grub_mdraid_dev = {
 
228
  .name = "mdraid09",
 
229
  .detect = grub_mdraid_detect,
 
230
  .next = 0
 
231
};
 
232
 
 
233
GRUB_MOD_INIT (mdraid09)
 
234
{
 
235
  grub_raid_register (&grub_mdraid_dev);
 
236
}
 
237
 
 
238
GRUB_MOD_FINI (mdraid09)
 
239
{
 
240
  grub_raid_unregister (&grub_mdraid_dev);
 
241
}