From c55f037ce1adcde605066e205debab31354700c0 Mon Sep 17 00:00:00 2001 From: adilger Date: Mon, 21 Oct 2002 18:26:53 +0000 Subject: [PATCH] Add permission bits to open(O_CREAT) (b=624321). Add a verifiable data pattern so that we can confirm if data is going to the correct stripe. --- lustre/tests/lovstripe.c | 73 +++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/lustre/tests/lovstripe.c b/lustre/tests/lovstripe.c index 5f004e4..14aa2cf 100644 --- a/lustre/tests/lovstripe.c +++ b/lustre/tests/lovstripe.c @@ -12,18 +12,35 @@ /****************** Functions ******************/ -int write_file( char *name, struct lov_user_md *striping ); +int write_file(char *name, struct lov_user_md *striping, int bufsize, + char *buf1, char *buf2); /************************ Main **********************/ -int main( void ) +#define STRIPE_SIZE 128 * 1024 + +int main(int argc, char *argv[]) { - int result; struct lov_user_md a_striping; + long bufsize = sizeof(long) * STRIPE_SIZE; + char *rbuf, *wbuf; + int data, *dp; + int result; + + rbuf = malloc(bufsize); + wbuf = malloc(bufsize); + if (!rbuf || !wbuf) { + fprintf(stderr, "%s: unable to allocate buffers\n", argv[0]); + return 1; + } + + /* Initialize to an easily-verified pattern */ + for (data = 0, dp = (int *)wbuf; data < STRIPE_SIZE; data++, dp++) + *dp = data; /* Init defaults on striping info */ - a_striping.lum_stripe_size = 128 * 1024; + a_striping.lum_stripe_size = STRIPE_SIZE; a_striping.lum_stripe_pattern = 0; /* Write file for OST1 only */ @@ -31,38 +48,44 @@ int main( void ) a_striping.lum_stripe_offset = 0; a_striping.lum_stripe_count = 1; - result = write_file("/mnt/lustre/ost1", &a_striping); + result = write_file("/mnt/lustre/ost1", &a_striping, bufsize, + wbuf, rbuf); if (result < 0) - exit(-1); + goto out; /* Write file for OST2 only */ /* Start at OST 1, and use only 1 OST */ a_striping.lum_stripe_offset = 1; a_striping.lum_stripe_count = 1; - result = write_file("/mnt/lustre/ost2", &a_striping); + result = write_file("/mnt/lustre/ost2", &a_striping, bufsize, + wbuf, rbuf); if (result < 0) - exit(-1); + goto out; /* Write file across both OST1 and OST2 */ /* Start at OST 0, and use only 2 OSTs */ a_striping.lum_stripe_offset = 0; a_striping.lum_stripe_count = 2; - result = write_file("/mnt/lustre/ost1and2", &a_striping); + result = write_file("/mnt/lustre/ost1and2", &a_striping, bufsize, + wbuf, rbuf); if (result < 0) - exit(-1); + goto out; - return 0; +out: + free(rbuf); + free(wbuf); + return result; } -int write_file(char *name, struct lov_user_md *striping) +int write_file(char *name, struct lov_user_md *striping, int bufsize, + char *wbuf, char *rbuf) { - char buf[262144], buf2[262144]; int fd, result; printf("opening %s\n", name); @@ -70,7 +93,7 @@ int write_file(char *name, struct lov_user_md *striping) if (fd < 0) { fprintf(stderr, "\nUnable to open '%s': %s\n", name, strerror(errno)); - return -1; + return -errno; } printf("setting stripe data on %s\n", name); @@ -79,22 +102,22 @@ int write_file(char *name, struct lov_user_md *striping) fprintf(stderr, "\nError on ioctl for '%s' (%d): %s\n", name, fd, strerror(errno)); close(fd); - return -1; + return -errno; } /* Write bogus data */ printf("writing data to %s\n", name); - result = write(fd, buf, sizeof(buf)); + result = write(fd, wbuf, bufsize); if (result < 0) { fprintf(stderr, "\nerror: writing data to '%s' (%d): %s\n", name, fd, strerror(errno)); close(fd); - return -1; + return -errno; } - if (result != sizeof(buf)) { + if (result != bufsize) { fprintf(stderr, "\nerror: short write to '%s' (%d): %d != %d\n", - name, fd, result, sizeof(buf)); + name, fd, result, bufsize); close(fd); return -1; } @@ -106,27 +129,27 @@ int write_file(char *name, struct lov_user_md *striping) fprintf(stderr, "\nerror: seeking to beginning '%s' (%d): %s\n", name, fd, strerror(errno)); close(fd); - return -1; + return -errno; } /* Read bogus data back */ printf("reading data from %s\n", name); - result = read(fd, buf2, sizeof(buf)); + result = read(fd, rbuf, bufsize); if (result < 0) { fprintf(stderr, "\nerror: reading data from '%s' (%d): %s\n", name, fd, strerror(errno)); close(fd); - return -1; + return -errno; } - if (result != sizeof(buf)) { + if (result != bufsize) { fprintf(stderr,"\nerror: short read from '%s' (%d): %d != %d\n", - name, fd, result, sizeof(buf)); + name, fd, result, bufsize); close(fd); return -1; } - if (memcmp(buf, buf2, sizeof(buf))) { + if (memcmp(wbuf, rbuf, bufsize)) { fprintf(stderr, "\nerror: comparing data in '%s' (%d): %s\n", name, fd, strerror(errno)); close(fd); -- 1.8.3.1