Whamcloud - gitweb
b=4966
[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 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         RETURN(rc);
159 }
160
161 /* tell the LOV-OSC by how much to pre-create */
162 int mds_lov_set_growth(struct mds_obd *mds, int count)
163 {
164         int rc;
165         ENTRY;
166
167         rc = obd_set_info(mds->mds_osc_exp, strlen("growth_count"),
168                           "growth_count", sizeof(count), &count);
169
170         RETURN(rc);
171 }
172
173 int mds_lov_connect(struct obd_device *obd, char * lov_name)
174 {
175         struct mds_obd *mds = &obd->u.mds;
176         struct lustre_handle conn = {0,};
177         int valsize;
178         int rc, i;
179         ENTRY;
180
181         if (IS_ERR(mds->mds_osc_obd))
182                 RETURN(PTR_ERR(mds->mds_osc_obd));
183
184         if (mds->mds_osc_obd)
185                 RETURN(0);
186
187         mds->mds_osc_obd = class_name2obd(lov_name);
188         if (!mds->mds_osc_obd) {
189                 CERROR("MDS cannot locate LOV %s\n", lov_name);
190                 mds->mds_osc_obd = ERR_PTR(-ENOTCONN);
191                 RETURN(-ENOTCONN);
192         }
193
194         rc = obd_connect(&conn, mds->mds_osc_obd, &obd->obd_uuid);
195         if (rc) {
196                 CERROR("MDS cannot connect to LOV %s (%d)\n", lov_name, rc);
197                 mds->mds_osc_obd = ERR_PTR(rc);
198                 RETURN(rc);
199         }
200         mds->mds_osc_exp = class_conn2export(&conn);
201
202         rc = obd_register_observer(mds->mds_osc_obd, obd);
203         if (rc) {
204                 CERROR("MDS cannot register as observer of LOV %s (%d)\n",
205                        lov_name, rc);
206                 GOTO(err_discon, rc);
207         }
208
209         valsize = sizeof(mds->mds_lov_desc);
210         rc = obd_get_info(mds->mds_osc_exp, strlen("lovdesc") + 1, "lovdesc",
211                           &valsize, &mds->mds_lov_desc);
212         if (rc)
213                 GOTO(err_reg, rc);
214
215         mds->mds_max_mdsize = lov_mds_md_size(mds->mds_lov_desc.ld_tgt_count);
216         mds->mds_max_cookiesize = mds->mds_lov_desc.ld_tgt_count*
217                 sizeof(struct llog_cookie);
218         mds->mds_has_lov_desc = 1;
219         rc = mds_lov_read_objids(obd);
220         if (rc) {
221                 CERROR("cannot read %s: rc = %d\n", "lov_objids", rc);
222                 GOTO(err_reg, rc);
223         }
224
225         rc = llog_cat_initialize(obd, mds->mds_lov_desc.ld_tgt_count);
226         if (rc) {
227                 CERROR("failed to initialize catalog %d\n", rc);
228                 GOTO(err_reg, rc);
229         }
230
231         /* If we're mounting this code for the first time on an existing FS,
232          * we need to populate the objids array from the real OST values */
233         if (!mds->mds_lov_objids_valid) {
234                 int size = sizeof(obd_id) * mds->mds_lov_desc.ld_tgt_count;
235                 rc = obd_get_info(mds->mds_osc_exp, strlen("last_id"),
236                                   "last_id", &size, mds->mds_lov_objids);
237                 if (!rc) {
238                         for (i = 0; i < mds->mds_lov_desc.ld_tgt_count; i++)
239                                 CWARN("got last object "LPU64" from OST %d\n",
240                                       mds->mds_lov_objids[i], i);
241                         mds->mds_lov_objids_valid = 1;
242                         rc = mds_lov_write_objids(obd);
243                         if (rc)
244                                 CERROR("got last objids from OSTs, but error "
245                                        "writing objids file: %d\n", rc);
246                 }
247         }
248
249         /* I want to see a callback happen when the OBD moves to a
250          * "For General Use" state, and that's when we'll call
251          * set_nextid().  The class driver can help us here, because
252          * it can use the obd_recovering flag to determine when the
253          * the OBD is full available. */
254         if (!obd->obd_recovering)
255                 rc = mds_postrecov(obd);
256         RETURN(rc);
257
258 err_reg:
259         obd_register_observer(mds->mds_osc_obd, NULL);
260 err_discon:
261         obd_disconnect(mds->mds_osc_exp, 0);
262         mds->mds_osc_exp = NULL;
263         mds->mds_osc_obd = ERR_PTR(rc);
264         RETURN(rc);
265 }
266
267 int mds_lov_disconnect(struct obd_device *obd, int flags)
268 {
269         struct mds_obd *mds = &obd->u.mds;
270         int rc = 0;
271         ENTRY;
272
273         if (!IS_ERR(mds->mds_osc_obd) && mds->mds_osc_exp != NULL) {
274                 /* cleanup all llogging subsystems */
275                 rc = obd_llog_finish(obd, mds->mds_lov_desc.ld_tgt_count);
276                 if (rc)
277                         CERROR("failed to cleanup llogging subsystems\n");
278
279                 obd_register_observer(mds->mds_osc_obd, NULL);
280
281                 rc = obd_disconnect(mds->mds_osc_exp, flags);
282                 /* if obd_disconnect fails (probably because the
283                  * export was disconnected by class_disconnect_exports)
284                  * then we just need to drop our ref. */
285                 if (rc != 0)
286                         class_export_put(mds->mds_osc_exp);
287                 mds->mds_osc_exp = NULL;
288                 mds->mds_osc_obd = NULL;
289         }
290
291         RETURN(rc);
292 }
293
294 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
295                   void *karg, void *uarg)
296 {
297         static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
298         struct obd_device *obd = exp->exp_obd;
299         struct mds_obd *mds = &obd->u.mds;
300         struct obd_ioctl_data *data = karg;
301         struct obd_run_ctxt saved;
302         int rc = 0;
303
304         switch (cmd) {
305         case OBD_IOC_RECORD: {
306                 char *name = data->ioc_inlbuf1;
307                 if (mds->mds_cfg_llh)
308                         RETURN(-EBUSY);
309
310                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
311                 rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT),
312                                  &mds->mds_cfg_llh, NULL, name);
313                 if (rc == 0)
314                         llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
315                                          &cfg_uuid);
316                 else
317                         mds->mds_cfg_llh = NULL;
318                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
319
320                 RETURN(rc);
321         }
322
323         case OBD_IOC_ENDRECORD: {
324                 if (!mds->mds_cfg_llh)
325                         RETURN(-EBADF);
326
327                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
328                 rc = llog_close(mds->mds_cfg_llh);
329                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
330
331                 mds->mds_cfg_llh = NULL;
332                 RETURN(rc);
333         }
334
335         case OBD_IOC_CLEAR_LOG: {
336                 char *name = data->ioc_inlbuf1;
337                 if (mds->mds_cfg_llh)
338                         RETURN(-EBUSY);
339
340                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
341                 rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT), 
342                                  &mds->mds_cfg_llh, NULL, name);
343                 if (rc == 0) {
344                         llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
345                                          NULL);
346
347                         rc = llog_destroy(mds->mds_cfg_llh);
348                         llog_free_handle(mds->mds_cfg_llh);
349                 }
350                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
351
352                 mds->mds_cfg_llh = NULL;
353                 RETURN(rc);
354         }
355
356         case OBD_IOC_DORECORD: {
357                 char *cfg_buf;
358                 struct llog_rec_hdr rec;
359                 if (!mds->mds_cfg_llh)
360                         RETURN(-EBADF);
361
362                 rec.lrh_len = llog_data_len(data->ioc_plen1);
363
364                 if (data->ioc_type == LUSTRE_CFG_TYPE) {
365                         rec.lrh_type = OBD_CFG_REC;
366                 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
367                         rec.lrh_type = PTL_CFG_REC;
368                 } else {
369                         CERROR("unknown cfg record type:%d \n", data->ioc_type);
370                         RETURN(-EINVAL);
371                 }
372
373                 OBD_ALLOC(cfg_buf, data->ioc_plen1);
374                 if (cfg_buf == NULL)
375                         RETURN(-EINVAL);
376                 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
377                 if (rc) {
378                         OBD_FREE(cfg_buf, data->ioc_plen1);
379                         RETURN(rc);
380                 }
381
382                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
383                 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
384                                     cfg_buf, -1);
385                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
386
387                 OBD_FREE(cfg_buf, data->ioc_plen1);
388                 RETURN(rc);
389         }
390
391         case OBD_IOC_PARSE: {
392                 struct llog_ctxt *ctxt =
393                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
394                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
395                 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
396                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
397                 if (rc)
398                         RETURN(rc);
399
400                 RETURN(rc);
401         }
402
403         case OBD_IOC_DUMP_LOG: {
404                 struct llog_ctxt *ctxt =
405                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
406                 push_ctxt(&saved, &obd->obd_ctxt, NULL);
407                 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
408                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
409                 if (rc)
410                         RETURN(rc);
411
412                 RETURN(rc);
413         }
414
415         case OBD_IOC_SET_READONLY: {
416                 void *handle;
417                 struct inode *inode = obd->u.mds.mds_sb->s_root->d_inode;
418                 BDEVNAME_DECLARE_STORAGE(tmp);
419                 CERROR("setting device %s read-only\n",
420                        ll_bdevname(obd->u.mds.mds_sb, tmp));
421
422                 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
423                 LASSERT(handle);
424                 rc = fsfilt_commit(obd, inode, handle, 1);
425
426                 dev_set_rdonly(ll_sbdev(obd->u.mds.mds_sb), 2);
427                 RETURN(0);
428         }
429
430         case OBD_IOC_CATLOGLIST: {
431                 int count = mds->mds_lov_desc.ld_tgt_count;
432                 rc = llog_catalog_list(obd, count, data);
433                 RETURN(rc);
434
435         }
436         case OBD_IOC_LLOG_CHECK:
437         case OBD_IOC_LLOG_CANCEL:
438         case OBD_IOC_LLOG_REMOVE: {
439                 struct llog_ctxt *ctxt =
440                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
441                 int rc2;
442
443                 obd_llog_finish(obd, mds->mds_lov_desc.ld_tgt_count);
444                 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
445                 rc = llog_ioctl(ctxt, cmd, data);
446                 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
447                 llog_cat_initialize(obd, mds->mds_lov_desc.ld_tgt_count);
448                 rc2 = obd_set_info(mds->mds_osc_exp, strlen("mds_conn"),
449                                    "mds_conn", 0, NULL);
450                 if (!rc)
451                         rc = rc2;
452                 RETURN(rc);
453         }
454         case OBD_IOC_LLOG_INFO:
455         case OBD_IOC_LLOG_PRINT: {
456                 struct llog_ctxt *ctxt =
457                         llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
458
459                 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
460                 rc = llog_ioctl(ctxt, cmd, data);
461                 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
462
463                 RETURN(rc);
464         }
465
466         case OBD_IOC_ABORT_RECOVERY:
467                 CERROR("aborting recovery for device %s\n", obd->obd_name);
468                 target_abort_recovery(obd);
469                 RETURN(0);
470
471         default:
472                 RETURN(-EINVAL);
473         }
474         RETURN(0);
475
476 }
477
478 struct mds_lov_sync_info {
479         struct obd_device *mlsi_obd; /* the lov device to sync */
480         struct obd_uuid   *mlsi_uuid;  /* target to sync */
481 };
482
483 int mds_lov_synchronize(void *data)
484 {
485         struct mds_lov_sync_info *mlsi = data;
486         struct obd_device *obd;
487         struct obd_uuid *uuid;
488         unsigned long flags;
489         int rc;
490
491         lock_kernel();
492         ptlrpc_daemonize();
493
494         SIGNAL_MASK_LOCK(current, flags);
495         sigfillset(&current->blocked);
496         RECALC_SIGPENDING;
497         SIGNAL_MASK_UNLOCK(current, flags);
498
499         obd = mlsi->mlsi_obd;
500         uuid = mlsi->mlsi_uuid;
501
502         OBD_FREE(mlsi, sizeof(*mlsi));
503
504         LASSERT(obd != NULL);
505         LASSERT(uuid != NULL);
506
507         rc = obd_set_info(obd->u.mds.mds_osc_exp, strlen("mds_conn"), 
508                           "mds_conn", 0, uuid);
509         if (rc != 0)
510                 RETURN(rc);
511
512         rc = llog_connect(llog_get_context(obd, LLOG_UNLINK_ORIG_CTXT),
513                           obd->u.mds.mds_lov_desc.ld_tgt_count,
514                           NULL, NULL, uuid);
515         if (rc != 0) {
516                 CERROR("%s: failed at llog_origin_connect: %d\n", 
517                        obd->obd_name, rc);
518                 RETURN(rc);
519         }
520
521         CWARN("MDS %s: %s now active, resetting orphans\n",
522               obd->obd_name, uuid->uuid);
523         rc = mds_lov_clearorphans(&obd->u.mds, uuid);
524         if (rc != 0) {
525                 CERROR("%s: failed at mds_lov_clearorphans: %d\n", 
526                        obd->obd_name, rc);
527                 RETURN(rc);
528         }
529
530         RETURN(0);
531 }
532
533 int mds_lov_start_synchronize(struct obd_device *obd, struct obd_uuid *uuid)
534 {
535         struct mds_lov_sync_info *mlsi;
536         int rc;
537
538         ENTRY;
539
540         OBD_ALLOC(mlsi, sizeof(*mlsi));
541         if (mlsi == NULL)
542                 RETURN(-ENOMEM);
543
544         mlsi->mlsi_obd = obd;
545         mlsi->mlsi_uuid = uuid;
546
547         rc = kernel_thread(mds_lov_synchronize, mlsi, CLONE_VM | CLONE_FILES);
548         if (rc < 0)
549                 CERROR("%s: error starting mds_lov_synchronize: %d\n", 
550                        obd->obd_name, rc);
551         else {
552                 CDEBUG(D_HA, "%s: mds_lov_synchronize thread: %d\n", 
553                        obd->obd_name, rc);
554                 rc = 0;
555         }
556
557         RETURN(rc);
558 }
559
560 int mds_notify(struct obd_device *obd, struct obd_device *watched, int active)
561 {
562         struct obd_uuid *uuid;
563         int rc = 0;
564         ENTRY;
565
566         if (!active)
567                 RETURN(0);
568
569         if (strcmp(watched->obd_type->typ_name, "osc")) {
570                 CERROR("unexpected notification of %s %s!\n",
571                        watched->obd_type->typ_name, watched->obd_name);
572                 RETURN(-EINVAL);
573         }
574
575         uuid = &watched->u.cli.cl_import->imp_target_uuid;
576         if (obd->obd_recovering) {
577                 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
578                       obd->obd_name, uuid->uuid);
579         } else {
580                 LASSERT(llog_get_context(obd, LLOG_UNLINK_ORIG_CTXT) != NULL);
581
582                 rc = mds_lov_start_synchronize(obd, uuid);
583         }
584         RETURN(rc);
585 }
586
587 /* Convert the on-disk LOV EA structre.
588  * We always try to convert from an old LOV EA format to the common in-memory
589  * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
590  * then convert back to the new on-disk format and save it back to disk
591  * (obd_packmd() only ever saves to the new on-disk format) so we don't have
592  * to convert it each time this inode is accessed.
593  *
594  * This function is a bit interesting in the error handling.  We can safely
595  * ship the old lmm to the client in case of failure, since it uses the same
596  * obd_unpackmd() code and can do the conversion if the MDS fails for some
597  * reason.  We will not delete the old lmm data until we have written the
598  * new format lmm data in fsfilt_set_md(). */
599 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
600                        struct lov_mds_md *lmm, int lmm_size)
601 {
602         struct lov_stripe_md *lsm = NULL;
603         void *handle;
604         int rc, err;
605         ENTRY;
606
607         if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
608                 RETURN(0);
609
610         CDEBUG(D_INODE, "converting LOV EA on %lu/%u from V0 to V1\n",
611                inode->i_ino, inode->i_generation);
612         rc = obd_unpackmd(obd->u.mds.mds_osc_exp, &lsm, lmm, lmm_size);
613         if (rc < 0)
614                 GOTO(conv_end, rc);
615
616         rc = obd_packmd(obd->u.mds.mds_osc_exp, &lmm, lsm);
617         if (rc < 0)
618                 GOTO(conv_free, rc);
619         lmm_size = rc;
620
621         handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
622         if (IS_ERR(handle)) {
623                 rc = PTR_ERR(handle);
624                 GOTO(conv_free, rc);
625         }
626
627         rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size);
628
629         err = fsfilt_commit(obd, inode, handle, 0);
630         if (!rc)
631                 rc = err ? err : lmm_size;
632         GOTO(conv_free, rc);
633 conv_free:
634         obd_free_memmd(obd->u.mds.mds_osc_exp, &lsm);
635 conv_end:
636         return rc;
637 }