Add _FORTIFY_SOURCE to mdadm.O2 build.

When building mdadm.O2, set _FORTIFY_SOURCE to get more
warnings, and also build mdmon.O2 to find warnings in that
code too.
Then fix the warnings.

Suggested-by: Luca Berra <bluca@comedia.it>
Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2010-03-03 10:54:17 +11:00
parent 53f5035339
commit fcf5762500
4 changed files with 44 additions and 20 deletions

45
Grow.c
View File

@ -1254,6 +1254,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
*
*/
/* FIXME return status is never checked */
int grow_backup(struct mdinfo *sra,
unsigned long long offset, /* per device */
unsigned long stripes, /* per device */
@ -1336,16 +1337,16 @@ int grow_backup(struct mdinfo *sra,
bsb.sb_csum2 = bsb_csum((char*)&bsb,
((char*)&bsb.sb_csum2)-((char*)&bsb));
lseek64(destfd[i], destoffsets[i] - 4096, 0);
write(destfd[i], &bsb, 512);
rv |= lseek64(destfd[i], destoffsets[i] - 4096, 0);
rv = rv ?: write(destfd[i], &bsb, 512);
if (destoffsets[i] > 4096) {
lseek64(destfd[i], destoffsets[i]+stripes*chunk*odata, 0);
write(destfd[i], &bsb, 512);
rv |= lseek64(destfd[i], destoffsets[i]+stripes*chunk*odata, 0);
rv = rv ?: write(destfd[i], &bsb, 512);
}
fsync(destfd[i]);
}
return 0;
return rv;
}
/* in 2.6.30, the value reported by sync_completed can be
@ -1358,6 +1359,7 @@ int grow_backup(struct mdinfo *sra,
* The various caller give appropriate values so that
* every works.
*/
/* FIXME return value is often ignored */
int wait_backup(struct mdinfo *sra,
unsigned long long offset, /* per device */
unsigned long long blocks, /* per device */
@ -1371,6 +1373,7 @@ int wait_backup(struct mdinfo *sra,
int fd = sysfs_get_fd(sra, NULL, "sync_completed");
unsigned long long completed;
int i;
int rv;
if (fd < 0)
return -1;
@ -1402,24 +1405,26 @@ int wait_backup(struct mdinfo *sra,
bsb.length = __cpu_to_le64(0);
}
bsb.mtime = __cpu_to_le64(time(0));
rv = 0;
for (i = 0; i < dests; i++) {
bsb.devstart = __cpu_to_le64(destoffsets[i]/512);
bsb.sb_csum = bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb));
if (memcmp(bsb.magic, "md_backup_data-2", 16) == 0)
bsb.sb_csum2 = bsb_csum((char*)&bsb,
((char*)&bsb.sb_csum2)-((char*)&bsb));
lseek64(destfd[i], destoffsets[i]-4096, 0);
write(destfd[i], &bsb, 512);
rv |= lseek64(destfd[i], destoffsets[i]-4096, 0);
rv = rv ?: write(destfd[i], &bsb, 512);
fsync(destfd[i]);
}
return 0;
return rv;
}
static void fail(char *msg)
{
write(2, msg, strlen(msg));
write(2, "\n", 1);
exit(1);
int rv;
rv = write(2, msg, strlen(msg));
rv |= write(2, "\n", 1);
exit(rv ? 1 : 2);
}
static char *abuf, *bbuf;
@ -1455,8 +1460,12 @@ static void validate(int afd, int bfd, unsigned long long offset)
free(abuf);
free(bbuf);
abuflen = len;
posix_memalign((void**)&abuf, 4096, abuflen);
posix_memalign((void**)&bbuf, 4096, abuflen);
if (posix_memalign((void**)&abuf, 4096, abuflen) ||
posix_memalign((void**)&bbuf, 4096, abuflen)) {
abuflen = 0;
/* just stop validating on mem-alloc failure */
return;
}
}
lseek64(bfd, offset, 0);
@ -1511,7 +1520,9 @@ static int child_grow(int afd, struct mdinfo *sra, unsigned long stripes,
char *buf;
int degraded = 0;
posix_memalign((void**)&buf, 4096, disks * chunk);
if (posix_memalign((void**)&buf, 4096, disks * chunk))
/* Don't start the 'reshape' */
return 0;
sysfs_set_num(sra, NULL, "suspend_hi", 0);
sysfs_set_num(sra, NULL, "suspend_lo", 0);
grow_backup(sra, 0, stripes,
@ -1539,7 +1550,8 @@ static int child_shrink(int afd, struct mdinfo *sra, unsigned long stripes,
int rv;
int degraded = 0;
posix_memalign((void**)&buf, 4096, disks * chunk);
if (posix_memalign((void**)&buf, 4096, disks * chunk))
return 0;
start = sra->component_size - stripes * chunk/512;
sysfs_set_num(sra, NULL, "sync_max", start);
sysfs_set_str(sra, NULL, "sync_action", "reshape");
@ -1578,7 +1590,8 @@ static int child_same_size(int afd, struct mdinfo *sra, unsigned long stripes,
int degraded = 0;
posix_memalign((void**)&buf, 4096, disks * chunk);
if (posix_memalign((void**)&buf, 4096, disks * chunk))
return 0;
sysfs_set_num(sra, NULL, "suspend_lo", 0);
sysfs_set_num(sra, NULL, "suspend_hi", 0);

View File

@ -97,6 +97,10 @@ MON_OBJS = mdmon.o monitor.o managemon.o util.o mdstat.o sysfs.o config.o \
super-ddf.o sha1.o crc32.o msg.o bitmap.o \
platform-intel.o probe_roms.o
MON_SRCS = mdmon.c monitor.c managemon.c util.c mdstat.c sysfs.c config.c \
Kill.c sg_io.c dlink.c ReadMe.c super0.c super1.c super-intel.c \
super-ddf.c sha1.c crc32.c msg.c bitmap.c \
platform-intel.c probe_roms.c
STATICSRC = pwgr.c
STATICOBJS = pwgr.o
@ -138,8 +142,11 @@ mdadm.klibc : $(SRCS) mdadm.h
mdadm.Os : $(SRCS) mdadm.h
$(CC) -o mdadm.Os $(CFLAGS) -DHAVE_STDINT_H -Os $(SRCS)
mdadm.O2 : $(SRCS) mdadm.h
$(CC) -o mdadm.O2 $(CFLAGS) -DHAVE_STDINT_H -O2 $(SRCS)
mdadm.O2 : $(SRCS) mdadm.h mdmon.O2
$(CC) -o mdadm.O2 $(CFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(SRCS)
mdmon.O2 : $(MON_SRCS) mdadm.h mdmon.h
$(CC) -o mdmon.O2 $(CFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(MON_SRCS)
mdmon : $(MON_OBJS)
$(CC) $(LDFLAGS) -o mdmon $(MON_OBJS) $(LDLIBS)

View File

@ -176,7 +176,10 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
fl = fcntl(sock, F_GETFL, 0);
fl &= ~O_NONBLOCK;
fcntl(sock, F_SETFL, fl);
read(sock, buf, 100);
n = read(sock, buf, 100);
/* Ignore result, it is just the wait that
* matters
*/
}
void remove_pidfile(char *devname)

View File

@ -565,7 +565,8 @@ int restore_stripes(int *dest, unsigned long long *offsets,
int data_disks = raid_disks - (level == 0 ? 0 : level <= 5 ? 1 : 2);
posix_memalign((void**)&stripe_buf, 4096, raid_disks * chunk_size);
if (posix_memalign((void**)&stripe_buf, 4096, raid_disks * chunk_size))
stripe_buf = NULL;
if (zero == NULL) {
zero = malloc(chunk_size);
if (zero)