]> git.ipfire.org Git - thirdparty/mdadm.git/blame - mdassemble.c
imsm: enforce "all member disks must be members of all arrays"
[thirdparty/mdadm.git] / mdassemble.c
CommitLineData
98c6faba
NB
1/*
2 * mdassemble - assemble Linux "md" devices aka RAID arrays.
3 *
4f589ad0 4 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
98c6faba
NB
5 * Copyright (C) 2003 Luca Berra <bluca@vodka.it>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * Author: Neil Brown
23 * Email: <neilb@cse.unsw.edu.au>
24 * Paper: Neil Brown
25 * School of Computer Science and Engineering
26 * The University of New South Wales
27 * Sydney, 2052
28 * Australia
29 */
30
31#include "mdadm.h"
32#include "md_p.h"
33
34/* from readme.c */
35mapping_t pers[] = {
36 { "linear", -1},
37 { "raid0", 0},
38 { "0", 0},
39 { "stripe", 0},
40 { "raid1", 1},
41 { "1", 1},
42 { "mirror", 1},
43 { "raid4", 4},
44 { "4", 4},
45 { "raid5", 5},
46 { "5", 5},
47 { "multipath", -4},
48 { "mp", -4},
b5e64645
NB
49 { "raid6", 6},
50 { "6", 6},
51 { "raid10", 10},
52 { "10", 10},
98c6faba
NB
53 { NULL, 0}
54};
55
b5e64645 56#ifndef MDASSEMBLE_AUTO
b56c3630 57/* from mdopen.c */
7f91af49 58int open_mddev(char *dev, int report_errors/*unused*/)
98c6faba 59{
fb97b4d6 60 int mdfd = open(dev, O_RDWR);
98c6faba
NB
61 if (mdfd < 0)
62 fprintf(stderr, Name ": error opening %s: %s\n",
63 dev, strerror(errno));
64 else if (md_get_version(mdfd) <= 0) {
65 fprintf(stderr, Name ": %s does not appear to be an md device\n",
66 dev);
67 close(mdfd);
68 mdfd = -1;
69 }
70 return mdfd;
71}
69207ff6
N
72int create_mddev(char *dev, char *name, int autof/*unused*/, int trustworthy,
73 char *chosen)
7f91af49
N
74{
75 return open_mddev(dev, 0);
76}
97590376
N
77int sysfs_uevent(struct mdinfo *info, char *event)
78{
79 return 0;
80}
b5e64645 81#endif
a04d5763
N
82int map_update(struct map_ent **mpp, int devnum, char *metadata,
83 int *uuid, char *path)
84{
85 return 0;
86}
f2e55ecc
N
87struct map_ent *map_by_name(struct map_ent **mpp, char *name)
88{
89 return NULL;
90}
98c6faba 91
98c6faba
NB
92int rv;
93int mdfd = -1;
94int runstop = 0;
95int readonly = 0;
96int verbose = 0;
97int force = 0;
98
b56c3630 99int main(int argc, char *argv[]) {
8aec876d 100 mddev_ident_t array_list = conf_get_ident(NULL);
98c6faba
NB
101 if (!array_list) {
102 fprintf(stderr, Name ": No arrays found in config file\n");
103 rv = 1;
104 } else
105 for (; array_list; array_list = array_list->next) {
106 mdu_array_info_t array;
7f91af49
N
107 mdfd = open_mddev(array_list->devname, 0);
108 if (mdfd >= 0 && ioctl(mdfd, GET_ARRAY_INFO, &array) == 0) {
435d4ebb 109 rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */
7f91af49 110 continue;
435d4ebb 111 }
7f91af49
N
112 if (mdfd >= 0)
113 close(mdfd);
114 rv |= Assemble(array_list->st, array_list->devname,
115 array_list, NULL, NULL,
116 readonly, runstop, NULL, NULL, verbose, force);
98c6faba 117 }
b56c3630 118 return rv;
98c6faba 119}