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_dt_save_objids(struct obd_device *obd, obd_id *ids)
60 struct mds_obd *mds = &obd->u.mds;
64 spin_lock(&mds->mds_dt_lock);
65 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
66 ids[i] = mds->mds_dt_objids[i];
67 spin_unlock(&mds->mds_dt_lock);
71 void mds_dt_update_objids(struct obd_device *obd, obd_id *ids)
73 struct mds_obd *mds = &obd->u.mds;
77 spin_lock(&mds->mds_dt_lock);
78 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
79 if (ids[i] > mds->mds_dt_objids[i])
80 mds->mds_dt_objids[i] = ids[i];
81 spin_unlock(&mds->mds_dt_lock);
85 static int mds_dt_read_objids(struct obd_device *obd)
87 struct mds_obd *mds = &obd->u.mds;
93 if (mds->mds_dt_objids != NULL)
96 size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
100 mds->mds_dt_objids = ids;
102 if (mds->mds_dt_objid_filp->f_dentry->d_inode->i_size == 0)
105 rc = fsfilt_read_record(obd, mds->mds_dt_objid_filp, ids, size, &off);
107 CERROR("error reading objids %d\n", rc);
109 mds->mds_dt_objids_valid = 1;
113 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++) {
114 CDEBUG(D_INFO, "read last object "LPU64
115 " for idx %d\n", mds->mds_dt_objids[i], i);
121 int mds_dt_write_objids(struct obd_device *obd)
123 struct mds_obd *mds = &obd->u.mds;
128 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
129 CDEBUG(D_INFO, "writing last object "LPU64" for idx %d\n",
130 mds->mds_dt_objids[i], i);
132 size = mds->mds_dt_desc.ld_tgt_count * sizeof(obd_id);
133 rc = fsfilt_write_record(obd, mds->mds_dt_objid_filp,
134 mds->mds_dt_objids, size, &off, 0);
138 int mds_dt_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
140 struct lov_stripe_md *empty_ea = NULL;
141 struct obd_trans_info oti = { 0 };
142 struct obdo *oa = NULL;
146 LASSERT(mds->mds_dt_objids != NULL);
149 * this create will in fact either create or destroy: If the OST is
150 * missing objects below this ID, they will be created. If it finds
151 * objects above this ID, they will be removed.
157 memset(oa, 0, sizeof(*oa));
159 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
160 oa->o_valid = OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
161 oa->o_flags = OBD_FL_DELORPHAN;
163 if (ost_uuid != NULL) {
164 memcpy(&oa->o_inline, ost_uuid,
166 oa->o_valid |= OBD_MD_FLINLINE;
170 * passing current objids for letting data layer know last objids MDS
171 * knows about and do appropriate. --umka
173 oti.oti_objid = mds->mds_dt_objids;
175 rc = obd_create(mds->mds_dt_exp, oa,
176 NULL, 0, &empty_ea, &oti);
182 /* tell the LOV-OSC by how much to pre-create */
183 int mds_dt_set_growth(struct mds_obd *mds, int count)
188 rc = obd_set_info(mds->mds_dt_exp, strlen("growth_count"),
189 "growth_count", sizeof(count), &count);
194 static int mds_dt_update_desc(struct obd_device *obd, struct obd_export *lov)
196 struct mds_obd *mds = &obd->u.mds;
197 __u32 valsize = sizeof(mds->mds_dt_desc);
198 int old_count, rc = 0, i;
201 old_count = mds->mds_dt_desc.ld_tgt_count;
203 rc = obd_get_info(lov, strlen("lovdesc") + 1, "lovdesc",
204 &valsize, &mds->mds_dt_desc);
208 /* The size of the LOV target table may have increased. */
209 if (old_count >= mds->mds_dt_desc.ld_tgt_count) {
213 size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
214 OBD_ALLOC(ids, size);
218 memset(ids, 0, size);
220 if (mds->mds_dt_objids != NULL) {
221 int oldsize = old_count * sizeof(*ids);
223 memcpy(ids, mds->mds_dt_objids, oldsize);
224 OBD_FREE(mds->mds_dt_objids, oldsize);
226 mds->mds_dt_objids = ids;
229 i = lov_mds_md_size(mds->mds_dt_desc.ld_tgt_count);
230 if (i > mds->mds_max_mdsize)
231 mds->mds_max_mdsize = i;
232 mds->mds_max_cookiesize = mds->mds_dt_desc.ld_tgt_count *
233 sizeof(struct llog_cookie);
234 mds->mds_has_dt_desc = 1;
238 int mds_dt_connect(struct obd_device *obd, char *lov_name)
240 struct mds_obd *mds = &obd->u.mds;
241 struct lustre_handle conn = { 0 };
245 if (IS_ERR(mds->mds_dt_obd))
246 RETURN(PTR_ERR(mds->mds_dt_obd));
251 spin_lock_init(&mds->mds_dt_lock);
252 mds->mds_dt_obd = class_name2obd(lov_name);
253 if (!mds->mds_dt_obd) {
254 CERROR("MDS cannot locate LOV %s\n", lov_name);
255 mds->mds_dt_obd = ERR_PTR(-ENOTCONN);
259 if (mds->mds_ost_sec) {
260 rc = obd_set_info(mds->mds_dt_obd->obd_self_export,
261 strlen("sec"), "sec",
262 strlen(mds->mds_ost_sec),
265 mds->mds_dt_obd = ERR_PTR(rc);
270 CDEBUG(D_HA, "obd: %s osc: %s lov_name: %s\n",
271 obd->obd_name, mds->mds_dt_obd->obd_name, lov_name);
273 rc = obd_connect(&conn, mds->mds_dt_obd, &obd->obd_uuid, NULL,
274 mds->mds_num + FILTER_GROUP_FIRST_MDS);
276 CERROR("MDS cannot connect to LOV %s (%d)\n", lov_name, rc);
277 mds->mds_dt_obd = ERR_PTR(rc);
280 mds->mds_dt_exp = class_conn2export(&conn);
282 rc = obd_register_observer(mds->mds_dt_obd, obd);
284 CERROR("MDS cannot register as observer of LOV %s (%d)\n",
286 GOTO(err_discon, rc);
289 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
293 rc = mds_dt_read_objids(obd);
295 CERROR("cannot read %s: rc = %d\n", "lov_objids", rc);
299 rc = obd_llog_cat_initialize(obd, &obd->obd_llogs,
300 mds->mds_dt_desc.ld_tgt_count, CATLIST);
302 CERROR("failed to initialize catalog %d\n", rc);
307 * If we're mounting this code for the first time on an existing FS, we
308 * need to populate the objids array from the real OST values.
310 if (!mds->mds_dt_objids_valid) {
311 __u32 size = sizeof(obd_id) * mds->mds_dt_desc.ld_tgt_count;
313 rc = obd_get_info(mds->mds_dt_exp, strlen("last_id"),
314 "last_id", &size, mds->mds_dt_objids);
316 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
317 CWARN("got last object "LPU64" from OST %d\n",
318 mds->mds_dt_objids[i], i);
319 mds->mds_dt_objids_valid = 1;
320 rc = mds_dt_write_objids(obd);
322 CERROR("got last objids from OSTs, but error "
323 "writing objids file: %d\n", rc);
328 * I want to see a callback happen when the OBD moves to a "For General
329 * Use" state, and that's when we'll call set_nextid(). The class driver
330 * can help us here, because it can use the obd_recovering flag to
331 * determine when the the OBD is full available.
333 if (!obd->obd_recovering) {
334 CDEBUG(D_OTHER, "call mds_postrecov_common()\n");
335 rc = mds_postrecov_common(obd);
342 obd_register_observer(mds->mds_dt_obd, NULL);
344 obd_disconnect(mds->mds_dt_exp, 0);
345 mds->mds_dt_obd = ERR_PTR(rc);
346 mds->mds_dt_exp = NULL;
350 int mds_dt_disconnect(struct obd_device *obd, int flags)
352 struct mds_obd *mds = &obd->u.mds;
356 if (!IS_ERR(mds->mds_dt_obd) && mds->mds_dt_exp != NULL) {
357 /* cleanup all llogging subsystems */
358 rc = obd_llog_finish(obd, &obd->obd_llogs,
359 mds->mds_dt_desc.ld_tgt_count);
361 CERROR("failed to cleanup llogging subsystems\n");
363 obd_register_observer(mds->mds_dt_obd, NULL);
365 rc = obd_disconnect(mds->mds_dt_exp, flags);
366 /* if obd_disconnect fails (probably because the
367 * export was disconnected by class_disconnect_exports)
368 * then we just need to drop our ref. */
370 class_export_put(mds->mds_dt_exp);
371 mds->mds_dt_exp = NULL;
372 mds->mds_dt_obd = NULL;
378 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
379 void *karg, void *uarg)
381 static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
382 struct obd_device *obd = exp->exp_obd;
383 struct mds_obd *mds = &obd->u.mds;
384 struct obd_ioctl_data *data = karg;
385 struct lvfs_run_ctxt saved;
389 CDEBUG(D_INFO, "ioctl cmd %x\n", cmd);
391 case OBD_IOC_RECORD: {
392 char *name = data->ioc_inlbuf1;
393 if (mds->mds_cfg_llh)
396 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
397 rc = llog_open(llog_get_context(&obd->obd_llogs,
398 LLOG_CONFIG_ORIG_CTXT),
399 &mds->mds_cfg_llh, NULL, name,
402 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
405 mds->mds_cfg_llh = NULL;
406 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
411 case OBD_IOC_ENDRECORD: {
412 if (!mds->mds_cfg_llh)
415 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
416 rc = llog_close(mds->mds_cfg_llh);
417 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
419 mds->mds_cfg_llh = NULL;
423 case OBD_IOC_CLEAR_LOG: {
424 char *name = data->ioc_inlbuf1;
425 if (mds->mds_cfg_llh)
428 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
429 rc = llog_open(llog_get_context(&obd->obd_llogs,
430 LLOG_CONFIG_ORIG_CTXT),
431 &mds->mds_cfg_llh, NULL, name,
434 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
437 rc = llog_destroy(mds->mds_cfg_llh);
438 llog_free_handle(mds->mds_cfg_llh);
440 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
442 mds->mds_cfg_llh = NULL;
446 case OBD_IOC_DORECORD: {
448 struct llog_rec_hdr rec;
449 if (!mds->mds_cfg_llh)
452 /* XXX - this probably should be a parameter to this ioctl.
453 * For now, just use llh_max_transno for expediency. */
454 rec.lrh_len = llog_data_len(data->ioc_plen1);
456 if (data->ioc_type == LUSTRE_CFG_TYPE) {
457 rec.lrh_type = OBD_CFG_REC;
458 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
459 rec.lrh_type = PTL_CFG_REC;
461 CERROR("unknown cfg record type:%d \n", data->ioc_type);
465 OBD_ALLOC(cfg_buf, data->ioc_plen1);
468 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
470 OBD_FREE(cfg_buf, data->ioc_plen1);
474 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
475 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
477 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
479 OBD_FREE(cfg_buf, data->ioc_plen1);
482 case OBD_IOC_PARSE: {
483 struct llog_ctxt *ctxt =
484 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
485 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
486 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
487 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
493 case OBD_IOC_DUMP_LOG: {
494 struct llog_ctxt *ctxt =
495 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
496 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
497 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
498 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
502 case OBD_IOC_SET_READONLY: {
504 struct inode *inode = obd->u.mds.mds_sb->s_root->d_inode;
505 BDEVNAME_DECLARE_STORAGE(tmp);
506 CERROR("setting device %s read-only\n",
507 ll_bdevname(obd->u.mds.mds_sb, tmp));
509 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
511 rc = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 1);
513 ll_set_rdonly(ll_sbdev(obd->u.mds.mds_sb));
517 case OBD_IOC_CATLOGLIST: {
518 int count = mds->mds_dt_desc.ld_tgt_count;
519 rc = llog_catalog_list(obd, count, data);
523 case OBD_IOC_LLOG_CHECK:
524 case OBD_IOC_LLOG_CANCEL:
525 case OBD_IOC_LLOG_REMOVE: {
526 struct llog_ctxt *ctxt =
527 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
531 obd_llog_finish(obd, &obd->obd_llogs,
532 mds->mds_dt_desc.ld_tgt_count);
533 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
534 rc = llog_ioctl(ctxt, cmd, data);
535 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
536 obd_llog_cat_initialize(obd, &obd->obd_llogs,
537 mds->mds_dt_desc.ld_tgt_count,
539 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
540 valsize = sizeof(group);
541 rc2 = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
542 "mds_conn", valsize, &group);
547 case OBD_IOC_LLOG_INFO:
548 case OBD_IOC_LLOG_PRINT: {
549 struct llog_ctxt *ctxt =
550 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
552 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
553 rc = llog_ioctl(ctxt, cmd, data);
554 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
559 case OBD_IOC_ABORT_RECOVERY:
560 target_stop_recovery_thread(obd);
562 case OBD_IOC_ROOT_SQUASH: {
563 __u32 *p = (__u32 *) data->ioc_inlbuf1;
565 if (data->ioc_inllen1 !=
566 (sizeof(__u32) * 4 + sizeof(ptl_nid_t)))
569 if (*p == 0) { /* get */
571 *p++ = mds->mds_squash_uid;
572 *p++ = mds->mds_squash_gid;
573 *((ptl_nid_t*) p) = mds->mds_nosquash_nid;
576 mds->mds_squash_uid = *p++;
577 mds->mds_squash_gid = *p++;
578 mds->mds_nosquash_nid = *((ptl_nid_t*) p);
579 CWARN("MDS: squash root to %d:%d, except nid 0x%llx\n",
580 mds->mds_squash_uid, mds->mds_squash_gid,
581 mds->mds_nosquash_nid);
586 CDEBUG(D_INFO, "unknown command %x\n", cmd);
593 struct mds_dt_sync_info {
594 struct obd_device *mlsi_obd; /* the mds to sync */
595 struct obd_device *mlsi_watched; /* new lov target */
596 int mlsi_index; /* index into mds_dt_objids */
599 int mds_dt_synchronize(void *data)
601 struct mds_dt_sync_info *mlsi = data;
602 struct llog_ctxt *ctxt;
603 struct obd_device *obd;
604 struct obd_device *watched;
606 struct obd_uuid *uuid;
615 char name[32] = "CATLIST";
621 SIGNAL_MASK_LOCK(current, flags);
622 sigfillset(¤t->blocked);
624 SIGNAL_MASK_UNLOCK(current, flags);
628 obd = mlsi->mlsi_obd;
629 watched = mlsi->mlsi_watched;
630 index = mlsi->mlsi_index;
632 LASSERT(obd != NULL);
633 LASSERT(watched != NULL);
635 OBD_FREE(mlsi, sizeof(*mlsi));
638 down(&mds->mds_orphan_recovery_sem);
640 uuid = &watched->u.cli.cl_import->imp_target_uuid;
642 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
643 rc = obd_set_info(watched->obd_self_export, strlen("mds_conn"),
644 "mds_conn", sizeof(group), &group);
648 old_count = mds->mds_dt_desc.ld_tgt_count;
650 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
654 count = mds->mds_dt_desc.ld_tgt_count;
655 LASSERT(count >= old_count);
657 vallen = sizeof(vals[1]);
658 rc = obd_get_info(watched->obd_self_export, strlen("last_id"),
659 "last_id", &vallen, &vals[1]);
663 /* we don't set next id manually, instead OSCs will set them
664 * during own recovery from DELORPHAN reply -bzzz */
667 rc = mds_dt_set_info(obd->obd_self_export, strlen("next_id"),
673 obd_llog_finish(obd, &obd->obd_llogs, old_count);
674 obd_llog_cat_initialize(obd, &obd->obd_llogs, count, name);
676 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
677 LASSERT(ctxt != NULL);
679 rc = llog_connect(ctxt, count, NULL, NULL, uuid);
681 CERROR("%s: failed at llog_origin_connect: %d\n",
686 CWARN("MDS %s: %s now active, resetting orphans\n",
687 obd->obd_name, uuid->uuid);
689 rc = mds_dt_clear_orphans(&obd->u.mds, uuid);
691 CERROR("%s: failed at mds_dt_clear_orphans(): %d\n",
699 up(&mds->mds_orphan_recovery_sem);
703 int mds_dt_start_synchronize(struct obd_device *obd,
704 struct obd_device *watched,
707 struct mds_dt_sync_info *mlsi;
712 OBD_ALLOC(mlsi, sizeof(*mlsi));
716 mlsi->mlsi_obd = obd;
717 mlsi->mlsi_watched = watched;
718 mlsi->mlsi_index = (int)data;
720 rc = kernel_thread(mds_dt_synchronize, mlsi, CLONE_VM | CLONE_FILES);
722 CERROR("%s: error starting mds_dt_synchronize(): %d\n",
725 CDEBUG(D_HA, "%s: mds_dt_synchronize() thread: %d\n",
733 int mds_notify(struct obd_device *obd, struct obd_device *watched,
734 int active, void *data)
742 if (!strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME))
745 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
746 CERROR("unexpected notification of %s %s!\n",
747 watched->obd_type->typ_name, watched->obd_name);
751 if (obd->obd_recovering) {
752 struct obd_uuid *uuid;
753 uuid = &watched->u.cli.cl_import->imp_target_uuid;
755 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
756 obd->obd_name, uuid->uuid);
758 rc = mds_dt_start_synchronize(obd, watched, data);
763 int mds_dt_set_info(struct obd_export *exp, obd_count keylen,
764 void *key, obd_count vallen, void *val)
766 struct obd_device *obd = class_exp2obd(exp);
767 struct mds_obd *mds = &obd->u.mds;
770 #define KEY_IS(str) \
771 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
773 if (KEY_IS("next_id")) {
774 obd_id *id = (obd_id *)val;
777 /* XXX - this really should be vallen != (2 * sizeof(*id)) *
778 * Just following the precedent set by lov_set_info. */
783 if ((idx != *id) || (idx >= mds->mds_dt_desc.ld_tgt_count))
786 CDEBUG(D_CONFIG, "idx: %d id: %llu\n", idx, *(id + 1));
788 mds->mds_dt_objids[idx] = *++id;
789 CDEBUG(D_CONFIG, "objid: %d: %lld\n", idx, *id);
790 /* XXX - should we be writing this out here ? */
791 RETURN(mds_dt_write_objids(obd));
797 int mds_dt_update_config(struct obd_device *obd, int clean)
799 struct mds_obd *mds = &obd->u.mds;
800 struct lvfs_run_ctxt saved;
801 struct config_llog_instance cfg;
802 struct llog_ctxt *ctxt;
803 char *profile = mds->mds_profile, *name;
804 int rc, version, namelen;
810 cfg.cfg_instance = NULL;
811 cfg.cfg_uuid = mds->mds_dt_uuid;
813 namelen = strlen(profile) + 20; /* -clean-######### */
814 OBD_ALLOC(name, namelen);
819 version = mds->mds_config_version - 1;
820 sprintf(name, "%s-clean-%d", profile, version);
822 version = mds->mds_config_version + 1;
823 sprintf(name, "%s-%d", profile, version);
826 CWARN("Applying configuration log %s\n", name);
828 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
829 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
830 rc = class_config_process_llog(ctxt, name, &cfg);
831 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
833 mds->mds_config_version = version;
834 CWARN("Finished applying configuration log %s: %d\n", name, rc);
836 OBD_FREE(name, namelen);
840 /* Convert the on-disk LOV EA structre.
841 * We always try to convert from an old LOV EA format to the common in-memory
842 * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
843 * then convert back to the new on-disk format and save it back to disk
844 * (obd_packmd() only ever saves to the new on-disk format) so we don't have
845 * to convert it each time this inode is accessed.
847 * This function is a bit interesting in the error handling. We can safely
848 * ship the old lmm to the client in case of failure, since it uses the same
849 * obd_unpackmd() code and can do the conversion if the MDS fails for some
850 * reason. We will not delete the old lmm data until we have written the
851 * new format lmm data in fsfilt_set_md(). */
852 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
853 struct lov_mds_md *lmm, int lmm_size)
855 struct lov_stripe_md *lsm = NULL;
860 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
863 CDEBUG(D_INODE, "converting LOV EA on %lu/%u from V0 to V1\n",
864 inode->i_ino, inode->i_generation);
865 rc = obd_unpackmd(obd->u.mds.mds_dt_exp, &lsm, lmm, lmm_size);
869 rc = obd_packmd(obd->u.mds.mds_dt_exp, &lmm, lsm);
874 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
875 if (IS_ERR(handle)) {
876 rc = PTR_ERR(handle);
880 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
881 err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0);
883 rc = err ? err : lmm_size;
886 obd_free_memmd(obd->u.mds.mds_dt_exp, &lsm);
891 /* Must be called with i_sem held */
892 int mds_revalidate_lov_ea(struct obd_device *obd, struct inode *inode,
893 struct lustre_msg *msg, int offset)
895 struct mds_obd *mds = &obd->u.mds;
896 struct obd_export *dt_exp = mds->mds_dt_exp;
897 struct lov_mds_md *lmm= NULL;
898 struct lov_stripe_md *lsm = NULL;
899 struct obdo *oa = NULL;
900 struct obd_trans_info oti = {0};
902 int lmm_size = 0, lsm_size = 0, err, rc;
906 LASSERT(down_trylock(&inode->i_sem) != 0);
908 /* XXX - add way to know if EA is already up to date & return
909 * without doing anything. Easy to do since we get notified of
912 lmm = lustre_msg_buf(msg, offset, 0);
914 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
918 lmm_size = msg->buflens[offset];
920 rc = obd_unpackmd(dt_exp, &lsm, lmm, lmm_size);
926 LASSERT(lsm->lsm_magic == LOV_MAGIC);
930 GOTO(out_lsm, rc = -ENOMEM);
931 oa->o_mode = S_IFREG | 0600;
932 oa->o_id = inode->i_ino;
933 oa->o_generation = inode->i_generation;
934 oa->o_uid = 0; /* must have 0 uid / gid on OST */
936 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
938 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
939 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID |
941 valid = OBD_MD_FLTYPE | OBD_MD_FLATIME | OBD_MD_FLMTIME |
943 obdo_from_inode(oa, inode, valid);
945 rc = obd_revalidate_md(dt_exp, oa, lsm, &oti);
949 CERROR("Error validating LOV EA on %lu/%u: %d\n",
950 inode->i_ino, inode->i_generation, rc);
954 rc = obd_packmd(dt_exp, &lmm, lsm);
959 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
960 if (IS_ERR(handle)) {
961 rc = PTR_ERR(handle);
965 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
966 err = fsfilt_commit(obd, inode->i_sb, inode, handle, 0);
974 obd_free_memmd(dt_exp, &lsm);