/*
* mdadm - Intel(R) Matrix Storage Manager Support
*
- * Copyright (C) 2002-2007 Intel Corporation
+ * Copyright (C) 2002-2008 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#define HAVE_STDINT_H 1
#include "mdadm.h"
#include "mdmon.h"
+#include "sha1.h"
+#include "platform-intel.h"
#include <values.h>
#include <scsi/sg.h>
#include <ctype.h>
+#include <dirent.h>
/* MPB == Metadata Parameter Block */
#define MPB_SIGNATURE "Intel Raid ISM Cfg Sig. "
#define MPB_SIG_LEN (strlen(MPB_SIGNATURE))
#define MPB_VERSION_RAID0 "1.0.00"
#define MPB_VERSION_RAID1 "1.1.00"
+#define MPB_VERSION_MANY_VOLUMES_PER_ARRAY "1.2.00"
+#define MPB_VERSION_3OR4_DISK_ARRAY "1.2.01"
#define MPB_VERSION_RAID5 "1.2.02"
+#define MPB_VERSION_5OR6_DISK_ARRAY "1.2.04"
+#define MPB_VERSION_CNG "1.2.06"
+#define MPB_VERSION_ATTRIBS "1.3.00"
#define MAX_SIGNATURE_LENGTH 32
#define MAX_RAID_SERIAL_LEN 16
+
+#define MPB_ATTRIB_CHECKSUM_VERIFY __cpu_to_le32(0x80000000)
+#define MPB_ATTRIB_PM __cpu_to_le32(0x40000000)
+#define MPB_ATTRIB_2TB __cpu_to_le32(0x20000000)
+#define MPB_ATTRIB_RAID0 __cpu_to_le32(0x00000001)
+#define MPB_ATTRIB_RAID1 __cpu_to_le32(0x00000002)
+#define MPB_ATTRIB_RAID10 __cpu_to_le32(0x00000004)
+#define MPB_ATTRIB_RAID1E __cpu_to_le32(0x00000008)
+#define MPB_ATTRIB_RAID5 __cpu_to_le32(0x00000010)
+#define MPB_ATTRIB_RAIDCNG __cpu_to_le32(0x00000020)
+
#define MPB_SECTOR_CNT 418
#define IMSM_RESERVED_SECTORS 4096
__u8 serial[MAX_RAID_SERIAL_LEN];/* 0xD8 - 0xE7 ascii serial number */
__u32 total_blocks; /* 0xE8 - 0xEB total blocks */
__u32 scsi_id; /* 0xEC - 0xEF scsi ID */
+#define SPARE_DISK __cpu_to_le32(0x01) /* Spare */
+#define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
+#define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
+#define USABLE_DISK __cpu_to_le32(0x08) /* Fully usable unless FAILED_DISK is set */
__u32 status; /* 0xF0 - 0xF3 */
-#define SPARE_DISK 0x01 /* Spare */
-#define CONFIGURED_DISK 0x02 /* Member of some RaidDev */
-#define FAILED_DISK 0x04 /* Permanent failure */
-#define USABLE_DISK 0x08 /* Fully usable unless FAILED_DISK is set */
-
-#define IMSM_DISK_FILLERS 5
+ __u32 owner_cfg_num; /* which config 0,1,2... owns this disk */
+#define IMSM_DISK_FILLERS 4
__u32 filler[IMSM_DISK_FILLERS]; /* 0xF4 - 0x107 MPB_DISK_FILLERS for future expansion */
};
__u8 map_state; /* Normal, Uninitialized, Degraded, Failed */
#define IMSM_T_STATE_NORMAL 0
#define IMSM_T_STATE_UNINITIALIZED 1
-#define IMSM_T_STATE_DEGRADED 2 /* FIXME: is this correct? */
-#define IMSM_T_STATE_FAILED 3 /* FIXME: is this correct? */
+#define IMSM_T_STATE_DEGRADED 2
+#define IMSM_T_STATE_FAILED 3
__u8 raid_level;
#define IMSM_T_RAID0 0
#define IMSM_T_RAID1 1
#define IMSM_T_RAID5 5 /* since metadata version 1.2.02 ? */
__u8 num_members; /* number of member disks */
- __u8 reserved[3];
+ __u8 num_domains; /* number of parity domains */
+ __u8 failed_disk_num; /* valid only when state is degraded */
+ __u8 reserved[1];
__u32 filler[7]; /* expansion area */
#define IMSM_ORD_REBUILD (1 << 24)
__u32 disk_ord_tbl[1]; /* disk_ord_tbl[num_members],
} __attribute__ ((packed));
struct imsm_vol {
- __u32 reserved[2];
+ __u32 curr_migr_unit;
+ __u32 checkpoint_id; /* id to access curr_migr_unit */
__u8 migr_state; /* Normal or Migrating */
+#define MIGR_INIT 0
+#define MIGR_REBUILD 1
+#define MIGR_VERIFY 2 /* analagous to echo check > sync_action */
+#define MIGR_GEN_MIGR 3
+#define MIGR_STATE_CHANGE 4
__u8 migr_type; /* Initializing, Rebuilding, ... */
__u8 dirty;
- __u8 fill[1];
- __u32 filler[5];
+ __u8 fs_state; /* fast-sync state for CnG (0xff == disabled) */
+ __u16 verify_errors; /* number of mismatches */
+ __u16 bad_blocks; /* number of bad blocks during verify */
+ __u32 filler[4];
struct imsm_map map[1];
/* here comes another one if migr_state */
} __attribute__ ((packed));
struct imsm_dev {
- __u8 volume[MAX_RAID_SERIAL_LEN];
+ __u8 volume[MAX_RAID_SERIAL_LEN];
__u32 size_low;
__u32 size_high;
+#define DEV_BOOTABLE __cpu_to_le32(0x01)
+#define DEV_BOOT_DEVICE __cpu_to_le32(0x02)
+#define DEV_READ_COALESCING __cpu_to_le32(0x04)
+#define DEV_WRITE_COALESCING __cpu_to_le32(0x08)
+#define DEV_LAST_SHUTDOWN_DIRTY __cpu_to_le32(0x10)
+#define DEV_HIDDEN_AT_BOOT __cpu_to_le32(0x20)
+#define DEV_CURRENTLY_HIDDEN __cpu_to_le32(0x40)
+#define DEV_VERIFY_AND_FIX __cpu_to_le32(0x80)
+#define DEV_MAP_STATE_UNINIT __cpu_to_le32(0x100)
+#define DEV_NO_AUTO_RECOVERY __cpu_to_le32(0x200)
+#define DEV_CLONE_N_GO __cpu_to_le32(0x400)
+#define DEV_CLONE_MAN_SYNC __cpu_to_le32(0x800)
+#define DEV_CNG_MASTER_DISK_NUM __cpu_to_le32(0x1000)
__u32 status; /* Persistent RaidDev status */
__u32 reserved_blocks; /* Reserved blocks at beginning of volume */
-#define IMSM_DEV_FILLERS 12
+ __u8 migr_priority;
+ __u8 num_sub_vols;
+ __u8 tid;
+ __u8 cng_master_disk;
+ __u16 cache_policy;
+ __u8 cng_state;
+ __u8 cng_sub_state;
+#define IMSM_DEV_FILLERS 10
__u32 filler[IMSM_DEV_FILLERS];
struct imsm_vol vol;
} __attribute__ ((packed));
return sector_count(__le32_to_cpu(mpb->mpb_size));
}
+struct intel_dev {
+ struct imsm_dev *dev;
+ struct intel_dev *next;
+ int index;
+};
+
/* internal representation of IMSM metadata */
struct intel_super {
union {
struct imsm_super *anchor; /* immovable parameters */
};
size_t len; /* size of the 'buf' allocation */
+ void *next_buf; /* for realloc'ing buf from the manager */
+ size_t next_len;
int updates_pending; /* count of pending updates for mdmon */
int creating_imsm; /* flag to indicate container creation */
int current_vol; /* index of raid device undergoing creation */
- #define IMSM_MAX_RAID_DEVS 2
- struct imsm_dev *dev_tbl[IMSM_MAX_RAID_DEVS];
+ __u32 create_offset; /* common start for 'current_vol' */
+ struct intel_dev *devlist;
struct dl {
struct dl *next;
int index;
char *devname;
struct imsm_disk disk;
int fd;
+ int extent_cnt;
+ struct extent *e; /* for determining freespace @ create */
} *disks;
- struct bbm_log *bbm_log;
+ struct dl *add; /* list of disks to add while mdmon active */
+ struct dl *missing; /* disks removed while we weren't looking */
+ struct bbm_log *bbm_log;
+ const char *hba; /* device path of the raid controller for this metadata */
+ const struct imsm_orom *orom; /* platform firmware support */
};
struct extent {
enum imsm_update_type {
update_activate_spare,
update_create_array,
+ update_add_disk,
};
struct imsm_update_activate_spare {
struct imsm_update_activate_spare *next;
};
+struct disk_info {
+ __u8 serial[MAX_RAID_SERIAL_LEN];
+};
+
struct imsm_update_create_array {
enum imsm_update_type type;
int dev_idx;
struct imsm_dev dev;
};
-static int imsm_env_devname_as_serial(void)
-{
- char *val = getenv("IMSM_DEVNAME_AS_SERIAL");
-
- if (val && atoi(val) == 1)
- return 1;
-
- return 0;
-}
-
+struct imsm_update_add_disk {
+ enum imsm_update_type type;
+};
static struct supertype *match_metadata_desc_imsm(char *arg)
{
return st;
}
+#ifndef MDASSEMBLE
static __u8 *get_imsm_version(struct imsm_super *mpb)
{
return &mpb->sig[MPB_SIG_LEN];
}
+#endif
/* retrieve a disk directly from the anchor when the anchor is known to be
* up-to-date, currently only at load time
return &mpb->disk[index];
}
+#ifndef MDASSEMBLE
/* retrieve a disk from the parsed metadata */
static struct imsm_disk *get_imsm_disk(struct intel_super *super, __u8 index)
{
return NULL;
}
+#endif
/* generate a checksum directly from the anchor when the anchor is known to be
* up-to-date, currently only at load or write_super after coalescing
__u32 *p = (__u32 *) mpb;
__u32 sum = 0;
- while (end--)
- sum += __le32_to_cpu(*p++);
+ while (end--) {
+ sum += __le32_to_cpu(*p);
+ p++;
+ }
return sum - __le32_to_cpu(mpb->check_sum);
}
return size;
}
+#ifndef MDASSEMBLE
+/* retrieve disk serial number list from a metadata update */
+static struct disk_info *get_disk_info(struct imsm_update_create_array *update)
+{
+ void *u = update;
+ struct disk_info *inf;
+
+ inf = u + sizeof(*update) - sizeof(struct imsm_dev) +
+ sizeof_imsm_dev(&update->dev, 0);
+
+ return inf;
+}
+#endif
+
static struct imsm_dev *__get_imsm_dev(struct imsm_super *mpb, __u8 index)
{
int offset;
static struct imsm_dev *get_imsm_dev(struct intel_super *super, __u8 index)
{
+ struct intel_dev *dv;
+
if (index >= super->anchor->num_raid_devs)
return NULL;
- return super->dev_tbl[index];
-}
-
-static __u32 get_imsm_disk_idx(struct imsm_map *map, int slot)
-{
- __u32 *ord_tbl = &map->disk_ord_tbl[slot];
-
- /* top byte identifies disk under rebuild
- * why not just use the USABLE bit... oh well.
- */
- return __le32_to_cpu(*ord_tbl & ~(0xff << 24));
+ for (dv = super->devlist; dv; dv = dv->next)
+ if (dv->index == index)
+ return dv->dev;
+ return NULL;
}
static __u32 get_imsm_ord_tbl_ent(struct imsm_dev *dev, int slot)
struct imsm_map *map;
if (dev->vol.migr_state)
- map = get_imsm_map(dev, 0);
- else
map = get_imsm_map(dev, 1);
+ else
+ map = get_imsm_map(dev, 0);
- return map->disk_ord_tbl[slot];
+ /* top byte identifies disk under rebuild */
+ return __le32_to_cpu(map->disk_ord_tbl[slot]);
+}
+
+#define ord_to_idx(ord) (((ord) << 8) >> 8)
+static __u32 get_imsm_disk_idx(struct imsm_dev *dev, int slot)
+{
+ __u32 ord = get_imsm_ord_tbl_ent(dev, slot);
+
+ return ord_to_idx(ord);
+}
+
+static void set_imsm_ord_tbl_ent(struct imsm_map *map, int slot, __u32 ord)
+{
+ map->disk_ord_tbl[slot] = __cpu_to_le32(ord);
}
static int get_imsm_raid_level(struct imsm_map *map)
return 0;
}
-static struct extent *get_extents(struct intel_super *super, struct dl *dl)
+static int count_memberships(struct dl *dl, struct intel_super *super)
{
- /* find a list of used extents on the given physical device */
- struct extent *rv, *e;
- int i, j;
int memberships = 0;
+ int i, j;
for (i = 0; i < super->anchor->num_raid_devs; i++) {
struct imsm_dev *dev = get_imsm_dev(super, i);
struct imsm_map *map = get_imsm_map(dev, 0);
for (j = 0; j < map->num_members; j++) {
- __u32 index = get_imsm_disk_idx(map, j);
+ __u32 index = get_imsm_disk_idx(dev, j);
if (index == dl->index)
memberships++;
}
}
+
+ return memberships;
+}
+
+static struct extent *get_extents(struct intel_super *super, struct dl *dl)
+{
+ /* find a list of used extents on the given physical device */
+ struct extent *rv, *e;
+ int i, j;
+ int memberships = count_memberships(dl, super);
+ __u32 reservation = MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS;
+
rv = malloc(sizeof(struct extent) * (memberships + 1));
if (!rv)
return NULL;
struct imsm_map *map = get_imsm_map(dev, 0);
for (j = 0; j < map->num_members; j++) {
- __u32 index = get_imsm_disk_idx(map, j);
+ __u32 index = get_imsm_disk_idx(dev, j);
if (index == dl->index) {
e->start = __le32_to_cpu(map->pba_of_lba0);
}
qsort(rv, memberships, sizeof(*rv), cmp_extent);
- e->start = __le32_to_cpu(dl->disk.total_blocks) -
- (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS);
+ /* determine the start of the metadata
+ * when no raid devices are defined use the default
+ * ...otherwise allow the metadata to truncate the value
+ * as is the case with older versions of imsm
+ */
+ if (memberships) {
+ struct extent *last = &rv[memberships - 1];
+ __u32 remainder;
+
+ remainder = __le32_to_cpu(dl->disk.total_blocks) -
+ (last->start + last->size);
+ /* round down to 1k block to satisfy precision of the kernel
+ * 'size' interface
+ */
+ remainder &= ~1UL;
+ /* make sure remainder is still sane */
+ if (remainder < ROUND_UP(super->len, 512) >> 9)
+ remainder = ROUND_UP(super->len, 512) >> 9;
+ if (reservation > remainder)
+ reservation = remainder;
+ }
+ e->start = __le32_to_cpu(dl->disk.total_blocks) - reservation;
e->size = 0;
return rv;
}
+/* try to determine how much space is reserved for metadata from
+ * the last get_extents() entry, otherwise fallback to the
+ * default
+ */
+static __u32 imsm_reserved_sectors(struct intel_super *super, struct dl *dl)
+{
+ struct extent *e;
+ int i;
+ __u32 rv;
+
+ /* for spares just return a minimal reservation which will grow
+ * once the spare is picked up by an array
+ */
+ if (dl->index == -1)
+ return MPB_SECTOR_CNT;
+
+ e = get_extents(super, dl);
+ if (!e)
+ return MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS;
+
+ /* scroll to last entry */
+ for (i = 0; e[i].size; i++)
+ continue;
+
+ rv = __le32_to_cpu(dl->disk.total_blocks) - e[i].start;
+
+ free(e);
+
+ return rv;
+}
+
#ifndef MDASSEMBLE
-static void print_imsm_dev(struct imsm_dev *dev, int index)
+static void print_imsm_dev(struct imsm_dev *dev, char *uuid, int disk_idx)
{
__u64 sz;
int slot;
struct imsm_map *map = get_imsm_map(dev, 0);
+ __u32 ord;
printf("\n");
- printf("[%s]:\n", dev->volume);
+ printf("[%.16s]:\n", dev->volume);
+ printf(" UUID : %s\n", uuid);
printf(" RAID Level : %d\n", get_imsm_raid_level(map));
printf(" Members : %d\n", map->num_members);
for (slot = 0; slot < map->num_members; slot++)
- if (index == get_imsm_disk_idx(map, slot))
+ if (disk_idx== get_imsm_disk_idx(dev, slot))
break;
- if (slot < map->num_members)
- printf(" This Slot : %d\n", slot);
- else
+ if (slot < map->num_members) {
+ ord = get_imsm_ord_tbl_ent(dev, slot);
+ printf(" This Slot : %d%s\n", slot,
+ ord & IMSM_ORD_REBUILD ? " (out-of-sync)" : "");
+ } else
printf(" This Slot : ?\n");
sz = __le32_to_cpu(dev->size_high);
sz <<= 32;
printf(" Map State : %s", map_state_str[map->map_state]);
if (dev->vol.migr_state) {
struct imsm_map *map = get_imsm_map(dev, 1);
- printf(", %s", map_state_str[map->map_state]);
+ printf(" <-- %s", map_state_str[map->map_state]);
}
printf("\n");
printf(" Dirty State : %s\n", dev->vol.dirty ? "dirty" : "clean");
}
-static void print_imsm_disk(struct imsm_super *mpb, int index)
+static void print_imsm_disk(struct imsm_super *mpb, int index, __u32 reserved)
{
struct imsm_disk *disk = __get_imsm_disk(mpb, index);
- char str[MAX_RAID_SERIAL_LEN];
+ char str[MAX_RAID_SERIAL_LEN + 1];
__u32 s;
__u64 sz;
return;
printf("\n");
- snprintf(str, MAX_RAID_SERIAL_LEN, "%s", disk->serial);
+ snprintf(str, MAX_RAID_SERIAL_LEN + 1, "%s", disk->serial);
printf(" Disk%02d Serial : %s\n", index, str);
- s = __le32_to_cpu(disk->status);
+ s = disk->status;
printf(" State :%s%s%s%s\n", s&SPARE_DISK ? " spare" : "",
s&CONFIGURED_DISK ? " active" : "",
s&FAILED_DISK ? " failed" : "",
s&USABLE_DISK ? " usable" : "");
printf(" Id : %08x\n", __le32_to_cpu(disk->scsi_id));
- sz = __le32_to_cpu(disk->total_blocks) -
- (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS * mpb->num_raid_devs);
+ sz = __le32_to_cpu(disk->total_blocks) - reserved;
printf(" Usable Size : %llu%s\n", (unsigned long long)sz,
human_size(sz * 512));
}
+static void getinfo_super_imsm(struct supertype *st, struct mdinfo *info);
+
static void examine_super_imsm(struct supertype *st, char *homehost)
{
struct intel_super *super = st->sb;
struct imsm_super *mpb = super->anchor;
char str[MAX_SIGNATURE_LENGTH];
int i;
+ struct mdinfo info;
+ char nbuf[64];
__u32 sum;
+ __u32 reserved = imsm_reserved_sectors(super, super->disks);
+
snprintf(str, MPB_SIG_LEN, "%s", mpb->sig);
printf(" Magic : %s\n", str);
printf(" Version : %s\n", get_imsm_version(mpb));
printf(" Family : %08x\n", __le32_to_cpu(mpb->family_num));
printf(" Generation : %08x\n", __le32_to_cpu(mpb->generation_num));
+ getinfo_super_imsm(st, &info);
+ fname_from_uuid(st, &info, nbuf,'-');
+ printf(" UUID : %s\n", nbuf + 5);
sum = __le32_to_cpu(mpb->check_sum);
printf(" Checksum : %08x %s\n", sum,
__gen_imsm_checksum(mpb) == sum ? "correct" : "incorrect");
printf(" MPB Sectors : %d\n", mpb_sectors(mpb));
printf(" Disks : %d\n", mpb->num_disks);
printf(" RAID Devices : %d\n", mpb->num_raid_devs);
- print_imsm_disk(mpb, super->disks->index);
+ print_imsm_disk(mpb, super->disks->index, reserved);
if (super->bbm_log) {
struct bbm_log *log = super->bbm_log;
printf(" Spare Blocks : %d\n", __le32_to_cpu(log->reserved_spare_block_count));
printf(" First Spare : %llx\n", __le64_to_cpu(log->first_spare_lba));
}
- for (i = 0; i < mpb->num_raid_devs; i++)
- print_imsm_dev(__get_imsm_dev(mpb, i), super->disks->index);
+ for (i = 0; i < mpb->num_raid_devs; i++) {
+ struct mdinfo info;
+ struct imsm_dev *dev = __get_imsm_dev(mpb, i);
+
+ super->current_vol = i;
+ getinfo_super_imsm(st, &info);
+ fname_from_uuid(st, &info, nbuf, '-');
+ print_imsm_dev(dev, nbuf + 5, super->disks->index);
+ }
for (i = 0; i < mpb->num_disks; i++) {
if (i == super->disks->index)
continue;
- print_imsm_disk(mpb, i);
+ print_imsm_disk(mpb, i, reserved);
}
}
static void brief_examine_super_imsm(struct supertype *st)
{
- printf("ARRAY /dev/imsm metadata=imsm\n");
+ /* We just write a generic IMSM ARRAY entry */
+ struct mdinfo info;
+ char nbuf[64];
+ char nbuf1[64];
+ struct intel_super *super = st->sb;
+ int i;
+
+ if (!super->anchor->num_raid_devs)
+ return;
+
+ getinfo_super_imsm(st, &info);
+ fname_from_uuid(st, &info, nbuf,'-');
+ printf("ARRAY metadata=imsm auto=md UUID=%s\n", nbuf + 5);
+ for (i = 0; i < super->anchor->num_raid_devs; i++) {
+ struct imsm_dev *dev = get_imsm_dev(super, i);
+
+ super->current_vol = i;
+ getinfo_super_imsm(st, &info);
+ fname_from_uuid(st, &info, nbuf1,'-');
+ printf("ARRAY /dev/md/%.16s container=%s\n"
+ " member=%d auto=mdp UUID=%s\n",
+ dev->volume, nbuf + 5, i, nbuf1 + 5);
+ }
}
static void detail_super_imsm(struct supertype *st, char *homehost)
{
- printf("%s\n", __FUNCTION__);
+ struct mdinfo info;
+ char nbuf[64];
+
+ getinfo_super_imsm(st, &info);
+ fname_from_uuid(st, &info, nbuf,'-');
+ printf("\n UUID : %s\n", nbuf + 5);
}
static void brief_detail_super_imsm(struct supertype *st)
{
- printf("%s\n", __FUNCTION__);
+ struct mdinfo info;
+ char nbuf[64];
+ getinfo_super_imsm(st, &info);
+ fname_from_uuid(st, &info, nbuf,'-');
+ printf(" UUID=%s", nbuf + 5);
+}
+
+static int imsm_read_serial(int fd, char *devname, __u8 *serial);
+static void fd2devname(int fd, char *name);
+
+static int imsm_enumerate_ports(const char *hba_path, int port_count, int host_base, int verbose)
+{
+ /* dump an unsorted list of devices attached to ahci, as well as
+ * non-connected ports
+ */
+ int hba_len = strlen(hba_path) + 1;
+ struct dirent *ent;
+ DIR *dir;
+ char *path = NULL;
+ int err = 0;
+ unsigned long port_mask = (1 << port_count) - 1;
+
+ if (port_count > sizeof(port_mask) * 8) {
+ if (verbose)
+ fprintf(stderr, Name ": port_count %d out of range\n", port_count);
+ return 2;
+ }
+
+ /* scroll through /sys/dev/block looking for devices attached to
+ * this hba
+ */
+ dir = opendir("/sys/dev/block");
+ for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) {
+ int fd;
+ char model[64];
+ char vendor[64];
+ char buf[1024];
+ int major, minor;
+ char *device;
+ char *c;
+ int port;
+ int type;
+
+ if (sscanf(ent->d_name, "%d:%d", &major, &minor) != 2)
+ continue;
+ path = devt_to_devpath(makedev(major, minor));
+ if (!path)
+ continue;
+ if (!path_attached_to_hba(path, hba_path)) {
+ free(path);
+ path = NULL;
+ continue;
+ }
+
+ /* retrieve the scsi device type */
+ if (asprintf(&device, "/sys/dev/block/%d:%d/device/xxxxxxx", major, minor) < 0) {
+ if (verbose)
+ fprintf(stderr, Name ": failed to allocate 'device'\n");
+ err = 2;
+ break;
+ }
+ sprintf(device, "/sys/dev/block/%d:%d/device/type", major, minor);
+ if (load_sys(device, buf) != 0) {
+ if (verbose)
+ fprintf(stderr, Name ": failed to read device type for %s\n",
+ path);
+ err = 2;
+ free(device);
+ break;
+ }
+ type = strtoul(buf, NULL, 10);
+
+ /* if it's not a disk print the vendor and model */
+ if (!(type == 0 || type == 7 || type == 14)) {
+ vendor[0] = '\0';
+ model[0] = '\0';
+ sprintf(device, "/sys/dev/block/%d:%d/device/vendor", major, minor);
+ if (load_sys(device, buf) == 0) {
+ strncpy(vendor, buf, sizeof(vendor));
+ vendor[sizeof(vendor) - 1] = '\0';
+ c = (char *) &vendor[sizeof(vendor) - 1];
+ while (isspace(*c) || *c == '\0')
+ *c-- = '\0';
+
+ }
+ sprintf(device, "/sys/dev/block/%d:%d/device/model", major, minor);
+ if (load_sys(device, buf) == 0) {
+ strncpy(model, buf, sizeof(model));
+ model[sizeof(model) - 1] = '\0';
+ c = (char *) &model[sizeof(model) - 1];
+ while (isspace(*c) || *c == '\0')
+ *c-- = '\0';
+ }
+
+ if (vendor[0] && model[0])
+ sprintf(buf, "%.64s %.64s", vendor, model);
+ else
+ switch (type) { /* numbers from hald/linux/device.c */
+ case 1: sprintf(buf, "tape"); break;
+ case 2: sprintf(buf, "printer"); break;
+ case 3: sprintf(buf, "processor"); break;
+ case 4:
+ case 5: sprintf(buf, "cdrom"); break;
+ case 6: sprintf(buf, "scanner"); break;
+ case 8: sprintf(buf, "media_changer"); break;
+ case 9: sprintf(buf, "comm"); break;
+ case 12: sprintf(buf, "raid"); break;
+ default: sprintf(buf, "unknown");
+ }
+ } else
+ buf[0] = '\0';
+ free(device);
+
+ /* chop device path to 'host%d' and calculate the port number */
+ c = strchr(&path[hba_len], '/');
+ *c = '\0';
+ if (sscanf(&path[hba_len], "host%d", &port) == 1)
+ port -= host_base;
+ else {
+ if (verbose) {
+ *c = '/'; /* repair the full string */
+ fprintf(stderr, Name ": failed to determine port number for %s\n",
+ path);
+ }
+ err = 2;
+ break;
+ }
+
+ /* mark this port as used */
+ port_mask &= ~(1 << port);
+
+ /* print out the device information */
+ if (buf[0]) {
+ printf(" Port%d : - non-disk device (%s) -\n", port, buf);
+ continue;
+ }
+
+ fd = dev_open(ent->d_name, O_RDONLY);
+ if (fd < 0)
+ printf(" Port%d : - disk info unavailable -\n", port);
+ else {
+ fd2devname(fd, buf);
+ printf(" Port%d : %s", port, buf);
+ if (imsm_read_serial(fd, NULL, (__u8 *) buf) == 0)
+ printf(" (%s)\n", buf);
+ else
+ printf("()\n");
+ }
+ close(fd);
+ free(path);
+ path = NULL;
+ }
+ if (path)
+ free(path);
+ if (dir)
+ closedir(dir);
+ if (err == 0) {
+ int i;
+
+ for (i = 0; i < port_count; i++)
+ if (port_mask & (1 << i))
+ printf(" Port%d : - no device attached -\n", i);
+ }
+
+ return err;
+}
+
+static int detail_platform_imsm(int verbose)
+{
+ /* There are two components to imsm platform support, the ahci SATA
+ * controller and the option-rom. To find the SATA controller we
+ * simply look in /sys/bus/pci/drivers/ahci to see if an ahci
+ * controller with the Intel vendor id is present. This approach
+ * allows mdadm to leverage the kernel's ahci detection logic, with the
+ * caveat that if ahci.ko is not loaded mdadm will not be able to
+ * detect platform raid capabilities. The option-rom resides in a
+ * platform "Adapter ROM". We scan for its signature to retrieve the
+ * platform capabilities. If raid support is disabled in the BIOS the
+ * option-rom capability structure will not be available.
+ */
+ const struct imsm_orom *orom;
+ struct sys_dev *list, *hba;
+ DIR *dir;
+ struct dirent *ent;
+ const char *hba_path;
+ int host_base = 0;
+ int port_count = 0;
+
+ list = find_driver_devices("pci", "ahci");
+ for (hba = list; hba; hba = hba->next)
+ if (devpath_to_vendor(hba->path) == 0x8086)
+ break;
+
+ if (!hba) {
+ if (verbose)
+ fprintf(stderr, Name ": unable to find active ahci controller\n");
+ free_sys_dev(&list);
+ return 2;
+ } else if (verbose)
+ fprintf(stderr, Name ": found Intel SATA AHCI Controller\n");
+ hba_path = hba->path;
+ hba->path = NULL;
+ free_sys_dev(&list);
+
+ orom = find_imsm_orom();
+ if (!orom) {
+ if (verbose)
+ fprintf(stderr, Name ": imsm option-rom not found\n");
+ return 2;
+ }
+
+ printf(" Platform : Intel(R) Matrix Storage Manager\n");
+ printf(" Version : %d.%d.%d.%d\n", orom->major_ver, orom->minor_ver,
+ orom->hotfix_ver, orom->build);
+ printf(" RAID Levels :%s%s%s%s%s\n",
+ imsm_orom_has_raid0(orom) ? " raid0" : "",
+ imsm_orom_has_raid1(orom) ? " raid1" : "",
+ imsm_orom_has_raid1e(orom) ? " raid1e" : "",
+ imsm_orom_has_raid10(orom) ? " raid10" : "",
+ imsm_orom_has_raid5(orom) ? " raid5" : "");
+ printf(" Max Disks : %d\n", orom->tds);
+ printf(" Max Volumes : %d\n", orom->vpa);
+ printf(" I/O Controller : %s\n", hba_path);
+
+ /* find the smallest scsi host number to determine a port number base */
+ dir = opendir(hba_path);
+ for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) {
+ int host;
+
+ if (sscanf(ent->d_name, "host%d", &host) != 1)
+ continue;
+ if (port_count == 0)
+ host_base = host;
+ else if (host < host_base)
+ host_base = host;
+
+ if (host + 1 > port_count + host_base)
+ port_count = host + 1 - host_base;
+
+ }
+ if (dir)
+ closedir(dir);
+
+ if (!port_count || imsm_enumerate_ports(hba_path, port_count,
+ host_base, verbose) != 0) {
+ if (verbose)
+ fprintf(stderr, Name ": failed to enumerate ports\n");
+ return 2;
+ }
+
+ return 0;
}
#endif
static int match_home_imsm(struct supertype *st, char *homehost)
{
- printf("%s\n", __FUNCTION__);
+ /* the imsm metadata format does not specify any host
+ * identification information. We return -1 since we can never
+ * confirm nor deny whether a given array is "meant" for this
+ * host. We rely on compare_super and the 'family_num' field to
+ * exclude member disks that do not belong, and we rely on
+ * mdadm.conf to specify the arrays that should be assembled.
+ * Auto-assembly may still pick up "foreign" arrays.
+ */
- return 0;
+ return -1;
}
static void uuid_from_super_imsm(struct supertype *st, int uuid[4])
{
- printf("%s\n", __FUNCTION__);
+ /* The uuid returned here is used for:
+ * uuid to put into bitmap file (Create, Grow)
+ * uuid for backup header when saving critical section (Grow)
+ * comparing uuids when re-adding a device into an array
+ * In these cases the uuid required is that of the data-array,
+ * not the device-set.
+ * uuid to recognise same set when adding a missing device back
+ * to an array. This is a uuid for the device-set.
+ *
+ * For each of these we can make do with a truncated
+ * or hashed uuid rather than the original, as long as
+ * everyone agrees.
+ * In each case the uuid required is that of the data-array,
+ * not the device-set.
+ */
+ /* imsm does not track uuid's so we synthesis one using sha1 on
+ * - The signature (Which is constant for all imsm array, but no matter)
+ * - the family_num of the container
+ * - the index number of the volume
+ * - the 'serial' number of the volume.
+ * Hopefully these are all constant.
+ */
+ struct intel_super *super = st->sb;
+
+ char buf[20];
+ struct sha1_ctx ctx;
+ struct imsm_dev *dev = NULL;
+
+ sha1_init_ctx(&ctx);
+ sha1_process_bytes(super->anchor->sig, MPB_SIG_LEN, &ctx);
+ sha1_process_bytes(&super->anchor->family_num, sizeof(__u32), &ctx);
+ if (super->current_vol >= 0)
+ dev = get_imsm_dev(super, super->current_vol);
+ if (dev) {
+ __u32 vol = super->current_vol;
+ sha1_process_bytes(&vol, sizeof(vol), &ctx);
+ sha1_process_bytes(dev->volume, MAX_RAID_SERIAL_LEN, &ctx);
+ }
+ sha1_finish_ctx(&ctx, buf);
+ memcpy(uuid, buf, 4*4);
}
#if 0
case 6:
return ALGORITHM_LEFT_ASYMMETRIC;
case 10:
- return 0x102; //FIXME is this correct?
+ return 0x102;
}
return -1;
}
info->array.md_minor = -1;
info->array.ctime = 0;
info->array.utime = 0;
- info->array.chunk_size = __le16_to_cpu(map->blocks_per_strip * 512);
+ info->array.chunk_size = __le16_to_cpu(map->blocks_per_strip) << 9;
+ info->array.state = !dev->vol.dirty;
+
+ info->disk.major = 0;
+ info->disk.minor = 0;
info->data_offset = __le32_to_cpu(map->pba_of_lba0);
info->component_size = __le32_to_cpu(map->blocks_per_member);
+ memset(info->uuid, 0, sizeof(info->uuid));
- info->disk.major = 0;
- info->disk.minor = 0;
+ if (map->map_state == IMSM_T_STATE_UNINITIALIZED || dev->vol.dirty)
+ info->resync_start = 0;
+ else if (dev->vol.migr_state)
+ info->resync_start = __le32_to_cpu(dev->vol.curr_migr_unit);
+ else
+ info->resync_start = ~0ULL;
+ strncpy(info->name, (char *) dev->volume, MAX_RAID_SERIAL_LEN);
+ info->name[MAX_RAID_SERIAL_LEN] = 0;
+
+ info->array.major_version = -1;
+ info->array.minor_version = -2;
sprintf(info->text_version, "/%s/%d",
devnum2devname(st->container_dev),
info->container_member);
+ info->safe_mode_delay = 4000; /* 4 secs like the Matrix driver */
+ uuid_from_super_imsm(st, info->uuid);
}
info->disk.minor = 0;
info->disk.raid_disk = -1;
info->reshape_active = 0;
+ info->array.major_version = -1;
+ info->array.minor_version = -2;
strcpy(info->text_version, "imsm");
+ info->safe_mode_delay = 0;
info->disk.number = -1;
info->disk.state = 0;
+ info->name[0] = 0;
if (super->disks) {
+ __u32 reserved = imsm_reserved_sectors(super, super->disks);
+
disk = &super->disks->disk;
- info->disk.number = super->disks->index;
- info->disk.raid_disk = super->disks->index;
- info->data_offset = __le32_to_cpu(disk->total_blocks) -
- (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS);
- info->component_size = MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS;
- s = __le32_to_cpu(disk->status);
+ info->data_offset = __le32_to_cpu(disk->total_blocks) - reserved;
+ info->component_size = reserved;
+ s = disk->status;
info->disk.state = s & CONFIGURED_DISK ? (1 << MD_DISK_ACTIVE) : 0;
info->disk.state |= s & FAILED_DISK ? (1 << MD_DISK_FAULTY) : 0;
- info->disk.state |= s & USABLE_DISK ? (1 << MD_DISK_SYNC) : 0;
+ info->disk.state |= s & SPARE_DISK ? 0 : (1 << MD_DISK_SYNC);
}
+
+ /* only call uuid_from_super_imsm when this disk is part of a populated container,
+ * ->compare_super may have updated the 'num_raid_devs' field for spares
+ */
+ if (info->disk.state & (1 << MD_DISK_SYNC) || super->anchor->num_raid_devs)
+ uuid_from_super_imsm(st, info->uuid);
+ else
+ memcpy(info->uuid, uuid_match_any, sizeof(int[4]));
}
static int update_super_imsm(struct supertype *st, struct mdinfo *info,
return devsize - (MPB_SECTOR_CNT + IMSM_RESERVED_SECTORS);
}
+static void free_devlist(struct intel_super *super)
+{
+ struct intel_dev *dv;
+
+ while (super->devlist) {
+ dv = super->devlist->next;
+ free(super->devlist->dev);
+ free(super->devlist);
+ super->devlist = dv;
+ }
+}
+
+static void imsm_copy_dev(struct imsm_dev *dest, struct imsm_dev *src)
+{
+ memcpy(dest, src, sizeof_imsm_dev(src, 0));
+}
+
static int compare_super_imsm(struct supertype *st, struct supertype *tst)
{
/*
sec->anchor->num_raid_devs > 0) {
if (first->anchor->family_num != sec->anchor->family_num)
return 3;
- if (first->anchor->mpb_size != sec->anchor->mpb_size)
- return 3;
- if (first->anchor->check_sum != sec->anchor->check_sum)
+ }
+
+ /* if 'first' is a spare promote it to a populated mpb with sec's
+ * family number
+ */
+ if (first->anchor->num_raid_devs == 0 &&
+ sec->anchor->num_raid_devs > 0) {
+ int i;
+ struct intel_dev *dv;
+ struct imsm_dev *dev;
+
+ /* we need to copy raid device info from sec if an allocation
+ * fails here we don't associate the spare
+ */
+ for (i = 0; i < sec->anchor->num_raid_devs; i++) {
+ dv = malloc(sizeof(*dv));
+ if (!dv)
+ break;
+ dev = malloc(sizeof_imsm_dev(get_imsm_dev(sec, i), 1));
+ if (!dev) {
+ free(dv);
+ break;
+ }
+ dv->dev = dev;
+ dv->index = i;
+ dv->next = first->devlist;
+ first->devlist = dv;
+ }
+ if (i <= sec->anchor->num_raid_devs) {
+ /* allocation failure */
+ free_devlist(first);
+ fprintf(stderr, "imsm: failed to associate spare\n");
return 3;
+ }
+ for (i = 0; i < sec->anchor->num_raid_devs; i++)
+ imsm_copy_dev(get_imsm_dev(first, i), get_imsm_dev(sec, i));
+
+ first->anchor->num_raid_devs = sec->anchor->num_raid_devs;
+ first->anchor->family_num = sec->anchor->family_num;
}
return 0;
unsigned char scsi_serial[255];
int rv;
int rsp_len;
- int i, cnt;
+ int len;
+ char *c, *rsp_buf;
memset(scsi_serial, 0, sizeof(scsi_serial));
- if (imsm_env_devname_as_serial()) {
- char name[MAX_RAID_SERIAL_LEN];
-
- fd2devname(fd, name);
- strcpy((char *) serial, name);
+ rv = scsi_get_serial(fd, scsi_serial, sizeof(scsi_serial));
+
+ if (rv && check_env("IMSM_DEVNAME_AS_SERIAL")) {
+ memset(serial, 0, MAX_RAID_SERIAL_LEN);
+ fd2devname(fd, (char *) serial);
return 0;
}
- rv = scsi_get_serial(fd, scsi_serial, sizeof(scsi_serial));
-
if (rv != 0) {
if (devname)
fprintf(stderr,
return rv;
}
+ /* trim leading whitespace */
rsp_len = scsi_serial[3];
- for (i = 0, cnt = 0; i < rsp_len; i++) {
- if (!isspace(scsi_serial[4 + i]))
- serial[cnt++] = scsi_serial[4 + i];
- if (cnt == MAX_RAID_SERIAL_LEN)
- break;
- }
+ rsp_buf = (char *) &scsi_serial[4];
+ c = rsp_buf;
+ while (isspace(*c))
+ c++;
+
+ /* truncate len to the end of rsp_buf if necessary */
+ if (c + MAX_RAID_SERIAL_LEN > rsp_buf + rsp_len)
+ len = rsp_len - (c - rsp_buf);
+ else
+ len = MAX_RAID_SERIAL_LEN;
+
+ /* initialize the buffer and copy rsp_buf characters */
+ memset(serial, 0, MAX_RAID_SERIAL_LEN);
+ memcpy(serial, c, len);
- serial[MAX_RAID_SERIAL_LEN - 1] = '\0';
+ /* trim trailing whitespace starting with the last character copied */
+ c = (char *) &serial[len - 1];
+ while (isspace(*c) || *c == '\0')
+ *c-- = '\0';
return 0;
}
+static int serialcmp(__u8 *s1, __u8 *s2)
+{
+ return strncmp((char *) s1, (char *) s2, MAX_RAID_SERIAL_LEN);
+}
+
+static void serialcpy(__u8 *dest, __u8 *src)
+{
+ strncpy((char *) dest, (char *) src, MAX_RAID_SERIAL_LEN);
+}
+
+static struct dl *serial_to_dl(__u8 *serial, struct intel_super *super)
+{
+ struct dl *dl;
+
+ for (dl = super->disks; dl; dl = dl->next)
+ if (serialcmp(dl->serial, serial) == 0)
+ break;
+
+ return dl;
+}
+
static int
load_imsm_disk(int fd, struct intel_super *super, char *devname, int keep_fd)
{
* super->disks while the current anchor believes it is a raid member,
* check if we need to update dl->index
*/
- for (dl = super->disks; dl; dl = dl->next)
- if (memcmp(dl->serial, serial, MAX_RAID_SERIAL_LEN) == 0)
- break;
-
+ dl = serial_to_dl(serial, super);
if (!dl)
dl = malloc(sizeof(*dl));
else
dl->next = super->disks;
dl->fd = keep_fd ? fd : -1;
dl->devname = devname ? strdup(devname) : NULL;
- strncpy((char *) dl->serial, (char *) serial, MAX_RAID_SERIAL_LEN);
+ serialcpy(dl->serial, serial);
+ dl->index = -2;
+ dl->e = NULL;
} else if (keep_fd) {
close(dl->fd);
dl->fd = fd;
disk_iter = __get_imsm_disk(super->anchor, i);
- if (memcmp(disk_iter->serial, dl->serial,
- MAX_RAID_SERIAL_LEN) == 0) {
- __u32 status;
-
+ if (serialcmp(disk_iter->serial, dl->serial) == 0) {
dl->disk = *disk_iter;
- status = __le32_to_cpu(dl->disk.status);
/* only set index on disks that are a member of a
* populated contianer, i.e. one with raid_devs
*/
- if (status & SPARE_DISK)
+ if (dl->disk.status & FAILED_DISK)
+ dl->index = -2;
+ else if (dl->disk.status & SPARE_DISK)
dl->index = -1;
else
dl->index = i;
+
break;
}
}
- if (i == super->anchor->num_disks && alloc) {
- if (devname)
- fprintf(stderr,
- Name ": failed to load disk with serial \'%s\' for %s\n",
- dl->serial, devname);
- free(dl);
- return 1;
- }
+ /* no match, maybe a stale failed drive */
if (i == super->anchor->num_disks && dl->index >= 0) {
- if (devname)
- fprintf(stderr,
- Name ": confused... disk %d with serial \'%s\' "
- "is not listed in the current anchor\n",
- dl->index, dl->serial);
- return 1;
+ dl->disk = *__get_imsm_disk(super->anchor, dl->index);
+ if (dl->disk.status & FAILED_DISK)
+ dl->index = -2;
}
if (alloc)
super->disks = dl;
-
+
return 0;
}
-static void imsm_copy_dev(struct imsm_dev *dest, struct imsm_dev *src)
+#ifndef MDASSEMBLE
+/* When migrating map0 contains the 'destination' state while map1
+ * contains the current state. When not migrating map0 contains the
+ * current state. This routine assumes that map[0].map_state is set to
+ * the current array state before being called.
+ *
+ * Migration is indicated by one of the following states
+ * 1/ Idle (migr_state=0 map0state=normal||unitialized||degraded||failed)
+ * 2/ Initialize (migr_state=1 migr_type=MIGR_INIT map0state=normal
+ * map1state=unitialized)
+ * 3/ Verify (Resync) (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
+ * map1state=normal)
+ * 4/ Rebuild (migr_state=1 migr_type=MIGR_REBUILD map0state=normal
+ * map1state=degraded)
+ */
+static void migrate(struct imsm_dev *dev, __u8 to_state, int rebuild_resync)
{
- memcpy(dest, src, sizeof_imsm_dev(src, 0));
+ struct imsm_map *dest;
+ struct imsm_map *src = get_imsm_map(dev, 0);
+
+ dev->vol.migr_state = 1;
+ dev->vol.migr_type = rebuild_resync;
+ dev->vol.curr_migr_unit = 0;
+ dest = get_imsm_map(dev, 1);
+
+ memcpy(dest, src, sizeof_imsm_map(src));
+ src->map_state = to_state;
}
-static void dup_map(struct imsm_dev *dev)
+static void end_migration(struct imsm_dev *dev, __u8 map_state)
{
- struct imsm_map *dest = get_imsm_map(dev, 1);
- struct imsm_map *src = get_imsm_map(dev, 0);
+ struct imsm_map *map = get_imsm_map(dev, 0);
- memcpy(dest, src, sizeof_imsm_map(src));
+ dev->vol.migr_state = 0;
+ dev->vol.curr_migr_unit = 0;
+ map->map_state = map_state;
}
+#endif
static int parse_raid_devices(struct intel_super *super)
{
int i;
struct imsm_dev *dev_new;
- size_t len;
+ size_t len, len_migr;
+ size_t space_needed = 0;
+ struct imsm_super *mpb = super->anchor;
for (i = 0; i < super->anchor->num_raid_devs; i++) {
struct imsm_dev *dev_iter = __get_imsm_dev(super->anchor, i);
+ struct intel_dev *dv;
- len = sizeof_imsm_dev(dev_iter, 1);
- dev_new = malloc(len);
- if (!dev_new)
+ len = sizeof_imsm_dev(dev_iter, 0);
+ len_migr = sizeof_imsm_dev(dev_iter, 1);
+ if (len_migr > len)
+ space_needed += len_migr - len;
+
+ dv = malloc(sizeof(*dv));
+ if (!dv)
return 1;
+ dev_new = malloc(len_migr);
+ if (!dev_new) {
+ free(dv);
+ return 1;
+ }
imsm_copy_dev(dev_new, dev_iter);
- super->dev_tbl[i] = dev_new;
+ dv->dev = dev_new;
+ dv->index = i;
+ dv->next = super->devlist;
+ super->devlist = dv;
}
+ /* ensure that super->buf is large enough when all raid devices
+ * are migrating
+ */
+ if (__le32_to_cpu(mpb->mpb_size) + space_needed > super->len) {
+ void *buf;
+
+ len = ROUND_UP(__le32_to_cpu(mpb->mpb_size) + space_needed, 512);
+ if (posix_memalign(&buf, 512, len) != 0)
+ return 1;
+
+ memcpy(buf, super->buf, len);
+ free(super->buf);
+ super->buf = buf;
+ super->len = len;
+ }
+
return 0;
}
}
__free_imsm(super, 0);
- super->len = __le32_to_cpu(anchor->mpb_size);
super->len = ROUND_UP(anchor->mpb_size, 512);
if (posix_memalign(&super->buf, 512, super->len) != 0) {
if (devname)
rc = load_imsm_disk(fd, super, devname, 0);
if (rc == 0)
rc = parse_raid_devices(super);
+
return rc;
}
+static void __free_imsm_disk(struct dl *d)
+{
+ if (d->fd >= 0)
+ close(d->fd);
+ if (d->devname)
+ free(d->devname);
+ if (d->e)
+ free(d->e);
+ free(d);
+
+}
static void free_imsm_disks(struct intel_super *super)
{
- while (super->disks) {
- struct dl *d = super->disks;
+ struct dl *d;
+ while (super->disks) {
+ d = super->disks;
super->disks = d->next;
- if (d->fd >= 0)
- close(d->fd);
- if (d->devname)
- free(d->devname);
- free(d);
+ __free_imsm_disk(d);
+ }
+ while (super->missing) {
+ d = super->missing;
+ super->missing = d->next;
+ __free_imsm_disk(d);
}
+
}
/* free all the pieces hanging off of a super pointer */
static void __free_imsm(struct intel_super *super, int free_disks)
{
- int i;
-
if (super->buf) {
free(super->buf);
super->buf = NULL;
}
if (free_disks)
free_imsm_disks(super);
- for (i = 0; i < IMSM_MAX_RAID_DEVS; i++)
- if (super->dev_tbl[i]) {
- free(super->dev_tbl[i]);
- super->dev_tbl[i] = NULL;
- }
+ free_devlist(super);
+ if (super->hba) {
+ free((void *) super->hba);
+ super->hba = NULL;
+ }
}
static void free_imsm(struct intel_super *super)
memset(super, 0, sizeof(*super));
super->creating_imsm = creating_imsm;
super->current_vol = -1;
+ super->create_offset = ~((__u32 ) 0);
+ if (!check_env("IMSM_NO_PLATFORM"))
+ super->orom = find_imsm_orom();
+ if (super->orom) {
+ struct sys_dev *list, *ent;
+
+ /* find the first intel ahci controller */
+ list = find_driver_devices("pci", "ahci");
+ for (ent = list; ent; ent = ent->next)
+ if (devpath_to_vendor(ent->path) == 0x8086)
+ break;
+ if (ent) {
+ super->hba = ent->path;
+ ent->path = NULL;
+ }
+ free_sys_dev(&list);
+ }
}
return super;
}
#ifndef MDASSEMBLE
+/* find_missing - helper routine for load_super_imsm_all that identifies
+ * disks that have disappeared from the system. This routine relies on
+ * the mpb being uptodate, which it is at load time.
+ */
+static int find_missing(struct intel_super *super)
+{
+ int i;
+ struct imsm_super *mpb = super->anchor;
+ struct dl *dl;
+ struct imsm_disk *disk;
+
+ for (i = 0; i < mpb->num_disks; i++) {
+ disk = __get_imsm_disk(mpb, i);
+ dl = serial_to_dl(disk->serial, super);
+ if (dl)
+ continue;
+ /* ok we have a 'disk' without a live entry in
+ * super->disks
+ */
+ if (disk->status & FAILED_DISK || !(disk->status & USABLE_DISK))
+ continue; /* never mind, already marked */
+
+ dl = malloc(sizeof(*dl));
+ if (!dl)
+ return 1;
+ dl->major = 0;
+ dl->minor = 0;
+ dl->fd = -1;
+ dl->devname = strdup("missing");
+ dl->index = i;
+ serialcpy(dl->serial, disk->serial);
+ dl->disk = *disk;
+ dl->next = super->missing;
+ super->missing = dl;
+ }
+
+ return 0;
+}
+
static int load_super_imsm_all(struct supertype *st, int fd, void **sbp,
char *devname, int keep_fd)
{
close(dfd);
}
+
+ if (find_missing(super) != 0) {
+ free_imsm(super);
+ return 2;
+ }
+
if (st->subarray[0]) {
if (atoi(st->subarray) <= super->anchor->num_raid_devs)
super->current_vol = atoi(st->subarray);
}
*sbp = super;
+ st->container_dev = fd2devnum(fd);
if (st->ss == NULL) {
st->ss = &super_imsm;
st->minor_version = 0;
st->max_devs = IMSM_MAX_DEVICES;
- st->container_dev = fd2devnum(fd);
}
+ st->loaded_container = 1;
return 0;
}
st->minor_version = 0;
st->max_devs = IMSM_MAX_DEVICES;
}
+ st->loaded_container = 0;
return 0;
}
return (info->size * 2) & ~(info_to_blocks_per_strip(info) - 1);
}
+static void imsm_update_version_info(struct intel_super *super)
+{
+ /* update the version and attributes */
+ struct imsm_super *mpb = super->anchor;
+ char *version;
+ struct imsm_dev *dev;
+ struct imsm_map *map;
+ int i;
+
+ for (i = 0; i < mpb->num_raid_devs; i++) {
+ dev = get_imsm_dev(super, i);
+ map = get_imsm_map(dev, 0);
+ if (__le32_to_cpu(dev->size_high) > 0)
+ mpb->attributes |= MPB_ATTRIB_2TB;
+
+ /* FIXME detect when an array spans a port multiplier */
+ #if 0
+ mpb->attributes |= MPB_ATTRIB_PM;
+ #endif
+
+ if (mpb->num_raid_devs > 1 ||
+ mpb->attributes != MPB_ATTRIB_CHECKSUM_VERIFY) {
+ version = MPB_VERSION_ATTRIBS;
+ switch (get_imsm_raid_level(map)) {
+ case 0: mpb->attributes |= MPB_ATTRIB_RAID0; break;
+ case 1: mpb->attributes |= MPB_ATTRIB_RAID1; break;
+ case 10: mpb->attributes |= MPB_ATTRIB_RAID10; break;
+ case 5: mpb->attributes |= MPB_ATTRIB_RAID5; break;
+ }
+ } else {
+ if (map->num_members >= 5)
+ version = MPB_VERSION_5OR6_DISK_ARRAY;
+ else if (dev->status == DEV_CLONE_N_GO)
+ version = MPB_VERSION_CNG;
+ else if (get_imsm_raid_level(map) == 5)
+ version = MPB_VERSION_RAID5;
+ else if (map->num_members >= 3)
+ version = MPB_VERSION_3OR4_DISK_ARRAY;
+ else if (get_imsm_raid_level(map) == 1)
+ version = MPB_VERSION_RAID1;
+ else
+ version = MPB_VERSION_RAID0;
+ }
+ strcpy(((char *) mpb->sig) + strlen(MPB_SIGNATURE), version);
+ }
+}
+
static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
unsigned long long size, char *name,
char *homehost, int *uuid)
*/
struct intel_super *super = st->sb;
struct imsm_super *mpb = super->anchor;
+ struct intel_dev *dv;
struct imsm_dev *dev;
struct imsm_vol *vol;
struct imsm_map *map;
int idx = mpb->num_raid_devs;
int i;
unsigned long long array_blocks;
- __u32 offset = 0;
size_t size_old, size_new;
- if (mpb->num_raid_devs >= 2) {
+ if (super->orom && mpb->num_raid_devs >= super->orom->vpa) {
fprintf(stderr, Name": This imsm-container already has the "
- "maximum of 2 volumes\n");
+ "maximum of %d volumes\n", super->orom->vpa);
return 0;
}
if (super->current_vol == 0)
mpb->num_disks = 0;
sprintf(st->subarray, "%d", idx);
+ dv = malloc(sizeof(*dv));
+ if (!dv) {
+ fprintf(stderr, Name ": failed to allocate device list entry\n");
+ return 0;
+ }
dev = malloc(sizeof(*dev) + sizeof(__u32) * (info->raid_disks - 1));
if (!dev) {
+ free(dv);
fprintf(stderr, Name": could not allocate raid device\n");
return 0;
}
strncpy((char *) dev->volume, name, MAX_RAID_SERIAL_LEN);
- array_blocks = calc_array_size(info->level, info->raid_disks,
- info->layout, info->chunk_size,
- info->size*2);
+ if (info->level == 1)
+ array_blocks = info_to_blocks_per_member(info);
+ else
+ array_blocks = calc_array_size(info->level, info->raid_disks,
+ info->layout, info->chunk_size,
+ info->size*2);
dev->size_low = __cpu_to_le32((__u32) array_blocks);
dev->size_high = __cpu_to_le32((__u32) (array_blocks >> 32));
dev->status = __cpu_to_le32(0);
dev->reserved_blocks = __cpu_to_le32(0);
vol = &dev->vol;
vol->migr_state = 0;
- vol->migr_type = 0;
+ vol->migr_type = MIGR_INIT;
vol->dirty = 0;
- for (i = 0; i < idx; i++) {
- struct imsm_dev *prev = get_imsm_dev(super, i);
- struct imsm_map *pmap = get_imsm_map(prev, 0);
-
- offset += __le32_to_cpu(pmap->blocks_per_member);
- offset += IMSM_RESERVED_SECTORS;
- }
+ vol->curr_migr_unit = 0;
map = get_imsm_map(dev, 0);
- map->pba_of_lba0 = __cpu_to_le32(offset);
+ map->pba_of_lba0 = __cpu_to_le32(super->create_offset);
map->blocks_per_member = __cpu_to_le32(info_to_blocks_per_member(info));
map->blocks_per_strip = __cpu_to_le16(info_to_blocks_per_strip(info));
map->num_data_stripes = __cpu_to_le32(info_to_num_data_stripes(info));
"in a raid1 volume\n");
return 0;
}
- if (info->level == 10)
+ if (info->level == 10) {
map->raid_level = 1;
- else
+ map->num_domains = info->raid_disks / 2;
+ } else {
map->raid_level = info->level;
+ map->num_domains = !!map->raid_level;
+ }
map->num_members = info->raid_disks;
for (i = 0; i < map->num_members; i++) {
/* initialized in add_to_super */
- map->disk_ord_tbl[i] = __cpu_to_le32(0);
+ set_imsm_ord_tbl_ent(map, i, 0);
}
mpb->num_raid_devs++;
- super->dev_tbl[super->current_vol] = dev;
+
+ dv->dev = dev;
+ dv->index = super->current_vol;
+ dv->next = super->devlist;
+ super->devlist = dv;
+
+ imsm_update_version_info(super);
return 1;
}
struct intel_super *super;
struct imsm_super *mpb;
size_t mpb_size;
+ char *version;
if (!info) {
st->sb = NULL;
mpb = super->buf;
memset(mpb, 0, mpb_size);
- memcpy(mpb->sig, MPB_SIGNATURE, strlen(MPB_SIGNATURE));
- memcpy(mpb->sig + strlen(MPB_SIGNATURE), MPB_VERSION_RAID5,
- strlen(MPB_VERSION_RAID5));
+ mpb->attributes = MPB_ATTRIB_CHECKSUM_VERIFY;
+
+ version = (char *) mpb->sig;
+ strcpy(version, MPB_SIGNATURE);
+ version += strlen(MPB_SIGNATURE);
+ strcpy(version, MPB_VERSION_RAID0);
mpb->mpb_size = mpb_size;
st->sb = super;
return 1;
}
-static void add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
+#ifndef MDASSEMBLE
+static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
int fd, char *devname)
{
struct intel_super *super = st->sb;
struct dl *dl;
struct imsm_dev *dev;
struct imsm_map *map;
- __u32 status;
dev = get_imsm_dev(super, super->current_vol);
map = get_imsm_map(dev, 0);
+ if (! (dk->state & (1<<MD_DISK_SYNC))) {
+ fprintf(stderr, Name ": %s: Cannot add spare devices to IMSM volume\n",
+ devname);
+ return 1;
+ }
+
for (dl = super->disks; dl ; dl = dl->next)
if (dl->major == dk->major &&
dl->minor == dk->minor)
break;
- if (!dl || ! (dk->state & (1<<MD_DISK_SYNC)))
- return;
+ if (!dl) {
+ fprintf(stderr, Name ": %s is not a member of the same container\n", devname);
+ return 1;
+ }
/* add a pristine spare to the metadata */
if (dl->index < 0) {
dl->index = super->anchor->num_disks;
super->anchor->num_disks++;
}
- map->disk_ord_tbl[dk->number] = __cpu_to_le32(dl->index);
- status = CONFIGURED_DISK | USABLE_DISK;
- dl->disk.status = __cpu_to_le32(status);
+ set_imsm_ord_tbl_ent(map, dk->number, dl->index);
+ dl->disk.status = CONFIGURED_DISK | USABLE_DISK;
/* if we are creating the first raid device update the family number */
if (super->current_vol == 0) {
sum = __gen_imsm_checksum(mpb);
mpb->family_num = __cpu_to_le32(sum);
}
+
+ return 0;
}
-static void add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
+static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
int fd, char *devname)
{
struct intel_super *super = st->sb;
struct dl *dd;
unsigned long long size;
- __u32 status, id;
+ __u32 id;
int rv;
struct stat stb;
- if (super->current_vol >= 0) {
- add_to_super_imsm_volume(st, dk, fd, devname);
- return;
+ /* if we are on an RAID enabled platform check that the disk is
+ * attached to the raid controller
+ */
+ if (super->hba && !disk_attached_to_hba(fd, super->hba)) {
+ fprintf(stderr,
+ Name ": %s is not attached to the raid controller: %s\n",
+ devname ? : "disk", super->hba);
+ return 1;
}
+ if (super->current_vol >= 0)
+ return add_to_super_imsm_volume(st, dk, fd, devname);
+
fstat(fd, &stb);
dd = malloc(sizeof(*dd));
if (!dd) {
fprintf(stderr,
Name ": malloc failed %s:%d.\n", __func__, __LINE__);
- abort();
+ return 1;
}
memset(dd, 0, sizeof(*dd));
dd->major = major(stb.st_rdev);
dd->minor = minor(stb.st_rdev);
dd->index = -1;
dd->devname = devname ? strdup(devname) : NULL;
- dd->next = super->disks;
dd->fd = fd;
rv = imsm_read_serial(fd, devname, dd->serial);
if (rv) {
get_dev_size(fd, NULL, &size);
size /= 512;
- status = USABLE_DISK | SPARE_DISK;
- strcpy((char *) dd->disk.serial, (char *) dd->serial);
+ serialcpy(dd->disk.serial, dd->serial);
dd->disk.total_blocks = __cpu_to_le32(size);
- dd->disk.status = __cpu_to_le32(status);
+ dd->disk.status = USABLE_DISK | SPARE_DISK;
if (sysfs_disk_to_scsi_id(fd, &id) == 0)
dd->disk.scsi_id = __cpu_to_le32(id);
else
dd->disk.scsi_id = __cpu_to_le32(0);
- super->disks = dd;
+
+ if (st->update_tail) {
+ dd->next = super->add;
+ super->add = dd;
+ } else {
+ dd->next = super->disks;
+ super->disks = dd;
+ }
+
+ return 0;
}
static int store_imsm_mpb(int fd, struct intel_super *super);
mpb->generation_num = __cpu_to_le32(1UL);
for (d = super->disks; d; d = d->next) {
- if (d->index >= 0)
+ if (d->index != -1)
continue;
mpb->disk[0] = d->disk;
__u32 generation;
__u32 sum;
int spares = 0;
- int raid_disks = 0;
int i;
__u32 mpb_size = sizeof(struct imsm_super) - sizeof(struct imsm_disk);
generation++;
mpb->generation_num = __cpu_to_le32(generation);
+ mpb_size += sizeof(struct imsm_disk) * mpb->num_disks;
for (d = super->disks; d; d = d->next) {
- if (d->index < 0)
+ if (d->index == -1)
spares++;
- else {
- raid_disks++;
+ else
mpb->disk[d->index] = d->disk;
- mpb_size += sizeof(struct imsm_disk);
- }
- }
- if (raid_disks != mpb->num_disks) {
- fprintf(stderr, "%s: expected %d disks only found %d\n",
- __func__, mpb->num_disks, raid_disks);
- return 1;
}
+ for (d = super->missing; d; d = d->next)
+ mpb->disk[d->index] = d->disk;
for (i = 0; i < mpb->num_raid_devs; i++) {
struct imsm_dev *dev = __get_imsm_dev(mpb, i);
- imsm_copy_dev(dev, super->dev_tbl[i]);
+ imsm_copy_dev(dev, get_imsm_dev(super, i));
mpb_size += sizeof_imsm_dev(dev, 0);
}
mpb_size += __le32_to_cpu(mpb->bbm_log_size);
for (d = super->disks; d ; d = d->next) {
if (d->index < 0)
continue;
- if (store_imsm_mpb(d->fd, super)) {
+ if (store_imsm_mpb(d->fd, super))
fprintf(stderr, "%s: failed for device %d:%d %s\n",
__func__, d->major, d->minor, strerror(errno));
- return 1;
- }
if (doclose) {
close(d->fd);
d->fd = -1;
return 0;
}
+
+static int create_array(struct supertype *st)
+{
+ size_t len;
+ struct imsm_update_create_array *u;
+ struct intel_super *super = st->sb;
+ struct imsm_dev *dev = get_imsm_dev(super, super->current_vol);
+ struct imsm_map *map = get_imsm_map(dev, 0);
+ struct disk_info *inf;
+ struct imsm_disk *disk;
+ int i;
+ int idx;
+
+ len = sizeof(*u) - sizeof(*dev) + sizeof_imsm_dev(dev, 0) +
+ sizeof(*inf) * map->num_members;
+ u = malloc(len);
+ if (!u) {
+ fprintf(stderr, "%s: failed to allocate update buffer\n",
+ __func__);
+ return 1;
+ }
+
+ u->type = update_create_array;
+ u->dev_idx = super->current_vol;
+ imsm_copy_dev(&u->dev, dev);
+ inf = get_disk_info(u);
+ for (i = 0; i < map->num_members; i++) {
+ idx = get_imsm_disk_idx(dev, i);
+ disk = get_imsm_disk(super, idx);
+ serialcpy(inf[i].serial, disk->serial);
+ }
+ append_metadata_update(st, u, len);
+
+ return 0;
+}
+
+static int _add_disk(struct supertype *st)
+{
+ struct intel_super *super = st->sb;
+ size_t len;
+ struct imsm_update_add_disk *u;
+
+ if (!super->add)
+ return 0;
+
+ len = sizeof(*u);
+ u = malloc(len);
+ if (!u) {
+ fprintf(stderr, "%s: failed to allocate update buffer\n",
+ __func__);
+ return 1;
+ }
+
+ u->type = update_add_disk;
+ append_metadata_update(st, u, len);
+
+ return 0;
+}
+
static int write_init_super_imsm(struct supertype *st)
{
if (st->update_tail) {
- /* queue the recently created array as a metadata update */
- size_t len;
- struct imsm_update_create_array *u;
+ /* queue the recently created array / added disk
+ * as a metadata update */
struct intel_super *super = st->sb;
- struct imsm_dev *dev;
struct dl *d;
+ int rv;
- if (super->current_vol < 0 ||
- !(dev = get_imsm_dev(super, super->current_vol))) {
- fprintf(stderr, "%s: could not determine sub-array\n",
- __func__);
- return 1;
- }
-
-
- len = sizeof(*u) - sizeof(*dev) + sizeof_imsm_dev(dev, 0);
- u = malloc(len);
- if (!u) {
- fprintf(stderr, "%s: failed to allocate update buffer\n",
- __func__);
- return 1;
- }
-
- u->type = update_create_array;
- u->dev_idx = super->current_vol;
- imsm_copy_dev(&u->dev, dev);
- append_metadata_update(st, u, len);
+ /* determine if we are creating a volume or adding a disk */
+ if (super->current_vol < 0) {
+ /* in the add disk case we are running in mdmon
+ * context, so don't close fd's
+ */
+ return _add_disk(st);
+ } else
+ rv = create_array(st);
for (d = super->disks; d ; d = d->next) {
close(d->fd);
d->fd = -1;
}
- return 0;
+ return rv;
} else
return write_super_imsm(st->sb, 1);
}
+#endif
static int store_zero_imsm(struct supertype *st, int fd)
{
return 0;
}
-static int validate_geometry_imsm_container(struct supertype *st, int level,
- int layout, int raiddisks, int chunk,
- unsigned long long size, char *dev,
- unsigned long long *freesize,
- int verbose)
-{
- int fd;
- unsigned long long ldsize;
+static int imsm_bbm_log_size(struct imsm_super *mpb)
+{
+ return __le32_to_cpu(mpb->bbm_log_size);
+}
+
+#ifndef MDASSEMBLE
+static int validate_geometry_imsm_container(struct supertype *st, int level,
+ int layout, int raiddisks, int chunk,
+ unsigned long long size, char *dev,
+ unsigned long long *freesize,
+ int verbose)
+{
+ int fd;
+ unsigned long long ldsize;
+ const struct imsm_orom *orom;
+
+ if (level != LEVEL_CONTAINER)
+ return 0;
+ if (!dev)
+ return 1;
+
+ if (check_env("IMSM_NO_PLATFORM"))
+ orom = NULL;
+ else
+ orom = find_imsm_orom();
+ if (orom && raiddisks > orom->tds) {
+ if (verbose)
+ fprintf(stderr, Name ": %d exceeds maximum number of"
+ " platform supported disks: %d\n",
+ raiddisks, orom->tds);
+ return 0;
+ }
+
+ fd = open(dev, O_RDONLY|O_EXCL, 0);
+ if (fd < 0) {
+ if (verbose)
+ fprintf(stderr, Name ": imsm: Cannot open %s: %s\n",
+ dev, strerror(errno));
+ return 0;
+ }
+ if (!get_dev_size(fd, dev, &ldsize)) {
+ close(fd);
+ return 0;
+ }
+ close(fd);
+
+ *freesize = avail_size_imsm(st, ldsize >> 9);
+
+ return 1;
+}
+
+static unsigned long long find_size(struct extent *e, int *idx, int num_extents)
+{
+ const unsigned long long base_start = e[*idx].start;
+ unsigned long long end = base_start + e[*idx].size;
+ int i;
+
+ if (base_start == end)
+ return 0;
+
+ *idx = *idx + 1;
+ for (i = *idx; i < num_extents; i++) {
+ /* extend overlapping extents */
+ if (e[i].start >= base_start &&
+ e[i].start <= end) {
+ if (e[i].size == 0)
+ return 0;
+ if (e[i].start + e[i].size > end)
+ end = e[i].start + e[i].size;
+ } else if (e[i].start > end) {
+ *idx = i;
+ break;
+ }
+ }
+
+ return end - base_start;
+}
+
+static unsigned long long merge_extents(struct intel_super *super, int sum_extents)
+{
+ /* build a composite disk with all known extents and generate a new
+ * 'maxsize' given the "all disks in an array must share a common start
+ * offset" constraint
+ */
+ struct extent *e = calloc(sum_extents, sizeof(*e));
+ struct dl *dl;
+ int i, j;
+ int start_extent;
+ unsigned long long pos;
+ unsigned long long start;
+ unsigned long long maxsize;
+ unsigned long reserve;
+
+ if (!e)
+ return ~0ULL; /* error */
+
+ /* coalesce and sort all extents. also, check to see if we need to
+ * reserve space between member arrays
+ */
+ j = 0;
+ for (dl = super->disks; dl; dl = dl->next) {
+ if (!dl->e)
+ continue;
+ for (i = 0; i < dl->extent_cnt; i++)
+ e[j++] = dl->e[i];
+ }
+ qsort(e, sum_extents, sizeof(*e), cmp_extent);
+
+ /* merge extents */
+ i = 0;
+ j = 0;
+ while (i < sum_extents) {
+ e[j].start = e[i].start;
+ e[j].size = find_size(e, &i, sum_extents);
+ j++;
+ if (e[j-1].size == 0)
+ break;
+ }
+
+ pos = 0;
+ maxsize = 0;
+ start_extent = 0;
+ i = 0;
+ do {
+ unsigned long long esize;
+
+ esize = e[i].start - pos;
+ if (esize >= maxsize) {
+ maxsize = esize;
+ start = pos;
+ start_extent = i;
+ }
+ pos = e[i].start + e[i].size;
+ i++;
+ } while (e[i-1].size);
+ free(e);
+
+ if (start_extent > 0)
+ reserve = IMSM_RESERVED_SECTORS; /* gap between raid regions */
+ else
+ reserve = 0;
+
+ if (maxsize < reserve)
+ return ~0ULL;
- if (level != LEVEL_CONTAINER)
- return 0;
- if (!dev)
- return 1;
+ super->create_offset = ~((__u32) 0);
+ if (start + reserve > super->create_offset)
+ return ~0ULL; /* start overflows create_offset */
+ super->create_offset = start + reserve;
- fd = open(dev, O_RDONLY|O_EXCL, 0);
- if (fd < 0) {
- if (verbose)
- fprintf(stderr, Name ": imsm: Cannot open %s: %s\n",
- dev, strerror(errno));
- return 0;
- }
- if (!get_dev_size(fd, dev, &ldsize)) {
- close(fd);
+ return maxsize - reserve;
+}
+
+static int is_raid_level_supported(const struct imsm_orom *orom, int level, int raiddisks)
+{
+ if (level < 0 || level == 6 || level == 4)
return 0;
- }
- close(fd);
- *freesize = avail_size_imsm(st, ldsize >> 9);
+ /* if we have an orom prevent invalid raid levels */
+ if (orom)
+ switch (level) {
+ case 0: return imsm_orom_has_raid0(orom);
+ case 1:
+ if (raiddisks > 2)
+ return imsm_orom_has_raid1e(orom);
+ else
+ return imsm_orom_has_raid1(orom);
+ case 10: return imsm_orom_has_raid10(orom);
+ case 5: return imsm_orom_has_raid5(orom);
+ }
+ else
+ return 1; /* not on an Intel RAID platform so anything goes */
- return 1;
+ return 0;
}
+#define vprintf(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg))
/* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
* FIX ME add ahci details
*/
struct extent *e;
int i;
- if (level == LEVEL_CONTAINER)
+ /* We must have the container info already read in. */
+ if (!super)
return 0;
- if (level == 1 && raiddisks > 2) {
- if (verbose)
- fprintf(stderr, Name ": imsm does not support more "
- "than 2 in a raid1 configuration\n");
+ if (!is_raid_level_supported(super->orom, level, raiddisks)) {
+ vprintf(": platform does not support raid level: %d\n", level);
return 0;
}
-
- /* We must have the container info already read in. */
- if (!super)
+ if (super->orom && !imsm_orom_has_chunk(super->orom, chunk)) {
+ vprintf(": platform does not support a chunk size of: %d\n", chunk);
return 0;
+ }
+ if (layout != imsm_level_to_layout(level)) {
+ if (level == 5)
+ vprintf(": imsm raid 5 only supports the left-asymmetric layout\n");
+ else if (level == 10)
+ vprintf(": imsm raid 10 only supports the n2 layout\n");
+ else
+ vprintf(": imsm unknown layout %#x for this raid level %d\n",
+ layout, level);
+ return 0;
+ }
if (!dev) {
/* General test: make sure there is space for
}
return 1;
}
+
/* This device must be a member of the set */
if (stat(dev, &stb) < 0)
return 0;
"same imsm set\n", dev);
return 0;
}
+
+ /* retrieve the largest free space block */
e = get_extents(super, dl);
maxsize = 0;
i = 0;
- if (e) do {
- unsigned long long esize;
- esize = e[i].start - pos;
- if (esize >= maxsize)
- maxsize = esize;
- pos = e[i].start + e[i].size;
- i++;
- } while (e[i-1].size);
+ if (e) {
+ do {
+ unsigned long long esize;
+
+ esize = e[i].start - pos;
+ if (esize >= maxsize)
+ maxsize = esize;
+ pos = e[i].start + e[i].size;
+ i++;
+ } while (e[i-1].size);
+ dl->e = e;
+ dl->extent_cnt = i;
+ } else {
+ if (verbose)
+ fprintf(stderr, Name ": unable to determine free space for: %s\n",
+ dev);
+ return 0;
+ }
+ if (maxsize < size) {
+ if (verbose)
+ fprintf(stderr, Name ": %s not enough space (%llu < %llu)\n",
+ dev, maxsize, size);
+ return 0;
+ }
+
+ /* count total number of extents for merge */
+ i = 0;
+ for (dl = super->disks; dl; dl = dl->next)
+ if (dl->e)
+ i += dl->extent_cnt;
+
+ maxsize = merge_extents(super, i);
+ if (maxsize < size) {
+ if (verbose)
+ fprintf(stderr, Name ": not enough space after merge (%llu < %llu)\n",
+ maxsize, size);
+ return 0;
+ } else if (maxsize == ~0ULL) {
+ if (verbose)
+ fprintf(stderr, Name ": failed to merge %d extents\n", i);
+ return 0;
+ }
+
*freesize = maxsize;
return 1;
}
-int imsm_bbm_log_size(struct imsm_super *mpb)
-{
- return __le32_to_cpu(mpb->bbm_log_size);
-}
-
static int validate_geometry_imsm(struct supertype *st, int level, int layout,
int raiddisks, int chunk, unsigned long long size,
char *dev, unsigned long long *freesize,
return 1;
}
+#endif /* MDASSEMBLE */
static struct mdinfo *container_content_imsm(struct supertype *st)
{
for (i = 0; i < mpb->num_raid_devs; i++) {
struct imsm_dev *dev = get_imsm_dev(super, i);
- struct imsm_vol *vol = &dev->vol;
struct imsm_map *map = get_imsm_map(dev, 0);
struct mdinfo *this;
int slot;
memset(this, 0, sizeof(*this));
this->next = rest;
- this->array.level = get_imsm_raid_level(map);
- this->array.raid_disks = map->num_members;
- this->array.layout = imsm_level_to_layout(this->array.level);
- this->array.md_minor = -1;
- this->array.ctime = 0;
- this->array.utime = 0;
- this->array.chunk_size = __le16_to_cpu(map->blocks_per_strip) << 9;
- this->array.state = !vol->dirty;
- this->container_member = i;
- if (map->map_state == IMSM_T_STATE_UNINITIALIZED ||
- dev->vol.dirty || dev->vol.migr_state)
- this->resync_start = 0;
- else
- this->resync_start = ~0ULL;
-
- strncpy(this->name, (char *) dev->volume, MAX_RAID_SERIAL_LEN);
- this->name[MAX_RAID_SERIAL_LEN] = 0;
-
- sprintf(this->text_version, "/%s/%d",
- devnum2devname(st->container_dev),
- this->container_member);
-
- memset(this->uuid, 0, sizeof(this->uuid));
-
- this->component_size = __le32_to_cpu(map->blocks_per_member);
-
+ super->current_vol = i;
+ getinfo_super_imsm_volume(st, this);
for (slot = 0 ; slot < map->num_members; slot++) {
struct mdinfo *info_d;
struct dl *d;
__u32 ord;
skip = 0;
- idx = get_imsm_disk_idx(map, slot);
+ idx = get_imsm_disk_idx(dev, slot);
ord = get_imsm_ord_tbl_ent(dev, slot);
for (d = super->disks; d ; d = d->next)
if (d->index == idx)
if (d == NULL)
skip = 1;
- s = d ? __le32_to_cpu(d->disk.status) : 0;
+ s = d ? d->disk.status : 0;
if (s & FAILED_DISK)
skip = 1;
if (!(s & USABLE_DISK))
}
+#ifndef MDASSEMBLE
static int imsm_open_new(struct supertype *c, struct active_array *a,
char *inst)
{
return 0;
}
-static __u8 imsm_check_degraded(struct intel_super *super, int n, int failed)
+static __u8 imsm_check_degraded(struct intel_super *super, struct imsm_dev *dev, int failed)
{
- struct imsm_dev *dev = get_imsm_dev(super, n);
struct imsm_map *map = get_imsm_map(dev, 0);
if (!failed)
case 10:
{
/**
- * check to see if any mirrors have failed,
- * otherwise we are degraded
+ * check to see if any mirrors have failed, otherwise we
+ * are degraded. Even numbered slots are mirrored on
+ * slot+1
*/
- int device_per_mirror = 2; /* FIXME is this always the case?
- * and are they always adjacent?
- */
- int failed = 0;
int i;
+ /* gcc -Os complains that this is unused */
+ int insync = insync;
for (i = 0; i < map->num_members; i++) {
- int idx = get_imsm_disk_idx(map, i);
- struct imsm_disk *disk = get_imsm_disk(super, idx);
+ __u32 ord = get_imsm_ord_tbl_ent(dev, i);
+ int idx = ord_to_idx(ord);
+ struct imsm_disk *disk;
- if (__le32_to_cpu(disk->status) & FAILED_DISK)
- failed++;
+ /* reset the potential in-sync count on even-numbered
+ * slots. num_copies is always 2 for imsm raid10
+ */
+ if ((i & 1) == 0)
+ insync = 2;
- if (failed >= device_per_mirror)
- return IMSM_T_STATE_FAILED;
+ disk = get_imsm_disk(super, idx);
+ if (!disk || disk->status & FAILED_DISK ||
+ ord & IMSM_ORD_REBUILD)
+ insync--;
- /* reset 'failed' for next mirror set */
- if (!((i + 1) % device_per_mirror))
- failed = 0;
+ /* no in-sync disks left in this mirror the
+ * array has failed
+ */
+ if (insync == 0)
+ return IMSM_T_STATE_FAILED;
}
return IMSM_T_STATE_DEGRADED;
return map->map_state;
}
-static int imsm_count_failed(struct intel_super *super, struct imsm_map *map)
+static int imsm_count_failed(struct intel_super *super, struct imsm_dev *dev)
{
int i;
int failed = 0;
struct imsm_disk *disk;
+ struct imsm_map *map = get_imsm_map(dev, 0);
for (i = 0; i < map->num_members; i++) {
- int idx = get_imsm_disk_idx(map, i);
+ __u32 ord = get_imsm_ord_tbl_ent(dev, i);
+ int idx = ord_to_idx(ord);
disk = get_imsm_disk(super, idx);
- if (__le32_to_cpu(disk->status) & FAILED_DISK)
+ if (!disk || disk->status & FAILED_DISK ||
+ ord & IMSM_ORD_REBUILD)
failed++;
}
return failed;
}
-static void imsm_set_array_state(struct active_array *a, int consistent)
+static int is_resyncing(struct imsm_dev *dev)
+{
+ struct imsm_map *migr_map;
+
+ if (!dev->vol.migr_state)
+ return 0;
+
+ if (dev->vol.migr_type == MIGR_INIT)
+ return 1;
+
+ migr_map = get_imsm_map(dev, 1);
+
+ if (migr_map->map_state == IMSM_T_STATE_NORMAL)
+ return 1;
+ else
+ return 0;
+}
+
+static int is_rebuilding(struct imsm_dev *dev)
+{
+ struct imsm_map *migr_map;
+
+ if (!dev->vol.migr_state)
+ return 0;
+
+ if (dev->vol.migr_type != MIGR_REBUILD)
+ return 0;
+
+ migr_map = get_imsm_map(dev, 1);
+
+ if (migr_map->map_state == IMSM_T_STATE_DEGRADED)
+ return 1;
+ else
+ return 0;
+}
+
+static void mark_failure(struct imsm_disk *disk)
+{
+ if (disk->status & FAILED_DISK)
+ return;
+ disk->status |= FAILED_DISK;
+ disk->scsi_id = __cpu_to_le32(~(__u32)0);
+ memmove(&disk->serial[0], &disk->serial[1], MAX_RAID_SERIAL_LEN - 1);
+}
+
+/* Handle dirty -> clean transititions and resync. Degraded and rebuild
+ * states are handled in imsm_set_disk() with one exception, when a
+ * resync is stopped due to a new failure this routine will set the
+ * 'degraded' state for the array.
+ */
+static int imsm_set_array_state(struct active_array *a, int consistent)
{
int inst = a->info.container_member;
struct intel_super *super = a->container->sb;
struct imsm_dev *dev = get_imsm_dev(super, inst);
struct imsm_map *map = get_imsm_map(dev, 0);
- int dirty = !consistent;
- int failed;
- __u8 map_state;
-
- failed = imsm_count_failed(super, map);
- map_state = imsm_check_degraded(super, inst, failed);
+ int failed = imsm_count_failed(super, dev);
+ __u8 map_state = imsm_check_degraded(super, dev, failed);
- if (consistent && !dev->vol.dirty &&
- (dev->vol.migr_state || map_state != IMSM_T_STATE_NORMAL))
- a->resync_start = 0ULL;
+ /* before we activate this array handle any missing disks */
+ if (consistent == 2 && super->missing) {
+ struct dl *dl;
- if (a->resync_start == ~0ULL) {
- /* complete recovery or initial resync */
- if (map->map_state != map_state) {
- dprintf("imsm: map_state %d: %d\n",
- inst, map_state);
- map->map_state = map_state;
- super->updates_pending++;
- }
- if (dev->vol.migr_state) {
- dprintf("imsm: mark resync complete\n");
- dev->vol.migr_state = 0;
- dev->vol.migr_type = 0;
+ dprintf("imsm: mark missing\n");
+ end_migration(dev, map_state);
+ for (dl = super->missing; dl; dl = dl->next)
+ mark_failure(&dl->disk);
+ super->updates_pending++;
+ }
+
+ if (consistent == 2 &&
+ (!is_resync_complete(a) ||
+ map_state != IMSM_T_STATE_NORMAL ||
+ dev->vol.migr_state))
+ consistent = 0;
+
+ if (is_resync_complete(a)) {
+ /* complete intialization / resync,
+ * recovery is completed in ->set_disk
+ */
+ if (is_resyncing(dev)) {
+ dprintf("imsm: mark resync done\n");
+ end_migration(dev, map_state);
super->updates_pending++;
}
- } else if (!dev->vol.migr_state) {
- dprintf("imsm: mark '%s' (%llu)\n",
- failed ? "rebuild" : "initializing", a->resync_start);
- /* mark that we are rebuilding */
- map->map_state = failed ? map_state : IMSM_T_STATE_NORMAL;
- dev->vol.migr_state = 1;
- dev->vol.migr_type = failed ? 1 : 0;
- dup_map(dev);
- a->check_degraded = 1;
+ } else if (!is_resyncing(dev) && !failed) {
+ /* mark the start of the init process if nothing is failed */
+ dprintf("imsm: mark resync start (%llu)\n", a->resync_start);
+ if (map->map_state == IMSM_T_STATE_NORMAL)
+ migrate(dev, IMSM_T_STATE_NORMAL, MIGR_REBUILD);
+ else
+ migrate(dev, IMSM_T_STATE_NORMAL, MIGR_INIT);
+ super->updates_pending++;
+ }
+
+ /* check if we can update the migration checkpoint */
+ if (dev->vol.migr_state &&
+ __le32_to_cpu(dev->vol.curr_migr_unit) != a->resync_start) {
+ dprintf("imsm: checkpoint migration (%llu)\n", a->resync_start);
+ dev->vol.curr_migr_unit = __cpu_to_le32(a->resync_start);
super->updates_pending++;
}
/* mark dirty / clean */
- if (dirty != dev->vol.dirty) {
+ if (dev->vol.dirty != !consistent) {
dprintf("imsm: mark '%s' (%llu)\n",
- dirty ? "dirty" : "clean", a->resync_start);
- dev->vol.dirty = dirty;
+ consistent ? "clean" : "dirty", a->resync_start);
+ if (consistent)
+ dev->vol.dirty = 0;
+ else
+ dev->vol.dirty = 1;
super->updates_pending++;
}
+ return consistent;
}
static void imsm_set_disk(struct active_array *a, int n, int state)
struct imsm_dev *dev = get_imsm_dev(super, inst);
struct imsm_map *map = get_imsm_map(dev, 0);
struct imsm_disk *disk;
- __u32 status;
- int failed = 0;
- int new_failure = 0;
+ int failed;
+ __u32 ord;
+ __u8 map_state;
if (n > map->num_members)
fprintf(stderr, "imsm: set_disk %d out of range 0..%d\n",
dprintf("imsm: set_disk %d:%x\n", n, state);
- disk = get_imsm_disk(super, get_imsm_disk_idx(map, n));
+ ord = get_imsm_ord_tbl_ent(dev, n);
+ disk = get_imsm_disk(super, ord_to_idx(ord));
/* check for new failures */
- status = __le32_to_cpu(disk->status);
- if ((state & DS_FAULTY) && !(status & FAILED_DISK)) {
- status |= FAILED_DISK;
- disk->status = __cpu_to_le32(status);
- new_failure = 1;
+ if ((state & DS_FAULTY) && !(disk->status & FAILED_DISK)) {
+ mark_failure(disk);
super->updates_pending++;
}
+
/* check if in_sync */
- if ((state & DS_INSYNC) && !(status & USABLE_DISK)) {
- status |= USABLE_DISK;
- disk->status = __cpu_to_le32(status);
+ if (state & DS_INSYNC && ord & IMSM_ORD_REBUILD) {
+ struct imsm_map *migr_map = get_imsm_map(dev, 1);
+
+ set_imsm_ord_tbl_ent(migr_map, n, ord_to_idx(ord));
super->updates_pending++;
}
- /* the number of failures have changed, count up 'failed' to determine
- * degraded / failed status
- */
- if (new_failure && map->map_state != IMSM_T_STATE_FAILED)
- failed = imsm_count_failed(super, map);
-
- /* determine map_state based on failed or in_sync count */
- if (failed)
- map->map_state = imsm_check_degraded(super, inst, failed);
- else if (map->map_state == IMSM_T_STATE_DEGRADED) {
- struct mdinfo *d;
- int working = 0;
-
- for (d = a->info.devs ; d ; d = d->next)
- if (d->curr_state & DS_INSYNC)
- working++;
+ failed = imsm_count_failed(super, dev);
+ map_state = imsm_check_degraded(super, dev, failed);
- if (working == a->info.array.raid_disks) {
- map->map_state = IMSM_T_STATE_NORMAL;
- dev->vol.migr_state = 0;
- dev->vol.migr_type = 0;
- super->updates_pending++;
- }
+ /* check if recovery complete, newly degraded, or failed */
+ if (map_state == IMSM_T_STATE_NORMAL && is_rebuilding(dev)) {
+ end_migration(dev, map_state);
+ super->updates_pending++;
+ } else if (map_state == IMSM_T_STATE_DEGRADED &&
+ map->map_state != map_state &&
+ !dev->vol.migr_state) {
+ dprintf("imsm: mark degraded\n");
+ map->map_state = map_state;
+ super->updates_pending++;
+ } else if (map_state == IMSM_T_STATE_FAILED &&
+ map->map_state != map_state) {
+ dprintf("imsm: mark failed\n");
+ end_migration(dev, map_state);
+ super->updates_pending++;
}
}
static struct dl *imsm_readd(struct intel_super *super, int idx, struct active_array *a)
{
struct imsm_dev *dev = get_imsm_dev(super, a->info.container_member);
- struct imsm_map *map = get_imsm_map(dev, 0);
- int i = get_imsm_disk_idx(map, idx);
+ int i = get_imsm_disk_idx(dev, idx);
struct dl *dl;
for (dl = super->disks; dl; dl = dl->next)
if (dl->index == i)
break;
- if (__le32_to_cpu(dl->disk.status) & FAILED_DISK)
+ if (dl && dl->disk.status & FAILED_DISK)
dl = NULL;
if (dl)
return dl;
}
-static struct dl *imsm_add_spare(struct intel_super *super, int idx, struct active_array *a)
+static struct dl *imsm_add_spare(struct intel_super *super, int slot, struct active_array *a)
{
struct imsm_dev *dev = get_imsm_dev(super, a->info.container_member);
+ int idx = get_imsm_disk_idx(dev, slot);
struct imsm_map *map = get_imsm_map(dev, 0);
unsigned long long esize;
unsigned long long pos;
int j;
int found;
__u32 array_start;
- __u32 status;
struct dl *dl;
for (dl = super->disks; dl; dl = dl->next) {
/* If in this array, skip */
for (d = a->info.devs ; d ; d = d->next)
- if (d->disk.major == dl->major &&
+ if (d->state_fd >= 0 &&
+ d->disk.major == dl->major &&
d->disk.minor == dl->minor) {
dprintf("%x:%x already in array\n", dl->major, dl->minor);
break;
if (d)
continue;
- /* skip marked in use or failed drives */
- status = __le32_to_cpu(dl->disk.status);
- if (status & FAILED_DISK || status & CONFIGURED_DISK) {
+ /* skip in use or failed drives */
+ if (dl->disk.status & FAILED_DISK || idx == dl->index) {
dprintf("%x:%x status ( %s%s)\n",
dl->major, dl->minor,
- status & FAILED_DISK ? "failed " : "",
- status & CONFIGURED_DISK ? "configured " : "");
+ dl->disk.status & FAILED_DISK ? "failed " : "",
+ idx == dl->index ? "in use " : "");
continue;
}
dprintf("imsm: activate spare: inst=%d failed=%d (%d) level=%d\n",
inst, failed, a->info.array.raid_disks, a->info.array.level);
- if (imsm_check_degraded(super, inst, failed) != IMSM_T_STATE_DEGRADED)
+ if (imsm_check_degraded(super, dev, failed) != IMSM_T_STATE_DEGRADED)
return NULL;
/* For each slot, if it is not working, find a spare */
/* found a usable disk with enough space */
di = malloc(sizeof(*di));
+ if (!di)
+ continue;
memset(di, 0, sizeof(*di));
/* dl->index will be -1 in the case we are activating a
* disk_ord_tbl for the array
*/
mu = malloc(sizeof(*mu));
- mu->buf = malloc(sizeof(struct imsm_update_activate_spare) * num_spares);
+ if (mu) {
+ mu->buf = malloc(sizeof(struct imsm_update_activate_spare) * num_spares);
+ if (mu->buf == NULL) {
+ free(mu);
+ mu = NULL;
+ }
+ }
+ if (!mu) {
+ while (rv) {
+ struct mdinfo *n = rv->next;
+
+ free(rv);
+ rv = n;
+ }
+ return NULL;
+ }
+
mu->space = NULL;
mu->len = sizeof(struct imsm_update_activate_spare) * num_spares;
mu->next = *updates;
return rv;
}
-static int disks_overlap(struct imsm_map *m1, struct imsm_map *m2)
+static int disks_overlap(struct intel_super *super, int idx, struct imsm_update_create_array *u)
{
+ struct imsm_dev *dev = get_imsm_dev(super, idx);
+ struct imsm_map *map = get_imsm_map(dev, 0);
+ struct imsm_map *new_map = get_imsm_map(&u->dev, 0);
+ struct disk_info *inf = get_disk_info(u);
+ struct imsm_disk *disk;
int i;
int j;
- int idx;
- for (i = 0; i < m1->num_members; i++) {
- idx = get_imsm_disk_idx(m1, i);
- for (j = 0; j < m2->num_members; j++)
- if (idx == get_imsm_disk_idx(m2, j))
+ for (i = 0; i < map->num_members; i++) {
+ disk = get_imsm_disk(super, get_imsm_disk_idx(dev, i));
+ for (j = 0; j < new_map->num_members; j++)
+ if (serialcmp(disk->serial, inf[j].serial) == 0)
return 1;
}
return 0;
}
+static void imsm_delete(struct intel_super *super, struct dl **dlp, int index);
+
static void imsm_process_update(struct supertype *st,
struct metadata_update *update)
{
* flag
*/
struct intel_super *super = st->sb;
- struct imsm_super *mpb = super->anchor;
+ struct imsm_super *mpb;
enum imsm_update_type type = *(enum imsm_update_type *) update->buf;
+ /* update requires a larger buf but the allocation failed */
+ if (super->next_len && !super->next_buf) {
+ super->next_len = 0;
+ return;
+ }
+
+ if (super->next_buf) {
+ memcpy(super->next_buf, super->buf, super->len);
+ free(super->buf);
+ super->len = super->next_len;
+ super->buf = super->next_buf;
+
+ super->next_len = 0;
+ super->next_buf = NULL;
+ }
+
+ mpb = super->anchor;
+
switch (type) {
case update_activate_spare: {
struct imsm_update_activate_spare *u = (void *) update->buf;
struct imsm_dev *dev = get_imsm_dev(super, u->array);
struct imsm_map *map = get_imsm_map(dev, 0);
+ struct imsm_map *migr_map;
struct active_array *a;
struct imsm_disk *disk;
- __u32 status;
+ __u8 to_state;
struct dl *dl;
unsigned int found;
- int victim;
+ int failed;
+ int victim = get_imsm_disk_idx(dev, u->slot);
int i;
for (dl = super->disks; dl; dl = dl->next)
if (!dl) {
fprintf(stderr, "error: imsm_activate_spare passed "
- "an unknown disk (index: %d serial: %s)\n",
- u->dl->index, u->dl->serial);
+ "an unknown disk (index: %d)\n",
+ u->dl->index);
return;
}
super->updates_pending++;
+ /* count failures (excluding rebuilds and the victim)
+ * to determine map[0] state
+ */
+ failed = 0;
+ for (i = 0; i < map->num_members; i++) {
+ if (i == u->slot)
+ continue;
+ disk = get_imsm_disk(super, get_imsm_disk_idx(dev, i));
+ if (!disk || disk->status & FAILED_DISK)
+ failed++;
+ }
+
/* adding a pristine spare, assign a new index */
if (dl->index < 0) {
dl->index = super->anchor->num_disks;
super->anchor->num_disks++;
}
- victim = get_imsm_disk_idx(map, u->slot);
- map->disk_ord_tbl[u->slot] = __cpu_to_le32(dl->index);
disk = &dl->disk;
- status = __le32_to_cpu(disk->status);
- status |= CONFIGURED_DISK;
- status &= ~(SPARE_DISK | USABLE_DISK);
- disk->status = __cpu_to_le32(status);
+ disk->status |= CONFIGURED_DISK;
+ disk->status &= ~SPARE_DISK;
+
+ /* mark rebuild */
+ to_state = imsm_check_degraded(super, dev, failed);
+ map->map_state = IMSM_T_STATE_DEGRADED;
+ migrate(dev, to_state, MIGR_REBUILD);
+ migr_map = get_imsm_map(dev, 1);
+ set_imsm_ord_tbl_ent(map, u->slot, dl->index);
+ set_imsm_ord_tbl_ent(migr_map, u->slot, dl->index | IMSM_ORD_REBUILD);
/* count arrays using the victim in the metadata */
found = 0;
for (a = st->arrays; a ; a = a->next) {
dev = get_imsm_dev(super, a->info.container_member);
- map = get_imsm_map(dev, 0);
for (i = 0; i < map->num_members; i++)
- if (victim == get_imsm_disk_idx(map, i))
+ if (victim == get_imsm_disk_idx(dev, i))
found++;
}
- /* clear some flags if the victim is no longer being
+ /* delete the victim if it is no longer being
* utilized anywhere
*/
if (!found) {
- disk = get_imsm_disk(super, victim);
- status = __le32_to_cpu(disk->status);
- status &= ~(CONFIGURED_DISK | USABLE_DISK);
- disk->status = __cpu_to_le32(status);
- /* at this point the disk can be removed from the
- * metadata, however we need to guarantee that we do
- * not race with any manager thread routine that relies
- * on dl->index or map->disk_ord_tbl
- */
+ struct dl **dlp;
+
+ /* We know that 'manager' isn't touching anything,
+ * so it is safe to delete
+ */
+ for (dlp = &super->disks; *dlp; dlp = &(*dlp)->next)
+ if ((*dlp)->index == victim)
+ break;
+
+ /* victim may be on the missing list */
+ if (!*dlp)
+ for (dlp = &super->missing; *dlp; dlp = &(*dlp)->next)
+ if ((*dlp)->index == victim)
+ break;
+ imsm_delete(super, dlp, victim);
}
break;
}
* (FIX ME) notice that its update did not take hold.
*/
struct imsm_update_create_array *u = (void *) update->buf;
+ struct intel_dev *dv;
struct imsm_dev *dev;
struct imsm_map *map, *new_map;
unsigned long long start, end;
unsigned long long new_start, new_end;
int i;
- int overlap = 0;
+ struct disk_info *inf;
+ struct dl *dl;
/* handle racing creates: first come first serve */
if (u->dev_idx < mpb->num_raid_devs) {
dprintf("%s: subarray %d already defined\n",
__func__, u->dev_idx);
- return;
+ goto create_error;
}
/* check update is next in sequence */
if (u->dev_idx != mpb->num_raid_devs) {
dprintf("%s: can not create array %d expected index %d\n",
__func__, u->dev_idx, mpb->num_raid_devs);
- return;
+ goto create_error;
}
new_map = get_imsm_map(&u->dev, 0);
new_start = __le32_to_cpu(new_map->pba_of_lba0);
new_end = new_start + __le32_to_cpu(new_map->blocks_per_member);
+ inf = get_disk_info(u);
/* handle activate_spare versus create race:
* check to make sure that overlapping arrays do not include
end = start + __le32_to_cpu(map->blocks_per_member);
if ((new_start >= start && new_start <= end) ||
(start >= new_start && start <= new_end))
- overlap = 1;
- if (overlap && disks_overlap(map, new_map)) {
+ /* overlap */;
+ else
+ continue;
+
+ if (disks_overlap(super, i, u)) {
dprintf("%s: arrays overlap\n", __func__);
- return;
+ goto create_error;
}
}
- /* check num_members sanity */
- if (new_map->num_members > mpb->num_disks) {
- dprintf("%s: num_disks out of range\n", __func__);
- return;
- }
/* check that prepare update was successful */
if (!update->space) {
dprintf("%s: prepare update failed\n", __func__);
- return;
+ goto create_error;
+ }
+
+ /* check that all disks are still active before committing
+ * changes. FIXME: could we instead handle this by creating a
+ * degraded array? That's probably not what the user expects,
+ * so better to drop this update on the floor.
+ */
+ for (i = 0; i < new_map->num_members; i++) {
+ dl = serial_to_dl(inf[i].serial, super);
+ if (!dl) {
+ dprintf("%s: disk disappeared\n", __func__);
+ goto create_error;
+ }
}
super->updates_pending++;
- dev = update->space;
+
+ /* convert spares to members and fixup ord_tbl */
+ for (i = 0; i < new_map->num_members; i++) {
+ dl = serial_to_dl(inf[i].serial, super);
+ if (dl->index == -1) {
+ dl->index = mpb->num_disks;
+ mpb->num_disks++;
+ dl->disk.status |= CONFIGURED_DISK;
+ dl->disk.status &= ~SPARE_DISK;
+ }
+ set_imsm_ord_tbl_ent(new_map, i, dl->index);
+ }
+
+ dv = update->space;
+ dev = dv->dev;
update->space = NULL;
imsm_copy_dev(dev, &u->dev);
- super->dev_tbl[u->dev_idx] = dev;
+ dv->index = u->dev_idx;
+ dv->next = super->devlist;
+ super->devlist = dv;
mpb->num_raid_devs++;
- /* fix up flags, if arrays overlap then the drives can not be
- * spares
+ imsm_update_version_info(super);
+ break;
+ create_error:
+ /* mdmon knows how to release update->space, but not
+ * ((struct intel_dev *) update->space)->dev
*/
- for (i = 0; i < map->num_members; i++) {
- struct imsm_disk *disk;
- __u32 status;
-
- disk = get_imsm_disk(super, get_imsm_disk_idx(map, i));
- status = __le32_to_cpu(disk->status);
- status |= CONFIGURED_DISK;
- if (overlap)
- status &= ~SPARE_DISK;
- disk->status = __cpu_to_le32(status);
+ if (update->space) {
+ dv = update->space;
+ free(dv->dev);
}
break;
}
+ case update_add_disk:
+
+ /* we may be able to repair some arrays if disks are
+ * being added */
+ if (super->add) {
+ struct active_array *a;
+
+ super->updates_pending++;
+ for (a = st->arrays; a; a = a->next)
+ a->check_degraded = 1;
+ }
+ /* add some spares to the metadata */
+ while (super->add) {
+ struct dl *al;
+
+ al = super->add;
+ super->add = al->next;
+ al->next = super->disks;
+ super->disks = al;
+ dprintf("%s: added %x:%x\n",
+ __func__, al->major, al->minor);
+ }
+
+ break;
}
}
struct metadata_update *update)
{
/**
- * Allocate space to hold new disk entries, raid-device entries or a
- * new mpb if necessary. We currently maintain an mpb large enough to
- * hold 2 subarrays for the given number of disks. This may not be
- * sufficient when reshaping.
- *
- * FIX ME handle the reshape case.
- *
- * The monitor will be able to safely change super->mpb by arranging
- * for it to be freed in check_update_queue(). I.e. the monitor thread
- * will start using the new pointer and the manager can continue to use
- * the old value until check_update_queue() runs.
+ * Allocate space to hold new disk entries, raid-device entries or a new
+ * mpb if necessary. The manager synchronously waits for updates to
+ * complete in the monitor, so new mpb buffers allocated here can be
+ * integrated by the monitor thread without worrying about live pointers
+ * in the manager thread.
*/
enum imsm_update_type type = *(enum imsm_update_type *) update->buf;
+ struct intel_super *super = st->sb;
+ struct imsm_super *mpb = super->anchor;
+ size_t buf_len;
+ size_t len = 0;
switch (type) {
case update_create_array: {
struct imsm_update_create_array *u = (void *) update->buf;
- size_t len = sizeof_imsm_dev(&u->dev, 1);
+ struct intel_dev *dv;
+ struct imsm_dev *dev = &u->dev;
+ struct imsm_map *map = get_imsm_map(dev, 0);
+ struct dl *dl;
+ struct disk_info *inf;
+ int i;
+ int activate = 0;
+
+ inf = get_disk_info(u);
+ len = sizeof_imsm_dev(dev, 1);
+ /* allocate a new super->devlist entry */
+ dv = malloc(sizeof(*dv));
+ if (dv) {
+ dv->dev = malloc(len);
+ if (dv->dev)
+ update->space = dv;
+ else {
+ free(dv);
+ update->space = NULL;
+ }
+ }
- update->space = malloc(len);
+ /* count how many spares will be converted to members */
+ for (i = 0; i < map->num_members; i++) {
+ dl = serial_to_dl(inf[i].serial, super);
+ if (!dl) {
+ /* hmm maybe it failed?, nothing we can do about
+ * it here
+ */
+ continue;
+ }
+ if (count_memberships(dl, super) == 0)
+ activate++;
+ }
+ len += activate * sizeof(struct imsm_disk);
break;
default:
break;
}
}
- return;
+ /* check if we need a larger metadata buffer */
+ if (super->next_buf)
+ buf_len = super->next_len;
+ else
+ buf_len = super->len;
+
+ if (__le32_to_cpu(mpb->mpb_size) + len > buf_len) {
+ /* ok we need a larger buf than what is currently allocated
+ * if this allocation fails process_update will notice that
+ * ->next_len is set and ->next_buf is NULL
+ */
+ buf_len = ROUND_UP(__le32_to_cpu(mpb->mpb_size) + len, 512);
+ if (super->next_buf)
+ free(super->next_buf);
+
+ super->next_len = buf_len;
+ if (posix_memalign(&super->next_buf, buf_len, 512) != 0)
+ super->next_buf = NULL;
+ }
+}
+
+/* must be called while manager is quiesced */
+static void imsm_delete(struct intel_super *super, struct dl **dlp, int index)
+{
+ struct imsm_super *mpb = super->anchor;
+ struct dl *iter;
+ struct imsm_dev *dev;
+ struct imsm_map *map;
+ int i, j, num_members;
+ __u32 ord;
+
+ dprintf("%s: deleting device[%d] from imsm_super\n",
+ __func__, index);
+
+ /* shift all indexes down one */
+ for (iter = super->disks; iter; iter = iter->next)
+ if (iter->index > index)
+ iter->index--;
+ for (iter = super->missing; iter; iter = iter->next)
+ if (iter->index > index)
+ iter->index--;
+
+ for (i = 0; i < mpb->num_raid_devs; i++) {
+ dev = get_imsm_dev(super, i);
+ map = get_imsm_map(dev, 0);
+ num_members = map->num_members;
+ for (j = 0; j < num_members; j++) {
+ /* update ord entries being careful not to propagate
+ * ord-flags to the first map
+ */
+ ord = get_imsm_ord_tbl_ent(dev, j);
+
+ if (ord_to_idx(ord) <= index)
+ continue;
+
+ map = get_imsm_map(dev, 0);
+ set_imsm_ord_tbl_ent(map, j, ord_to_idx(ord - 1));
+ map = get_imsm_map(dev, 1);
+ if (map)
+ set_imsm_ord_tbl_ent(map, j, ord - 1);
+ }
+ }
+
+ mpb->num_disks--;
+ super->updates_pending++;
+ if (*dlp) {
+ struct dl *dl = *dlp;
+
+ *dlp = (*dlp)->next;
+ __free_imsm_disk(dl);
+ }
}
+#endif /* MDASSEMBLE */
struct superswitch super_imsm = {
#ifndef MDASSEMBLE
.detail_super = detail_super_imsm,
.brief_detail_super = brief_detail_super_imsm,
.write_init_super = write_init_super_imsm,
+ .validate_geometry = validate_geometry_imsm,
+ .add_to_super = add_to_super_imsm,
+ .detail_platform = detail_platform_imsm,
#endif
.match_home = match_home_imsm,
.uuid_from_super= uuid_from_super_imsm,
.load_super = load_super_imsm,
.init_super = init_super_imsm,
- .add_to_super = add_to_super_imsm,
.store_super = store_zero_imsm,
.free_super = free_super_imsm,
.match_metadata_desc = match_metadata_desc_imsm,
.container_content = container_content_imsm,
- .validate_geometry = validate_geometry_imsm,
.external = 1,
+ .name = "imsm",
+#ifndef MDASSEMBLE
/* for mdmon */
.open_new = imsm_open_new,
.load_super = load_super_imsm,
.activate_spare = imsm_activate_spare,
.process_update = imsm_process_update,
.prepare_update = imsm_prepare_update,
+#endif /* MDASSEMBLE */
};