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);
350 for (i = 0; i < 2; i++) {
351 if (!mds->mds_capa_keys[i].k_key)
353 rc = obd_set_info(mds->mds_dt_exp, strlen("capa_key"),
354 "capa_key", sizeof(struct lustre_capa_key),
355 mds->mds_capa_keys[i].k_key);
362 obd_register_observer(mds->mds_dt_obd, NULL);
364 obd_disconnect(mds->mds_dt_exp, 0);
365 mds->mds_dt_obd = ERR_PTR(rc);
366 mds->mds_dt_exp = NULL;
370 int mds_dt_disconnect(struct obd_device *obd, int flags)
372 struct mds_obd *mds = &obd->u.mds;
376 if (!IS_ERR(mds->mds_dt_obd) && mds->mds_dt_exp != NULL) {
377 /* cleanup all llogging subsystems */
378 rc = obd_llog_finish(obd, &obd->obd_llogs,
379 mds->mds_dt_desc.ld_tgt_count);
381 CERROR("failed to cleanup llogging subsystems\n");
383 obd_register_observer(mds->mds_dt_obd, NULL);
385 rc = obd_disconnect(mds->mds_dt_exp, flags);
386 /* if obd_disconnect fails (probably because the
387 * export was disconnected by class_disconnect_exports)
388 * then we just need to drop our ref. */
390 class_export_put(mds->mds_dt_exp);
391 mds->mds_dt_exp = NULL;
392 mds->mds_dt_obd = NULL;
398 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
399 void *karg, void *uarg)
401 static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
402 struct obd_device *obd = exp->exp_obd;
403 struct mds_obd *mds = &obd->u.mds;
404 struct obd_ioctl_data *data = karg;
405 struct lvfs_run_ctxt saved;
409 CDEBUG(D_INFO, "ioctl cmd %x\n", cmd);
411 case OBD_IOC_RECORD: {
412 char *name = data->ioc_inlbuf1;
413 if (mds->mds_cfg_llh)
416 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
417 rc = llog_open(llog_get_context(&obd->obd_llogs,
418 LLOG_CONFIG_ORIG_CTXT),
419 &mds->mds_cfg_llh, NULL, name,
422 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
425 mds->mds_cfg_llh = NULL;
426 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
431 case OBD_IOC_ENDRECORD: {
432 if (!mds->mds_cfg_llh)
435 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
436 rc = llog_close(mds->mds_cfg_llh);
437 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
439 mds->mds_cfg_llh = NULL;
443 case OBD_IOC_CLEAR_LOG: {
444 char *name = data->ioc_inlbuf1;
445 if (mds->mds_cfg_llh)
448 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
449 rc = llog_open(llog_get_context(&obd->obd_llogs,
450 LLOG_CONFIG_ORIG_CTXT),
451 &mds->mds_cfg_llh, NULL, name,
454 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
457 rc = llog_destroy(mds->mds_cfg_llh);
458 llog_free_handle(mds->mds_cfg_llh);
460 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
462 mds->mds_cfg_llh = NULL;
466 case OBD_IOC_DORECORD: {
468 struct llog_rec_hdr rec;
469 if (!mds->mds_cfg_llh)
472 /* XXX - this probably should be a parameter to this ioctl.
473 * For now, just use llh_max_transno for expediency. */
474 rec.lrh_len = llog_data_len(data->ioc_plen1);
476 if (data->ioc_type == LUSTRE_CFG_TYPE) {
477 rec.lrh_type = OBD_CFG_REC;
478 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
479 rec.lrh_type = PTL_CFG_REC;
481 CERROR("unknown cfg record type:%d \n", data->ioc_type);
485 OBD_ALLOC(cfg_buf, data->ioc_plen1);
488 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
490 OBD_FREE(cfg_buf, data->ioc_plen1);
494 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
495 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
497 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
499 OBD_FREE(cfg_buf, data->ioc_plen1);
502 case OBD_IOC_PARSE: {
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_process_llog(ctxt, data->ioc_inlbuf1, NULL);
507 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
513 case OBD_IOC_DUMP_LOG: {
514 struct llog_ctxt *ctxt =
515 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
516 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
517 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
518 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
522 case OBD_IOC_SET_READONLY: {
524 struct inode *inode = obd->u.mds.mds_sb->s_root->d_inode;
525 BDEVNAME_DECLARE_STORAGE(tmp);
526 CERROR("setting device %s read-only\n",
527 ll_bdevname(obd->u.mds.mds_sb, tmp));
529 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
531 rc = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 1);
533 ll_set_rdonly(ll_sbdev(obd->u.mds.mds_sb));
537 case OBD_IOC_CATLOGLIST: {
538 int count = mds->mds_dt_desc.ld_tgt_count;
539 rc = llog_catalog_list(obd, count, data);
543 case OBD_IOC_LLOG_CHECK:
544 case OBD_IOC_LLOG_CANCEL:
545 case OBD_IOC_LLOG_REMOVE: {
546 struct llog_ctxt *ctxt =
547 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
551 obd_llog_finish(obd, &obd->obd_llogs,
552 mds->mds_dt_desc.ld_tgt_count);
553 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
554 rc = llog_ioctl(ctxt, cmd, data);
555 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
556 obd_llog_cat_initialize(obd, &obd->obd_llogs,
557 mds->mds_dt_desc.ld_tgt_count,
559 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
560 valsize = sizeof(group);
561 rc2 = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
562 "mds_conn", valsize, &group);
567 case OBD_IOC_LLOG_INFO:
568 case OBD_IOC_LLOG_PRINT: {
569 struct llog_ctxt *ctxt =
570 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
572 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
573 rc = llog_ioctl(ctxt, cmd, data);
574 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
579 case OBD_IOC_ABORT_RECOVERY:
580 target_stop_recovery_thread(obd);
582 case OBD_IOC_ROOT_SQUASH: {
583 __u32 *p = (__u32 *) data->ioc_inlbuf1;
585 if (data->ioc_inllen1 !=
586 (sizeof(__u32) * 4 + sizeof(ptl_nid_t)))
589 if (*p == 0) { /* get */
591 *p++ = mds->mds_squash_uid;
592 *p++ = mds->mds_squash_gid;
593 *((ptl_nid_t*) p) = mds->mds_nosquash_nid;
596 mds->mds_squash_uid = *p++;
597 mds->mds_squash_gid = *p++;
598 mds->mds_nosquash_nid = *((ptl_nid_t*) p);
599 CWARN("MDS: squash root to %d:%d, except nid 0x%llx\n",
600 mds->mds_squash_uid, mds->mds_squash_gid,
601 mds->mds_nosquash_nid);
606 CDEBUG(D_INFO, "unknown command %x\n", cmd);
613 struct mds_dt_sync_info {
614 struct obd_device *mlsi_obd; /* the mds to sync */
615 struct obd_device *mlsi_watched; /* new lov target */
616 int mlsi_index; /* index into mds_dt_objids */
619 int mds_dt_synchronize(void *data)
621 struct mds_dt_sync_info *mlsi = data;
622 struct llog_ctxt *ctxt;
623 struct obd_device *obd;
624 struct obd_device *watched;
626 struct obd_uuid *uuid;
630 int old_count, count, index, i;
632 char name[32] = "CATLIST";
638 SIGNAL_MASK_LOCK(current, flags);
639 sigfillset(¤t->blocked);
641 SIGNAL_MASK_UNLOCK(current, flags);
645 obd = mlsi->mlsi_obd;
646 watched = mlsi->mlsi_watched;
647 index = mlsi->mlsi_index;
649 LASSERT(obd != NULL);
650 LASSERT(watched != NULL);
652 OBD_FREE(mlsi, sizeof(*mlsi));
655 down(&mds->mds_orphan_recovery_sem);
657 uuid = &watched->u.cli.cl_import->imp_target_uuid;
658 CWARN("MDS %s: %s now active, repairing the connection\n",
659 obd->obd_name, uuid->uuid);
661 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
662 rc = obd_set_info(watched->obd_self_export, strlen("mds_conn"),
663 "mds_conn", sizeof(group), &group);
667 old_count = mds->mds_dt_desc.ld_tgt_count;
669 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
673 count = mds->mds_dt_desc.ld_tgt_count;
674 LASSERT(count >= old_count);
676 vallen = sizeof(vals[1]);
677 rc = obd_get_info(watched->obd_self_export, strlen("last_id"),
678 "last_id", &vallen, &vals[1]);
682 for (i = 0; i < 2; i++) {
683 if (!mds->mds_capa_keys[i].k_key)
685 rc = obd_set_info(mds->mds_dt_exp, strlen("capa_key"),
686 "capa_key", sizeof(struct lustre_capa_key),
687 mds->mds_capa_keys[i].k_key);
692 /* we don't set next id manually, instead OSCs will set them
693 * during own recovery from DELORPHAN reply -bzzz */
696 rc = mds_dt_set_info(obd->obd_self_export, strlen("next_id"),
702 obd_llog_finish(obd, &obd->obd_llogs, old_count);
703 obd_llog_cat_initialize(obd, &obd->obd_llogs, count, name);
705 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
706 LASSERT(ctxt != NULL);
708 rc = llog_connect(ctxt, count, NULL, NULL, uuid);
710 CERROR("%s: failed at llog_origin_connect: %d\n",
715 CWARN("MDS %s: %s now active, resetting orphans\n",
716 obd->obd_name, uuid->uuid);
718 rc = mds_dt_clear_orphans(&obd->u.mds, uuid);
720 CERROR("%s: failed at mds_dt_clear_orphans(): %d\n",
728 up(&mds->mds_orphan_recovery_sem);
732 int mds_dt_start_synchronize(struct obd_device *obd,
733 struct obd_device *watched,
736 struct mds_dt_sync_info *mlsi;
741 OBD_ALLOC(mlsi, sizeof(*mlsi));
745 mlsi->mlsi_obd = obd;
746 mlsi->mlsi_watched = watched;
747 mlsi->mlsi_index = (int)data;
749 rc = kernel_thread(mds_dt_synchronize, mlsi, CLONE_VM | CLONE_FILES);
751 CERROR("%s: error starting mds_dt_synchronize(): %d\n",
754 CDEBUG(D_HA, "%s: mds_dt_synchronize() thread: %d\n",
762 int mds_notify(struct obd_device *obd, struct obd_device *watched,
763 int active, void *data)
771 if (!strcmp(watched->obd_type->typ_name, OBD_MDC_DEVICENAME))
774 if (strcmp(watched->obd_type->typ_name, OBD_OSC_DEVICENAME)) {
775 CERROR("unexpected notification of %s %s!\n",
776 watched->obd_type->typ_name, watched->obd_name);
780 if (obd->obd_recovering) {
781 struct obd_uuid *uuid;
782 uuid = &watched->u.cli.cl_import->imp_target_uuid;
784 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
785 obd->obd_name, uuid->uuid);
787 rc = mds_dt_start_synchronize(obd, watched, data);
792 int mds_dt_set_info(struct obd_export *exp, obd_count keylen,
793 void *key, obd_count vallen, void *val)
795 struct obd_device *obd = class_exp2obd(exp);
796 struct mds_obd *mds = &obd->u.mds;
799 #define KEY_IS(str) \
800 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
802 if (KEY_IS("next_id")) {
803 obd_id *id = (obd_id *)val;
806 /* XXX - this really should be vallen != (2 * sizeof(*id)) *
807 * Just following the precedent set by lov_set_info. */
812 if ((idx != *id) || (idx >= mds->mds_dt_desc.ld_tgt_count))
815 CDEBUG(D_CONFIG, "idx: %d id: %llu\n", idx, *(id + 1));
817 mds->mds_dt_objids[idx] = *++id;
818 CDEBUG(D_CONFIG, "objid: %d: %lld\n", idx, *id);
819 /* XXX - should we be writing this out here ? */
820 RETURN(mds_dt_write_objids(obd));
826 int mds_dt_update_config(struct obd_device *obd, int clean)
828 struct mds_obd *mds = &obd->u.mds;
829 struct lvfs_run_ctxt saved;
830 struct llog_ctxt *ctxt;
831 struct config_llog_instance cfg;
832 char *profile = mds->mds_profile, *name;
833 int rc, version, namelen, value;
839 cfg.cfg_instance = NULL;
840 cfg.cfg_uuid = mds->mds_dt_uuid;
842 namelen = strlen(profile) + 20; /* -clean-######### */
843 OBD_ALLOC(name, namelen);
847 version = mds->mds_config_version - 1;
848 sprintf(name, "%s-clean-%d", profile, version);
850 version = mds->mds_config_version + 1;
851 sprintf(name, "%s-%d", profile, version);
853 CWARN("Applying configuration log %s\n", name);
855 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
856 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
857 rc = class_config_process_llog(ctxt, name, &cfg);
858 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
859 CWARN("Finished applying configuration log %s: %d\n", name, rc);
863 /* retrieve size of EA */
864 rc = obd_get_info(mds->mds_md_exp, strlen("mdsize"),
865 "mdsize", &valsize, &value);
867 if (value > mds->mds_max_mdsize)
868 mds->mds_max_mdsize = value;
870 CDEBUG(D_INFO, "mds max md size %d \n", mds->mds_max_mdsize);
873 mds->mds_config_version = version;
875 OBD_FREE(name, namelen);
879 /* Convert the on-disk LOV EA structre.
880 * We always try to convert from an old LOV EA format to the common in-memory
881 * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
882 * then convert back to the new on-disk format and save it back to disk
883 * (obd_packmd() only ever saves to the new on-disk format) so we don't have
884 * to convert it each time this inode is accessed.
886 * This function is a bit interesting in the error handling. We can safely
887 * ship the old lmm to the client in case of failure, since it uses the same
888 * obd_unpackmd() code and can do the conversion if the MDS fails for some
889 * reason. We will not delete the old lmm data until we have written the
890 * new format lmm data in fsfilt_set_md(). */
891 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
892 struct lov_mds_md *lmm, int lmm_size)
894 struct lov_stripe_md *lsm = NULL;
899 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
902 CDEBUG(D_INODE, "converting LOV EA on %lu/%u from V0 to V1\n",
903 inode->i_ino, inode->i_generation);
904 rc = obd_unpackmd(obd->u.mds.mds_dt_exp, &lsm, lmm, lmm_size);
908 rc = obd_packmd(obd->u.mds.mds_dt_exp, &lmm, lsm);
913 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
914 if (IS_ERR(handle)) {
915 rc = PTR_ERR(handle);
919 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
920 err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0);
922 rc = err ? err : lmm_size;
925 obd_free_memmd(obd->u.mds.mds_dt_exp, &lsm);
930 /* Must be called with i_sem held */
931 int mds_revalidate_lov_ea(struct obd_device *obd, struct dentry *dentry,
932 struct lustre_msg *msg, int offset)
934 struct mds_obd *mds = &obd->u.mds;
935 struct obd_export *dt_exp = mds->mds_dt_exp;
936 struct inode *inode = dentry->d_inode;
937 struct lov_mds_md *lmm= NULL;
938 struct lov_stripe_md *lsm = NULL;
939 struct obdo *oa = NULL;
940 struct obd_trans_info oti = {0};
941 struct iattr iattr = { 0 };
943 char idname[LL_ID_NAMELEN];
944 int lmm_size = 0, lsm_size = 0, err, rc;
948 LASSERT(down_trylock(&inode->i_sem) != 0);
950 ll_id2str(idname, inode->i_ino, inode->i_generation);
952 /* XXX - add way to know if EA is already up to date & return
953 * without doing anything. Easy to do since we get notified of
956 lmm = lustre_msg_buf(msg, offset, 0);
958 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
962 lmm_size = msg->buflens[offset];
964 rc = obd_unpackmd(dt_exp, &lsm, lmm, lmm_size);
970 LASSERT(lsm->lsm_magic == LOV_MAGIC);
974 GOTO(out_lsm, rc = -ENOMEM);
975 oa->o_mode = S_IFREG | 0600;
976 oa->o_id = inode->i_ino;
977 oa->o_generation = inode->i_generation;
978 oa->o_uid = 0; /* must have 0 uid / gid on OST */
980 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
982 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
983 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID |
985 valid = OBD_MD_FLTYPE | OBD_MD_FLATIME | OBD_MD_FLMTIME |
987 obdo_from_inode(oa, inode, valid);
989 rc = obd_revalidate_md(dt_exp, oa, lsm, &oti);
993 CERROR("Error validating LOV EA on %lu/%u: %d\n",
994 inode->i_ino, inode->i_generation, rc);
998 rc = obd_packmd(dt_exp, &lmm, lsm);
1003 DOWN_WRITE_I_ALLOC_SEM(inode);
1004 mds_inode_set_attrs_old(inode);
1005 UP_WRITE_I_ALLOC_SEM(inode);
1007 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
1008 if (IS_ERR(handle)) {
1009 rc = PTR_ERR(handle);
1013 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
1015 CERROR("error in fsfilt_set_md(%s): rc %d\n", idname, rc);
1019 /* the EA has changed - let's update i_size/i_blocks */
1020 /* NOTE: that we're calling mds_validate_size() with the i_sem held. */
1021 mds_validate_size(obd, inode, NULL, lsm, &iattr);
1022 if (iattr.ia_valid != 0) {
1023 rc = fsfilt_setattr(obd, dentry, handle, &iattr, 0);
1025 CERROR("error in setattr(%s): rc %d\n", idname, rc);
1028 err = fsfilt_commit(obd, inode->i_sb, inode, handle, 0);
1035 obd_free_memmd(dt_exp, &lsm);