]> git.ipfire.org Git - thirdparty/mdadm.git/blob - mdassemble.c
sysfs: Avoid if and return on the same line
[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 char const Name[] = "mdassemble";
30
31 #ifndef MDASSEMBLE_AUTO
32 /* from mdopen.c */
33 int open_mddev(char *dev, int report_errors/*unused*/)
34 {
35 int mdfd = open(dev, O_RDWR);
36 if (mdfd < 0)
37 pr_err("error opening %s: %s\n",
38 dev, strerror(errno));
39 else if (md_get_version(mdfd) <= 0) {
40 pr_err("%s does not appear to be an md device\n",
41 dev);
42 close(mdfd);
43 mdfd = -1;
44 }
45 return mdfd;
46 }
47 int create_mddev(char *dev, char *name, int autof/*unused*/, int trustworthy,
48 char *chosen)
49 {
50 return open_mddev(dev, 0);
51 }
52 #endif
53
54 int rv;
55 int mdfd = -1;
56
57 int main(int argc, char *argv[])
58 {
59 struct mddev_ident *array_list = conf_get_ident(NULL);
60 struct context c = { .freeze_reshape = 1 };
61 if (!array_list) {
62 pr_err("No arrays found in config file\n");
63 rv = 1;
64 } else
65 for (; array_list; array_list = array_list->next) {
66 mdu_array_info_t array;
67 if (strcasecmp(array_list->devname, "<ignore>") == 0)
68 continue;
69 mdfd = open_mddev(array_list->devname, 0);
70 if (mdfd >= 0 && ioctl(mdfd, GET_ARRAY_INFO, &array) == 0) {
71 rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */
72 continue;
73 }
74 if (mdfd >= 0)
75 close(mdfd);
76 rv |= Assemble(array_list->st, array_list->devname,
77 array_list, NULL, &c);
78 }
79 return rv;
80 }