From a888b6e9dc7e85b750cabb994987379ff2e92a4a Mon Sep 17 00:00:00 2001 From: Wang Di Date: Tue, 17 Jun 2014 12:10:14 -0700 Subject: [PATCH] LU-4976 osp: add comment to osp_dev.c 1. Add comments to each function in osp_dev.c. 2. remove unnecessary rc in osp_recovery_complete. 3. remove unnecessary LASSERTF in osp_device_fini. 4. rename some single character variable name to more meaningful name, like m-->osp, l-->ld etc 5. rename osp_find_or_create to osp_find_or_create_local_file to indicate it is actually for finding or creating a local file. Signed-off-by: wang di Change-Id: Ia9ca565818aa6fc6f9ff932c371d9150e926fb60 Reviewed-on: http://review.whamcloud.com/10502 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Ned Bass Reviewed-by: Richard Henwood Reviewed-by: Oleg Drokin --- lustre/osp/osp_dev.c | 682 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 532 insertions(+), 150 deletions(-) diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index 2b0ccbd..09e9bd0 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -35,7 +35,13 @@ * * lustre/osp/osp_dev.c * - * Lustre OST Proxy Device + * Lustre OST/MDT Proxy Device (OSP) is in the MDS stack, and used as + * a proxy device to communicate with other MDTs and OSTs. + * + * The purpose is to export the OSD API from the remote MDT or OST's underlying + * OSD for access and modification by the local service (typically MDD/LOD, or + * LFSCK) as if it were a local OSD. The goal is that the OSP provides a + * transparent interface for access to the remote OSD. * * Author: Alex Zhuravlev * Author: Mikhail Pershin @@ -66,6 +72,21 @@ static struct lu_kmem_descr osp_caches[] = { } }; +/** + * Implementation of lu_device_operations::ldo_object_alloc + * + * Allocates an OSP object in memory, whose FID is on the remote target. + * + * \param[in] env execution environment + * \param[in] hdr The header of the object stack. If it is NULL, it + * means the object is not built from top device, i.e. + * it is a sub-stripe object of striped directory or + * an OST object. + * \param[in] d OSP device + * + * \retval object object being created if the creation succeed. + * \retval NULL NULL if the creation failed. + */ struct lu_object *osp_object_alloc(const struct lu_env *env, const struct lu_object_header *hdr, struct lu_device *d) @@ -99,9 +120,25 @@ struct lu_object *osp_object_alloc(const struct lu_env *env, } } +/** + * Find or create the local object + * + * Finds or creates the local file referenced by \a reg_id and return the + * attributes of the local file. + * + * \param[in] env execution environment + * \param[in] osp OSP device + * \param[out] attr attributes of the object + * \param[in] reg_id the local object ID of the file. It will be used + * to compose a local FID{FID_SEQ_LOCAL_FILE, reg_id, 0} + * to identify the object. + * + * \retval object object(dt_object) found or created + * \retval ERR_PTR(errno) ERR_PTR(errno) if not get the object. + */ static struct dt_object -*osp_find_or_create(const struct lu_env *env, struct osp_device *osp, - struct lu_attr *attr, __u32 reg_id) +*osp_find_or_create_local_file(const struct lu_env *env, struct osp_device *osp, + struct lu_attr *attr, __u32 reg_id) { struct osp_thread_info *osi = osp_env_info(env); struct dt_object_format dof = { 0 }; @@ -113,11 +150,13 @@ static struct dt_object attr->la_valid = LA_MODE; attr->la_mode = S_IFREG | 0644; dof.dof_type = DFT_REGULAR; + /* Find or create the local object by osi_fid. */ dto = dt_find_or_create(env, osp->opd_storage, &osi->osi_fid, &dof, attr); if (IS_ERR(dto)) RETURN(dto); + /* Get attributes of the local object. */ rc = dt_attr_get(env, dto, attr, NULL); if (rc) { CERROR("%s: can't be initialized: rc = %d\n", @@ -128,6 +167,19 @@ static struct dt_object RETURN(dto); } +/** + * Write data buffer to a local file object. + * + * \param[in] env execution environment + * \param[in] osp OSP device + * \param[in] dt_obj object written to + * \param[in] buf buffer containing byte array and length + * \param[in] offset write offset in the object in bytes + * + * \retval 0 0 if write succeed + * \retval -EFAULT -EFAULT if only part of buffer is written. + * \retval negative other negative errno if write failed. + */ static int osp_write_local_file(const struct lu_env *env, struct osp_device *osp, struct dt_object *dt_obj, @@ -154,6 +206,20 @@ out: RETURN(rc); } +/** + * Initialize last ID object. + * + * This function initializes the LAST_ID file, which stores the current last + * used id of data objects. The MDT will use the last used id and the last_seq + * (\see osp_init_last_seq()) to synchronize the precreate object cache with + * OSTs. + * + * \param[in] env execution environment + * \param[in] osp OSP device + * + * \retval 0 0 if initialization succeed + * \retval negative negative errno if initialization failed + */ static int osp_init_last_objid(const struct lu_env *env, struct osp_device *osp) { struct osp_thread_info *osi = osp_env_info(env); @@ -162,9 +228,11 @@ static int osp_init_last_objid(const struct lu_env *env, struct osp_device *osp) int rc; ENTRY; - dto = osp_find_or_create(env, osp, &osi->osi_attr, MDD_LOV_OBJ_OID); + dto = osp_find_or_create_local_file(env, osp, &osi->osi_attr, + MDD_LOV_OBJ_OID); if (IS_ERR(dto)) RETURN(PTR_ERR(dto)); + /* object will be released in device cleanup path */ if (osi->osi_attr.la_size >= sizeof(osi->osi_id) * (osp->opd_index + 1)) { @@ -179,6 +247,8 @@ static int osp_init_last_objid(const struct lu_env *env, struct osp_device *osp) osp->opd_index); rc = osp_write_local_file(env, osp, dto, &osi->osi_lb, osi->osi_off); + if (rc != 0) + GOTO(out, rc); } osp->opd_last_used_oid_file = dto; RETURN(0); @@ -191,6 +261,20 @@ out: RETURN(rc); } +/** + * Initialize last sequence object. + * + * This function initializes the LAST_SEQ file in the local OSD, which stores + * the current last used sequence of data objects. The MDT will use the last + * sequence and last id (\see osp_init_last_objid()) to synchronize the + * precreate object cache with OSTs. + * + * \param[in] env execution environment + * \param[in] osp OSP device + * + * \retval 0 0 if initialization succeed + * \retval negative negative errno if initialization failed + */ static int osp_init_last_seq(const struct lu_env *env, struct osp_device *osp) { struct osp_thread_info *osi = osp_env_info(env); @@ -199,7 +283,8 @@ static int osp_init_last_seq(const struct lu_env *env, struct osp_device *osp) int rc; ENTRY; - dto = osp_find_or_create(env, osp, &osi->osi_attr, MDD_LOV_OBJ_OSEQ); + dto = osp_find_or_create_local_file(env, osp, &osi->osi_attr, + MDD_LOV_OBJ_OSEQ); if (IS_ERR(dto)) RETURN(PTR_ERR(dto)); @@ -229,6 +314,19 @@ out: RETURN(rc); } +/** + * Initialize last OID and sequence object. + * + * If the MDT is just upgraded to 2.4 from the lower version, where the + * LAST_SEQ file does not exist, the file will be created and IDIF sequence + * will be written into the file. + * + * \param[in] env execution environment + * \param[in] osp OSP device + * + * \retval 0 0 if initialization succeed + * \retval negative negative error if initialization failed + */ static int osp_last_used_init(const struct lu_env *env, struct osp_device *osp) { struct osp_thread_info *osi = osp_env_info(env); @@ -293,20 +391,36 @@ out: RETURN(rc); } -static void osp_last_used_fini(const struct lu_env *env, struct osp_device *d) +/** + * Release the last sequence and OID file objects in OSP device. + * + * \param[in] env execution environment + * \param[in] osp OSP device + */ +static void osp_last_used_fini(const struct lu_env *env, struct osp_device *osp) { /* release last_used file */ - if (d->opd_last_used_oid_file != NULL) { - lu_object_put(env, &d->opd_last_used_oid_file->do_lu); - d->opd_last_used_oid_file = NULL; + if (osp->opd_last_used_oid_file != NULL) { + lu_object_put(env, &osp->opd_last_used_oid_file->do_lu); + osp->opd_last_used_oid_file = NULL; } - if (d->opd_last_used_seq_file != NULL) { - lu_object_put(env, &d->opd_last_used_seq_file->do_lu); - d->opd_last_used_seq_file = NULL; + if (osp->opd_last_used_seq_file != NULL) { + lu_object_put(env, &osp->opd_last_used_seq_file->do_lu); + osp->opd_last_used_seq_file = NULL; } } +/** + * Disconnects the connection between OSP and its correspondent MDT or OST, and + * the import will be marked as inactive. It will only be called during OSP + * cleanup process. + * + * \param[in] d OSP device being disconnected + * + * \retval 0 0 if disconnection succeed + * \retval negative negative errno if disconnection failed + */ static int osp_disconnect(struct osp_device *d) { struct obd_import *imp; @@ -339,6 +453,16 @@ static int osp_disconnect(struct osp_device *d) RETURN(rc); } +/** + * Cleanup OSP, which includes disconnect import, cleanup unlink log, stop + * precreate threads etc. + * + * \param[in] env execution environment. + * \param[in] d OSP device being disconnected. + * + * \retval 0 0 if cleanup succeed + * \retval negative negative errno if cleanup failed + */ static int osp_shutdown(const struct lu_env *env, struct osp_device *d) { int rc = 0; @@ -363,6 +487,20 @@ static int osp_shutdown(const struct lu_env *env, struct osp_device *d) RETURN(rc); } +/** + * Implementation of osp_lu_ops::ldo_process_config + * + * This function processes config log records in OSP layer. It is usually + * called from the top layer of MDT stack, and goes through the stack by calling + * ldo_process_config of next layer. + * + * \param[in] env execution environment + * \param[in] dev lu_device of OSP + * \param[in] lcfg config log + * + * \retval 0 0 if the config log record is executed correctly. + * \retval negative negative errno if the record execution fails. + */ static int osp_process_config(const struct lu_env *env, struct lu_device *dev, struct lustre_cfg *lcfg) { @@ -407,18 +545,29 @@ static int osp_process_config(const struct lu_env *env, RETURN(rc); } +/** + * Implementation of osp_lu_ops::ldo_recovery_complete + * + * This function is called after recovery is finished, and OSP layer + * will wake up precreate thread here. + * + * \param[in] env execution environment + * \param[in] dev lu_device of OSP + * + * \retval 0 0 unconditionally + */ static int osp_recovery_complete(const struct lu_env *env, struct lu_device *dev) { struct osp_device *osp = lu2osp_dev(dev); - int rc = 0; ENTRY; osp->opd_recovery_completed = 1; if (!osp->opd_connect_mdt && osp->opd_pre != NULL) wake_up(&osp->opd_pre_waitq); - RETURN(rc); + + RETURN(0); } const struct lu_device_operations osp_lu_ops = { @@ -428,8 +577,21 @@ const struct lu_device_operations osp_lu_ops = { }; /** - * provides with statfs from corresponded OST + * Implementation of dt_device_operations::dt_statfs + * + * This function provides statfs status (for precreation) from + * corresponding OST. Note: this function only retrieves the status + * from the OSP device, and the real statfs RPC happens inside + * precreate thread (\see osp_statfs_update). Note: OSP for MDT does + * not need to retrieve statfs data for now. + * + * \param[in] env execution environment. + * \param[in] dev dt_device of OSP. + * \param[out] sfs holds the retrieved statfs data. * + * \retval 0 0 statfs data was retrieved successfully or + * retrieval was not needed + * \retval negative negative errno if get statfs failed. */ static int osp_statfs(const struct lu_env *env, struct dt_device *dev, struct obd_statfs *sfs) @@ -476,6 +638,18 @@ static int osp_sync_timeout(void *data) return 1; } +/** + * Implementation of dt_device_operations::dt_sync + * + * This function synchronizes the OSP cache to the remote target. It wakes + * up unlink log threads and sends out unlink records to the remote OST. + * + * \param[in] env execution environment + * \param[in] dev dt_device of OSP + * + * \retval 0 0 if synchronization succeeds + * \retval negative negative errno if synchronization fails + */ static int osp_sync(const struct lu_env *env, struct dt_device *dev) { struct osp_device *d = dt2osp_dev(dev); @@ -570,7 +744,22 @@ const struct dt_device_operations osp_dt_ops = { .dt_trans_stop = osp_trans_stop, }; -static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *m, +/** + * Connect OSP to local OSD. + * + * Locate the local OSD referenced by \a nextdev and connect to it. Sometimes, + * OSP needs to access the local OSD to store some information. For example, + * during precreate, it needs to update last used OID and sequence file + * (LAST_SEQ) in local OSD. + * + * \param[in] env execution environment + * \param[in] osp OSP device + * \param[in] nextdev the name of local OSD + * + * \retval 0 0 connection succeeded + * \retval negative negative errno connection failed + */ +static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *osp, const char *nextdev) { struct obd_connect_data *data = NULL; @@ -579,7 +768,7 @@ static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *m, ENTRY; - LASSERT(m->opd_storage_exp == NULL); + LASSERT(osp->opd_storage_exp == NULL); OBD_ALLOC_PTR(data); if (data == NULL) @@ -588,29 +777,54 @@ static int osp_connect_to_osd(const struct lu_env *env, struct osp_device *m, obd = class_name2obd(nextdev); if (obd == NULL) { CERROR("%s: can't locate next device: %s\n", - m->opd_obd->obd_name, nextdev); + osp->opd_obd->obd_name, nextdev); GOTO(out, rc = -ENOTCONN); } - rc = obd_connect(env, &m->opd_storage_exp, obd, &obd->obd_uuid, data, + rc = obd_connect(env, &osp->opd_storage_exp, obd, &obd->obd_uuid, data, NULL); if (rc) { CERROR("%s: cannot connect to next dev %s: rc = %d\n", - m->opd_obd->obd_name, nextdev, rc); + osp->opd_obd->obd_name, nextdev, rc); GOTO(out, rc); } - m->opd_dt_dev.dd_lu_dev.ld_site = - m->opd_storage_exp->exp_obd->obd_lu_dev->ld_site; - LASSERT(m->opd_dt_dev.dd_lu_dev.ld_site); - m->opd_storage = lu2dt_dev(m->opd_storage_exp->exp_obd->obd_lu_dev); + osp->opd_dt_dev.dd_lu_dev.ld_site = + osp->opd_storage_exp->exp_obd->obd_lu_dev->ld_site; + LASSERT(osp->opd_dt_dev.dd_lu_dev.ld_site); + osp->opd_storage = lu2dt_dev(osp->opd_storage_exp->exp_obd->obd_lu_dev); out: OBD_FREE_PTR(data); RETURN(rc); } -static int osp_init0(const struct lu_env *env, struct osp_device *m, +/** + * Initialize OSP device according to the parameters in the configuration + * log \a cfg. + * + * Reconstruct the local device name from the configuration profile, and + * initialize necessary threads and structures according to the OSP type + * (MDT or OST). + * + * Since there is no record in the MDT configuration for the local disk + * device, we have to extract this from elsewhere in the profile. + * The only information we get at setup is from the OSC records: + * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID + * + * Note: configs generated by Lustre 1.8 are missing the -MDTxxxx part, + * so, we need to reconstruct the name of the underlying OSD from this: + * {fsname}-{svname}-osd, for example "lustre-MDT0000-osd". + * + * \param[in] env execution environment + * \param[in] osp OSP device + * \param[in] ldt lu device type of OSP + * \param[in] cfg configuration log + * + * \retval 0 0 if OSP initialization succeeded. + * \retval negative negative errno if OSP initialization failed. + */ +static int osp_init0(const struct lu_env *env, struct osp_device *osp, struct lu_device_type *ldt, struct lustre_cfg *cfg) { struct obd_device *obd; @@ -622,7 +836,7 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, ENTRY; - mutex_init(&m->opd_async_requests_mutex); + mutex_init(&osp->opd_async_requests_mutex); obd = class_name2obd(lustre_cfg_string(cfg, 0)); if (obd == NULL) { @@ -630,17 +844,7 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, lustre_cfg_string(cfg, 0)); RETURN(-ENODEV); } - m->opd_obd = obd; - - /* There is no record in the MDT configuration for the local disk - * device, so we have to extract this from elsewhere in the profile. - * The only information we get at setup is from the OSC records: - * setup 0:{fsname}-OSTxxxx-osc[-MDTxxxx] 1:lustre-OST0000_UUID 2:NID - * Note that 1.8 generated configs are missing the -MDTxxxx part. - * We need to reconstruct the name of the underlying OSD from this: - * {fsname}-{svname}-osd, for example "lustre-MDT0000-osd". We - * also need to determine the OST index from this - will be used - * to calculate the offset in shared lov_objids file later */ + osp->opd_obd = obd; src = lustre_cfg_string(cfg, 0); if (src == NULL) @@ -648,8 +852,9 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, tgt = strrchr(src, '-'); if (tgt == NULL) { - CERROR("%s: invalid target name %s\n", - m->opd_obd->obd_name, lustre_cfg_string(cfg, 0)); + CERROR("%s: invalid target name %s: rc = %d\n", + osp->opd_obd->obd_name, lustre_cfg_string(cfg, 0), + -EINVAL); RETURN(-EINVAL); } @@ -658,68 +863,72 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, for (tgt--; tgt > src && *tgt != '-'; tgt--) ; if (tgt == src) { - CERROR("%s: invalid target name %s\n", - m->opd_obd->obd_name, lustre_cfg_string(cfg, 0)); + CERROR("%s: invalid target name %s: rc = %d\n", + osp->opd_obd->obd_name, + lustre_cfg_string(cfg, 0), -EINVAL); RETURN(-EINVAL); } if (strncmp(tgt, "-OST", 4) != 0) { - CERROR("%s: invalid target name %s\n", - m->opd_obd->obd_name, lustre_cfg_string(cfg, 0)); + CERROR("%s: invalid target name %s: rc = %d\n", + osp->opd_obd->obd_name, + lustre_cfg_string(cfg, 0), -EINVAL); RETURN(-EINVAL); } idx = simple_strtol(tgt + 4, &mdt, 16); if (mdt[0] != '-' || idx > INT_MAX || idx < 0) { - CERROR("%s: invalid OST index in '%s'\n", - m->opd_obd->obd_name, src); + CERROR("%s: invalid OST index in '%s': rc = %d\n", + osp->opd_obd->obd_name, src, -EINVAL); RETURN(-EINVAL); } - m->opd_index = idx; - m->opd_group = 0; + osp->opd_index = idx; + osp->opd_group = 0; idx = tgt - src; } else { /* New OSC name fsname-OSTXXXX-osc-MDTXXXX */ if (strncmp(tgt, "-MDT", 4) != 0 && strncmp(tgt, "-OST", 4) != 0) { - CERROR("%s: invalid target name %s\n", - m->opd_obd->obd_name, lustre_cfg_string(cfg, 0)); + CERROR("%s: invalid target name %s: rc = %d\n", + osp->opd_obd->obd_name, + lustre_cfg_string(cfg, 0), -EINVAL); RETURN(-EINVAL); } idx = simple_strtol(tgt + 4, &mdt, 16); if (*mdt != '\0' || idx > INT_MAX || idx < 0) { - CERROR("%s: invalid OST index in '%s'\n", - m->opd_obd->obd_name, src); + CERROR("%s: invalid OST index in '%s': rc = %d\n", + osp->opd_obd->obd_name, src, -EINVAL); RETURN(-EINVAL); } /* Get MDT index from the name and set it to opd_group, * which will be used by OSP to connect with OST */ - m->opd_group = idx; + osp->opd_group = idx; if (tgt - src <= 12) { - CERROR("%s: invalid mdt index retrieve from %s\n", - m->opd_obd->obd_name, lustre_cfg_string(cfg, 0)); + CERROR("%s: invalid mdt index from %s: rc =%d\n", + osp->opd_obd->obd_name, + lustre_cfg_string(cfg, 0), -EINVAL); RETURN(-EINVAL); } if (strncmp(tgt - 12, "-MDT", 4) == 0) - m->opd_connect_mdt = 1; + osp->opd_connect_mdt = 1; idx = simple_strtol(tgt - 8, &mdt, 16); if (mdt[0] != '-' || idx > INT_MAX || idx < 0) { - CERROR("%s: invalid OST index in '%s'\n", - m->opd_obd->obd_name, src); + CERROR("%s: invalid OST index in '%s': rc =%d\n", + osp->opd_obd->obd_name, src, -EINVAL); RETURN(-EINVAL); } - m->opd_index = idx; + osp->opd_index = idx; idx = tgt - src - 12; } /* check the fsname length, and after this everything else will fit */ if (idx > MTI_NAME_MAXLEN) { - CERROR("%s: fsname too long in '%s'\n", - m->opd_obd->obd_name, src); + CERROR("%s: fsname too long in '%s': rc = %d\n", + osp->opd_obd->obd_name, src, -EINVAL); RETURN(-EINVAL); } @@ -738,8 +947,8 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, strcat(osdname, "-osd"); CDEBUG(D_HA, "%s: connect to %s (%s)\n", obd->obd_name, osdname, src); - if (m->opd_connect_mdt) { - struct client_obd *cli = &m->opd_obd->u.cli; + if (osp->opd_connect_mdt) { + struct client_obd *cli = &osp->opd_obd->u.cli; OBD_ALLOC(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock)); if (!cli->cl_rpc_lock) @@ -747,11 +956,12 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, osp_init_rpc_lock(cli->cl_rpc_lock); } - m->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops; - m->opd_dt_dev.dd_ops = &osp_dt_ops; - obd->obd_lu_dev = &m->opd_dt_dev.dd_lu_dev; + osp->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops; + osp->opd_dt_dev.dd_ops = &osp_dt_ops; + + obd->obd_lu_dev = &osp->opd_dt_dev.dd_lu_dev; - rc = osp_connect_to_osd(env, m, osdname); + rc = osp_connect_to_osd(env, osp, osdname); if (rc) GOTO(out_fini, rc); @@ -761,31 +971,32 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, rc = client_obd_setup(obd, cfg); if (rc) { - CERROR("%s: can't setup obd: %d\n", m->opd_obd->obd_name, rc); + CERROR("%s: can't setup obd: rc = %d\n", osp->opd_obd->obd_name, + rc); GOTO(out_ref, rc); } - osp_lprocfs_init(m); + osp_lprocfs_init(osp); - rc = obd_fid_init(m->opd_obd, NULL, m->opd_connect_mdt ? + rc = obd_fid_init(osp->opd_obd, NULL, osp->opd_connect_mdt ? LUSTRE_SEQ_METADATA : LUSTRE_SEQ_DATA); if (rc) { CERROR("%s: fid init error: rc = %d\n", - m->opd_obd->obd_name, rc); + osp->opd_obd->obd_name, rc); GOTO(out_proc, rc); } - if (!m->opd_connect_mdt) { + if (!osp->opd_connect_mdt) { /* Initialize last id from the storage - will be * used in orphan cleanup. */ - rc = osp_last_used_init(env, m); + rc = osp_last_used_init(env, osp); if (rc) GOTO(out_proc, rc); /* Initialize precreation thread, it handles new * connections as well. */ - rc = osp_init_precreate(m); + rc = osp_init_precreate(osp); if (rc) GOTO(out_last_used, rc); } @@ -795,7 +1006,7 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, * care of propogating changes to OST in near * transactional manner. */ - rc = osp_sync_init(env, m); + rc = osp_sync_init(env, osp); if (rc) GOTO(out_precreat, rc); @@ -803,7 +1014,7 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, * Initiate connect to OST */ ll_generate_random_uuid(uuid); - class_uuid_unparse(uuid, &m->opd_cluuid); + class_uuid_unparse(uuid, &osp->opd_cluuid); imp = obd->u.cli.cl_import; @@ -816,124 +1027,167 @@ static int osp_init0(const struct lu_env *env, struct osp_device *m, out: /* stop sync thread */ - osp_sync_fini(m); + osp_sync_fini(osp); out_precreat: /* stop precreate thread */ - if (!m->opd_connect_mdt) - osp_precreate_fini(m); + if (!osp->opd_connect_mdt) + osp_precreate_fini(osp); out_last_used: - if (!m->opd_connect_mdt) - osp_last_used_fini(env, m); + if (!osp->opd_connect_mdt) + osp_last_used_fini(env, osp); out_proc: ptlrpc_lprocfs_unregister_obd(obd); lprocfs_obd_cleanup(obd); - if (m->opd_symlink) - lprocfs_remove(&m->opd_symlink); + if (osp->opd_symlink) + lprocfs_remove(&osp->opd_symlink); client_obd_cleanup(obd); out_ref: ptlrpcd_decref(); out_disconnect: - if (m->opd_connect_mdt) { - struct client_obd *cli = &m->opd_obd->u.cli; + if (osp->opd_connect_mdt) { + struct client_obd *cli = &osp->opd_obd->u.cli; if (cli->cl_rpc_lock != NULL) { OBD_FREE_PTR(cli->cl_rpc_lock); cli->cl_rpc_lock = NULL; } } - obd_disconnect(m->opd_storage_exp); + obd_disconnect(osp->opd_storage_exp); out_fini: if (osdname) OBD_FREE(osdname, MAX_OBD_NAME); RETURN(rc); } +/** + * Implementation of lu_device_type_operations::ldto_device_free + * + * Free the OSP device in memory. No return value is needed for now, + * so always return NULL to comply with the interface. + * + * \param[in] env execution environment + * \param[in] lu lu_device of OSP + * + * \retval NULL NULL unconditionally + */ static struct lu_device *osp_device_free(const struct lu_env *env, struct lu_device *lu) { - struct osp_device *m = lu2osp_dev(lu); - - ENTRY; + struct osp_device *osp = lu2osp_dev(lu); if (atomic_read(&lu->ld_ref) && lu->ld_site) { LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL); lu_site_print(env, lu->ld_site, &msgdata, lu_cdebug_printer); } - dt_device_fini(&m->opd_dt_dev); - OBD_FREE_PTR(m); - RETURN(NULL); + dt_device_fini(&osp->opd_dt_dev); + OBD_FREE_PTR(osp); + + return NULL; } +/** + * Implementation of lu_device_type_operations::ldto_device_alloc + * + * This function allocates and initializes OSP device in memory according to + * the config log. + * + * \param[in] env execution environment + * \param[in] type device type of OSP + * \param[in] lcfg config log + * + * \retval pointer the pointer of allocated OSP if succeed. + * \retval ERR_PTR(errno) ERR_PTR(errno) if failed. + */ static struct lu_device *osp_device_alloc(const struct lu_env *env, - struct lu_device_type *t, + struct lu_device_type *type, struct lustre_cfg *lcfg) { - struct osp_device *m; - struct lu_device *l; + struct osp_device *osp; + struct lu_device *ld; - OBD_ALLOC_PTR(m); - if (m == NULL) { - l = ERR_PTR(-ENOMEM); + OBD_ALLOC_PTR(osp); + if (osp == NULL) { + ld = ERR_PTR(-ENOMEM); } else { int rc; - l = osp2lu_dev(m); - dt_device_init(&m->opd_dt_dev, t); - rc = osp_init0(env, m, t, lcfg); + ld = osp2lu_dev(osp); + dt_device_init(&osp->opd_dt_dev, type); + rc = osp_init0(env, osp, type, lcfg); if (rc != 0) { - osp_device_free(env, l); - l = ERR_PTR(rc); + osp_device_free(env, ld); + ld = ERR_PTR(rc); } } - return l; + return ld; } +/** + * Implementation of lu_device_type_operations::ldto_device_fini + * + * This function cleans up the OSP device, i.e. release and free those + * attached items in osp_device. + * + * \param[in] env execution environment + * \param[in] ld lu_device of OSP + * + * \retval NULL NULL if cleanup succeeded. + * \retval ERR_PTR(errno) ERR_PTR(errno) if cleanup failed. + */ static struct lu_device *osp_device_fini(const struct lu_env *env, - struct lu_device *d) + struct lu_device *ld) { - struct osp_device *m = lu2osp_dev(d); + struct osp_device *osp = lu2osp_dev(ld); struct obd_import *imp; int rc; ENTRY; - if (m->opd_async_requests != NULL) { - out_destroy_update_req(m->opd_async_requests); - m->opd_async_requests = NULL; + if (osp->opd_async_requests != NULL) { + out_destroy_update_req(osp->opd_async_requests); + osp->opd_async_requests = NULL; } - if (m->opd_storage_exp) - obd_disconnect(m->opd_storage_exp); + if (osp->opd_storage_exp) + obd_disconnect(osp->opd_storage_exp); - imp = m->opd_obd->u.cli.cl_import; + imp = osp->opd_obd->u.cli.cl_import; if (imp->imp_rq_pool) { ptlrpc_free_rq_pool(imp->imp_rq_pool); imp->imp_rq_pool = NULL; } - if (m->opd_symlink) - lprocfs_remove(&m->opd_symlink); + if (osp->opd_symlink) + lprocfs_remove(&osp->opd_symlink); - LASSERT(m->opd_obd); - ptlrpc_lprocfs_unregister_obd(m->opd_obd); - lprocfs_obd_cleanup(m->opd_obd); + LASSERT(osp->opd_obd); + ptlrpc_lprocfs_unregister_obd(osp->opd_obd); + lprocfs_obd_cleanup(osp->opd_obd); - if (m->opd_connect_mdt) { - struct client_obd *cli = &m->opd_obd->u.cli; + if (osp->opd_connect_mdt) { + struct client_obd *cli = &osp->opd_obd->u.cli; if (cli->cl_rpc_lock != NULL) { OBD_FREE_PTR(cli->cl_rpc_lock); cli->cl_rpc_lock = NULL; } } - rc = client_obd_cleanup(m->opd_obd); - LASSERTF(rc == 0, "error %d\n", rc); + rc = client_obd_cleanup(osp->opd_obd); + if (rc != 0) { + ptlrpcd_decref(); + RETURN(ERR_PTR(rc)); + } ptlrpcd_decref(); RETURN(NULL); } +/** + * Implementation of obd_ops::o_reconnect + * + * This function is empty and does not need to do anything for now. + */ static int osp_reconnect(const struct lu_env *env, struct obd_export *exp, struct obd_device *obd, struct obd_uuid *cluuid, @@ -943,20 +1197,25 @@ static int osp_reconnect(const struct lu_env *env, return 0; } -static int osp_prepare_fid_client(struct osp_device *osp) -{ - LASSERT(osp->opd_obd->u.cli.cl_seq != NULL); - if (osp->opd_obd->u.cli.cl_seq->lcs_exp != NULL) - return 0; - - LASSERT(osp->opd_exp != NULL); - osp->opd_obd->u.cli.cl_seq->lcs_exp = - class_export_get(osp->opd_exp); - return 0; -} - /* - * we use exports to track all LOD users + * Implementation of obd_ops::o_connect + * + * Connect OSP to the remote target (MDT or OST). Allocate the + * export and return it to the LOD, which calls this function + * for each OSP to connect it to the remote target. This function + * is currently only called once per OSP. + * + * \param[in] env execution environment + * \param[out] exp export connected to OSP + * \param[in] obd OSP device + * \param[in] cluuid OSP device client uuid + * \param[in] data connect_data to be used to connect to the remote + * target + * \param[in] localdata necessary for the API interface, but not used in + * this function + * + * \retval 0 0 if the connection succeeded. + * \retval negative negative errno if the connection failed. */ static int osp_obd_connect(const struct lu_env *env, struct obd_export **exp, struct obd_device *obd, struct obd_uuid *cluuid, @@ -1008,9 +1267,17 @@ out: RETURN(rc); } -/* - * once last export (we don't count self-export) disappeared - * osp can be released +/** + * Implementation of obd_ops::o_disconnect + * + * Disconnect the export for the OSP. This is called by LOD to release the + * OSP during cleanup (\see lod_del_device()). The OSP will be released after + * the export is released. + * + * \param[in] exp export to be disconnected. + * + * \retval 0 0 if disconnection succeed + * \retval negative negative errno if disconnection failed */ static int osp_obd_disconnect(struct obd_export *exp) { @@ -1036,11 +1303,24 @@ static int osp_obd_disconnect(struct obd_export *exp) RETURN(rc); } -/* - * lprocfs helpers still use OBD API, let's keep obd_statfs() support +/** + * Implementation of obd_ops::o_statfs + * + * Send a RPC to the remote target to get statfs status. This is only used + * in lprocfs helpers by obd_statfs. + * + * \param[in] env execution environment + * \param[in] exp connection state from this OSP to the parent (LOD) + * device + * \param[out] osfs hold the statfs result + * \param[in] unused Not used in this function for now + * \param[in] flags flags to indicate how OSP will issue the RPC + * + * \retval 0 0 if statfs succeeded. + * \retval negative negative errno if statfs failed. */ static int osp_obd_statfs(const struct lu_env *env, struct obd_export *exp, - struct obd_statfs *osfs, __u64 max_age, __u32 flags) + struct obd_statfs *osfs, __u64 unused, __u32 flags) { struct obd_statfs *msfs; struct ptlrpc_request *req; @@ -1058,12 +1338,6 @@ static int osp_obd_statfs(const struct lu_env *env, struct obd_export *exp, if (!imp) RETURN(-ENODEV); - /* We could possibly pass max_age in the request (as an absolute - * timestamp or a "seconds.usec ago") so the target can avoid doing - * extra calls into the filesystem if that isn't necessary (e.g. - * during mount that would help a bit). Having relative timestamps - * is not so great if request processing is slow, while absolute - * timestamps are not ideal because they need time synchronization. */ req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS); class_import_put(imp); @@ -1102,6 +1376,40 @@ out: return rc; } +/** + * Prepare fid client. + * + * This function prepares the FID client for the OSP. It will check and assign + * the export (to MDT0) for its FID client, so OSP can allocate super sequence + * or lookup sequence in FLDB of MDT0. + * + * \param[in] osp OSP device + */ +static void osp_prepare_fid_client(struct osp_device *osp) +{ + LASSERT(osp->opd_obd->u.cli.cl_seq != NULL); + if (osp->opd_obd->u.cli.cl_seq->lcs_exp != NULL) + return; + + LASSERT(osp->opd_exp != NULL); + osp->opd_obd->u.cli.cl_seq->lcs_exp = + class_export_get(osp->opd_exp); +} + +/** + * Implementation of obd_ops::o_import_event + * + * This function is called when some related import event happens. It will + * mark the necessary flags according to the event and notify the necessary + * threads (mainly precreate thread). + * + * \param[in] obd OSP OBD device + * \param[in] imp import attached from OSP to remote (OST/MDT) service + * \param[in] event event related to remote service (IMP_EVENT_*) + * + * \retval 0 0 if the event handling succeeded. + * \retval negative negative errno if the event handling failed. + */ static int osp_import_event(struct obd_device *obd, struct obd_import *imp, enum obd_import_event event) { @@ -1136,9 +1444,7 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp, case IMP_EVENT_ACTIVE: d->opd_imp_active = 1; - if (osp_prepare_fid_client(d) != 0) - break; - + osp_prepare_fid_client(d); if (d->opd_got_disconnected) d->opd_new_connection = 1; d->opd_imp_connected = 1; @@ -1168,6 +1474,23 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp, return 0; } +/** + * Implementation of obd_ops: o_iocontrol + * + * This function is the ioctl handler for OSP. Note: lctl will access the OSP + * directly by ioctl, instead of through the MDS stack. + * + * param[in] cmd ioctl command. + * param[in] exp export of this OSP. + * param[in] len data length of \a karg. + * param[in] karg input argument which is packed as + * obd_ioctl_data + * param[out] uarg pointer to userspace buffer (must access by + * copy_to_user()). + * + * \retval 0 0 if the ioctl handling succeeded. + * \retval negative negative errno if the ioctl handling failed. + */ static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg) { @@ -1211,9 +1534,27 @@ static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len, return rc; } +/** + * Implementation of obd_ops::o_get_info + * + * Retrieve information by key. Retrieval starts from the top layer + * (MDT) of the MDS stack and traverses the stack by calling the + * obd_get_info() method of the next sub-layer. + * + * \param[in] env execution environment + * \param[in] exp export of this OSP + * \param[in] keylen length of \a key + * \param[in] key the key + * \param[out] vallen length of \a val + * \param[out] val holds the value returned by the key + * \param[in] unused necessary for the interface but unused + * + * \retval 0 0 if getting information succeeded. + * \retval negative negative errno if getting information failed. + */ static int osp_obd_get_info(const struct lu_env *env, struct obd_export *exp, __u32 keylen, void *key, __u32 *vallen, void *val, - struct lov_stripe_md *lsm) + struct lov_stripe_md *unused) { int rc = -EINVAL; @@ -1237,8 +1578,31 @@ static int osp_obd_get_info(const struct lu_env *env, struct obd_export *exp, RETURN(rc); } +/** + * Implementation of obd_ops: o_fid_alloc + * + * Allocate a FID. There are two cases in which OSP performs + * FID allocation. + * + * 1. FID precreation for data objects, which is done in + * osp_precreate_fids() instead of this function. + * 2. FID allocation for each sub-stripe of a striped directory. + * Similar to other FID clients, OSP requests the sequence + * from its corresponding remote MDT, which in turn requests + * sequences from the sequence controller (MDT0). + * + * \param[in] env execution environment + * \param[in] exp export of the OSP + * \param[out] fid FID being allocated + * \param[in] unused necessary for the interface but unused. + * + * \retval 0 0 FID allocated successfully. + * \retval 1 1 FID allocated successfully and new sequence + * requested from seq meta server + * \retval negative negative errno if FID allocation failed. + */ int osp_fid_alloc(const struct lu_env *env, struct obd_export *exp, - struct lu_fid *fid, struct md_op_data *op_data) + struct lu_fid *fid, struct md_op_data *unused) { struct client_obd *cli = &exp->exp_obd->u.cli; struct osp_device *osp = lu2osp_dev(exp->exp_obd->obd_lu_dev); @@ -1318,6 +1682,18 @@ static struct obd_ops osp_obd_device_ops = { struct llog_operations osp_mds_ost_orig_logops; +/** + * Initialize OSP module. + * + * Register device types OSP and Light Weight Proxy (LWP) (\see lwp_dev.c) + * in obd_types (\see class_obd.c). Initialize procfs for the + * the OSP device. Note: OSP was called OSC before Lustre 2.4, + * so for compatibility it still uses the name "osc" in procfs. + * This is called at module load time. + * + * \retval 0 0 if initialization succeeds. + * \retval negative negative errno if initialization failed. + */ static int __init osp_mod_init(void) { struct obd_type *type; @@ -1370,6 +1746,12 @@ static int __init osp_mod_init(void) return rc; } +/** + * Finalize OSP module. + * + * This callback is called when kernel unloads OSP module from memory, and + * it will deregister OSP and LWP device type from obd_types (\see class_obd.c). + */ static void __exit osp_mod_exit(void) { class_unregister_type(LUSTRE_LWP_NAME); -- 1.8.3.1