return 1;
}
- nfd = open(newdev, O_RDWR|O_EXCL);
+ nfd = open(newdev, O_RDWR|O_EXCL|O_DIRECT);
if (nfd < 0) {
fprintf(stderr, Name ": cannot open %s\n", newdev);
return 1;
__u64 arraystart;
__u64 length;
__u32 sb_csum; /* csum of preceeding bytes. */
-};
+ __u8 pad[512-68];
+} __attribute__((aligned(512))) bsb;
int bsb_csum(char *buf, int len)
{
struct mdu_array_info_s array;
char *c;
- struct mdp_backup_super bsb;
struct supertype *st;
int nlevel, olevel;
int nrdisks;
int err;
- struct sysarray *sra;
+ struct mdinfo *sra;
struct mdinfo *sd;
if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) {
last_block = nstripe * ndata;
ostripe = last_block / odata / (ochunk/512) * (ochunk/512);
}
- printf("mdadm: Need to backup %lluK of critical section..\n", last_block/2);
+ fprintf(stderr, Name ": Need to backup %lluK of critical "
+ "section..\n", last_block/2);
sra = sysfs_read(fd, 0,
GET_COMPONENT|GET_DEVS|GET_OFFSET|GET_STATE|
devname);
return 1;
}
- if (sra->spares == 0 && backup_file == NULL) {
+ if (sra->array.spare_disks == 0 && backup_file == NULL) {
fprintf(stderr, Name ": %s: Cannot grow - need a spare or backup-file to backup critical section\n",
devname);
return 1;
}
- nrdisks = array.nr_disks + sra->spares;
+ nrdisks = array.nr_disks + sra->array.spare_disks;
/* Now we need to open all these devices so we can read/write.
*/
fdlist = malloc((1+nrdisks) * sizeof(int));
" --grow aborted\n", devname, i);
goto abort;
}
- spares = sra->spares;
+ spares = sra->array.spare_disks;
if (backup_file) {
- fdlist[d] = open(backup_file, O_RDWR|O_CREAT|O_EXCL, 0600);
+ fdlist[d] = open(backup_file, O_RDWR|O_CREAT|O_EXCL, S_IRUSR | S_IWUSR);
if (fdlist[d] < 0) {
fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
devname, backup_file, strerror(errno));
* a leading superblock 4K earlier.
*/
for (i=array.raid_disks; i<d; i++) {
- char buf[4096];
+ char abuf[4096+512];
+ char *buf = (char*)(((unsigned long)abuf+511)& ~511);
if (i==d-1 && backup_file) {
/* This is the backup file */
offsets[i] = 8;
fprintf(stderr, Name ": could not seek...\n");
goto abort;
}
- memset(buf, 0, sizeof(buf));
+ memset(buf, 0, 4096);
bsb.devstart = __cpu_to_le64(offsets[i]);
bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb));
memcpy(buf, &bsb, sizeof(bsb));
if (lseek64(fdlist[i], (offsets[i]+last_block)<<9, 0) < 0 ||
write(fdlist[i], &bsb, sizeof(bsb)) != sizeof(bsb) ||
fsync(fdlist[i]) != 0) {
- fprintf(stderr, Name ": %s: fail to save metadata for critical region backups.\n",
+ fprintf(stderr, Name ": %s: failed to save metadata for critical region backups.\n",
devname);
goto abort_resume;
}
if (backup_file)
unlink(backup_file);
- printf(Name ": ... critical section passed.\n");
+ fprintf(stderr, Name ": ... critical section passed.\n");
break;
}
return 0;
for (i=old_disks-(backup_file?1:0); i<cnt; i++) {
struct mdinfo dinfo;
- struct mdp_backup_super bsb;
char buf[4096];
int fd;