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>
39 #include <linux/lustre_sec.h>
41 #include "mds_internal.h"
43 void le_lov_desc_to_cpu (struct lov_desc *ld)
45 ld->ld_tgt_count = le32_to_cpu (ld->ld_tgt_count);
46 ld->ld_default_stripe_count = le32_to_cpu (ld->ld_default_stripe_count);
47 ld->ld_default_stripe_size = le32_to_cpu (ld->ld_default_stripe_size);
48 ld->ld_pattern = le32_to_cpu (ld->ld_pattern);
51 void cpu_to_le_lov_desc (struct lov_desc *ld)
53 ld->ld_tgt_count = cpu_to_le32 (ld->ld_tgt_count);
54 ld->ld_default_stripe_count = cpu_to_le32 (ld->ld_default_stripe_count);
55 ld->ld_default_stripe_size = cpu_to_le32 (ld->ld_default_stripe_size);
56 ld->ld_pattern = cpu_to_le32 (ld->ld_pattern);
59 void mds_dt_save_objids(struct obd_device *obd, obd_id *ids)
61 struct mds_obd *mds = &obd->u.mds;
65 spin_lock(&mds->mds_dt_lock);
66 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
67 ids[i] = mds->mds_dt_objids[i];
68 spin_unlock(&mds->mds_dt_lock);
72 void mds_dt_update_objids(struct obd_device *obd, obd_id *ids)
74 struct mds_obd *mds = &obd->u.mds;
78 spin_lock(&mds->mds_dt_lock);
79 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
80 if (ids[i] > mds->mds_dt_objids[i])
81 mds->mds_dt_objids[i] = ids[i];
82 spin_unlock(&mds->mds_dt_lock);
86 static int mds_dt_read_objids(struct obd_device *obd)
88 struct mds_obd *mds = &obd->u.mds;
94 if (mds->mds_dt_objids != NULL)
97 size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
101 mds->mds_dt_objids = ids;
103 if (mds->mds_dt_objid_filp->f_dentry->d_inode->i_size == 0)
106 rc = fsfilt_read_record(obd, mds->mds_dt_objid_filp, ids, size, &off);
108 CERROR("error reading objids %d\n", rc);
110 mds->mds_dt_objids_valid = 1;
114 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++) {
115 CDEBUG(D_INFO, "read last object "LPU64
116 " for idx %d\n", mds->mds_dt_objids[i], i);
122 int mds_dt_write_objids(struct obd_device *obd)
124 struct mds_obd *mds = &obd->u.mds;
129 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
130 CDEBUG(D_INFO, "writing last object "LPU64" for idx %d\n",
131 mds->mds_dt_objids[i], i);
133 size = mds->mds_dt_desc.ld_tgt_count * sizeof(obd_id);
134 rc = fsfilt_write_record(obd, mds->mds_dt_objid_filp,
135 mds->mds_dt_objids, size, &off, 0);
139 int mds_dt_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
141 struct lov_stripe_md *empty_ea = NULL;
142 struct obd_trans_info oti = { 0 };
143 struct obdo *oa = NULL;
147 LASSERT(mds->mds_dt_objids != NULL);
150 * this create will in fact either create or destroy: If the OST is
151 * missing objects below this ID, they will be created. If it finds
152 * objects above this ID, they will be removed.
158 memset(oa, 0, sizeof(*oa));
160 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
161 oa->o_valid = OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
162 oa->o_flags = OBD_FL_DELORPHAN;
164 if (ost_uuid != NULL) {
165 memcpy(&oa->o_inline, ost_uuid,
167 oa->o_valid |= OBD_MD_FLINLINE;
171 * passing current objids for letting data layer know last objids MDS
172 * knows about and do appropriate. --umka
174 oti.oti_objid = mds->mds_dt_objids;
176 rc = obd_create(mds->mds_dt_exp, oa,
177 NULL, 0, &empty_ea, &oti);
183 /* tell the LOV-OSC by how much to pre-create */
184 int mds_dt_set_growth(struct mds_obd *mds, int count)
189 rc = obd_set_info(mds->mds_dt_exp, strlen("growth_count"),
190 "growth_count", sizeof(count), &count);
195 static int mds_dt_update_desc(struct obd_device *obd, struct obd_export *lov)
197 struct mds_obd *mds = &obd->u.mds;
198 __u32 valsize = sizeof(mds->mds_dt_desc);
199 int old_count, rc = 0, i;
202 old_count = mds->mds_dt_desc.ld_tgt_count;
204 rc = obd_get_info(lov, strlen("lovdesc") + 1, "lovdesc",
205 &valsize, &mds->mds_dt_desc);
209 /* The size of the LOV target table may have increased. */
210 if (old_count >= mds->mds_dt_desc.ld_tgt_count) {
214 size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
215 OBD_ALLOC(ids, size);
219 memset(ids, 0, size);
221 if (mds->mds_dt_objids != NULL) {
222 int oldsize = old_count * sizeof(*ids);
224 memcpy(ids, mds->mds_dt_objids, oldsize);
225 OBD_FREE(mds->mds_dt_objids, oldsize);
227 mds->mds_dt_objids = ids;
230 i = lov_mds_md_size(mds->mds_dt_desc.ld_tgt_count);
231 if (i > mds->mds_max_mdsize)
232 mds->mds_max_mdsize = i;
233 mds->mds_max_cookiesize = mds->mds_dt_desc.ld_tgt_count *
234 sizeof(struct llog_cookie);
235 mds->mds_has_dt_desc = 1;
239 int mds_dt_connect(struct obd_device *obd, char *lov_name)
241 struct mds_obd *mds = &obd->u.mds;
242 struct lustre_handle conn = { 0 };
243 unsigned long sec_flags = PTLRPC_SEC_FL_MDS;
247 if (IS_ERR(mds->mds_dt_obd))
248 RETURN(PTR_ERR(mds->mds_dt_obd));
253 spin_lock_init(&mds->mds_dt_lock);
254 mds->mds_dt_obd = class_name2obd(lov_name);
255 if (!mds->mds_dt_obd) {
256 CERROR("MDS cannot locate LOV %s\n", lov_name);
257 mds->mds_dt_obd = ERR_PTR(-ENOTCONN);
261 if (mds->mds_ost_sec) {
262 rc = obd_set_info(mds->mds_dt_obd->obd_self_export,
263 strlen("sec"), "sec",
264 strlen(mds->mds_ost_sec), mds->mds_ost_sec);
266 mds->mds_dt_obd = ERR_PTR(rc);
271 rc = obd_set_info(mds->mds_dt_obd->obd_self_export,
272 strlen("sec_flags"), "sec_flags",
273 sizeof(sec_flags), &sec_flags);
275 mds->mds_dt_obd = ERR_PTR(rc);
279 CDEBUG(D_HA, "obd: %s osc: %s lov_name: %s\n",
280 obd->obd_name, mds->mds_dt_obd->obd_name, lov_name);
282 rc = obd_connect(&conn, mds->mds_dt_obd, &obd->obd_uuid, NULL,
283 mds->mds_num + FILTER_GROUP_FIRST_MDS);
285 CERROR("MDS cannot connect to LOV %s (%d)\n", lov_name, rc);
286 mds->mds_dt_obd = ERR_PTR(rc);
289 mds->mds_dt_exp = class_conn2export(&conn);
291 rc = obd_register_observer(mds->mds_dt_obd, obd);
293 CERROR("MDS cannot register as observer of LOV %s (%d)\n",
295 GOTO(err_discon, rc);
298 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
302 rc = mds_dt_read_objids(obd);
304 CERROR("cannot read %s: rc = %d\n", "lov_objids", rc);
308 rc = obd_llog_cat_initialize(obd, &obd->obd_llogs,
309 mds->mds_dt_desc.ld_tgt_count, CATLIST);
311 CERROR("failed to initialize catalog %d\n", rc);
316 * If we're mounting this code for the first time on an existing FS, we
317 * need to populate the objids array from the real OST values.
319 if (!mds->mds_dt_objids_valid) {
320 __u32 size = sizeof(obd_id) * mds->mds_dt_desc.ld_tgt_count;
322 rc = obd_get_info(mds->mds_dt_exp, strlen("last_id"),
323 "last_id", &size, mds->mds_dt_objids);
325 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
326 CWARN("got last object "LPU64" from OST %d\n",
327 mds->mds_dt_objids[i], i);
328 mds->mds_dt_objids_valid = 1;
329 rc = mds_dt_write_objids(obd);
331 CERROR("got last objids from OSTs, but error "
332 "writing objids file: %d\n", rc);
337 * I want to see a callback happen when the OBD moves to a "For General
338 * Use" state, and that's when we'll call set_nextid(). The class driver
339 * can help us here, because it can use the obd_recovering flag to
340 * determine when the the OBD is full available.
342 if (!obd->obd_recovering) {
343 CDEBUG(D_OTHER, "call mds_postrecov_common()\n");
344 rc = mds_postrecov_common(obd);
351 obd_register_observer(mds->mds_dt_obd, NULL);
353 obd_disconnect(mds->mds_dt_exp, 0);
354 mds->mds_dt_obd = ERR_PTR(rc);
355 mds->mds_dt_exp = NULL;
359 int mds_dt_disconnect(struct obd_device *obd, int flags)
361 struct mds_obd *mds = &obd->u.mds;
365 if (!IS_ERR(mds->mds_dt_obd) && mds->mds_dt_exp != NULL) {
366 /* cleanup all llogging subsystems */
367 rc = obd_llog_finish(obd, &obd->obd_llogs,
368 mds->mds_dt_desc.ld_tgt_count);
370 CERROR("failed to cleanup llogging subsystems\n");
372 obd_register_observer(mds->mds_dt_obd, NULL);
374 rc = obd_disconnect(mds->mds_dt_exp, flags);
375 /* if obd_disconnect fails (probably because the
376 * export was disconnected by class_disconnect_exports)
377 * then we just need to drop our ref. */
379 class_export_put(mds->mds_dt_exp);
380 mds->mds_dt_exp = NULL;
381 mds->mds_dt_obd = NULL;
387 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
388 void *karg, void *uarg)
390 static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
391 struct obd_device *obd = exp->exp_obd;
392 struct mds_obd *mds = &obd->u.mds;
393 struct obd_ioctl_data *data = karg;
394 struct lvfs_run_ctxt saved;
398 CDEBUG(D_INFO, "ioctl cmd %x\n", cmd);
400 case OBD_IOC_RECORD: {
401 char *name = data->ioc_inlbuf1;
402 if (mds->mds_cfg_llh)
405 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
406 rc = llog_open(llog_get_context(&obd->obd_llogs,
407 LLOG_CONFIG_ORIG_CTXT),
408 &mds->mds_cfg_llh, NULL, name,
411 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
414 mds->mds_cfg_llh = NULL;
415 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
420 case OBD_IOC_ENDRECORD: {
421 if (!mds->mds_cfg_llh)
424 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
425 rc = llog_close(mds->mds_cfg_llh);
426 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
428 mds->mds_cfg_llh = NULL;
432 case OBD_IOC_CLEAR_LOG: {
433 char *name = data->ioc_inlbuf1;
434 if (mds->mds_cfg_llh)
437 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
438 rc = llog_open(llog_get_context(&obd->obd_llogs,
439 LLOG_CONFIG_ORIG_CTXT),
440 &mds->mds_cfg_llh, NULL, name,
443 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
446 rc = llog_destroy(mds->mds_cfg_llh);
447 llog_free_handle(mds->mds_cfg_llh);
449 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
451 mds->mds_cfg_llh = NULL;
455 case OBD_IOC_DORECORD: {
457 struct llog_rec_hdr rec;
458 if (!mds->mds_cfg_llh)
461 /* XXX - this probably should be a parameter to this ioctl.
462 * For now, just use llh_max_transno for expediency. */
463 rec.lrh_len = llog_data_len(data->ioc_plen1);
465 if (data->ioc_type == LUSTRE_CFG_TYPE) {
466 rec.lrh_type = OBD_CFG_REC;
467 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
468 rec.lrh_type = PTL_CFG_REC;
470 CERROR("unknown cfg record type:%d \n", data->ioc_type);
474 OBD_ALLOC(cfg_buf, data->ioc_plen1);
477 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
479 OBD_FREE(cfg_buf, data->ioc_plen1);
483 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
484 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
486 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
488 OBD_FREE(cfg_buf, data->ioc_plen1);
491 case OBD_IOC_PARSE: {
492 struct llog_ctxt *ctxt =
493 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
494 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
495 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
496 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
502 case OBD_IOC_DUMP_LOG: {
503 struct llog_ctxt *ctxt =
504 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
505 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
506 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
507 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
511 case OBD_IOC_SET_READONLY: {
513 struct inode *inode = obd->u.mds.mds_sb->s_root->d_inode;
514 BDEVNAME_DECLARE_STORAGE(tmp);
515 CERROR("setting device %s read-only\n",
516 ll_bdevname(obd->u.mds.mds_sb, tmp));
518 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
520 rc = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 1);
522 ll_set_rdonly(ll_sbdev(obd->u.mds.mds_sb));
526 case OBD_IOC_CATLOGLIST: {
527 int count = mds->mds_dt_desc.ld_tgt_count;
528 rc = llog_catalog_list(obd, count, data);
532 case OBD_IOC_LLOG_CHECK:
533 case OBD_IOC_LLOG_CANCEL:
534 case OBD_IOC_LLOG_REMOVE: {
535 struct llog_ctxt *ctxt =
536 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
540 obd_llog_finish(obd, &obd->obd_llogs,
541 mds->mds_dt_desc.ld_tgt_count);
542 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
543 rc = llog_ioctl(ctxt, cmd, data);
544 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
545 obd_llog_cat_initialize(obd, &obd->obd_llogs,
546 mds->mds_dt_desc.ld_tgt_count,
548 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
549 valsize = sizeof(group);
550 rc2 = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
551 "mds_conn", valsize, &group);
556 case OBD_IOC_LLOG_INFO:
557 case OBD_IOC_LLOG_PRINT: {
558 struct llog_ctxt *ctxt =
559 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
561 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
562 rc = llog_ioctl(ctxt, cmd, data);
563 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
568 case OBD_IOC_ABORT_RECOVERY:
569 target_stop_recovery_thread(obd);
571 case OBD_IOC_ROOT_SQUASH: {
572 __u32 *p = (__u32 *) data->ioc_inlbuf1;
574 if (data->ioc_inllen1 !=
575 (sizeof(__u32) * 4 + sizeof(ptl_nid_t)))
578 if (*p == 0) { /* get */
580 *p++ = mds->mds_squash_uid;
581 *p++ = mds->mds_squash_gid;
582 *((ptl_nid_t*) p) = mds->mds_nosquash_nid;
585 mds->mds_squash_uid = *p++;
586 mds->mds_squash_gid = *p++;
587 mds->mds_nosquash_nid = *((ptl_nid_t*) p);
588 CWARN("MDS: squash root to %d:%d, except nid 0x%llx\n",
589 mds->mds_squash_uid, mds->mds_squash_gid,
590 mds->mds_nosquash_nid);
595 CDEBUG(D_INFO, "unknown command %x\n", cmd);
602 struct mds_dt_sync_info {
603 struct obd_device *mlsi_obd; /* the mds to sync */
604 struct obd_device *mlsi_watched; /* new lov target */
605 int mlsi_index; /* index into mds_dt_objids */
608 int mds_dt_synchronize(void *data)
610 struct mds_dt_sync_info *mlsi = data;
611 struct llog_ctxt *ctxt;
612 struct obd_device *obd;
613 struct obd_device *watched;
615 struct obd_uuid *uuid;
624 char name[32] = "CATLIST";
630 SIGNAL_MASK_LOCK(current, flags);
631 sigfillset(¤t->blocked);
633 SIGNAL_MASK_UNLOCK(current, flags);
637 obd = mlsi->mlsi_obd;
638 watched = mlsi->mlsi_watched;
639 index = mlsi->mlsi_index;
641 LASSERT(obd != NULL);
642 LASSERT(watched != NULL);
644 OBD_FREE(mlsi, sizeof(*mlsi));
647 down(&mds->mds_orphan_recovery_sem);
649 uuid = &watched->u.cli.cl_import->imp_target_uuid;
651 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
652 rc = obd_set_info(watched->obd_self_export, strlen("mds_conn"),
653 "mds_conn", sizeof(group), &group);
657 old_count = mds->mds_dt_desc.ld_tgt_count;
659 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
663 count = mds->mds_dt_desc.ld_tgt_count;
664 LASSERT(count >= old_count);
666 vallen = sizeof(vals[1]);
667 rc = obd_get_info(watched->obd_self_export, strlen("last_id"),
668 "last_id", &vallen, &vals[1]);
672 /* we don't set next id manually, instead OSCs will set them
673 * during own recovery from DELORPHAN reply -bzzz */
676 rc = mds_dt_set_info(obd->obd_self_export, strlen("next_id"),
682 obd_llog_finish(obd, &obd->obd_llogs, old_count);
683 obd_llog_cat_initialize(obd, &obd->obd_llogs, count, name);
685 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
686 LASSERT(ctxt != NULL);
688 rc = llog_connect(ctxt, count, NULL, NULL, uuid);
690 CERROR("%s: failed at llog_origin_connect: %d\n",
695 CWARN("MDS %s: %s now active, resetting orphans\n",
696 obd->obd_name, uuid->uuid);
698 rc = mds_dt_clear_orphans(&obd->u.mds, uuid);
700 CERROR("%s: failed at mds_dt_clear_orphans(): %d\n",
708 up(&mds->mds_orphan_recovery_sem);
712 int mds_dt_start_synchronize(struct obd_device *obd,
713 struct obd_device *watched,
716 struct mds_dt_sync_info *mlsi;
721 OBD_ALLOC(mlsi, sizeof(*mlsi));
725 mlsi->mlsi_obd = obd;
726 mlsi->mlsi_watched = watched;
727 mlsi->mlsi_index = (int)data;
729 rc = kernel_thread(mds_dt_synchronize, mlsi, CLONE_VM | CLONE_FILES);
731 CERROR("%s: error starting mds_dt_synchronize(): %d\n",
734 CDEBUG(D_HA, "%s: mds_dt_synchronize() thread: %d\n",
742 int mds_notify(struct obd_device *obd, struct obd_device *watched,
743 int active, void *data)
751 if (!strcmp(watched->obd_type->typ_name, OBD_MDC_DEVICENAME))
754 if (strcmp(watched->obd_type->typ_name, OBD_OSC_DEVICENAME)) {
755 CERROR("unexpected notification of %s %s!\n",
756 watched->obd_type->typ_name, watched->obd_name);
760 if (obd->obd_recovering) {
761 struct obd_uuid *uuid;
762 uuid = &watched->u.cli.cl_import->imp_target_uuid;
764 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
765 obd->obd_name, uuid->uuid);
767 rc = mds_dt_start_synchronize(obd, watched, data);
772 int mds_dt_set_info(struct obd_export *exp, obd_count keylen,
773 void *key, obd_count vallen, void *val)
775 struct obd_device *obd = class_exp2obd(exp);
776 struct mds_obd *mds = &obd->u.mds;
779 #define KEY_IS(str) \
780 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
782 if (KEY_IS("next_id")) {
783 obd_id *id = (obd_id *)val;
786 /* XXX - this really should be vallen != (2 * sizeof(*id)) *
787 * Just following the precedent set by lov_set_info. */
792 if ((idx != *id) || (idx >= mds->mds_dt_desc.ld_tgt_count))
795 CDEBUG(D_CONFIG, "idx: %d id: %llu\n", idx, *(id + 1));
797 mds->mds_dt_objids[idx] = *++id;
798 CDEBUG(D_CONFIG, "objid: %d: %lld\n", idx, *id);
799 /* XXX - should we be writing this out here ? */
800 RETURN(mds_dt_write_objids(obd));
806 int mds_dt_update_config(struct obd_device *obd, int clean)
808 struct mds_obd *mds = &obd->u.mds;
809 struct lvfs_run_ctxt saved;
810 struct config_llog_instance cfg;
811 struct llog_ctxt *ctxt;
812 char *profile = mds->mds_profile, *name;
813 int rc, version, namelen;
819 cfg.cfg_instance = NULL;
820 cfg.cfg_uuid = mds->mds_dt_uuid;
822 namelen = strlen(profile) + 20; /* -clean-######### */
823 OBD_ALLOC(name, namelen);
828 version = mds->mds_config_version - 1;
829 sprintf(name, "%s-clean-%d", profile, version);
831 version = mds->mds_config_version + 1;
832 sprintf(name, "%s-%d", profile, version);
835 CWARN("Applying configuration log %s\n", name);
837 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
838 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
839 rc = class_config_process_llog(ctxt, name, &cfg);
840 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
842 mds->mds_config_version = version;
843 CWARN("Finished applying configuration log %s: %d\n", name, rc);
845 OBD_FREE(name, namelen);
849 /* Convert the on-disk LOV EA structre.
850 * We always try to convert from an old LOV EA format to the common in-memory
851 * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
852 * then convert back to the new on-disk format and save it back to disk
853 * (obd_packmd() only ever saves to the new on-disk format) so we don't have
854 * to convert it each time this inode is accessed.
856 * This function is a bit interesting in the error handling. We can safely
857 * ship the old lmm to the client in case of failure, since it uses the same
858 * obd_unpackmd() code and can do the conversion if the MDS fails for some
859 * reason. We will not delete the old lmm data until we have written the
860 * new format lmm data in fsfilt_set_md(). */
861 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
862 struct lov_mds_md *lmm, int lmm_size)
864 struct lov_stripe_md *lsm = NULL;
869 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
872 CDEBUG(D_INODE, "converting LOV EA on %lu/%u from V0 to V1\n",
873 inode->i_ino, inode->i_generation);
874 rc = obd_unpackmd(obd->u.mds.mds_dt_exp, &lsm, lmm, lmm_size);
878 rc = obd_packmd(obd->u.mds.mds_dt_exp, &lmm, lsm);
883 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
884 if (IS_ERR(handle)) {
885 rc = PTR_ERR(handle);
889 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
890 err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0);
892 rc = err ? err : lmm_size;
895 obd_free_memmd(obd->u.mds.mds_dt_exp, &lsm);
900 /* Must be called with i_sem held */
901 int mds_revalidate_lov_ea(struct obd_device *obd, struct inode *inode,
902 struct lustre_msg *msg, int offset)
904 struct mds_obd *mds = &obd->u.mds;
905 struct obd_export *dt_exp = mds->mds_dt_exp;
906 struct lov_mds_md *lmm= NULL;
907 struct lov_stripe_md *lsm = NULL;
908 struct obdo *oa = NULL;
909 struct obd_trans_info oti = {0};
911 int lmm_size = 0, lsm_size = 0, err, rc;
915 LASSERT(down_trylock(&inode->i_sem) != 0);
917 /* XXX - add way to know if EA is already up to date & return
918 * without doing anything. Easy to do since we get notified of
921 lmm = lustre_msg_buf(msg, offset, 0);
923 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
927 lmm_size = msg->buflens[offset];
929 rc = obd_unpackmd(dt_exp, &lsm, lmm, lmm_size);
935 LASSERT(lsm->lsm_magic == LOV_MAGIC);
939 GOTO(out_lsm, rc = -ENOMEM);
940 oa->o_mode = S_IFREG | 0600;
941 oa->o_id = inode->i_ino;
942 oa->o_generation = inode->i_generation;
943 oa->o_uid = 0; /* must have 0 uid / gid on OST */
945 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
947 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
948 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID |
950 valid = OBD_MD_FLTYPE | OBD_MD_FLATIME | OBD_MD_FLMTIME |
952 obdo_from_inode(oa, inode, valid);
954 rc = obd_revalidate_md(dt_exp, oa, lsm, &oti);
958 CERROR("Error validating LOV EA on %lu/%u: %d\n",
959 inode->i_ino, inode->i_generation, rc);
963 rc = obd_packmd(dt_exp, &lmm, lsm);
968 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
969 if (IS_ERR(handle)) {
970 rc = PTR_ERR(handle);
974 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
975 err = fsfilt_commit(obd, inode->i_sb, inode, handle, 0);
983 obd_free_memmd(dt_exp, &lsm);