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);
327 * I want to see a callback happen when the OBD moves to a "For General
328 * Use" state, and that's when we'll call set_nextid(). The class driver
329 * can help us here, because it can use the obd_recovering flag to
330 * determine when the the OBD is full available.
332 if (!obd->obd_recovering) {
333 CDEBUG(D_OTHER, "call mds_postrecov_common()\n");
334 rc = mds_postrecov_common(obd);
341 obd_register_observer(mds->mds_dt_obd, NULL);
343 obd_disconnect(mds->mds_dt_exp, 0);
344 mds->mds_dt_obd = ERR_PTR(rc);
345 mds->mds_dt_exp = NULL;
349 int mds_dt_disconnect(struct obd_device *obd, int flags)
351 struct mds_obd *mds = &obd->u.mds;
355 if (!IS_ERR(mds->mds_dt_obd) && mds->mds_dt_exp != NULL) {
356 /* cleanup all llogging subsystems */
357 rc = obd_llog_finish(obd, &obd->obd_llogs,
358 mds->mds_dt_desc.ld_tgt_count);
360 CERROR("failed to cleanup llogging subsystems\n");
362 obd_register_observer(mds->mds_dt_obd, NULL);
364 rc = obd_disconnect(mds->mds_dt_exp, flags);
365 /* if obd_disconnect fails (probably because the
366 * export was disconnected by class_disconnect_exports)
367 * then we just need to drop our ref. */
369 class_export_put(mds->mds_dt_exp);
370 mds->mds_dt_exp = NULL;
371 mds->mds_dt_obd = NULL;
377 int mds_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
378 void *karg, void *uarg)
380 static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" };
381 struct obd_device *obd = exp->exp_obd;
382 struct mds_obd *mds = &obd->u.mds;
383 struct obd_ioctl_data *data = karg;
384 struct lvfs_run_ctxt saved;
388 CDEBUG(D_INFO, "ioctl cmd %x\n", cmd);
390 case OBD_IOC_RECORD: {
391 char *name = data->ioc_inlbuf1;
392 if (mds->mds_cfg_llh)
395 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
396 rc = llog_open(llog_get_context(&obd->obd_llogs,
397 LLOG_CONFIG_ORIG_CTXT),
398 &mds->mds_cfg_llh, NULL, name,
401 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
404 mds->mds_cfg_llh = NULL;
405 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
410 case OBD_IOC_ENDRECORD: {
411 if (!mds->mds_cfg_llh)
414 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
415 rc = llog_close(mds->mds_cfg_llh);
416 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
418 mds->mds_cfg_llh = NULL;
422 case OBD_IOC_CLEAR_LOG: {
423 char *name = data->ioc_inlbuf1;
424 if (mds->mds_cfg_llh)
427 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
428 rc = llog_open(llog_get_context(&obd->obd_llogs,
429 LLOG_CONFIG_ORIG_CTXT),
430 &mds->mds_cfg_llh, NULL, name,
433 llog_init_handle(mds->mds_cfg_llh, LLOG_F_IS_PLAIN,
436 rc = llog_destroy(mds->mds_cfg_llh);
437 llog_free_handle(mds->mds_cfg_llh);
439 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
441 mds->mds_cfg_llh = NULL;
445 case OBD_IOC_DORECORD: {
447 struct llog_rec_hdr rec;
448 if (!mds->mds_cfg_llh)
451 /* XXX - this probably should be a parameter to this ioctl.
452 * For now, just use llh_max_transno for expediency. */
453 rec.lrh_len = llog_data_len(data->ioc_plen1);
455 if (data->ioc_type == LUSTRE_CFG_TYPE) {
456 rec.lrh_type = OBD_CFG_REC;
457 } else if (data->ioc_type == PORTALS_CFG_TYPE) {
458 rec.lrh_type = PTL_CFG_REC;
460 CERROR("unknown cfg record type:%d \n", data->ioc_type);
464 OBD_ALLOC(cfg_buf, data->ioc_plen1);
467 rc = copy_from_user(cfg_buf, data->ioc_pbuf1, data->ioc_plen1);
469 OBD_FREE(cfg_buf, data->ioc_plen1);
473 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
474 rc = llog_write_rec(mds->mds_cfg_llh, &rec, NULL, 0,
476 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
478 OBD_FREE(cfg_buf, data->ioc_plen1);
481 case OBD_IOC_PARSE: {
482 struct llog_ctxt *ctxt =
483 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
484 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
485 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
486 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
492 case OBD_IOC_DUMP_LOG: {
493 struct llog_ctxt *ctxt =
494 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
495 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
496 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
497 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
501 case OBD_IOC_SET_READONLY: {
503 struct inode *inode = obd->u.mds.mds_sb->s_root->d_inode;
504 BDEVNAME_DECLARE_STORAGE(tmp);
505 CERROR("setting device %s read-only\n",
506 ll_bdevname(obd->u.mds.mds_sb, tmp));
508 handle = fsfilt_start(obd, inode, FSFILT_OP_MKNOD, NULL);
510 rc = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 1);
512 ll_set_rdonly(ll_sbdev(obd->u.mds.mds_sb));
516 case OBD_IOC_CATLOGLIST: {
517 int count = mds->mds_dt_desc.ld_tgt_count;
518 rc = llog_catalog_list(obd, count, data);
522 case OBD_IOC_LLOG_CHECK:
523 case OBD_IOC_LLOG_CANCEL:
524 case OBD_IOC_LLOG_REMOVE: {
525 struct llog_ctxt *ctxt =
526 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
530 obd_llog_finish(obd, &obd->obd_llogs,
531 mds->mds_dt_desc.ld_tgt_count);
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);
535 obd_llog_cat_initialize(obd, &obd->obd_llogs,
536 mds->mds_dt_desc.ld_tgt_count,
538 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
539 valsize = sizeof(group);
540 rc2 = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
541 "mds_conn", valsize, &group);
546 case OBD_IOC_LLOG_INFO:
547 case OBD_IOC_LLOG_PRINT: {
548 struct llog_ctxt *ctxt =
549 llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
551 push_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
552 rc = llog_ioctl(ctxt, cmd, data);
553 pop_ctxt(&saved, ctxt->loc_lvfs_ctxt, NULL);
558 case OBD_IOC_ABORT_RECOVERY:
559 target_stop_recovery_thread(obd);
561 case OBD_IOC_ROOT_SQUASH: {
562 __u32 *p = (__u32 *) data->ioc_inlbuf1;
564 if (data->ioc_inllen1 !=
565 (sizeof(__u32) * 4 + sizeof(ptl_nid_t)))
568 if (*p == 0) { /* get */
570 *p++ = mds->mds_squash_uid;
571 *p++ = mds->mds_squash_gid;
572 *((ptl_nid_t*) p) = mds->mds_nosquash_nid;
575 mds->mds_squash_uid = *p++;
576 mds->mds_squash_gid = *p++;
577 mds->mds_nosquash_nid = *((ptl_nid_t*) p);
578 CWARN("MDS: squash root to %d:%d, except nid 0x%llx\n",
579 mds->mds_squash_uid, mds->mds_squash_gid,
580 mds->mds_nosquash_nid);
585 CDEBUG(D_INFO, "unknown command %x\n", cmd);
592 struct mds_dt_sync_info {
593 struct obd_device *mlsi_obd; /* the mds to sync */
594 struct obd_device *mlsi_watched; /* new lov target */
595 int mlsi_index; /* index into mds_dt_objids */
598 int mds_dt_synchronize(void *data)
600 struct mds_dt_sync_info *mlsi = data;
601 struct llog_ctxt *ctxt;
602 struct obd_device *obd;
603 struct obd_device *watched;
605 struct obd_uuid *uuid;
614 char name[32] = "CATLIST";
620 SIGNAL_MASK_LOCK(current, flags);
621 sigfillset(¤t->blocked);
623 SIGNAL_MASK_UNLOCK(current, flags);
627 obd = mlsi->mlsi_obd;
628 watched = mlsi->mlsi_watched;
629 index = mlsi->mlsi_index;
631 LASSERT(obd != NULL);
632 LASSERT(watched != NULL);
634 OBD_FREE(mlsi, sizeof(*mlsi));
637 down(&mds->mds_orphan_recovery_sem);
639 uuid = &watched->u.cli.cl_import->imp_target_uuid;
641 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
642 rc = obd_set_info(watched->obd_self_export, strlen("mds_conn"),
643 "mds_conn", sizeof(group), &group);
647 old_count = mds->mds_dt_desc.ld_tgt_count;
649 rc = mds_dt_update_desc(obd, mds->mds_dt_exp);
653 count = mds->mds_dt_desc.ld_tgt_count;
654 LASSERT(count >= old_count);
656 vallen = sizeof(vals[1]);
657 rc = obd_get_info(watched->obd_self_export, strlen("last_id"),
658 "last_id", &vallen, &vals[1]);
663 rc = mds_dt_set_info(obd->obd_self_export, strlen("next_id"),
668 obd_llog_finish(obd, &obd->obd_llogs, old_count);
669 obd_llog_cat_initialize(obd, &obd->obd_llogs, count, name);
671 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
672 LASSERT(ctxt != NULL);
674 rc = llog_connect(ctxt, count, NULL, NULL, uuid);
676 CERROR("%s: failed at llog_origin_connect: %d\n",
681 CWARN("MDS %s: %s now active, resetting orphans\n",
682 obd->obd_name, uuid->uuid);
684 rc = mds_dt_clear_orphans(&obd->u.mds, uuid);
686 CERROR("%s: failed at mds_dt_clear_orphans(): %d\n",
694 up(&mds->mds_orphan_recovery_sem);
698 int mds_dt_start_synchronize(struct obd_device *obd,
699 struct obd_device *watched,
702 struct mds_dt_sync_info *mlsi;
707 OBD_ALLOC(mlsi, sizeof(*mlsi));
711 mlsi->mlsi_obd = obd;
712 mlsi->mlsi_watched = watched;
713 mlsi->mlsi_index = (int)data;
715 rc = kernel_thread(mds_dt_synchronize, mlsi, CLONE_VM | CLONE_FILES);
717 CERROR("%s: error starting mds_dt_synchronize(): %d\n",
720 CDEBUG(D_HA, "%s: mds_dt_synchronize() thread: %d\n",
728 int mds_notify(struct obd_device *obd, struct obd_device *watched,
729 int active, void *data)
737 if (!strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME))
740 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
741 CERROR("unexpected notification of %s %s!\n",
742 watched->obd_type->typ_name, watched->obd_name);
746 if (obd->obd_recovering) {
747 struct obd_uuid *uuid;
748 uuid = &watched->u.cli.cl_import->imp_target_uuid;
750 CWARN("MDS %s: in recovery, not resetting orphans on %s\n",
751 obd->obd_name, uuid->uuid);
753 rc = mds_dt_start_synchronize(obd, watched, data);
758 int mds_dt_set_info(struct obd_export *exp, obd_count keylen,
759 void *key, obd_count vallen, void *val)
761 struct obd_device *obd = class_exp2obd(exp);
762 struct mds_obd *mds = &obd->u.mds;
765 #define KEY_IS(str) \
766 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
768 if (KEY_IS("next_id")) {
769 obd_id *id = (obd_id *)val;
772 /* XXX - this really should be vallen != (2 * sizeof(*id)) *
773 * Just following the precedent set by lov_set_info. */
778 if ((idx != *id) || (idx >= mds->mds_dt_desc.ld_tgt_count))
781 CDEBUG(D_CONFIG, "idx: %d id: %llu\n", idx, *(id + 1));
783 mds->mds_dt_objids[idx] = *++id;
784 CDEBUG(D_CONFIG, "objid: %d: %lld\n", idx, *id);
785 /* XXX - should we be writing this out here ? */
786 RETURN(mds_dt_write_objids(obd));
792 int mds_dt_update_config(struct obd_device *obd, int clean)
794 struct mds_obd *mds = &obd->u.mds;
795 struct lvfs_run_ctxt saved;
796 struct config_llog_instance cfg;
797 struct llog_ctxt *ctxt;
798 char *profile = mds->mds_profile, *name;
799 int rc, version, namelen;
805 cfg.cfg_instance = NULL;
806 cfg.cfg_uuid = mds->mds_dt_uuid;
808 namelen = strlen(profile) + 20; /* -clean-######### */
809 OBD_ALLOC(name, namelen);
814 version = mds->mds_config_version - 1;
815 sprintf(name, "%s-clean-%d", profile, version);
817 version = mds->mds_config_version + 1;
818 sprintf(name, "%s-%d", profile, version);
821 CWARN("Applying configuration log %s\n", name);
823 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
824 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
825 rc = class_config_process_llog(ctxt, name, &cfg);
826 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
828 mds->mds_config_version = version;
829 CWARN("Finished applying configuration log %s: %d\n", name, rc);
831 OBD_FREE(name, namelen);
835 /* Convert the on-disk LOV EA structre.
836 * We always try to convert from an old LOV EA format to the common in-memory
837 * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
838 * then convert back to the new on-disk format and save it back to disk
839 * (obd_packmd() only ever saves to the new on-disk format) so we don't have
840 * to convert it each time this inode is accessed.
842 * This function is a bit interesting in the error handling. We can safely
843 * ship the old lmm to the client in case of failure, since it uses the same
844 * obd_unpackmd() code and can do the conversion if the MDS fails for some
845 * reason. We will not delete the old lmm data until we have written the
846 * new format lmm data in fsfilt_set_md(). */
847 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
848 struct lov_mds_md *lmm, int lmm_size)
850 struct lov_stripe_md *lsm = NULL;
855 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC)
858 CDEBUG(D_INODE, "converting LOV EA on %lu/%u from V0 to V1\n",
859 inode->i_ino, inode->i_generation);
860 rc = obd_unpackmd(obd->u.mds.mds_dt_exp, &lsm, lmm, lmm_size);
864 rc = obd_packmd(obd->u.mds.mds_dt_exp, &lmm, lsm);
869 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
870 if (IS_ERR(handle)) {
871 rc = PTR_ERR(handle);
875 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
876 err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0);
878 rc = err ? err : lmm_size;
881 obd_free_memmd(obd->u.mds.mds_dt_exp, &lsm);
886 /* Must be called with i_sem held */
887 int mds_revalidate_lov_ea(struct obd_device *obd, struct inode *inode,
888 struct lustre_msg *msg, int offset)
890 struct mds_obd *mds = &obd->u.mds;
891 struct obd_export *dt_exp = mds->mds_dt_exp;
892 struct lov_mds_md *lmm= NULL;
893 struct lov_stripe_md *lsm = NULL;
894 struct obdo *oa = NULL;
895 struct obd_trans_info oti = {0};
897 int lmm_size = 0, lsm_size = 0, err, rc;
901 LASSERT(down_trylock(&inode->i_sem) != 0);
903 /* XXX - add way to know if EA is already up to date & return
904 * without doing anything. Easy to do since we get notified of
907 lmm = lustre_msg_buf(msg, offset, 0);
909 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
913 lmm_size = msg->buflens[offset];
915 rc = obd_unpackmd(dt_exp, &lsm, lmm, lmm_size);
921 LASSERT(lsm->lsm_magic == LOV_MAGIC);
925 GOTO(out_lsm, rc = -ENOMEM);
926 oa->o_mode = S_IFREG | 0600;
927 oa->o_id = inode->i_ino;
928 oa->o_generation = inode->i_generation;
929 oa->o_uid = 0; /* must have 0 uid / gid on OST */
931 oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num;
933 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
934 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID |
936 valid = OBD_MD_FLTYPE | OBD_MD_FLATIME | OBD_MD_FLMTIME |
938 obdo_from_inode(oa, inode, valid);
940 rc = obd_revalidate_md(dt_exp, oa, lsm, &oti);
944 CERROR("Error validating LOV EA on %lu/%u: %d\n",
945 inode->i_ino, inode->i_generation, rc);
949 rc = obd_packmd(dt_exp, &lmm, lsm);
954 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
955 if (IS_ERR(handle)) {
956 rc = PTR_ERR(handle);
960 rc = fsfilt_set_md(obd, inode, handle, lmm, lmm_size, EA_LOV);
961 err = fsfilt_commit(obd, inode->i_sb, inode, handle, 0);
969 obd_free_memmd(dt_exp, &lsm);