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