/****************** 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 */
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);
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);
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;
}
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);