10 /****************** Custom includes ********************/
11 #include <linux/lustre_lite.h>
12 #include <linux/lustre_idl.h>
15 /****************** Functions ******************/
16 int write_file(char *name, struct lov_mds_md *striping, int bufsize,
17 char *buf1, char *buf2);
20 /************************ Main **********************/
22 #define STRIPE_SIZE 128 * 1024
24 int main(int argc, char *argv[])
26 struct lov_mds_md a_striping;
27 long bufsize = sizeof(long) * STRIPE_SIZE;
32 rbuf = malloc(bufsize);
33 wbuf = malloc(bufsize);
35 fprintf(stderr, "%s: unable to allocate buffers\n", argv[0]);
39 /* Initialize to an easily-verified pattern */
40 for (data = 0, dp = (int *)wbuf; data < STRIPE_SIZE; data++, dp++)
43 /* Init defaults on striping info */
44 a_striping.lmm_magic = LOV_MAGIC;
45 a_striping.lmm_stripe_size = STRIPE_SIZE;
46 a_striping.lmm_stripe_pattern = 0;
48 /* Write file for OST1 only */
49 /* Start at OST 0, and use only 1 OST */
50 a_striping.lmm_stripe_offset = 0;
51 a_striping.lmm_stripe_count = 1;
53 result = write_file("/mnt/lustre/ost1", &a_striping, bufsize,
59 /* Write file for OST2 only */
60 /* Start at OST 1, and use only 1 OST */
61 a_striping.lmm_stripe_offset = 1;
62 a_striping.lmm_stripe_count = 1;
64 result = write_file("/mnt/lustre/ost2", &a_striping, bufsize,
70 /* Write file across both OST1 and OST2 */
71 /* Start at OST 0, and use only 2 OSTs */
72 a_striping.lmm_stripe_offset = 0;
73 a_striping.lmm_stripe_count = 2;
75 result = write_file("/mnt/lustre/ost1and2", &a_striping, bufsize,
88 int write_file(char *name, struct lov_mds_md *striping, int bufsize,
89 char *wbuf, char *rbuf)
93 printf("opening %s\n", name);
94 fd = open(name, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644);
96 fprintf(stderr, "\nUnable to open '%s': %s\n",
97 name, strerror(errno));
101 printf("setting stripe data on %s\n", name);
102 result = ioctl(fd, LL_IOC_LOV_SETSTRIPE, striping);
104 fprintf(stderr, "\nError on ioctl for '%s' (%d): %s\n",
105 name, fd, strerror(errno));
110 /* Write bogus data */
111 printf("writing data to %s\n", name);
112 result = write(fd, wbuf, bufsize);
114 fprintf(stderr, "\nerror: writing data to '%s' (%d): %s\n",
115 name, fd, strerror(errno));
120 if (result != bufsize) {
121 fprintf(stderr, "\nerror: short write to '%s' (%d): %d != %d\n",
122 name, fd, result, bufsize);
127 /* Seek to beginning again */
128 printf("seeking in %s\n", name);
129 result = lseek(fd, 0, SEEK_SET);
131 fprintf(stderr, "\nerror: seeking to beginning '%s' (%d): %s\n",
132 name, fd, strerror(errno));
137 /* Read bogus data back */
138 printf("reading data from %s\n", name);
139 result = read(fd, rbuf, bufsize);
141 fprintf(stderr, "\nerror: reading data from '%s' (%d): %s\n",
142 name, fd, strerror(errno));
147 if (result != bufsize) {
148 fprintf(stderr,"\nerror: short read from '%s' (%d): %d != %d\n",
149 name, fd, result, bufsize);
154 if (memcmp(wbuf, rbuf, bufsize)) {
155 fprintf(stderr, "\nerror: comparing data in '%s' (%d): %s\n",
156 name, fd, strerror(errno));