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_update_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 if (ids[i] > (mds->mds_dt_objids)[i])
67 (mds->mds_dt_objids)[i] = ids[i];
68 spin_unlock(&mds->mds_dt_lock);
72 static int mds_dt_read_objids(struct obd_device *obd)
74 struct mds_obd *mds = &obd->u.mds;
77 int i, rc, size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
80 if (mds->mds_dt_objids != NULL)
86 mds->mds_dt_objids = ids;
88 if (mds->mds_dt_objid_filp->f_dentry->d_inode->i_size == 0)
90 rc = fsfilt_read_record(obd, mds->mds_dt_objid_filp, ids, size, &off);
92 CERROR("Error reading objids %d\n", rc);
94 mds->mds_dt_objids_valid = 1;
98 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
99 CDEBUG(D_INFO, "read last object "LPU64" for idx %d\n",
100 mds->mds_dt_objids[i], i);
105 int mds_dt_write_objids(struct obd_device *obd)
107 struct mds_obd *mds = &obd->u.mds;
109 int i, rc, size = mds->mds_dt_desc.ld_tgt_count * sizeof(obd_id);
112 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
113 CDEBUG(D_INFO, "writing last object "LPU64" for idx %d\n",
114 mds->mds_dt_objids[i], i);
116 rc = fsfilt_write_record(obd, mds->mds_dt_objid_filp,
117 mds->mds_dt_objids, size, &off, 0);
121 int mds_dt_clearorphans(struct mds_obd *mds, struct obd_uuid *ost_uuid)
124 struct obdo *oa = NULL;
125 struct obd_trans_info oti = {0};
126 struct lov_stripe_md *empty_ea = NULL;
129 LASSERT(mds->mds_dt_objids != NULL);
132 * this create will in fact either create or destroy: If the OST is
133 * missing objects below this ID, they will be created. If it finds
134 * objects above this ID, they will be removed.
140 memset(oa, 0, sizeof(*oa));
141 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
142 oa->o_valid = OBD_MD_FLFLAGS | OBD_MD_FLGROUP;
143 oa->o_flags = OBD_FL_DELORPHAN;
145 if (ost_uuid != NULL) {
146 memcpy(&oa->o_inline, ost_uuid, sizeof(*ost_uuid));
147 oa->o_valid |= OBD_MD_FLINLINE;
149 rc = obd_create(mds->mds_dt_exp, oa, &empty_ea, &oti);
154 /* update the LOV-OSC knowledge of the last used object id's */
155 int mds_dt_set_nextid(struct obd_device *obd)
157 struct mds_obd *mds = &obd->u.mds;
161 LASSERT(!obd->obd_recovering);
163 LASSERT(mds->mds_dt_objids != NULL);
165 rc = obd_set_info(mds->mds_dt_exp, strlen("next_id"), "next_id",
166 mds->mds_dt_desc.ld_tgt_count, mds->mds_dt_objids);
170 /* tell the LOV-OSC by how much to pre-create */
171 int mds_dt_set_growth(struct mds_obd *mds, int count)
176 rc = obd_set_info(mds->mds_dt_exp, strlen("growth_count"),
177 "growth_count", sizeof(count), &count);
182 static int mds_dt_update_desc(struct obd_device *obd, struct obd_export *lov)
184 struct mds_obd *mds = &obd->u.mds;
185 int valsize = sizeof(mds->mds_dt_desc), rc, i;
186 int old_count = mds->mds_dt_desc.ld_tgt_count;
189 rc = obd_get_info(lov, strlen("lovdesc") + 1, "lovdesc", &valsize,
194 /* The size of the LOV target table may have increased. */
195 if (old_count >= mds->mds_dt_desc.ld_tgt_count) {
199 size = mds->mds_dt_desc.ld_tgt_count * sizeof(*ids);
200 OBD_ALLOC(ids, size);
204 memset(ids, 0, size);
206 if (mds->mds_dt_objids != NULL) {
207 int oldsize = old_count * sizeof(*ids);
209 memcpy(ids, mds->mds_dt_objids, oldsize);
210 OBD_FREE(mds->mds_dt_objids, oldsize);
212 mds->mds_dt_objids = ids;
215 i = lov_mds_md_size(mds->mds_dt_desc.ld_tgt_count);
216 if (i > mds->mds_max_mdsize)
217 mds->mds_max_mdsize = i;
218 mds->mds_max_cookiesize = mds->mds_dt_desc.ld_tgt_count *
219 sizeof(struct llog_cookie);
220 mds->mds_has_dt_desc = 1;
224 int mds_dt_connect(struct obd_device *obd, char * lov_name)
226 struct mds_obd *mds = &obd->u.mds;
227 struct lustre_handle conn = {0,};
231 if (IS_ERR(mds->mds_dt_obd))
232 RETURN(PTR_ERR(mds->mds_dt_obd));
237 spin_lock_init(&mds->mds_dt_lock);
238 mds->mds_dt_obd = class_name2obd(lov_name);
239 if (!mds->mds_dt_obd) {
240 CERROR("MDS cannot locate LOV %s\n", lov_name);
241 mds->mds_dt_obd = ERR_PTR(-ENOTCONN);
245 if (mds->mds_ost_sec) {
246 rc = obd_set_info(mds->mds_dt_obd->obd_self_export,
247 strlen("sec"), "sec",
248 strlen(mds->mds_ost_sec), mds->mds_ost_sec);
250 mds->mds_dt_obd = ERR_PTR(rc);
255 CDEBUG(D_HA, "obd: %s osc: %s lov_name: %s\n",
256 obd->obd_name, mds->mds_dt_obd->obd_name, lov_name);
258 rc = obd_connect(&conn, mds->mds_dt_obd, &obd->obd_uuid, NULL,
259 mds->mds_num + FILTER_GROUP_FIRST_MDS);
261 CERROR("MDS cannot connect to LOV %s (%d)\n", lov_name, rc);
262 mds->mds_dt_obd = ERR_PTR(rc);
265 mds->mds_dt_exp = class_conn2export(&conn);
267 rc = obd_register_observer(mds->mds_dt_obd, obd);
269 CERROR("MDS cannot register as observer of LOV %s (%d)\n",
271 GOTO(err_discon, rc);
274 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
278 rc = mds_dt_read_objids(obd);
280 CERROR("cannot read %s: rc = %d\n", "lov_objids", rc);
284 rc = obd_llog_cat_initialize(obd, &obd->obd_llogs,
285 mds->mds_dt_desc.ld_tgt_count, CATLIST);
287 CERROR("failed to initialize catalog %d\n", rc);
291 /* If we're mounting this code for the first time on an existing FS,
292 * we need to populate the objids array from the real OST values */
293 if (!mds->mds_dt_objids_valid) {
294 int size = sizeof(obd_id) * mds->mds_dt_desc.ld_tgt_count;
295 rc = obd_get_info(mds->mds_dt_exp, strlen("last_id"),
296 "last_id", &size, mds->mds_dt_objids);
298 for (i = 0; i < mds->mds_dt_desc.ld_tgt_count; i++)
299 CWARN("got last object "LPU64" from OST %d\n",
300 mds->mds_dt_objids[i], i);
301 mds->mds_dt_objids_valid = 1;
302 rc = mds_dt_write_objids(obd);
304 CERROR("got last objids from OSTs, but error "
305 "writing objids file: %d\n", rc);
309 /* I want to see a callback happen when the OBD moves to a
310 * "For General Use" state, and that's when we'll call
311 * set_nextid(). The class driver can help us here, because
312 * it can use the obd_recovering flag to determine when the
313 * the OBD is full available. */
314 if (!obd->obd_recovering) {
315 rc = mds_postrecov_common(obd);
322 obd_register_observer(mds->mds_dt_obd, NULL);
324 obd_disconnect(mds->mds_dt_exp, 0);
325 mds->mds_dt_exp = NULL;
326 mds->mds_dt_obd = ERR_PTR(rc);
330 int mds_dt_disconnect(struct obd_device *obd, int flags)
332 struct mds_obd *mds = &obd->u.mds;
336 if (!IS_ERR(mds->mds_dt_obd) && mds->mds_dt_exp != NULL) {
337 /* cleanup all llogging subsystems */
338 rc = obd_llog_finish(obd, &obd->obd_llogs,
339 mds->mds_dt_desc.ld_tgt_count);
341 CERROR("failed to cleanup llogging subsystems\n");
343 obd_register_observer(mds->mds_dt_obd, NULL);
345 rc = obd_disconnect(mds->mds_dt_exp, flags);
346 /* if obd_disconnect fails (probably because the
347 * export was disconnected by class_disconnect_exports)
348 * then we just need to drop our ref. */
350 class_export_put(mds->mds_dt_exp);
351 mds->mds_dt_exp = NULL;
352 mds->mds_dt_obd = NULL;
358 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
359 void *karg, void *uarg)
361 static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
362 struct obd_device *obd = exp->exp_obd;
363 struct mds_obd *mds = &obd->u.mds;
364 struct obd_ioctl_data *data = karg;
365 struct lvfs_run_ctxt saved;
369 CDEBUG(D_INFO, "ioctl cmd %x\n", cmd);
371 case OBD_IOC_RECORD: {
372 char *name = data->ioc_inlbuf1;
373 if (mds->mds_cfg_llh)
376 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
377 rc = llog_open(llog_get_context(&obd->obd_llogs,
378 LLOG_CONFIG_ORIG_CTXT),
379 &mds->mds_cfg_llh, NULL, name,
382 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
385 mds->mds_cfg_llh = NULL;
386 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
391 case OBD_IOC_ENDRECORD: {
392 if (!mds->mds_cfg_llh)
395 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
396 rc = llog_close(mds->mds_cfg_llh);
397 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
399 mds->mds_cfg_llh = NULL;
403 case OBD_IOC_CLEAR_LOG: {
404 char *name = data->ioc_inlbuf1;
405 if (mds->mds_cfg_llh)
408 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
409 rc = llog_open(llog_get_context(&obd->obd_llogs,
410 LLOG_CONFIG_ORIG_CTXT),
411 &mds->mds_cfg_llh, NULL, name,
414 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
417 rc = llog_destroy(mds->mds_cfg_llh);
418 llog_free_handle(mds->mds_cfg_llh);
420 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
422 mds->mds_cfg_llh = NULL;
426 case OBD_IOC_DORECORD: {
428 struct llog_rec_hdr rec;
429 if (!mds->mds_cfg_llh)
432 /* XXX - this probably should be a parameter to this ioctl.
433 * For now, just use llh_max_transno for expediency. */
434 rec.lrh_len = llog_data_len(data->ioc_plen1);
436 if (data->ioc_type == LUSTRE_CFG_TYPE) {
437 rec.lrh_type = OBD_CFG_REC;
438 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
439 rec.lrh_type = PTL_CFG_REC;
441 CERROR("unknown cfg record type:%d \n", data->ioc_type);
445 OBD_ALLOC(cfg_buf, data->ioc_plen1);
448 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
450 OBD_FREE(cfg_buf, data->ioc_plen1);
454 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
455 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
457 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
459 OBD_FREE(cfg_buf, data->ioc_plen1);
462 case OBD_IOC_PARSE: {
463 struct llog_ctxt *ctxt =
464 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
465 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
466 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
467 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
473 case OBD_IOC_DUMP_LOG: {
474 struct llog_ctxt *ctxt =
475 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
476 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
477 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
478 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 ll_set_rdonly(ll_sbdev(obd->u.mds.mds_sb));
497 case OBD_IOC_CATLOGLIST: {
498 int count = mds->mds_dt_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);
511 obd_llog_finish(obd, &obd->obd_llogs,
512 mds->mds_dt_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_dt_desc.ld_tgt_count,
519 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
520 valsize = sizeof(group);
521 rc2 = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
522 "mds_conn", valsize, &group);
527 case OBD_IOC_LLOG_INFO:
528 case OBD_IOC_LLOG_PRINT: {
529 struct llog_ctxt *ctxt =
530 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
532 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
533 rc = llog_ioctl(ctxt, cmd, data);
534 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
539 case OBD_IOC_ABORT_RECOVERY:
540 target_stop_recovery_thread(obd);
542 case OBD_IOC_ROOT_SQUASH: {
543 __u32 *p = (__u32 *) data->ioc_inlbuf1;
545 if (data->ioc_inllen1 !=
546 (sizeof(__u32) * 4 + sizeof(ptl_nid_t)))
549 if (*p == 0) { /* get */
551 *p++ = mds->mds_squash_uid;
552 *p++ = mds->mds_squash_gid;
553 *((ptl_nid_t*) p) = mds->mds_nosquash_nid;
556 mds->mds_squash_uid = *p++;
557 mds->mds_squash_gid = *p++;
558 mds->mds_nosquash_nid = *((ptl_nid_t*) p);
559 CWARN("MDS: squash root to %d:%d, except nid 0x%llx\n",
560 mds->mds_squash_uid, mds->mds_squash_gid,
561 mds->mds_nosquash_nid);
566 CDEBUG(D_INFO, "unknown command %x\n", cmd);
573 struct mds_dt_sync_info {
574 struct obd_device *mlsi_obd; /* the mds to sync */
575 struct obd_device *mlsi_watched; /* new lov target */
576 int mlsi_index; /* index into mds_dt_objids */
579 int mds_dt_synchronize(void *data)
581 struct mds_dt_sync_info *mlsi = data;
582 struct llog_ctxt *ctxt;
583 struct obd_device *obd;
584 struct obd_device *watched;
586 struct obd_uuid *uuid;
595 char name[32] = "CATLIST";
601 SIGNAL_MASK_LOCK(current, flags);
602 sigfillset(¤t->blocked);
604 SIGNAL_MASK_UNLOCK(current, flags);
608 obd = mlsi->mlsi_obd;
609 watched = mlsi->mlsi_watched;
610 index = mlsi->mlsi_index;
612 LASSERT(obd != NULL);
613 LASSERT(watched != NULL);
615 OBD_FREE(mlsi, sizeof(*mlsi));
618 down(&mds->mds_orphan_recovery_sem);
620 uuid = &watched->u.cli.cl_import->imp_target_uuid;
622 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
623 rc = obd_set_info(watched->obd_self_export, strlen("mds_conn"),
624 "mds_conn", sizeof(group), &group);
628 old_count = mds->mds_dt_desc.ld_tgt_count;
630 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
634 count = mds->mds_dt_desc.ld_tgt_count;
635 LASSERT(count >= old_count);
637 vallen = sizeof(vals[1]);
638 rc = obd_get_info(watched->obd_self_export, strlen("last_id"),
639 "last_id", &vallen, &vals[1]);
644 rc = mds_dt_set_info(obd->obd_self_export, strlen("next_id"),
649 obd_llog_finish(obd, &obd->obd_llogs, old_count);
650 obd_llog_cat_initialize(obd, &obd->obd_llogs, count, name);
652 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
653 LASSERT(ctxt != NULL);
655 rc = llog_connect(ctxt, count, NULL, NULL, uuid);
657 CERROR("%s: failed at llog_origin_connect: %d\n",
662 CWARN("MDS %s: %s now active, resetting orphans\n",
663 obd->obd_name, uuid->uuid);
665 rc = mds_dt_clearorphans(&obd->u.mds, uuid);
667 CERROR("%s: failed at mds_dt_clearorphans(): %d\n",
675 up(&mds->mds_orphan_recovery_sem);
679 int mds_dt_start_synchronize(struct obd_device *obd,
680 struct obd_device *watched,
683 struct mds_dt_sync_info *mlsi;
688 OBD_ALLOC(mlsi, sizeof(*mlsi));
692 mlsi->mlsi_obd = obd;
693 mlsi->mlsi_watched = watched;
694 mlsi->mlsi_index = (int)data;
696 rc = kernel_thread(mds_dt_synchronize, mlsi, CLONE_VM | CLONE_FILES);
698 CERROR("%s: error starting mds_dt_synchronize(): %d\n",
701 CDEBUG(D_HA, "%s: mds_dt_synchronize() thread: %d\n",
709 int mds_notify(struct obd_device *obd, struct obd_device *watched,
710 int active, void *data)
718 if (!strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME))
721 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
722 CERROR("unexpected notification of %s %s!\n",
723 watched->obd_type->typ_name, watched->obd_name);
727 if (obd->obd_recovering) {
728 struct obd_uuid *uuid;
729 uuid = &watched->u.cli.cl_import->imp_target_uuid;
731 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
732 obd->obd_name, uuid->uuid);
734 rc = mds_dt_start_synchronize(obd, watched, data);
739 int mds_dt_set_info(struct obd_export *exp, obd_count keylen,
740 void *key, obd_count vallen, void *val)
742 struct obd_device *obd = class_exp2obd(exp);
743 struct mds_obd *mds = &obd->u.mds;
746 #define KEY_IS(str) \
747 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
749 if (KEY_IS("next_id")) {
750 obd_id *id = (obd_id *)val;
753 /* XXX - this really should be vallen != (2 * sizeof(*id)) *
754 * Just following the precedent set by lov_set_info. */
759 if ((idx != *id) || (idx >= mds->mds_dt_desc.ld_tgt_count))
762 CDEBUG(D_CONFIG, "idx: %d id: %llu\n", idx, *(id + 1));
764 mds->mds_dt_objids[idx] = *++id;
765 CDEBUG(D_CONFIG, "objid: %d: %lld\n", idx, *id);
766 /* XXX - should we be writing this out here ? */
767 RETURN(mds_dt_write_objids(obd));
773 int mds_dt_update_config(struct obd_device *obd, int clean)
775 struct mds_obd *mds = &obd->u.mds;
776 struct lvfs_run_ctxt saved;
777 struct config_llog_instance cfg;
778 struct llog_ctxt *ctxt;
779 char *profile = mds->mds_profile, *name;
780 int rc, version, namelen;
786 cfg.cfg_instance = NULL;
787 cfg.cfg_uuid = mds->mds_dt_uuid;
789 namelen = strlen(profile) + 20; /* -clean-######### */
790 OBD_ALLOC(name, namelen);
795 version = mds->mds_config_version - 1;
796 sprintf(name, "%s-clean-%d", profile, version);
798 version = mds->mds_config_version + 1;
799 sprintf(name, "%s-%d", profile, version);
802 CWARN("Applying configuration log %s\n", name);
804 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
805 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
806 rc = class_config_process_llog(ctxt, name, &cfg);
807 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
809 mds->mds_config_version = version;
810 CWARN("Finished applying configuration log %s: %d\n", name, rc);
812 OBD_FREE(name, namelen);
816 /* Convert the on-disk LOV EA structre.
817 * We always try to convert from an old LOV EA format to the common in-memory
818 * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
819 * then convert back to the new on-disk format and save it back to disk
820 * (obd_packmd() only ever saves to the new on-disk format) so we don't have
821 * to convert it each time this inode is accessed.
823 * This function is a bit interesting in the error handling. We can safely
824 * ship the old lmm to the client in case of failure, since it uses the same
825 * obd_unpackmd() code and can do the conversion if the MDS fails for some
826 * reason. We will not delete the old lmm data until we have written the
827 * new format lmm data in fsfilt_set_md(). */
828 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
829 struct lov_mds_md *lmm, int lmm_size)
831 struct lov_stripe_md *lsm = NULL;
836 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
839 CDEBUG(D_INODE, "converting LOV EA on %lu/%u from V0 to V1\n",
840 inode->i_ino, inode->i_generation);
841 rc = obd_unpackmd(obd->u.mds.mds_dt_exp, &lsm, lmm, lmm_size);
845 rc = obd_packmd(obd->u.mds.mds_dt_exp, &lmm, lsm);
850 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
851 if (IS_ERR(handle)) {
852 rc = PTR_ERR(handle);
856 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
857 err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0);
859 rc = err ? err : lmm_size;
862 obd_free_memmd(obd->u.mds.mds_dt_exp, &lsm);
867 /* Must be called with i_sem held */
868 int mds_revalidate_lov_ea(struct obd_device *obd, struct inode *inode,
869 struct lustre_msg *msg, int offset)
871 struct mds_obd *mds = &obd->u.mds;
872 struct obd_export *dt_exp = mds->mds_dt_exp;
873 struct lov_mds_md *lmm= NULL;
874 struct lov_stripe_md *lsm = NULL;
875 struct obdo *oa = NULL;
876 struct obd_trans_info oti = {0};
878 int lmm_size = 0, lsm_size = 0, err, rc;
882 LASSERT(down_trylock(&inode->i_sem) != 0);
884 /* XXX - add way to know if EA is already up to date & return
885 * without doing anything. Easy to do since we get notified of
888 lmm = lustre_msg_buf(msg, offset, 0);
890 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
894 lmm_size = msg->buflens[offset];
896 rc = obd_unpackmd(dt_exp, &lsm, lmm, lmm_size);
902 LASSERT(lsm->lsm_magic == LOV_MAGIC);
906 GOTO(out_lsm, rc = -ENOMEM);
907 oa->o_mode = S_IFREG | 0600;
908 oa->o_id = inode->i_ino;
909 oa->o_generation = inode->i_generation;
910 oa->o_uid = 0; /* must have 0 uid / gid on OST */
912 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
914 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
915 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID |
917 valid = OBD_MD_FLTYPE | OBD_MD_FLATIME | OBD_MD_FLMTIME |
919 obdo_from_inode(oa, inode, valid);
921 rc = obd_revalidate_md(dt_exp, oa, lsm, &oti);
925 CERROR("Error validating LOV EA on %lu/%u: %d\n",
926 inode->i_ino, inode->i_generation, rc);
930 rc = obd_packmd(dt_exp, &lmm, lsm);
935 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
936 if (IS_ERR(handle)) {
937 rc = PTR_ERR(handle);
941 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
942 err = fsfilt_commit(obd, inode->i_sb, inode, handle, 0);
950 obd_free_memmd(dt_exp, &lsm);