#define CONFIGURED_DISK __cpu_to_le32(0x02) /* Member of some RaidDev */
#define FAILED_DISK __cpu_to_le32(0x04) /* Permanent failure */
__u32 status; /* 0xF0 - 0xF3 */
- __u32 owner_cfg_num; /* which config 0,1,2... owns this disk */
+ __u32 owner_cfg_num; /* which config 0,1,2... owns this disk */
__u32 total_blocks_hi; /* 0xF4 - 0xF5 total blocks hi */
#define IMSM_DISK_FILLERS 3
__u32 filler[IMSM_DISK_FILLERS]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
struct bbm_log_entry mapped_block_entries[BBM_LOG_MAX_ENTRIES];
} __attribute__ ((__packed__));
-
#ifndef MDASSEMBLE
static char *map_state_str[] = { "normal", "uninitialized", "degraded", "failed" };
#endif
* MIGR_REC_BUF_SIZE <= MIGR_REC_POSITION
*/
-
#define UNIT_SRC_NORMAL 0 /* Source data for curr_migr_unit must
* be recovered using srcMap */
#define UNIT_SRC_IN_CP_AREA 1 /* Source data for curr_migr_unit has
enum imsm_update_type type;
};
-
static const char *_sys_dev_type[] = {
[SYS_DEV_UNKNOWN] = "Unknown",
[SYS_DEV_SAS] = "SAS",
return NULL;
}
-
static int find_intel_hba_capability(int fd, struct intel_super *super,
char *devname);
}
qsort(rv, memberships, sizeof(*rv), cmp_extent);
- /* determine the start of the metadata
+ /* 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
/*******************************************************************************
* function: imsm_check_attributes
* Description: Function checks if features represented by attributes flags
- * are supported by mdadm.
+ * are supported by mdadm.
* Parameters:
* attributes - Attributes read from metadata
* Returns:
- * 0 - passed attributes contains unsupported features flags
- * 1 - all features are supported
+ * 0 - passed attributes contains unsupported features flags
+ * 1 - all features are supported
******************************************************************************/
static int imsm_check_attributes(__u32 attributes)
{
* 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.
return update_memory_size;
}
-
static void imsm_update_metadata_locally(struct supertype *st,
void *buf, int len);
static int imsm_count_failed(struct intel_super *super, struct imsm_dev *dev,
int look_in_map);
-
#ifndef MDASSEMBLE
static void manage_second_map(struct intel_super *super, struct imsm_dev *dev)
{
info->array.level = LEVEL_CONTAINER;
info->array.layout = 0;
info->array.md_minor = -1;
- info->array.ctime = 0; /* N/A for imsm */
+ info->array.ctime = 0; /* N/A for imsm */
info->array.utime = 0;
info->array.chunk_size = 0;
}
-
/* if 'first' is a spare promote it to a populated mpb with sec's
* family number
*/
if (i < sec->anchor->num_raid_devs) {
/* allocation failure */
free_devlist(first);
- fprintf(stderr, "imsm: failed to associate spare\n");
+ pr_err("imsm: failed to associate spare\n");
return 3;
}
first->anchor->num_raid_devs = sec->anchor->num_raid_devs;
if (__le32_to_cpu(mpb->bbm_log_size)) {
ptr = mpb;
ptr += mpb->mpb_size - __le32_to_cpu(mpb->bbm_log_size);
- }
+ }
return ptr;
}
for (s = super_list; s; s = s->next) {
if (family_num != s->anchor->family_num)
continue;
- fprintf(stderr, "Conflict, offlining family %#x on '%s'\n",
+ pr_err("Conflict, offlining family %#x on '%s'\n",
__le32_to_cpu(family_num), s->disks->devname);
}
}
champion = s;
if (conflict)
- fprintf(stderr, "Chose family %#x on '%s', "
+ pr_err("Chose family %#x on '%s', "
"assemble conflicts to new container with '--update=uuid'\n",
__le32_to_cpu(s->anchor->family_num), s->disks->devname);
return champion;
}
-
static int
get_sra_super_block(int fd, struct intel_super **super_list, char *devname, int *max, int keep_fd);
static int get_super_block(struct intel_super **super_list, char *devnm, char *devname,
get_devlist_super_block(struct md_list *devlist, struct intel_super **super_list,
int *max, int keep_fd);
-
static int load_super_imsm_all(struct supertype *st, int fd, void **sbp,
char *devname, struct md_list *devlist,
int keep_fd)
free_imsm(s);
}
-
if (err)
return err;
return 0;
}
-
static int
get_devlist_super_block(struct md_list *devlist, struct intel_super **super_list,
int *max, int keep_fd)
{
struct intel_super *super;
int rv;
+ int retry;
- if (!st->ignore_hw_compat && test_partition(fd))
+ if (test_partition(fd))
/* IMSM not allowed on partitions */
return 1;
}
rv = load_and_parse_mpb(fd, super, devname, 0);
+ /* retry the load if we might have raced against mdmon */
+ if (rv == 3) {
+ struct mdstat_ent *mdstat = mdstat_by_component(fd2devnm(fd));
+
+ if (mdstat && mdmon_running(mdstat->devnm) && getpid() != mdmon_pid(mdstat->devnm)) {
+ for (retry = 0; retry < 3; retry++) {
+ usleep(3000);
+ rv = load_and_parse_mpb(fd, super, devname, 0);
+ if (rv != 3)
+ break;
+ }
+ }
+
+ free_mdstat(mdstat);
+ }
+
if (rv) {
if (devname)
pr_err("Failed to load all information "
return 0;
}
-
static int remove_from_super_imsm(struct supertype *st, mdu_disk_info_t *dk)
{
struct intel_super *super = st->sb;
dd->next = super->disk_mgmt_list;
super->disk_mgmt_list = dd;
-
return 0;
}
spare->check_sum = __cpu_to_le32(sum);
if (store_imsm_mpb(d->fd, spare)) {
- fprintf(stderr, "%s: failed for device %d:%d %s\n",
+ pr_err("%s: failed for device %d:%d %s\n",
__func__, d->major, d->minor, strerror(errno));
return 1;
}
return 0;
}
-
static int create_array(struct supertype *st, int dev_idx)
{
size_t len;
int idx = get_imsm_disk_idx(dev, i, MAP_X);
disk = get_imsm_disk(super, idx);
+ if (!disk)
+ disk = get_imsm_missing(super, idx);
serialcpy(inf[i].serial, disk->serial);
}
append_metadata_update(st, u, len);
return 0;
}
-
static int
active_arrays_by_format(char *name, char* hba, struct md_list **devlist,
int dpa, int verbose)
continue;
}
-
dv = xcalloc(1, sizeof(*dv));
dv->devname = xstrdup(buf);
dv->next = devlist;
return count;
}
-
static int
count_volumes(char *hba, int dpa, int verbose)
{
return 0;
}
- if (chunk && (*chunk == 0 || *chunk == UnSet))
+ if (*chunk == 0 || *chunk == UnSet)
*chunk = imsm_default_chunk(super->orom);
- if (super->orom && chunk && !imsm_orom_has_chunk(super->orom, *chunk)) {
+ if (super->orom && !imsm_orom_has_chunk(super->orom, *chunk)) {
pr_vrb(": platform does not support a chunk size of: "
"%d\n", *chunk);
return 0;
return 0;
}
- if (super->orom && (super->orom->attr & IMSM_OROM_ATTR_2TB) == 0 && chunk &&
+ if (super->orom && (super->orom->attr & IMSM_OROM_ATTR_2TB) == 0 &&
(calc_array_size(level, raiddisks, layout, *chunk, size) >> 32) > 0) {
pr_vrb(": platform does not support a volume size over 2TB\n");
return 0;
return 1;
}
-/* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
+/* validate_geometry_imsm_volume - lifted from validate_geometry_ddf_bvd
* FIX ME add ahci details
*/
static int validate_geometry_imsm_volume(struct supertype *st, int level,
/* Must be a fresh device to add to a container */
return validate_geometry_imsm_container(st, level, layout,
raiddisks,
- chunk?*chunk:0,
+ *chunk,
size, data_offset,
dev, freesize,
verbose);
}
if (freesize)
return reserve_space(st, raiddisks, size,
- chunk?*chunk:0, freesize);
+ *chunk, freesize);
}
return 1;
}
sb_errors = 1;
}
-
/* count spare devices, not used in maps
*/
for (d = super->disks; d; d = d->next)
if (ord & IMSM_ORD_REBUILD)
recovery_start = 0;
- /*
+ /*
* if we skip some disks the array will be assmebled degraded;
* reset resync start to avoid a dirty-degraded
* situation when performing the intial sync
return rest;
}
-
static __u8 imsm_check_degraded(struct intel_super *super, struct imsm_dev *dev,
int failed, int look_in_map)
{
map = get_imsm_map(dev, look_in_map);
if (!failed)
- return map->map_state == IMSM_T_STATE_UNINITIALIZED ?
+ return map->map_state == IMSM_T_STATE_UNINITIALIZED ?
IMSM_T_STATE_UNINITIALIZED : IMSM_T_STATE_NORMAL;
switch (get_imsm_raid_level(map)) {
struct imsm_disk *disk;
/* reset the potential in-sync count on even-numbered
- * slots. num_copies is always 2 for imsm raid10
+ * slots. num_copies is always 2 for imsm raid10
*/
if ((i & 1) == 0)
insync = 2;
struct imsm_super *mpb = super->anchor;
if (atoi(inst) >= mpb->num_raid_devs) {
- fprintf(stderr, "%s: subarry index %d, out of range\n",
+ pr_err("%s: subarry index %d, out of range\n",
__func__, atoi(inst));
return -ENODEV;
}
__u8 map_state;
if (n > map->num_members)
- fprintf(stderr, "imsm: set_disk %d out of range 0..%d\n",
+ pr_err("imsm: set_disk %d out of range 0..%d\n",
n, map->num_members - 1);
if (n < 0)
return dl;
}
-
static int imsm_rebuild_allowed(struct supertype *cont, int dev_idx, int failed)
{
struct imsm_dev *dev2;
dl = imsm_add_spare(super, i, a, 1, rv);
if (!dl)
continue;
-
+
/* found a usable disk with enough space */
di = xcalloc(1, sizeof(*di));
* disk_ord_tbl for the array
*/
mu = xmalloc(sizeof(*mu));
- mu->buf = xcalloc(num_spares,
+ mu->buf = xcalloc(num_spares,
sizeof(struct imsm_update_activate_spare));
mu->space = NULL;
mu->space_list = NULL;
return 0;
}
-
static struct dl *get_disk_super(struct intel_super *super, int major, int minor)
{
struct dl *dl = NULL;
return check_degraded;
}
-
static int apply_reshape_migration_update(struct imsm_update_reshape_migration *u,
struct intel_super *super,
void ***space_list)
return ret_val;
}
-
static int apply_update_activate_spare(struct imsm_update_activate_spare *u,
struct intel_super *super,
struct active_array *active_array)
break;
if (!dl) {
- fprintf(stderr, "error: imsm_activate_spare passed "
+ pr_err("error: imsm_activate_spare passed "
"an unknown disk (index: %d)\n",
u->dl->index);
return 0;
* the arrays for general migration and convert selected spares
* into active devices.
* update_activate_spare - a spare device has replaced a failed
- * device in an array, update the disk_ord_tbl. If this disk is
- * present in all member arrays then also clear the SPARE_DISK
- * flag
+ * device in an array, update the disk_ord_tbl. If this disk is
+ * present in all member arrays then also clear the SPARE_DISK
+ * flag
* update_create_array
* update_kill_array
* update_rename_array
break;
}
case update_activate_spare: {
- struct imsm_update_activate_spare *u = (void *) update->buf;
+ struct imsm_update_activate_spare *u = (void *) update->buf;
if (apply_update_activate_spare(u, super, st->arrays))
super->updates_pending++;
break;
}
case update_add_remove_disk: {
/* we may be able to repair some arrays if disks are
- * being added, check teh status of add_remove_disk
+ * being added, check the status of add_remove_disk
* if discs has been added.
*/
if (add_remove_disk_update(super)) {
break;
}
default:
- fprintf(stderr, "error: unsuported process update type:"
+ pr_err("error: unsuported process update type:"
"(type: %d)\n", type);
}
}
static struct mdinfo *get_spares_for_grow(struct supertype *st);
-static void imsm_prepare_update(struct supertype *st,
- struct metadata_update *update)
+static int imsm_prepare_update(struct supertype *st,
+ struct metadata_update *update)
{
/**
* Allocate space to hold new disk entries, raid-device entries or a new
* 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;
+ enum imsm_update_type type;
struct intel_super *super = st->sb;
struct imsm_super *mpb = super->anchor;
size_t buf_len;
size_t len = 0;
+ if (update->len < (int)sizeof(type))
+ return 0;
+
+ type = *(enum imsm_update_type *) update->buf;
+
switch (type) {
case update_general_migration_checkpoint:
+ if (update->len < (int)sizeof(struct imsm_update_general_migration_checkpoint))
+ return 0;
dprintf("imsm: prepare_update() "
"for update_general_migration_checkpoint called\n");
break;
case update_takeover: {
struct imsm_update_takeover *u = (void *)update->buf;
+ if (update->len < (int)sizeof(*u))
+ return 0;
if (u->direction == R0_TO_R10) {
void **tail = (void **)&update->space_list;
struct imsm_dev *dev = get_imsm_dev(super, u->subarray);
struct intel_dev *dl;
void **space_tail = (void**)&update->space_list;
+ if (update->len < (int)sizeof(*u))
+ return 0;
+
dprintf("imsm: imsm_prepare_update() for update_reshape\n");
for (dl = super->devlist; dl; dl = dl->next) {
void *s;
int current_level = -1;
+ if (update->len < (int)sizeof(*u))
+ return 0;
+
dprintf("imsm: imsm_prepare_update() for update_reshape\n");
/* add space for bigger array in update
break;
}
case update_size_change: {
+ if (update->len < (int)sizeof(struct imsm_update_size_change))
+ return 0;
+ break;
+ }
+ case update_activate_spare: {
+ if (update->len < (int)sizeof(struct imsm_update_activate_spare))
+ return 0;
break;
}
case update_create_array: {
int i;
int activate = 0;
+ if (update->len < (int)sizeof(*u))
+ return 0;
+
inf = get_disk_info(u);
len = sizeof_imsm_dev(dev, 1);
/* allocate a new super->devlist entry */
}
len += activate * sizeof(struct imsm_disk);
break;
- default:
+ }
+ case update_kill_array: {
+ if (update->len < (int)sizeof(struct imsm_update_kill_array))
+ return 0;
break;
}
+ case update_rename_array: {
+ if (update->len < (int)sizeof(struct imsm_update_rename_array))
+ return 0;
+ break;
+ }
+ case update_add_remove_disk:
+ /* no update->len needed */
+ break;
+ default:
+ return 0;
}
/* check if we need a larger metadata buffer */
else
super->next_buf = NULL;
}
+ return 1;
}
/* must be called while manager is quiesced */
}
}
-
/*******************************************************************************
* Function: open_backup_targets
* Description: Function opens file descriptors for all devices given in
sd->disk.minor, 1);
raid_fds[sd->disk.raid_disk] = dev_open(dn, O_RDWR);
if (raid_fds[sd->disk.raid_disk] < 0) {
- fprintf(stderr, "cannot open component\n");
+ pr_err("cannot open component\n");
continue;
}
opened++;
imsm_get_allowed_degradation(info->new_level,
raid_disks,
super, dev)) {
- fprintf(stderr, "Not enough disks can be opened.\n");
+ pr_err("Not enough disks can be opened.\n");
close_targets(raid_fds, raid_disks);
return -2;
}
return 0;
}
+/*******************************************************************************
+ * Function: validate_container_imsm
+ * Description: This routine validates container after assemble,
+ * eg. if devices in container are under the same controller.
+ *
+ * Parameters:
+ * info : linked list with info about devices used in array
+ * Returns:
+ * 1 : HBA mismatch
+ * 0 : Success
+ ******************************************************************************/
+int validate_container_imsm(struct mdinfo *info)
+{
+ if (!check_env("IMSM_NO_PLATFORM")) {
+ struct sys_dev *idev;
+ struct mdinfo *dev;
+ char *hba_path = NULL;
+ char *dev_path = devt_to_devpath(makedev(info->disk.major,
+ info->disk.minor));
+
+ for (idev = find_intel_devices(); idev; idev = idev->next) {
+ if (strstr(dev_path, idev->path)) {
+ hba_path = idev->path;
+ break;
+ }
+ }
+ free(dev_path);
+
+ if (hba_path) {
+ for (dev = info->next; dev; dev = dev->next) {
+ if (!devt_attached_to_hba(makedev(dev->disk.major,
+ dev->disk.minor), hba_path)) {
+ pr_err("WARNING - IMSM container assembled with disks under different HBAs!\n"
+ " This operation is not supported and can lead to data loss.\n");
+ return 1;
+ }
+ }
+ }
+ }
+ return 0;
+}
#ifndef MDASSEMBLE
/*******************************************************************************
* Function: init_migr_record_imsm
migr_rec->post_migr_vol_cap = dev->size_low;
migr_rec->post_migr_vol_cap_hi = dev->size_high;
-
/* Find the smallest dev */
for (sd = info->devs ; sd ; sd = sd->next) {
sprintf(nm, "%d:%d", sd->disk.major, sd->disk.minor);
char *drv=NULL;
struct stat st;
- strncpy(disk_path, disk_by_path, PATH_MAX - 1);
+ strcpy(disk_path, disk_by_path);
strncat(disk_path, path, PATH_MAX - strlen(disk_path) - 1);
if (stat(disk_path, &st) == 0) {
struct sys_dev* hba;
drv = "isci";
else if (hba && hba->type == SYS_DEV_SATA)
drv = "ahci";
- else
+ else
drv = "unknown";
dprintf("path: %s hba: %s attached: %s\n",
path, (hba) ? hba->path : "NULL", drv);
/* Function: get_spares_for_grow
* Description: Allocates memory and creates list of spare devices
- * avaliable in container. Checks if spare drive size is acceptable.
+ * avaliable in container. Checks if spare drive size is acceptable.
* Parameters: Pointer to the supertype structure
* Returns: Pointer to the list of spare devices (mdinfo structure) on success,
- * NULL if fail
+ * NULL if fail
*/
static struct mdinfo *get_spares_for_grow(struct supertype *st)
{
return 0;
}
-
/******************************************************************************
* function: imsm_create_metadata_update_for_size_change()
* Creates update for IMSM array for array size change.
mu.space = NULL;
mu.space_list = NULL;
mu.next = NULL;
- imsm_prepare_update(st, &mu);
- imsm_process_update(st, &mu);
+ if (imsm_prepare_update(st, &mu))
+ imsm_process_update(st, &mu);
while (mu.space_list) {
void **space = mu.space_list;
/***************************************************************************
* Function: imsm_analyze_change
* Description: Function analyze change for single volume
-* and validate if transition is supported
+* and validate if transition is supported
* Parameters: Geometry parameters, supertype structure,
* metadata change direction (apply/rollback)
* Returns: Operation type code on success, -1 if fail
dprintf("imsm: info: Volume operation\n");
/* find requested device */
while (dev) {
- char *devnm =
+ char *devnm =
imsm_find_array_devnm_by_subdev(
dev->index, st->container_devnm);
if (devnm && strcmp(devnm, geo.devnm) == 0)
******************************************************************************/
int wait_for_reshape_imsm(struct mdinfo *sra, int ndata)
{
- int fd = sysfs_get_fd(sra, NULL, "reshape_position");
+ int fd = sysfs_get_fd(sra, NULL, "sync_completed");
unsigned long long completed;
/* to_complete : new sync_max position */
unsigned long long to_complete = sra->reshape_progress;
return 0;
}
- if (completed > to_complete) {
+ if (completed > position_to_set) {
dprintf("imsm: wait_for_reshape_imsm() "
"wrong next position to set %llu (%llu)\n",
- to_complete, completed);
+ to_complete, position_to_set);
close(fd);
return -1;
}
do {
char action[20];
- fd_set rfds;
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
- select(fd+1, &rfds, NULL, NULL, NULL);
+ sysfs_wait(fd, NULL);
if (sysfs_get_str(sra, NULL, "sync_action",
action, 20) > 0 &&
strncmp(action, "reshape", 7) != 0)
close(fd);
return 1;
}
- } while (completed < to_complete);
+ } while (completed < position_to_set);
close(fd);
return 0;
dprintf("wait_for_reshape_imsm returned error!\n");
goto abort;
}
+ if (sigterm)
+ goto abort;
if (save_checkpoint_imsm(st, sra, UNIT_SRC_NORMAL) == 1) {
/* ignore error == 2, this can mean end of reshape here
return ret_val;
}
+
#endif /* MDASSEMBLE */
struct superswitch super_imsm = {
.free_super = free_super_imsm,
.match_metadata_desc = match_metadata_desc_imsm,
.container_content = container_content_imsm,
-
+ .validate_container = validate_container_imsm,
.external = 1,
.name = "imsm",