4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdd/mdd_device.c
38 * Lustre Metadata Server (mdd) routines
40 * Author: Wang Di <wangdi@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_MDS
45 #include <obd_class.h>
46 #include <lprocfs_status.h>
47 #include <lustre_fid.h>
48 #include <lustre_mds.h>
49 #include <lustre_disk.h> /* for changelogs */
50 #include <lustre_param.h>
51 #include <lustre_fid.h>
53 #include "mdd_internal.h"
55 const struct md_device_operations mdd_ops;
56 static struct lu_device_type mdd_device_type;
58 static const char mdd_root_dir_name[] = "ROOT";
59 static const char mdd_obf_dir_name[] = "fid";
61 /* Slab for MDD object allocation */
62 cfs_mem_cache_t *mdd_object_kmem;
64 static struct lu_kmem_descr mdd_caches[] = {
66 .ckd_cache = &mdd_object_kmem,
67 .ckd_name = "mdd_obj",
68 .ckd_size = sizeof(struct mdd_object)
75 static int mdd_device_init(const struct lu_env *env, struct lu_device *d,
76 const char *name, struct lu_device *next)
78 struct mdd_device *mdd = lu2mdd_dev(d);
82 mdd->mdd_child = lu2dt_dev(next);
84 /* Prepare transactions callbacks. */
85 mdd->mdd_txn_cb.dtc_txn_start = NULL;
86 mdd->mdd_txn_cb.dtc_txn_stop = mdd_txn_stop_cb;
87 mdd->mdd_txn_cb.dtc_txn_commit = NULL;
88 mdd->mdd_txn_cb.dtc_cookie = mdd;
89 mdd->mdd_txn_cb.dtc_tag = LCT_MD_THREAD;
90 CFS_INIT_LIST_HEAD(&mdd->mdd_txn_cb.dtc_linkage);
91 mdd->mdd_atime_diff = MAX_ATIME_DIFF;
92 /* sync permission changes */
93 mdd->mdd_sync_permission = 1;
95 rc = mdd_procfs_init(mdd, name);
99 static struct lu_device *mdd_device_fini(const struct lu_env *env,
102 struct mdd_device *mdd = lu2mdd_dev(d);
105 rc = mdd_procfs_fini(mdd);
107 CERROR("proc fini error %d \n", rc);
113 static void mdd_changelog_fini(const struct lu_env *env,
114 struct mdd_device *mdd);
116 static void mdd_device_shutdown(const struct lu_env *env,
117 struct mdd_device *m, struct lustre_cfg *cfg)
120 mdd_lfsck_cleanup(env, m);
121 mdd_changelog_fini(env, m);
122 dt_txn_callback_del(m->mdd_child, &m->mdd_txn_cb);
123 if (m->mdd_dot_lustre_objs.mdd_obf)
124 mdd_object_put(env, m->mdd_dot_lustre_objs.mdd_obf);
125 if (m->mdd_dot_lustre)
126 mdd_object_put(env, m->mdd_dot_lustre);
128 mdd_fini_obd(env, m, cfg);
129 orph_index_fini(env, m);
130 if (m->mdd_capa != NULL) {
131 lu_object_put(env, &m->mdd_capa->do_lu);
134 /* remove upcall device*/
135 md_upcall_fini(&m->mdd_md_dev);
139 static int changelog_init_cb(const struct lu_env *env, struct llog_handle *llh,
140 struct llog_rec_hdr *hdr, void *data)
142 struct mdd_device *mdd = (struct mdd_device *)data;
143 struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
146 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
147 LASSERT(rec->cr_hdr.lrh_type == CHANGELOG_REC);
150 "seeing record at index %d/%d/"LPU64" t=%x %.*s in log "LPX64"\n",
151 hdr->lrh_index, rec->cr_hdr.lrh_index, rec->cr.cr_index,
152 rec->cr.cr_type, rec->cr.cr_namelen, rec->cr.cr_name,
153 llh->lgh_id.lgl_oid);
155 mdd->mdd_cl.mc_index = rec->cr.cr_index;
156 RETURN(LLOG_PROC_BREAK);
159 static int changelog_user_init_cb(const struct lu_env *env,
160 struct llog_handle *llh,
161 struct llog_rec_hdr *hdr, void *data)
163 struct mdd_device *mdd = (struct mdd_device *)data;
164 struct llog_changelog_user_rec *rec =
165 (struct llog_changelog_user_rec *)hdr;
168 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
169 LASSERT(rec->cur_hdr.lrh_type == CHANGELOG_USER_REC);
171 CDEBUG(D_INFO, "seeing user at index %d/%d id=%d endrec="LPU64
172 " in log "LPX64"\n", hdr->lrh_index, rec->cur_hdr.lrh_index,
173 rec->cur_id, rec->cur_endrec, llh->lgh_id.lgl_oid);
175 cfs_spin_lock(&mdd->mdd_cl.mc_user_lock);
176 mdd->mdd_cl.mc_lastuser = rec->cur_id;
177 cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
179 RETURN(LLOG_PROC_BREAK);
183 static int mdd_changelog_llog_init(struct mdd_device *mdd)
185 struct obd_device *obd = mdd2obd_dev(mdd);
186 struct llog_ctxt *ctxt;
189 /* Find last changelog entry number */
190 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
192 CERROR("no changelog context\n");
195 if (!ctxt->loc_handle) {
200 rc = llog_cat_reverse_process(NULL, ctxt->loc_handle,
201 changelog_init_cb, mdd);
205 CERROR("changelog init failed: %d\n", rc);
208 CDEBUG(D_IOCTL, "changelog starting index="LPU64"\n",
209 mdd->mdd_cl.mc_index);
211 /* Find last changelog user id */
212 ctxt = llog_get_context(obd, LLOG_CHANGELOG_USER_ORIG_CTXT);
214 CERROR("no changelog user context\n");
217 if (!ctxt->loc_handle) {
222 rc = llog_cat_reverse_process(NULL, ctxt->loc_handle,
223 changelog_user_init_cb, mdd);
227 CERROR("changelog user init failed: %d\n", rc);
231 /* If we have registered users, assume we want changelogs on */
232 if (mdd->mdd_cl.mc_lastuser > 0)
233 rc = mdd_changelog_on(mdd, 1);
238 static int mdd_changelog_init(const struct lu_env *env, struct mdd_device *mdd)
242 mdd->mdd_cl.mc_index = 0;
243 cfs_spin_lock_init(&mdd->mdd_cl.mc_lock);
244 mdd->mdd_cl.mc_starttime = cfs_time_current_64();
245 mdd->mdd_cl.mc_flags = 0; /* off by default */
246 mdd->mdd_cl.mc_mask = CHANGELOG_DEFMASK;
247 cfs_spin_lock_init(&mdd->mdd_cl.mc_user_lock);
248 mdd->mdd_cl.mc_lastuser = 0;
250 rc = mdd_changelog_llog_init(mdd);
252 CERROR("Changelog setup during init failed %d\n", rc);
253 mdd->mdd_cl.mc_flags |= CLM_ERR;
259 static void mdd_changelog_fini(const struct lu_env *env, struct mdd_device *mdd)
261 mdd->mdd_cl.mc_flags = 0;
264 /* Start / stop recording */
265 int mdd_changelog_on(struct mdd_device *mdd, int on)
269 if ((on == 1) && ((mdd->mdd_cl.mc_flags & CLM_ON) == 0)) {
270 LCONSOLE_INFO("%s: changelog on\n", mdd2obd_dev(mdd)->obd_name);
271 if (mdd->mdd_cl.mc_flags & CLM_ERR) {
272 CERROR("Changelogs cannot be enabled due to error "
273 "condition (see %s log).\n",
274 mdd2obd_dev(mdd)->obd_name);
277 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
278 mdd->mdd_cl.mc_flags |= CLM_ON;
279 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
280 rc = mdd_changelog_write_header(mdd, CLM_START);
282 } else if ((on == 0) && ((mdd->mdd_cl.mc_flags & CLM_ON) == CLM_ON)) {
283 LCONSOLE_INFO("%s: changelog off\n",mdd2obd_dev(mdd)->obd_name);
284 rc = mdd_changelog_write_header(mdd, CLM_FINI);
285 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
286 mdd->mdd_cl.mc_flags &= ~CLM_ON;
287 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
292 static __u64 cl_time(void) {
295 cfs_fs_time_current(&time);
296 return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
299 /** Add a changelog entry \a rec to the changelog llog
302 * \param handle - currently ignored since llogs start their own transaction;
303 * this will hopefully be fixed in llog rewrite
306 int mdd_changelog_llog_write(struct mdd_device *mdd,
307 struct llog_changelog_rec *rec,
308 struct thandle *handle)
310 struct obd_device *obd = mdd2obd_dev(mdd);
311 struct llog_ctxt *ctxt;
314 rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
315 /* llog_lvfs_write_rec sets the llog tail len */
316 rec->cr_hdr.lrh_type = CHANGELOG_REC;
317 rec->cr.cr_time = cl_time();
318 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
319 /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
320 but as long as the MDD transactions are ordered correctly for e.g.
321 rename conflicts, I don't think this should matter. */
322 rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
323 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
324 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
328 /* nested journal transaction */
329 rc = llog_add(NULL, ctxt, &rec->cr_hdr, NULL, NULL, 0);
335 /** Add a changelog_ext entry \a rec to the changelog llog
338 * \param handle - currently ignored since llogs start their own transaction;
339 * this will hopefully be fixed in llog rewrite
342 int mdd_changelog_ext_llog_write(struct mdd_device *mdd,
343 struct llog_changelog_ext_rec *rec,
344 struct thandle *handle)
346 struct obd_device *obd = mdd2obd_dev(mdd);
347 struct llog_ctxt *ctxt;
350 rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
351 /* llog_lvfs_write_rec sets the llog tail len */
352 rec->cr_hdr.lrh_type = CHANGELOG_REC;
353 rec->cr.cr_time = cl_time();
354 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
355 /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
356 * but as long as the MDD transactions are ordered correctly for e.g.
357 * rename conflicts, I don't think this should matter. */
358 rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
359 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
360 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
364 /* nested journal transaction */
365 rc = llog_add(NULL, ctxt, &rec->cr_hdr, NULL, NULL, 0);
371 /** Remove entries with indicies up to and including \a endrec from the
377 int mdd_changelog_llog_cancel(const struct lu_env *env,
378 struct mdd_device *mdd, long long endrec)
380 struct obd_device *obd = mdd2obd_dev(mdd);
381 struct llog_ctxt *ctxt;
382 long long unsigned cur;
385 ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
389 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
390 cur = (long long)mdd->mdd_cl.mc_index;
391 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
395 /* purge to "0" is shorthand for everything */
399 /* If purging all records, write a header entry so we don't have an
400 empty catalog and we're sure to have a valid starting index next
401 time. In case of crash, we just restart with old log so we're
404 /* XXX: transaction is started by llog itself */
405 rc = mdd_changelog_write_header(mdd, CLM_PURGE);
410 /* Some records were purged, so reset repeat-access time (so we
411 record new mtime update records, so users can see a file has been
412 changed since the last purge) */
413 mdd->mdd_cl.mc_starttime = cfs_time_current_64();
415 /* XXX: transaction is started by llog itself */
416 rc = llog_cancel(env, ctxt, NULL, 1, (struct llog_cookie *)&endrec, 0);
422 /** Add a CL_MARK record to the changelog
424 * \param markerflags - CLM_*
427 int mdd_changelog_write_header(struct mdd_device *mdd, int markerflags)
429 struct obd_device *obd = mdd2obd_dev(mdd);
430 struct llog_changelog_rec *rec;
432 int len = strlen(obd->obd_name);
436 reclen = llog_data_len(sizeof(*rec) + len);
437 OBD_ALLOC(rec, reclen);
441 rec->cr.cr_flags = CLF_VERSION;
442 rec->cr.cr_type = CL_MARK;
443 rec->cr.cr_namelen = len;
444 memcpy(rec->cr.cr_name, obd->obd_name, rec->cr.cr_namelen);
445 /* Status and action flags */
446 rec->cr.cr_markerflags = mdd->mdd_cl.mc_flags | markerflags;
448 /* XXX: transaction is started by llog itself */
449 rc = (mdd->mdd_cl.mc_mask & (1 << CL_MARK)) ?
450 mdd_changelog_llog_write(mdd, rec, NULL) : 0;
452 /* assume on or off event; reset repeat-access time */
453 mdd->mdd_cl.mc_starttime = cfs_time_current_64();
455 OBD_FREE(rec, reclen);
460 * Create ".lustre" directory.
462 static int create_dot_lustre_dir(const struct lu_env *env, struct mdd_device *m)
464 struct lu_fid *fid = &mdd_env_info(env)->mti_fid;
465 struct md_object *mdo;
468 memcpy(fid, &LU_DOT_LUSTRE_FID, sizeof(struct lu_fid));
469 mdo = llo_store_create_index(env, &m->mdd_md_dev, m->mdd_child,
470 mdd_root_dir_name, dot_lustre_name,
471 fid, &dt_directory_features);
472 /* .lustre dir may be already present */
473 if (IS_ERR(mdo) && PTR_ERR(mdo) != -EEXIST) {
475 CERROR("creating obj [%s] fid = "DFID" rc = %d\n",
476 dot_lustre_name, PFID(fid), rc);
481 lu_object_put(env, &mdo->mo_lu);
487 static int dot_lustre_mdd_permission(const struct lu_env *env,
488 struct md_object *pobj,
489 struct md_object *cobj,
490 struct md_attr *attr, int mask)
492 if (mask & ~(MAY_READ | MAY_EXEC))
498 static int dot_lustre_mdd_xattr_get(const struct lu_env *env,
499 struct md_object *obj, struct lu_buf *buf,
505 static int dot_lustre_mdd_xattr_list(const struct lu_env *env,
506 struct md_object *obj, struct lu_buf *buf)
511 static int dot_lustre_mdd_xattr_set(const struct lu_env *env,
512 struct md_object *obj,
513 const struct lu_buf *buf, const char *name,
519 static int dot_lustre_mdd_xattr_del(const struct lu_env *env,
520 struct md_object *obj,
526 static int dot_lustre_mdd_readlink(const struct lu_env *env,
527 struct md_object *obj, struct lu_buf *buf)
532 static int dot_lustre_mdd_object_create(const struct lu_env *env,
533 struct md_object *obj,
534 const struct md_op_spec *spec,
540 static int dot_lustre_mdd_ref_add(const struct lu_env *env,
541 struct md_object *obj,
542 const struct md_attr *ma)
547 static int dot_lustre_mdd_ref_del(const struct lu_env *env,
548 struct md_object *obj,
554 static int dot_lustre_mdd_open(const struct lu_env *env, struct md_object *obj,
557 struct mdd_object *mdd_obj = md2mdd_obj(obj);
559 mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD);
560 mdd_obj->mod_count++;
561 mdd_write_unlock(env, mdd_obj);
566 static int dot_lustre_mdd_close(const struct lu_env *env, struct md_object *obj,
567 struct md_attr *ma, int mode)
569 struct mdd_object *mdd_obj = md2mdd_obj(obj);
571 mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD);
572 mdd_obj->mod_count--;
573 mdd_write_unlock(env, mdd_obj);
578 static int dot_lustre_mdd_object_sync(const struct lu_env *env,
579 struct md_object *obj)
584 static int dot_lustre_mdd_path(const struct lu_env *env, struct md_object *obj,
585 char *path, int pathlen, __u64 *recno, int *linkno)
590 static int dot_file_lock(const struct lu_env *env, struct md_object *obj,
591 struct lov_mds_md *lmm, struct ldlm_extent *extent,
592 struct lustre_handle *lockh)
597 static int dot_file_unlock(const struct lu_env *env, struct md_object *obj,
598 struct lov_mds_md *lmm, struct lustre_handle *lockh)
603 static struct md_object_operations mdd_dot_lustre_obj_ops = {
604 .moo_permission = dot_lustre_mdd_permission,
605 .moo_attr_get = mdd_attr_get,
606 .moo_attr_set = mdd_attr_set,
607 .moo_xattr_get = dot_lustre_mdd_xattr_get,
608 .moo_xattr_list = dot_lustre_mdd_xattr_list,
609 .moo_xattr_set = dot_lustre_mdd_xattr_set,
610 .moo_xattr_del = dot_lustre_mdd_xattr_del,
611 .moo_readpage = mdd_readpage,
612 .moo_readlink = dot_lustre_mdd_readlink,
613 .moo_object_create = dot_lustre_mdd_object_create,
614 .moo_ref_add = dot_lustre_mdd_ref_add,
615 .moo_ref_del = dot_lustre_mdd_ref_del,
616 .moo_open = dot_lustre_mdd_open,
617 .moo_close = dot_lustre_mdd_close,
618 .moo_capa_get = mdd_capa_get,
619 .moo_object_sync = dot_lustre_mdd_object_sync,
620 .moo_path = dot_lustre_mdd_path,
621 .moo_file_lock = dot_file_lock,
622 .moo_file_unlock = dot_file_unlock,
626 static int dot_lustre_mdd_lookup(const struct lu_env *env, struct md_object *p,
627 const struct lu_name *lname, struct lu_fid *f,
628 struct md_op_spec *spec)
630 if (strcmp(lname->ln_name, mdd_obf_dir_name) == 0)
638 static mdl_mode_t dot_lustre_mdd_lock_mode(const struct lu_env *env,
639 struct md_object *obj,
645 static int dot_lustre_mdd_create(const struct lu_env *env,
646 struct md_object *pobj,
647 const struct lu_name *lname,
648 struct md_object *child,
649 struct md_op_spec *spec,
655 static int dot_lustre_mdd_create_data(const struct lu_env *env,
658 const struct md_op_spec *spec,
664 static int dot_lustre_mdd_rename(const struct lu_env *env,
665 struct md_object *src_pobj,
666 struct md_object *tgt_pobj,
667 const struct lu_fid *lf,
668 const struct lu_name *lsname,
669 struct md_object *tobj,
670 const struct lu_name *ltname,
676 static int dot_lustre_mdd_link(const struct lu_env *env,
677 struct md_object *tgt_obj,
678 struct md_object *src_obj,
679 const struct lu_name *lname,
685 static int dot_lustre_mdd_unlink(const struct lu_env *env,
686 struct md_object *pobj,
687 struct md_object *cobj,
688 const struct lu_name *lname,
694 static int dot_lustre_mdd_name_insert(const struct lu_env *env,
695 struct md_object *obj,
696 const struct lu_name *lname,
697 const struct lu_fid *fid,
698 const struct md_attr *ma)
703 static int dot_lustre_mdd_name_remove(const struct lu_env *env,
704 struct md_object *obj,
705 const struct lu_name *lname,
706 const struct md_attr *ma)
711 static int dot_lustre_mdd_rename_tgt(const struct lu_env *env,
712 struct md_object *pobj,
713 struct md_object *tobj,
714 const struct lu_fid *fid,
715 const struct lu_name *lname,
722 static struct md_dir_operations mdd_dot_lustre_dir_ops = {
723 .mdo_is_subdir = mdd_is_subdir,
724 .mdo_lookup = dot_lustre_mdd_lookup,
725 .mdo_lock_mode = dot_lustre_mdd_lock_mode,
726 .mdo_create = dot_lustre_mdd_create,
727 .mdo_create_data = dot_lustre_mdd_create_data,
728 .mdo_rename = dot_lustre_mdd_rename,
729 .mdo_link = dot_lustre_mdd_link,
730 .mdo_unlink = dot_lustre_mdd_unlink,
731 .mdo_name_insert = dot_lustre_mdd_name_insert,
732 .mdo_name_remove = dot_lustre_mdd_name_remove,
733 .mdo_rename_tgt = dot_lustre_mdd_rename_tgt,
736 static int obf_attr_get(const struct lu_env *env, struct md_object *obj,
741 if (ma->ma_need & MA_INODE) {
742 struct mdd_device *mdd = mdo2mdd(obj);
744 /* "fid" is a virtual object and hence does not have any "real"
745 * attributes. So we reuse attributes of .lustre for "fid" dir */
746 ma->ma_need |= MA_INODE;
747 rc = mdd_attr_get(env, &mdd->mdd_dot_lustre->mod_obj, ma);
750 ma->ma_valid |= MA_INODE;
753 /* "fid" directory does not have any striping information. */
754 if (ma->ma_need & MA_LOV) {
755 struct mdd_object *mdd_obj = md2mdd_obj(obj);
757 if (ma->ma_valid & MA_LOV)
760 if (!(S_ISREG(mdd_object_type(mdd_obj)) ||
761 S_ISDIR(mdd_object_type(mdd_obj))))
764 if (ma->ma_need & MA_LOV_DEF) {
765 rc = mdd_get_default_md(mdd_obj, ma->ma_lmm);
767 ma->ma_lmm_size = rc;
768 ma->ma_valid |= MA_LOV;
777 static int obf_attr_set(const struct lu_env *env, struct md_object *obj,
778 const struct md_attr *ma)
783 static int obf_xattr_list(const struct lu_env *env,
784 struct md_object *obj, struct lu_buf *buf)
789 static int obf_xattr_get(const struct lu_env *env,
790 struct md_object *obj, struct lu_buf *buf,
796 static int obf_xattr_set(const struct lu_env *env,
797 struct md_object *obj,
798 const struct lu_buf *buf, const char *name,
804 static int obf_xattr_del(const struct lu_env *env,
805 struct md_object *obj,
811 static int obf_mdd_open(const struct lu_env *env, struct md_object *obj,
814 struct mdd_object *mdd_obj = md2mdd_obj(obj);
816 mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD);
817 mdd_obj->mod_count++;
818 mdd_write_unlock(env, mdd_obj);
823 static int obf_mdd_close(const struct lu_env *env, struct md_object *obj,
824 struct md_attr *ma, int mode)
826 struct mdd_object *mdd_obj = md2mdd_obj(obj);
828 mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD);
829 mdd_obj->mod_count--;
830 mdd_write_unlock(env, mdd_obj);
835 /** Nothing to list in "fid" directory */
836 static int obf_mdd_readpage(const struct lu_env *env, struct md_object *obj,
837 const struct lu_rdpg *rdpg)
842 static int obf_path(const struct lu_env *env, struct md_object *obj,
843 char *path, int pathlen, __u64 *recno, int *linkno)
848 static struct md_object_operations mdd_obf_obj_ops = {
849 .moo_attr_get = obf_attr_get,
850 .moo_attr_set = obf_attr_set,
851 .moo_xattr_list = obf_xattr_list,
852 .moo_xattr_get = obf_xattr_get,
853 .moo_xattr_set = obf_xattr_set,
854 .moo_xattr_del = obf_xattr_del,
855 .moo_open = obf_mdd_open,
856 .moo_close = obf_mdd_close,
857 .moo_readpage = obf_mdd_readpage,
862 * Lookup method for "fid" object. Only filenames with correct SEQ:OID format
863 * are valid. We also check if object with passed fid exists or not.
865 static int obf_lookup(const struct lu_env *env, struct md_object *p,
866 const struct lu_name *lname, struct lu_fid *f,
867 struct md_op_spec *spec)
869 char *name = (char *)lname->ln_name;
870 struct mdd_device *mdd = mdo2mdd(p);
871 struct mdd_object *child;
877 sscanf(name, SFID, RFID(f));
878 if (!fid_is_sane(f)) {
879 CWARN("%s: bad FID format [%s], should be "DFID"\n",
880 mdd->mdd_obd_dev->obd_name, lname->ln_name,
881 (__u64)FID_SEQ_NORMAL, 1, 0);
882 GOTO(out, rc = -EINVAL);
885 if (!fid_is_norm(f)) {
886 CWARN("%s: "DFID" is invalid, sequence should be "
887 ">= "LPX64"\n", mdd->mdd_obd_dev->obd_name, PFID(f),
888 (__u64)FID_SEQ_NORMAL);
889 GOTO(out, rc = -EINVAL);
892 /* Check if object with this fid exists */
893 child = mdd_object_find(env, mdd, f);
897 GOTO(out, rc = PTR_ERR(child));
899 if (mdd_object_exists(child) == 0)
902 mdd_object_put(env, child);
908 static int obf_create(const struct lu_env *env, struct md_object *pobj,
909 const struct lu_name *lname, struct md_object *child,
910 struct md_op_spec *spec, struct md_attr* ma)
915 static int obf_rename(const struct lu_env *env,
916 struct md_object *src_pobj, struct md_object *tgt_pobj,
917 const struct lu_fid *lf, const struct lu_name *lsname,
918 struct md_object *tobj, const struct lu_name *ltname,
924 static int obf_link(const struct lu_env *env, struct md_object *tgt_obj,
925 struct md_object *src_obj, const struct lu_name *lname,
931 static int obf_unlink(const struct lu_env *env, struct md_object *pobj,
932 struct md_object *cobj, const struct lu_name *lname,
938 static struct md_dir_operations mdd_obf_dir_ops = {
939 .mdo_lookup = obf_lookup,
940 .mdo_create = obf_create,
941 .mdo_rename = obf_rename,
942 .mdo_link = obf_link,
943 .mdo_unlink = obf_unlink
947 * Create special in-memory "fid" object for open-by-fid.
949 static int mdd_obf_setup(const struct lu_env *env, struct mdd_device *m)
951 struct mdd_object *mdd_obf;
952 struct lu_object *obf_lu_obj;
955 m->mdd_dot_lustre_objs.mdd_obf = mdd_object_find(env, m,
957 if (m->mdd_dot_lustre_objs.mdd_obf == NULL ||
958 IS_ERR(m->mdd_dot_lustre_objs.mdd_obf))
959 GOTO(out, rc = -ENOENT);
961 mdd_obf = m->mdd_dot_lustre_objs.mdd_obf;
962 mdd_obf->mod_obj.mo_dir_ops = &mdd_obf_dir_ops;
963 mdd_obf->mod_obj.mo_ops = &mdd_obf_obj_ops;
964 /* Don't allow objects to be created in "fid" dir */
965 mdd_obf->mod_flags |= IMMUTE_OBJ;
967 obf_lu_obj = mdd2lu_obj(mdd_obf);
968 obf_lu_obj->lo_header->loh_attr |= (LOHA_EXISTS | S_IFDIR);
974 /** Setup ".lustre" directory object */
975 static int mdd_dot_lustre_setup(const struct lu_env *env, struct mdd_device *m)
977 struct dt_object *dt_dot_lustre;
978 struct lu_fid *fid = &mdd_env_info(env)->mti_fid;
981 rc = create_dot_lustre_dir(env, m);
985 dt_dot_lustre = dt_store_open(env, m->mdd_child, mdd_root_dir_name,
986 dot_lustre_name, fid);
987 if (IS_ERR(dt_dot_lustre)) {
988 rc = PTR_ERR(dt_dot_lustre);
992 /* references are released in mdd_device_shutdown() */
993 m->mdd_dot_lustre = lu2mdd_obj(lu_object_locate(dt_dot_lustre->do_lu.lo_header,
996 m->mdd_dot_lustre->mod_obj.mo_dir_ops = &mdd_dot_lustre_dir_ops;
997 m->mdd_dot_lustre->mod_obj.mo_ops = &mdd_dot_lustre_obj_ops;
999 rc = mdd_obf_setup(env, m);
1001 CERROR("Error initializing \"fid\" object - %d.\n", rc);
1007 static int mdd_process_config(const struct lu_env *env,
1008 struct lu_device *d, struct lustre_cfg *cfg)
1010 struct mdd_device *m = lu2mdd_dev(d);
1011 struct dt_device *dt = m->mdd_child;
1012 struct lu_device *next = &dt->dd_lu_dev;
1016 switch (cfg->lcfg_command) {
1018 struct lprocfs_static_vars lvars;
1020 lprocfs_mdd_init_vars(&lvars);
1021 rc = class_process_proc_param(PARAM_MDD, lvars.obd_vars, cfg,m);
1022 if (rc > 0 || rc == -ENOSYS)
1023 /* we don't understand; pass it on */
1024 rc = next->ld_ops->ldo_process_config(env, next, cfg);
1028 rc = next->ld_ops->ldo_process_config(env, next, cfg);
1031 dt->dd_ops->dt_conf_get(env, dt, &m->mdd_dt_conf);
1033 rc = mdd_init_obd(env, m, cfg);
1035 CERROR("lov init error %d\n", rc);
1039 mdd_changelog_init(env, m);
1042 lu_dev_del_linkage(d->ld_site, d);
1043 mdd_device_shutdown(env, m, cfg);
1045 rc = next->ld_ops->ldo_process_config(env, next, cfg);
1053 static int mdd_lov_set_nextid(const struct lu_env *env,
1054 struct mdd_device *mdd)
1056 struct mds_obd *mds = &mdd->mdd_obd_dev->u.mds;
1060 LASSERT(mds->mds_lov_objids != NULL);
1061 rc = obd_set_info_async(mds->mds_lov_exp, strlen(KEY_NEXT_ID),
1062 KEY_NEXT_ID, mds->mds_lov_desc.ld_tgt_count,
1063 mds->mds_lov_objids, NULL);
1068 static int mdd_cleanup_unlink_llog(const struct lu_env *env,
1069 struct mdd_device *mdd)
1071 /* XXX: to be implemented! */
1076 static int mdd_recovery_complete(const struct lu_env *env,
1077 struct lu_device *d)
1079 struct mdd_device *mdd = lu2mdd_dev(d);
1080 struct lu_device *next = &mdd->mdd_child->dd_lu_dev;
1081 struct obd_device *obd = mdd2obd_dev(mdd);
1085 LASSERT(mdd != NULL);
1086 LASSERT(obd != NULL);
1088 /* XXX: Do we need this in new stack? */
1089 rc = mdd_lov_set_nextid(env, mdd);
1091 CERROR("mdd_lov_set_nextid() failed %d\n",
1096 /* XXX: cleanup unlink. */
1097 rc = mdd_cleanup_unlink_llog(env, mdd);
1099 CERROR("mdd_cleanup_unlink_llog() failed %d\n",
1104 /* Call that with obd_recovering = 1 just to update objids */
1105 obd_notify(obd->u.mds.mds_lov_obd, NULL, (obd->obd_async_recov ?
1106 OBD_NOTIFY_SYNC_NONBLOCK : OBD_NOTIFY_SYNC), NULL);
1108 /* Drop obd_recovering to 0 and call o_postrecov to recover mds_lov */
1109 cfs_spin_lock(&obd->obd_dev_lock);
1110 obd->obd_recovering = 0;
1111 cfs_spin_unlock(&obd->obd_dev_lock);
1112 obd->obd_type->typ_dt_ops->o_postrecov(obd);
1114 /* XXX: orphans handling. */
1115 __mdd_orphan_cleanup(env, mdd);
1116 rc = next->ld_ops->ldo_recovery_complete(env, next);
1121 static int mdd_prepare(const struct lu_env *env,
1122 struct lu_device *pdev,
1123 struct lu_device *cdev)
1125 struct mdd_device *mdd = lu2mdd_dev(cdev);
1126 struct lu_device *next = &mdd->mdd_child->dd_lu_dev;
1127 struct dt_object *root;
1132 rc = next->ld_ops->ldo_prepare(env, cdev, next);
1136 dt_txn_callback_add(mdd->mdd_child, &mdd->mdd_txn_cb);
1137 root = dt_store_open(env, mdd->mdd_child, "", mdd_root_dir_name,
1138 &mdd->mdd_root_fid);
1139 if (!IS_ERR(root)) {
1140 LASSERT(root != NULL);
1141 lu_object_put(env, &root->do_lu);
1142 rc = orph_index_init(env, mdd);
1149 rc = mdd_dot_lustre_setup(env, mdd);
1151 CERROR("Error(%d) initializing .lustre objects\n", rc);
1155 /* we use capa file to declare llog changes,
1156 * will be fixed with new llog in 2.3 */
1157 root = dt_store_open(env, mdd->mdd_child, "", CAPA_KEYS, &fid);
1159 GOTO(out, rc = PTR_ERR(root));
1161 mdd->mdd_capa = root;
1162 rc = mdd_lfsck_setup(env, mdd);
1170 const struct lu_device_operations mdd_lu_ops = {
1171 .ldo_object_alloc = mdd_object_alloc,
1172 .ldo_process_config = mdd_process_config,
1173 .ldo_recovery_complete = mdd_recovery_complete,
1174 .ldo_prepare = mdd_prepare,
1178 * No permission check is needed.
1180 static int mdd_root_get(const struct lu_env *env,
1181 struct md_device *m, struct lu_fid *f)
1183 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1186 *f = mdd->mdd_root_fid;
1191 * No permission check is needed.
1193 static int mdd_statfs(const struct lu_env *env, struct md_device *m,
1194 struct obd_statfs *sfs)
1196 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1201 rc = mdd_child_ops(mdd)->dt_statfs(env, mdd->mdd_child, sfs);
1207 * No permission check is needed.
1209 static int mdd_maxsize_get(const struct lu_env *env, struct md_device *m,
1210 int *md_size, int *cookie_size)
1212 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1215 *md_size = mdd_lov_mdsize(env, mdd);
1216 *cookie_size = mdd_lov_cookiesize(env, mdd);
1221 static int mdd_init_capa_ctxt(const struct lu_env *env, struct md_device *m,
1222 int mode, unsigned long timeout, __u32 alg,
1223 struct lustre_capa_key *keys)
1225 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1226 struct mds_obd *mds = &mdd2obd_dev(mdd)->u.mds;
1230 /* need barrier for mds_capa_keys access. */
1231 cfs_down_write(&mds->mds_notify_lock);
1232 mds->mds_capa_keys = keys;
1233 cfs_up_write(&mds->mds_notify_lock);
1235 rc = mdd_child_ops(mdd)->dt_init_capa_ctxt(env, mdd->mdd_child, mode,
1236 timeout, alg, keys);
1240 static int mdd_update_capa_key(const struct lu_env *env,
1241 struct md_device *m,
1242 struct lustre_capa_key *key)
1244 struct mds_capa_info info = { .uuid = NULL, .capa = key };
1245 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1246 struct obd_export *lov_exp = mdd2obd_dev(mdd)->u.mds.mds_lov_exp;
1250 rc = obd_set_info_async(env, lov_exp, sizeof(KEY_CAPA_KEY),
1251 KEY_CAPA_KEY, sizeof(info), &info, NULL);
1255 static int mdd_llog_ctxt_get(const struct lu_env *env, struct md_device *m,
1258 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1260 *h = llog_group_get_ctxt(&mdd2obd_dev(mdd)->obd_olg, idx);
1261 return (*h == NULL ? -ENOENT : 0);
1264 static struct lu_device *mdd_device_alloc(const struct lu_env *env,
1265 struct lu_device_type *t,
1266 struct lustre_cfg *lcfg)
1268 struct lu_device *l;
1269 struct mdd_device *m;
1273 l = ERR_PTR(-ENOMEM);
1275 md_device_init(&m->mdd_md_dev, t);
1277 l->ld_ops = &mdd_lu_ops;
1278 m->mdd_md_dev.md_ops = &mdd_ops;
1279 md_upcall_init(&m->mdd_md_dev, NULL);
1285 static struct lu_device *mdd_device_free(const struct lu_env *env,
1286 struct lu_device *lu)
1288 struct mdd_device *m = lu2mdd_dev(lu);
1291 LASSERT(cfs_atomic_read(&lu->ld_ref) == 0);
1292 md_device_fini(&m->mdd_md_dev);
1297 static struct obd_ops mdd_obd_device_ops = {
1298 .o_owner = THIS_MODULE
1301 /* context key constructor/destructor: mdd_ucred_key_init, mdd_ucred_key_fini */
1302 LU_KEY_INIT_FINI(mdd_ucred, struct md_ucred);
1304 static struct lu_context_key mdd_ucred_key = {
1305 .lct_tags = LCT_SESSION,
1306 .lct_init = mdd_ucred_key_init,
1307 .lct_fini = mdd_ucred_key_fini
1310 struct md_ucred *md_ucred(const struct lu_env *env)
1312 LASSERT(env->le_ses != NULL);
1313 return lu_context_key_get(env->le_ses, &mdd_ucred_key);
1315 EXPORT_SYMBOL(md_ucred);
1318 * context key constructor/destructor:
1319 * mdd_capainfo_key_init, mdd_capainfo_key_fini
1321 LU_KEY_INIT_FINI(mdd_capainfo, struct md_capainfo);
1323 struct lu_context_key mdd_capainfo_key = {
1324 .lct_tags = LCT_SESSION,
1325 .lct_init = mdd_capainfo_key_init,
1326 .lct_fini = mdd_capainfo_key_fini
1329 struct md_capainfo *md_capainfo(const struct lu_env *env)
1331 /* NB, in mdt_init0 */
1332 if (env->le_ses == NULL)
1334 return lu_context_key_get(env->le_ses, &mdd_capainfo_key);
1336 EXPORT_SYMBOL(md_capainfo);
1339 * context key constructor/destructor:
1340 * mdd_quota_key_init, mdd_quota_key_fini
1342 LU_KEY_INIT_FINI(mdd_quota, struct md_quota);
1344 struct lu_context_key mdd_quota_key = {
1345 .lct_tags = LCT_SESSION,
1346 .lct_init = mdd_quota_key_init,
1347 .lct_fini = mdd_quota_key_fini
1350 struct md_quota *md_quota(const struct lu_env *env)
1352 LASSERT(env->le_ses != NULL);
1353 return lu_context_key_get(env->le_ses, &mdd_quota_key);
1355 EXPORT_SYMBOL(md_quota);
1357 static int mdd_changelog_user_register(struct mdd_device *mdd, int *id)
1359 struct llog_ctxt *ctxt;
1360 struct llog_changelog_user_rec *rec;
1364 ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
1370 llog_ctxt_put(ctxt);
1374 /* Assume we want it on since somebody registered */
1375 rc = mdd_changelog_on(mdd, 1);
1379 rec->cur_hdr.lrh_len = sizeof(*rec);
1380 rec->cur_hdr.lrh_type = CHANGELOG_USER_REC;
1381 cfs_spin_lock(&mdd->mdd_cl.mc_user_lock);
1382 if (mdd->mdd_cl.mc_lastuser == (unsigned int)(-1)) {
1383 cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
1384 CERROR("Maximum number of changelog users exceeded!\n");
1385 GOTO(out, rc = -EOVERFLOW);
1387 *id = rec->cur_id = ++mdd->mdd_cl.mc_lastuser;
1388 rec->cur_endrec = mdd->mdd_cl.mc_index;
1389 cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
1391 rc = llog_add(NULL, ctxt, &rec->cur_hdr, NULL, NULL, 0);
1393 CDEBUG(D_IOCTL, "Registered changelog user %d\n", *id);
1396 llog_ctxt_put(ctxt);
1400 int mdd_declare_llog_cancel(const struct lu_env *env, struct mdd_device *mdd,
1401 struct thandle *handle)
1406 /* XXX: this is a temporary solution to declare llog changes
1407 * will be fixed in 2.3 with new llog implementation */
1409 LASSERT(mdd->mdd_capa);
1411 /* the llog record could be canceled either by modifying
1412 * the plain llog's header or by destroying the llog itself
1413 * when this record is the last one in it, it can't be known
1414 * here, but the catlog's header will also be modified for
1415 * the second case, then the first case can be covered and
1416 * is no need to declare it */
1418 /* destroy empty plain log */
1419 rc = dt_declare_destroy(env, mdd->mdd_capa, handle);
1423 /* record the catlog's header if an empty plain log was destroyed */
1424 rc = dt_declare_record_write(env, mdd->mdd_capa,
1425 sizeof(struct llog_logid_rec), 0, handle);
1429 struct mdd_changelog_user_data {
1430 __u64 mcud_endrec; /**< purge record for this user */
1431 __u64 mcud_minrec; /**< lowest changelog recno still referenced */
1433 __u32 mcud_minid; /**< user id with lowest rec reference */
1434 __u32 mcud_usercount;
1436 struct mdd_device *mcud_mdd;
1438 #define MCUD_UNREGISTER -1LL
1441 * 1. Find the smallest record everyone is willing to purge
1442 * 2. Update the last purgeable record for this user
1444 static int mdd_changelog_user_purge_cb(const struct lu_env *env,
1445 struct llog_handle *llh,
1446 struct llog_rec_hdr *hdr, void *data)
1448 struct llog_changelog_user_rec *rec;
1449 struct mdd_changelog_user_data *mcud = data;
1454 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
1456 rec = (struct llog_changelog_user_rec *)hdr;
1458 mcud->mcud_usercount++;
1460 /* If we have a new endrec for this id, use it for the following
1461 min check instead of its old value */
1462 if (rec->cur_id == mcud->mcud_id)
1463 rec->cur_endrec = max(rec->cur_endrec, mcud->mcud_endrec);
1465 /* Track the minimum referenced record */
1466 if (mcud->mcud_minid == 0 || mcud->mcud_minrec > rec->cur_endrec) {
1467 mcud->mcud_minid = rec->cur_id;
1468 mcud->mcud_minrec = rec->cur_endrec;
1471 if (rec->cur_id != mcud->mcud_id)
1474 /* Update this user's record */
1475 mcud->mcud_found = 1;
1477 /* Special case: unregister this user */
1478 if (mcud->mcud_endrec == MCUD_UNREGISTER) {
1479 struct llog_cookie cookie;
1481 struct mdd_device *mdd = mcud->mcud_mdd;
1483 cookie.lgc_lgl = llh->lgh_id;
1484 cookie.lgc_index = hdr->lrh_index;
1486 /* XXX This is a workaround for the deadlock of changelog
1487 * adding vs. changelog cancelling. LU-81. */
1488 th = mdd_trans_create(env, mdd);
1490 CERROR("Cannot get thandle\n");
1494 rc = mdd_declare_llog_cancel(env, mdd, th);
1498 rc = mdd_trans_start(env, mdd, th);
1502 rc = llog_cat_cancel_records(env, llh->u.phd.phd_cat_handle,
1505 mcud->mcud_usercount--;
1508 mdd_trans_stop(env, mdd, 0, th);
1512 /* Update the endrec */
1513 CDEBUG(D_IOCTL, "Rewriting changelog user %d endrec to "LPU64"\n",
1514 mcud->mcud_id, rec->cur_endrec);
1516 /* hdr+1 is loc of data */
1517 hdr->lrh_len -= sizeof(*hdr) + sizeof(struct llog_rec_tail);
1518 rc = llog_write_rec(env, llh, hdr, NULL, 0, (void *)(hdr + 1),
1524 static int mdd_changelog_user_purge(const struct lu_env *env,
1525 struct mdd_device *mdd, int id,
1528 struct mdd_changelog_user_data data;
1529 struct llog_ctxt *ctxt;
1533 CDEBUG(D_IOCTL, "Purge request: id=%d, endrec=%lld\n", id, endrec);
1536 data.mcud_minid = 0;
1537 data.mcud_minrec = 0;
1538 data.mcud_usercount = 0;
1539 data.mcud_endrec = endrec;
1540 data.mcud_mdd = mdd;
1541 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
1542 endrec = mdd->mdd_cl.mc_index;
1543 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
1544 if ((data.mcud_endrec == 0) ||
1545 ((data.mcud_endrec > endrec) &&
1546 (data.mcud_endrec != MCUD_UNREGISTER)))
1547 data.mcud_endrec = endrec;
1549 ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
1552 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
1554 rc = llog_cat_process(env, ctxt->loc_handle,
1555 mdd_changelog_user_purge_cb, (void *)&data,
1557 if ((rc >= 0) && (data.mcud_minrec > 0)) {
1558 CDEBUG(D_IOCTL, "Purging changelog entries up to "LPD64
1559 ", referenced by "CHANGELOG_USER_PREFIX"%d\n",
1560 data.mcud_minrec, data.mcud_minid);
1561 rc = mdd_changelog_llog_cancel(env, mdd, data.mcud_minrec);
1563 CWARN("Could not determine changelog records to purge; rc=%d\n",
1567 llog_ctxt_put(ctxt);
1569 if (!data.mcud_found) {
1570 CWARN("No entry for user %d. Last changelog reference is "
1571 LPD64" by changelog user %d\n", data.mcud_id,
1572 data.mcud_minrec, data.mcud_minid);
1576 if (!rc && data.mcud_usercount == 0)
1577 /* No more users; turn changelogs off */
1578 rc = mdd_changelog_on(mdd, 0);
1584 * May be called remotely from mdt_iocontrol_handle or locally from
1585 * mdt_iocontrol. Data may be freeform - remote handling doesn't enforce
1586 * an obd_ioctl_data format (but local ioctl handler does).
1588 * \param len - data len
1589 * \param karg - ioctl data, in kernel space
1591 static int mdd_iocontrol(const struct lu_env *env, struct md_device *m,
1592 unsigned int cmd, int len, void *karg)
1594 struct mdd_device *mdd;
1595 struct obd_ioctl_data *data = karg;
1599 mdd = lu2mdd_dev(&m->md_lu_dev);
1601 /* Doesn't use obd_ioctl_data */
1603 case OBD_IOC_CHANGELOG_CLEAR: {
1604 struct changelog_setinfo *cs = karg;
1605 rc = mdd_changelog_user_purge(env, mdd, cs->cs_id,
1609 case OBD_IOC_GET_MNTOPT: {
1610 mntopt_t *mntopts = (mntopt_t *)karg;
1611 *mntopts = mdd->mdd_dt_conf.ddp_mntopts;
1614 case OBD_IOC_START_LFSCK: {
1615 struct lfsck_start *start = karg;
1616 struct md_lfsck *lfsck = &mdd->mdd_lfsck;
1618 /* Return the kernel service version. */
1619 /* XXX: version can be used for compatibility in the future. */
1620 start->ls_version = lfsck->ml_version;
1621 rc = mdd_lfsck_start(env, lfsck, start);
1624 case OBD_IOC_STOP_LFSCK: {
1625 rc = mdd_lfsck_stop(env, &mdd->mdd_lfsck);
1630 /* Below ioctls use obd_ioctl_data */
1631 if (len != sizeof(*data)) {
1632 CERROR("Bad ioctl size %d\n", len);
1635 if (data->ioc_version != OBD_IOCTL_VERSION) {
1636 CERROR("Bad magic %x != %x\n", data->ioc_version,
1642 case OBD_IOC_CHANGELOG_REG:
1643 rc = mdd_changelog_user_register(mdd, &data->ioc_u32_1);
1645 case OBD_IOC_CHANGELOG_DEREG:
1646 rc = mdd_changelog_user_purge(env, mdd, data->ioc_u32_1,
1656 /* type constructor/destructor: mdd_type_init, mdd_type_fini */
1657 LU_TYPE_INIT_FINI(mdd, &mdd_thread_key, &mdd_ucred_key, &mdd_capainfo_key,
1660 const struct md_device_operations mdd_ops = {
1661 .mdo_statfs = mdd_statfs,
1662 .mdo_root_get = mdd_root_get,
1663 .mdo_maxsize_get = mdd_maxsize_get,
1664 .mdo_init_capa_ctxt = mdd_init_capa_ctxt,
1665 .mdo_update_capa_key= mdd_update_capa_key,
1666 .mdo_llog_ctxt_get = mdd_llog_ctxt_get,
1667 .mdo_iocontrol = mdd_iocontrol,
1668 #ifdef HAVE_QUOTA_SUPPORT
1670 .mqo_notify = mdd_quota_notify,
1671 .mqo_setup = mdd_quota_setup,
1672 .mqo_cleanup = mdd_quota_cleanup,
1673 .mqo_recovery = mdd_quota_recovery,
1674 .mqo_check = mdd_quota_check,
1675 .mqo_on = mdd_quota_on,
1676 .mqo_off = mdd_quota_off,
1677 .mqo_setinfo = mdd_quota_setinfo,
1678 .mqo_getinfo = mdd_quota_getinfo,
1679 .mqo_setquota = mdd_quota_setquota,
1680 .mqo_getquota = mdd_quota_getquota,
1681 .mqo_getoinfo = mdd_quota_getoinfo,
1682 .mqo_getoquota = mdd_quota_getoquota,
1683 .mqo_invalidate = mdd_quota_invalidate,
1684 .mqo_finvalidate = mdd_quota_finvalidate
1689 static struct lu_device_type_operations mdd_device_type_ops = {
1690 .ldto_init = mdd_type_init,
1691 .ldto_fini = mdd_type_fini,
1693 .ldto_start = mdd_type_start,
1694 .ldto_stop = mdd_type_stop,
1696 .ldto_device_alloc = mdd_device_alloc,
1697 .ldto_device_free = mdd_device_free,
1699 .ldto_device_init = mdd_device_init,
1700 .ldto_device_fini = mdd_device_fini
1703 static struct lu_device_type mdd_device_type = {
1704 .ldt_tags = LU_DEVICE_MD,
1705 .ldt_name = LUSTRE_MDD_NAME,
1706 .ldt_ops = &mdd_device_type_ops,
1707 .ldt_ctx_tags = LCT_MD_THREAD
1710 /* context key constructor: mdd_key_init */
1711 LU_KEY_INIT(mdd, struct mdd_thread_info);
1713 static void mdd_key_fini(const struct lu_context *ctx,
1714 struct lu_context_key *key, void *data)
1716 struct mdd_thread_info *info = data;
1717 if (info->mti_max_lmm != NULL)
1718 OBD_FREE(info->mti_max_lmm, info->mti_max_lmm_size);
1719 if (info->mti_max_cookie != NULL)
1720 OBD_FREE(info->mti_max_cookie, info->mti_max_cookie_size);
1721 mdd_buf_put(&info->mti_big_buf);
1726 /* context key: mdd_thread_key */
1727 LU_CONTEXT_KEY_DEFINE(mdd, LCT_MD_THREAD);
1729 static struct lu_local_obj_desc llod_capa_key = {
1730 .llod_name = CAPA_KEYS,
1731 .llod_oid = MDD_CAPA_KEYS_OID,
1735 static struct lu_local_obj_desc llod_mdd_orphan = {
1736 .llod_name = orph_index_name,
1737 .llod_oid = MDD_ORPHAN_OID,
1739 .llod_feat = &dt_directory_features,
1742 static struct lu_local_obj_desc llod_mdd_root = {
1743 .llod_name = mdd_root_dir_name,
1744 .llod_oid = MDD_ROOT_INDEX_OID,
1746 .llod_feat = &dt_directory_features,
1749 static struct lu_local_obj_desc llod_lfsck_bookmark = {
1750 .llod_name = lfsck_bookmark_name,
1751 .llod_oid = LFSCK_BOOKMARK_OID,
1755 static int __init mdd_mod_init(void)
1757 struct lprocfs_static_vars lvars;
1760 lprocfs_mdd_init_vars(&lvars);
1762 rc = lu_kmem_init(mdd_caches);
1766 llo_local_obj_register(&llod_capa_key);
1767 llo_local_obj_register(&llod_mdd_orphan);
1768 llo_local_obj_register(&llod_mdd_root);
1769 llo_local_obj_register(&llod_lfsck_bookmark);
1771 rc = class_register_type(&mdd_obd_device_ops, NULL, lvars.module_vars,
1772 LUSTRE_MDD_NAME, &mdd_device_type);
1774 lu_kmem_fini(mdd_caches);
1778 static void __exit mdd_mod_exit(void)
1780 llo_local_obj_unregister(&llod_capa_key);
1781 llo_local_obj_unregister(&llod_mdd_orphan);
1782 llo_local_obj_unregister(&llod_mdd_root);
1783 llo_local_obj_unregister(&llod_lfsck_bookmark);
1785 class_unregister_type(LUSTRE_MDD_NAME);
1786 lu_kmem_fini(mdd_caches);
1789 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1790 MODULE_DESCRIPTION("Lustre Meta-data Device Prototype ("LUSTRE_MDD_NAME")");
1791 MODULE_LICENSE("GPL");
1793 cfs_module(mdd, "0.1.0", mdd_mod_init, mdd_mod_exit);