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