]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - policy.c
Monitor: include containers in scan mode
[thirdparty/mdadm.git] / policy.c
index 0bc3c4525cd8b98e2292f0ed39893ae70905a63a..cc126949a7f98ae8c675b773028c222c9c3fd5d1 100644 (file)
--- a/policy.c
+++ b/policy.c
@@ -519,6 +519,8 @@ static enum policy_action map_act(char *act)
                return act_re_add;
        if (strcmp(act, "spare") == 0)
                return act_spare;
+       if (strcmp(act, "spare-same-slot") == 0)
+               return act_spare_same_slot;
        if (strcmp(act, "force-spare") == 0)
                return act_force_spare;
        return act_err;
@@ -644,3 +646,70 @@ void domain_free(struct domainlist *dl)
                free(head);
        }
 }
+
+/*
+ * same-path policy.
+ * Some policy decisions are guided by knowledge of which
+ * array previously owned the device at a given physical location (path).
+ * When removing a device from an array we might record the array against
+ * the path, and when finding a new device, we might look for which
+ * array previously used that path.
+ *
+ * The 'array' is described by a map_ent, and the path by a the disk in an
+ * mdinfo, or a string.
+ */
+
+void policy_save_path(char *id_path, struct map_ent *array)
+{
+       char path[PATH_MAX];
+       FILE *f = NULL;
+
+       if (mkdir(FAILED_SLOTS_DIR, S_IRWXU) < 0 && errno != EEXIST) {
+               fprintf(stderr, Name ": can't create file to save path "
+                       "to old disk: %s\n", strerror(errno));
+               return;
+       }
+
+       snprintf(path, PATH_MAX, FAILED_SLOTS_DIR "/%s", id_path);
+       f = fopen(path, "w");
+       if (!f) {
+               fprintf(stderr, Name ": can't create file to"
+                       " save path to old disk: %s\n",
+                       strerror(errno));
+               return;
+       }
+
+       if (fprintf(f, "%s %08x:%08x:%08x:%08x\n",
+                   array->metadata,
+                   array->uuid[0], array->uuid[1],
+                   array->uuid[2], array->uuid[3]) <= 0)
+               fprintf(stderr, Name ": Failed to write to "
+                       "<id_path> cookie\n");
+
+       fclose(f);
+}
+
+int policy_check_path(struct mdinfo *disk, struct map_ent *array)
+{
+       char path[PATH_MAX];
+       FILE *f = NULL;
+       char *id_path = disk_path(disk);
+       int rv;
+
+       if (!id_path)
+               return 0;
+
+       snprintf(path, PATH_MAX, FAILED_SLOTS_DIR "/%s", id_path);
+       f = fopen(path, "r");
+       if (!f)
+               return 0;
+
+       rv = fscanf(f, " %s %x:%x:%x:%x\n",
+                   array->metadata,
+                   array->uuid,
+                   array->uuid+1,
+                   array->uuid+2,
+                   array->uuid+3);
+       fclose(f);
+       return rv == 5;
+}