Whamcloud - gitweb
17a9b7ea9ac29c9d60f8ab0e989e6cfa453d3809
[fs/lustre-release.git] / lustre / lov / lov_ea.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/lov/lov_ea.c
33  *
34  * Author: Wang Di <wangdi@clusterfs.com>
35  */
36
37 #define DEBUG_SUBSYSTEM S_LOV
38
39 #include <linux/math64.h>
40 #include <linux/sort.h>
41 #include <libcfs/libcfs.h>
42
43 #include <obd_class.h>
44 #include "lov_internal.h"
45
46 static inline void
47 lu_extent_le_to_cpu(struct lu_extent *dst, const struct lu_extent *src)
48 {
49         dst->e_start = le64_to_cpu(src->e_start);
50         dst->e_end = le64_to_cpu(src->e_end);
51 }
52
53 /*
54  * Find minimum stripe maxbytes value.  For inactive or
55  * reconnecting targets use LUSTRE_EXT3_STRIPE_MAXBYTES.
56  */
57 static loff_t lov_tgt_maxbytes(struct lov_tgt_desc *tgt)
58 {
59         struct obd_import *imp;
60         loff_t maxbytes = LUSTRE_EXT3_STRIPE_MAXBYTES;
61
62         if (!tgt->ltd_active)
63                 return maxbytes;
64
65         imp = tgt->ltd_obd->u.cli.cl_import;
66         if (!imp)
67                 return maxbytes;
68
69         spin_lock(&imp->imp_lock);
70         if ((imp->imp_state == LUSTRE_IMP_FULL ||
71             imp->imp_state == LUSTRE_IMP_IDLE) &&
72             (imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_MAXBYTES) &&
73             imp->imp_connect_data.ocd_maxbytes > 0)
74                 maxbytes = imp->imp_connect_data.ocd_maxbytes;
75
76         spin_unlock(&imp->imp_lock);
77
78         return maxbytes;
79 }
80
81 static int lsm_lmm_verify_v1v3(struct lov_mds_md *lmm, size_t lmm_size,
82                                u16 stripe_count)
83 {
84         u32 pattern = le32_to_cpu(lmm->lmm_pattern);
85         int rc = 0;
86
87         if (stripe_count > LOV_V1_INSANE_STRIPE_COUNT) {
88                 rc = -EINVAL;
89                 CERROR("lov: bad stripe count %d: rc = %d\n",
90                        stripe_count, rc);
91                 lov_dump_lmm_common(D_WARNING, lmm);
92                 goto out;
93         }
94
95         if (lmm_oi_id(&lmm->lmm_oi) == 0) {
96                 rc = -EINVAL;
97                 CERROR("lov: zero object id: rc = %d\n", rc);
98                 lov_dump_lmm_common(D_WARNING, lmm);
99                 goto out;
100         }
101
102         if (!lov_pattern_supported(lov_pattern(pattern))) {
103                 rc = -EINVAL;
104                 CERROR("lov: unrecognized striping pattern: rc = %d\n", rc);
105                 lov_dump_lmm_common(D_WARNING, lmm);
106                 goto out;
107         }
108
109         if (lmm->lmm_stripe_size == 0 ||
110             (le32_to_cpu(lmm->lmm_stripe_size)&(LOV_MIN_STRIPE_SIZE-1)) != 0) {
111                 rc = -EINVAL;
112                 CERROR("lov: bad stripe size %u: rc = %d\n",
113                        le32_to_cpu(lmm->lmm_stripe_size), rc);
114                 lov_dump_lmm_common(D_WARNING, lmm);
115                 goto out;
116         }
117
118 out:
119         return rc;
120 }
121
122 static void lsme_free(struct lov_stripe_md_entry *lsme)
123 {
124         unsigned int stripe_count = lsme->lsme_stripe_count;
125         unsigned int i;
126         size_t lsme_size;
127
128         if (!lsme_inited(lsme) ||
129             lsme->lsme_pattern & LOV_PATTERN_F_RELEASED)
130                 stripe_count = 0;
131         for (i = 0; i < stripe_count; i++)
132                 OBD_SLAB_FREE_PTR(lsme->lsme_oinfo[i], lov_oinfo_slab);
133
134         lsme_size = offsetof(typeof(*lsme), lsme_oinfo[stripe_count]);
135         OBD_FREE_LARGE(lsme, lsme_size);
136 }
137
138 void lsm_free(struct lov_stripe_md *lsm)
139 {
140         unsigned int entry_count = lsm->lsm_entry_count;
141         unsigned int i;
142         size_t lsm_size;
143
144         if (lsm->lsm_magic == LOV_MAGIC_FOREIGN) {
145                 OBD_FREE_LARGE(lsm_foreign(lsm), lsm->lsm_foreign_size);
146         } else {
147                 for (i = 0; i < entry_count; i++)
148                         lsme_free(lsm->lsm_entries[i]);
149         }
150
151         lsm_size = lsm->lsm_magic == LOV_MAGIC_FOREIGN ?
152                    offsetof(typeof(*lsm), lsm_entries[1]) :
153                    offsetof(typeof(*lsm), lsm_entries[entry_count]);
154         OBD_FREE(lsm, lsm_size);
155 }
156
157 /**
158  * Unpack a struct lov_mds_md into a struct lov_stripe_md_entry.
159  *
160  * The caller should set id and extent.
161  */
162 static struct lov_stripe_md_entry *
163 lsme_unpack(struct lov_obd *lov, struct lov_mds_md *lmm, size_t buf_size,
164             const char *pool_name, bool inited, struct lov_ost_data_v1 *objects,
165             loff_t *maxbytes)
166 {
167         struct lov_stripe_md_entry *lsme;
168         size_t lsme_size;
169         loff_t min_stripe_maxbytes = 0;
170         loff_t lov_bytes;
171         u32 magic;
172         u32 pattern;
173         unsigned int stripe_count;
174         unsigned int i;
175         int rc;
176
177         magic = le32_to_cpu(lmm->lmm_magic);
178         if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3)
179                 RETURN(ERR_PTR(-EINVAL));
180
181         pattern = le32_to_cpu(lmm->lmm_pattern);
182         if (pattern & LOV_PATTERN_F_RELEASED || !inited)
183                 stripe_count = 0;
184         else
185                 stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
186
187         if (buf_size < (magic == LOV_MAGIC_V1 ? sizeof(struct lov_mds_md_v1) :
188                                                 sizeof(struct lov_mds_md_v3))) {
189                 CERROR("LOV EA %s too small: %zu, need %u\n",
190                        magic == LOV_MAGIC_V1 ? "V1" : "V3", buf_size,
191                        lov_mds_md_size(stripe_count, magic == LOV_MAGIC_V1 ?
192                                        LOV_MAGIC_V1 : LOV_MAGIC_V3));
193                 lov_dump_lmm_common(D_WARNING, lmm);
194                 return ERR_PTR(-EINVAL);
195         }
196
197         rc = lsm_lmm_verify_v1v3(lmm, buf_size, stripe_count);
198         if (rc < 0)
199                 return ERR_PTR(rc);
200
201         lsme_size = offsetof(typeof(*lsme), lsme_oinfo[stripe_count]);
202         OBD_ALLOC_LARGE(lsme, lsme_size);
203         if (!lsme)
204                 RETURN(ERR_PTR(-ENOMEM));
205
206         lsme->lsme_magic = magic;
207         lsme->lsme_pattern = pattern;
208         lsme->lsme_flags = 0;
209         lsme->lsme_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
210         /* preserve the possible -1 stripe count for uninstantiated component */
211         lsme->lsme_stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
212         lsme->lsme_layout_gen = le16_to_cpu(lmm->lmm_layout_gen);
213
214         if (pool_name) {
215                 size_t pool_name_len;
216
217                 pool_name_len = strlcpy(lsme->lsme_pool_name, pool_name,
218                                         sizeof(lsme->lsme_pool_name));
219                 if (pool_name_len >= sizeof(lsme->lsme_pool_name))
220                         GOTO(out_lsme, rc = -E2BIG);
221         }
222
223         /* with Data-on-MDT set maxbytes to stripe size */
224         if (lsme_is_dom(lsme)) {
225                 if (maxbytes) {
226                         lov_bytes = lsme->lsme_stripe_size;
227                         goto out_dom1;
228                 } else {
229                         goto out_dom2;
230                 }
231         }
232
233         for (i = 0; i < stripe_count; i++) {
234                 struct lov_oinfo *loi;
235                 struct lov_tgt_desc *ltd;
236
237                 OBD_SLAB_ALLOC_PTR_GFP(loi, lov_oinfo_slab, GFP_NOFS);
238                 if (!loi)
239                         GOTO(out_lsme, rc = -ENOMEM);
240
241                 lsme->lsme_oinfo[i] = loi;
242
243                 ostid_le_to_cpu(&objects[i].l_ost_oi, &loi->loi_oi);
244                 loi->loi_ost_idx = le32_to_cpu(objects[i].l_ost_idx);
245                 loi->loi_ost_gen = le32_to_cpu(objects[i].l_ost_gen);
246                 if (lov_oinfo_is_dummy(loi))
247                         continue;
248
249                 if (loi->loi_ost_idx >= lov->desc.ld_tgt_count &&
250                     !lov2obd(lov)->obd_process_conf) {
251                         CERROR("%s: OST index %d more than OST count %d\n",
252                                (char*)lov->desc.ld_uuid.uuid,
253                                loi->loi_ost_idx, lov->desc.ld_tgt_count);
254                         lov_dump_lmm_v1(D_WARNING, lmm);
255                         GOTO(out_lsme, rc = -EINVAL);
256                 }
257
258                 ltd = lov->lov_tgts[loi->loi_ost_idx];
259                 if (!ltd) {
260                         CERROR("%s: OST index %d missing\n",
261                                (char*)lov->desc.ld_uuid.uuid, loi->loi_ost_idx);
262                         lov_dump_lmm_v1(D_WARNING, lmm);
263                         continue;
264                 }
265
266                 lov_bytes = lov_tgt_maxbytes(ltd);
267                 if (min_stripe_maxbytes == 0 || lov_bytes < min_stripe_maxbytes)
268                         min_stripe_maxbytes = lov_bytes;
269         }
270
271         if (maxbytes) {
272                 if (min_stripe_maxbytes == 0)
273                         min_stripe_maxbytes = LUSTRE_EXT3_STRIPE_MAXBYTES;
274
275                 if (stripe_count == 0)
276                         stripe_count = lov->desc.ld_tgt_count;
277
278                 if (min_stripe_maxbytes <= LLONG_MAX / stripe_count)
279                         lov_bytes = min_stripe_maxbytes * stripe_count;
280                 else
281                         lov_bytes = MAX_LFS_FILESIZE;
282 out_dom1:
283                 *maxbytes = min_t(loff_t, lov_bytes, MAX_LFS_FILESIZE);
284         }
285 out_dom2:
286
287         return lsme;
288
289 out_lsme:
290         for (i = 0; i < stripe_count; i++) {
291                 struct lov_oinfo *loi = lsme->lsme_oinfo[i];
292
293                 if (loi)
294                         OBD_SLAB_FREE_PTR(lsme->lsme_oinfo[i], lov_oinfo_slab);
295         }
296         OBD_FREE_LARGE(lsme, lsme_size);
297
298         return ERR_PTR(rc);
299 }
300
301 static struct
302 lov_stripe_md *lsm_unpackmd_v1v3(struct lov_obd *lov, struct lov_mds_md *lmm,
303                                  size_t buf_size, const char *pool_name,
304                                  struct lov_ost_data_v1 *objects)
305 {
306         struct lov_stripe_md *lsm;
307         struct lov_stripe_md_entry *lsme;
308         size_t lsm_size;
309         loff_t maxbytes;
310         u32 pattern;
311         int rc;
312
313         pattern = le32_to_cpu(lmm->lmm_pattern);
314
315         lsme = lsme_unpack(lov, lmm, buf_size, pool_name, true, objects,
316                            &maxbytes);
317         if (IS_ERR(lsme))
318                 RETURN(ERR_CAST(lsme));
319
320         lsme->lsme_flags = LCME_FL_INIT;
321         lsme->lsme_extent.e_start = 0;
322         lsme->lsme_extent.e_end = LUSTRE_EOF;
323
324         lsm_size = offsetof(typeof(*lsm), lsm_entries[1]);
325         OBD_ALLOC(lsm, lsm_size);
326         if (!lsm)
327                 GOTO(out_lsme, rc = -ENOMEM);
328
329         atomic_set(&lsm->lsm_refc, 1);
330         spin_lock_init(&lsm->lsm_lock);
331         lsm->lsm_maxbytes = maxbytes;
332         lmm_oi_le_to_cpu(&lsm->lsm_oi, &lmm->lmm_oi);
333         lsm->lsm_magic = le32_to_cpu(lmm->lmm_magic);
334         lsm->lsm_layout_gen = le16_to_cpu(lmm->lmm_layout_gen);
335         lsm->lsm_entry_count = 1;
336         lsm->lsm_is_released = pattern & LOV_PATTERN_F_RELEASED;
337         lsm->lsm_entries[0] = lsme;
338
339         return lsm;
340
341 out_lsme:
342         lsme_free(lsme);
343
344         return ERR_PTR(rc);
345 }
346
347 static inline struct lov_stripe_md *
348 lsm_unpackmd_v1(struct lov_obd *lov, void *buf, size_t buf_size)
349 {
350         struct lov_mds_md_v1 *lmm = buf;
351
352         return lsm_unpackmd_v1v3(lov, buf, buf_size, NULL, lmm->lmm_objects);
353 }
354
355 const struct lsm_operations lsm_v1_ops = {
356         .lsm_unpackmd           = lsm_unpackmd_v1,
357 };
358
359 static inline
360 struct lov_stripe_md *lsm_unpackmd_v3(struct lov_obd *lov, void *buf,
361                                       size_t buf_size)
362 {
363         struct lov_mds_md_v3 *lmm = buf;
364
365         return lsm_unpackmd_v1v3(lov, buf, buf_size, lmm->lmm_pool_name,
366                                  lmm->lmm_objects);
367 }
368
369 const struct lsm_operations lsm_v3_ops = {
370         .lsm_unpackmd           = lsm_unpackmd_v3,
371 };
372
373 static int lsm_verify_comp_md_v1(struct lov_comp_md_v1 *lcm,
374                                  size_t lcm_buf_size)
375 {
376         unsigned int entry_count;
377         unsigned int i;
378         size_t lcm_size;
379
380         lcm_size = le32_to_cpu(lcm->lcm_size);
381         if (lcm_buf_size < lcm_size) {
382                 CERROR("bad LCM buffer size %zu, expected %zu\n",
383                        lcm_buf_size, lcm_size);
384                 RETURN(-EINVAL);
385         }
386
387         entry_count = le16_to_cpu(lcm->lcm_entry_count);
388         for (i = 0; i < entry_count; i++) {
389                 struct lov_comp_md_entry_v1 *lcme = &lcm->lcm_entries[i];
390                 size_t blob_offset;
391                 size_t blob_size;
392
393                 blob_offset = le32_to_cpu(lcme->lcme_offset);
394                 blob_size = le32_to_cpu(lcme->lcme_size);
395
396                 if (lcm_size < blob_offset || lcm_size < blob_size ||
397                     lcm_size < blob_offset + blob_size) {
398                         CERROR("LCM entry %u has invalid blob: "
399                                "LCM size = %zu, offset = %zu, size = %zu\n",
400                                le32_to_cpu(lcme->lcme_id),
401                                lcm_size, blob_offset, blob_size);
402                         RETURN(-EINVAL);
403                 }
404         }
405
406         return 0;
407 }
408
409 static struct lov_stripe_md_entry *
410 lsme_unpack_comp(struct lov_obd *lov, struct lov_mds_md *lmm,
411                  size_t lmm_buf_size, bool inited, loff_t *maxbytes)
412 {
413         unsigned int magic;
414         unsigned int stripe_count;
415
416         stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
417         if (stripe_count == 0 &&
418             lov_pattern(le32_to_cpu(lmm->lmm_pattern)) != LOV_PATTERN_MDT)
419                 RETURN(ERR_PTR(-EINVAL));
420         /* un-instantiated lmm contains no ost id info, i.e. lov_ost_data_v1 */
421         if (!inited)
422                 stripe_count = 0;
423
424         magic = le32_to_cpu(lmm->lmm_magic);
425         if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3)
426                 RETURN(ERR_PTR(-EINVAL));
427
428         if (lmm_buf_size < lov_mds_md_size(stripe_count, magic))
429                 RETURN(ERR_PTR(-EINVAL));
430
431         if (magic == LOV_MAGIC_V1) {
432                 return lsme_unpack(lov, lmm, lmm_buf_size, NULL,
433                                    inited, lmm->lmm_objects, maxbytes);
434         } else {
435                 struct lov_mds_md_v3 *lmm3 = (struct lov_mds_md_v3 *)lmm;
436
437                 return lsme_unpack(lov, lmm, lmm_buf_size, lmm3->lmm_pool_name,
438                                    inited, lmm3->lmm_objects, maxbytes);
439         }
440 }
441
442 static struct lov_stripe_md *
443 lsm_unpackmd_comp_md_v1(struct lov_obd *lov, void *buf, size_t buf_size)
444 {
445         struct lov_comp_md_v1 *lcm = buf;
446         struct lov_stripe_md *lsm;
447         size_t lsm_size;
448         unsigned int entry_count = 0;
449         unsigned int i;
450         loff_t maxbytes;
451         int rc;
452
453         rc = lsm_verify_comp_md_v1(buf, buf_size);
454         if (rc < 0)
455                 return ERR_PTR(rc);
456
457         entry_count = le16_to_cpu(lcm->lcm_entry_count);
458
459         lsm_size = offsetof(typeof(*lsm), lsm_entries[entry_count]);
460         OBD_ALLOC(lsm, lsm_size);
461         if (!lsm)
462                 return ERR_PTR(-ENOMEM);
463
464         atomic_set(&lsm->lsm_refc, 1);
465         spin_lock_init(&lsm->lsm_lock);
466         lsm->lsm_magic = le32_to_cpu(lcm->lcm_magic);
467         lsm->lsm_layout_gen = le32_to_cpu(lcm->lcm_layout_gen);
468         lsm->lsm_entry_count = entry_count;
469         lsm->lsm_mirror_count = le16_to_cpu(lcm->lcm_mirror_count);
470         lsm->lsm_flags = le16_to_cpu(lcm->lcm_flags);
471         lsm->lsm_is_released = true;
472         lsm->lsm_maxbytes = LLONG_MIN;
473
474         for (i = 0; i < entry_count; i++) {
475                 struct lov_comp_md_entry_v1 *lcme = &lcm->lcm_entries[i];
476                 struct lov_stripe_md_entry *lsme;
477                 size_t blob_offset;
478                 size_t blob_size;
479                 void *blob;
480
481                 blob_offset = le32_to_cpu(lcme->lcme_offset);
482                 blob_size = le32_to_cpu(lcme->lcme_size);
483                 blob = (char *)lcm + blob_offset;
484
485                 lsme = lsme_unpack_comp(lov, blob, blob_size,
486                                         le32_to_cpu(lcme->lcme_flags) &
487                                         LCME_FL_INIT,
488                                         (i == entry_count - 1) ? &maxbytes :
489                                                                  NULL);
490                 if (IS_ERR(lsme))
491                         GOTO(out_lsm, rc = PTR_ERR(lsme));
492
493                 if (!(lsme->lsme_pattern & LOV_PATTERN_F_RELEASED))
494                         lsm->lsm_is_released = false;
495
496                 lsm->lsm_entries[i] = lsme;
497                 lsme->lsme_id = le32_to_cpu(lcme->lcme_id);
498                 lsme->lsme_flags = le32_to_cpu(lcme->lcme_flags);
499                 if (lsme->lsme_flags & LCME_FL_NOSYNC)
500                         lsme->lsme_timestamp =
501                                 le64_to_cpu(lcme->lcme_timestamp);
502                 lu_extent_le_to_cpu(&lsme->lsme_extent, &lcme->lcme_extent);
503
504                 if (i == entry_count - 1) {
505                         lsm->lsm_maxbytes = (loff_t)lsme->lsme_extent.e_start +
506                                             maxbytes;
507                         /*
508                          * the last component hasn't been defined, or
509                          * lsm_maxbytes overflowed.
510                          */
511                         if (!lsme_is_dom(lsme) &&
512                             (lsme->lsme_extent.e_end != LUSTRE_EOF ||
513                              lsm->lsm_maxbytes <
514                              (loff_t)lsme->lsme_extent.e_start))
515                                 lsm->lsm_maxbytes = MAX_LFS_FILESIZE;
516                 }
517         }
518
519         RETURN(lsm);
520
521 out_lsm:
522         for (i = 0; i < entry_count; i++)
523                 if (lsm->lsm_entries[i])
524                         lsme_free(lsm->lsm_entries[i]);
525
526         OBD_FREE(lsm, lsm_size);
527
528         RETURN(ERR_PTR(rc));
529 }
530
531 const struct lsm_operations lsm_comp_md_v1_ops = {
532         .lsm_unpackmd         = lsm_unpackmd_comp_md_v1,
533 };
534
535 static struct
536 lov_stripe_md *lsm_unpackmd_foreign(struct lov_obd *lov, void *buf,
537                                     size_t buf_size)
538 {
539         struct lov_foreign_md *lfm = buf;
540         struct lov_stripe_md *lsm;
541         size_t lsm_size;
542         struct lov_stripe_md_entry *lsme;
543
544         lsm_size = offsetof(typeof(*lsm), lsm_entries[1]);
545         OBD_ALLOC(lsm, lsm_size);
546         if (lsm == NULL)
547                 RETURN(ERR_PTR(-ENOMEM));
548
549         atomic_set(&lsm->lsm_refc, 1);
550         spin_lock_init(&lsm->lsm_lock);
551         lsm->lsm_magic = le32_to_cpu(lfm->lfm_magic);
552         lsm->lsm_foreign_size = foreign_size_le(lfm);
553
554         /* alloc for full foreign EA including format fields */
555         OBD_ALLOC_LARGE(lsme, lsm->lsm_foreign_size);
556         if (lsme == NULL) {
557                 OBD_FREE(lsm, lsm_size);
558                 RETURN(ERR_PTR(-ENOMEM));
559         }
560
561         /* copy full foreign EA including format fields */
562         memcpy(lsme, buf, lsm->lsm_foreign_size);
563
564         lsm_foreign(lsm) = lsme;
565
566         return lsm;
567 }
568
569 const struct lsm_operations lsm_foreign_ops = {
570         .lsm_unpackmd         = lsm_unpackmd_foreign,
571 };
572
573 void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm)
574 {
575         int i, j;
576
577         CDEBUG_LIMIT(level,
578                      "lsm %p, objid "DOSTID", maxbytes %#llx, magic 0x%08X, refc: %d, entry: %u, layout_gen %u\n",
579                lsm, POSTID(&lsm->lsm_oi), lsm->lsm_maxbytes, lsm->lsm_magic,
580                atomic_read(&lsm->lsm_refc), lsm->lsm_entry_count,
581                lsm->lsm_layout_gen);
582
583         if (lsm->lsm_magic == LOV_MAGIC_FOREIGN) {
584                 struct lov_foreign_md *lfm = (void *)lsm_foreign(lsm);
585
586                 CDEBUG_LIMIT(level,
587                              "foreign LOV EA, magic %x, length %u, type %x, flags %x, value '%.*s'\n",
588                        lfm->lfm_magic, lfm->lfm_length, lfm->lfm_type,
589                        lfm->lfm_flags, lfm->lfm_length, lfm->lfm_value);
590                 return;
591         }
592
593         for (i = 0; i < lsm->lsm_entry_count; i++) {
594                 struct lov_stripe_md_entry *lse = lsm->lsm_entries[i];
595
596                 CDEBUG(level, DEXT ": id: %u, flags: %x, "
597                        "magic 0x%08X, layout_gen %u, "
598                        "stripe count %u, sstripe size %u, "
599                        "pool: ["LOV_POOLNAMEF"]\n",
600                        PEXT(&lse->lsme_extent), lse->lsme_id, lse->lsme_flags,
601                        lse->lsme_magic, lse->lsme_layout_gen,
602                        lse->lsme_stripe_count, lse->lsme_stripe_size,
603                        lse->lsme_pool_name);
604                 if (!lsme_inited(lse) ||
605                     lse->lsme_pattern & LOV_PATTERN_F_RELEASED)
606                         continue;
607                 for (j = 0; j < lse->lsme_stripe_count; j++) {
608                         CDEBUG(level, "   oinfo:%p: ostid: "DOSTID
609                                " ost idx: %d gen: %d\n",
610                                lse->lsme_oinfo[j],
611                                POSTID(&lse->lsme_oinfo[j]->loi_oi),
612                                lse->lsme_oinfo[j]->loi_ost_idx,
613                                lse->lsme_oinfo[j]->loi_ost_gen);
614                 }
615         }
616 }
617
618 int lov_lsm_entry(const struct lov_stripe_md *lsm, __u64 offset)
619 {
620         int i;
621
622         for (i = 0; i < lsm->lsm_entry_count; i++) {
623                 struct lov_stripe_md_entry *lse = lsm->lsm_entries[i];
624
625                 if ((offset >= lse->lsme_extent.e_start &&
626                      offset < lse->lsme_extent.e_end) ||
627                     (offset == OBD_OBJECT_EOF &&
628                      lse->lsme_extent.e_end == OBD_OBJECT_EOF))
629                         return i;
630         }
631
632         return -1;
633 }