]> git.ipfire.org Git - thirdparty/mdadm.git/blob - mdassemble.c
Assemble/super0: allow non-in-sync devices to be assembled without complaint.
[thirdparty/mdadm.git] / mdassemble.c
1 /*
2 * mdassemble - assemble Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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@suse.de>
24 */
25
26 #include "mdadm.h"
27 #include "md_p.h"
28
29 /* from readme.c */
30 mapping_t pers[] = {
31 { "linear", -1},
32 { "raid0", 0},
33 { "0", 0},
34 { "stripe", 0},
35 { "raid1", 1},
36 { "1", 1},
37 { "mirror", 1},
38 { "raid4", 4},
39 { "4", 4},
40 { "raid5", 5},
41 { "5", 5},
42 { "multipath", -4},
43 { "mp", -4},
44 { "raid6", 6},
45 { "6", 6},
46 { "raid10", 10},
47 { "10", 10},
48 { NULL, 0}
49 };
50
51 #ifndef MDASSEMBLE_AUTO
52 /* from mdopen.c */
53 int open_mddev(char *dev, int report_errors/*unused*/)
54 {
55 int mdfd = open(dev, O_RDWR);
56 if (mdfd < 0)
57 fprintf(stderr, Name ": error opening %s: %s\n",
58 dev, strerror(errno));
59 else if (md_get_version(mdfd) <= 0) {
60 fprintf(stderr, Name ": %s does not appear to be an md device\n",
61 dev);
62 close(mdfd);
63 mdfd = -1;
64 }
65 return mdfd;
66 }
67 int create_mddev(char *dev, char *name, int autof/*unused*/, int trustworthy,
68 char *chosen)
69 {
70 return open_mddev(dev, 0);
71 }
72 #endif
73 int map_update(struct map_ent **mpp, int devnum, char *metadata,
74 int *uuid, char *path)
75 {
76 return 0;
77 }
78 struct map_ent *map_by_name(struct map_ent **mpp, char *name)
79 {
80 return NULL;
81 }
82
83 int rv;
84 int mdfd = -1;
85 int runstop = 0;
86 int readonly = 0;
87 int verbose = 0;
88 int force = 0;
89
90 int main(int argc, char *argv[]) {
91 mddev_ident_t array_list = conf_get_ident(NULL);
92 if (!array_list) {
93 fprintf(stderr, Name ": No arrays found in config file\n");
94 rv = 1;
95 } else
96 for (; array_list; array_list = array_list->next) {
97 mdu_array_info_t array;
98 if (strcasecmp(array_list->devname, "<ignore>") == 0)
99 continue;
100 mdfd = open_mddev(array_list->devname, 0);
101 if (mdfd >= 0 && ioctl(mdfd, GET_ARRAY_INFO, &array) == 0) {
102 rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */
103 continue;
104 }
105 if (mdfd >= 0)
106 close(mdfd);
107 rv |= Assemble(array_list->st, array_list->devname,
108 array_list, NULL, NULL,
109 readonly, runstop, NULL, NULL, 0,
110 verbose, force);
111 }
112 return rv;
113 }