]>
Commit | Line | Data |
---|---|---|
98c6faba NB |
1 | /* |
2 | * mdassemble - assemble Linux "md" devices aka RAID arrays. | |
3 | * | |
e736b623 | 4 | * Copyright (C) 2001-2009 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 | |
e736b623 | 23 | * Email: <neilb@suse.de> |
98c6faba NB |
24 | */ |
25 | ||
26 | #include "mdadm.h" | |
27 | #include "md_p.h" | |
28 | ||
e4fa82a8 N |
29 | char const Name[] = "mdassemble"; |
30 | ||
b5e64645 | 31 | #ifndef MDASSEMBLE_AUTO |
b56c3630 | 32 | /* from mdopen.c */ |
7f91af49 | 33 | int open_mddev(char *dev, int report_errors/*unused*/) |
98c6faba | 34 | { |
1c959111 | 35 | struct mdu_array_info_s array; |
f71d2b8f | 36 | int mdfd = open(dev, O_RDONLY); |
98c6faba | 37 | if (mdfd < 0) |
1c959111 JS |
38 | pr_err("error opening %s: %s\n", dev, strerror(errno)); |
39 | else if (md_get_array_info(mdfd, &array) != 0) { | |
40 | pr_err("%s does not appear to be an md device\n", dev); | |
98c6faba NB |
41 | close(mdfd); |
42 | mdfd = -1; | |
43 | } | |
44 | return mdfd; | |
45 | } | |
69207ff6 N |
46 | int create_mddev(char *dev, char *name, int autof/*unused*/, int trustworthy, |
47 | char *chosen) | |
7f91af49 N |
48 | { |
49 | return open_mddev(dev, 0); | |
50 | } | |
b5e64645 | 51 | #endif |
98c6faba | 52 | |
98c6faba NB |
53 | int rv; |
54 | int mdfd = -1; | |
98c6faba | 55 | |
4977146a N |
56 | int main(int argc, char *argv[]) |
57 | { | |
fa56eddb | 58 | struct mddev_ident *array_list = conf_get_ident(NULL); |
4977146a | 59 | struct context c = { .freeze_reshape = 1 }; |
98c6faba | 60 | if (!array_list) { |
e7b84f9d | 61 | pr_err("No arrays found in config file\n"); |
98c6faba NB |
62 | rv = 1; |
63 | } else | |
64 | for (; array_list; array_list = array_list->next) { | |
65 | mdu_array_info_t array; | |
112cace6 N |
66 | if (strcasecmp(array_list->devname, "<ignore>") == 0) |
67 | continue; | |
7f91af49 | 68 | mdfd = open_mddev(array_list->devname, 0); |
9cd39f01 | 69 | if (mdfd >= 0 && md_get_array_info(mdfd, &array) == 0) { |
435d4ebb | 70 | rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */ |
7f91af49 | 71 | continue; |
435d4ebb | 72 | } |
7f91af49 N |
73 | if (mdfd >= 0) |
74 | close(mdfd); | |
75 | rv |= Assemble(array_list->st, array_list->devname, | |
4977146a | 76 | array_list, NULL, &c); |
98c6faba | 77 | } |
b56c3630 | 78 | return rv; |
98c6faba | 79 | } |