return (a*1000000)+(b*1000)+c;
}
+#ifndef MDASSEMBLE
int mdadm_version(char *version)
{
int a, b, c;
return (a*1000000)+(b*1000)+c;
}
-#ifndef MDASSEMBLE
long long parse_size(char *size)
{
/* parse 'size' which should be a number optionally
return 1;
}
+int test_partition_from_id(dev_t id)
+{
+ char buf[20];
+ int fd, rv;
+
+ sprintf(buf, "%d:%d", major(id), minor(id));
+ fd = dev_open(buf, O_RDONLY);
+ if (fd < 0)
+ return -1;
+ rv = test_partition(fd);
+ close(fd);
+ return rv;
+}
int enough(int level, int raid_disks, int layout, int clean,
char *avail, int avail_disks)
}
-const int uuid_match_any[4] = { ~0, ~0, ~0, ~0 };
+const int uuid_zero[4] = { 0, 0, 0, 0 };
+
int same_uuid(int a[4], int b[4], int swapuuid)
{
- if (memcmp(a, uuid_match_any, sizeof(int[4])) == 0 ||
- memcmp(b, uuid_match_any, sizeof(int[4])) == 0)
- return 1;
-
if (swapuuid) {
/* parse uuids are hostendian.
* uuid's from some superblocks are big-ending
}
#endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
-int dev_size_from_id(unsigned int id, unsigned long long *size)
+int dev_size_from_id(dev_t id, unsigned long long *size)
{
char buf[20];
int fd;
for (ent = mdstat; ent; ent = ent->next)
if (is_container_member(ent, container))
- if (!subarray ||
- strcmp(to_subarray(ent, container), subarray) == 0)
+ if (strcmp(to_subarray(ent, container), subarray) == 0)
break;
free_mdstat(mdstat);
return ent != NULL;
}
-int is_container_active(char *container)
-{
- return is_subarray_active(NULL, container);
-}
-
/* open_subarray - opens a subarray in a container
* @dev: container device name
* @st: empty supertype
return recovery_start;
}
-char *devnum2devname(int num)
+void fmt_devname(char *name, int num)
{
- char name[100];
if (num >= 0)
sprintf(name, "md%d", num);
else
sprintf(name, "md_d%d", -1-num);
+}
+
+char *devnum2devname(int num)
+{
+ char name[100];
+ fmt_devname(name,num);
return strdup(name);
}
link[n] = 0;
cp = strrchr(link, '/');
if (cp) *cp = 0;
- cp = strchr(link, '/');
+ cp = strrchr(link, '/');
if (cp && strncmp(cp, "/md", 3) == 0)
return devname2devnum(cp+1);
}
mu->buf = buf;
mu->len = len;
mu->space = NULL;
+ mu->space_list = NULL;
mu->next = NULL;
*st->update_tail = mu;
st->update_tail = &mu->next;
unsigned int __invalid_size_argument_for_IOC = 0;
#endif
+int experimental(void)
+{
+ if (check_env("MDADM_EXPERIMENTAL"))
+ return 1;
+ else {
+ fprintf(stderr, Name ": To use this feature MDADM_EXPERIMENTAL enviroment variable has to defined.\n");
+ return 0;
+ }
+}
+
+/* Pick all spares matching given criteria from a container
+ * if min_size == 0 do not check size
+ * if domlist == NULL do not check domains
+ * if spare_group given add it to domains of each spare
+ * metadata allows to test domains using metadata of destination array */
+struct mdinfo *container_choose_spares(struct supertype *st,
+ unsigned long long min_size,
+ struct domainlist *domlist,
+ char *spare_group,
+ const char *metadata, int get_one)
+{
+ struct mdinfo *d, **dp, *disks = NULL;
+
+ /* get list of all disks in container */
+ if (st->ss->getinfo_super_disks)
+ disks = st->ss->getinfo_super_disks(st);
+
+ if (!disks)
+ return disks;
+ /* find spare devices on the list */
+ dp = &disks->devs;
+ disks->array.spare_disks = 0;
+ while (*dp) {
+ int found = 0;
+ d = *dp;
+ if (d->disk.state == 0) {
+ /* check if size is acceptable */
+ unsigned long long dev_size;
+ dev_t dev = makedev(d->disk.major,d->disk.minor);
+
+ if (!min_size ||
+ (dev_size_from_id(dev, &dev_size) &&
+ dev_size >= min_size))
+ found = 1;
+ /* check if domain matches */
+ if (found && domlist) {
+ struct dev_policy *pol = devnum_policy(dev);
+ if (spare_group)
+ pol_add(&pol, pol_domain,
+ spare_group, NULL);
+ if (domain_test(domlist, pol, metadata) != 1)
+ found = 0;
+ dev_policy_free(pol);
+ }
+ }
+ if (found) {
+ dp = &d->next;
+ disks->array.spare_disks++;
+ if (get_one) {
+ sysfs_free(*dp);
+ d->next = NULL;
+ }
+ } else {
+ *dp = d->next;
+ d->next = NULL;
+ sysfs_free(d);
+ }
+ }
+ return disks;
+}