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