Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / lov / lov_pack.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *   Author: Andreas Dilger <adilger@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * (Un)packing of OST/MDS requests
23  *
24  */
25 #ifndef EXPORT_SYMTAB
26 # define EXPORT_SYMTAB
27 #endif
28 #define DEBUG_SUBSYSTEM S_LOV
29 #ifndef __KERNEL__
30 #include <liblustre.h>
31 #endif
32
33 #include <linux/lustre_net.h>
34 #include <linux/obd.h>
35 #include <linux/obd_lov.h>
36 #include <linux/obd_class.h>
37 #include <linux/obd_support.h>
38 #include <lustre/lustre_user.h>
39
40 #include "lov_internal.h"
41
42 void lov_dump_lmm_v0(int level, struct lov_mds_md_v0 *lmm)
43 {
44         int i, num_ost, stripe, idx;
45
46         num_ost = le32_to_cpu(lmm->lmm_ost_count);
47         idx = le32_to_cpu(lmm->lmm_stripe_offset);
48         CDEBUG(level, "objid "LPX64", magic 0x%08X, ost_count %u\n",
49                le64_to_cpu(lmm->lmm_object_id), le32_to_cpu(lmm->lmm_magic),
50                num_ost);
51         CDEBUG(level,"stripe_size %u, stripe_count %u, stripe_offset %u\n",
52                le32_to_cpu(lmm->lmm_stripe_size),
53                le32_to_cpu(lmm->lmm_stripe_count), idx);
54         for (i = stripe = 0; i < le32_to_cpu(lmm->lmm_ost_count); i++, idx++) {
55                 idx %= num_ost;
56                 if (lmm->lmm_objects[idx].l_object_id == 0)
57                         continue;
58                 CDEBUG(level, "stripe %u idx %u subobj "LPX64"\n", stripe, idx,
59                        le64_to_cpu(lmm->lmm_objects[idx].l_object_id));
60                 stripe++;
61         }
62 }
63
64 void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm)
65 {
66         struct lov_ost_data_v1 *lod;
67         int i;
68
69         CDEBUG(level, "objid "LPX64", magic 0x%08X, pattern %#X\n",
70                le64_to_cpu(lmm->lmm_object_id), le32_to_cpu(lmm->lmm_magic),
71                le32_to_cpu(lmm->lmm_pattern));
72         CDEBUG(level,"stripe_size %u, stripe_count %u\n",
73                le32_to_cpu(lmm->lmm_stripe_size),
74                le32_to_cpu(lmm->lmm_stripe_count));
75         for (i = 0, lod = lmm->lmm_objects;
76              i < le32_to_cpu(lmm->lmm_stripe_count); i++, lod++)
77                 CDEBUG(level, "stripe %u idx %u subobj "LPX64"/"LPX64"\n",
78                        i, le32_to_cpu(lod->l_ost_idx),
79                        le64_to_cpu(lod->l_object_gr),
80                        le64_to_cpu(lod->l_object_id));
81 }
82
83 #define LMM_ASSERT(test)                                                \
84 do {                                                                    \
85         if (!(test)) lov_dump_lmm(D_ERROR, lmm);                        \
86         LASSERT(test); /* so we know what assertion failed */           \
87 } while(0)
88
89 /* Pack LOV object metadata for disk storage.  It is packed in LE byte
90  * order and is opaque to the networking layer.
91  *
92  * XXX In the future, this will be enhanced to get the EA size from the
93  *     underlying OSC device(s) to get their EA sizes so we can stack
94  *     LOVs properly.  For now lov_mds_md_size() just assumes one obd_id
95  *     per stripe.
96  */
97 int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
98                struct lov_stripe_md *lsm)
99 {
100         struct obd_device *obd = class_exp2obd(exp);
101         struct lov_obd *lov = &obd->u.lov;
102         struct lov_oinfo *loi;
103         struct lov_mds_md *lmm;
104         int stripe_count = lov->desc.ld_tgt_count;
105         int lmm_size;
106         int i;
107         ENTRY;
108
109         if (lsm) {
110                 if (lsm->lsm_magic != LOV_MAGIC) {
111                         CWARN("bad LOV MAGIC: 0x%08X != 0x%08X\n",
112                                lsm->lsm_magic, LOV_MAGIC);
113                         RETURN(-EINVAL);
114                 }
115                 stripe_count = lsm->lsm_stripe_count;
116         }
117
118         /* XXX LOV STACKING call into osc for sizes */
119         lmm_size = lov_mds_md_size(stripe_count);
120
121         if (!lmmp)
122                 RETURN(lmm_size);
123
124         if (*lmmp && !lsm) {
125                 stripe_count = le32_to_cpu((*lmmp)->lmm_stripe_count);
126                 OBD_FREE(*lmmp, lov_mds_md_size(stripe_count));
127                 *lmmp = NULL;
128                 RETURN(0);
129         }
130
131         if (!*lmmp) {
132                 OBD_ALLOC(*lmmp, lmm_size);
133                 if (!*lmmp)
134                         RETURN(-ENOMEM);
135         }
136
137         lmm = *lmmp;
138         lmm->lmm_magic = cpu_to_le32(LOV_MAGIC); /* only write new format */
139
140         if (!lsm)
141                 RETURN(lmm_size);
142
143         lmm->lmm_object_id = cpu_to_le64(lsm->lsm_object_id);
144         lmm->lmm_object_gr = cpu_to_le64(lsm->lsm_object_gr);
145         lmm->lmm_stripe_size = cpu_to_le32(lsm->lsm_stripe_size);
146         lmm->lmm_stripe_count = cpu_to_le32(stripe_count);
147         lmm->lmm_pattern = cpu_to_le32(lsm->lsm_pattern);
148
149         for (i = 0, loi = lsm->lsm_oinfo; i < stripe_count; i++, loi++) {
150                 /* XXX LOV STACKING call down to osc_packmd() to do packing */
151                 LASSERT(loi->loi_id);
152                 lmm->lmm_objects[i].l_object_id = cpu_to_le64(loi->loi_id);
153                 lmm->lmm_objects[i].l_object_gr = cpu_to_le64(loi->loi_gr);
154                 lmm->lmm_objects[i].l_ost_gen = cpu_to_le32(loi->loi_ost_gen);
155                 lmm->lmm_objects[i].l_ost_idx = cpu_to_le32(loi->loi_ost_idx);
156         }
157
158         RETURN(lmm_size);
159 }
160
161 int lov_get_stripecnt(struct lov_obd *lov, int stripe_count)
162 {
163         if (!stripe_count)
164                 stripe_count = lov->desc.ld_default_stripe_count;
165         if (!stripe_count || stripe_count > lov->desc.ld_active_tgt_count)
166                 stripe_count = lov->desc.ld_active_tgt_count;
167
168         return stripe_count;
169 }
170
171 static int lov_verify_lmm_v0(struct lov_mds_md_v0 *lmm, int lmm_bytes,
172                              int *stripe_count)
173 {
174         if (lmm_bytes < sizeof(*lmm)) {
175                 CERROR("lov_mds_md too small: %d, need at least %d\n",
176                        lmm_bytes, (int)sizeof(*lmm));
177                 return -EINVAL;
178         }
179
180         *stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
181
182         if (*stripe_count == 0 ||
183             *stripe_count > le32_to_cpu(lmm->lmm_ost_count)) {
184                 CERROR("bad stripe count %d\n", *stripe_count);
185                 lov_dump_lmm_v0(D_WARNING, lmm);
186                 return -EINVAL;
187         }
188
189         if (lmm_bytes < lov_mds_md_v0_size(*stripe_count)) {
190                 CERROR("LOV EA too small: %d, need %d\n",
191                        lmm_bytes, lov_mds_md_v0_size(*stripe_count));
192                 lov_dump_lmm_v0(D_WARNING, lmm);
193                 return -EINVAL;
194         }
195
196         if (lmm->lmm_object_id == 0) {
197                 CERROR("zero object id\n");
198                 lov_dump_lmm_v0(D_WARNING, lmm);
199                 return -EINVAL;
200         }
201
202         if (le32_to_cpu(lmm->lmm_stripe_offset) >
203             le32_to_cpu(lmm->lmm_ost_count)) {
204                 CERROR("stripe offset %d more than number of OSTs %d\n",
205                        le32_to_cpu(lmm->lmm_stripe_offset),
206                        le32_to_cpu(lmm->lmm_ost_count));
207                 lov_dump_lmm_v0(D_WARNING, lmm);
208                 return -EINVAL;
209         }
210
211         if (lmm->lmm_stripe_size == 0) {
212                 CERROR("zero stripe size\n");
213                 lov_dump_lmm_v0(D_WARNING, lmm);
214                 return -EINVAL;
215         }
216
217         return 0;
218 }
219
220 static int lov_verify_lmm_v1(struct lov_mds_md_v1 *lmm, int lmm_bytes,
221                              int *stripe_count)
222 {
223         if (lmm_bytes < sizeof(*lmm)) {
224                 CERROR("lov_mds_md too small: %d, need at least %d\n",
225                        lmm_bytes, (int)sizeof(*lmm));
226                 return -EINVAL;
227         }
228
229         if (lmm->lmm_magic != le32_to_cpu(LOV_MAGIC_V1)) {
230                 CERROR("bad disk LOV MAGIC: 0x%08X\n",
231                        le32_to_cpu(*(__u32 *)lmm));
232                 return -EINVAL;
233         }
234
235         *stripe_count = le32_to_cpu(lmm->lmm_stripe_count);
236
237         if (*stripe_count == 0) {
238                 CERROR("bad stripe count %d\n", *stripe_count);
239                 lov_dump_lmm_v1(D_WARNING, lmm);
240                 return -EINVAL;
241         }
242
243         if (lmm_bytes < lov_mds_md_v1_size(*stripe_count)) {
244                 CERROR("LOV EA too small: %d, need %d\n",
245                        lmm_bytes, lov_mds_md_v1_size(*stripe_count));
246                 lov_dump_lmm_v1(D_WARNING, lmm);
247                 return -EINVAL;
248         }
249
250         if (lmm->lmm_object_id == 0) {
251                 CERROR("zero object id\n");
252                 lov_dump_lmm_v1(D_WARNING, lmm);
253                 return -EINVAL;
254         }
255
256         if (lmm->lmm_pattern != cpu_to_le32(LOV_PATTERN_RAID0)) {
257                 CERROR("bad striping pattern\n");
258                 lov_dump_lmm_v1(D_WARNING, lmm);
259                 return -EINVAL;
260         }
261
262         if (lmm->lmm_stripe_size == 0 ||
263             (__u64)le32_to_cpu(lmm->lmm_stripe_size) * *stripe_count > ~0UL) {
264                 CERROR("bad stripe size %u\n",
265                        le32_to_cpu(lmm->lmm_stripe_size));
266                 lov_dump_lmm_v1(D_WARNING, lmm);
267                 return -EINVAL;
268         }
269
270         return 0;
271 }
272
273 static int lov_verify_lmm(void *lmm, int lmm_bytes, int *stripe_count)
274 {
275         switch (le32_to_cpu(*(__u32 *)lmm)) {
276         case LOV_MAGIC_V1:
277                 return lov_verify_lmm_v1(lmm, lmm_bytes, stripe_count);
278         case LOV_MAGIC_V0:
279                 return lov_verify_lmm_v0(lmm, lmm_bytes, stripe_count);
280         default:
281                 CERROR("bad disk LOV MAGIC: 0x%08X\n",
282                        le32_to_cpu(*(__u32 *)lmm));
283                 return -EINVAL;
284         }
285 }
286
287 int lov_alloc_memmd(struct lov_stripe_md **lsmp, int stripe_count, int pattern)
288 {
289         int lsm_size = lov_stripe_md_size(stripe_count);
290         struct lov_oinfo *loi;
291         int i;
292
293         OBD_ALLOC(*lsmp, lsm_size);
294         if (!*lsmp)
295                 return -ENOMEM;
296
297         (*lsmp)->lsm_magic = LOV_MAGIC;
298         (*lsmp)->lsm_stripe_count = stripe_count;
299         (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES * stripe_count;
300         (*lsmp)->lsm_xfersize = PTLRPC_MAX_BRW_SIZE * stripe_count;
301         (*lsmp)->lsm_pattern = pattern;
302         (*lsmp)->lsm_oinfo[0].loi_ost_idx = ~0;
303         (*lsmp)->lsm_oinfo[0].loi_ost_gen = ~0;
304
305         for (i = 0, loi = (*lsmp)->lsm_oinfo; i < stripe_count; i++, loi++)
306                 loi_init(loi);
307
308         return lsm_size;
309 }
310 EXPORT_SYMBOL(lov_alloc_memmd);
311
312 void lov_free_memmd(struct lov_stripe_md **lsmp)
313 {
314         OBD_FREE(*lsmp, lov_stripe_md_size((*lsmp)->lsm_stripe_count));
315         *lsmp = NULL;
316 }
317 EXPORT_SYMBOL(lov_free_memmd);
318
319 int lov_unpackmd_v0(struct lov_obd *lov, struct lov_stripe_md *lsm,
320                     struct lov_mds_md_v0 *lmm)
321 {
322         struct lov_oinfo *loi;
323         int i, ost_offset, ost_count;
324
325         lsm->lsm_object_id = le64_to_cpu(lmm->lmm_object_id);
326         /* lsm->lsm_object_gr = 0; implicit */
327         lsm->lsm_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
328         lsm->lsm_xfersize = lsm->lsm_stripe_size * lsm->lsm_stripe_count;
329         lsm->lsm_pattern = LOV_PATTERN_RAID0;
330         ost_offset = le32_to_cpu(lmm->lmm_stripe_offset);
331         ost_count = le16_to_cpu(lmm->lmm_ost_count);
332
333         for (i = 0, loi = lsm->lsm_oinfo; i < ost_count; i++, ost_offset++) {
334                 ost_offset %= ost_count;
335
336                 if (!lmm->lmm_objects[ost_offset].l_object_id)
337                         continue;
338
339                 loi->loi_id =
340                         le64_to_cpu(lmm->lmm_objects[ost_offset].l_object_id);
341                 /* loi->loi_gr = 0; implicit */
342                 loi->loi_ost_idx = ost_offset;
343                 loi->loi_ost_gen = 1;
344                 loi++;
345         }
346
347         if (loi - lsm->lsm_oinfo != lsm->lsm_stripe_count) {
348                 CERROR("missing objects in lmm struct\n");
349                 lov_dump_lmm_v0(D_WARNING, lmm);
350                 return -EINVAL;
351         }
352
353         return 0;
354 }
355
356 int lov_unpackmd_v1(struct lov_obd *lov, struct lov_stripe_md *lsm,
357                     struct lov_mds_md_v1 *lmm)
358 {
359         struct lov_oinfo *loi;
360         int i;
361
362         lsm->lsm_object_id = le64_to_cpu(lmm->lmm_object_id);
363         lsm->lsm_object_gr = le64_to_cpu(lmm->lmm_object_gr);
364         lsm->lsm_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
365         lsm->lsm_pattern = le32_to_cpu(lmm->lmm_pattern);
366         lsm->lsm_xfersize = lsm->lsm_stripe_size * lsm->lsm_stripe_count;
367
368         for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++) {
369                 /* XXX LOV STACKING call down to osc_unpackmd() */
370                 loi->loi_id = le64_to_cpu(lmm->lmm_objects[i].l_object_id);
371                 loi->loi_gr = le64_to_cpu(lmm->lmm_objects[i].l_object_gr);
372                 loi->loi_ost_idx = le32_to_cpu(lmm->lmm_objects[i].l_ost_idx);
373                 loi->loi_ost_gen = le32_to_cpu(lmm->lmm_objects[i].l_ost_gen);
374                 if (loi->loi_ost_idx >= lov->desc.ld_tgt_count) {
375                         CERROR("OST index %d more than OST count %d. "
376                                "MDS and client use different OST sets?\n",
377                                loi->loi_ost_idx, lov->desc.ld_tgt_count);
378                         lov_dump_lmm_v1(D_WARNING, lmm);
379                         return -EINVAL;
380                 }
381                 loi++;
382         }
383
384         return 0;
385 }
386
387 /* Unpack LOV object metadata from disk storage.  It is packed in LE byte
388  * order and is opaque to the networking layer.
389  */
390 int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
391                  struct lov_mds_md *lmm, int lmm_bytes)
392 {
393         struct obd_device *obd = class_exp2obd(exp);
394         struct lov_obd *lov = &obd->u.lov;
395         int rc = 0, stripe_count, lsm_size;
396         ENTRY;
397
398         /* If passed an MDS struct use values from there, otherwise defaults */
399         if (lmm) {
400                 rc = lov_verify_lmm(lmm, lmm_bytes, &stripe_count);
401                 if (rc)
402                         RETURN(rc);
403         } else {
404                 stripe_count = lov_get_stripecnt(lov, 0);
405         }
406
407         /* If we aren't passed an lsmp struct, we just want the size */
408         if (!lsmp)
409                 /* XXX LOV STACKING call into osc for sizes */
410                 RETURN(lov_stripe_md_size(stripe_count));
411
412         /* If we are passed an allocated struct but nothing to unpack, free */
413         if (*lsmp && !lmm) {
414                 lov_free_memmd(lsmp);
415                 RETURN(0);
416         }
417
418         lsm_size = lov_alloc_memmd(lsmp, stripe_count, LOV_PATTERN_RAID0);
419         if (lsm_size < 0)
420                 RETURN(lsm_size);
421
422         /* If we are passed a pointer but nothing to unpack, we only alloc */
423         if (!lmm)
424                 RETURN(lsm_size);
425
426         switch (le32_to_cpu(lmm->lmm_magic)) {
427         case LOV_MAGIC_V1:
428                 rc = lov_unpackmd_v1(lov, *lsmp, lmm);
429                 break;
430         case LOV_MAGIC_V0:
431                 rc = lov_unpackmd_v0(lov, *lsmp, (void *)lmm);
432                 break;
433         }
434
435         if (rc) {
436                 lov_free_memmd(lsmp);
437                 RETURN(rc);
438         }
439
440         RETURN(lsm_size);
441 }
442
443 /* Configure object striping information on a new file.
444  *
445  * @lmmu is a pointer to a user struct with one or more of the fields set to
446  * indicate the application preference: lmm_stripe_count, lmm_stripe_size,
447  * lmm_stripe_offset, and lmm_stripe_pattern.  lmm_magic must be LOV_MAGIC.
448  * @lsmp is a pointer to an in-core stripe MD that needs to be filled in.
449  */
450 int lov_setstripe(struct obd_export *exp, struct lov_stripe_md **lsmp,
451                   struct lov_user_md *lump)
452 {
453         struct obd_device *obd = class_exp2obd(exp);
454         struct lov_obd *lov = &obd->u.lov;
455         struct lov_user_md lum;
456         int stripe_count;
457         int rc;
458         ENTRY;
459
460         rc = copy_from_user(&lum, lump, sizeof(lum));
461         if (rc)
462                 RETURN(-EFAULT);
463
464         if (lum.lmm_magic != LOV_USER_MAGIC) {
465                 CDEBUG(D_IOCTL, "bad userland LOV MAGIC: %#08x != %#08x\n",
466                        lum.lmm_magic, LOV_USER_MAGIC);
467                 RETURN(-EINVAL);
468         }
469
470         if (lum.lmm_pattern == 0) {
471                 lum.lmm_pattern = lov->desc.ld_pattern ?
472                         lov->desc.ld_pattern : LOV_PATTERN_RAID0;
473         }
474
475         if (lum.lmm_pattern != LOV_PATTERN_RAID0) {
476                 CDEBUG(D_IOCTL, "bad userland stripe pattern: %#x\n",
477                        lum.lmm_pattern);
478                 RETURN(-EINVAL);
479         }
480
481         if (lum.lmm_stripe_size & (PAGE_SIZE - 1)) {
482                 CDEBUG(D_IOCTL, "stripe size %u not multiple of %lu\n",
483                        lum.lmm_stripe_size, PAGE_SIZE);
484                 RETURN(-EINVAL);
485         }
486
487         if ((lum.lmm_stripe_offset >= lov->desc.ld_active_tgt_count) &&
488             (lum.lmm_stripe_offset != (typeof(lum.lmm_stripe_offset))(-1))) {
489                 CDEBUG(D_IOCTL, "stripe offset %u > number of active OSTs %u\n",
490                        lum.lmm_stripe_offset, lov->desc.ld_active_tgt_count);
491                 RETURN(-EINVAL);
492         }
493         stripe_count = lov_get_stripecnt(lov, lum.lmm_stripe_count);
494
495         if ((__u64)lum.lmm_stripe_size * stripe_count > ~0UL) {
496                 CDEBUG(D_IOCTL, "stripe width %ux%u > %lu on 32-bit system\n",
497                        lum.lmm_stripe_size, (int)lum.lmm_stripe_count, ~0UL);
498                 RETURN(-EINVAL);
499         }
500
501         rc = lov_alloc_memmd(lsmp, stripe_count, lum.lmm_pattern);
502
503         if (rc < 0)
504                 RETURN(rc);
505
506         (*lsmp)->lsm_oinfo[0].loi_ost_idx = lum.lmm_stripe_offset;
507         /* XXX - what about loi_ost_gen ? */
508         (*lsmp)->lsm_stripe_size = lum.lmm_stripe_size;
509         (*lsmp)->lsm_xfersize = lum.lmm_stripe_size * stripe_count;
510
511         RETURN(0);
512 }
513
514 int lov_setea(struct obd_export *exp, struct lov_stripe_md **lsmp,
515               struct lov_user_md *lump)
516 {
517         int i;
518         int rc;
519         struct obd_export *oexp;
520         struct lov_obd *lov = &exp->exp_obd->u.lov;
521         obd_id last_id = 0;
522
523         for (i = 0; i < lump->lmm_stripe_count; i++) {
524                 struct lov_tgt_desc *tgt;
525                 __u32 len = sizeof(last_id);
526
527                 tgt = lov->tgts + lump->lmm_objects[i].l_ost_idx;
528                 if (!lov_tgt_active(lov, tgt, lump->lmm_objects[i].l_ost_gen)) {
529                         CERROR("Object on ost idx %d: osc inactive.\n",
530                                lump->lmm_objects[i].l_ost_idx);
531                         continue;
532                 }
533
534                 oexp = tgt->ltd_exp;
535                 rc = obd_get_info(oexp, strlen("last_id"), "last_id",
536                                   &len, &last_id);
537                 lov_tgt_decref(lov, tgt);
538                 if (rc)
539                         RETURN(rc);
540                 if (lump->lmm_objects[i].l_object_id > last_id) {
541                         CERROR("Setting EA for object > than last id on "
542                                "ost idx %d "LPD64" > "LPD64" \n",
543                                lump->lmm_objects[i].l_ost_idx,
544                                lump->lmm_objects[i].l_object_id, last_id);
545                         RETURN(-EINVAL);
546                 }
547         }
548
549         rc = lov_setstripe(exp, lsmp, lump);
550         if (rc)
551                 RETURN(rc);
552
553         for (i = 0; i < lump->lmm_stripe_count; i++) {
554                 (*lsmp)->lsm_oinfo[i].loi_ost_idx =
555                         lump->lmm_objects[i].l_ost_idx;
556                 (*lsmp)->lsm_oinfo[i].loi_ost_gen =
557                         lump->lmm_objects[i].l_ost_gen;
558                 (*lsmp)->lsm_oinfo[i].loi_id = lump->lmm_objects[i].l_object_id;
559                 (*lsmp)->lsm_oinfo[i].loi_gr = lump->lmm_objects[i].l_object_gr;
560         }
561         RETURN(0);
562 }
563
564
565 /* Retrieve object striping information.
566  *
567  * @lump is a pointer to an in-core struct with lmm_ost_count indicating
568  * the maximum number of OST indices which will fit in the user buffer.
569  * lmm_magic must be LOV_USER_MAGIC.
570  */
571 int lov_getstripe(struct obd_export *exp, struct lov_stripe_md *lsm,
572                   struct lov_user_md *lump)
573 {
574         struct lov_user_md lum;
575         struct lov_mds_md *lmmk = NULL;
576         int rc, lmm_size;
577         ENTRY;
578
579         if (!lsm)
580                 RETURN(-ENODATA);
581
582         rc = copy_from_user(&lum, lump, sizeof(lum));
583         if (rc)
584                 RETURN(-EFAULT);
585
586         if (lum.lmm_magic != LOV_USER_MAGIC)
587                 RETURN(-EINVAL);
588
589         rc = lov_packmd(exp, &lmmk, lsm);
590         if (rc < 0)
591                 RETURN(rc);
592         lmm_size = rc;
593         rc = 0;
594
595         /* FIXME: Bug 1185 - copy fields properly when structs change */
596         LASSERT(sizeof(lum) == sizeof(*lmmk));
597         LASSERT(sizeof(lum.lmm_objects[0]) == sizeof(lmmk->lmm_objects[0]));
598
599         /* User wasn't expecting this many OST entries */
600         if (lum.lmm_stripe_count == 0) {
601                 rc = copy_to_user(lump, lmmk, sizeof(lum));
602                 if (rc)
603                         rc = -EFAULT;
604         } else if (lum.lmm_stripe_count < lmmk->lmm_stripe_count) {
605                 rc = -EOVERFLOW;
606         } else if (copy_to_user(lump, lmmk, lmm_size)) {
607                 rc = -EFAULT;
608         }
609
610         obd_free_diskmd(exp, &lmmk);
611
612         RETURN(rc);
613 }