1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Server (mds) handling of striped file data
7 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
8 * Author: Peter Braam <braam@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
27 # define EXPORT_SYMTAB
29 #define DEBUG_SUBSYSTEM S_MDS
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>
40 #include "mds_internal.h"
42 void le_lov_desc_to_cpu (struct lov_desc *ld)
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);
50 void cpu_to_le_lov_desc (struct lov_desc *ld)
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);
58 void mds_lov_update_objids(struct obd_device *obd, obd_id *ids)
60 struct mds_obd *mds = &obd->u.mds;
64 spin_lock(&mds->mds_lov_lock);
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 spin_unlock(&mds->mds_lov_lock);
72 static int mds_lov_read_objids(struct obd_device *obd)
74 struct mds_obd *mds = &obd->u.mds;
77 int i, rc, size = mds->mds_lov_desc.ld_tgt_count * sizeof(*ids);
80 if (mds->mds_lov_objids != NULL)
86 mds->mds_lov_objids = ids;
88 if (mds->mds_lov_objid_filp->f_dentry->d_inode->i_size == 0)
90 rc = fsfilt_read_record(obd, mds->mds_lov_objid_filp, ids, size, &off);
92 CERROR("Error reading objids %d\n", rc);
94 mds->mds_lov_objids_valid = 1;
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);
105 int mds_lov_write_objids(struct obd_device *obd)
107 struct mds_obd *mds = &obd->u.mds;
109 int i, rc, size = mds->mds_lov_desc.ld_tgt_count * sizeof(obd_id);
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);
116 rc = fsfilt_write_record(obd, mds->mds_lov_objid_filp,
117 mds->mds_lov_objids, size, &off, 0);
121 int mds_lov_clearorphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
125 struct obd_trans_info oti = {0};
126 struct lov_stripe_md *empty_ea = NULL;
129 LASSERT(mds->mds_lov_objids != NULL);
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;
142 rc = obd_create(mds->mds_osc_exp, &oa, &empty_ea, &oti);
147 /* update the LOV-OSC knowledge of the last used object id's */
148 int mds_lov_set_nextid(struct obd_device *obd)
150 struct mds_obd *mds = &obd->u.mds;
154 LASSERT(!obd->obd_recovering);
156 LASSERT(mds->mds_lov_objids != NULL);
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);
163 /* tell the LOV-OSC by how much to pre-create */
164 int mds_lov_set_growth(struct mds_obd *mds, int count)
169 rc = obd_set_info(mds->mds_osc_exp, strlen("growth_count"),
170 "growth_count", sizeof(count), &count);
175 static int mds_lov_update_desc(struct obd_device *obd, struct obd_export *lov)
177 struct mds_obd *mds = &obd->u.mds;
178 int valsize = sizeof(mds->mds_lov_desc), rc, i;
179 int old_count = mds->mds_lov_desc.ld_tgt_count;
182 rc = obd_get_info(lov, strlen("lovdesc") + 1, "lovdesc", &valsize,
187 /* The size of the LOV target table may have increased. */
188 if (old_count >= mds->mds_lov_desc.ld_tgt_count) {
192 size = mds->mds_lov_desc.ld_tgt_count * sizeof(*ids);
193 OBD_ALLOC(ids, size);
197 memset(ids, 0, size);
199 if (mds->mds_lov_objids != NULL) {
200 int oldsize = old_count * sizeof(*ids);
202 memcpy(ids, mds->mds_lov_objids, oldsize);
203 OBD_FREE(mds->mds_lov_objids, oldsize);
205 mds->mds_lov_objids = ids;
208 i = lov_mds_md_size(mds->mds_lov_desc.ld_tgt_count);
209 if (i > mds->mds_max_mdsize)
210 mds->mds_max_mdsize = i;
211 mds->mds_max_cookiesize = mds->mds_lov_desc.ld_tgt_count *
212 sizeof(struct llog_cookie);
213 mds->mds_has_lov_desc = 1;
217 int mds_lov_connect(struct obd_device *obd, char * lov_name)
219 struct mds_obd *mds = &obd->u.mds;
220 struct lustre_handle conn = {0,};
221 char name[32] = "CATLIST";
226 if (IS_ERR(mds->mds_osc_obd))
227 RETURN(PTR_ERR(mds->mds_osc_obd));
229 if (mds->mds_osc_obd)
232 spin_lock_init(&mds->mds_lov_lock);
233 mds->mds_osc_obd = class_name2obd(lov_name);
234 if (!mds->mds_osc_obd) {
235 CERROR("MDS cannot locate LOV %s\n",
237 mds->mds_osc_obd = ERR_PTR(-ENOTCONN);
241 CDEBUG(D_HA, "obd: %s osc: %s lov_name: %s\n",
242 obd->obd_name, mds->mds_osc_obd->obd_name, lov_name);
244 rc = obd_connect(&conn, mds->mds_osc_obd, &obd->obd_uuid,
245 mds->mds_num + FILTER_GROUP_FIRST_MDS);
247 CERROR("MDS cannot connect to LOV %s (%d)\n",
249 mds->mds_osc_obd = ERR_PTR(rc);
252 mds->mds_osc_exp = class_conn2export(&conn);
254 rc = obd_register_observer(mds->mds_osc_obd, obd);
256 CERROR("MDS cannot register as observer of LOV %s (%d)\n",
258 GOTO(err_discon, rc);
261 rc = mds_lov_update_desc(obd, mds->mds_osc_exp);
265 rc = mds_lov_read_objids(obd);
267 CERROR("cannot read %s: rc = %d\n", "lov_objids", rc);
271 rc = obd_llog_cat_initialize(obd, &obd->obd_llogs,
272 mds->mds_lov_desc.ld_tgt_count, name);
274 CERROR("failed to initialize catalog %d\n", rc);
278 /* FIXME before set info call is made, we must initialize logging */
279 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
280 valsize = sizeof(group);
281 rc = obd_set_info(mds->mds_osc_exp, strlen("mds_conn"), "mds_conn",
286 /* If we're mounting this code for the first time on an existing FS,
287 * we need to populate the objids array from the real OST values */
288 if (!mds->mds_lov_objids_valid) {
289 int size = sizeof(obd_id) * mds->mds_lov_desc.ld_tgt_count;
290 rc = obd_get_info(mds->mds_osc_exp, strlen("last_id"),
291 "last_id", &size, mds->mds_lov_objids);
293 for (i = 0; i < mds->mds_lov_desc.ld_tgt_count; i++)
294 CWARN("got last object "LPU64" from OST %d\n",
295 mds->mds_lov_objids[i], i);
296 mds->mds_lov_objids_valid = 1;
297 rc = mds_lov_write_objids(obd);
299 CERROR("got last objids from OSTs, but error "
300 "writing objids file: %d\n", rc);
304 /* I want to see a callback happen when the OBD moves to a
305 * "For General Use" state, and that's when we'll call
306 * set_nextid(). The class driver can help us here, because
307 * it can use the obd_recovering flag to determine when the
308 * the OBD is full available. */
309 if (!obd->obd_recovering)
310 rc = mds_postrecov(obd);
314 obd_register_observer(mds->mds_osc_obd, NULL);
316 obd_disconnect(mds->mds_osc_exp, 0);
317 mds->mds_osc_exp = NULL;
318 mds->mds_osc_obd = ERR_PTR(rc);
322 int mds_lov_disconnect(struct obd_device *obd, int flags)
324 struct mds_obd *mds = &obd->u.mds;
328 if (!IS_ERR(mds->mds_osc_obd) && mds->mds_osc_exp != NULL) {
329 /* cleanup all llogging subsystems */
330 rc = obd_llog_finish(obd, &obd->obd_llogs,
331 mds->mds_lov_desc.ld_tgt_count);
333 CERROR("failed to cleanup llogging subsystems\n");
335 obd_register_observer(mds->mds_osc_obd, NULL);
337 rc = obd_disconnect(mds->mds_osc_exp, flags);
338 /* if obd_disconnect fails (probably because the
339 * export was disconnected by class_disconnect_exports)
340 * then we just need to drop our ref. */
342 class_export_put(mds->mds_osc_exp);
343 mds->mds_osc_exp = NULL;
344 mds->mds_osc_obd = NULL;
350 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
351 void *karg, void *uarg)
353 static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
354 struct obd_device *obd = exp->exp_obd;
355 struct mds_obd *mds = &obd->u.mds;
356 struct obd_ioctl_data *data = karg;
357 struct lvfs_run_ctxt saved;
362 case OBD_IOC_RECORD: {
363 char *name = data->ioc_inlbuf1;
364 if (mds->mds_cfg_llh)
367 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
368 rc = llog_open(llog_get_context(&obd->obd_llogs,
369 LLOG_CONFIG_ORIG_CTXT),
370 &mds->mds_cfg_llh, NULL, name,
373 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
376 mds->mds_cfg_llh = NULL;
377 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
382 case OBD_IOC_ENDRECORD: {
383 if (!mds->mds_cfg_llh)
386 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
387 rc = llog_close(mds->mds_cfg_llh);
388 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
390 mds->mds_cfg_llh = NULL;
394 case OBD_IOC_CLEAR_LOG: {
395 char *name = data->ioc_inlbuf1;
396 if (mds->mds_cfg_llh)
399 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
400 rc = llog_open(llog_get_context(&obd->obd_llogs,
401 LLOG_CONFIG_ORIG_CTXT),
402 &mds->mds_cfg_llh, NULL, name,
405 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
408 rc = llog_destroy(mds->mds_cfg_llh);
409 llog_free_handle(mds->mds_cfg_llh);
411 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
413 mds->mds_cfg_llh = NULL;
417 case OBD_IOC_DORECORD: {
419 struct llog_rec_hdr rec;
420 if (!mds->mds_cfg_llh)
423 /* XXX - this probably should be a parameter to this ioctl.
424 * For now, just use llh_max_transno for expediency. */
425 rec.lrh_len = llog_data_len(data->ioc_plen1);
427 if (data->ioc_type == LUSTRE_CFG_TYPE) {
428 rec.lrh_type = OBD_CFG_REC;
429 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
430 rec.lrh_type = PTL_CFG_REC;
432 CERROR("unknown cfg record type:%d \n", data->ioc_type);
436 OBD_ALLOC(cfg_buf, data->ioc_plen1);
439 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
441 OBD_FREE(cfg_buf, data->ioc_plen1);
445 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
446 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
448 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
450 OBD_FREE(cfg_buf, data->ioc_plen1);
453 case OBD_IOC_SNAP_ADD: {
454 char *name = data->ioc_inlbuf1;
456 rc = fsfilt_set_snap_item(obd, mds->mds_sb, name);
460 case OBD_IOC_PARSE: {
461 struct llog_ctxt *ctxt =
462 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
463 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
464 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
465 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
472 case OBD_IOC_DUMP_LOG: {
473 struct llog_ctxt *ctxt =
474 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
475 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
476 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
477 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
482 case OBD_IOC_SET_READONLY: {
484 struct inode *inode = obd->u.mds.mds_sb->s_root->d_inode;
485 BDEVNAME_DECLARE_STORAGE(tmp);
486 CERROR("setting device %s read-only\n",
487 ll_bdevname(obd->u.mds.mds_sb, tmp));
489 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
491 rc = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 1);
493 dev_set_rdonly(ll_sbdev(obd->u.mds.mds_sb), 2);
497 case OBD_IOC_CATLOGLIST: {
498 int count = mds->mds_lov_desc.ld_tgt_count;
499 rc = llog_catalog_list(obd, count, data);
503 case OBD_IOC_LLOG_CHECK:
504 case OBD_IOC_LLOG_CANCEL:
505 case OBD_IOC_LLOG_REMOVE: {
506 struct llog_ctxt *ctxt =
507 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
508 char name[32] = "CATLIST";
511 obd_llog_finish(obd, &obd->obd_llogs,
512 mds->mds_lov_desc.ld_tgt_count);
513 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
514 rc = llog_ioctl(ctxt, cmd, data);
515 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
516 obd_llog_cat_initialize(obd, &obd->obd_llogs,
517 mds->mds_lov_desc.ld_tgt_count,
519 rc2 = obd_set_info(mds->mds_osc_exp, strlen("mds_conn"),
520 "mds_conn", 0, NULL);
525 case OBD_IOC_LLOG_INFO:
526 case OBD_IOC_LLOG_PRINT: {
527 struct llog_ctxt *ctxt =
528 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
530 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
531 rc = llog_ioctl(ctxt, cmd, data);
532 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
537 case OBD_IOC_ABORT_RECOVERY:
538 target_stop_recovery_thread(obd);
548 struct mds_lov_sync_info {
549 struct obd_device *mlsi_obd; /* the mds to sync */
550 struct obd_device *mlsi_watched; /* new lov target */
551 int mlsi_index; /* index into mds_lov_objids */
554 int mds_lov_synchronize(void *data)
556 struct mds_lov_sync_info *mlsi = data;
557 struct llog_ctxt *ctxt;
558 struct obd_device *obd;
559 struct obd_device *watched;
561 struct obd_uuid *uuid;
570 char name[32] = "CATLIST";
576 SIGNAL_MASK_LOCK(current, flags);
577 sigfillset(¤t->blocked);
579 SIGNAL_MASK_UNLOCK(current, flags);
583 obd = mlsi->mlsi_obd;
584 watched = mlsi->mlsi_watched;
585 index = mlsi->mlsi_index;
587 LASSERT(obd != NULL);
588 LASSERT(watched != NULL);
590 OBD_FREE(mlsi, sizeof(*mlsi));
593 uuid = &watched->u.cli.cl_import->imp_target_uuid;
595 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
596 rc = obd_set_info(watched->obd_self_export, strlen("mds_conn"),
597 "mds_conn", sizeof(group), &group);
601 old_count = mds->mds_lov_desc.ld_tgt_count;
603 rc = mds_lov_update_desc(obd, mds->mds_osc_exp);
607 count = mds->mds_lov_desc.ld_tgt_count;
608 LASSERT(count >= old_count);
610 vallen = sizeof(vals[1]);
611 rc = obd_get_info(watched->obd_self_export, strlen("last_id"),
612 "last_id", &vallen, &vals[1]);
617 rc = mds_lov_set_info(obd->obd_self_export, strlen("next_id"),
622 obd_llog_finish(obd, &obd->obd_llogs, old_count);
623 obd_llog_cat_initialize(obd, &obd->obd_llogs, count, name);
625 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
626 LASSERT(ctxt != NULL);
628 rc = llog_connect(ctxt, count, NULL, NULL, uuid);
630 CERROR("%s: failed at llog_origin_connect: %d\n",
635 CWARN("MDS %s: %s now active, resetting orphans\n",
636 obd->obd_name, uuid->uuid);
638 rc = mds_lov_clearorphans(&obd->u.mds, uuid);
640 CERROR("%s: failed at mds_lov_clearorphans: %d\n",
648 int mds_lov_start_synchronize(struct obd_device *obd,
649 struct obd_device *watched, void *data)
651 struct mds_lov_sync_info *mlsi;
656 OBD_ALLOC(mlsi, sizeof(*mlsi));
660 mlsi->mlsi_obd = obd;
661 mlsi->mlsi_watched = watched;
662 mlsi->mlsi_index = (int)data;
664 rc = kernel_thread(mds_lov_synchronize, mlsi, CLONE_VM | CLONE_FILES);
666 CERROR("%s: error starting mds_lov_synchronize: %d\n",
669 CDEBUG(D_HA, "%s: mds_lov_synchronize thread: %d\n",
677 int mds_notify(struct obd_device *obd, struct obd_device *watched,
678 int active, void *data)
686 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
687 CERROR("unexpected notification of %s %s!\n",
688 watched->obd_type->typ_name, watched->obd_name);
692 if (obd->obd_recovering) {
693 struct obd_uuid *uuid;
694 uuid = &watched->u.cli.cl_import->imp_target_uuid;
696 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
697 obd->obd_name, uuid->uuid);
699 rc = mds_lov_start_synchronize(obd, watched, data);
704 int mds_lov_set_info(struct obd_export *exp, obd_count keylen,
705 void *key, obd_count vallen, void *val)
707 struct obd_device *obd = class_exp2obd(exp);
708 struct mds_obd *mds = &obd->u.mds;
711 #define KEY_IS(str) \
712 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
714 if (KEY_IS("next_id")) {
715 obd_id *id = (obd_id *)val;
718 /* XXX - this really should be vallen != (2 * sizeof(*id)) *
719 * Just following the precedent set by lov_set_info. */
724 if ((idx != *id) || (idx >= mds->mds_lov_desc.ld_tgt_count))
727 CDEBUG(D_CONFIG, "idx: %d id: %llu\n", idx, *(id + 1));
729 mds->mds_lov_objids[idx] = *++id;
730 CDEBUG(D_CONFIG, "objid: %d: %lld\n", idx, *id);
731 /* XXX - should we be writing this out here ? */
732 RETURN(mds_lov_write_objids(obd));
738 int mds_lov_update_config(struct obd_device *obd, int clean)
740 struct mds_obd *mds = &obd->u.mds;
741 struct lvfs_run_ctxt saved;
742 struct config_llog_instance cfg;
743 struct llog_ctxt *ctxt;
744 char *profile = mds->mds_profile, *name;
745 int rc, version, namelen;
751 cfg.cfg_instance = NULL;
752 cfg.cfg_uuid = mds->mds_lov_uuid;
754 namelen = strlen(profile) + 20; /* -clean-######### */
755 OBD_ALLOC(name, namelen);
760 version = mds->mds_config_version - 1;
761 sprintf(name, "%s-clean-%d", profile, version);
763 version = mds->mds_config_version + 1;
764 sprintf(name, "%s-%d", profile, version);
767 CWARN("Applying configuration log %s\n", name);
769 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
770 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
771 rc = class_config_process_llog(ctxt, name, &cfg);
772 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
774 mds->mds_config_version = version;
776 CWARN("Finished applying configuration log %s: %d\n", name, rc);
778 OBD_FREE(name, namelen);
782 /* Convert the on-disk LOV EA structre.
783 * We always try to convert from an old LOV EA format to the common in-memory
784 * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
785 * then convert back to the new on-disk format and save it back to disk
786 * (obd_packmd() only ever saves to the new on-disk format) so we don't have
787 * to convert it each time this inode is accessed.
789 * This function is a bit interesting in the error handling. We can safely
790 * ship the old lmm to the client in case of failure, since it uses the same
791 * obd_unpackmd() code and can do the conversion if the MDS fails for some
792 * reason. We will not delete the old lmm data until we have written the
793 * new format lmm data in fsfilt_set_md(). */
794 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
795 struct lov_mds_md *lmm, int lmm_size)
797 struct lov_stripe_md *lsm = NULL;
802 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
805 CWARN("converting LOV EA on %lu/%u from V0 to V1\n",
806 inode->i_ino, inode->i_generation);
807 rc = obd_unpackmd(obd->u.mds.mds_osc_exp, &lsm, lmm, lmm_size);
811 rc = obd_packmd(obd->u.mds.mds_osc_exp, &lmm, lsm);
816 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
817 if (IS_ERR(handle)) {
818 rc = PTR_ERR(handle);
822 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size);
824 err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0);
826 rc = err ? err : lmm_size;
829 obd_free_memmd(obd->u.mds.mds_osc_exp, &lsm);
834 /* Must be called with i_sem held */
835 int mds_revalidate_lov_ea(struct obd_device *obd, struct inode *inode,
836 struct lustre_msg *msg, int offset)
838 struct mds_obd *mds = &obd->u.mds;
839 struct obd_export *osc_exp = mds->mds_osc_exp;
840 struct lov_mds_md *lmm= NULL;
841 struct lov_stripe_md *lsm = NULL;
843 struct obd_trans_info oti = {0};
845 int lmm_size = 0, lsm_size = 0, err, rc;
849 LASSERT(down_trylock(&inode->i_sem) != 0);
851 /* XXX - add way to know if EA is already up to date & return
852 * without doing anything. Easy to do since we get notified of
855 lmm = lustre_msg_buf(msg, offset, 0);
857 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
861 lmm_size = msg->buflens[offset];
863 rc = obd_unpackmd(osc_exp, &lsm, lmm, lmm_size);
869 LASSERT(lsm->lsm_magic == LOV_MAGIC);
873 GOTO(out_lsm, rc = -ENOMEM);
874 oa->o_mode = S_IFREG | 0600;
875 oa->o_id = inode->i_ino;
876 oa->o_generation = inode->i_generation;
877 oa->o_uid = 0; /* must have 0 uid / gid on OST */
879 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
881 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
882 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID |
884 valid = OBD_MD_FLTYPE | OBD_MD_FLATIME | OBD_MD_FLMTIME |
886 obdo_from_inode(oa, inode, valid);
888 rc = obd_revalidate_md(osc_exp, oa, lsm, &oti);
892 CERROR("Error validating LOV EA on %lu/%u: %d\n",
893 inode->i_ino, inode->i_generation, rc);
897 rc = obd_packmd(osc_exp, &lmm, lsm);
902 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
903 if (IS_ERR(handle)) {
904 rc = PTR_ERR(handle);
908 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size);
909 err = fsfilt_commit(obd, inode->i_sb, inode, handle, 0);
915 obd_free_memmd(osc_exp, &lsm);