Whamcloud - gitweb
LU-17848 osd: deduplicate osd_fid_init()/fini()/alloc() 10/55110/6
authorTimothy Day <timday@amazon.com>
Tue, 14 May 2024 20:59:16 +0000 (20:59 +0000)
committerOleg Drokin <green@whamcloud.com>
Wed, 29 May 2024 04:52:28 +0000 (04:52 +0000)
These functions are identical in the two OSD implementations. This
can be moved to lustre/fid/ and made generic.

These functions are forced to live in fid.ko rather than obdclass.ko
due to module dependency issues.

Signed-off-by: Timothy Day <timday@amazon.com>
Change-Id: If97ca5615d9bdfe0fe9886686e9ce3ec2b740f7d
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55110
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Mikhail Pershin <mpershin@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/fid/fid_lib.c
lustre/include/dt_object.h
lustre/include/lustre_fid.h
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_io.c
lustre/osd-zfs/osd_handler.c
lustre/osd-zfs/osd_internal.h

index 2d247a6..5acf5df 100644 (file)
 
 #include <libcfs/libcfs.h>
 #include <linux/module.h>
+#include <obd.h>
+#include <obd_class.h>
+#include <obd_support.h>
 #include <lustre_fid.h>
 
+#include "fid_internal.h"
+
 /**
  * A cluster-wide range from which fid-sequences are granted to servers and
  * then clients.
@@ -84,3 +89,59 @@ const struct lu_fid LU_BACKEND_LPF_FID = { .f_seq = FID_SEQ_LOCAL_FILE,
                                           .f_oid = OSD_LPF_OID,
                                           .f_ver = 0x0000000000000000 };
 EXPORT_SYMBOL(LU_BACKEND_LPF_FID);
+
+int fid_alloc_generic(const struct lu_env *env, struct lu_device *lu,
+                     struct lu_fid *fid, struct lu_object *parent,
+                     const struct lu_name *name)
+{
+       struct dt_device *dt = container_of(lu, struct dt_device,
+                                           dd_lu_dev);
+
+       return seq_client_alloc_fid(env, dt->dd_cl_seq, fid);
+}
+EXPORT_SYMBOL(fid_alloc_generic);
+
+int seq_target_init(const struct lu_env *env,
+                   struct dt_device *dt, char *svname,
+                   bool is_ost)
+{
+       struct seq_server_site *ss = dt->dd_lu_dev.ld_site->ld_seq_site;
+       int rc = 0;
+
+       if (is_ost || dt->dd_cl_seq != NULL)
+               return 0;
+
+       if (unlikely(!ss))
+               return -ENODEV;
+
+       OBD_ALLOC_PTR(dt->dd_cl_seq);
+       if (!dt->dd_cl_seq)
+               return -ENOMEM;
+
+       seq_client_init(dt->dd_cl_seq, NULL, LUSTRE_SEQ_METADATA,
+                       svname, ss->ss_server_seq);
+
+       /*
+        * If the OSD on the sequence controller(MDT0), then allocate
+        * sequence here, otherwise allocate sequence after connected
+        * to MDT0 (see mdt_register_lwp_callback()).
+        */
+       if (!ss->ss_node_id)
+               rc = seq_server_alloc_meta(dt->dd_cl_seq->lcs_srv,
+                                  &dt->dd_cl_seq->lcs_space, env);
+
+       return rc;
+}
+EXPORT_SYMBOL(seq_target_init);
+
+void seq_target_fini(const struct lu_env *env,
+                    struct dt_device *dt)
+{
+       if (!dt->dd_cl_seq)
+               return;
+
+       seq_client_fini(dt->dd_cl_seq);
+       OBD_FREE_PTR(dt->dd_cl_seq);
+       dt->dd_cl_seq = NULL;
+}
+EXPORT_SYMBOL(seq_target_fini);
index 3b15bf3..04d2764 100644 (file)
@@ -1879,6 +1879,7 @@ enum dt_otable_it_flags {
 struct dt_device {
        struct lu_device                   dd_lu_dev;
        const struct dt_device_operations *dd_ops;
+       struct lu_client_seq              *dd_cl_seq;
 
        /**
         * List of dt_txn_callback (see below). This is not protected in any
index c454a37..079c659 100644 (file)
  */
 
 #include <libcfs/libcfs.h>
+#include <lu_object.h>
 #include <uapi/linux/lustre/lustre_fid.h>
 #include <uapi/linux/lustre/lustre_idl.h>
 #include <uapi/linux/lustre/lustre_ostid.h>
@@ -526,6 +527,18 @@ int seq_server_set_cli(const struct lu_env *env,
 
 int seq_server_check_and_alloc_super(const struct lu_env *env,
                                     struct lu_server_seq *seq);
+
+int fid_alloc_generic(const struct lu_env *env, struct lu_device *lu,
+                     struct lu_fid *fid, struct lu_object *parent,
+                     const struct lu_name *name);
+
+int seq_target_init(const struct lu_env *env,
+                   struct dt_device *dt, char *svname,
+                   bool is_ost);
+
+void seq_target_fini(const struct lu_env *env,
+                    struct dt_device *dt);
+
 /* Client methods */
 void seq_client_init(struct lu_client_seq *seq,
                     struct obd_export *exp,
index a101ffb..a292a4c 100644 (file)
@@ -8216,49 +8216,6 @@ static int osd_device_init(const struct lu_env *env, struct lu_device *d,
        return osd_procfs_init(osd, name);
 }
 
-static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
-{
-       struct seq_server_site *ss = osd_seq_site(osd);
-       int rc = 0;
-
-       ENTRY;
-
-       if (osd->od_is_ost || osd->od_cl_seq != NULL)
-               RETURN(0);
-
-       if (unlikely(ss == NULL))
-               RETURN(-ENODEV);
-
-       OBD_ALLOC_PTR(osd->od_cl_seq);
-       if (osd->od_cl_seq == NULL)
-               RETURN(-ENOMEM);
-
-       seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
-                       osd->od_svname, ss->ss_server_seq);
-
-       if (ss->ss_node_id == 0) {
-               /*
-                * If the OSD on the sequence controller(MDT0), then allocate
-                * sequence here, otherwise allocate sequence after connected
-                * to MDT0 (see mdt_register_lwp_callback()).
-                */
-               rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
-                                  &osd->od_cl_seq->lcs_space, env);
-       }
-
-       RETURN(rc);
-}
-
-static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
-{
-       if (osd->od_cl_seq == NULL)
-               return;
-
-       seq_client_fini(osd->od_cl_seq);
-       OBD_FREE_PTR(osd->od_cl_seq);
-       osd->od_cl_seq = NULL;
-}
-
 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
 {
        ENTRY;
@@ -8278,7 +8235,7 @@ static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
                qsd_fini(env, qsd);
        }
 
-       osd_fid_fini(env, o);
+       seq_target_fini(env, &o->od_dt_dev);
        osd_scrub_cleanup(env, o);
 
        RETURN(0);
@@ -8904,27 +8861,13 @@ static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
 #endif
        }
 
-       result = osd_fid_init(env, osd);
+       result = seq_target_init(env, &osd->od_dt_dev,
+                                osd->od_svname,
+                                osd->od_is_ost);
 
        RETURN(result);
 }
 
