From: Timothy Day Date: Tue, 14 May 2024 20:59:16 +0000 (+0000) Subject: LU-17848 osd: deduplicate osd_fid_init()/fini()/alloc() X-Git-Tag: 2.15.64~152 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F55110%2F6;p=fs%2Flustre-release.git LU-17848 osd: deduplicate osd_fid_init()/fini()/alloc() 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 Change-Id: If97ca5615d9bdfe0fe9886686e9ce3ec2b740f7d Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55110 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Mikhail Pershin Reviewed-by: Oleg Drokin --- diff --git a/lustre/fid/fid_lib.c b/lustre/fid/fid_lib.c index 2d247a6..5acf5df 100644 --- a/lustre/fid/fid_lib.c +++ b/lustre/fid/fid_lib.c @@ -40,8 +40,13 @@ #include #include +#include +#include +#include #include +#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); diff --git a/lustre/include/dt_object.h b/lustre/include/dt_object.h index 3b15bf3..04d2764 100644 --- a/lustre/include/dt_object.h +++ b/lustre/include/dt_object.h @@ -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 diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index c454a37..079c659 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -148,6 +148,7 @@ */ #include +#include #include #include #include @@ -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, diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index a101ffb..a292a4c 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -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 = { diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 3cc562a..0325e66 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -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 diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index 7f6688a..1eea451 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -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; diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index a278d17..f1c53a7 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -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) diff --git a/lustre/osd-zfs/osd_internal.h b/lustre/osd-zfs/osd_internal.h index 5d7be73..0fc1e57 100644 --- a/lustre/osd-zfs/osd_internal.h +++ b/lustre/osd-zfs/osd_internal.h @@ -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;