free(super);
super = NULL;
}
-
+
dfd = dev_open(devname, O_RDONLY|O_EXCL);
if (dfd < 0) {
if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": no uptodate device for slot %d of %s\n",
i, mddev);
}
-
+
if (runstop == 1 ||
(runstop <= 0 &&
( enough(info.array.level, info.array.raid_disks,
fprintf(stderr, Name ": Cannot start array: %s\n",
strerror(errno));
}
-
+
}
if (must_close) close(mdfd);
return 0;
vers = md_get_version(mdfd);
-
+
/* looks Ok, go for it */
if (vers >= 9000) {
mdu_array_info_t array;
}
fd = open(dv->devname, O_RDONLY|O_EXCL);
if (fd < 0) {
- fprintf(stderr, Name ": Cannot open %s: %s\n",
+ fprintf(stderr, Name ": Cannot open %s: %s\n",
dv->devname, strerror(errno));
goto abort;
}
bitmap_file);
return 1;
}
- }
+ }
if (bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
else
ioctl(mdfd, STOP_MD, 0);
return 1;
-
}
if (level > 0 || level == LEVEL_MULTIPATH || level == LEVEL_FAULTY) {
/* size is meaningful */
if (minsize > 0x100000000ULL && st->ss->major == 0) {
- fprintf(stderr, Name ": devices too large for RAID level %d\n", level);
+ fprintf(stderr, Name ": devices too large for RAID level %d\n", level);
return 1;
}
size = minsize;
Name ": This level does not support missing devices\n");
return 1;
}
-
+
/* Ok, lets try some ioctls */
array.level = level;
inf.major_version = st->ss->major;
inf.minor_version = st->minor_version;
rv = ioctl(mdfd, SET_ARRAY_INFO, &inf);
- } else
+ } else
rv = ioctl(mdfd, SET_ARRAY_INFO, NULL);
if (rv) {
fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
break;
default: break;
}
-
+
if (e && e->percent >= 0) {
printf(" Re%s Status : %d%% complete\n",
(super && info.reshape_active)? "shape":"build",
}
if (disk.major == 0 && disk.minor == 0)
continue;
- if (disk.raid_disk >= 0 && disk.raid_disk < array.raid_disks)
+ if (disk.raid_disk >= 0 && disk.raid_disk < array.raid_disks)
disks[disk.raid_disk] = disk;
else if (next < max_disks)
disks[next++] = disk;
if (!brief) {
if (d == array.raid_disks) printf("\n");
if (disk.raid_disk < 0)
- printf(" %5d %5d %5d - ",
+ printf(" %5d %5d %5d - ",
disk.number, disk.major, disk.minor);
else
- printf(" %5d %5d %5d %5d ",
+ printf(" %5d %5d %5d %5d ",
disk.number, disk.major, disk.minor, disk.raid_disk);
- if (disk.state & (1<<MD_DISK_FAULTY)) {
- printf(" faulty");
+ if (disk.state & (1<<MD_DISK_FAULTY)) {
+ printf(" faulty");
if (disk.raid_disk < array.raid_disks &&
disk.raid_disk >= 0)
failed++;
* If (brief) gather devices for same array and just print a mdadm.conf line including devices=
* if devlist==NULL, use conf_get_devs()
*/
- int fd;
+ int fd;
void *super = NULL;
int rv = 0;
int err = 0;
int nfd, fd2;
int d, nd;
struct supertype *st = NULL;
-
+
if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) {
fprintf(stderr, Name ": cannot get array info for %s\n", devname);
/* Ok, looks good. Lets update the superblock and write it out to
* newdev.
*/
-
+
info.disk.number = d;
info.disk.major = major(stb.st_rdev);
info.disk.minor = minor(stb.st_rdev);
st->ss->update_super(&info, super, "linear-grow-update", dv,
0, 0, NULL);
-
+
if (st->ss->store_super(st, fd2, super)) {
fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
close(fd2);
break;
sleep(1);
}
-
+
/* invalidate superblocks */
memset(&bsb, 0, sizeof(bsb));
for (i=odisks; i<d ; i++) {
void *super;
int fd, rv = 0;
struct supertype *st;
-
+
fd = open(dev, O_RDWR|O_EXCL);
if (fd < 0) {
if (!quiet)
*
*/
mdu_array_info_t array;
-
+
if (md_get_version(fd) < 9000) {
fprintf(stderr, Name ": need md driver version 0.90.0 or later\n");
return 1;
devname);
return 1;
}
-
+
if (readonly>0) {
if (ioctl(fd, STOP_ARRAY_RO, NULL)) {
fprintf(stderr, Name ": failed to set readonly for %s: %s\n",
return 1;
}
}
- return 0;
+ return 0;
}
#ifndef MDASSEMBLE
return 1;
}
}
-
+
if (md_get_version(fd) < 9000) {
fprintf(stderr, Name ": need md driver version 0.90.0 or later\n");
return 1;
}
/* need to find a sample superblock to copy, and
- * a spare slot to use
+ * a spare slot to use
*/
for (j=0; j<st->max_devs; j++) {
char *dev;
}
}
return 0;
-
+
}
int autodetect(void)
static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mailfrom,
char *cmd, int dosyslog);
-static char *percentalerts[] = {
+static char *percentalerts[] = {
"RebuildStarted",
"Rebuild20",
"Rebuild40",
alert("DegradedArray", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
if (st->utime == 0 && /* new array */
- st->expected_spares > 0 &&
- array.spare_disks < st->expected_spares)
+ st->expected_spares > 0 &&
+ array.spare_disks < st->expected_spares)
alert("SparesMissing", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
if (mse &&
- st->percent == -1 &&
+ st->percent == -1 &&
mse->percent >= 0)
alert("RebuildStarted", dev, NULL, mailaddr, mailfrom, alert_cmd, dosyslog);
if (mse &&
/* now check if there are any new devices found in mdstat */
if (scan) {
struct mdstat_ent *mse;
- for (mse=mdstat; mse; mse=mse->next)
+ for (mse=mdstat; mse; mse=mse->next)
if (mse->devnum != INT_MAX &&
(strcmp(mse->level, "raid0")!=0 &&
strcmp(mse->level, "linear")!=0)
}
}
if (dev > 0) {
- if (ioctl(fd2, HOT_REMOVE_DISK,
+ if (ioctl(fd2, HOT_REMOVE_DISK,
(unsigned long)dev) == 0) {
if (ioctl(fd1, HOT_ADD_DISK,
(unsigned long)dev) == 0) {
if (!cmd && !mailaddr) {
time_t now = time(0);
-
+
printf("%1.15s: %s on %s %s\n", ctime(&now)+4, event, dev, disc?disc:"unknown device");
}
if (cmd) {
exit(2);
}
}
- if (mailaddr &&
- (strncmp(event, "Fail", 4)==0 ||
+ if (mailaddr &&
+ (strncmp(event, "Fail", 4)==0 ||
strncmp(event, "Test", 4)==0 ||
strncmp(event, "Spares", 6)==0 ||
strncmp(event, "Degrade", 7)==0)) {
int Query(char *dev)
{
/* Give a brief description of the device,
- * whether it is an md device and whether it has
+ * whether it is an md device and whether it has
* a superblock
*/
int fd = open(dev, O_RDONLY, 0);
if (ioctl(fd, GET_ARRAY_INFO, &array)<0)
ioctlerr = errno;
else ioctlerr = 0;
-
+
fstat(fd, &stb);
if (vers>=9000 && !ioctlerr) {
larray_size = 0;
}
- if (vers < 0)
+ if (vers < 0)
printf("%s: is not an md array\n", dev);
else if (vers < 9000)
printf("%s: is an md device, but kernel cannot provide details\n", dev);
if (st) {
superror = st->ss->load_super(st, fd, &super, dev);
superrno = errno;
- } else
+ } else
superror = -1;
close(fd);
if (superror == 0) {
disc.number = info.disk.number;
activity = "undetected";
if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
- if (md_get_version(fd) >= 9000 &&
+ if (md_get_version(fd) >= 9000 &&
ioctl(fd, GET_ARRAY_INFO, &array)>= 0) {
if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 &&
makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
mddev = "array";
}
printf("%s: device %d in %d device %s %s %s. Use mdadm --examine for more detail.\n",
- dev,
+ dev,
info.disk.number, info.array.raid_disks,
activity,
map_num(pers, info.array.level),
return 0;
}
-
/* synonyms */
{"monitor", 0, 0, 'F'},
-
+
/* after those will normally come the name of the md device */
{"help", 0, 0, 'h'},
{"help-options",0,0,'h'},
skip = sizeof(info->sb);
sb_le_to_cpu(&info->sb); /* convert superblock to CPU byte ordering */
-
+
if (brief || info->sb.sync_size == 0)
goto out;
if (!st) {
/* just look at device... */
lseek(fd, 0, 0);
- } else {
+ } else {
st->ss->locate_bitmap(st, fd, NULL);
}
ioctl(fd, BLKFLSBUF, 0); /* make sure we read current data */
}
bytes -= sizeof(block);
}
-
+
rv = 0;
fflush(fp);
/* make the file be the right size (well, to the nearest byte) */
* (1) This event counter is updated before the eventcounter in the md superblock
* When a bitmap is loaded, it is only accepted if this event counter is equal
* to, or one greater than, the event counter in the superblock.
- * (2) This event counter is updated when the other one is *if*and*only*if* the
+ * (2) This event counter is updated when the other one is *if*and*only*if* the
* array is not degraded. As bits are not cleared when the array is degraded,
* this represents the last time that any bits were cleared.
* If a device is being added that has an event count with this value or
unsigned int hijacked;
/*
* count of dirty bits on the page
- */
+ */
int count;
};
{
int len = strlen(word);
int n;
-
+
if (len < 3) return -1;
for (n=0; keywords[n]; n++) {
if (strncasecmp(word, keywords[n], len)==0)
}
return word;
}
-
+
/*
* conf_line reads one logical line from the conffile.
* It skips comments and continues until it finds a line that starts
if (buf[0] != ' ')
continue;
major = strtoul(buf, &mp, 10);
- if (mp == buf || *mp != ' ')
+ if (mp == buf || *mp != ' ')
continue;
minor = strtoul(mp, NULL, 10);
}
}
-void devline(char *line)
+void devline(char *line)
{
char *w;
struct conf_dev *cd;
} else if (strncasecmp(w, "metadata=", 9) == 0) {
/* style of metadata on the devices. */
int i;
-
+
for(i=0; superlist[i] && !mis.st; i++)
mis.st = superlist[i]->match_metadata_desc(w+9);
}
free_line(line);
}
-
+
fclose(f);
/* printf("got file\n"); */
free(t->devname);
free(t);
}
-
+
load_conffile();
if (cdevlist == NULL)
/*
md_p.h : physical layout of Linux RAID devices
Copyright (C) 1996-98 Ingo Molnar, Gadi Oxman
-
+
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, or (at your option)
any later version.
-
+
You should have received a copy of the GNU General Public License
(for example /usr/src/linux/COPYING); if not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _MD_P_H
#define MD_DISK_REMOVED 3 /* disk is in sync with the raid set */
#define MD_DISK_WRITEMOSTLY 9 /* disk is "write-mostly" is RAID1 config.
- * read requests will only be sent here in
+ * read requests will only be sent here in
* dire need
*/
return (ev<<32)| sb->events_lo;
}
-#endif
+#endif
/*
md_u.h : user <=> kernel API between Linux raidtools and RAID drivers
Copyright (C) 1998 Ingo Molnar
-
+
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, or (at your option)
any later version.
-
+
You should have received a copy of the GNU General Public License
(for example /usr/src/linux/COPYING); if not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _MD_U_H
int max_fault; /* unused for now */
} mdu_param_t;
-#endif
+#endif
* Sydney, 2052
* Australia
*
- * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
+ * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
* Paul Clements, SteelEye Technology, Inc.
*/
/* firstly, some mode-independant options */
switch(opt) {
case 'h':
- if (option_index > 0 &&
+ if (option_index > 0 &&
strcmp(long_options[option_index].name, "help-options")==0)
print_help = 2;
else
}
/* second, figure out the mode.
* Some options force the mode. Others
- * set the mode if it isn't already
+ * set the mode if it isn't already
*/
switch(opt) {
mode = newmode;
} else {
/* special case of -c --help */
- if (opt == 'c' &&
+ if (opt == 'c' &&
( strncmp(optarg, "--h", 3)==0 ||
strncmp(optarg, "-h", 2)==0)) {
fputs(Help_config, stdout);
dv->next = NULL;
*devlistend = dv;
devlistend = &dv->next;
-
+
devs_found++;
continue;
}
dv->next = NULL;
*devlistend = dv;
devlistend = &dv->next;
-
+
devs_found++;
continue;
}
fprintf(stderr, Name ": metadata information already given\n");
exit(2);
}
- for(i=0; !ss && superlist[i]; i++)
+ for(i=0; !ss && superlist[i]; i++)
ss = superlist[i]->match_metadata_desc(optarg);
if (!ss) {
case -5: /* Faulty
* modeNNN
*/
-
+
{
int ln = strcspn(optarg, "0123456789");
char *m = strdup(optarg);
exit(2);
}
update = optarg;
- if (strcmp(update, "sparc2.2")==0)
+ if (strcmp(update, "sparc2.2")==0)
continue;
if (strcmp(update, "super-minor") == 0)
continue;
fprintf(stderr, Name ": must not set metadata type with --update=byteorder.\n");
exit(2);
}
- for(i=0; !ss && superlist[i]; i++)
+ for(i=0; !ss && superlist[i]; i++)
ss = superlist[i]->match_metadata_desc("0.swap");
if (!ss) {
fprintf(stderr, Name ": INTERNAL ERROR cannot find 0.swap\n");
exit(2);
}
if ((int)ident.super_minor == -2 && autof) {
- fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
+ fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
exit(2);
}
if (mode == MANAGE || mode == GROW)
devlist->devname);
rv |= 1;
} else {
- mdfd = open_mddev(devlist->devname,
+ mdfd = open_mddev(devlist->devname,
array_ident->autof ? array_ident->autof : autof);
if (mdfd < 0)
rv |= 1;
rv |= 1;
continue;
}
- mdfd = open_mddev(dv->devname,
+ mdfd = open_mddev(dv->devname,
array_ident->autof ?array_ident->autof : autof);
if (mdfd < 0) {
rv |= 1;
case GROW:
if (devs_found > 1) {
-
+
/* must be '-a'. */
if (size >= 0 || raiddisks) {
fprintf(stderr, Name ": --size, --raiddisks, and --add are exclusing in --grow mode\n");
#define UnSet (0xfffe)
typedef struct mddev_ident_s {
char *devname;
-
+
int uuid_set;
int uuid[4];
char name[33];
* If the device name is in a 'standard' format,
* intuit the minor from that, else
* easiest to read /proc/mdstat, and hunt through for
- * an unused number
+ * an unused number
*/
if (num < 0) {
/* need to pick an unused number */
ent->dev = strdup(line);
ent->devnum = devnum;
-
+
for (w=dl_next(line); w!= line ; w=dl_next(w)) {
int l = strlen(w);
char *eq;
strncmp(w, "resync", 4)==0) {
ent->resync = 1;
} else if (ent->percent == -1 &&
- w[0] >= '0' &&
+ w[0] >= '0' &&
w[0] <= '9' &&
w[l-1] == '%') {
ent->percent = atoi(w);
unsigned int blocksperchunk= chunksize/4096;
unsigned long b;
-
+
for (b=0; b<blocks; b++) {
unsigned long stripe = b / blocksperchunk;
unsigned int offset = b - (stripe*blocksperchunk);
* - initialising a new superblock
* - printing the superblock for --examine
* - printing part of the superblock for --detail
- * .. other stuff
+ * .. other stuff
*/
void super0_swap_endian(struct mdp_superblock_s *sb)
{
/* as super0 superblocks are host-endian, it is sometimes
- * useful to be able to swap the endianness
+ * useful to be able to swap the endianness
* as (almost) everything is u32's we byte-swap every 4byte
* number.
* We then also have to swap the events_hi and events_lo
if (strcmp(update, "summaries") == 0) {
int i;
/* set nr_disks, active_disks, working_disks,
- * failed_disks, spare_disks based on disks[]
+ * failed_disks, spare_disks based on disks[]
* array in superblock.
* Also make sure extra slots aren't 'failed'
*/
sb->nr_disks = sb->active_disks =
sb->working_disks = sb->failed_disks =
sb->spare_disks = 0;
- for (i=0; i < MD_SB_DISKS ; i++)
+ for (i=0; i < MD_SB_DISKS ; i++)
if (sb->disks[i].major ||
sb->disks[i].minor) {
int state = sb->disks[i].state;
mdp_super_t *super;
int uuid[4];
struct bitmap_super_s *bsb;
-
+
if (!get_dev_size(fd, devname, &dsize))
return 1;
unsigned long long dsize;
unsigned long long offset;
mdp_super_t *sb = sbv;
-
+
int rv = 0;
int towrite, n;
memset(buf, 0xff, sizeof(buf));
while (towrite > 0) {
n = towrite;
- if (n > sizeof(buf))
+ if (n > sizeof(buf))
n = sizeof(buf);
n = write(fd, buf, n);
if (n > 0)
*/
int parse_uuid(char *str, int uuid[4])
{
- int hit = 0; /* number of Hex digIT */
- int i;
- char c;
- for (i=0; i<4; i++) uuid[i]=0;
-
- while ((c= *str++)) {
- int n;
- if (c>='0' && c<='9')
- n = c-'0';
- else if (c>='a' && c <= 'f')
- n = 10 + c - 'a';
- else if (c>='A' && c <= 'F')
- n = 10 + c - 'A';
- else if (strchr(":. -", c))
- continue;
- else return 0;
-
- if (hit<32) {
- uuid[hit/8] <<= 4;
- uuid[hit/8] += n;
+ int hit = 0; /* number of Hex digIT */
+ int i;
+ char c;
+ for (i=0; i<4; i++) uuid[i]=0;
+
+ while ((c= *str++)) {
+ int n;
+ if (c>='0' && c<='9')
+ n = c-'0';
+ else if (c>='a' && c <= 'f')
+ n = 10 + c - 'a';
+ else if (c>='A' && c <= 'F')
+ n = 10 + c - 'A';
+ else if (strchr(":. -", c))
+ continue;
+ else return 0;
+
+ if (hit<32) {
+ uuid[hit/8] <<= 4;
+ uuid[hit/8] += n;
+ }
+ hit++;
}
- hit++;
- }
- if (hit == 32)
- return 1;
- return 0;
-
+ if (hit == 32)
+ return 1;
+ return 0;
}
return -1;
}
-
int get_linux_version()
{
struct utsname name;
if (swapuuid) {
/* parse uuids are hostendian.
* uuid's from some superblocks are big-ending
- * if there is a difference, we need to swap..
+ * if there is a difference, we need to swap..
*/
unsigned char *ac = (unsigned char *)a;
unsigned char *bc = (unsigned char *)b;
fprintf(stderr, Name ": %s appears to contain a reiserfs file system\n",name);
size = sb[0]|(sb[1]|(sb[2]|sb[3]<<8)<<8)<<8;
fprintf(stderr, " size = %luK\n", size*4);
-
+
return 1;
}
{
/* tests if dev is a "standard" md dev name.
* i.e if the last component is "/dNN" or "/mdNN",
- * where NN is a string of digits
+ * where NN is a string of digits
*/
char *d = strrchr(dev, '/');
int type=0;
newcsum+= superc[i];
csum = (newcsum& 0xffffffff) + (newcsum>>32);
#ifdef __alpha__
-/* The in-kernel checksum calculation is always 16bit on
+/* The in-kernel checksum calculation is always 16bit on
* the alpha, though it is 32 bit on i386...
* I wonder what it is elsewhere... (it uses and API in
* a way that it shouldn't).
char *human_size_brief(long long bytes)
{
static char buf[30];
-
if (bytes < 5000*1024)
snprintf(buf, sizeof(buf), "%ld.%02ldKiB",
struct supertype *st;
unsigned long besttime = 0;
int bestsuper = -1;
-
+
void *sbp = NULL;
int i;