From f39434bac39fbc9e95d5706dd9552ec650838dd8 Mon Sep 17 00:00:00 2001 From: wangdi Date: Mon, 3 Apr 2006 14:42:30 +0000 Subject: [PATCH] Branch: b_new_cmd update mdd proto type of mdd --- lustre/Makefile.in | 2 +- lustre/autoconf/lustre-core.m4 | 2 + lustre/mdd/Makefile.in | 4 + lustre/mdd/autoMakefile.am | 11 ++ lustre/mdd/mdd_handler.c | 289 +++++++++++++++++++++++------------------ lustre/mdd/mdd_internal.h | 28 ++++ 6 files changed, 211 insertions(+), 125 deletions(-) create mode 100644 lustre/mdd/Makefile.in create mode 100644 lustre/mdd/autoMakefile.am diff --git a/lustre/Makefile.in b/lustre/Makefile.in index 4369a2a..dcd5065 100644 --- a/lustre/Makefile.in +++ b/lustre/Makefile.in @@ -8,7 +8,7 @@ subdir-m += osc subdir-m += obdecho subdir-m += mgc -@SERVER_TRUE@subdir-m += mds obdfilter ost mgs mdt +@SERVER_TRUE@subdir-m += mds obdfilter ost mgs mdt mdd @CLIENT_TRUE@subdir-m += mdc llite @QUOTA_TRUE@subdir-m += quota diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index e0a754f..03da0f6 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -643,6 +643,8 @@ lustre/mds/Makefile lustre/mds/autoMakefile lustre/mdt/Makefile lustre/mdt/autoMakefile +lustre/mdd/Makefile +lustre/mdd/autoMakefile lustre/obdclass/Makefile lustre/obdclass/autoMakefile lustre/obdecho/Makefile diff --git a/lustre/mdd/Makefile.in b/lustre/mdd/Makefile.in new file mode 100644 index 0000000..2ed1249 --- /dev/null +++ b/lustre/mdd/Makefile.in @@ -0,0 +1,4 @@ +MODULES := mdd +mdd-objs := mdd_handler.o + +@INCLUDE_RULES@ diff --git a/lustre/mdd/autoMakefile.am b/lustre/mdd/autoMakefile.am new file mode 100644 index 0000000..6ea543b --- /dev/null +++ b/lustre/mdd/autoMakefile.am @@ -0,0 +1,11 @@ +# Copyright (C) 2001 Cluster File Systems, Inc. +# +# This code is issued under the GNU General Public License. +# See the file COPYING in this distribution + +if MODULES +modulefs_DATA = mdd$(KMODEXT) +endif + +MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ +DIST_SOURCES := $(mdd-objs:%.o=%.c) diff --git a/lustre/mdd/mdd_handler.c b/lustre/mdd/mdd_handler.c index 84527ac..854f42e 100644 --- a/lustre/mdd/mdd_handler.c +++ b/lustre/mdd/mdd_handler.c @@ -123,7 +123,6 @@ void mdd_object_free(struct lu_object *o) void mdd_object_release(struct lu_object *o) { - struct mdd_device *d = mdd_dev(o->lo_dev); } int mdd_object_print(struct seq_file *f, const struct lu_object *o) @@ -171,8 +170,6 @@ __mdd_object_create(struct mdd_device *mdd, struct mdd_object *pobj, struct mdd_object *child, struct context *uctxt, void *handle) { - struct mdd_object *mdd_obj; - struct lu_object *lu; int rc; ENTRY; @@ -184,26 +181,27 @@ __mdd_object_create(struct mdd_device *mdd, struct mdd_object *pobj, } static int -mdd_object_create(struct mdd_object *pobj, struct mdd_object *child, +mdd_object_create(struct md_object *pobj, struct mdd_object *child, struct context *uctxt) { struct mdd_device *mdd = mdo2mdd(pobj); + struct mdd_object *mdd_pobj = mdo2mddo(pobj); void *handle = NULL; int rc; ENTRY; - handle = mdd_trans_start(mdd, obj); + handle = mdd_trans_start(mdd, mdd_pobj); if (!handle) RETURN(-ENOMEM); - rc = __mdd_object_create(mdd, pobj, child, uctxt, handle); + rc = __mdd_object_create(mdd, mdd_pobj, child, uctxt, handle); - mdd_trans_stop(handle); + mdd_trans_stop(mdd, handle); RETURN(rc); } -static int mdd_add_orphan(struct obd_device *obd, struct mdd_object *obj, +static int mdd_add_orphan(struct mdd_device *mdd, struct mdd_object *obj, void *handle) { int rc = 0; @@ -213,7 +211,7 @@ static int mdd_add_orphan(struct obd_device *obd, struct mdd_object *obj, } static int -_mdd_object_destroy(struct mdd_device *mdd, struct mdd_object *obj, +__mdd_object_destroy(struct mdd_device *mdd, struct mdd_object *obj, void *handle) { int rc = 0; @@ -224,17 +222,32 @@ _mdd_object_destroy(struct mdd_device *mdd, struct mdd_object *obj, } static int -mdd_object_destroy(struct md_object *pobj, struct mdd_object *obj) +open_orphan(struct mdd_object *obj) { - struct mdd_device *mdd = mdo2mdd(pobj); + return 0; +} + +static int +mdd_add_unlink_log(struct mdd_device *mdd, struct mdd_object *obj, + void *handle) +{ + return 0; +} + +static int +mdd_object_destroy(struct md_object *obj) +{ + struct mdd_device *mdd = mdo2mdd(obj); + struct mdd_object *mdd_obj = mdo2mddo(obj); void *handle; + int rc ; ENTRY; - handle = mdd_trans_start(mdd, pobj); + handle = mdd_trans_start(mdd, mdd_obj); if (!handle) RETURN(-ENOMEM); - mdd_lock(mdd, pobj, WRITE_LOCK); + mdd_lock(mdd, mdd_obj, WRITE_LOCK); if (open_orphan(mdd_obj)) rc = mdd_add_orphan(mdd, mdd_obj, handle); else { @@ -245,191 +258,214 @@ mdd_object_destroy(struct md_object *pobj, struct mdd_object *obj) rc = mdd_add_unlink_log(mdd, mdd_obj, handle); } exit: - mdd_unlock(mdd, pobj, WRITE_LOCK); - mdd_trans_stop(handle); + mdd_unlock(mdd, mdd_obj, WRITE_LOCK); + mdd_trans_stop(mdd, handle); RETURN(rc); } -static void -mdd_object_get(struct mdd_device *mdd, struct mdd_object *obj) +void mdd_object_get(struct mdd_device *mdd, struct mdd_object *obj) { mdd_child_ops(mdd)->osd_object_get(mdd_object_child(obj)); } static int -mdd_attr_get(struct mdd_device *mdd, struct mdd_object *obj, void *buf, - int buf_len, const char *name, struct context *uc_context) -{ - int rc; - ENTRY; - - mdd_object_get(mdd, obj); - rc = mdd_child_ops(mdd)->osd_attr_get(mdd_object_child(obj), - buf, buf_len, name, - uc_context); - mdd_object_put(mdd, obj); - RETURN(rc); -} - -static int __mdd_attr_set(struct mdd_device *mdd, struct mdd_object *obj, void *buf, int buf_len, const char *name, struct context *uc_context, void *handle) { - return mdd_child_ops(ops)->osd_attr_set(mdd_object_child(obj), + return mdd_child_ops(mdd)->osd_attr_set(mdd_object_child(obj), buf, buf_len, name, uc_context, handle); } -static int -mdd_attr_set(struct mdd_device *mdd, struct mdd_object *obj, void *buf, - int buf_len, const char *name, struct context *uc_context) +static int +mdd_attr_set(struct md_object *obj, void *buf, int buf_len, const char *name, + struct context *uc_context) { - int rc; + struct mdd_device *mdd = mdo2mdd(obj); void *handle = NULL; + int rc; ENTRY; - handle = mdd_trans_start(mdd, obj); + handle = mdd_trans_start(mdd, mdo2mddo(obj)); if (!handle) RETURN(-ENOMEM); - __mdd_attr_set(mdd, obj, buf, buf_len, name, uc_context, handle); - + rc = __mdd_attr_set(mdd, mdo2mddo(obj), buf, buf_len, name, uc_context, + handle); + mdd_trans_stop(mdd, handle); - + RETURN(rc); } -static int +static int mdd_object_dec_check(struct mdd_device *mdd, struct mdd_object *obj) -{ +{ return mdd_child_ops(mdd)->osd_object_dec_check(mdd_object_child(obj)); } + +static struct ll_fid *mdd_object_getfid(struct mdd_object *obj) +{ + return &(obj->mod_obj.mo_lu.lo_header->loh_fid); +} + static int -mdd_object_put(struct mdd_device *mdd, struct mdd_object *obj) +mdd_attr_get(struct md_object *obj, void *buf, int buf_len, const char *name, + struct context *uctxt) { - int nlink, rc = 0; + struct mdd_object *mdd_obj = mdo2mddo(obj); + struct mdd_device *mdd = mdo2mdd(obj); + int rc; + + ENTRY; + + mdd_object_get(mdd, mdd_obj); + rc = mdd_child_ops(mdd)->osd_attr_get(mdd_object_child(mdd_obj), + buf, buf_len, name, uctxt); + mdd_object_put(mdd, mdd_obj); + RETURN(rc); +} + +int mdd_object_put(struct mdd_device *mdd, struct mdd_object *obj) +{ + int rc = 0; if ((mdd_object_dec_check(mdd, obj)) == 0) { - rc = mdd_attr_get(mdd, obj, &nlink, sizeof(nlink), - "NLINK", uc_context); + int nlink; + + rc = mdd_attr_get(&obj->mod_obj, &nlink, sizeof(nlink), "NLINK", + NULL); if (!rc) RETURN(-EINVAL); + + if (nlink == 0) + rc = mdd_object_destroy(&obj->mod_obj); } - if (nlink == 0) - rc = mdd_object_destroy(mdd, obj); RETURN(rc); } -static struct ll_fid *mdd_object_getfid(struct mdd_object *obj) -{ - return &(obj->mod_obj.mo_lu->lo_header->loh_fid); -} static int __mdd_index_insert(struct mdd_device *mdd, struct mdd_object *pobj, struct mdd_object *obj, const char *name, - struct uc_context *uc_context, void *handle) + struct context *uctxt, void *handle) { + int rc; + ENTRY; + mdd_object_get(mdd, pobj); mdd_lock(mdd, pobj, WRITE_LOCK); mdd_lock(mdd, obj, WRITE_LOCK); - mdd_child_ops(mdd)->osd_index_insert(mdd_object_child(pobj), + rc = mdd_child_ops(mdd)->osd_index_insert(mdd_object_child(pobj), mdd_object_getfid(obj), name, uctxt, handle); mdd_unlock(mdd, pobj, WRITE_LOCK); mdd_unlock(mdd, obj, WRITE_LOCK); - mdd_put_obj(mdd, pobj); + mdd_object_put(mdd, pobj); + + RETURN(rc); } static int -mdd_index_insert(struct mdd_device *mdd, struct mdd_object *pobj, - struct mdd_object *obj, const char *name, - struct uc_context *uc_context) +mdd_index_insert(struct mdd_device *mdd, struct md_object *pobj, + struct md_object *obj, const char *name, + struct context *uctxt) { + int rc; void *handle = NULL; ENTRY; - handle = mdd_trans_start(mdd, obj); + handle = mdd_trans_start(mdd, mdo2mddo(pobj)); if (!handle) RETURN(-ENOMEM); - __mdd_index_insert(mdd, pobj, obj, name, uc_context, handle); + rc = __mdd_index_insert(mdd, mdo2mddo(pobj), mdo2mddo(obj), name, uctxt, + handle); mdd_trans_stop(mdd, handle); + RETURN(rc); } static int -__mdd_index_delete(struct mdd_device *mdd, struct mdd_obj *pobj, - struct mdd_obj *obj, const char *name, - struct uc_context *uc_context, void *handle) +__mdd_index_delete(struct mdd_device *mdd, struct mdd_object *pobj, + struct mdd_object *obj, const char *name, + struct context *uctxt, void *handle) { + int rc; + ENTRY; + mdd_object_get(mdd, pobj); mdd_lock(mdd, pobj, WRITE_LOCK); mdd_lock(mdd, obj, WRITE_LOCK); - mdd_child_ops(mdd)->osd_insert_delete(mdd_object_child(pobj), + rc = mdd_child_ops(mdd)->osd_insert_delete(mdd_object_child(pobj), mdd_object_getfid(obj), name, uctxt, handle); mdd_unlock(mdd, pobj, WRITE_LOCK); mdd_unlock(mdd, obj, WRITE_LOCK); - mdd_put_obj(mdd, pobj); + mdd_object_put(mdd, pobj); + RETURN(rc); } static int -mdd_index_delete(struct mdd_device *obd, struct lustre_obj *pobj, - struct lustre_obj *obj, const char *name, - struct uc_context *uc_context) +mdd_index_delete(struct md_object *pobj, struct md_object *obj, + const char *name, struct context *uctxt) { + struct mdd_object *mdd_pobj = mdo2mddo(pobj); + struct mdd_object *mdd_obj = mdo2mddo(obj); + struct mdd_device *mdd = mdo2mdd(obj); void *handle = NULL; + int rc; ENTRY; - handle = mdd_trans_start(mdd, obj); + handle = mdd_trans_start(mdd, mdo2mddo(obj)); if (!handle) RETURN(-ENOMEM); - __mdd_index_delete(mdd, pobj, obj, name, uc_context, handle); + rc = __mdd_index_delete(mdd, mdd_pobj, mdd_obj, name, uctxt, handle); - mdd_trans_stop(handle); + mdd_trans_stop(mdd, handle); + + RETURN(rc); } static int -mdd_link(struct mdd_device *mdd, struct mdd_object *tgt_obj, - struct mdd_object *src_obj, const char *name, - struct context *uc_context) +mdd_link(struct md_object *tgt_obj, struct md_object *src_obj, + const char *name, struct context *uctxt) { - void *handle = NULL; + struct mdd_object *mdd_tobj = mdo2mddo(tgt_obj); + struct mdd_object *mdd_sobj = mdo2mddo(src_obj); + struct mdd_device *mdd = mdo2mdd(src_obj); + void *handle = NULL; int rc, nlink; ENTRY; - handle = mdd_trans_start(mdd, src_obj); + handle = mdd_trans_start(mdd, mdd_sobj); if (!handle) RETURN(-ENOMEM); - mdd_lock(mdd, tgt_obj, WRITE_LOCK); - mdd_lock(mdd, src_obj, WRITE_LOCK); - - rc = __mdd_index_insert(mdd, tgt_obj, name, src_obj, - uctxt, handle); + mdd_lock(mdd, mdd_tobj, WRITE_LOCK); + mdd_lock(mdd, mdd_sobj, WRITE_LOCK); + + rc = __mdd_index_insert(mdd, mdd_tobj, mdd_sobj, name, uctxt, handle); if (rc) - GOTO(trans_exit, rc); + GOTO(exit, rc); - rc = mdd_attr_get(mdd, src_obj, &nlink, sizeof(nlink), - "NLINK", uc_context); + rc = mdd_attr_get(src_obj, &nlink, sizeof(nlink), "NLINK", uctxt); ++nlink; - - rc = __mdd_attr_set(mdd, obj, &nlink, sizeof(nlink), "NLINK", - uc_context, handle); -exit: - mdd_unlock(mdd, tgt_obj, WRITE_LOCK); - mdd_unlock(mdd, src_obj, WRITE_LOCK); - + rc = __mdd_attr_set(mdd, mdd_sobj, &nlink, sizeof(nlink), "NLINK", + uctxt, handle); +exit: + mdd_unlock(mdd, mdd_tobj, WRITE_LOCK); + mdd_unlock(mdd, mdd_sobj, WRITE_LOCK); + mdd_trans_stop(mdd, handle); RETURN(rc); } @@ -449,36 +485,41 @@ static void mdd_rename_unlock(struct mdd_device *mdd, struct mdd_object *src_pob } static int -mdd_rename(struct mdd_device *mdd, struct mdd_object *src_pobj, - struct lustre_obj *tgt_pobj, struct lustre_obj *sobj, - const char *sname, struct lustre_obj, *tobj, +mdd_rename(struct md_object *src_pobj, struct md_object *tgt_pobj, + struct md_object *sobj, const char *sname, struct md_object *tobj, const char *tname, struct context *uctxt) { + struct mdd_device *mdd = mdo2mdd(src_pobj); + struct mdd_object *mdd_spobj = mdo2mddo(src_pobj); + struct mdd_object *mdd_tpobj = mdo2mddo(tgt_pobj); + struct mdd_object *mdd_sobj = mdo2mddo(sobj); + struct mdd_object *mdd_tobj = mdo2mddo(tobj); + int rc; void *handle = NULL; - handle = mdd_trans_start(mdd, src_pobj); + handle = mdd_trans_start(mdd, mdd_spobj); if (!handle) RETURN(-ENOMEM); - - mdd_rename_lock(mdd, src_pobj, tgt_pobj, sobj, tobj); - - rc = __mdd_index_delete(mdd, src_pobj, sname, sobj, uctxt, handle); + + mdd_rename_lock(mdd, mdd_spobj, mdd_tpobj, mdd_sobj, mdd_tobj); + + rc = __mdd_index_delete(mdd, mdd_spobj, mdd_sobj, sname, uctxt, handle); if (rc) GOTO(cleanup, rc); - rc = __mdd_index_delete(mdd, tgt_pobj, tname, tobj, uctxt, handle); + rc = __mdd_index_delete(mdd, mdd_tpobj, mdd_tobj, tname, uctxt, handle); if (rc) GOTO(cleanup, rc); - rc = __mdd_index_insert(mdd, src_pobj, tname, tobj, uctxt, handle); + rc = __mdd_index_insert(mdd, mdd_spobj, mdd_tobj, tname, uctxt, handle); if (rc) GOTO(cleanup, rc); - - rc = __mdd_obj_destroy(mdd, src_pobj, sname, sobj, uctxt, handle); + + rc = __mdd_object_destroy(mdd, mdd_sobj, handle); if (rc) GOTO(cleanup, rc); cleanup: - mdd_rename_unlock(mdd, src_pobj, tgt_pobj, sobj, tobj); + mdd_rename_unlock(mdd, mdd_spobj, mdd_tpobj, mdd_sobj, mdd_tobj); mdd_trans_stop(mdd, handle); RETURN(rc); } @@ -486,42 +527,47 @@ cleanup: static int mdd_mkdir(struct md_object *pobj, const char *name, struct md_object *child) { - struct mdd_device *mdd = mdo2mdd(obj); - struct context *context; + struct mdd_device *mdd = mdo2mdd(pobj); void *handle; int rc = 0; ENTRY; - handle = mdd_trans_start(mdd, obj); + handle = mdd_trans_start(mdd, mdo2mddo(pobj)); if (!handle) RETURN(-ENOMEM); - mdd_lock(mdd, mdo2mddo(obj), WRITE_LOCK); + mdd_lock(mdd, mdo2mddo(pobj), WRITE_LOCK); - rc = __mdd_object_create(mdd, mdo2mddo(obj), child, NULL, handle); + rc = __mdd_object_create(mdd, mdo2mddo(pobj), mdo2mddo(child), NULL, + handle); if (rc) GOTO(cleanup, rc); - rc = __mdd_index_insert(mdd, mdo2mddo(obj), pobj, child, name, + rc = __mdd_index_insert(mdd, mdo2mddo(pobj), mdo2mddo(child), name, NULL, handle); if (rc) GOTO(cleanup, rc); cleanup: - mdd_trans_stop(mdd, obj); - mdd_unlock(mdd, md2mdo(obj), WRITE_LOCK); + mdd_unlock(mdd, mdo2mddo(pobj), WRITE_LOCK); + mdd_trans_stop(mdd, handle); RETURN(rc); } -static int mdo_root_get(struct md_device *m, struct ll_fid *f) +static int mdd_root_get(struct md_device *m, struct ll_fid *f) { return 0; } -struct md_device_operations mdd_ops{ - .mdo_root_get = mdd_root_get; - .mdo_mkdir = mdd_mkdir; - .mdo_rename = mdd_rename; - .mdo_link = mdd_link; +struct md_device_operations mdd_ops = { + .mdo_root_get = mdd_root_get, + .mdo_mkdir = mdd_mkdir, + .mdo_rename = mdd_rename, + .mdo_link = mdd_link, + .mdo_attr_get = mdd_attr_get, + .mdo_attr_set = mdd_attr_set, + .mdo_index_insert = mdd_index_insert, + .mdo_index_delete = mdd_index_delete, + .mdo_object_create = mdd_object_create, }; static int mdd_fs_setup(struct mdd_device *mdd) @@ -539,11 +585,6 @@ static int mdd_setup(struct mdd_device *mdd, struct lustre_cfg* lcfg) int rc = 0; ENTRY; - /*XXX should mdd care about this*/ - mdd->mdd_max_mdsize = sizeof(struct lov_mds_md); - mdd->mdd_max_cookiesize = sizeof(struct llog_cookie); - mdd->mdd_atime_diff = MAX_ATIME_DIFF; - rc = mdd_fs_setup(mdd); if (rc) GOTO(err, rc); diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index b652bfd..c525eb1 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -7,6 +7,7 @@ #define LUSTRE_MDD_NAME "mdd" #define LUSTRE_OSD_NAME "osd" +#define WRITE_LOCK 1 /*the context of the mdd ops*/ struct context { const char *name; @@ -43,6 +44,7 @@ struct osd_device { struct osd_device_operations *osd_ops; }; + struct md_device { struct lu_device md_lu_dev; struct md_device_operations *md_ops; @@ -86,4 +88,30 @@ struct osd_object { struct dentry *oo_dentry; }; +struct md_device_operations { + int (*mdo_root_get)(struct md_device *m, struct ll_fid *f); + int (*mdo_mkdir)(struct md_object *obj, const char *name, + struct md_object *child); + + int (*mdo_rename)(struct md_object *spobj, struct md_object *tpobj, + struct md_object *sobj, const char *sname, + struct md_object *tobj, const char *tname, + struct context *uctxt); + int (*mdo_link)(struct md_object *tobj, struct md_object *sobj, + const char *name, struct context *uctxt); + int (*mdo_attr_get)(struct md_object *obj, void *buf, int buf_len, + const char *name, struct context *uctxt); + int (*mdo_attr_set)(struct md_object *obj, void *buf, int buf_len, + const char *name, struct context *uctxt); + int (*mdo_index_insert)(struct mdd_device *mdd, struct md_object *pobj, + struct md_object *obj, const char *name, + struct context *uctxt); + int (*mdo_index_delete)(struct md_object *pobj, struct md_object *obj, + const char *name, struct context *uctxt); + int (*mdo_object_create)(struct md_object *pobj, struct mdd_object *child, + struct context *uctxt); +}; + +int mdd_object_put(struct mdd_device *mdd, struct mdd_object *obj); +void mdd_object_get(struct mdd_device *mdd, struct mdd_object *obj); #endif -- 1.8.3.1