+
+int hw_setup_raid(struct hw_destination* dest) {
+ char* cmd = NULL;
+
+ assert(dest->is_raid);
+
+ asprintf(&cmd, "echo \"y\" | /sbin/mdadm --create --verbose --metadata=0.9 %s", dest->path);
+
+ switch (dest->raid_level) {
+ case 1:
+ asprintf(&cmd, "%s --level=1 --raid-devices=2", cmd);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ if (dest->disk1) {
+ asprintf(&cmd, "%s %s", cmd, dest->disk1->path);
+ }
+
+ if (dest->disk2) {
+ asprintf(&cmd, "%s %s", cmd, dest->disk2->path);
+ }
+
+ int r = mysystem(cmd);
+ free(cmd);
+
+ // Wait a moment until the device has been properly brought up
+ if (r == 0) {
+ unsigned int counter = 10;
+ while (counter-- > 0) {
+ sleep(1);
+
+ if (access(dest->path, R_OK) == 0)
+ break;
+ }
+ }
+
+ return r;
+}
+
+int hw_stop_all_raid_arrays() {
+ return mysystem("/sbin/mdadm --stop --scan");
+}