Blame SOURCES/bz635995-data_corruption_during_activation_volume_marked_for_rebuild.patch

8ccba5
--- a/lib/activate/activate.c	
8ccba5
+++ a/lib/activate/activate.c	
8ccba5
@@ -370,7 +370,10 @@ get_dm_devs(struct raid_set *rs, int valid)
8ccba5
 	return ret + get_rds(rs, valid);
8ccba5
 }
8ccba5
 
8ccba5
-/* Retrieve number of drive to rebuild from metadata format handler. */
8ccba5
+/* Retrieve number of drive to rebuild from metadata format handler.
8ccba5
+ *
8ccba5
+ * Returns number of drive to rebuild or -1 if there is no drive to rebuild
8ccba5
+ */
8ccba5
 static int
8ccba5
 get_rebuild_drive(struct lib_context *lc, struct raid_set *rs,
8ccba5
 		  struct handler_info *info)
8ccba5
@@ -378,25 +381,23 @@ get_rebuild_drive(struct lib_context *lc, struct raid_set *rs,
8ccba5
 	/* Initialize drive to rebuild invalid. */
8ccba5
 	info->data.i32 = -1;
8ccba5
 
8ccba5
-	if (lc->options[LC_REBUILD_SET].opt) {
8ccba5
-		struct raid_dev *rd;
8ccba5
+	struct raid_dev *rd;
8ccba5
 
8ccba5
-		if (list_empty(&rs->devs))
8ccba5
-			LOG_ERR(lc, 0, "RAID set has no devices!");
8ccba5
+	if (list_empty(&rs->devs))
8ccba5
+		LOG_ERR(lc, 0, "RAID set has no devices!");
8ccba5
 
8ccba5
-		rd = list_entry(rs->devs.next, typeof(*rd), devs);
8ccba5
-		if (rd->fmt->metadata_handler) {
8ccba5
-			if (!rd->
8ccba5
-			    fmt->metadata_handler(lc, GET_REBUILD_DRIVE_NO,
8ccba5
-						  info, rs))
8ccba5
-				LOG_ERR(lc, 0, "Can't get rebuild drive #!");
8ccba5
-		} else
8ccba5
-			LOG_ERR(lc, 0,
8ccba5
-				"Can't rebuild w/o metadata_handler for %s",
8ccba5
-				rd->fmt->name);
8ccba5
-	}
8ccba5
+	rd = list_entry(rs->devs.next, typeof(*rd), devs);
8ccba5
+	if (rd->fmt->metadata_handler) {
8ccba5
+		if (!rd->
8ccba5
+		    fmt->metadata_handler(lc, GET_REBUILD_DRIVE_NO,
8ccba5
+					  info, rs))
8ccba5
+			LOG_ERR(lc, 0, "Can't get rebuild drive #!");
8ccba5
+	} else
8ccba5
+		LOG_ERR(lc, 0,
8ccba5
+			"Can't rebuild w/o metadata_handler for %s",
8ccba5
+			rd->fmt->name);
8ccba5
 
8ccba5
-	return 1;
8ccba5
+	return info->data.i32;
8ccba5
 }
8ccba5
 
8ccba5
 /* Return true if RAID set needs rebuilding. */
8ccba5
@@ -458,7 +459,7 @@ dm_raid1(struct lib_context *lc, char **table, struct raid_set *rs)
8ccba5
 	 */
8ccba5
 	need_sync = rs_need_sync(rs);
8ccba5
 	rebuild_drive.data.i32 = -1;
8ccba5
-	if (need_sync && !get_rebuild_drive(lc, rs, &rebuild_drive))
8ccba5
+	if (need_sync && get_rebuild_drive(lc, rs, &rebuild_drive) < 0)
8ccba5
 		return 0;
8ccba5
 
8ccba5
 	if (!_dm_raid1_bol(lc, table, rs, sectors, mirrors, need_sync))
8ccba5
@@ -540,7 +541,7 @@ _dm_raid45_bol(struct lib_context *lc, char **table, struct raid_set *rs,
8ccba5
 
8ccba5
 	/* Get drive as rebuild target. */
8ccba5
 	rebuild_drive.data.i32 = -1;
8ccba5
-	if (need_sync && !get_rebuild_drive(lc, rs, &rebuild_drive))
8ccba5
+	if (need_sync && get_rebuild_drive(lc, rs, &rebuild_drive) < 0)
8ccba5
 		return 0;
8ccba5
 
8ccba5
 	return p_fmt(lc, table, "0 %U %s core 2 %u %s %s 1 %u %u %d",
8ccba5
--- a/lib/format/ataraid/isw.c	
8ccba5
+++ a/lib/format/ataraid/isw.c	
8ccba5
@@ -1302,11 +1302,9 @@ isw_metadata_handler(struct lib_context *lc, enum handler_commands command,
8ccba5
 	case GET_REBUILD_DRIVE_NO:
8ccba5
 		rd = list_entry(rs->devs.next, typeof(*rd), devs);
8ccba5
 		isw = META(rd, isw);
8ccba5
-		idx = rd_idx_by_name(isw, lc->options[LC_REBUILD_SET].arg.str);
8ccba5
-		if (idx < 0)
8ccba5
-			return 0;
8ccba5
 
8ccba5
-		dev = raiddev(isw, idx);
8ccba5
+		/* Get disk to rebuild index form metadata stored on first disk */
8ccba5
+		dev = raiddev(isw, 0);
8ccba5
 		disk = isw->disk;
8ccba5
 
8ccba5
 		if (info) {