Whamcloud - gitweb
LU-18162 obdclass: create ldto wrappers and default LU allocator 83/58783/3
authorTimothy Day <timday@amazon.com>
Mon, 14 Apr 2025 20:16:20 +0000 (20:16 +0000)
committerOleg Drokin <green@whamcloud.com>
Fri, 2 May 2025 02:20:00 +0000 (02:20 +0000)
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 <timday@amazon.com>
Change-Id: Iac40138a31a0eef9a2100f958be8e00849301e46
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58783
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lu_object.h
lustre/include/obd_class.h
lustre/llite/vvp_dev.c
lustre/lov/lovsub_dev.c
lustre/obdclass/cl_object.c
lustre/obdclass/lu_object.c
lustre/obdecho/echo_client.c

index 131bed6..1e83626 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdarg.h>
 #endif
 #include <libcfs/libcfs.h>
+#include <obd_support.h>
 #include <uapi/linux/lustre/lustre_idl.h>
 #include <linux/percpu_counter.h>
 #include <linux/rhashtable.h>
@@ -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);
index a76f687..e08b39c 100644 (file)
@@ -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;
                }
index 058b88a..186e852 100644 (file)
@@ -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);
        }
index 5768443..bbbef13 100644 (file)
@@ -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);
index 891ea3b..287fdaa 100644 (file)
@@ -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);
 
index dc03289..cd809df 100644 (file)
@@ -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);
 }
 
 /**
index 2589edc..96255d7 100644 (file)
@@ -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);