-/**
- * Implementation of lu_device_operations::ldo_fid_alloc() for OSD
- *
- * Allocate FID.
- *
- * see include/lu_object.h for the details.
- */
-static int osd_fid_alloc(const struct lu_env *env, struct lu_device *d,
-                        struct lu_fid *fid, struct lu_object *parent,
-                        const struct lu_name *name)
-{
-       struct osd_device *osd = osd_dev(d);
-
-       return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
-}
-
 static const struct lu_object_operations osd_lu_obj_ops = {
        .loo_object_init      = osd_object_init,
        .loo_object_delete    = osd_object_delete,
@@ -8939,7 +8882,7 @@ const struct lu_device_operations osd_lu_ops = {
        .ldo_process_config    = osd_process_config,
        .ldo_recovery_complete = osd_recovery_complete,
        .ldo_prepare           = osd_prepare,
-       .ldo_fid_alloc         = osd_fid_alloc,
+       .ldo_fid_alloc         = fid_alloc_generic,
 };
 
 static const struct lu_device_type_operations osd_device_type_ops = {
index 3cc562a..0325e66 100644 (file)
@@ -338,8 +338,6 @@ struct osd_device {
        /* quota slave instance for block */
        struct qsd_instance     *od_quota_slave_dt;
 
-       /* osd seq instance */
-       struct lu_client_seq    *od_cl_seq;
        /* If the ratio of "the total OI mappings count" vs
         * "the bad OI mappings count" is lower than the
         * osd_device::od_full_scrub_ratio, then trigger
index 7f6688a..1eea451 100644 (file)
@@ -1973,7 +1973,7 @@ static int osd_ldiskfs_write_record(struct dt_object *dt, void *buf,
                         * XXX: this is a workaround until we have a proper
                         *      fix in mballoc
                         * XXX: works with extent-based files only */
-                       if (!osd->od_cl_seq)
+                       if (!osd->od_dt_dev.dd_cl_seq)
                                flags |= LDISKFS_GET_BLOCKS_NO_NORMALIZE;
                        bh = __ldiskfs_bread(handle, inode, block, flags);
                        create = true;
index a278d17..f1c53a7 100644 (file)
@@ -810,16 +810,6 @@ struct lu_context_key osd_key = {
        .lct_exit = osd_key_exit
 };
 
-static void osd_fid_fini(const struct lu_env *env, struct osd_device *osd)
-{
-       if (osd->od_cl_seq == NULL)
-               return;
-
-       seq_client_fini(osd->od_cl_seq);
-       OBD_FREE_PTR(osd->od_cl_seq);
-       osd->od_cl_seq = NULL;
-}
-
 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
 {
        ENTRY;
@@ -840,7 +830,8 @@ static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
                qsd_fini(env, o->od_quota_slave_dt);
                o->od_quota_slave_dt = NULL;
        }
-       osd_fid_fini(env, o);
+
+       seq_target_fini(env, &o->od_dt_dev);
 
        RETURN(0);
 }
@@ -1555,38 +1546,6 @@ static int osd_obd_disconnect(struct obd_export *exp)
        RETURN(rc);
 }
 
-static int osd_fid_init(const struct lu_env *env, struct osd_device *osd)
-{
-       struct seq_server_site *ss = osd_seq_site(osd);
-       int rc = 0;
-
-       ENTRY;
-       if (osd->od_is_ost || osd->od_cl_seq != NULL)
-               RETURN(0);
-
-       if (unlikely(ss == NULL))
-               RETURN(-ENODEV);
-
-       OBD_ALLOC_PTR(osd->od_cl_seq);
-       if (osd->od_cl_seq == NULL)
-               RETURN(-ENOMEM);
-
-       seq_client_init(osd->od_cl_seq, NULL, LUSTRE_SEQ_METADATA,
-                       osd->od_svname, ss->ss_server_seq);
-
-       if (ss->ss_node_id == 0) {
-               /*
-                * If the OSD on the sequence controller(MDT0), then allocate
-                * sequence here, otherwise allocate sequence after connected
-                * to MDT0 (see mdt_register_lwp_callback()).
-                */
-               rc = seq_server_alloc_meta(osd->od_cl_seq->lcs_srv,
-                                  &osd->od_cl_seq->lcs_space, env);
-       }
-
-       RETURN(rc);
-}
-
 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
                       struct lu_device *dev)
 {
@@ -1608,33 +1567,18 @@ static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
                        RETURN(rc);
        }
 
