From 77080adc914d7ed09448d481c27e1a5bbf4fce91 Mon Sep 17 00:00:00 2001 From: tappro Date: Wed, 17 May 2006 18:58:47 +0000 Subject: [PATCH] add lookup method, use inlines for md_ operaions --- lustre/cmm/cmm_device.c | 1 + lustre/cmm/cmm_internal.h | 15 ---- lustre/cmm/cmm_object.c | 190 +++++++++++++++++++++++++--------------------- 3 files changed, 106 insertions(+), 100 deletions(-) diff --git a/lustre/cmm/cmm_device.c b/lustre/cmm/cmm_device.c index 1630ecf..95bb99c 100644 --- a/lustre/cmm/cmm_device.c +++ b/lustre/cmm/cmm_device.c @@ -120,6 +120,7 @@ static int cmm_add_mdc(struct lu_context *ctx, struct mdc_device *mc = lu2mdc_dev(ld); list_add_tail(&mc->mc_linkage, &cm->cmm_targets); lu_device_get(cmm2lu_dev(cm)); + cm->cmm_tgt_count++; } RETURN(rc); } diff --git a/lustre/cmm/cmm_internal.h b/lustre/cmm/cmm_internal.h index 08fb439..bceb019 100644 --- a/lustre/cmm/cmm_internal.h +++ b/lustre/cmm/cmm_internal.h @@ -95,21 +95,6 @@ static inline struct md_object *cmm2child_obj(struct cmm_object *o) /* cmm_object.c */ struct lu_object *cmm_object_alloc(struct lu_context *ctx, struct lu_device *); void cmm_object_free(struct lu_context *ctx, struct lu_object *o); -//int cmm_getattr(struct lu_object *o, struct lu_attr *a); -//int cmm_setattr(struct lu_object *o, struct lu_attr *a); - -/* cmm md operations */ -int cmm_config(struct lu_context *ctx, struct md_device *md, const char *name, - void *buf, int size, int mode); -int cmm_root_get(struct lu_context *ctx, struct md_device *m, struct lu_fid *f); -int cmm_statfs(struct lu_context *ctx, - struct md_device *m, struct kstatfs *sfs); -int cmm_mkdir(struct lu_context *ctxt, struct lu_attr*, - struct md_object *o, const char *name, - struct md_object *child); -int cmm_xattr_get(struct lu_context *ctxt, - struct md_object *obj, void *buf, int size, - const char *name); #endif /* __KERNEL__ */ #endif /* _CMM_INTERNAL_H */ diff --git a/lustre/cmm/cmm_object.c b/lustre/cmm/cmm_object.c index 4bc3e9e..e734ee2 100644 --- a/lustre/cmm/cmm_object.c +++ b/lustre/cmm/cmm_object.c @@ -68,142 +68,162 @@ static struct lu_device *cmm_get_child(struct cmm_device *d, __u32 num) } struct lu_object *cmm_object_alloc(struct lu_context *ctx, - struct lu_device *d) + struct lu_device *ld) { - struct cmm_object *mo; + struct cmm_object *co; + struct lu_object *lo; ENTRY; - OBD_ALLOC_PTR(mo); - if (mo != NULL) { - struct lu_object *o; - - o = &mo->cmo_obj.mo_lu; - lu_object_init(o, NULL, d); - mo->cmo_obj.mo_ops = &cmm_mo_ops; - mo->cmo_obj.mo_dir_ops = &cmm_dir_ops; - o->lo_ops = &cmm_obj_ops; - RETURN(o); - } else - RETURN(NULL); + OBD_ALLOC_PTR(co); + if (co != NULL) { + lo = &co->cmo_obj.mo_lu; + lu_object_init(lo, NULL, ld); + co->cmo_obj.mo_ops = &cmm_mo_ops; + co->cmo_obj.mo_dir_ops = &cmm_dir_ops; + lo->lo_ops = &cmm_obj_ops; + } else + lo = NULL; + + RETURN(lo); } -int cmm_object_init(struct lu_context *ctx, struct lu_object *o) +void cmm_object_free(struct lu_context *ctx, struct lu_object *lo) { - struct cmm_device *d = lu2cmm_dev(o->lo_dev); - struct lu_device *under; - struct lu_object *below; - const struct lu_fid *fid = lu_object_fid(o); - int mdsnum; + struct cmm_object *co = lu2cmm_obj(lo); + lu_object_fini(lo); + OBD_FREE_PTR(co); +} + +int cmm_object_init(struct lu_context *ctx, struct lu_object *lo) +{ + struct cmm_device *cd = lu2cmm_dev(lo->lo_dev); + struct lu_device *c_dev; + struct lu_object *c_obj; + const struct lu_fid *fid = lu_object_fid(lo); + int mdsnum, rc; + ENTRY; /* under device can be MDD or MDC */ mdsnum = cmm_fld_lookup(fid); - under = cmm_get_child(d, mdsnum); - if (under == NULL) - RETURN(-ENOENT); - - below = under->ld_ops->ldo_object_alloc(ctx, under); - if (below != NULL) { - struct cmm_object *co = lu2cmm_obj(o); - - lu_object_add(o, below); - co->cmo_num = mdsnum; - RETURN(0); - } else - RETURN(-ENOMEM); + c_dev = cmm_get_child(cd, mdsnum); + if (c_dev == NULL) { + rc = -ENOENT; + } else { + c_obj = c_dev->ld_ops->ldo_object_alloc(ctx, c_dev); + if (c_obj != NULL) { + struct cmm_object *co = lu2cmm_obj(lo); + + lu_object_add(lo, c_obj); + co->cmo_num = mdsnum; + rc = 0; + } else { + rc = -ENOMEM; + } + } + + RETURN(rc); } -void cmm_object_free(struct lu_context *ctx, struct lu_object *o) +static int cmm_object_exists(struct lu_context *ctx, struct lu_object *lo) { - struct cmm_object *mo = lu2cmm_obj(o); - lu_object_fini(o); - OBD_FREE_PTR(mo); + return lu_object_exists(ctx, lu_object_next(lo)); } -void cmm_object_release(struct lu_context *ctx, struct lu_object *o) +static int cmm_object_print(struct lu_context *ctx, + struct seq_file *f, const struct lu_object *lo) { - return; + return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", lo); } -static int cmm_object_exists(struct lu_context *ctx, struct lu_object *o) +static struct lu_object_operations cmm_obj_ops = { + .loo_object_init = cmm_object_init, + .loo_object_print = cmm_object_print, + .loo_object_exists = cmm_object_exists +}; + +/* md_object operations */ +static int cmm_object_create(struct lu_context *ctx, struct md_object *mo, + struct lu_attr *attr) { - return lu_object_exists(ctx, lu_object_next(o)); + struct md_object *ch = cmm2child_obj(md2cmm_obj(mo)); + int rc; + + ENTRY; + + LASSERT (cmm_is_local_obj(md2cmm_obj(mo))); + + rc = mo_object_create(ctx, ch, attr); + + RETURN(rc); } -static int cmm_object_print(struct lu_context *ctx, - struct seq_file *f, const struct lu_object *o) +static int cmm_attr_get(struct lu_context *ctx, struct md_object *mo, + struct lu_attr *attr) { - return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", o); + struct md_object *ch = cmm2child_obj(md2cmm_obj(mo)); + int rc; + + ENTRY; + + LASSERT (cmm_is_local_obj(md2cmm_obj(mo))); + + rc = mo_attr_get(ctx, ch, attr); + + RETURN(rc); } -/* Metadata API */ -static int cmm_object_create(struct lu_context *ctx, - struct md_object *mo, struct lu_attr *attr) +static struct md_object_operations cmm_mo_ops = { + .moo_attr_get = cmm_attr_get, + .moo_object_create = cmm_object_create, +}; + +static int cmm_lookup(struct lu_context *ctx, struct md_object *mo_p, + const char *name, struct lu_fid *lf) { - struct cmm_object *cmo = md2cmm_obj(mo); - struct md_object *nxo = cmm2child_obj(cmo); + struct md_object *ch_p = cmm2child_obj(md2cmm_obj(mo_p)); int rc; ENTRY; + + LASSERT(cmm_is_local_obj(md2cmm_obj(mo_p))); - LASSERT (cmm_is_local_obj(cmo)); - - rc = nxo->mo_ops->moo_object_create(ctx, nxo, attr); + rc = mdo_lookup(ctx, ch_p, name, lf); RETURN(rc); + } -int cmm_mkdir(struct lu_context *ctx, struct lu_attr *attr, - struct md_object *p, const char *name, struct md_object *c) + +static int cmm_mkdir(struct lu_context *ctx, struct lu_attr *attr, + struct md_object *mo_p, const char *name, + struct md_object *mo_c) { - struct cmm_object *cmm_p = md2cmm_obj(p); - struct cmm_object *cmm_c = md2cmm_obj(c); - struct md_object *local = cmm2child_obj(cmm_p); + struct md_object *ch_c = cmm2child_obj(md2cmm_obj(mo_c)); + struct md_object *ch_p = cmm2child_obj(md2cmm_obj(mo_p)); int rc; ENTRY; - if (cmm_is_local_obj(cmm_c)) { + if (cmm_is_local_obj(md2cmm_obj(mo_c))) { /* fully local mkdir */ - rc = local->mo_dir_ops->mdo_mkdir(ctx, attr, local, name, - cmm2child_obj(cmm_c)); + rc = mdo_mkdir(ctx, attr, ch_p, name, ch_c); } else { - const struct lu_fid *fid = lu_object_fid(&c->mo_lu); - struct md_object *remote = cmm2child_obj(cmm_c); + const struct lu_fid *lf = lu_object_fid(&mo_c->mo_lu); /* remote object creation and local name insert */ - rc = remote->mo_ops->moo_object_create(ctx, remote, attr); + rc = mo_object_create(ctx, ch_c, attr); if (rc == 0) { - rc = local->mo_dir_ops->mdo_name_insert(ctx, local, - name, fid, - attr); + rc = mdo_name_insert(ctx, ch_p, name, lf, attr); } } RETURN(rc); } -int cmm_attr_get(struct lu_context *ctx, struct md_object *obj, - struct lu_attr *attr) -{ - struct md_object *next = cmm2child_obj(md2cmm_obj(obj)); - - return next->mo_ops->moo_attr_get(ctx, next, attr); -} - static struct md_dir_operations cmm_dir_ops = { + .mdo_lookup = cmm_lookup, .mdo_mkdir = cmm_mkdir, }; -static struct md_object_operations cmm_mo_ops = { - .moo_attr_get = cmm_attr_get, - .moo_object_create = cmm_object_create, - -}; -static struct lu_object_operations cmm_obj_ops = { - .loo_object_init = cmm_object_init, - .loo_object_release = cmm_object_release, - .loo_object_print = cmm_object_print, - .loo_object_exists = cmm_object_exists -}; -- 1.8.3.1