mdadm/Build.c

207 lines
5.6 KiB
C
Raw Normal View History

2001-06-08 04:36:23 +02:00
/*
2002-03-08 01:03:52 +01:00
* mdadm - manage Linux "md" devices aka RAID arrays.
2001-06-08 04:36:23 +02:00
*
* Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
2001-06-08 04:36:23 +02:00
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Neil Brown
* Email: <neilb@suse.de>
2001-06-08 04:36:23 +02:00
*/
2002-03-08 01:03:52 +01:00
#include "mdadm.h"
2001-06-08 04:36:23 +02:00
int Build(char *mddev, struct mddev_dev *devlist,
struct shape *s, struct context *c)
2001-06-08 04:36:23 +02:00
{
2001-07-26 09:00:09 +02:00
/* Build a linear or raid0 arrays without superblocks
* We cannot really do any checks, we just do it.
* For md_version < 0.90.0, we call REGISTER_DEV
* with the device numbers, and then
* START_MD giving the "geometry"
* geometry is 0xpp00cc
* where pp is personality: 1==linear, 2=raid0
* cc = chunk size factor: 0==4k, 1==8k etc.
*/
int i;
dev_t rdev;
From paul.clements@steeleye.com Thu May 19 11:09:55 2005 X-VM-v5-Data: ([nil nil nil nil t nil nil nil nil] ["2589" "Wednesday" "18" "May" "2005" "21:09:47" "-0400" "Paul Clements" "paul.clements@steeleye.com" nil "93" "[PATCH 1/1] mdadm 2.0 devel: fix bitmap size calculation and allow \"missing\" device in Build command" "^From:" "neilb@cse.unsw.edu.au" "neilb@cse.unsw.edu.au" "5" nil nil nil nil nil nil nil nil nil] nil) Return-Path: <paul.clements@steeleye.com> Received: From smtp-dist.unsw.edu.au ([149.171.97.16] == smtp-dist-01.services.comms.unsw.EDU.AU) (for <neilb@cse.unsw.edu.au>) By note With Smtp ; Thu, 19 May 2005 11:09:55 +1000 Received: from localhost (avspam-03.services.comms.unsw.edu.au [149.171.100.18]) by smtp-dist.unsw.edu.au (8.13.1/8.13.1) with ESMTP id j4J19t05017496 for <VRT+EFNJ=JQ=cse.unsw.edu.au=neilb@cse.unsw.edu.au>; Thu, 19 May 2005 11:09:55 +1000 (EST) Received: from note.orchestra.cse.unsw.EDU.AU (note.orchestra.cse.unsw.EDU.AU [129.94.242.24]) by smtp.unsw.edu.au (8.13.1/8.13.1) with ESMTP id j4J19qEL010258 for <VRT+EFNJ=JQ=cse.unsw.edu.au=neilb@cse.unsw.edu.au>; Thu, 19 May 2005 11:09:53 +1000 (EST) Received: From hancock.sc.steeleye.com ([209.192.50.48] == stat16.steeleye.com) (for <neilb@cse.unsw.edu.au>) By note With Smtp ; Thu, 19 May 2005 11:09:52 +1000 Received: from steeleye.com (clements.sc.steeleye.com [172.17.6.4]) by hancock.sc.steeleye.com (8.11.6/8.11.6) with ESMTP id j4J19lA29968 for <neilb@cse.unsw.edu.au>; Wed, 18 May 2005 21:09:48 -0400 Message-ID: <428BE75B.20803@steeleye.com> User-Agent: Mozilla Thunderbird 0.5 (X11/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <428A496D.6000303@steeleye.com> In-Reply-To: <428A496D.6000303@steeleye.com> From: Paul Clements <paul.clements@steeleye.com> To: neilb@cse.unsw.edu.au Subject: [PATCH 1/1] mdadm 2.0 devel: fix bitmap size calculation and allow "missing" device in Build command Date: Wed, 18 May 2005 21:09:47 -0400 Content-Type: multipart/mixed; boundary="------------090601020206040308050709" This is a multi-part message in MIME format. Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
2005-06-14 08:29:20 +02:00
int subdevs = 0, missing_disks = 0;
struct mddev_dev *dv;
int bitmap_fd;
unsigned long long bitmapsize;
int mdfd;
char chosen_name[1024];
int uuid[4] = {0,0,0,0};
struct map_ent *map = NULL;
mdu_array_info_t array;
mdu_param_t param; /* not used by syscall */
2001-07-26 09:00:09 +02:00
if (s->level == UnSet) {
pr_err("a RAID level is needed to Build an array.\n");
return 1;
}
2001-07-26 09:00:09 +02:00
/* scan all devices, make sure they really are block devices */
2002-03-07 00:17:40 +01:00
for (dv = devlist; dv; dv=dv->next) {
From paul.clements@steeleye.com Thu May 19 11:09:55 2005 X-VM-v5-Data: ([nil nil nil nil t nil nil nil nil] ["2589" "Wednesday" "18" "May" "2005" "21:09:47" "-0400" "Paul Clements" "paul.clements@steeleye.com" nil "93" "[PATCH 1/1] mdadm 2.0 devel: fix bitmap size calculation and allow \"missing\" device in Build command" "^From:" "neilb@cse.unsw.edu.au" "neilb@cse.unsw.edu.au" "5" nil nil nil nil nil nil nil nil nil] nil) Return-Path: <paul.clements@steeleye.com> Received: From smtp-dist.unsw.edu.au ([149.171.97.16] == smtp-dist-01.services.comms.unsw.EDU.AU) (for <neilb@cse.unsw.edu.au>) By note With Smtp ; Thu, 19 May 2005 11:09:55 +1000 Received: from localhost (avspam-03.services.comms.unsw.edu.au [149.171.100.18]) by smtp-dist.unsw.edu.au (8.13.1/8.13.1) with ESMTP id j4J19t05017496 for <VRT+EFNJ=JQ=cse.unsw.edu.au=neilb@cse.unsw.edu.au>; Thu, 19 May 2005 11:09:55 +1000 (EST) Received: from note.orchestra.cse.unsw.EDU.AU (note.orchestra.cse.unsw.EDU.AU [129.94.242.24]) by smtp.unsw.edu.au (8.13.1/8.13.1) with ESMTP id j4J19qEL010258 for <VRT+EFNJ=JQ=cse.unsw.edu.au=neilb@cse.unsw.edu.au>; Thu, 19 May 2005 11:09:53 +1000 (EST) Received: From hancock.sc.steeleye.com ([209.192.50.48] == stat16.steeleye.com) (for <neilb@cse.unsw.edu.au>) By note With Smtp ; Thu, 19 May 2005 11:09:52 +1000 Received: from steeleye.com (clements.sc.steeleye.com [172.17.6.4]) by hancock.sc.steeleye.com (8.11.6/8.11.6) with ESMTP id j4J19lA29968 for <neilb@cse.unsw.edu.au>; Wed, 18 May 2005 21:09:48 -0400 Message-ID: <428BE75B.20803@steeleye.com> User-Agent: Mozilla Thunderbird 0.5 (X11/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <428A496D.6000303@steeleye.com> In-Reply-To: <428A496D.6000303@steeleye.com> From: Paul Clements <paul.clements@steeleye.com> To: neilb@cse.unsw.edu.au Subject: [PATCH 1/1] mdadm 2.0 devel: fix bitmap size calculation and allow "missing" device in Build command Date: Wed, 18 May 2005 21:09:47 -0400 Content-Type: multipart/mixed; boundary="------------090601020206040308050709" This is a multi-part message in MIME format. Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
2005-06-14 08:29:20 +02:00
subdevs++;
if (strcmp("missing", dv->devname) == 0) {
missing_disks++;
continue;
}
if (!stat_is_blkdev(dv->devname, NULL))
2001-07-26 09:00:09 +02:00
return 1;
2002-03-07 00:17:40 +01:00
}
if (s->raiddisks != subdevs) {
pr_err("requested %d devices in array but listed %d\n",
s->raiddisks, subdevs);
2002-03-07 00:17:40 +01:00
return 1;
2001-07-26 09:00:09 +02:00
}
if (s->layout == UnSet)
s->layout = default_layout(NULL, s->level, c->verbose);
2004-11-01 05:49:34 +01:00
/* We need to create the device. It can have no name. */
map_lock(&map);
mdfd = create_mddev(mddev, NULL, c->autof, LOCAL,
chosen_name, 0);
if (mdfd < 0) {
map_unlock(&map);
return 1;
}
mddev = chosen_name;
2004-11-01 05:49:34 +01:00
map_update(&map, fd2devnm(mdfd), "none", uuid, chosen_name);
map_unlock(&map);
array.level = s->level;
if (s->size == MAX_SIZE)
s->size = 0;
array.size = s->size;
array.nr_disks = s->raiddisks;
array.raid_disks = s->raiddisks;
array.md_minor = 0;
if (fstat_is_blkdev(mdfd, mddev, &rdev))
array.md_minor = minor(rdev);
array.not_persistent = 1;
array.state = 0; /* not clean, but no errors */
if (s->assume_clean)
array.state |= 1;
array.active_disks = s->raiddisks - missing_disks;
array.working_disks = s->raiddisks - missing_disks;
array.spare_disks = 0;
array.failed_disks = missing_disks;
if (s->chunk == 0 && (s->level==0 || s->level==LEVEL_LINEAR))
s->chunk = 64;
array.chunk_size = s->chunk*1024;
array.layout = s->layout;
if (md_set_array_info(mdfd, &array)) {
pr_err("md_set_array_info() failed for %s: %s\n",
mddev, strerror(errno));
goto abort;
2001-07-26 09:00:09 +02:00
}
if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0)
s->bitmap_file = NULL;
if (s->bitmap_file && s->level <= 0) {
pr_err("bitmaps not meaningful with level %s\n",
map_num(pers, s->level)?:"given");
goto abort;
}
2001-07-26 09:00:09 +02:00
/* now add the devices */
2002-03-07 00:17:40 +01:00
for ((i=0), (dv = devlist) ; dv ; i++, dv=dv->next) {
mdu_disk_info_t disk;
unsigned long long dsize;
int fd;
From paul.clements@steeleye.com Thu May 19 11:09:55 2005 X-VM-v5-Data: ([nil nil nil nil t nil nil nil nil] ["2589" "Wednesday" "18" "May" "2005" "21:09:47" "-0400" "Paul Clements" "paul.clements@steeleye.com" nil "93" "[PATCH 1/1] mdadm 2.0 devel: fix bitmap size calculation and allow \"missing\" device in Build command" "^From:" "neilb@cse.unsw.edu.au" "neilb@cse.unsw.edu.au" "5" nil nil nil nil nil nil nil nil nil] nil) Return-Path: <paul.clements@steeleye.com> Received: From smtp-dist.unsw.edu.au ([149.171.97.16] == smtp-dist-01.services.comms.unsw.EDU.AU) (for <neilb@cse.unsw.edu.au>) By note With Smtp ; Thu, 19 May 2005 11:09:55 +1000 Received: from localhost (avspam-03.services.comms.unsw.edu.au [149.171.100.18]) by smtp-dist.unsw.edu.au (8.13.1/8.13.1) with ESMTP id j4J19t05017496 for <VRT+EFNJ=JQ=cse.unsw.edu.au=neilb@cse.unsw.edu.au>; Thu, 19 May 2005 11:09:55 +1000 (EST) Received: from note.orchestra.cse.unsw.EDU.AU (note.orchestra.cse.unsw.EDU.AU [129.94.242.24]) by smtp.unsw.edu.au (8.13.1/8.13.1) with ESMTP id j4J19qEL010258 for <VRT+EFNJ=JQ=cse.unsw.edu.au=neilb@cse.unsw.edu.au>; Thu, 19 May 2005 11:09:53 +1000 (EST) Received: From hancock.sc.steeleye.com ([209.192.50.48] == stat16.steeleye.com) (for <neilb@cse.unsw.edu.au>) By note With Smtp ; Thu, 19 May 2005 11:09:52 +1000 Received: from steeleye.com (clements.sc.steeleye.com [172.17.6.4]) by hancock.sc.steeleye.com (8.11.6/8.11.6) with ESMTP id j4J19lA29968 for <neilb@cse.unsw.edu.au>; Wed, 18 May 2005 21:09:48 -0400 Message-ID: <428BE75B.20803@steeleye.com> User-Agent: Mozilla Thunderbird 0.5 (X11/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 References: <428A496D.6000303@steeleye.com> In-Reply-To: <428A496D.6000303@steeleye.com> From: Paul Clements <paul.clements@steeleye.com> To: neilb@cse.unsw.edu.au Subject: [PATCH 1/1] mdadm 2.0 devel: fix bitmap size calculation and allow "missing" device in Build command Date: Wed, 18 May 2005 21:09:47 -0400 Content-Type: multipart/mixed; boundary="------------090601020206040308050709" This is a multi-part message in MIME format. Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
2005-06-14 08:29:20 +02:00
if (strcmp("missing", dv->devname) == 0)
continue;
if (!stat_is_blkdev(dv->devname, &rdev))
2001-07-26 09:00:09 +02:00
goto abort;
fd = open(dv->devname, O_RDONLY|O_EXCL);
if (fd < 0) {
pr_err("Cannot open %s: %s\n",
dv->devname, strerror(errno));
goto abort;
}
if (get_dev_size(fd, NULL, &dsize) &&
(s->size == 0 || s->size == MAX_SIZE || dsize < s->size))
s->size = dsize;
close(fd);
disk.number = i;
disk.raid_disk = i;
disk.state = (1<<MD_DISK_SYNC) | (1<<MD_DISK_ACTIVE);
if (dv->writemostly == FlagSet)
disk.state |= 1<<MD_DISK_WRITEMOSTLY;
disk.major = major(rdev);
disk.minor = minor(rdev);
if (ioctl(mdfd, ADD_NEW_DISK, &disk)) {
pr_err("ADD_NEW_DISK failed for %s: %s\n",
dv->devname, strerror(errno));
goto abort;
2001-07-26 09:00:09 +02:00
}
}
/* now to start it */
if (s->bitmap_file) {
bitmap_fd = open(s->bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
int major = BITMAP_MAJOR_HI;
#if 0
if (s->bitmap_chunk == UnSet) {
pr_err("%s cannot be opened.\n", s->bitmap_file);
goto abort;
}
#endif
bitmapsize = s->size >> 9; /* FIXME wrong for RAID10 */
if (CreateBitmap(s->bitmap_file, 1, NULL,
s->bitmap_chunk, c->delay,
s->write_behind, bitmapsize, major)) {
goto abort;
2007-12-14 10:13:43 +01:00
}
bitmap_fd = open(s->bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
pr_err("%s cannot be opened.\n", s->bitmap_file);
goto abort;
}
}
if (bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
pr_err("Cannot set bitmap file for %s: %s\n",
mddev, strerror(errno));
goto abort;
}
2001-07-26 09:00:09 +02:00
}
}
if (ioctl(mdfd, RUN_ARRAY, &param)) {
pr_err("RUN_ARRAY failed: %s\n", strerror(errno));
if (s->chunk & (s->chunk - 1)) {
cont_err("Problem may be that chunk size is not a power of 2\n");
2001-07-26 09:00:09 +02:00
}
goto abort;
2001-07-26 09:00:09 +02:00
}
if (c->verbose >= 0)
pr_err("array %s built and started.\n",
mddev);
wait_for(mddev, mdfd);
close(mdfd);
2001-07-26 09:00:09 +02:00
return 0;
abort:
ioctl(mdfd, STOP_ARRAY, 0);
close(mdfd);
2001-07-26 09:00:09 +02:00
return 1;
2001-06-08 04:36:23 +02:00
}