-       rc = osd_fid_init(env, osd);
+       rc = seq_target_init(env, &osd->od_dt_dev, osd->od_svname,
+                            osd->od_is_ost);
 
        RETURN(rc);
 }
 
-/**
- * Implementation of lu_device_operations::ldo_fid_alloc() for OSD
- *
- * Allocate FID.
- *
- * see include/lu_object.h for the details.
- */
-static int osd_fid_alloc(const struct lu_env *env, struct lu_device *d,
-                        struct lu_fid *fid, struct lu_object *parent,
-                        const struct lu_name *name)
-{
-       struct osd_device *osd = osd_dev(d);
-
-       return seq_client_alloc_fid(env, osd->od_cl_seq, fid);
-}
-
 const struct lu_device_operations osd_lu_ops = {
        .ldo_object_alloc       = osd_object_alloc,
        .ldo_process_config     = osd_process_config,
        .ldo_recovery_complete  = osd_recovery_complete,
        .ldo_prepare            = osd_prepare,
-       .ldo_fid_alloc          = osd_fid_alloc,
+       .ldo_fid_alloc          = fid_alloc_generic,
 };
 
 static void osd_type_start(struct lu_device_type *t)
index 5d7be73..0fc1e57 100644 (file)
@@ -394,9 +394,6 @@ struct osd_device {
 
        arc_prune_t             *arc_prune_cb;
 
-       /* osd seq instance */
-       struct lu_client_seq    *od_cl_seq;
-
        struct semaphore         od_otable_sem;
        struct osd_otable_it    *od_otable_it;
        struct lustre_scrub      od_scrub;