From 225e268c61f1ffada7c9a43f0952bd7bc8102f25 Mon Sep 17 00:00:00 2001 From: nikita Date: Sat, 18 Oct 2008 17:17:44 +0000 Subject: [PATCH] Introduce two new methods in lu_device_type_operations, that are invoked when first instance of a given type is created and last one is destroyed respectively. This is need by CLIO. b=16450 --- lustre/ChangeLog | 7 ++++ lustre/cmm/cmm_device.c | 3 ++ lustre/cmm/mdc_device.c | 3 ++ lustre/include/lu_object.h | 11 ++++++ lustre/mdt/mdt_handler.c | 3 ++ lustre/obdclass/autoMakefile.am | 1 + lustre/obdclass/genops.c | 4 +-- lustre/obdclass/lu_object.c | 75 +++++++++++++++++++++++++++++++++-------- 8 files changed, 91 insertions(+), 16 deletions(-) diff --git a/lustre/ChangeLog b/lustre/ChangeLog index 3a5d5bc..a0e72e8 100644 --- a/lustre/ChangeLog +++ b/lustre/ChangeLog @@ -1608,6 +1608,13 @@ Details : Introduce new lu_context functions that are needed on the client side, where some system threads (ptlrpcd) are shared by multiple modules, and so cannot be stopped during module shutdown. +Severity : normal +Bugzilla : 16450 +Description: Add start and stop methods to lu_device_type_operations. +Details : Introduce two new methods in lu_device_type_operations, that are + invoked when first instance of a given type is created and last one + is destroyed respectively. This is need by CLIO. + -------------------------------------------------------------------------------- 2007-08-10 Cluster File Systems, Inc. diff --git a/lustre/cmm/cmm_device.c b/lustre/cmm/cmm_device.c index 3cf494b..38c62da 100644 --- a/lustre/cmm/cmm_device.c +++ b/lustre/cmm/cmm_device.c @@ -483,6 +483,9 @@ static struct lu_device_type_operations cmm_device_type_ops = { .ldto_init = cmm_type_init, .ldto_fini = cmm_type_fini, + .ldto_start = cmm_type_start, + .ldto_stop = cmm_type_stop, + .ldto_device_alloc = cmm_device_alloc, .ldto_device_free = cmm_device_free, diff --git a/lustre/cmm/mdc_device.c b/lustre/cmm/mdc_device.c index 568d608..21dada3 100644 --- a/lustre/cmm/mdc_device.c +++ b/lustre/cmm/mdc_device.c @@ -321,6 +321,9 @@ static struct lu_device_type_operations mdc_device_type_ops = { .ldto_init = mdc_type_init, .ldto_fini = mdc_type_fini, + .ldto_start = mdc_type_start, + .ldto_stop = mdc_type_stop, + .ldto_device_alloc = mdc_device_alloc, .ldto_device_free = mdc_device_free, diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index c1ab0d3..50665df 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -1170,6 +1170,17 @@ void lu_context_key_revive (struct lu_context_key *key); } \ struct __##mod##_dummy_type_fini {;} +#define LU_TYPE_START(mod, ...) \ + static void mod##_type_start(struct lu_device_type *t) \ + { \ + } \ + struct __##mod##_dummy_type_start {;} + +#define LU_TYPE_STOP(mod, ...) \ + static void mod##_type_stop(struct lu_device_type *t) \ + { \ + } \ + struct __##mod##_dummy_type_stop {;} diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 3667afa..6a3fad4 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -4804,6 +4804,9 @@ static struct lu_device_type_operations mdt_device_type_ops = { .ldto_init = mdt_type_init, .ldto_fini = mdt_type_fini, + .ldto_start = mdt_type_start, + .ldto_stop = mdt_type_stop, + .ldto_device_alloc = mdt_device_alloc, .ldto_device_free = mdt_device_free, .ldto_device_fini = mdt_device_fini diff --git a/lustre/obdclass/autoMakefile.am b/lustre/obdclass/autoMakefile.am index 21886e6..44ae5ac 100644 --- a/lustre/obdclass/autoMakefile.am +++ b/lustre/obdclass/autoMakefile.am @@ -11,6 +11,7 @@ liblustreclass_a_SOURCES = class_obd.c debug.c genops.c statfs_pack.c mea.c uuid liblustreclass_a_SOURCES += lustre_handles.c lustre_peer.c lprocfs_status.c class_hash.c liblustreclass_a_SOURCES += obdo.c obd_config.c llog.c llog_obd.c llog_cat.c liblustreclass_a_SOURCES += llog_lvfs.c llog_swab.c capa.c +liblustreclass_a_SOURCES += lu_object.c liblustreclass_a_SOURCES += #llog_ioctl.c rbtree.c liblustreclass_a_CPPFLAGS = $(LLCPPFLAGS) liblustreclass_a_CFLAGS = $(LLCFLAGS) diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 2a92609..713a41c 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -194,7 +194,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, #endif if (ldt != NULL) { type->typ_lu = ldt; - rc = ldt->ldt_ops->ldto_init(ldt); + rc = lu_device_type_init(ldt); if (rc != 0) GOTO (failed, rc); } @@ -240,7 +240,7 @@ int class_unregister_type(const char *name) } if (type->typ_lu) - type->typ_lu->ldt_ops->ldto_fini(type->typ_lu); + lu_device_type_fini(type->typ_lu); spin_lock(&obd_types_lock); list_del(&type->typ_chain); diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index 30c4fe2..a097d69 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -518,18 +518,54 @@ struct lu_object *lu_object_find(const struct lu_env *env, EXPORT_SYMBOL(lu_object_find); /* +/** + * Global list of all device types. + */ +static CFS_LIST_HEAD(lu_device_types); + +int lu_device_type_init(struct lu_device_type *ldt) +{ + int result; + + CFS_INIT_LIST_HEAD(&ldt->ldt_linkage); + result = ldt->ldt_ops->ldto_init(ldt); + if (result == 0) + list_add(&ldt->ldt_linkage, &lu_device_types); + return result; +} +EXPORT_SYMBOL(lu_device_type_init); + +void lu_device_type_fini(struct lu_device_type *ldt) +{ + list_del_init(&ldt->ldt_linkage); + ldt->ldt_ops->ldto_fini(ldt); +} +EXPORT_SYMBOL(lu_device_type_fini); + +void lu_types_stop(void) +{ + struct lu_device_type *ldt; + + list_for_each_entry(ldt, &lu_device_types, ldt_linkage) { + if (ldt->ldt_device_nr == 0) + ldt->ldt_ops->ldto_stop(ldt); + } +} +EXPORT_SYMBOL(lu_types_stop); + +/** * Global list of all sites on this node */ static CFS_LIST_HEAD(lu_sites); static DECLARE_MUTEX(lu_sites_guard); -/* +/** * Global environment used by site shrinker. */ static struct lu_env lu_shrink_env; -/* - * Print all objects in @s. +/** + * Print all objects in \a s. */ void lu_site_print(const struct lu_env *env, struct lu_site *s, void *cookie, lu_printer_t printer) @@ -673,8 +709,8 @@ int lu_site_init_finish(struct lu_site *s) } EXPORT_SYMBOL(lu_site_init_finish); -/* - * Acquire additional reference on device @d +/** + * Acquire additional reference on device \a d */ void lu_device_get(struct lu_device *d) { @@ -682,44 +718,55 @@ void lu_device_get(struct lu_device *d) } EXPORT_SYMBOL(lu_device_get); -/* - * Release reference on device @d. +/** + * Release reference on device \a d. */ void lu_device_put(struct lu_device *d) { + LASSERT(atomic_read(&d->ld_ref) > 0); atomic_dec(&d->ld_ref); } EXPORT_SYMBOL(lu_device_put); -/* - * Initialize device @d of type @t. +/** + * Initialize device \a d of type \a t. */ int lu_device_init(struct lu_device *d, struct lu_device_type *t) { + if (t->ldt_device_nr++ == 0 && t->ldt_ops->ldto_start != NULL) + t->ldt_ops->ldto_start(t); memset(d, 0, sizeof *d); atomic_set(&d->ld_ref, 0); d->ld_type = t; + lu_ref_init(&d->ld_reference); return 0; } EXPORT_SYMBOL(lu_device_init); -/* - * Finalize device @d. +/** + * Finalize device \a d. */ void lu_device_fini(struct lu_device *d) { + struct lu_device_type *t; + + t = d->ld_type; if (d->ld_obd != NULL) /* finish lprocfs */ lprocfs_obd_cleanup(d->ld_obd); + lu_ref_fini(&d->ld_reference); LASSERTF(atomic_read(&d->ld_ref) == 0, "Refcount is %u\n", atomic_read(&d->ld_ref)); + LASSERT(t->ldt_device_nr > 0); + if (--t->ldt_device_nr == 0 && t->ldt_ops->ldto_stop != NULL) + t->ldt_ops->ldto_stop(t); } EXPORT_SYMBOL(lu_device_fini); -/* - * Initialize object @o that is part of compound object @h and was created by - * device @d. +/** + * Initialize object \a o that is part of compound object \a h and was created + * by device \a d. */ int lu_object_init(struct lu_object *o, struct lu_object_header *h, struct lu_device *d) -- 1.8.3.1