From d04233bbdcb04780b10cae9de5e4d78c23cfca73 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Mon, 14 Apr 2025 20:16:20 +0000 Subject: [PATCH] LU-18162 obdclass: create ldto wrappers and default LU allocator Wrap calls to ldto_device_* methods with small wrapper functions. This allows for default behavior to be defined when the ldto_device_* methods are not defined. Define a default allocator when ldto_device_alloc and ldto_device_free are not provided. This will allow many of the simplier OBD devices to be fully converted to LU devices without as much boilerplate. Similarly, allow ldto_device_init/fini to be optional. Signed-off-by: Timothy Day Change-Id: Iac40138a31a0eef9a2100f958be8e00849301e46 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58783 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Arshad Hussain Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/lu_object.h | 72 ++++++++++++++++++++++++++++++++++++++++++++ lustre/include/obd_class.h | 6 ++-- lustre/llite/vvp_dev.c | 3 +- lustre/lov/lovsub_dev.c | 2 +- lustre/obdclass/cl_object.c | 47 +++++++++++++++-------------- lustre/obdclass/lu_object.c | 9 ++---- lustre/obdecho/echo_client.c | 9 +++--- 7 files changed, 109 insertions(+), 39 deletions(-) diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 131bed6..1e83626 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -20,6 +20,7 @@ #include #endif #include +#include #include #include #include @@ -387,6 +388,77 @@ struct lu_device_type_operations { void (*ldto_stop)(struct lu_device_type *t); }; +static inline struct lu_device *ldto_device_alloc(const struct lu_env *env, + struct lu_device_type *ldt, + struct lustre_cfg *lcfg) +{ + const struct lu_device_type_operations *ldto; + struct lu_device *lu; + + LASSERT(ldt); + ldto = ldt->ldt_ops; + LASSERT(ldto); + + if (ldto->ldto_device_alloc) + return ldto->ldto_device_alloc(env, ldt, lcfg); + + OBD_ALLOC_PTR(lu); + if (!lu) + return ERR_PTR(-ENOMEM); + + return lu; +} + +static inline struct lu_device *ldto_device_free(const struct lu_env *env, + struct lu_device *lu) +{ + const struct lu_device_type_operations *ldto; + + LASSERT(lu); + LASSERT(lu->ld_type); + ldto = lu->ld_type->ldt_ops; + LASSERT(ldto); + + if (ldto->ldto_device_free) + return ldto->ldto_device_free(env, lu); + + OBD_FREE_PTR(lu); + return NULL; +} + +static inline int ldto_device_init(const struct lu_env *env, + struct lu_device *lu, const char *name, + struct lu_device *lu2) +{ + const struct lu_device_type_operations *ldto; + + LASSERT(lu); + LASSERT(lu->ld_type); + ldto = lu->ld_type->ldt_ops; + LASSERT(ldto); + + if (ldto->ldto_device_init) + return ldto->ldto_device_init(env, lu, name, lu2); + + return 0; +} + +static inline struct lu_device *ldto_device_fini(const struct lu_env *env, + struct lu_device *lu) +{ + const struct lu_device_type_operations *ldto; + + LASSERT(lu); + LASSERT(lu->ld_type); + ldto = lu->ld_type->ldt_ops; + LASSERT(ldto); + + if (ldto->ldto_device_fini) + return ldto->ldto_device_fini(env, lu); + + return NULL; +} + static inline int lu_device_is_md(const struct lu_device *d) { return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD); diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index a76f687..e08b39c 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -585,7 +585,7 @@ static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg) if (rc == 0) { struct lu_device *dev; env.le_ses = &session_ctx; - dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg); + dev = ldto_device_alloc(&env, ldt, cfg); lu_env_fini(&env); if (!IS_ERR(dev)) { obd->obd_lu_dev = dev; @@ -628,7 +628,7 @@ static inline int obd_precleanup(struct obd_device *obd) env = &_env; rc = lu_env_add(env); } - ldt->ldt_ops->ldto_device_fini(env, d); + ldto_device_fini(env, d); if (env == &_env) { if (rc == 0) lu_env_remove(env); @@ -655,7 +655,7 @@ static inline int obd_cleanup(struct obd_device *obd) rc = lu_env_init(&env, ldt->ldt_ctx_tags); if (rc == 0) { - ldt->ldt_ops->ldto_device_free(&env, d); + ldto_device_free(&env, d); lu_env_fini(&env); obd->obd_lu_dev = NULL; } diff --git a/lustre/llite/vvp_dev.c b/lustre/llite/vvp_dev.c index 058b88a..186e852 100644 --- a/lustre/llite/vvp_dev.c +++ b/lustre/llite/vvp_dev.c @@ -212,8 +212,7 @@ static int vvp_device_init(const struct lu_env *env, struct lu_device *d, LASSERT(d->ld_site != NULL && next->ld_type != NULL); next->ld_site = d->ld_site; - rc = next->ld_type->ldt_ops->ldto_device_init( - env, next, next->ld_type->ldt_name, NULL); + rc = ldto_device_init(env, next, next->ld_type->ldt_name, NULL); if (rc == 0) { lu_device_get(next); } diff --git a/lustre/lov/lovsub_dev.c b/lustre/lov/lovsub_dev.c index 5768443..bbbef13 100644 --- a/lustre/lov/lovsub_dev.c +++ b/lustre/lov/lovsub_dev.c @@ -37,7 +37,7 @@ static int lovsub_device_init(const struct lu_env *env, struct lu_device *d, next->ld_site = d->ld_site; ldt = next->ld_type; LASSERT(ldt != NULL); - rc = ldt->ldt_ops->ldto_device_init(env, next, ldt->ldt_name, NULL); + rc = ldto_device_init(env, next, ldt->ldt_name, NULL); if (rc) { next->ld_site = NULL; RETURN(rc); diff --git a/lustre/obdclass/cl_object.c b/lustre/obdclass/cl_object.c index 891ea3b..287fdaa 100644 --- a/lustre/obdclass/cl_object.c +++ b/lustre/obdclass/cl_object.c @@ -1008,32 +1008,35 @@ EXPORT_SYMBOL(cl_env_percpu_get); */ struct cl_device *cl_type_setup(const struct lu_env *env, struct lu_site *site, - struct lu_device_type *ldt, - struct lu_device *next) + struct lu_device_type *ldt, + struct lu_device *next) { - const char *typename; - struct lu_device *d; + const char *typename; + struct lu_device *d; - LASSERT(ldt != NULL); + LASSERT(ldt); - typename = ldt->ldt_name; - d = ldt->ldt_ops->ldto_device_alloc(env, ldt, NULL); - if (!IS_ERR(d)) { - int rc; + typename = ldt->ldt_name; + d = ldto_device_alloc(env, ldt, NULL); + if (!IS_ERR(d)) { + int rc; - if (site != NULL) - d->ld_site = site; - rc = ldt->ldt_ops->ldto_device_init(env, d, typename, next); - if (rc == 0) { - lu_device_get(d); - } else { - ldt->ldt_ops->ldto_device_free(env, d); - CERROR("can't init device '%s', %d\n", typename, rc); - d = ERR_PTR(rc); - } - } else - CERROR("Cannot allocate device: '%s'\n", typename); - return lu2cl_dev(d); + if (site) + d->ld_site = site; + + rc = ldto_device_init(env, d, typename, next); + if (rc == 0) { + lu_device_get(d); + } else { + ldto_device_free(env, d); + CERROR("can't init device '%s', %d\n", typename, rc); + d = ERR_PTR(rc); + } + } else { + CERROR("Cannot allocate device: '%s'\n", typename); + } + + return lu2cl_dev(d); } EXPORT_SYMBOL(cl_type_setup); diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index dc03289..cd809df 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -1339,18 +1339,15 @@ void lu_stack_fini(const struct lu_env *env, struct lu_device *top) lu_site_purge(env, site, ~0); for (scan = top; scan != NULL; scan = next) { - next = scan->ld_type->ldt_ops->ldto_device_fini(env, scan); + next = ldto_device_fini(env, scan); lu_device_put(scan); } /* purge again. */ lu_site_purge(env, site, ~0); - for (scan = top; scan != NULL; scan = next) { - const struct lu_device_type *ldt = scan->ld_type; - - next = ldt->ldt_ops->ldto_device_free(env, scan); - } + for (scan = top; scan != NULL; scan = next) + next = ldto_device_free(env, scan); } /** diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 2589edc..96255d7 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -726,9 +726,8 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env, GOTO(out, rc = -EBUSY); next->ld_site = ed->ed_site; - rc = next->ld_type->ldt_ops->ldto_device_init(env, next, - next->ld_type->ldt_name, - NULL); + rc = ldto_device_init(env, next, next->ld_type->ldt_name, + NULL); if (rc) GOTO(out, rc); } else { @@ -780,7 +779,7 @@ static struct lu_device *echo_device_fini(const struct lu_env *env, struct lu_device *next = ed->ed_next; while (next && !ed->ed_next_ismd) - next = next->ld_type->ldt_ops->ldto_device_fini(env, next); + next = ldto_device_fini(env, next); return NULL; } @@ -836,7 +835,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env, echo_ed_los_fini(env, ed); #endif while (next && !ed->ed_next_ismd) - next = next->ld_type->ldt_ops->ldto_device_free(env, next); + next = ldto_device_free(env, next); LASSERT(ed->ed_site == d->ld_site); echo_site_fini(env, ed); -- 1.8.3.1