summaryrefslogtreecommitdiffstats
path: root/super0.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2008-05-15 16:48:12 +1000
committerNeil Brown <neilb@suse.de>2008-05-15 16:48:12 +1000
commit111d01fcc76d2e7d0b05f78fae67e89cdf6856ad (patch)
tree2faa362b6581db04a41f876a57c4b1c9ca6582a7 /super0.c
parent11fcec12ef68fa3b915e26676c47ee0f97d62256 (diff)
downloadmdadm-111d01fcc76d2e7d0b05f78fae67e89cdf6856ad.tar.gz
mdadm-111d01fcc76d2e7d0b05f78fae67e89cdf6856ad.tar.xz
mdadm-111d01fcc76d2e7d0b05f78fae67e89cdf6856ad.zip
Change write_init_super to be called only once.
The current model for creating arrays involves writing a superblock to each device in the array. With containers (as with DDF), that model doesn't work. Every device in the container may need to be updated for an array made from just some the devices in a container. So instead of calling write_init_super for each device, we call it once for the array and have it iterate over all the devices in the array. To help with this, ->add_to_super now passes in an 'fd' and name for the device. These get saved for use by write_init_super. So add_to_super takes ownership of the fd, and write_init_super will close it. This information is stored in the new 'info' field of supertype. As part of this, write_init_super now removes any old traces of raid metadata rather than doing this in common code.
Diffstat (limited to 'super0.c')
-rw-r--r--super0.c65
1 files changed, 46 insertions, 19 deletions
diff --git a/super0.c b/super0.c
index a1c97f8..5c2ee87 100644
--- a/super0.c
+++ b/super0.c
@@ -623,17 +623,35 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
return 1;
}
+struct devinfo {
+ int fd;
+ char *devname;
+ mdu_disk_info_t disk;
+ struct devinfo *next;
+};
/* Add a device to the superblock being created */
-static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo)
+static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
+ int fd, char *devname)
{
mdp_super_t *sb = st->sb;
mdp_disk_t *dk = &sb->disks[dinfo->number];
+ struct devinfo *di, **dip;
dk->number = dinfo->number;
dk->major = dinfo->major;
dk->minor = dinfo->minor;
dk->raid_disk = dinfo->raid_disk;
dk->state = dinfo->state;
+
+ dip = (struct devinfo **)&st->info;
+ while (*dip)
+ dip = &(*dip)->next;
+ di = malloc(sizeof(struct devinfo));
+ di->fd = fd;
+ di->devname = devname;
+ di->disk = *dinfo;
+ di->next = NULL;
+ *dip = di;
}
static int store_super0(struct supertype *st, int fd)
@@ -669,32 +687,39 @@ static int store_super0(struct supertype *st, int fd)
return 0;
}
-static int write_init_super0(struct supertype *st,
- mdu_disk_info_t *dinfo, char *devname)
+#ifndef MDASSEMBLE
+static int write_init_super0(struct supertype *st)
{
mdp_super_t *sb = st->sb;
- int fd = open(devname, O_RDWR|O_EXCL);
- int rv;
+ int rv = 0;
+ struct devinfo *di;
- if (fd < 0) {
- fprintf(stderr, Name ": Failed to open %s to write superblock\n", devname);
- return -1;
- }
+ for (di = st->info ; di && ! rv ; di = di->next) {
- sb->disks[dinfo->number].state &= ~(1<<MD_DISK_FAULTY);
+ if (di->disk.state == 1)
+ continue;
+ Kill(di->devname, 0, 1, 1);
+ Kill(di->devname, 0, 1, 1);
- sb->this_disk = sb->disks[dinfo->number];
- sb->sb_csum = calc_sb0_csum(sb);
- rv = store_super0(st, fd);
+ sb->disks[di->disk.number].state &= ~(1<<MD_DISK_FAULTY);
- if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
- rv = st->ss->write_bitmap(st, fd);
+ sb->this_disk = sb->disks[di->disk.number];
+ sb->sb_csum = calc_sb0_csum(sb);
+ rv = store_super0(st, di->fd);
- close(fd);
- if (rv)
- fprintf(stderr, Name ": failed to write superblock to %s\n", devname);
+ if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
+ rv = st->ss->write_bitmap(st, di->fd);
+
+ if (rv)
+ fprintf(stderr,
+ Name ": failed to write superblock to %s\n",
+ di->devname);
+ close(di->fd);
+ di->fd = -1;
+ }
return rv;
}
+#endif
static int compare_super0(struct supertype *st, struct supertype *tst)
{
@@ -812,6 +837,7 @@ static int load_super0(struct supertype *st, int fd, char *devname)
st->ss = &super0;
st->minor_version = super->minor_version;
st->max_devs = MD_SB_DISKS;
+ st->info = NULL;
}
/* Now check on the bitmap superblock */
@@ -844,6 +870,7 @@ static struct supertype *match_metadata_desc0(char *arg)
if (!st) return st;
st->ss = &super0;
+ st->info = NULL;
st->minor_version = 90;
st->max_devs = MD_SB_DISKS;
st->sb = NULL;
@@ -1036,6 +1063,7 @@ struct superswitch super0 = {
.detail_super = detail_super0,
.brief_detail_super = brief_detail_super0,
.export_detail_super = export_detail_super0,
+ .write_init_super = write_init_super0,
#endif
.match_home = match_home0,
.uuid_from_super = uuid_from_super0,
@@ -1044,7 +1072,6 @@ struct superswitch super0 = {
.init_super = init_super0,
.add_to_super = add_to_super0,
.store_super = store_super0,
- .write_init_super = write_init_super0,
.compare_super = compare_super0,
.load_super = load_super0,
.match_metadata_desc = match_metadata_desc0,