imsm: Clear migration record when no migration in progress

When metadata is saved and there is no general migration in progress
/in container/ clear migration record in container.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: Krzysztof Wojcik <krzysztof.wojcik@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
Adam Kwolek 2011-06-08 17:09:16 +10:00 committed by NeilBrown
parent b915c95fd3
commit 146c626037
1 changed files with 16 additions and 0 deletions

View File

@ -4248,6 +4248,8 @@ static int write_super_imsm_spares(struct intel_super *super, int doclose)
return 0;
}
static int is_gen_migration(struct imsm_dev *dev);
static int write_super_imsm(struct supertype *st, int doclose)
{
struct intel_super *super = st->sb;
@ -4259,6 +4261,7 @@ static int write_super_imsm(struct supertype *st, int doclose)
int i;
__u32 mpb_size = sizeof(struct imsm_super) - sizeof(struct imsm_disk);
int num_disks = 0;
int clear_migration_record = 1;
/* 'generation' is incremented everytime the metadata is written */
generation = __le32_to_cpu(mpb->generation_num);
@ -4293,6 +4296,8 @@ static int write_super_imsm(struct supertype *st, int doclose)
imsm_copy_dev(dev, dev2);
mpb_size += sizeof_imsm_dev(dev, 0);
}
if (is_gen_migration(dev2))
clear_migration_record = 0;
}
mpb_size += __le32_to_cpu(mpb->bbm_log_size);
mpb->mpb_size = __cpu_to_le32(mpb_size);
@ -4301,6 +4306,9 @@ static int write_super_imsm(struct supertype *st, int doclose)
sum = __gen_imsm_checksum(mpb);
mpb->check_sum = __cpu_to_le32(sum);
if (clear_migration_record)
memset(super->migr_rec_buf, 0, 512);
/* write the mpb for disks that compose raid devices */
for (d = super->disks; d ; d = d->next) {
if (d->index < 0)
@ -4308,6 +4316,14 @@ static int write_super_imsm(struct supertype *st, int doclose)
if (store_imsm_mpb(d->fd, mpb))
fprintf(stderr, "%s: failed for device %d:%d %s\n",
__func__, d->major, d->minor, strerror(errno));
if (clear_migration_record) {
unsigned long long dsize;
get_dev_size(d->fd, NULL, &dsize);
if (lseek64(d->fd, dsize - 512, SEEK_SET) >= 0) {
write(d->fd, super->migr_rec_buf, 512);
}
}
if (doclose) {
close(d->fd);
d->fd = -1;