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