Whamcloud - gitweb
b=2264
[fs/lustre-release.git] / lustre / mds / mds_lov.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/mds/mds_lov.c
5  *  Lustre Metadata Server (mds) handling of striped file data
6  *
7  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
8  *   Author: Peter Braam <braam@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org.
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #ifndef EXPORT_SYMTAB
27 # define EXPORT_SYMTAB
28 #endif
29 #define DEBUG_SUBSYSTEM S_MDS
30
31 #include <linux/module.h>
32 #include <linux/lustre_mds.h>
33 #include <linux/lustre_idl.h>
34 #include <linux/obd_class.h>
35 #include <linux/obd_lov.h>
36 #include <linux/lustre_lib.h>
37 #include <linux/lustre_fsfilt.h>
38
39 #include "mds_internal.h"
40
41 void le_lov_desc_to_cpu (struct lov_desc *ld)
42 {
43         ld->ld_tgt_count = le32_to_cpu (ld->ld_tgt_count);
44         ld->ld_default_stripe_count = le32_to_cpu (ld->ld_default_stripe_count);
45         ld->ld_default_stripe_size = le32_to_cpu (ld->ld_default_stripe_size);
46         ld->ld_pattern = le32_to_cpu (ld->ld_pattern);
47 }
48
49 void cpu_to_le_lov_desc (struct lov_desc *ld)
50 {
51         ld->ld_tgt_count = cpu_to_le32 (ld->ld_tgt_count);
52         ld->ld_default_stripe_count = cpu_to_le32 (ld->ld_default_stripe_count);
53         ld->ld_default_stripe_size = cpu_to_le32 (ld->ld_default_stripe_size);
54         ld->ld_pattern = cpu_to_le32 (ld->ld_pattern);
55 }
56
57 void mds_lov_update_objids(struct obd_device *obd, obd_id *ids)
58 {
59         struct mds_obd *mds = &obd->u.mds;
60         int i;
61         ENTRY;
62
63         lock_kernel();
64         for (i = 0; i < mds->mds_lov_desc.ld_tgt_count; i++)
65                 if (ids[i] > (mds->mds_lov_objids)[i])
66                         (mds->mds_lov_objids)[i] = ids[i];
67         unlock_kernel();
68         EXIT;
69 }
70
71 static int mds_lov_read_objids(struct obd_device *obd)
72 {
73         struct mds_obd *mds = &obd->u.mds;
74         obd_id *ids;
75         loff_t off = 0;
76         int i, rc, size = mds->mds_lov_desc.ld_tgt_count * sizeof(*ids);
77         ENTRY;
78
79         if (mds->mds_lov_objids != NULL)
80                 RETURN(0);
81
82         OBD_ALLOC(ids, size);
83         if (ids == NULL)
84                 RETURN(-ENOMEM);
85         mds->mds_lov_objids = ids;
86
87         if (mds->mds_lov_objid_filp->f_dentry->d_inode->i_size == 0)
88                 RETURN(0);
89         rc = fsfilt_read_record(obd, mds->mds_lov_objid_filp, ids, size, &off);
90         if (rc < 0) {
91                 CERROR("Error reading objids %d\n", rc);
92         } else {
93                 mds->mds_lov_objids_valid = 1;
94                 rc = 0;
95         }
96
97         for (i = 0; i < mds->mds_lov_desc.ld_tgt_count; i++)
98                 CDEBUG(D_INFO, "read last object "LPU64" for idx %d\n",
99                        mds->mds_lov_objids[i], i);
100
101         RETURN(rc);
102 }
103
104 int mds_lov_write_objids(struct obd_device *obd)
105 {
106         struct mds_obd *mds = &obd->u.mds;
107         loff_t off = 0;
108         int i, rc, size = mds->mds_lov_desc.ld_tgt_count * sizeof(obd_id);
109         ENTRY;
110
111         for (i = 0; i < mds->mds_lov_desc.ld_tgt_count; i++)
112                 CDEBUG(D_INFO, "writing last object "LPU64" for idx %d\n",
113                        mds->mds_lov_objids[i], i);
114
115         rc = fsfilt_write_record(obd, mds->mds_lov_objid_filp,
116                                  mds->mds_lov_objids, size, &off, 0);
117         RETURN(rc);
118 }
119
120 static int mds_lov_clearorphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
121 {
122         int rc;
123         struct obdo oa;
124         struct obd_trans_info oti = {0};
125         struct lov_stripe_md  *empty_ea = NULL;
126         ENTRY;
127
128         LASSERT(mds->mds_lov_objids != NULL);
129
130         /* This create will in fact either create or destroy:  If the OST is
131          * missing objects below this ID, they will be created.  If it finds
132          * objects above this ID, they will be removed. */
133         memset(&oa, 0, sizeof(oa));
134         oa.o_valid = OBD_MD_FLFLAGS;
135         oa.o_flags = OBD_FL_DELORPHAN;
136         if (ost_uuid != NULL) {
137                 memcpy(&oa.o_inline, ost_uuid, sizeof(*ost_uuid));
138                 oa.o_valid |= OBD_MD_FLINLINE;
139         }
140         rc = obd_create(mds->mds_osc_exp, &oa, &empty_ea, &oti);
141
142         RETURN(rc);
143 }
144
145 /* update the LOV-OSC knowledge of the last used object id's */
146 int mds_lov_set_nextid(struct obd_device *obd)
147 {
148         struct mds_obd *mds = &obd->u.mds;
149         int rc;
150         ENTRY;
151
152         LASSERT(!obd->obd_recovering);
153
154         LASSERT(mds->mds_lov_objids != NULL);
155
156         rc = obd_set_info(mds->mds_osc_exp, strlen("next_id"), "next_id",
157                           mds->mds_lov_desc.ld_tgt_count, mds->mds_lov_objids);
158         if (rc < 0)
159                 GOTO(out, rc);
160
161         rc = mds_lov_clearorphans(mds, NULL /* all OSTs */);
162
163 out:
164         RETURN(rc);
165 }
166
167 /* tell the LOV-OSC by how much to pre-create */
168 int mds_lov_set_growth(struct mds_obd *mds, int count)
169 {
170         int rc;
171         ENTRY;
172
173         rc = obd_set_info(mds->mds_osc_exp, strlen("growth_count"),
174                           "growth_count", sizeof(count), &count);
175
176         RETURN(rc);
177 }
178
179 int mds_lov_connect(struct obd_device *obd, char * lov_name)
180 {
181         struct mds_obd *mds = &obd->u.mds;
182         struct lustre_handle conn = {0,};
183         int valsize;
184         int rc, i;
185         ENTRY;
186
187         if (IS_ERR(mds->mds_osc_obd))
188                 RETURN(PTR_ERR(mds->mds_osc_obd));
189
190         if (mds->mds_osc_obd)
191                 RETURN(0);
192
193         mds->mds_osc_obd = class_name2obd(lov_name);
194         if (!mds->mds_osc_obd) {
195                 CERROR("MDS cannot locate LOV %s\n",
196                        lov_name);
197                 mds->mds_osc_obd = ERR_PTR(-ENOTCONN);
198                 RETURN(-ENOTCONN);
199         }
200
201         rc = obd_connect(&conn, mds->mds_osc_obd, &obd->obd_uuid);
202         if (rc) {
203                 CERROR("MDS cannot connect to LOV %s (%d)\n",
204                        lov_name, rc);
205                 mds->mds_osc_obd = ERR_PTR(rc);
206                 RETURN(rc);
207         }
208         mds->mds_osc_exp = class_conn2export(&conn);
209
210         rc = obd_register_observer(mds->mds_osc_obd, obd);
211         if (rc) {
212                 CERROR("MDS cannot register as observer of LOV %s (%d)\n",
213                        lov_name, rc);
214                 GOTO(err_discon, rc);
215         }
216
217         valsize = sizeof(mds->mds_lov_desc);
218         rc = obd_get_info(mds->mds_osc_exp, strlen("lovdesc") + 1, "lovdesc",
219                           &valsize, &mds->mds_lov_desc);
220         if (rc)
221                 GOTO(err_reg, rc);
222
223         mds->mds_max_mdsize = lov_mds_md_size(mds->mds_lov_desc.ld_tgt_count);
224         mds->mds_max_cookiesize = mds->mds_lov_desc.ld_tgt_count*
225                 sizeof(struct llog_cookie);
226         mds->mds_has_lov_desc = 1;
227         rc = mds_lov_read_objids(obd);
228         if (rc) {
229                 CERROR("cannot read %s: rc = %d\n", "lov_objids", rc);
230                 GOTO(err_reg, rc);
231         }
232
233         rc = llog_cat_initialize(obd, mds->mds_lov_desc.ld_tgt_count);
234         if (rc) {
235                 CERROR("failed to initialize catalog %d\n", rc);
236                 GOTO(err_reg, rc);
237         }
238
239         /* FIXME before set info call is made, we must initialize logging */
240         rc = obd_set_info(mds->mds_osc_exp, strlen("mds_conn"), "mds_conn",
241                           0, NULL);
242         if (rc)
243                 GOTO(err_reg, rc);
244
245         /* If we're mounting this code for the first time on an existing FS,
246          * we need to populate the objids array from the real OST values */
247         if (!mds->mds_lov_objids_valid) {
248                 int size = sizeof(obd_id) * mds->mds_lov_desc.ld_tgt_count;
249                 rc = obd_get_info(mds->mds_osc_exp, strlen("last_id"),
250                                   "last_id", &size, mds->mds_lov_objids);
251                 if (!rc) {
252                         for (i = 0; i < mds->mds_lov_desc.ld_tgt_count; i++)
253                                 CWARN("got last object "LPU64" from OST %d\n",
254                                       mds->mds_lov_objids[i], i);
255                         mds->mds_lov_objids_valid = 1;
256                         rc = mds_lov_write_objids(obd);
257                         if (rc)
258                                 CERROR("got last objids from OSTs, but error "
259                                        "writing objids file: %d\n", rc);
260                 }
261         }
262
263         /* I want to see a callback happen when the OBD moves to a
264          * "For General Use" state, and that's when we'll call
265          * set_nextid().  The class driver can help us here, because
266          * it can use the obd_recovering flag to determine when the
267          * the OBD is full available. */
268         if (!obd->obd_recovering) {
269                 rc = llog_connect(llog_get_context(obd, LLOG_UNLINK_ORIG_CTXT),
270                                   obd->u.mds.mds_lov_desc.ld_tgt_count, NULL,
271                                   NULL, NULL);
272                 if (rc != 0)
273                         CERROR("faild at llog_origin_connect: %d\n", rc);
274
275                 rc = mds_cleanup_orphans(obd);
276                 if (rc > 0)
277                         CERROR("Cleanup %d orphans while MDS isn't recovering\n", rc);
278
279                 rc = mds_lov_set_nextid(obd);
280                 if (rc)
281                         GOTO(err_llog, rc);
282         }
283         RETURN(rc);
284
285 err_llog:
286         /* cleanup all llogging subsystems */
287         rc = obd_llog_finish(obd, mds->mds_lov_desc.ld_tgt_count);
288         if (rc)
289                 CERROR("failed to cleanup llogging subsystems\n");
290 err_reg:
291         obd_register_observer(mds->mds_osc_obd, NULL);
292 err_discon:
293         obd_disconnect(mds->mds_osc_exp, 0);
294         mds->mds_osc_exp = NULL;
295         mds->mds_osc_obd = ERR_PTR(rc);
296         RETURN(rc);
297 }
298
299 int mds_lov_disconnect(struct obd_device *obd, int flags)
300 {
301         struct mds_obd *mds = &obd->u.mds;
302         int rc = 0;
303         ENTRY;
304
305         if (!IS_ERR(mds->mds_osc_obd) && mds->mds_osc_exp != NULL) {
306                 /* cleanup all llogging subsystems */
307                 rc = obd_llog_finish(obd, mds->mds_lov_desc.ld_tgt_count);
308                 if (rc)
309                         CERROR("failed to cleanup llogging subsystems\n");
310
311                 obd_register_observer(mds->mds_osc_obd, NULL);
312
313                 rc = obd_disconnect(mds->mds_osc_exp, flags);
314                 /* if obd_disconnect fails (probably because the
315                  * export was disconnected by class_disconnect_exports)
316                  * then we just need to drop our ref. */
317                 if (rc != 0)
318                         class_export_put(mds->mds_osc_exp);
319                 mds->mds_osc_exp = NULL;
320                 mds->mds_osc_obd = NULL;
321         }
322
323         RETURN(rc);
324 }
325
326 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
327                   void *karg, void *uarg)
328 {
329         static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
330         struct obd_device *obd = exp->exp_obd;
331         struct mds_obd *mds = &obd->u.mds;
332         struct obd_ioctl_data *data = karg;
333         struct obd_run_ctxt saved;
334         int rc = 0;
335
336         switch (cmd) {
337         case OBD_IOC_RECORD: {
338                 char *name = data->ioc_inlbuf1;
339                 if (mds->mds_cfg_llh)
340                         RETURN(-EBUSY);
341
342                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
343                 rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
344                                  &mds->mds_cfg_llh, NULL, name);
345                 if (rc == 0)
346                         llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
347                                          &cfg_uuid);
348                 else
349                         mds->mds_cfg_llh = NULL;
350                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
351
352                 RETURN(rc);
353         }
354
355         case OBD_IOC_ENDRECORD: {
356                 if (!mds->mds_cfg_llh)
357                         RETURN(-EBADF);
358
359                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
360                 rc = llog_close(mds->mds_cfg_llh);
361                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
362
363                 mds->mds_cfg_llh = NULL;
364                 RETURN(rc);
365         }
366
367         case OBD_IOC_CLEAR_LOG: {
368                 char *name = data->ioc_inlbuf1;
369                 if (mds->mds_cfg_llh)
370                         RETURN(-EBUSY);
371
372                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
373                 rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT), 
374                                  &mds->mds_cfg_llh, NULL, name);
375                 if (rc == 0) {
376                         llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
377                                          NULL);
378
379                         rc = llog_destroy(mds->mds_cfg_llh);
380                         llog_free_handle(mds->mds_cfg_llh);
381                 }
382                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
383
384                 mds->mds_cfg_llh = NULL;
385                 RETURN(rc);
386         }
387
388         case OBD_IOC_CLEAR_LOG: {
389                 char *name = data->ioc_inlbuf1;
390                 if (mds->mds_cfg_llh)
391                         RETURN(-EBUSY);
392
393                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
394                 rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT), 
395                                  &mds->mds_cfg_llh, NULL, name);
396                 if (rc == 0) {
397                         llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
398                                          NULL);
399
400                         rc = llog_destroy(mds->mds_cfg_llh);
401                         llog_free_handle(mds->mds_cfg_llh);
402                 }
403                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
404
405                 mds->mds_cfg_llh = NULL;
406                 RETURN(rc);
407         }
408
409         case OBD_IOC_DORECORD: {
410                 char *cfg_buf;
411                 struct llog_rec_hdr rec;
412                 if (!mds->mds_cfg_llh)
413                         RETURN(-EBADF);
414
415                 rec.lrh_len = llog_data_len(data->ioc_plen1);
416
417                 if (data->ioc_type == LUSTRE_CFG_TYPE) {
418                         rec.lrh_type = OBD_CFG_REC;
419                 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
420                         rec.lrh_type = PTL_CFG_REC;
421                 } else {
422                         CERROR("unknown cfg record type:%d \n", data->ioc_type);
423                         RETURN(-EINVAL);
424                 }
425
426                 OBD_ALLOC(cfg_buf, data->ioc_plen1);
427                 if (cfg_buf == NULL)
428                         RETURN(-EINVAL);
429                 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
430                 if (rc) {
431                         OBD_FREE(cfg_buf, data->ioc_plen1);
432                         RETURN(rc);
433                 }
434
435                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
436                 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
437                                     cfg_buf, -1);
438                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
439
440                 OBD_FREE(cfg_buf, data->ioc_plen1);
441                 RETURN(rc);
442         }
443
444         case OBD_IOC_PARSE: {
445                 struct llog_ctxt *ctxt =
446                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
447                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
448                 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
449                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
450                 if (rc)
451                         RETURN(rc);
452
453                 RETURN(rc);
454         }
455
456         case OBD_IOC_DUMP_LOG: {
457                 struct llog_ctxt *ctxt =
458                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
459                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
460                 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
461                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
462                 if (rc)
463                         RETURN(rc);
464
465                 RETURN(rc);
466         }
467
468         case OBD_IOC_SET_READONLY: {
469                 void *handle;
470                 struct inode *inode = obd->u.mds.mds_sb->s_root->d_inode;
471                 BDEVNAME_DECLARE_STORAGE(tmp);
472                 CERROR("setting device %s read-only\n",
473                        ll_bdevname(obd->u.mds.mds_sb, tmp));
474
475                 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
476                 LASSERT(handle);
477                 rc = fsfilt_commit(obd, inode, handle, 1);
478
479                 dev_set_rdonly(ll_sbdev(obd->u.mds.mds_sb), 2);
480                 RETURN(0);
481         }
482
483         case OBD_IOC_CATLOGLIST: {
484                 int count = mds->mds_lov_desc.ld_tgt_count;
485                 rc = llog_catlog_list(obd, count, data);
486                 RETURN(rc);
487
488         }
489         case OBD_IOC_LLOG_CHECK:
490         case OBD_IOC_LLOG_CANCEL:
491         case OBD_IOC_LLOG_REMOVE: {
492                 struct llog_ctxt *ctxt =
493                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
494                 int rc2;
495
496                 obd_llog_finish(obd, mds->mds_lov_desc.ld_tgt_count);
497                 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
498                 rc = llog_ioctl(ctxt, cmd, data);
499                 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
500                 llog_cat_initialize(obd, mds->mds_lov_desc.ld_tgt_count);
501                 rc2 = obd_set_info(mds->mds_osc_exp, strlen("mds_conn"), "mds_conn",
502                           0, NULL);
503                 if (!rc)
504                         rc = rc2;
505                 RETURN(rc);
506         }
507         case OBD_IOC_LLOG_INFO:
508         case OBD_IOC_LLOG_PRINT: {
509                 struct llog_ctxt *ctxt =
510                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
511
512                 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
513                 rc = llog_ioctl(ctxt, cmd, data);
514                 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
515
516                 RETURN(rc);
517         }
518
519         case OBD_IOC_ABORT_RECOVERY:
520                 CERROR("aborting recovery for device %s\n", obd->obd_name);
521                 target_abort_recovery(obd);
522                 RETURN(0);
523
524         default:
525                 RETURN(-EINVAL);
526         }
527         RETURN(0);
528 }
529
530 int mds_notify(struct obd_device *obd, struct obd_device *watched, int active)
531 {
532         struct obd_uuid *uuid;
533         int rc = 0;
534         ENTRY;
535
536         if (!active)
537                 RETURN(0);
538
539         if (strcmp(watched->obd_type->typ_name, "osc")) {
540                 CERROR("unexpected notification of %s %s!\n",
541                        watched->obd_type->typ_name, watched->obd_name);
542                 RETURN(-EINVAL);
543         }
544
545         uuid = &watched->u.cli.cl_import->imp_target_uuid;
546         if (obd->obd_recovering) {
547                 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
548                       obd->obd_name, uuid->uuid);
549         } else {
550                 LASSERT(llog_get_context(obd, LLOG_UNLINK_ORIG_CTXT) != NULL);
551
552                 rc = obd_set_info(obd->u.mds.mds_osc_exp, strlen("mds_conn"), "mds_conn",
553                                   0, uuid);
554                 if (rc != 0)
555                         RETURN(rc);
556
557                 rc = llog_connect(llog_get_context(obd, LLOG_UNLINK_ORIG_CTXT),
558                                   obd->u.mds.mds_lov_desc.ld_tgt_count,
559                                   NULL, NULL, uuid);
560                 if (rc != 0) {
561                         CERROR("faild at llog_origin_connect: %d\n", rc);
562                         RETURN(rc);
563                 }
564
565                 CWARN("MDS %s: %s now active, resetting orphans\n",
566                       obd->obd_name, uuid->uuid);
567                 rc = mds_lov_clearorphans(&obd->u.mds, uuid);
568         }
569         RETURN(rc);
570 }
571
572 /* Convert the on-disk LOV EA structre.
573  * We always try to convert from an old LOV EA format to the common in-memory
574  * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
575  * then convert back to the new on-disk format and save it back to disk
576  * (obd_packmd() only ever saves to the new on-disk format) so we don't have
577  * to convert it each time this inode is accessed.
578  *
579  * This function is a bit interesting in the error handling.  We can safely
580  * ship the old lmm to the client in case of failure, since it uses the same
581  * obd_unpackmd() code and can do the conversion if the MDS fails for some
582  * reason.  We will not delete the old lmm data until we have written the
583  * new format lmm data in fsfilt_set_md(). */
584 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
585                        struct lov_mds_md *lmm, int lmm_size)
586 {
587         struct lov_stripe_md *lsm = NULL;
588         void *handle;
589         int rc, err;
590         ENTRY;
591
592         if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
593                 RETURN(0);
594
595         CWARN("converting LOV EA on %lu/%u from V0 to V1\n",
596               inode->i_ino, inode->i_generation);
597         rc = obd_unpackmd(obd->u.mds.mds_osc_exp, &lsm, lmm, lmm_size);
598         if (rc < 0)
599                 GOTO(conv_end, rc);
600
601         rc = obd_packmd(obd->u.mds.mds_osc_exp, &lmm, lsm);
602         if (rc < 0)
603                 GOTO(conv_free, rc);
604         lmm_size = rc;
605
606         handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
607         if (IS_ERR(handle)) {
608                 rc = PTR_ERR(handle);
609                 GOTO(conv_free, rc);
610         }
611
612         rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size);
613
614         err = fsfilt_commit(obd, inode, handle, 0);
615         if (!rc)
616                 rc = err ? err : lmm_size;
617         GOTO(conv_free, rc);
618 conv_free:
619         obd_free_memmd(obd->u.mds.mds_osc_exp, &lsm);
620 conv_end:
621         return rc;
622 }