19 #include <sys/types.h> 21 #include <sys/ioctl.h> 23 #include <sys/ioccom.h> 27 #define MIN(a,b) (((a)<(b))?(a):(b)) 28 #define MAX(a,b) (((a)>(b))?(a):(b)) 33 #define KMR_LOV_MAGIC_V1 0x0BD10BD0 34 #define KMR_LOV_MAGIC_V3 0x0BD30BD0 35 #define KMR_LOV_USER_MAGIC_OST_INDEX 0x0BD70BD0 36 #define KMR_LOV_PATTERN_RAID0 0x001 38 #define KMR_OST_MAX_PRECREATE 20000 46 uint16_t stripe_count;
47 uint16_t stripe_offset;
65 uint16_t o[KMR_OST_MAX_PRECREATE];
68 #define KMR_IOC_MDC_GETFILESTRIPE _IOWR('i', 21, struct kmr_lov_md_ost *) 69 #define KMR_IOC_MDC_GETINFO _IOWR('i', 23, struct kmr_lov_md_ostidx *) 84 int *err, _Bool debug_and_dump)
86 #if defined(__linux__) 94 perror(
"malloc(lov_user_md)");
103 fd = open(dir, O_RDONLY);
104 }
while (fd == -1 && errno == EINTR);
107 if (debug_and_dump) {
109 snprintf(ee,
sizeof(ee),
"open(%s)", dir);
117 strcpy((
void *)lov1, file);
118 cc = ioctl(fd, KMR_IOC_MDC_GETFILESTRIPE, (
void *)lov1);
120 cc = ioctl(fd, KMR_IOC_MDC_GETINFO, (
void *)lov7);
122 }
while (cc == -1 && errno == EINTR);
125 if (debug_and_dump) {
127 snprintf(ee,
sizeof(ee),
"ioctl(%s|%s)",
128 dir, (file == 0 ?
"." : file));
142 if (!(md->magic == KMR_LOV_MAGIC_V1
143 || md->magic == KMR_LOV_MAGIC_V3
144 || md->magic == KMR_LOV_USER_MAGIC_OST_INDEX)) {
146 if (debug_and_dump) {
148 snprintf(ee,
sizeof(ee),
149 "Not Lustre FS (%s/%s), bad magic (%x)",
150 dir, (file == 0 ?
"." : file), md->magic);
151 fprintf(stderr,
"%s\n", ee);
157 if (md->magic == KMR_LOV_MAGIC_V3) {
158 if (debug_and_dump) {
160 snprintf(ee,
sizeof(ee),
161 "Lustre FS (%s/%s), bad version (%x)",
162 dir, (file == 0 ?
"." : file), md->magic);
163 fprintf(stderr,
"%s\n", ee);
169 assert(md->magic == KMR_LOV_MAGIC_V1
170 || md->magic == KMR_LOV_USER_MAGIC_OST_INDEX);
171 if (md->pattern != KMR_LOV_PATTERN_RAID0) {
172 if (debug_and_dump) {
174 snprintf(ee,
sizeof(ee),
175 "Lustre FS (%s/%s), bad pattern (%x)",
176 dir, (file == 0 ?
"." : file), md->pattern);
177 fprintf(stderr,
"%s\n", ee);
184 uint16_t *o7 = &lov7->o[0];
185 if (debug_and_dump) {
186 fprintf(stderr,
"lov_user_md(%s)=\n", (file != 0 ?
"file" :
"dir"));
187 fprintf(stderr,
"magic=%x\n", md->magic);
188 fprintf(stderr,
"pattern=%x\n", md->pattern);
189 fprintf(stderr,
"id=%lx\n", md->id);
190 fprintf(stderr,
"gr=%lx\n", md->gr);
191 fprintf(stderr,
"stripe_size=%ud\n", md->stripe_size);
192 fprintf(stderr,
"stripe_count=%d\n", md->stripe_count);
193 fprintf(stderr,
"stripe_offset=%d\n", md->stripe_offset);
194 if (md->magic == KMR_LOV_MAGIC_V1) {
195 for (
int i = 0; i < md->stripe_count; i++) {
196 fprintf(stderr,
"[%d] id=%lud gr=%lud gen=%ud idx=%ud\n",
197 i, o1[i].
id, o1[i].gr, o1[i].gen, o1[i].idx);
199 }
else if (md->magic == KMR_LOV_USER_MAGIC_OST_INDEX) {
200 for (
int i = 0; i < md->stripe_count; i++) {
201 fprintf(stderr,
"[%d] idx=%d\n", i, o7[i]);
207 assert(md->stripe_count < 20000);
208 stripe->s.size = md->stripe_size;
209 stripe->s.count = md->stripe_count;
210 stripe->s.offset = md->stripe_offset;
211 if (md->magic == KMR_LOV_MAGIC_V1) {
212 for (
int i = 0; i < md->stripe_count; i++) {
213 assert(o1[i].idx < USHRT_MAX);
214 stripe->obdidx[i] = (uint16_t)o1[i].idx;
216 }
else if (md->magic == KMR_LOV_USER_MAGIC_OST_INDEX) {
217 for (
int i = 0; i < md->stripe_count; i++) {
218 stripe->obdidx[i] = o7[i];
225 #elif defined(__APPLE__) && defined(__MACH__) 228 #elif defined(__SVR4) 242 kmr_readin(
char *f,
char *b,
int sz)
245 int fd = open(f, O_RDONLY, 0);
249 cc = read(fd, &b[ii], (sz - ii));
266 main(
int argc,
char **argv)
268 static char b[8 * 1024];
270 MPI_Init(&argc, &argv);
272 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
273 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
274 MPI_Barrier(MPI_COMM_WORLD);
279 printf(
"print ost of shared directory on each rank.\n");
283 MPI_Barrier(MPI_COMM_WORLD);
285 for (
int i = 0; i < nprocs; i++) {
287 kmr_readin(
"/proc/tofu/position", b,
sizeof(b));
288 printf(
"rank=%d position=%s\n", rank, b);
292 printf(
"[%04d] rankdirfile=./a.out stripe_count=%d\n",
294 for (
int j = 0; j < stripe.count; j++) {
295 printf(
"[%04d] idx=%d\n", rank, stripe.obdidx[j]);
301 printf(
"[%04d] sharedir=.. stripe_count=%d\n",
303 for (
int j = 0; j < stripe.count; j++) {
304 printf(
"[%04d] idx=%d\n", rank, stripe.obdidx[j]);
310 MPI_Barrier(MPI_COMM_WORLD);
314 int fd = open(
"../aho", O_WRONLY, O_CREAT, 0);
320 printf(
"[%04d] sharedir=../aho stripe_count=%d\n",
322 for (
int j = 0; j < stripe.count; j++) {
323 printf(
"[%04d] idx=%d\n", rank, stripe.obdidx[j]);
328 MPI_Barrier(MPI_COMM_WORLD);
Lustre Striping Information with OBDIDX.
int kmr_fefs_get_stripe(const char *dir, const char *file, struct kmr_fefs_stripe *stripe, int *err, _Bool debug_and_dump)
Gets the OBDIDX information on the file or directory.
Lustre File System (or Fujitsu FEFS) Support.