From 0fd2cb35216e0716807b270727cd8f85c6fec0d6 Mon Sep 17 00:00:00 2001 From: tappro Date: Thu, 22 Jun 2006 18:36:12 +0000 Subject: [PATCH] first fixes after code inspection. --- lustre/cmm/cmm_device.c | 40 +++++++++++++++++++++++-------------- lustre/cmm/cmm_internal.h | 51 +++++++++++++++++++++++++++-------------------- lustre/cmm/cmm_object.c | 12 +++++------ lustre/cmm/mdc_device.c | 5 ++--- lustre/cmm/mdc_internal.h | 36 +++++++++++++++++++-------------- lustre/cmm/mdc_object.c | 19 +++++++++++++----- 6 files changed, 97 insertions(+), 66 deletions(-) diff --git a/lustre/cmm/cmm_device.c b/lustre/cmm/cmm_device.c index dcf2978..7d35f35 100644 --- a/lustre/cmm/cmm_device.c +++ b/lustre/cmm/cmm_device.c @@ -55,7 +55,7 @@ static inline int lu_device_is_cmm(struct lu_device *d) } static int cmm_root_get(const struct lu_context *ctx, struct md_device *md, - struct lu_fid *fid) + struct lu_fid *fid) { struct cmm_device *cmm_dev = md2cmm_dev(md); @@ -64,7 +64,7 @@ static int cmm_root_get(const struct lu_context *ctx, struct md_device *md, } static int cmm_statfs(const struct lu_context *ctxt, struct md_device *md, - struct kstatfs *sfs) { + struct kstatfs *sfs) { struct cmm_device *cmm_dev = md2cmm_dev(md); int rc; @@ -88,8 +88,7 @@ static int cmm_add_mdc(const struct lu_context *ctx, { struct lu_device_type *ldt = &mdc_device_type; struct lu_device *ld; - struct mdc_device *mc; - struct mdc_device *tmp; + struct mdc_device *mc, *tmp; __u32 mdc_num; int rc; ENTRY; @@ -100,22 +99,34 @@ static int cmm_add_mdc(const struct lu_context *ctx, spin_lock(&cm->cmm_tgt_guard); list_for_each_entry_safe(mc, tmp, &cm->cmm_targets, mc_linkage) { - if (mc->mc_num == mdc_num) + if (mc->mc_num == mdc_num) { + spin_unlock(&cm->cmm_tgt_guard); RETURN(-EEXIST); + } } spin_unlock(&cm->cmm_tgt_guard); ld = ldt->ldt_ops->ldto_device_alloc(ctx, ldt, cfg); ld->ld_site = cmm2lu_dev(cm)->ld_site; rc = ldt->ldt_ops->ldto_device_init(ctx, ld, NULL); - if (rc) + if (rc) { ldt->ldt_ops->ldto_device_free(ctx, ld); - + RETURN (rc); + } /* pass config to the just created MDC */ rc = ld->ld_ops->ldo_process_config(ctx, ld, cfg); if (rc == 0) { - mc = lu2mdc_dev(ld); spin_lock(&cm->cmm_tgt_guard); + list_for_each_entry_safe(mc, tmp, &cm->cmm_targets, + mc_linkage) { + if (mc->mc_num == mdc_num) { + spin_unlock(&cm->cmm_tgt_guard); + ldt->ldt_ops->ldto_device_fini(ctx, ld); + ldt->ldt_ops->ldto_device_free(ctx, ld); + RETURN(-EEXIST); + } + } + mc = lu2mdc_dev(ld); list_add_tail(&mc->mc_linkage, &cm->cmm_targets); cm->cmm_tgt_count++; spin_unlock(&cm->cmm_tgt_guard); @@ -161,8 +172,8 @@ static struct lu_device_operations cmm_lu_ops = { /* --- lu_device_type operations --- */ static struct lu_device *cmm_device_alloc(const struct lu_context *ctx, - struct lu_device_type *t, - struct lustre_cfg *cfg) + struct lu_device_type *t, + struct lustre_cfg *cfg) { struct lu_device *l; struct cmm_device *m; @@ -179,8 +190,7 @@ static struct lu_device *cmm_device_alloc(const struct lu_context *ctx, l->ld_ops = &cmm_lu_ops; } - EXIT; - return l; + RETURN (l); } static void cmm_device_free(const struct lu_context *ctx, struct lu_device *d) @@ -189,6 +199,7 @@ static void cmm_device_free(const struct lu_context *ctx, struct lu_device *d) LASSERT(atomic_read(&d->ld_ref) == 0); LASSERT(m->cmm_tgt_count == 0); + LASSERT(list_empty(&m->cmm_targets)); md_device_fini(&m->cmm_md_dev); OBD_FREE_PTR(m); } @@ -236,15 +247,14 @@ static struct lu_device *cmm_device_fini(const struct lu_context *ctx, list_for_each_entry_safe(mc, tmp, &cm->cmm_targets, mc_linkage) { struct lu_device *ld_m = mdc2lu_dev(mc); - list_del(&mc->mc_linkage); + list_del_init(&mc->mc_linkage); lu_device_put(cmm2lu_dev(cm)); ld->ld_type->ldt_ops->ldto_device_fini(ctx, ld_m); ld->ld_type->ldt_ops->ldto_device_free(ctx, ld_m); cm->cmm_tgt_count--; } - EXIT; - return md2lu_dev(cm->cmm_child); + RETURN (md2lu_dev(cm->cmm_child)); } static struct lu_device_type_operations cmm_device_type_ops = { diff --git a/lustre/cmm/cmm_internal.h b/lustre/cmm/cmm_internal.h index 7745e1c..ef73eff 100644 --- a/lustre/cmm/cmm_internal.h +++ b/lustre/cmm/cmm_internal.h @@ -1,23 +1,29 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * Copyright (C) 2006 Cluster File Systems, Inc. - * - * This file is part of Lustre, http://www.lustre.org. + * lustre/cmm/cmm_internal.h + * Lustre Cluster Metadata Manager (cmm) * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * Copyright (C) 2006 Cluster File Systems, Inc. + * Author: Mike Pershin + * + * This file is part of the Lustre file system, http://www.lustre.org + * Lustre is a trademark of Cluster File Systems, Inc. * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * You may have signed or agreed to another license before downloading + * this software. If so, you are bound by the terms and conditions + * of that agreement, and the following does not apply to you. See the + * LICENSE file included with this distribution for more information. * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * If you did not agree to a different license, then this copy of Lustre + * is open source software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. * + * In either case, Lustre is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license text for more details. */ #ifndef _CMM_INTERNAL_H @@ -34,7 +40,7 @@ struct cmm_device { /* device flags, taken from enum cmm_flags */ __u32 cmm_flags; /* underlaying device in MDS stack, usually MDD */ - struct md_device *cmm_child; + struct md_device *cmm_child; /* other MD servers in cluster */ __u32 cmm_local_num; __u32 cmm_tgt_count; @@ -64,20 +70,20 @@ static inline struct cmm_device *md2cmm_dev(struct md_device *m) static inline struct cmm_device *lu2cmm_dev(struct lu_device *d) { - return container_of0(d, struct cmm_device, cmm_md_dev.md_lu_dev); + return container_of0(d, struct cmm_device, cmm_md_dev.md_lu_dev); } static inline struct lu_device *cmm2lu_dev(struct cmm_device *d) { - return (&d->cmm_md_dev.md_lu_dev); + return (&d->cmm_md_dev.md_lu_dev); } struct cmm_object { - struct md_object cmo_obj; + struct md_object cmo_obj; int cmo_local; }; -/* local CMM objec */ +/* local CMM object */ struct cml_object { struct cmm_object cmm_obj; }; @@ -91,19 +97,19 @@ struct cmr_object { static inline struct cmm_device *cmm_obj2dev(struct cmm_object *c) { - return (md2cmm_dev(md_device_get(&c->cmo_obj))); + return (md2cmm_dev(md_obj2dev(&c->cmo_obj))); } static inline struct cmm_object *lu2cmm_obj(struct lu_object *o) { - //LASSERT(lu_device_is_cmm(o->lo_dev)); - return container_of0(o, struct cmm_object, cmo_obj.mo_lu); + //LASSERT(lu_device_is_cmm(o->lo_dev)); + return container_of0(o, struct cmm_object, cmo_obj.mo_lu); } /* get cmm object from md_object */ static inline struct cmm_object *md2cmm_obj(struct md_object *o) { - return container_of0(o, struct cmm_object, cmo_obj); + return container_of0(o, struct cmm_object, cmo_obj); } /* get lower-layer object */ static inline struct md_object *cmm2child_obj(struct cmm_object *o) @@ -124,3 +130,4 @@ struct lu_object *cmm_object_alloc(const struct lu_context *ctx, #endif /* __KERNEL__ */ #endif /* _CMM_INTERNAL_H */ + diff --git a/lustre/cmm/cmm_object.c b/lustre/cmm/cmm_object.c index 9937f3c..de413dd 100644 --- a/lustre/cmm/cmm_object.c +++ b/lustre/cmm/cmm_object.c @@ -50,7 +50,7 @@ static int cmm_fld_lookup(struct cmm_device *cm, __u64 mds; int rc; ENTRY; - return 0; + LASSERT(fid_is_sane(fid)); /* XXX: is this correct? We need this to prevent FLD lookups while CMM @@ -203,7 +203,7 @@ static int cml_object_exists(const struct lu_context *ctx, static int cml_object_print(const struct lu_context *ctx, struct seq_file *f, const struct lu_object *lo) { - return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", lo); + return seq_printf(f, LUSTRE_CMM0_NAME"-local@%p", lo); } static struct lu_object_operations cml_obj_ops = { @@ -408,7 +408,7 @@ static inline struct cmr_object *cmm2cmr_obj(struct cmm_object *co) return container_of0(co, struct cmr_object, cmm_obj); } -/* get local child device */ +/* get proper child device from MDCs */ static struct lu_device *cmr_child_dev(struct cmm_device *d, __u32 num) { struct lu_device *next = NULL; @@ -469,7 +469,7 @@ static int cmr_object_exists(const struct lu_context *ctx, static int cmr_object_print(const struct lu_context *ctx, struct seq_file *f, const struct lu_object *lo) { - return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", lo); + return seq_printf(f, LUSTRE_CMM0_NAME"-remote@%p", lo); } static struct lu_object_operations cmr_obj_ops = { @@ -618,8 +618,8 @@ static int cmr_rename(const struct lu_context *ctx, struct md_object *mo_po, * lookup and process this further */ LASSERT(mo_t == NULL); - rc = mdo_rename_tgt(ctx, cmm2child_obj(md2cmm_obj(mo_pn)), NULL/* mo_t */, - lf, t_name); + rc = mdo_rename_tgt(ctx, cmm2child_obj(md2cmm_obj(mo_pn)), + NULL/* mo_t */, lf, t_name); /* only old name is removed localy */ if (rc == 0) rc = mdo_name_remove(ctx, cmm2child_obj(md2cmm_obj(mo_po)), diff --git a/lustre/cmm/mdc_device.c b/lustre/cmm/mdc_device.c index 06d20cf..4ba8e3d 100644 --- a/lustre/cmm/mdc_device.c +++ b/lustre/cmm/mdc_device.c @@ -182,6 +182,7 @@ void mdc_device_free(const struct lu_context *ctx, struct lu_device *ld) struct mdc_device *mc = lu2mdc_dev(ld); LASSERT(atomic_read(&ld->ld_ref) == 0); + LASSERT(list_empty(&mc->mc_linkage)); md_device_fini(&mc->mc_md_dev); OBD_FREE_PTR(mc); } @@ -195,9 +196,7 @@ static void *mdc_thread_init(const struct lu_context *ctx, CLASSERT(CFS_PAGE_SIZE >= sizeof *info); OBD_ALLOC_PTR(info); - if (info != NULL) - info->mci_ctxt = ctx; - else + if (info == NULL) info = ERR_PTR(-ENOMEM); return info; } diff --git a/lustre/cmm/mdc_internal.h b/lustre/cmm/mdc_internal.h index e745cc6..4ae5048 100644 --- a/lustre/cmm/mdc_internal.h +++ b/lustre/cmm/mdc_internal.h @@ -1,23 +1,30 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * Copyright (C) 2006 Cluster File Systems, Inc. - * - * This file is part of Lustre, http://www.lustre.org. + * lustre/cmm/cmm_internal.h + * Lustre Cluster Metadata Manager (cmm), + * MDC device * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * Copyright (C) 2006 Cluster File Systems, Inc. + * Author: Mike Pershin + * + * This file is part of the Lustre file system, http://www.lustre.org + * Lustre is a trademark of Cluster File Systems, Inc. * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * You may have signed or agreed to another license before downloading + * this software. If so, you are bound by the terms and conditions + * of that agreement, and the following does not apply to you. See the + * LICENSE file included with this distribution for more information. * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * If you did not agree to a different license, then this copy of Lustre + * is open source software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. * + * In either case, Lustre is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license text for more details. */ #ifndef _CMM_MDC_INTERNAL_H @@ -43,7 +50,6 @@ struct mdc_device { }; struct mdc_thread_info { - const struct lu_context *mci_ctxt; struct md_op_data mci_opdata; struct ptlrpc_request *mci_req; }; @@ -64,7 +70,7 @@ static inline struct mdc_device *md2mdc_dev(struct md_device *md) static inline struct mdc_device *mdc_obj2dev(struct mdc_object *mco) { - return (md2mdc_dev(md_device_get(&mco->mco_obj))); + return (md2mdc_dev(md_obj2dev(&mco->mco_obj))); } static inline struct mdc_object *lu2mdc_obj(struct lu_object *lo) diff --git a/lustre/cmm/mdc_object.c b/lustre/cmm/mdc_object.c index 3fc55b8..36c074c 100644 --- a/lustre/cmm/mdc_object.c +++ b/lustre/cmm/mdc_object.c @@ -77,7 +77,8 @@ static int mdc_object_init(const struct lu_context *ctx, struct lu_object *lo) RETURN(0); } -static int mdc_object_exists(const struct lu_context *ctx, struct lu_object *lo) +static int mdc_object_exists(const struct lu_context *ctx, + struct lu_object *lo) { /* we don't know does it exists or not - but suppose that it does*/ return 1; @@ -100,7 +101,7 @@ static struct lu_object_operations mdc_obj_ops = { static int mdc_object_create(const struct lu_context *ctx, struct md_object *mo, struct lu_attr *attr) { - struct mdc_device *mc = md2mdc_dev(md_device_get(mo)); + struct mdc_device *mc = md2mdc_dev(md_obj2dev(mo)); struct mdc_thread_info *mci; int rc; ENTRY; @@ -117,12 +118,14 @@ static int mdc_object_create(const struct lu_context *ctx, attr->la_mode, attr->la_uid, attr->la_gid, 0, 0, &mci->mci_req); + ptlrpc_req_finished(mci->mci_req); + RETURN(rc); } static int mdc_ref_add(const struct lu_context *ctx, struct md_object *mo) { - struct mdc_device *mc = md2mdc_dev(md_device_get(mo)); + struct mdc_device *mc = md2mdc_dev(md_obj2dev(mo)); struct mdc_thread_info *mci; int rc; ENTRY; @@ -136,12 +139,14 @@ static int mdc_ref_add(const struct lu_context *ctx, struct md_object *mo) rc = md_link(mc->mc_desc.cl_exp, &mci->mci_opdata, &mci->mci_req); + ptlrpc_req_finished(mci->mci_req); + RETURN(rc); } static int mdc_ref_del(const struct lu_context *ctx, struct md_object *mo) { - struct mdc_device *mc = md2mdc_dev(md_device_get(mo)); + struct mdc_device *mc = md2mdc_dev(md_obj2dev(mo)); struct mdc_thread_info *mci; int rc; ENTRY; @@ -155,6 +160,8 @@ static int mdc_ref_del(const struct lu_context *ctx, struct md_object *mo) rc = md_unlink(mc->mc_desc.cl_exp, &mci->mci_opdata, &mci->mci_req); + ptlrpc_req_finished(mci->mci_req); + RETURN(rc); } @@ -169,7 +176,7 @@ static int mdc_rename_tgt(const struct lu_context *ctx, struct md_object *mo_p, struct md_object *mo_t, const struct lu_fid *lf, const char *name) { - struct mdc_device *mc = md2mdc_dev(md_device_get(mo_p)); + struct mdc_device *mc = md2mdc_dev(md_obj2dev(mo_p)); struct mdc_thread_info *mci; int rc; ENTRY; @@ -183,6 +190,8 @@ static int mdc_rename_tgt(const struct lu_context *ctx, rc = md_rename(mc->mc_desc.cl_exp, &mci->mci_opdata, NULL, 0, name, strlen(name), &mci->mci_req); + ptlrpc_req_finished(mci->mci_req); + RETURN(rc); } -- 1.8.3.1