From: nikita Date: Fri, 21 Apr 2006 20:34:43 +0000 (+0000) Subject: use container_of0() and fix few lu_device_is_foo() X-Git-Tag: v1_8_0_110~486^2~1951 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=ccb8cb1979c407000f11df8c4df0237c6f14bd8a;p=fs%2Flustre-release.git use container_of0() and fix few lu_device_is_foo() --- diff --git a/lustre/cmm/cmm_device.c b/lustre/cmm/cmm_device.c index 3096a7e..7760207 100644 --- a/lustre/cmm/cmm_device.c +++ b/lustre/cmm/cmm_device.c @@ -52,7 +52,7 @@ static inline int lu_device_is_cmm(struct lu_device *d) /* * XXX for now. Tags in lu_device_type->ldt_something are needed. */ - return ergo(d->ld_ops != NULL, d->ld_ops == &cmm_lu_ops); + return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &cmm_lu_ops); } static struct md_device_operations cmm_md_ops = { @@ -83,7 +83,7 @@ static struct lu_device *cmm_device_fini(struct lu_device *d) return next; } -static int cmm_process_config(struct lu_device *d, struct lustre_cfg *cfg) +static int cmm_process_config(struct lu_device *d, struct lustre_cfg *cfg) { struct cmm_device *m = lu2cmm_dev(d); struct lu_device *next = md2lu_dev(m->cmm_child); @@ -96,7 +96,6 @@ static int cmm_process_config(struct lu_device *d, struct lustre_cfg *cfg) default: err = next->ld_ops->ldo_process_config(next, cfg); } - RETURN(err); } diff --git a/lustre/cmm/cmm_internal.h b/lustre/cmm/cmm_internal.h index 1408cec..fbf81b0 100644 --- a/lustre/cmm/cmm_internal.h +++ b/lustre/cmm/cmm_internal.h @@ -44,13 +44,13 @@ static inline struct md_device_operations *cmm_child_ops(struct cmm_device *d) static inline struct cmm_device *md2cmm_dev(struct md_device *m) { - return container_of(m, struct cmm_device, cmm_md_dev); + return container_of0(m, struct cmm_device, cmm_md_dev); } -static struct cmm_device *lu2cmm_dev(struct lu_device *d) +static inline struct cmm_device *lu2cmm_dev(struct lu_device *d) { //LASSERT(lu_device_is_cmm(d)); - return container_of(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) @@ -70,13 +70,13 @@ static inline struct cmm_device *cmm_obj2dev(struct cmm_object *c) static inline struct cmm_object *lu2cmm_obj(struct lu_object *o) { //LASSERT(lu_device_is_cmm(o->lo_dev)); - return container_of(o, struct cmm_object, cmo_obj.mo_lu); + 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_of(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) diff --git a/lustre/include/linux/md_object.h b/lustre/include/linux/md_object.h index 0de87aa..80c5ef0 100644 --- a/lustre/include/linux/md_object.h +++ b/lustre/include/linux/md_object.h @@ -103,13 +103,13 @@ struct md_object { static inline int lu_device_is_md(const struct lu_device *d) { - return d->ld_type->ldt_tags & LU_DEVICE_MD; + return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD); } static inline struct md_device *lu2md_dev(const struct lu_device *d) { LASSERT(lu_device_is_md(d)); - return container_of(d, struct md_device, md_lu_dev); + return container_of0(d, struct md_device, md_lu_dev); } static inline struct lu_device *md2lu_dev(struct md_device *d) @@ -120,7 +120,7 @@ static inline struct lu_device *md2lu_dev(struct md_device *d) static inline struct md_object *lu2md(const struct lu_object *o) { LASSERT(lu_device_is_md(o->lo_dev)); - return container_of(o, struct md_object, mo_lu); + return container_of0(o, struct md_object, mo_lu); } static inline struct md_object *md_object_next(const struct md_object *obj) @@ -131,7 +131,7 @@ static inline struct md_object *md_object_next(const struct md_object *obj) static inline struct md_device *md_device_get(const struct md_object *o) { LASSERT(lu_device_is_md(o->mo_lu.lo_dev)); - return container_of(o->mo_lu.lo_dev, struct md_device, md_lu_dev); + return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev); } static inline int md_device_init(struct md_device *md, struct lu_device_type *t) diff --git a/lustre/mdd/mdd_handler.c b/lustre/mdd/mdd_handler.c index 4a2dd6b..4aad606 100644 --- a/lustre/mdd/mdd_handler.c +++ b/lustre/mdd/mdd_handler.c @@ -63,13 +63,13 @@ static int lu_device_is_mdd(struct lu_device *d) /* * XXX for now. Tags in lu_device_type->ldt_something are needed. */ - return ergo(d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops); + return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops); } static struct mdd_device* lu2mdd_dev(struct lu_device *d) { LASSERT(lu_device_is_mdd(d)); - return container_of(d, struct mdd_device, mdd_md_dev.md_lu_dev); + return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev); } static inline struct lu_device *mdd2lu_dev(struct mdd_device *d) @@ -80,7 +80,7 @@ static inline struct lu_device *mdd2lu_dev(struct mdd_device *d) static struct mdd_object *mdd_obj(struct lu_object *o) { LASSERT(lu_device_is_mdd(o->lo_dev)); - return container_of(o, struct mdd_object, mod_obj.mo_lu); + return container_of0(o, struct mdd_object, mod_obj.mo_lu); } static struct mdd_device* mdo2mdd(struct md_object *mdo) @@ -90,7 +90,7 @@ static struct mdd_device* mdo2mdd(struct md_object *mdo) static struct mdd_object* mdo2mddo(struct md_object *mdo) { - return container_of(mdo, struct mdd_object, mod_obj); + return container_of0(mdo, struct mdd_object, mod_obj); } static inline struct dt_device_operations *mdd_child_ops(struct mdd_device *d) @@ -298,7 +298,7 @@ static struct lu_device *mdd_device_fini(struct lu_device *d) return next; } -static int mdd_process_config(struct lu_device *d, struct lustre_cfg *cfg) +static int mdd_process_config(struct lu_device *d, struct lustre_cfg *cfg) { struct mdd_device *m = lu2mdd_dev(d); struct lu_device *next = &m->mdd_child->dd_lu_dev; @@ -324,8 +324,8 @@ static struct lu_device_operations mdd_lu_ops = { static struct dt_object* mdd_object_child(struct mdd_object *o) { - return container_of(lu_object_next(&o->mod_obj.mo_lu), - struct dt_object, do_lu); + return container_of0(lu_object_next(&o->mod_obj.mo_lu), + struct dt_object, do_lu); } static void mdd_lock(struct lu_context *ctxt, diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index 7434a69..6f9a6bf 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -118,7 +118,7 @@ static void lu_object_free(struct lu_context *ctx, struct lu_object *o) INIT_LIST_HEAD(&splice); list_splice_init(&o->lo_header->loh_layers, &splice); while (!list_empty(&splice)) { - o = container_of(splice.next, struct lu_object, lo_linkage); + o = container_of0(splice.next, struct lu_object, lo_linkage); list_del_init(&o->lo_linkage); LASSERT(lu_object_ops(o)->ldo_object_free != NULL); lu_object_ops(o)->ldo_object_free(ctx, o); @@ -143,7 +143,7 @@ void lu_site_purge(struct lu_context *ctx, struct lu_site *s, int nr) } spin_unlock(&s->ls_guard); while (!list_empty(&dispose)) { - h = container_of(dispose.next, + h = container_of0(dispose.next, struct lu_object_header, loh_lru); list_del_init(&h->loh_lru); lu_object_free(ctx, lu_object_top(h)); @@ -292,6 +292,7 @@ void lu_site_fini(struct lu_site *s) s->ls_hash = NULL; } if (s->ls_top_dev != NULL) { + s->ls_top_dev->ld_site = NULL; lu_device_put(s->ls_top_dev); s->ls_top_dev = NULL; } diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index f95a7c3..01d250a 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -68,7 +68,6 @@ static void osd_object_release(struct lu_context *ctxt, struct lu_object *l); static int osd_object_print (struct lu_context *ctx, struct seq_file *f, const struct lu_object *o); static void osd_device_free (struct lu_device *m); -static struct lu_device *osd_device_fini (struct lu_device *d); static int osd_device_init (struct lu_device *d, struct lu_device *); static void *osd_key_init (struct lu_context *ctx); static void osd_key_fini (struct lu_context *ctx, void *data); @@ -80,6 +79,7 @@ static int osd_inode_getattr (struct lu_context *ctx, static struct osd_object *osd_obj (const struct lu_object *o); static struct osd_device *osd_dev (const struct lu_device *d); static struct osd_device *osd_dt_dev (const struct dt_device *d); +static struct lu_device *osd_device_fini (struct lu_device *d); static struct lu_device *osd_device_alloc (struct lu_device_type *t, struct lustre_cfg *cfg); static struct lu_object *osd_object_alloc (struct lu_context *ctx, @@ -265,7 +265,7 @@ static int osd_mount(struct osd_device *o, struct lustre_cfg *cfg) int result; ENTRY; - + /* get mount */ lmi = server_get_mount(dev); if (lmi == NULL) { @@ -300,7 +300,7 @@ static struct lu_device *osd_device_fini(struct lu_device *d) o->od_root_dir = NULL; } osd_oi_fini(&o->od_oi); - + if (o->od_mount) server_put_mount(o->od_mount->lmi_name, o->od_mount->lmi_mnt); @@ -334,7 +334,7 @@ static void osd_device_free(struct lu_device *d) OBD_FREE_PTR(o); } -static int osd_process_config(struct lu_device *d, struct lustre_cfg *cfg) +static int osd_process_config(struct lu_device *d, struct lustre_cfg *cfg) { struct osd_device *o = lu2osd_dev(d); int err; @@ -342,6 +342,9 @@ static int osd_process_config(struct lu_device *d, struct lustre_cfg *cfg) switch(cfg->lcfg_command) { case LCFG_SETUP: err = osd_mount(o, cfg); + break; + default: + err = -ENOTTY; } RETURN(err); @@ -490,25 +493,25 @@ static int lu_device_is_osd(const struct lu_device *d) /* * XXX for now. Tags in lu_device_type->ldt_something are needed. */ - return ergo(d->ld_ops != NULL, d->ld_ops == &osd_lu_ops); + return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops); } static struct osd_object *osd_obj(const struct lu_object *o) { LASSERT(lu_device_is_osd(o->lo_dev)); - return container_of(o, struct osd_object, oo_dt.do_lu); + return container_of0(o, struct osd_object, oo_dt.do_lu); } static struct osd_device *osd_dt_dev(const struct dt_device *d) { LASSERT(lu_device_is_osd(&d->dd_lu_dev)); - return container_of(d, struct osd_device, od_dt_dev); + return container_of0(d, struct osd_device, od_dt_dev); } static struct osd_device *osd_dev(const struct lu_device *d) { LASSERT(lu_device_is_osd(d)); - return osd_dt_dev(container_of(d, struct dt_device, dd_lu_dev)); + return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev)); } static struct super_block *osd_sb(const struct osd_device *dev) diff --git a/lustre/osd/osd_internal.h b/lustre/osd/osd_internal.h index 4ca9db8..0bdac67 100644 --- a/lustre/osd/osd_internal.h +++ b/lustre/osd/osd_internal.h @@ -60,22 +60,22 @@ struct osd_device { static inline struct osd_object * dt2osd_obj(struct dt_object *o) { - return container_of(o, struct osd_object, oo_dt); + return container_of0(o, struct osd_object, oo_dt); } static inline struct osd_device * osd_obj2dev(struct osd_object *o) { struct lu_device *lu = o->oo_dt.do_lu.lo_dev; - struct dt_device *dt = container_of(lu, struct dt_device, dd_lu_dev); + struct dt_device *dt = container_of0(lu, struct dt_device, dd_lu_dev); - return container_of(dt, struct osd_device, od_dt_dev); + return container_of0(dt, struct osd_device, od_dt_dev); } static inline struct osd_device * dt2osd_dev(struct dt_device *dt) { - return container_of(dt, struct osd_device, od_dt_dev); + return container_of0(dt, struct osd_device, od_dt_dev); } static inline struct osd_device * lu2osd_dev(struct lu_device *d) { - return dt2osd_dev(container_of(d, struct dt_device, dd_lu_dev)); + return dt2osd_dev(container_of0(d, struct dt_device, dd_lu_dev)); } static inline struct lu_device * osd2lu_dev(struct osd_device * osd)