From: Fan Yong Date: Sat, 2 Nov 2013 18:42:47 +0000 (+0800) Subject: LU-3335 osd: use local transaction directly inside OSD X-Git-Tag: 2.5.53~47 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=3b8d55572ef3da2e8fdb655bb30c538833c0973a LU-3335 osd: use local transaction directly inside OSD For OSD internal function, it is unnecessay to call dt_trans_xxx for transaction operations. Instead, call backend journal APIs directly. Signed-off-by: Fan Yong Change-Id: I111c52f76a894e4269ad8ac6aec3ea7747ba4f59 Reviewed-on: http://review.whamcloud.com/7145 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Lai Siyao --- diff --git a/lustre/osd-ldiskfs/osd_compat.c b/lustre/osd-ldiskfs/osd_compat.c index a4323d0..6e28728 100644 --- a/lustre/osd-ldiskfs/osd_compat.c +++ b/lustre/osd-ldiskfs/osd_compat.c @@ -527,10 +527,9 @@ static int osd_obj_update_entry(struct osd_thread_info *info, struct dentry *dir, const char *name, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th) + handle_t *th) { struct inode *parent = dir->d_inode; - struct osd_thandle *oh; struct dentry *child; struct ldiskfs_dir_entry_2 *de; struct buffer_head *bh; @@ -542,9 +541,8 @@ static int osd_obj_update_entry(struct osd_thread_info *info, int rc; ENTRY; - oh = container_of(th, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle != NULL); - LASSERT(oh->ot_handle->h_transaction != NULL); + LASSERT(th != NULL); + LASSERT(th->h_transaction != NULL); child = &info->oti_child_dentry; child->d_parent = dir; @@ -605,12 +603,12 @@ update: * is still valid. Since it was referenced by an invalid entry, * making it as invisible temporary may be not worse. OI scrub * will process it later. */ - rc = ldiskfs_journal_get_write_access(oh->ot_handle, bh); + rc = ldiskfs_journal_get_write_access(th, bh); if (rc != 0) GOTO(out, rc); de->inode = cpu_to_le32(id->oii_ino); - rc = ldiskfs_journal_dirty_metadata(oh->ot_handle, bh); + rc = ldiskfs_journal_dirty_metadata(th, bh); GOTO(out, rc); @@ -623,19 +621,17 @@ out: static int osd_obj_del_entry(struct osd_thread_info *info, struct osd_device *osd, struct dentry *dird, char *name, - struct thandle *th) + handle_t *th) { struct ldiskfs_dir_entry_2 *de; struct buffer_head *bh; - struct osd_thandle *oh; struct dentry *child; struct inode *dir = dird->d_inode; int rc; ENTRY; - oh = container_of(th, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle != NULL); - LASSERT(oh->ot_handle->h_transaction != NULL); + LASSERT(th != NULL); + LASSERT(th->h_transaction != NULL); child = &info->oti_child_dentry; @@ -650,7 +646,7 @@ static int osd_obj_del_entry(struct osd_thread_info *info, rc = -ENOENT; bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL); if (bh) { - rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh); + rc = ldiskfs_delete_entry(th, dir, de, bh); brelse(bh); } mutex_unlock(&dir->i_mutex); @@ -662,9 +658,8 @@ int osd_obj_add_entry(struct osd_thread_info *info, struct osd_device *osd, struct dentry *dir, char *name, const struct osd_inode_id *id, - struct thandle *th) + handle_t *th) { - struct osd_thandle *oh; struct dentry *child; struct inode *inode; int rc; @@ -674,9 +669,8 @@ int osd_obj_add_entry(struct osd_thread_info *info, if (OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_NO_ENTRY)) RETURN(0); - oh = container_of(th, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle != NULL); - LASSERT(oh->ot_handle->h_transaction != NULL); + LASSERT(th != NULL); + LASSERT(th->h_transaction != NULL); inode = &info->oti_inode; inode->i_sb = osd_sb(osd); @@ -695,7 +689,7 @@ int osd_obj_add_entry(struct osd_thread_info *info, ll_vfs_dq_init(dir->d_inode); mutex_lock(&dir->d_inode->i_mutex); - rc = osd_ldiskfs_add_entry(oh->ot_handle, child, inode, NULL); + rc = osd_ldiskfs_add_entry(th, child, inode, NULL); mutex_unlock(&dir->d_inode->i_mutex); RETURN(rc); @@ -932,7 +926,7 @@ int osd_obj_map_insert(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th) + handle_t *th) { struct osd_obj_map *map; struct osd_obj_seq *osd_seq; @@ -975,7 +969,7 @@ again: } int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd, - const struct lu_fid *fid, struct thandle *th) + const struct lu_fid *fid, handle_t *th) { struct osd_obj_map *map; struct osd_obj_seq *osd_seq; @@ -1009,7 +1003,7 @@ int osd_obj_map_update(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th) + handle_t *th) { struct osd_obj_seq *osd_seq; struct dentry *d; @@ -1114,28 +1108,17 @@ int osd_obj_map_recover(struct osd_thread_info *info, * So keep it there before we have suitable solution. */ brelse(bh); mutex_unlock(&dir->i_mutex); + mutex_unlock(&src_parent->i_mutex); + ldiskfs_journal_stop(jh); rc = -EEXIST; /* If the src object has never been modified, then remove it. */ if (inode->i_size == 0 && inode->i_mode & S_ISUID && inode->i_mode & S_ISGID) { - bh = osd_ldiskfs_find_entry(src_parent, &src_child->d_name, - &de, NULL, NULL); - if (unlikely(bh == NULL)) { - mutex_unlock(&src_parent->i_mutex); - ldiskfs_journal_stop(jh); - RETURN(0); - } - - rc = ldiskfs_delete_entry(jh, src_parent, de, bh); - brelse(bh); - if (rc == 0) { - drop_nlink(inode); - ll_dirty_inode(inode, I_DIRTY_DATASYNC); - } + rc = vfs_unlink(src_parent, src_child); + if (unlikely(rc == -ENOENT)) + rc = 0; } - mutex_unlock(&src_parent->i_mutex); - ldiskfs_journal_stop(jh); RETURN(rc); } @@ -1189,7 +1172,7 @@ osd_object_spec_find(struct osd_thread_info *info, struct osd_device *osd, int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th) + handle_t *th) { struct dentry *root; char *name; @@ -1210,7 +1193,7 @@ int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd, int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th) + handle_t *th) { struct dentry *root; char *name; diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 8496ed4..6e276b8 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2143,16 +2143,20 @@ static int __osd_object_create(struct osd_thread_info *info, * \retval 0, on success */ static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj, - const struct lu_fid *fid, struct thandle *th) + const struct lu_fid *fid, struct thandle *th) { - struct osd_thread_info *info = osd_oti_get(env); - struct osd_inode_id *id = &info->oti_id; - struct osd_device *osd = osd_obj2dev(obj); + struct osd_thread_info *info = osd_oti_get(env); + struct osd_inode_id *id = &info->oti_id; + struct osd_device *osd = osd_obj2dev(obj); + struct osd_thandle *oh; - LASSERT(obj->oo_inode != NULL); + LASSERT(obj->oo_inode != NULL); + + oh = container_of0(th, struct osd_thandle, ot_super); + LASSERT(oh->ot_handle); osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation); - return osd_oi_insert(info, osd, fid, id, th, OI_CHECK_FLD); + return osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD); } int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd, @@ -2342,7 +2346,8 @@ static int osd_object_destroy(const struct lu_env *env, osd_trans_exec_op(env, th, OSD_OT_DESTROY); - result = osd_oi_delete(osd_oti_get(env), osd, fid, th, OI_CHECK_FLD); + result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle, + OI_CHECK_FLD); /* XXX: add to ext3 orphan list */ /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */ diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 20b4189..8d5ca40 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -650,12 +650,12 @@ int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, struct osd_inode_id *id); int osd_obj_map_insert(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th); + handle_t *th); int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd, - const struct lu_fid *fid, struct thandle *th); + const struct lu_fid *fid, handle_t *th); int osd_obj_map_update(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th); + handle_t *th); int osd_obj_map_recover(struct osd_thread_info *info, struct osd_device *osd, struct inode *src_parent, struct dentry *src_child, const struct lu_fid *fid); @@ -663,10 +663,10 @@ int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, struct osd_inode_id *id); int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th); + handle_t *th); int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th); + handle_t *th); void osd_scrub_file_reset(struct osd_scrub *scrub, __u8 *uuid, __u64 flags); int osd_scrub_file_store(struct osd_scrub *scrub); diff --git a/lustre/osd-ldiskfs/osd_oi.c b/lustre/osd-ldiskfs/osd_oi.c index 786e85b..54a016f 100644 --- a/lustre/osd-ldiskfs/osd_oi.c +++ b/lustre/osd-ldiskfs/osd_oi.c @@ -571,11 +571,10 @@ int osd_oi_lookup(struct osd_thread_info *info, struct osd_device *osd, static int osd_oi_iam_refresh(struct osd_thread_info *oti, struct osd_oi *oi, const struct dt_rec *rec, const struct dt_key *key, - struct thandle *th, bool insert) + handle_t *th, bool insert) { struct iam_container *bag; struct iam_path_descr *ipd; - struct osd_thandle *oh; int rc; ENTRY; @@ -588,14 +587,13 @@ static int osd_oi_iam_refresh(struct osd_thread_info *oti, struct osd_oi *oi, if (unlikely(ipd == NULL)) RETURN(-ENOMEM); - oh = container_of0(th, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle != NULL); - LASSERT(oh->ot_handle->h_transaction != NULL); + LASSERT(th != NULL); + LASSERT(th->h_transaction != NULL); if (insert) - rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key, + rc = iam_insert(th, bag, (const struct iam_key *)key, (const struct iam_rec *)rec, ipd); else - rc = iam_update(oh->ot_handle, bag, (const struct iam_key *)key, + rc = iam_update(th, bag, (const struct iam_key *)key, (const struct iam_rec *)rec, ipd); osd_ipd_put(oti->oti_env, bag, ipd); LINVRNT(osd_invariant(obj)); @@ -604,7 +602,7 @@ static int osd_oi_iam_refresh(struct osd_thread_info *oti, struct osd_oi *oi, int osd_oi_insert(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th, enum oi_check_flags flags) + handle_t *th, enum oi_check_flags flags) { struct lu_fid *oi_fid = &info->oti_fid2; struct osd_inode_id *oi_id = &info->oti_id2; @@ -677,36 +675,34 @@ update: } static int osd_oi_iam_delete(struct osd_thread_info *oti, struct osd_oi *oi, - const struct dt_key *key, struct thandle *handle) + const struct dt_key *key, handle_t *th) { - struct iam_container *bag; - struct iam_path_descr *ipd; - struct osd_thandle *oh; - int rc; - ENTRY; + struct iam_container *bag; + struct iam_path_descr *ipd; + int rc; + ENTRY; - LASSERT(oi); + LASSERT(oi); LASSERT(oi->oi_inode); ll_vfs_dq_init(oi->oi_inode); - bag = &oi->oi_dir.od_container; - ipd = osd_idx_ipd_get(oti->oti_env, bag); - if (unlikely(ipd == NULL)) - RETURN(-ENOMEM); + bag = &oi->oi_dir.od_container; + ipd = osd_idx_ipd_get(oti->oti_env, bag); + if (unlikely(ipd == NULL)) + RETURN(-ENOMEM); - oh = container_of0(handle, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle != NULL); - LASSERT(oh->ot_handle->h_transaction != NULL); + LASSERT(th != NULL); + LASSERT(th->h_transaction != NULL); - rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd); - osd_ipd_put(oti->oti_env, bag, ipd); - LINVRNT(osd_invariant(obj)); - RETURN(rc); + rc = iam_delete(th, bag, (const struct iam_key *)key, ipd); + osd_ipd_put(oti->oti_env, bag, ipd); + LINVRNT(osd_invariant(obj)); + RETURN(rc); } int osd_oi_delete(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, - struct thandle *th, enum oi_check_flags flags) + handle_t *th, enum oi_check_flags flags) { struct lu_fid *oi_fid = &info->oti_fid2; @@ -727,7 +723,7 @@ int osd_oi_delete(struct osd_thread_info *info, int osd_oi_update(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th, enum oi_check_flags flags) + handle_t *th, enum oi_check_flags flags) { struct lu_fid *oi_fid = &info->oti_fid2; struct osd_inode_id *oi_id = &info->oti_id2; diff --git a/lustre/osd-ldiskfs/osd_oi.h b/lustre/osd-ldiskfs/osd_oi.h index 5ddf162..2e6848f 100644 --- a/lustre/osd-ldiskfs/osd_oi.h +++ b/lustre/osd-ldiskfs/osd_oi.h @@ -53,6 +53,7 @@ /* struct rw_semaphore */ #include +#include #include #include #include @@ -65,7 +66,6 @@ struct lu_fid; struct osd_thread_info; struct lu_site; -struct thandle; struct dt_device; struct osd_device; @@ -145,13 +145,13 @@ int osd_oi_lookup(struct osd_thread_info *info, struct osd_device *osd, enum oi_check_flags flags); int osd_oi_insert(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th, enum oi_check_flags flags); + handle_t *th, enum oi_check_flags flags); int osd_oi_delete(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, - struct thandle *th, enum oi_check_flags flags); + handle_t *th, enum oi_check_flags flags); int osd_oi_update(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, const struct osd_inode_id *id, - struct thandle *th, enum oi_check_flags flags); + handle_t *th, enum oi_check_flags flags); int fid_is_on_ost(struct osd_thread_info *info, struct osd_device *osd, const struct lu_fid *fid, enum oi_check_flags flags); diff --git a/lustre/osd-ldiskfs/osd_scrub.c b/lustre/osd-ldiskfs/osd_scrub.c index 1804daa..18a0a2a 100644 --- a/lustre/osd-ldiskfs/osd_scrub.c +++ b/lustre/osd-ldiskfs/osd_scrub.c @@ -94,30 +94,26 @@ static int osd_scrub_refresh_mapping(struct osd_thread_info *info, int ops, bool force, enum oi_check_flags flags) { - const struct lu_env *env = info->oti_env; - struct thandle *th; - struct osd_thandle *oh; - int rc; + handle_t *th; + int rc; ENTRY; if (dev->od_scrub.os_file.sf_param & SP_DRYRUN && !force) RETURN(0); - th = dt_trans_create(env, &dev->od_dt_dev); - if (IS_ERR(th)) - RETURN(PTR_ERR(th)); - - oh = container_of0(th, struct osd_thandle, ot_super); - LASSERT(oh->ot_handle == NULL); + /* DTO_INDEX_INSERT is enough for other two ops: + * delete/update, but save stack. */ + th = ldiskfs_journal_start_sb(osd_sb(dev), + osd_dto_credits_noquota[DTO_INDEX_INSERT]); + if (IS_ERR(th)) { + rc = PTR_ERR(th); + CERROR("%s: fail to start trans for scrub %d: rc = %d\n", + osd_name(dev), ops, rc); + RETURN(rc); + } switch (ops) { case DTO_INDEX_UPDATE: - osd_trans_declare_op(env, oh, OSD_OT_UPDATE, - osd_dto_credits_noquota[DTO_INDEX_UPDATE]); - rc = dt_trans_start_local(env, &dev->od_dt_dev, th); - if (rc != 0) - GOTO(stop, rc); - rc = osd_oi_update(info, dev, fid, id, th, flags); if (unlikely(rc == -ENOENT)) { /* Some unlink thread may removed the OI mapping. */ @@ -125,12 +121,6 @@ static int osd_scrub_refresh_mapping(struct osd_thread_info *info, } break; case DTO_INDEX_INSERT: - osd_trans_declare_op(env, oh, OSD_OT_INSERT, - osd_dto_credits_noquota[DTO_INDEX_INSERT]); - rc = dt_trans_start_local(env, &dev->od_dt_dev, th); - if (rc != 0) - GOTO(stop, rc); - rc = osd_oi_insert(info, dev, fid, id, th, flags); if (unlikely(rc == -EEXIST)) { rc = 1; @@ -168,12 +158,6 @@ static int osd_scrub_refresh_mapping(struct osd_thread_info *info, } break; case DTO_INDEX_DELETE: - osd_trans_declare_op(env, oh, OSD_OT_DELETE, - osd_dto_credits_noquota[DTO_INDEX_DELETE]); - rc = dt_trans_start_local(env, &dev->od_dt_dev, th); - if (rc != 0) - GOTO(stop, rc); - rc = osd_oi_delete(info, dev, fid, th, flags); if (rc == -ENOENT) { /* It is normal that the unlink thread has removed the @@ -186,10 +170,7 @@ static int osd_scrub_refresh_mapping(struct osd_thread_info *info, break; } - GOTO(stop, rc); - -stop: - dt_trans_stop(env, &dev->od_dt_dev, th); + ldiskfs_journal_stop(th); return rc; }