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_obd_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_obd_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,
739 struct mdd_device *mdd = mdo2mdd(obj);
741 /* "fid" is a virtual object and hence does not have any "real"
742 * attributes. So we reuse attributes of .lustre for "fid" dir */
743 return mdd_attr_get(env, &mdd->mdd_dot_lustre->mod_obj, ma);
746 static int obf_attr_set(const struct lu_env *env, struct md_object *obj,
747 const struct md_attr *ma)
752 static int obf_xattr_list(const struct lu_env *env,
753 struct md_object *obj, struct lu_buf *buf)
758 static int obf_xattr_get(const struct lu_env *env,
759 struct md_object *obj, struct lu_buf *buf,
764 /* XXX: a temp. solution till LOD/OSP is landed */
765 if (strcmp(name, XATTR_NAME_LOV) == 0) {
766 if (buf->lb_buf == NULL) {
767 rc = sizeof(struct lov_user_md);
768 } else if (buf->lb_len >= sizeof(struct lov_user_md)) {
769 rc = mdd_get_default_md(md2mdd_obj(obj), buf->lb_buf);
778 static int obf_xattr_set(const struct lu_env *env,
779 struct md_object *obj,
780 const struct lu_buf *buf, const char *name,
786 static int obf_xattr_del(const struct lu_env *env,
787 struct md_object *obj,
793 static int obf_mdd_open(const struct lu_env *env, struct md_object *obj,
796 struct mdd_object *mdd_obj = md2mdd_obj(obj);
798 mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD);
799 mdd_obj->mod_count++;
800 mdd_write_unlock(env, mdd_obj);
805 static int obf_mdd_close(const struct lu_env *env, struct md_object *obj,
806 struct md_attr *ma, int mode)
808 struct mdd_object *mdd_obj = md2mdd_obj(obj);
810 mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD);
811 mdd_obj->mod_count--;
812 mdd_write_unlock(env, mdd_obj);
817 /** Nothing to list in "fid" directory */
818 static int obf_mdd_readpage(const struct lu_env *env, struct md_object *obj,
819 const struct lu_rdpg *rdpg)
824 static int obf_path(const struct lu_env *env, struct md_object *obj,
825 char *path, int pathlen, __u64 *recno, int *linkno)
830 static struct md_object_operations mdd_obf_obj_ops = {
831 .moo_attr_get = obf_attr_get,
832 .moo_attr_set = obf_attr_set,
833 .moo_xattr_list = obf_xattr_list,
834 .moo_xattr_get = obf_xattr_get,
835 .moo_xattr_set = obf_xattr_set,
836 .moo_xattr_del = obf_xattr_del,
837 .moo_open = obf_mdd_open,
838 .moo_close = obf_mdd_close,
839 .moo_readpage = obf_mdd_readpage,
844 * Lookup method for "fid" object. Only filenames with correct SEQ:OID format
845 * are valid. We also check if object with passed fid exists or not.
847 static int obf_lookup(const struct lu_env *env, struct md_object *p,
848 const struct lu_name *lname, struct lu_fid *f,
849 struct md_op_spec *spec)
851 char *name = (char *)lname->ln_name;
852 struct mdd_device *mdd = mdo2mdd(p);
853 struct mdd_object *child;
859 sscanf(name, SFID, RFID(f));
860 if (!fid_is_sane(f)) {
861 CWARN("%s: bad FID format [%s], should be "DFID"\n",
862 mdd->mdd_obd_dev->obd_name, lname->ln_name,
863 (__u64)FID_SEQ_NORMAL, 1, 0);
864 GOTO(out, rc = -EINVAL);
867 if (!fid_is_norm(f)) {
868 CWARN("%s: "DFID" is invalid, sequence should be "
869 ">= "LPX64"\n", mdd->mdd_obd_dev->obd_name, PFID(f),
870 (__u64)FID_SEQ_NORMAL);
871 GOTO(out, rc = -EINVAL);
874 /* Check if object with this fid exists */
875 child = mdd_object_find(env, mdd, f);
879 GOTO(out, rc = PTR_ERR(child));
881 if (mdd_object_exists(child) == 0)
884 mdd_object_put(env, child);
890 static int obf_create(const struct lu_env *env, struct md_object *pobj,
891 const struct lu_name *lname, struct md_object *child,
892 struct md_op_spec *spec, struct md_attr* ma)
897 static int obf_rename(const struct lu_env *env,
898 struct md_object *src_pobj, struct md_object *tgt_pobj,
899 const struct lu_fid *lf, const struct lu_name *lsname,
900 struct md_object *tobj, const struct lu_name *ltname,
906 static int obf_link(const struct lu_env *env, struct md_object *tgt_obj,
907 struct md_object *src_obj, const struct lu_name *lname,
913 static int obf_unlink(const struct lu_env *env, struct md_object *pobj,
914 struct md_object *cobj, const struct lu_name *lname,
920 static struct md_dir_operations mdd_obf_dir_ops = {
921 .mdo_lookup = obf_lookup,
922 .mdo_create = obf_create,
923 .mdo_rename = obf_rename,
924 .mdo_link = obf_link,
925 .mdo_unlink = obf_unlink
929 * Create special in-memory "fid" object for open-by-fid.
931 static int mdd_obf_setup(const struct lu_env *env, struct mdd_device *m)
933 struct mdd_object *mdd_obf;
934 struct lu_object *obf_lu_obj;
937 m->mdd_dot_lustre_objs.mdd_obf = mdd_object_find(env, m,
939 if (m->mdd_dot_lustre_objs.mdd_obf == NULL ||
940 IS_ERR(m->mdd_dot_lustre_objs.mdd_obf))
941 GOTO(out, rc = -ENOENT);
943 mdd_obf = m->mdd_dot_lustre_objs.mdd_obf;
944 mdd_obf->mod_obj.mo_dir_ops = &mdd_obf_dir_ops;
945 mdd_obf->mod_obj.mo_ops = &mdd_obf_obj_ops;
946 /* Don't allow objects to be created in "fid" dir */
947 mdd_obf->mod_flags |= IMMUTE_OBJ;
949 obf_lu_obj = mdd2lu_obj(mdd_obf);
950 obf_lu_obj->lo_header->loh_attr |= (LOHA_EXISTS | S_IFDIR);
956 /** Setup ".lustre" directory object */
957 static int mdd_dot_lustre_setup(const struct lu_env *env, struct mdd_device *m)
959 struct dt_object *dt_dot_lustre;
960 struct lu_fid *fid = &mdd_env_info(env)->mti_fid;
963 rc = create_dot_lustre_dir(env, m);
967 dt_dot_lustre = dt_store_open(env, m->mdd_child, mdd_root_dir_name,
968 dot_lustre_name, fid);
969 if (IS_ERR(dt_dot_lustre)) {
970 rc = PTR_ERR(dt_dot_lustre);
974 /* references are released in mdd_device_shutdown() */
975 m->mdd_dot_lustre = lu2mdd_obj(lu_object_locate(dt_dot_lustre->do_lu.lo_header,
978 m->mdd_dot_lustre->mod_obj.mo_dir_ops = &mdd_dot_lustre_dir_ops;
979 m->mdd_dot_lustre->mod_obj.mo_ops = &mdd_dot_lustre_obj_ops;
981 rc = mdd_obf_setup(env, m);
983 CERROR("Error initializing \"fid\" object - %d.\n", rc);
989 static int mdd_process_config(const struct lu_env *env,
990 struct lu_device *d, struct lustre_cfg *cfg)
992 struct mdd_device *m = lu2mdd_dev(d);
993 struct dt_device *dt = m->mdd_child;
994 struct lu_device *next = &dt->dd_lu_dev;
998 switch (cfg->lcfg_command) {
1000 struct lprocfs_static_vars lvars;
1002 lprocfs_mdd_init_vars(&lvars);
1003 rc = class_process_proc_param(PARAM_MDD, lvars.obd_vars, cfg,m);
1004 if (rc > 0 || rc == -ENOSYS)
1005 /* we don't understand; pass it on */
1006 rc = next->ld_ops->ldo_process_config(env, next, cfg);
1010 rc = next->ld_ops->ldo_process_config(env, next, cfg);
1013 dt->dd_ops->dt_conf_get(env, dt, &m->mdd_dt_conf);
1015 rc = mdd_init_obd(env, m, cfg);
1017 CERROR("lov init error %d\n", rc);
1021 mdd_changelog_init(env, m);
1024 lu_dev_del_linkage(d->ld_site, d);
1025 mdd_device_shutdown(env, m, cfg);
1027 rc = next->ld_ops->ldo_process_config(env, next, cfg);
1035 static int mdd_lov_set_nextid(const struct lu_env *env,
1036 struct mdd_device *mdd)
1038 struct mds_obd *mds = &mdd->mdd_obd_dev->u.mds;
1042 LASSERT(mds->mds_lov_objids != NULL);
1043 rc = obd_set_info_async(mds->mds_lov_exp, strlen(KEY_NEXT_ID),
1044 KEY_NEXT_ID, mds->mds_lov_desc.ld_tgt_count,
1045 mds->mds_lov_objids, NULL);
1050 static int mdd_cleanup_unlink_llog(const struct lu_env *env,
1051 struct mdd_device *mdd)
1053 /* XXX: to be implemented! */
1058 static int mdd_recovery_complete(const struct lu_env *env,
1059 struct lu_device *d)
1061 struct mdd_device *mdd = lu2mdd_dev(d);
1062 struct lu_device *next = &mdd->mdd_child->dd_lu_dev;
1063 struct obd_device *obd = mdd2obd_dev(mdd);
1067 LASSERT(mdd != NULL);
1068 LASSERT(obd != NULL);
1070 /* XXX: Do we need this in new stack? */
1071 rc = mdd_lov_set_nextid(env, mdd);
1073 CERROR("mdd_lov_set_nextid() failed %d\n",
1078 /* XXX: cleanup unlink. */
1079 rc = mdd_cleanup_unlink_llog(env, mdd);
1081 CERROR("mdd_cleanup_unlink_llog() failed %d\n",
1086 /* Call that with obd_recovering = 1 just to update objids */
1087 obd_notify(obd->u.mds.mds_lov_obd, NULL, (obd->obd_async_recov ?
1088 OBD_NOTIFY_SYNC_NONBLOCK : OBD_NOTIFY_SYNC), NULL);
1090 /* Drop obd_recovering to 0 and call o_postrecov to recover mds_lov */
1091 cfs_spin_lock(&obd->obd_dev_lock);
1092 obd->obd_recovering = 0;
1093 cfs_spin_unlock(&obd->obd_dev_lock);
1094 obd->obd_type->typ_dt_ops->o_postrecov(obd);
1096 /* XXX: orphans handling. */
1097 __mdd_orphan_cleanup(env, mdd);
1098 rc = next->ld_ops->ldo_recovery_complete(env, next);
1103 static int mdd_prepare(const struct lu_env *env,
1104 struct lu_device *pdev,
1105 struct lu_device *cdev)
1107 struct mdd_device *mdd = lu2mdd_dev(cdev);
1108 struct lu_device *next = &mdd->mdd_child->dd_lu_dev;
1109 struct dt_object *root;
1114 rc = next->ld_ops->ldo_prepare(env, cdev, next);
1118 dt_txn_callback_add(mdd->mdd_child, &mdd->mdd_txn_cb);
1119 root = dt_store_open(env, mdd->mdd_child, "", mdd_root_dir_name,
1120 &mdd->mdd_root_fid);
1121 if (!IS_ERR(root)) {
1122 LASSERT(root != NULL);
1123 lu_object_put(env, &root->do_lu);
1124 rc = orph_index_init(env, mdd);
1131 rc = mdd_dot_lustre_setup(env, mdd);
1133 CERROR("Error(%d) initializing .lustre objects\n", rc);
1137 /* we use capa file to declare llog changes,
1138 * will be fixed with new llog in 2.3 */
1139 root = dt_store_open(env, mdd->mdd_child, "", CAPA_KEYS, &fid);
1141 GOTO(out, rc = PTR_ERR(root));
1143 mdd->mdd_capa = root;
1144 rc = mdd_lfsck_setup(env, mdd);
1152 const struct lu_device_operations mdd_lu_ops = {
1153 .ldo_object_alloc = mdd_object_alloc,
1154 .ldo_process_config = mdd_process_config,
1155 .ldo_recovery_complete = mdd_recovery_complete,
1156 .ldo_prepare = mdd_prepare,
1160 * No permission check is needed.
1162 static int mdd_root_get(const struct lu_env *env,
1163 struct md_device *m, struct lu_fid *f)
1165 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1168 *f = mdd->mdd_root_fid;
1173 * No permission check is needed.
1175 static int mdd_statfs(const struct lu_env *env, struct md_device *m,
1176 struct obd_statfs *sfs)
1178 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1183 rc = mdd_child_ops(mdd)->dt_statfs(env, mdd->mdd_child, sfs);
1189 * No permission check is needed.
1191 static int mdd_maxsize_get(const struct lu_env *env, struct md_device *m,
1192 int *md_size, int *cookie_size)
1194 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1197 *md_size = mdd_lov_mdsize(env, mdd);
1198 *cookie_size = mdd_lov_cookiesize(env, mdd);
1203 static int mdd_init_capa_ctxt(const struct lu_env *env, struct md_device *m,
1204 int mode, unsigned long timeout, __u32 alg,
1205 struct lustre_capa_key *keys)
1207 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1208 struct mds_obd *mds = &mdd2obd_dev(mdd)->u.mds;
1212 /* need barrier for mds_capa_keys access. */
1213 cfs_down_write(&mds->mds_notify_lock);
1214 mds->mds_capa_keys = keys;
1215 cfs_up_write(&mds->mds_notify_lock);
1217 rc = mdd_child_ops(mdd)->dt_init_capa_ctxt(env, mdd->mdd_child, mode,
1218 timeout, alg, keys);
1222 static int mdd_update_capa_key(const struct lu_env *env,
1223 struct md_device *m,
1224 struct lustre_capa_key *key)
1226 struct mds_capa_info info = { .uuid = NULL, .capa = key };
1227 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1228 struct obd_export *lov_exp = mdd2obd_dev(mdd)->u.mds.mds_lov_exp;
1232 rc = obd_set_info_async(env, lov_exp, sizeof(KEY_CAPA_KEY),
1233 KEY_CAPA_KEY, sizeof(info), &info, NULL);
1237 static int mdd_llog_ctxt_get(const struct lu_env *env, struct md_device *m,
1240 struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
1242 *h = llog_group_get_ctxt(&mdd2obd_dev(mdd)->obd_olg, idx);
1243 return (*h == NULL ? -ENOENT : 0);
1246 static struct lu_device *mdd_device_alloc(const struct lu_env *env,
1247 struct lu_device_type *t,
1248 struct lustre_cfg *lcfg)
1250 struct lu_device *l;
1251 struct mdd_device *m;
1255 l = ERR_PTR(-ENOMEM);
1257 md_device_init(&m->mdd_md_dev, t);
1259 l->ld_ops = &mdd_lu_ops;
1260 m->mdd_md_dev.md_ops = &mdd_ops;
1261 md_upcall_init(&m->mdd_md_dev, NULL);
1267 static struct lu_device *mdd_device_free(const struct lu_env *env,
1268 struct lu_device *lu)
1270 struct mdd_device *m = lu2mdd_dev(lu);
1273 LASSERT(cfs_atomic_read(&lu->ld_ref) == 0);
1274 md_device_fini(&m->mdd_md_dev);
1279 static struct obd_ops mdd_obd_device_ops = {
1280 .o_owner = THIS_MODULE
1283 /* context key constructor/destructor: mdd_ucred_key_init, mdd_ucred_key_fini */
1284 LU_KEY_INIT_FINI(mdd_ucred, struct md_ucred);
1286 static struct lu_context_key mdd_ucred_key = {
1287 .lct_tags = LCT_SESSION,
1288 .lct_init = mdd_ucred_key_init,
1289 .lct_fini = mdd_ucred_key_fini
1292 struct md_ucred *md_ucred(const struct lu_env *env)
1294 LASSERT(env->le_ses != NULL);
1295 return lu_context_key_get(env->le_ses, &mdd_ucred_key);
1297 EXPORT_SYMBOL(md_ucred);
1300 * context key constructor/destructor:
1301 * mdd_capainfo_key_init, mdd_capainfo_key_fini
1303 LU_KEY_INIT_FINI(mdd_capainfo, struct md_capainfo);
1305 struct lu_context_key mdd_capainfo_key = {
1306 .lct_tags = LCT_SESSION,
1307 .lct_init = mdd_capainfo_key_init,
1308 .lct_fini = mdd_capainfo_key_fini
1311 struct md_capainfo *md_capainfo(const struct lu_env *env)
1313 /* NB, in mdt_init0 */
1314 if (env->le_ses == NULL)
1316 return lu_context_key_get(env->le_ses, &mdd_capainfo_key);
1318 EXPORT_SYMBOL(md_capainfo);
1320 static int mdd_changelog_user_register(struct mdd_device *mdd, int *id)
1322 struct llog_ctxt *ctxt;
1323 struct llog_changelog_user_rec *rec;
1327 ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
1333 llog_ctxt_put(ctxt);
1337 /* Assume we want it on since somebody registered */
1338 rc = mdd_changelog_on(mdd, 1);
1342 rec->cur_hdr.lrh_len = sizeof(*rec);
1343 rec->cur_hdr.lrh_type = CHANGELOG_USER_REC;
1344 cfs_spin_lock(&mdd->mdd_cl.mc_user_lock);
1345 if (mdd->mdd_cl.mc_lastuser == (unsigned int)(-1)) {
1346 cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
1347 CERROR("Maximum number of changelog users exceeded!\n");
1348 GOTO(out, rc = -EOVERFLOW);
1350 *id = rec->cur_id = ++mdd->mdd_cl.mc_lastuser;
1351 rec->cur_endrec = mdd->mdd_cl.mc_index;
1352 cfs_spin_unlock(&mdd->mdd_cl.mc_user_lock);
1354 rc = llog_obd_add(NULL, ctxt, &rec->cur_hdr, NULL, NULL, 0);
1356 CDEBUG(D_IOCTL, "Registered changelog user %d\n", *id);
1359 llog_ctxt_put(ctxt);
1363 int mdd_declare_llog_cancel(const struct lu_env *env, struct mdd_device *mdd,
1364 struct thandle *handle)
1369 /* XXX: this is a temporary solution to declare llog changes
1370 * will be fixed in 2.3 with new llog implementation */
1372 LASSERT(mdd->mdd_capa);
1374 /* the llog record could be canceled either by modifying
1375 * the plain llog's header or by destroying the llog itself
1376 * when this record is the last one in it, it can't be known
1377 * here, but the catlog's header will also be modified for
1378 * the second case, then the first case can be covered and
1379 * is no need to declare it */
1381 /* destroy empty plain log */
1382 rc = dt_declare_destroy(env, mdd->mdd_capa, handle);
1386 /* record the catlog's header if an empty plain log was destroyed */
1387 rc = dt_declare_record_write(env, mdd->mdd_capa,
1388 sizeof(struct llog_logid_rec), 0, handle);
1392 struct mdd_changelog_user_data {
1393 __u64 mcud_endrec; /**< purge record for this user */
1394 __u64 mcud_minrec; /**< lowest changelog recno still referenced */
1396 __u32 mcud_minid; /**< user id with lowest rec reference */
1397 __u32 mcud_usercount;
1399 struct mdd_device *mcud_mdd;
1401 #define MCUD_UNREGISTER -1LL
1404 * 1. Find the smallest record everyone is willing to purge
1405 * 2. Update the last purgeable record for this user
1407 static int mdd_changelog_user_purge_cb(const struct lu_env *env,
1408 struct llog_handle *llh,
1409 struct llog_rec_hdr *hdr, void *data)
1411 struct llog_changelog_user_rec *rec;
1412 struct mdd_changelog_user_data *mcud = data;
1417 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
1419 rec = (struct llog_changelog_user_rec *)hdr;
1421 mcud->mcud_usercount++;
1423 /* If we have a new endrec for this id, use it for the following
1424 min check instead of its old value */
1425 if (rec->cur_id == mcud->mcud_id)
1426 rec->cur_endrec = max(rec->cur_endrec, mcud->mcud_endrec);
1428 /* Track the minimum referenced record */
1429 if (mcud->mcud_minid == 0 || mcud->mcud_minrec > rec->cur_endrec) {
1430 mcud->mcud_minid = rec->cur_id;
1431 mcud->mcud_minrec = rec->cur_endrec;
1434 if (rec->cur_id != mcud->mcud_id)
1437 /* Update this user's record */
1438 mcud->mcud_found = 1;
1440 /* Special case: unregister this user */
1441 if (mcud->mcud_endrec == MCUD_UNREGISTER) {
1442 struct llog_cookie cookie;
1444 struct mdd_device *mdd = mcud->mcud_mdd;
1446 cookie.lgc_lgl = llh->lgh_id;
1447 cookie.lgc_index = hdr->lrh_index;
1449 /* XXX This is a workaround for the deadlock of changelog
1450 * adding vs. changelog cancelling. LU-81. */
1451 th = mdd_trans_create(env, mdd);
1453 CERROR("Cannot get thandle\n");
1457 rc = mdd_declare_llog_cancel(env, mdd, th);
1461 rc = mdd_trans_start(env, mdd, th);
1465 rc = llog_cat_cancel_records(env, llh->u.phd.phd_cat_handle,
1468 mcud->mcud_usercount--;
1471 mdd_trans_stop(env, mdd, 0, th);
1475 /* Update the endrec */
1476 CDEBUG(D_IOCTL, "Rewriting changelog user %d endrec to "LPU64"\n",
1477 mcud->mcud_id, rec->cur_endrec);
1479 /* hdr+1 is loc of data */
1480 hdr->lrh_len -= sizeof(*hdr) + sizeof(struct llog_rec_tail);
1481 rc = llog_write_rec(env, llh, hdr, NULL, 0, (void *)(hdr + 1),
1482 hdr->lrh_index, NULL);
1487 static int mdd_changelog_user_purge(const struct lu_env *env,
1488 struct mdd_device *mdd, int id,
1491 struct mdd_changelog_user_data data;
1492 struct llog_ctxt *ctxt;
1496 CDEBUG(D_IOCTL, "Purge request: id=%d, endrec=%lld\n", id, endrec);
1499 data.mcud_minid = 0;
1500 data.mcud_minrec = 0;
1501 data.mcud_usercount = 0;
1502 data.mcud_endrec = endrec;
1503 data.mcud_mdd = mdd;
1504 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
1505 endrec = mdd->mdd_cl.mc_index;
1506 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
1507 if ((data.mcud_endrec == 0) ||
1508 ((data.mcud_endrec > endrec) &&
1509 (data.mcud_endrec != MCUD_UNREGISTER)))
1510 data.mcud_endrec = endrec;
1512 ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
1515 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
1517 rc = llog_cat_process(env, ctxt->loc_handle,
1518 mdd_changelog_user_purge_cb, (void *)&data,
1520 if ((rc >= 0) && (data.mcud_minrec > 0)) {
1521 CDEBUG(D_IOCTL, "Purging changelog entries up to "LPD64
1522 ", referenced by "CHANGELOG_USER_PREFIX"%d\n",
1523 data.mcud_minrec, data.mcud_minid);
1524 rc = mdd_changelog_llog_cancel(env, mdd, data.mcud_minrec);
1526 CWARN("Could not determine changelog records to purge; rc=%d\n",
1530 llog_ctxt_put(ctxt);
1532 if (!data.mcud_found) {
1533 CWARN("No entry for user %d. Last changelog reference is "
1534 LPD64" by changelog user %d\n", data.mcud_id,
1535 data.mcud_minrec, data.mcud_minid);
1539 if (!rc && data.mcud_usercount == 0)
1540 /* No more users; turn changelogs off */
1541 rc = mdd_changelog_on(mdd, 0);
1547 * May be called remotely from mdt_iocontrol_handle or locally from
1548 * mdt_iocontrol. Data may be freeform - remote handling doesn't enforce
1549 * an obd_ioctl_data format (but local ioctl handler does).
1551 * \param len - data len
1552 * \param karg - ioctl data, in kernel space
1554 static int mdd_iocontrol(const struct lu_env *env, struct md_device *m,
1555 unsigned int cmd, int len, void *karg)
1557 struct mdd_device *mdd;
1558 struct obd_ioctl_data *data = karg;
1562 mdd = lu2mdd_dev(&m->md_lu_dev);
1564 /* Doesn't use obd_ioctl_data */
1566 case OBD_IOC_CHANGELOG_CLEAR: {
1567 struct changelog_setinfo *cs = karg;
1568 rc = mdd_changelog_user_purge(env, mdd, cs->cs_id,
1572 case OBD_IOC_GET_MNTOPT: {
1573 mntopt_t *mntopts = (mntopt_t *)karg;
1574 *mntopts = mdd->mdd_dt_conf.ddp_mntopts;
1577 case OBD_IOC_START_LFSCK: {
1578 struct lfsck_start *start = karg;
1579 struct md_lfsck *lfsck = &mdd->mdd_lfsck;
1581 /* Return the kernel service version. */
1582 /* XXX: version can be used for compatibility in the future. */
1583 start->ls_version = lfsck->ml_version;
1584 rc = mdd_lfsck_start(env, lfsck, start);
1587 case OBD_IOC_STOP_LFSCK: {
1588 rc = mdd_lfsck_stop(env, &mdd->mdd_lfsck);
1593 /* Below ioctls use obd_ioctl_data */
1594 if (len != sizeof(*data)) {
1595 CERROR("Bad ioctl size %d\n", len);
1598 if (data->ioc_version != OBD_IOCTL_VERSION) {
1599 CERROR("Bad magic %x != %x\n", data->ioc_version,
1605 case OBD_IOC_CHANGELOG_REG:
1606 rc = mdd_changelog_user_register(mdd, &data->ioc_u32_1);
1608 case OBD_IOC_CHANGELOG_DEREG:
1609 rc = mdd_changelog_user_purge(env, mdd, data->ioc_u32_1,
1619 /* type constructor/destructor: mdd_type_init, mdd_type_fini */
1620 LU_TYPE_INIT_FINI(mdd, &mdd_thread_key, &mdd_ucred_key, &mdd_capainfo_key);
1622 const struct md_device_operations mdd_ops = {
1623 .mdo_statfs = mdd_statfs,
1624 .mdo_root_get = mdd_root_get,
1625 .mdo_maxsize_get = mdd_maxsize_get,
1626 .mdo_init_capa_ctxt = mdd_init_capa_ctxt,
1627 .mdo_update_capa_key= mdd_update_capa_key,
1628 .mdo_llog_ctxt_get = mdd_llog_ctxt_get,
1629 .mdo_iocontrol = mdd_iocontrol,
1632 static struct lu_device_type_operations mdd_device_type_ops = {
1633 .ldto_init = mdd_type_init,
1634 .ldto_fini = mdd_type_fini,
1636 .ldto_start = mdd_type_start,
1637 .ldto_stop = mdd_type_stop,
1639 .ldto_device_alloc = mdd_device_alloc,
1640 .ldto_device_free = mdd_device_free,
1642 .ldto_device_init = mdd_device_init,
1643 .ldto_device_fini = mdd_device_fini
1646 static struct lu_device_type mdd_device_type = {
1647 .ldt_tags = LU_DEVICE_MD,
1648 .ldt_name = LUSTRE_MDD_NAME,
1649 .ldt_ops = &mdd_device_type_ops,
1650 .ldt_ctx_tags = LCT_MD_THREAD
1653 /* context key constructor: mdd_key_init */
1654 LU_KEY_INIT(mdd, struct mdd_thread_info);
1656 static void mdd_key_fini(const struct lu_context *ctx,
1657 struct lu_context_key *key, void *data)
1659 struct mdd_thread_info *info = data;
1660 if (info->mti_max_lmm != NULL)
1661 OBD_FREE(info->mti_max_lmm, info->mti_max_lmm_size);
1662 if (info->mti_max_cookie != NULL)
1663 OBD_FREE(info->mti_max_cookie, info->mti_max_cookie_size);
1664 mdd_buf_put(&info->mti_big_buf);
1669 /* context key: mdd_thread_key */
1670 LU_CONTEXT_KEY_DEFINE(mdd, LCT_MD_THREAD);
1672 static struct lu_local_obj_desc llod_capa_key = {
1673 .llod_name = CAPA_KEYS,
1674 .llod_oid = MDD_CAPA_KEYS_OID,
1678 static struct lu_local_obj_desc llod_mdd_orphan = {
1679 .llod_name = orph_index_name,
1680 .llod_oid = MDD_ORPHAN_OID,
1682 .llod_feat = &dt_directory_features,
1685 static struct lu_local_obj_desc llod_mdd_root = {
1686 .llod_name = mdd_root_dir_name,
1687 .llod_oid = MDD_ROOT_INDEX_OID,
1689 .llod_feat = &dt_directory_features,
1692 static struct lu_local_obj_desc llod_lfsck_bookmark = {
1693 .llod_name = lfsck_bookmark_name,
1694 .llod_oid = LFSCK_BOOKMARK_OID,
1698 static int __init mdd_mod_init(void)
1700 struct lprocfs_static_vars lvars;
1703 lprocfs_mdd_init_vars(&lvars);
1705 rc = lu_kmem_init(mdd_caches);
1709 llo_local_obj_register(&llod_capa_key);
1710 llo_local_obj_register(&llod_mdd_orphan);
1711 llo_local_obj_register(&llod_mdd_root);
1712 llo_local_obj_register(&llod_lfsck_bookmark);
1714 rc = class_register_type(&mdd_obd_device_ops, NULL, lvars.module_vars,
1715 LUSTRE_MDD_NAME, &mdd_device_type);
1717 lu_kmem_fini(mdd_caches);
1721 static void __exit mdd_mod_exit(void)
1723 llo_local_obj_unregister(&llod_capa_key);
1724 llo_local_obj_unregister(&llod_mdd_orphan);
1725 llo_local_obj_unregister(&llod_mdd_root);
1726 llo_local_obj_unregister(&llod_lfsck_bookmark);
1728 class_unregister_type(LUSTRE_MDD_NAME);
1729 lu_kmem_fini(mdd_caches);
1732 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1733 MODULE_DESCRIPTION("Lustre Meta-data Device Prototype ("LUSTRE_MDD_NAME")");
1734 MODULE_LICENSE("GPL");
1736 cfs_module(mdd, "0.1.0", mdd_mod_init, mdd_mod_exit);