Whamcloud - gitweb
file configurable-x86-stack-2.4.22-rh.patch was initially added on branch b_devel.
[fs/lustre-release.git] / lustre / utils / lstripe.c
1 #include <ctype.h>
2 #include <errno.h>
3 #include <fcntl.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/ioctl.h>
8 #include <unistd.h>
9
10
11 /****************** Custom includes ********************/
12 #include <linux/lustre_lite.h>
13 #include <linux/lustre_idl.h>
14
15
16 /******************  Functions ******************/
17
18 void usage(char *prog)
19 {
20         fprintf(stderr, "usage: %s <filename> <stripe size> <stripe start> "
21                         "<stripe count>\n", prog);
22
23         fprintf(stderr,
24                 "\tstripe size: number of bytes in each stripe (0 default)\n");
25         fprintf(stderr,
26                 "\tstripe start: OST index of first stripe (-1 default)\n");
27         fprintf(stderr,
28                 "\tstripe count: number of OSTs to stripe over (0 default)\n");
29 }
30
31 int create_file(char *name, long stripe_size, int stripe_offset,
32                 int stripe_count)
33 {
34         struct lov_mds_md a_striping;
35         int fd, result = 0;
36
37         /*  Initialize IOCTL striping pattern structure  */
38         a_striping.lmm_magic = LOV_MAGIC;
39         a_striping.lmm_stripe_size = stripe_size;
40         a_striping.lmm_stripe_offset = stripe_offset;
41         a_striping.lmm_stripe_count = stripe_count;
42
43         fd = open(name, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644);
44         if (fd < 0) {
45                 fprintf(stderr, "\nUnable to open '%s': %s\n",
46                         name, strerror(errno));
47                 result = -errno;
48         } else if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, &a_striping)) {
49                 char *errmsg = "stripe already set";
50
51                 if (errno != EEXIST && errno != EALREADY)
52                         errmsg = strerror(errno);
53
54                 fprintf(stderr, "\nError on ioctl for '%s' (%d): %s\n",
55                         name, fd, errmsg);
56                 result = -errno;
57         } else if (close(fd) < 0) {
58                 fprintf(stderr, "\nError on close for '%s' (%d): %s\n",
59                         name, fd, strerror(errno));
60                 result = -errno;
61         }
62
63         return result;
64 }
65
66 int main(int argc, char *argv[])
67 {
68         int result;
69         long st_size;
70         int  st_offset,
71              st_count;
72         char *end;
73
74         /*  Check to make sure we have enough parameters  */
75         if (argc != 5) {
76                 usage(argv[0]);
77                 return 1;
78         }
79
80         /* Get the stripe size */
81         st_size = strtoul(argv[2], &end, 0);
82         if (*end != '\0') {
83                 fprintf(stderr, "bad stripe size '%s'\n", argv[2]);
84                 usage(argv[0]);
85                 return 2;
86         }
87
88         /*
89         if (st_size & 4095) {
90                 fprintf(stderr, "stripe size must be multiple of page size\n");
91                 usage(argv[0]);
92                 return 3;
93         }
94         */
95
96         /* Get the stripe offset*/
97         st_offset = strtoul(argv[3], &end, 0);
98         if (*end != '\0') {
99                 fprintf(stderr, "bad stripe offset '%s'\n", argv[3]);
100                 usage(argv[0]);
101                 return 4;
102         }
103
104         /* Get the stripe count */
105         st_count = strtoul(argv[4], &end, 0);
106         if (*end != '\0') {
107                 fprintf(stderr, "bad stripe count '%s'\n", argv[4]);
108                 usage(argv[0]);
109                 return 5;
110         }
111
112         /*  Create the file, as specified.  Return and display any errors.  */
113         result = create_file(argv[1], st_size, st_offset, st_count);
114
115         return result;
116 }