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