Whamcloud - gitweb
LU-9846 lod: Add overstriping support
[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         int rc = 0;
85
86         if (stripe_count > LOV_V1_INSANE_STRIPE_COUNT) {
87                 rc = -EINVAL;
88                 CERROR("lov: bad stripe count %d: rc = %d\n",
89                        stripe_count, rc);
90                 lov_dump_lmm_common(D_WARNING, lmm);
91                 goto out;
92         }
93
94         if (lmm_oi_id(&lmm->lmm_oi) == 0) {
95                 rc = -EINVAL;
96                 CERROR("lov: zero object id: rc = %d\n", rc);
97                 lov_dump_lmm_common(D_WARNING, lmm);
98                 goto out;
99         }
100
101         if (lov_pattern(le32_to_cpu(lmm->lmm_pattern)) != LOV_PATTERN_MDT &&
102             lov_pattern(le32_to_cpu(lmm->lmm_pattern)) != LOV_PATTERN_RAID0 &&
103             lov_pattern(le32_to_cpu(lmm->lmm_pattern)) !=
104                         (LOV_PATTERN_RAID0 | LOV_PATTERN_OVERSTRIPING)) {
105                 rc = -EINVAL;
106                 CERROR("lov: unrecognized striping pattern: rc = %d\n", rc);
107                 lov_dump_lmm_common(D_WARNING, lmm);
108                 goto out;
109         }
110
111         if (lmm->lmm_stripe_size == 0 ||
112             (le32_to_cpu(lmm->lmm_stripe_size)&(LOV_MIN_STRIPE_SIZE-1)) != 0) {
113                 rc = -EINVAL;
114                 CERROR("lov: bad stripe size %u: rc = %d\n",
115                        le32_to_cpu(lmm->lmm_stripe_size), rc);
116                 lov_dump_lmm_common(D_WARNING, lmm);
117                 goto out;
118         }
119
120 out:
121         return rc;
122 }
123
124 static void lsme_free(struct lov_stripe_md_entry *lsme)
125 {
126         unsigned int stripe_count = lsme->lsme_stripe_count;
127         unsigned int i;
128         size_t lsme_size;
129
130         if (!lsme_inited(lsme) ||
131             lsme->lsme_pattern & LOV_PATTERN_F_RELEASED)
132                 stripe_count = 0;
133         for (i = 0; i < stripe_count; i++)
134                 OBD_SLAB_FREE_PTR(lsme->lsme_oinfo[i], lov_oinfo_slab);
135
136         lsme_size = offsetof(typeof(*lsme), lsme_oinfo[stripe_count]);
137         OBD_FREE_LARGE(lsme, lsme_size);
138 }
139
140 void lsm_free(struct lov_stripe_md *lsm)
141 {
142         unsigned int entry_count = lsm->lsm_entry_count;
143         unsigned int i;
144         size_t lsm_size;
145
146         if (lsm->lsm_magic == LOV_MAGIC_FOREIGN) {
147                 OBD_FREE_LARGE(lsm_foreign(lsm), lsm->lsm_foreign_size);
148         } else {
149                 for (i = 0; i < entry_count; i++)
150                         lsme_free(lsm->lsm_entries[i]);
151         }
152
153         lsm_size = lsm->lsm_magic == LOV_MAGIC_FOREIGN ?
154                    offsetof(typeof(*lsm), lsm_entries[1]) :
155                    offsetof(typeof(*lsm), lsm_entries[entry_count]);
156         OBD_FREE(lsm, lsm_size);
157 }
158
159 /**
160  * Unpack a struct lov_mds_md into a struct lov_stripe_md_entry.
161  *
162  * The caller should set id and extent.
163  */
164 static struct lov_stripe_md_entry *
165 lsme_unpack(struct lov_obd *lov, struct lov_mds_md *lmm, size_t buf_size,
166             const char *pool_name, bool inited, struct lov_ost_data_v1 *objects,
167             loff_t *maxbytes)
168 {
169         struct lov_stripe_md_entry *lsme;
170         size_t lsme_size;
171         loff_t min_stripe_maxbytes = 0;
172         loff_t lov_bytes;
173         u32 magic;
174         u32 pattern;
175         unsigned int stripe_count;
176         unsigned int i;
177         int rc;
178
179         magic = le32_to_cpu(lmm->lmm_magic);
180         if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3)
181                 RETURN(ERR_PTR(-EINVAL));
182
183         pattern = le32_to_cpu(lmm->lmm_pattern);
184         if (pattern & LOV_PATTERN_F_RELEASED || !inited)
185                 stripe_count = 0;
186         else
187                 stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
188
189         if (buf_size < (magic == LOV_MAGIC_V1 ? sizeof(struct lov_mds_md_v1) :
190                                                 sizeof(struct lov_mds_md_v3))) {
191                 CERROR("LOV EA %s too small: %zu, need %u\n",
192                        magic == LOV_MAGIC_V1 ? "V1" : "V3", buf_size,
193                        lov_mds_md_size(stripe_count, magic == LOV_MAGIC_V1 ?
194                                        LOV_MAGIC_V1 : LOV_MAGIC_V3));
195                 lov_dump_lmm_common(D_WARNING, lmm);
196                 return ERR_PTR(-EINVAL);
197         }
198
199         rc = lsm_lmm_verify_v1v3(lmm, buf_size, stripe_count);
200         if (rc < 0)
201                 return ERR_PTR(rc);
202
203         lsme_size = offsetof(typeof(*lsme), lsme_oinfo[stripe_count]);
204         OBD_ALLOC_LARGE(lsme, lsme_size);
205         if (!lsme)
206                 RETURN(ERR_PTR(-ENOMEM));
207
208         lsme->lsme_magic = magic;
209         lsme->lsme_pattern = pattern;
210         lsme->lsme_flags = 0;
211         lsme->lsme_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
212         /* preserve the possible -1 stripe count for uninstantiated component */
213         lsme->lsme_stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
214         lsme->lsme_layout_gen = le16_to_cpu(lmm->lmm_layout_gen);
215
216         if (pool_name) {
217                 size_t pool_name_len;
218
219                 pool_name_len = strlcpy(lsme->lsme_pool_name, pool_name,
220                                         sizeof(lsme->lsme_pool_name));
221                 if (pool_name_len >= sizeof(lsme->lsme_pool_name))
222                         GOTO(out_lsme, rc = -E2BIG);
223         }
224
225         /* with Data-on-MDT set maxbytes to stripe size */
226         if (lsme_is_dom(lsme)) {
227                 lov_bytes = lsme->lsme_stripe_size;
228                 goto out_dom;
229         }
230
231         for (i = 0; i < stripe_count; i++) {
232                 struct lov_oinfo *loi;
233                 struct lov_tgt_desc *ltd;
234
235                 OBD_SLAB_ALLOC_PTR_GFP(loi, lov_oinfo_slab, GFP_NOFS);
236                 if (!loi)
237                         GOTO(out_lsme, rc = -ENOMEM);
238
239                 lsme->lsme_oinfo[i] = loi;
240
241                 ostid_le_to_cpu(&objects[i].l_ost_oi, &loi->loi_oi);
242                 loi->loi_ost_idx = le32_to_cpu(objects[i].l_ost_idx);
243                 loi->loi_ost_gen = le32_to_cpu(objects[i].l_ost_gen);
244                 if (lov_oinfo_is_dummy(loi))
245                         continue;
246
247                 if (loi->loi_ost_idx >= lov->desc.ld_tgt_count &&
248                     !lov2obd(lov)->obd_process_conf) {
249                         CERROR("%s: OST index %d more than OST count %d\n",
250                                (char*)lov->desc.ld_uuid.uuid,
251                                loi->loi_ost_idx, lov->desc.ld_tgt_count);
252                         lov_dump_lmm_v1(D_WARNING, lmm);
253                         GOTO(out_lsme, rc = -EINVAL);
254                 }
255
256                 ltd = lov->lov_tgts[loi->loi_ost_idx];
257                 if (!ltd) {
258                         CERROR("%s: OST index %d missing\n",
259                                (char*)lov->desc.ld_uuid.uuid, loi->loi_ost_idx);
260                         lov_dump_lmm_v1(D_WARNING, lmm);
261                         continue;
262                 }
263
264                 lov_bytes = lov_tgt_maxbytes(ltd);
265                 if (min_stripe_maxbytes == 0 || lov_bytes < min_stripe_maxbytes)
266                         min_stripe_maxbytes = lov_bytes;
267         }
268
269         if (min_stripe_maxbytes == 0)
270                 min_stripe_maxbytes = LUSTRE_EXT3_STRIPE_MAXBYTES;
271
272         lov_bytes = min_stripe_maxbytes * stripe_count;
273
274 out_dom:
275         if (maxbytes) {
276                 if (lov_bytes < min_stripe_maxbytes) /* handle overflow */
277                         *maxbytes = MAX_LFS_FILESIZE;
278                 else
279                         *maxbytes = lov_bytes;
280         }
281
282         return lsme;
283
284 out_lsme:
285         for (i = 0; i < stripe_count; i++) {
286                 struct lov_oinfo *loi = lsme->lsme_oinfo[i];
287
288                 if (loi)
289                         OBD_SLAB_FREE_PTR(lsme->lsme_oinfo[i], lov_oinfo_slab);
290         }
291         OBD_FREE_LARGE(lsme, lsme_size);
292
293         return ERR_PTR(rc);
294 }
295
296 static struct
297 lov_stripe_md *lsm_unpackmd_v1v3(struct lov_obd *lov, struct lov_mds_md *lmm,
298                                  size_t buf_size, const char *pool_name,
299                                  struct lov_ost_data_v1 *objects)
300 {
301         struct lov_stripe_md *lsm;
302         struct lov_stripe_md_entry *lsme;
303         size_t lsm_size;
304         loff_t maxbytes;
305         u32 pattern;
306         int rc;
307
308         pattern = le32_to_cpu(lmm->lmm_pattern);
309
310         lsme = lsme_unpack(lov, lmm, buf_size, pool_name, true, objects,
311                            &maxbytes);
312         if (IS_ERR(lsme))
313                 RETURN(ERR_CAST(lsme));
314
315         lsme->lsme_flags = LCME_FL_INIT;
316         lsme->lsme_extent.e_start = 0;
317         lsme->lsme_extent.e_end = LUSTRE_EOF;
318
319         lsm_size = offsetof(typeof(*lsm), lsm_entries[1]);
320         OBD_ALLOC(lsm, lsm_size);
321         if (!lsm)
322                 GOTO(out_lsme, rc = -ENOMEM);
323
324         atomic_set(&lsm->lsm_refc, 1);
325         spin_lock_init(&lsm->lsm_lock);
326         lsm->lsm_maxbytes = maxbytes;
327         lmm_oi_le_to_cpu(&lsm->lsm_oi, &lmm->lmm_oi);
328         lsm->lsm_magic = le32_to_cpu(lmm->lmm_magic);
329         lsm->lsm_layout_gen = le16_to_cpu(lmm->lmm_layout_gen);
330         lsm->lsm_entry_count = 1;
331         lsm->lsm_is_released = pattern & LOV_PATTERN_F_RELEASED;
332         lsm->lsm_entries[0] = lsme;
333
334         return lsm;
335
336 out_lsme:
337         lsme_free(lsme);
338
339         return ERR_PTR(rc);
340 }
341
342 static inline struct lov_stripe_md *
343 lsm_unpackmd_v1(struct lov_obd *lov, void *buf, size_t buf_size)
344 {
345         struct lov_mds_md_v1 *lmm = buf;
346
347         return lsm_unpackmd_v1v3(lov, buf, buf_size, NULL, lmm->lmm_objects);
348 }
349
350 const struct lsm_operations lsm_v1_ops = {
351         .lsm_unpackmd           = lsm_unpackmd_v1,
352 };
353
354 static inline
355 struct lov_stripe_md *lsm_unpackmd_v3(struct lov_obd *lov, void *buf,
356                                       size_t buf_size)
357 {
358         struct lov_mds_md_v3 *lmm = buf;
359
360         return lsm_unpackmd_v1v3(lov, buf, buf_size, lmm->lmm_pool_name,
361                                  lmm->lmm_objects);
362 }
363
364 const struct lsm_operations lsm_v3_ops = {
365         .lsm_unpackmd           = lsm_unpackmd_v3,
366 };
367
368 static int lsm_verify_comp_md_v1(struct lov_comp_md_v1 *lcm,
369                                  size_t lcm_buf_size)
370 {
371         unsigned int entry_count;
372         unsigned int i;
373         size_t lcm_size;
374
375         lcm_size = le32_to_cpu(lcm->lcm_size);
376         if (lcm_buf_size < lcm_size) {
377                 CERROR("bad LCM buffer size %zu, expected %zu\n",
378                        lcm_buf_size, lcm_size);
379                 RETURN(-EINVAL);
380         }
381
382         entry_count = le16_to_cpu(lcm->lcm_entry_count);
383         for (i = 0; i < entry_count; i++) {
384                 struct lov_comp_md_entry_v1 *lcme = &lcm->lcm_entries[i];
385                 size_t blob_offset;
386                 size_t blob_size;
387
388                 blob_offset = le32_to_cpu(lcme->lcme_offset);
389                 blob_size = le32_to_cpu(lcme->lcme_size);
390
391                 if (lcm_size < blob_offset || lcm_size < blob_size ||
392                     lcm_size < blob_offset + blob_size) {
393                         CERROR("LCM entry %u has invalid blob: "
394                                "LCM size = %zu, offset = %zu, size = %zu\n",
395                                le32_to_cpu(lcme->lcme_id),
396                                lcm_size, blob_offset, blob_size);
397                         RETURN(-EINVAL);
398                 }
399         }
400
401         return 0;
402 }
403
404 static struct lov_stripe_md_entry *
405 lsme_unpack_comp(struct lov_obd *lov, struct lov_mds_md *lmm,
406                  size_t lmm_buf_size, bool inited, loff_t *maxbytes)
407 {
408         unsigned int magic;
409         unsigned int stripe_count;
410
411         stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
412         if (stripe_count == 0 &&
413             lov_pattern(le32_to_cpu(lmm->lmm_pattern)) != LOV_PATTERN_MDT)
414                 RETURN(ERR_PTR(-EINVAL));
415         /* un-instantiated lmm contains no ost id info, i.e. lov_ost_data_v1 */
416         if (!inited)
417                 stripe_count = 0;
418
419         magic = le32_to_cpu(lmm->lmm_magic);
420         if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3)
421                 RETURN(ERR_PTR(-EINVAL));
422
423         if (lmm_buf_size < lov_mds_md_size(stripe_count, magic))
424                 RETURN(ERR_PTR(-EINVAL));
425
426         if (magic == LOV_MAGIC_V1) {
427                 return lsme_unpack(lov, lmm, lmm_buf_size, NULL,
428                                    inited, lmm->lmm_objects, maxbytes);
429         } else {
430                 struct lov_mds_md_v3 *lmm3 = (struct lov_mds_md_v3 *)lmm;
431
432                 return lsme_unpack(lov, lmm, lmm_buf_size, lmm3->lmm_pool_name,
433                                    inited, lmm3->lmm_objects, maxbytes);
434         }
435 }
436
437 static struct lov_stripe_md *
438 lsm_unpackmd_comp_md_v1(struct lov_obd *lov, void *buf, size_t buf_size)
439 {
440         struct lov_comp_md_v1 *lcm = buf;
441         struct lov_stripe_md *lsm;
442         size_t lsm_size;
443         unsigned int entry_count = 0;
444         unsigned int i;
445         loff_t maxbytes;
446         int rc;
447
448         rc = lsm_verify_comp_md_v1(buf, buf_size);
449         if (rc < 0)
450                 return ERR_PTR(rc);
451
452         entry_count = le16_to_cpu(lcm->lcm_entry_count);
453
454         lsm_size = offsetof(typeof(*lsm), lsm_entries[entry_count]);
455         OBD_ALLOC(lsm, lsm_size);
456         if (!lsm)
457                 return ERR_PTR(-ENOMEM);
458
459         atomic_set(&lsm->lsm_refc, 1);
460         spin_lock_init(&lsm->lsm_lock);
461         lsm->lsm_magic = le32_to_cpu(lcm->lcm_magic);
462         lsm->lsm_layout_gen = le32_to_cpu(lcm->lcm_layout_gen);
463         lsm->lsm_entry_count = entry_count;
464         lsm->lsm_mirror_count = le16_to_cpu(lcm->lcm_mirror_count);
465         lsm->lsm_flags = le16_to_cpu(lcm->lcm_flags);
466         lsm->lsm_is_released = true;
467         lsm->lsm_maxbytes = LLONG_MIN;
468
469         for (i = 0; i < entry_count; i++) {
470                 struct lov_comp_md_entry_v1 *lcme = &lcm->lcm_entries[i];
471                 struct lov_stripe_md_entry *lsme;
472                 size_t blob_offset;
473                 size_t blob_size;
474                 void *blob;
475
476                 blob_offset = le32_to_cpu(lcme->lcme_offset);
477                 blob_size = le32_to_cpu(lcme->lcme_size);
478                 blob = (char *)lcm + blob_offset;
479
480                 lsme = lsme_unpack_comp(lov, blob, blob_size,
481                                         le32_to_cpu(lcme->lcme_flags) &
482                                         LCME_FL_INIT,
483                                         (i == entry_count - 1) ? &maxbytes :
484                                                                  NULL);
485                 if (IS_ERR(lsme))
486                         GOTO(out_lsm, rc = PTR_ERR(lsme));
487
488                 if (!(lsme->lsme_pattern & LOV_PATTERN_F_RELEASED))
489                         lsm->lsm_is_released = false;
490
491                 lsm->lsm_entries[i] = lsme;
492                 lsme->lsme_id = le32_to_cpu(lcme->lcme_id);
493                 lsme->lsme_flags = le32_to_cpu(lcme->lcme_flags);
494                 if (lsme->lsme_flags & LCME_FL_NOSYNC)
495                         lsme->lsme_timestamp =
496                                 le64_to_cpu(lcme->lcme_timestamp);
497                 lu_extent_le_to_cpu(&lsme->lsme_extent, &lcme->lcme_extent);
498
499                 if (i == entry_count - 1) {
500                         lsm->lsm_maxbytes = (loff_t)lsme->lsme_extent.e_start +
501                                             maxbytes;
502                         /*
503                          * the last component hasn't been defined, or
504                          * lsm_maxbytes overflowed.
505                          */
506                         if (!lsme_is_dom(lsme) &&
507                             (lsme->lsme_extent.e_end != LUSTRE_EOF ||
508                              lsm->lsm_maxbytes <
509                              (loff_t)lsme->lsme_extent.e_start))
510                                 lsm->lsm_maxbytes = MAX_LFS_FILESIZE;
511                 }
512         }
513
514         RETURN(lsm);
515
516 out_lsm:
517         for (i = 0; i < entry_count; i++)
518                 if (lsm->lsm_entries[i])
519                         lsme_free(lsm->lsm_entries[i]);
520
521         OBD_FREE(lsm, lsm_size);
522
523         RETURN(ERR_PTR(rc));
524 }
525
526 const struct lsm_operations lsm_comp_md_v1_ops = {
527         .lsm_unpackmd         = lsm_unpackmd_comp_md_v1,
528 };
529
530 static struct
531 lov_stripe_md *lsm_unpackmd_foreign(struct lov_obd *lov, void *buf,
532                                     size_t buf_size)
533 {
534         struct lov_foreign_md *lfm = buf;
535         struct lov_stripe_md *lsm;
536         size_t lsm_size;
537         struct lov_stripe_md_entry *lsme;
538
539         lsm_size = offsetof(typeof(*lsm), lsm_entries[1]);
540         OBD_ALLOC(lsm, lsm_size);
541         if (lsm == NULL)
542                 RETURN(ERR_PTR(-ENOMEM));
543
544         atomic_set(&lsm->lsm_refc, 1);
545         spin_lock_init(&lsm->lsm_lock);
546         lsm->lsm_magic = le32_to_cpu(lfm->lfm_magic);
547         lsm->lsm_foreign_size = foreign_size_le(lfm);
548
549         /* alloc for full foreign EA including format fields */
550         OBD_ALLOC_LARGE(lsme, lsm->lsm_foreign_size);
551         if (lsme == NULL) {
552                 OBD_FREE(lsm, lsm_size);
553                 RETURN(ERR_PTR(-ENOMEM));
554         }
555
556         /* copy full foreign EA including format fields */
557         memcpy(lsme, buf, lsm->lsm_foreign_size);
558
559         lsm_foreign(lsm) = lsme;
560
561         return lsm;
562 }
563
564 const struct lsm_operations lsm_foreign_ops = {
565         .lsm_unpackmd         = lsm_unpackmd_foreign,
566 };
567
568 void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm)
569 {
570         int i, j;
571
572         CDEBUG_LIMIT(level,
573                      "lsm %p, objid "DOSTID", maxbytes %#llx, magic 0x%08X, refc: %d, entry: %u, layout_gen %u\n",
574                lsm, POSTID(&lsm->lsm_oi), lsm->lsm_maxbytes, lsm->lsm_magic,
575                atomic_read(&lsm->lsm_refc), lsm->lsm_entry_count,
576                lsm->lsm_layout_gen);
577
578         if (lsm->lsm_magic == LOV_MAGIC_FOREIGN) {
579                 struct lov_foreign_md *lfm = (void *)lsm_foreign(lsm);
580
581                 CDEBUG_LIMIT(level,
582                              "foreign LOV EA, magic %x, length %u, type %x, flags %x, value '%.*s'\n",
583                        lfm->lfm_magic, lfm->lfm_length, lfm->lfm_type,
584                        lfm->lfm_flags, lfm->lfm_length, lfm->lfm_value);
585                 return;
586         }
587
588         for (i = 0; i < lsm->lsm_entry_count; i++) {
589                 struct lov_stripe_md_entry *lse = lsm->lsm_entries[i];
590
591                 CDEBUG(level, DEXT ": id: %u, flags: %x, "
592                        "magic 0x%08X, layout_gen %u, "
593                        "stripe count %u, sstripe size %u, "
594                        "pool: ["LOV_POOLNAMEF"]\n",
595                        PEXT(&lse->lsme_extent), lse->lsme_id, lse->lsme_flags,
596                        lse->lsme_magic, lse->lsme_layout_gen,
597                        lse->lsme_stripe_count, lse->lsme_stripe_size,
598                        lse->lsme_pool_name);
599                 if (!lsme_inited(lse) ||
600                     lse->lsme_pattern & LOV_PATTERN_F_RELEASED)
601                         continue;
602                 for (j = 0; j < lse->lsme_stripe_count; j++) {
603                         CDEBUG(level, "   oinfo:%p: ostid: "DOSTID
604                                " ost idx: %d gen: %d\n",
605                                lse->lsme_oinfo[j],
606                                POSTID(&lse->lsme_oinfo[j]->loi_oi),
607                                lse->lsme_oinfo[j]->loi_ost_idx,
608                                lse->lsme_oinfo[j]->loi_ost_gen);
609                 }
610         }
611 }
612
613 int lov_lsm_entry(const struct lov_stripe_md *lsm, __u64 offset)
614 {
615         int i;
616
617         for (i = 0; i < lsm->lsm_entry_count; i++) {
618                 struct lov_stripe_md_entry *lse = lsm->lsm_entries[i];
619
620                 if ((offset >= lse->lsme_extent.e_start &&
621                      offset < lse->lsme_extent.e_end) ||
622                     (offset == OBD_OBJECT_EOF &&
623                      lse->lsme_extent.e_end == OBD_OBJECT_EOF))
624                         return i;
625         }
626
627         return -1;
628 }